Thursday, April 30, 2020

Close-to-Close Historical Volatility Calculation – Volatility Analysis in Python

In a previous post, we touched upon a stock’s volatility through its beta. In this post, we are going to discuss historical volatilities of a stock in more details.

Also referred to as statistical volatility, historical volatility gauges the fluctuations of underlying securities by measuring price changes over predetermined periods of time. It is the less prevalent metric compared to implied volatility because it isn't forward-looking.

When there is a rise in historical volatility, a security's price will also move more than normal. At this time, there is an expectation that something will or has changed. If the historical volatility is dropping, on the other hand, it means any uncertainty has been eliminated, so things return to the way they were. Read more

There are various types of historical volatilities such as close to close, Parkinson, Garman-KIass, Yang-Zhang, etc. In this post, we will discuss the close-to-close historical volatility.

The close-to-close historical volatility (CCHV) is calculated as follows,

historical volatility in python

where xi are the logarithmic returns calculated based on the stock's closing prices,  and N is the sample size.  In this example, N=22, the average number of trading days in a month.

We implemented the above equation in Python. We downloaded SPY data from Yahoo finance and calculated CCHV using the Python program. The picture below shows the close-to-close historical volatility of SPY from March 2015 to March 2020.

volatility trading in python

It’s observed that the volatility is a mean-reverting process. The CCHV has the following characteristics [1]

Advantages

  • It has well-understood sampling properties
  • It is easy to correct bias
  • It is easy to convert to a form involving typical daily moves

Disadvantages

  • It is a very inefficient use of data and converges very slowly

Follow the link below to download the Python program.

 

References

[1] E. Sinclair, Volatility Trading, John Wiley & Sons, 2008

Article Source Here: Close-to-Close Historical Volatility Calculation – Volatility Analysis in Python

Tuesday, March 31, 2020

What is Stock Beta and How to Calculate Stock Beta in Python

In finance, beta measures a stock's volatility with respect to the overall market. It is used in many areas of financial analysis and investment, for example in the calculation of the Weighted Average Cost of Capital, in the Capital Asset Pricing Model and market-neutral trading.

Beta of an investment is a measure of the risk arising from exposure to general market movements as opposed to idiosyncratic factors.

The market portfolio of all investable assets has a beta of exactly 1. A beta below 1 can indicate either an investment with lower volatility than the market, or a volatile investment whose price movements are not highly correlated with the market. An example of the first is a treasury bill: the price does not fluctuate significantly, so it has a low beta. An example of the second is gold. The price of gold fluctuates significantly, but not in the same direction or at the same time as the market.

A beta greater than 1 generally means that the asset both is volatile and tends to move up and down with the market. An example is a stock in a big technology company. Negative betas are possible for investments that tend to go down when the market goes up, and vice versa. There are few fundamental investments with consistent and significant negative betas, but some derivatives like put options can have large negative betas. Read more

In this post, we present a concrete example of calculating the beta of Facebook, a technology stock. As for the market benchmark, we utilize SPY.

The beta of a financial instrument is calculated as follows,

Quantitative analysis of stock beta

where

  • rS is the stock return,
  • rM is the market return,
  • Cov denotes the return covariance and,
  • Var denotes the return variance.

We downloaded 5 years of data from Yahoo Finance and implemented equation (1) in Python.  The picture below shows the result returned by the Python program

How to calculate stock beta

It’s observed that the beta of Facebook is 1.19, which means that Facebook is more volatile than the market.

The next picture shows the stock returns regressed against market returns. Note that the slope of the linear regression line equals the beta of the stock.

Quantitative trading using beta in python

Follow the link below to download the Python program.

Article Source Here: What is Stock Beta and How to Calculate Stock Beta in Python

Wednesday, March 25, 2020

Correlation Between the VVIX and VIX indices

The VIX index is an important market indicator that everyone is watching. VVIX, on the other hand, receives less attention. In this post, we are going to take a look at the relationship between the VIX and VVIX indices.

While the VIX index measures the volatility risks, VVIX measures the volatility-of-volatility risks. Its calculation methodology is similar to the VIX’s except that instead of using SPX options it uses VIX options.

To study the relationship between these 2 indices, we first calculated the rolling 20-days correlation of the VIX and VVIX returns from January 2007 to March 2020. The median value of correlation is 0.807 and 25% quantile is 0.66

The figure below presents the rolling 20-days VIX/VVIX correlation for the last 2 years. We also superimposed SPY on the chart. We observe that the correlation is usually high but there are periods where it decreases significantly. The current period is one of those.

[caption id="attachment_393" align="alignnone" width="628"]Correlation Between the VVIX and VIX indices Correlation between the VVIX and VIX indices[/caption]

The next figure shows the scatter plot of VVIX returns vs. VIX returns. It’s observed that there is a significant population where VIX and VVIX returns are of opposite signs.  We subsequently calculated the number of instances where VIX and VVIX move in the opposite direction. This indeed happens 22% of the time.

[caption id="attachment_394" align="aligncenter" width="563"]VVIX returns vs. VIX returns VVIX returns vs. VIX returns[/caption]

Some implications of this study are:

  • Although the correlation between VIX and VVIX appears to be high, there is a significant number of instances where VIX and VVIX move in the opposite direction. So it’s fair to say that VVIX follows separate price dynamics which is different from the VIX. In other words, VVIX prices in different risks.
  • Long VIX options or SPX back spreads are not always a good hedge for an equity portfolio. The hedge can break down.
  • At times it’s cheaper to hedge a long equity portfolio using SPX options; at times it’s cheaper using VIX options.

See More Here: Correlation Between the VVIX and VIX indices

Monday, March 16, 2020

Value At Risk – Financial Risk Management in Python

Value at Risk (VaR) is a tool for measuring a portfolio’s risk.

Value at risk (VaR) is a measure of the risk of loss for investments. It estimates how much a set of investments might lose (with a given probability), given normal market conditions, in a set time period such as a day. ... For a given portfolio, time horizon, and probability p, the p VaR can be defined informally as the maximum possible loss during that time after we exclude all worse outcomes whose combined probability is at most p. This assumes mark-to-market pricing, and no trading in the portfolio.

For example, if a portfolio of stocks has a one-day 5% VaR of $1 million, that means that there is a 0.05 probability that the portfolio will fall in value by more than $1 million over a one-day period if there is no trading. Informally, a loss of $1 million or more on this portfolio is expected on 1 day out of 20 days (because of 5% probability). Read more

There are basically 3 methods for calculating the VaR [1]

  1. Historical simulation
  2. Variance-covariance approach
  3. Monte Carlo simulation

In this post, we implement the 3rd method, i.e. the Monte Carlo simulation, in Python.  More details of the methodology can be found in Ref [1].

The simulation parameters are as follows,

  • Portfolio value: $1 Million
  • Confidence interval: 95%
  • Time horizon: 1 day
  • Underlying: SPY

We utilize 5-years daily data of SPY retrieved from Yahoo Finance. The picture below shows the VaR retuned by the Python program.

Risk Management in Python, Value at Risk in Python

Note that the method presented in this post is suitable for calculating the VaR in a normal market condition. More advanced approaches such as Expected Tail Loss have been developed that can better take into account the tail risk.

Follow the link below to download the Python program.

References

[1] Hull, John C. (2003). Options, Futures, and Other Derivatives. Prentice-Hall

Article Source Here: Value At Risk – Financial Risk Management in Python

Saturday, February 29, 2020

Another Misuse of Financial Derivatives

Just like any financial derivatives that were initially designed for risk management purposes, interest rate swaps are an effective tool for managing and transferring interest rate risks as long as those risks are well understood.  But as banks and financial institutions are constantly trying to invent new financial products to sell to their consumers, sometimes the risks of those products are not well understood and disclosed.

This is what happened with the interest rate swap market in New Zealand where banks sold interest rate swaps to farmers in order for them to hedge the fluctuation in the mortgage rates.  However, the banks only emphasized the advantages of the interest rate swaps, and they did not discuss the potential downside in detail.

Swaps are enormously complicated and risky financial derivatives. They are used - mostly by big businesses or international dealing rooms - to hedge against interest rate moves.

But in the period 2005-2008, New Zealand banks aggressively sold swaps to farmers as a supposedly less risky alternative to fixed interest loans, and a way for farmers to protect themselves from hikes in their mortgage repayments if interest rates went up.

When the financial crisis hit, and the interest rates went down, farmers started losing money. Many were forced to sell their farms, and some of them committed suicide.

Walker estimates up to 2000 New Zealand farmers lost up to $1 billion on swaps. They lost farms they had inherited from their fathers and planned to pass onto their children. Too many committed suicide. Walker spent the three years following the Farmers Weekly survey doggedly researching banks' sales of swaps to New Zealand farmers. And then she went to see the regulators.  Read more

The problem is not in the financial derivative itself, but it is that the risks were not well understood and explained to the customers.

Banks will be asking what are the lessons, what do we need to change to make sure going forward we don't have this happen with a different product. It's not so much just about the swaps but how do we make this not happen in the future.

Article Source Here: Another Misuse of Financial Derivatives

Monday, February 24, 2020

Accounting for Convertible Debt

Convertible debt is a type of loan that can be converted back to stock after some specified future date. When making an investment in convertible debt, both the issuer and investor are clear that there is a possibility of debt being converted into stock in the future. International Account Standard 32 deals with accounting for convertible debt.

A convertible debt instrument is an alternative financing solution, normally used by companies to finance their operation or working capital. The peculiar thing about this arrangement is that both parties can be on the same page regarding an eventual conversion of convertible debt into common stock of the company. In other words, both the issuer and the holder can convert the debt into equity at a future date. However, the former (i.e. the forced conversion) is rare, while the latter (conversion by the holder) is more common.

Sometimes, it is not easy for the company to issue convertible debt because the shareholder may oppose this management decision. This is due to the fact that upon conversion of the debt to equity, the shareholders’ stock values will decline because of the share dilution. Therefore management needs to pursue by performing a cost-benefit analysis as to why the issuance of convertible debt is beneficial to the company and its shareholders at the same time.

An example of a convertible debt

Normally, the company issues the bond at par, but sometimes it can offer a discount to investors in convertible debts as an incentive. For example, Mr. A purchased a convertible bond on January 01, 2020, for $500,000 at $500 each, whereas the par value of the bond is $550. Why has the company offered a discount on the issuance of the bond?  It is because investors will be likely to convert their debts into equities.

Why offering a discount?

Debt is senior to equity in terms of payback at times of liquidation. So if an investor is willing to forgo his debt right for equity, then obviously the company has to offer some incentive in order to keep its investment.

Moving forward in the above-mentioned example, if the maturity of the bond is December 31, 2024, this means that after 5 years, the investor can convert and the company can reduce its debts leverage and issue its stocks in place.

Why is issuing a convertible bond good for the company?

A company at times is in need of financing, but they don’t want to increase their debt leverage, therefore they offer a discount to investors for investing in their convertible debt instruments. Once the investment has been made, the company can save itself from a debt burden.

Why is purchasing a convertible bond good for investors?

Often times it is worthwhile to invest in a company’s stock but for some reason, the investor does not want to invest in equity immediately. Therefore a better way is to go for convertible debt and then convert it into equity at a future date. This way, the investor will be in the position of a shareholder. In addition, as discussed above, the investor can be offered a discount as an incentive for investing in convertible debt.

How to account for the convertible debt:

As both the company and investors have the same understanding that after a defined period of time they can convert the debt into common stocks, therefore as per IAS-32, when accounting for the convertible debt, the company has to recognize the issuance of convertible debts as a compound instrument.

Every year the interests accrued on the debt portion of the convertible debt shall be recognized in the profit and loss statement, and at the maturity of that instrument, all the loan shall be converted into equity at par and will be recognized in the capital of the company.

Post Source Here: Accounting for Convertible Debt

Thursday, February 6, 2020

Valuing European Options Using Monte Carlo Simulation-Derivative Pricing in Python

In a previous post, we presented a methodology for pricing European options using a closed-form formula. In this installment, we price these options using a numerical method. Specifically, we will use Monte Carlo simulation.

Recall that,

  • A call option gives the buyer the right, but not the obligation to buy an agreed quantity of the underlying from the seller at a future time for a given price. The payoff of the call option at expiration is max(ST-K,0),
  • A put option gives the buyer the right, but not the obligation to sell an agreed quantity of the underlying to the seller at a future time for a given price. The payoff of the put option at expiration is max(K -ST,0),

where ST  denotes the stock price at expiration and K is the strike price.

To price these options, we first simulate the price paths using the following Stochastic Differential Equation:

Monte Carlo simulation in pythonwhere

  • St is the stock price at time t,
  • σ denotes the stock volatility,
  • µ is the drift which equals the risk-free rate, and
  • dWt represents the standard normal random variable.

The simulation is carried out until the options’ maturity. We then apply the terminal payoff functions and calculate the mean values of all the payoffs. Finally, we discount the mean values to the present and thus obtain the option values.  For a more detailed presentation of the Monte Carlo method, see Reference [1].

The picture below shows the call and put option prices using 100000 simulations. All other parameters are the same as in the previous post.

options pricing in Python using Monte Carlo

We compare the above results to the ones obtained by using a third-party software and notice that they are in good agreement.

derivative pricing in python

In the next installment, we will present a methodology for pricing American options using Monte Carlo simulation.

References

[1] Glasserman, Paul; Monte Carlo Methods in Financial Engineering, Springer; 2003

 

Follow the link below to download the Python program.

Originally Published Here: Valuing European Options Using Monte Carlo Simulation-Derivative Pricing in Python

Friday, January 31, 2020

Black-Scholes-Merton Option Pricing Model-Derivative Pricing in Python

The Black-Scholes-Merton model is one of the earliest option pricing models that was developed in the late 1960s and published in 1973 [1,2]. The most important concept behind the model is the dynamic hedging of an option portfolio in order to eliminate the market risk. First, a delta-neutral portfolio is constructed, and then it is adjusted to stay delta neutral as the market fluctuates. Finally, we arrive at a Partial-Differential Equation for the value of the option.

derivative pricing in python

where

  • V denotes the option value at time t,
  • S  is the stock price,
  • r is the risk-free interest rate and,
  • σ is the stock volatility.

This equation is also called a diffusion equation, and it has closed-form solutions for European call and put options. For a detailed derivation and analytical formula, see Reference [3].

In this post, we focus on the implementation of the Black-Scholes-Merton option pricing model in Python. Closed-form formula for European call and put are implemented in a Python code. The picture below shows the prices of the call and  put options for the following market parameters:

  • Stock price: $45
  • Strike price: $45
  • Time to maturity: 1 year
  • Risk-free rate: 2%
  • Volatility: 25%

option pricing in python

We compare the above results to the ones obtained by using third-party software and notice that they are in good agreement.

derivative valuation in python

In the next installment, we will price these options using Monte Carlo simulation.

References:

[1] Black, Fischer; Myron Scholes (1973). The Pricing of Options and Corporate Liabilities. Journal of Political Economy. 81 (3): 637–654

[2] Merton, Robert C. (1973). Theory of Rational Option Pricing. Bell Journal of Economics and Management Science.

[3] Hull, John C. (2003). Options, Futures, and Other Derivatives. Prentice Hall

 

Follow the link below to download the Python program.

Originally Published Here: Black-Scholes-Merton Option Pricing Model-Derivative Pricing in Python

Sunday, January 26, 2020

Derivative Pricing and Valuation

A derivative is a financial instrument whose price is derived from an underlying asset. Thus, in very simple words, the price and value of a derivative stem from its underlying asset. The underlying asset can be anything that has some value. The most common forms of derivatives are forwards, futures, options, and swaps. Although other derivatives also exist, known as exotic derivatives, in this article we will focus on these four types of derivatives.

Although the pricing models differ for each type of derivative, the underlying principle is the same: financial derivatives are priced based on non-arbitrage principle, or the law of one price.

Forward Contracts

A forward contract is a private agreement between two parties giving the buyer an obligation to purchase an asset, and the seller an obligation to sell an asset at a set price at a future point in time. The underlying asset can be anything of value. In order to understand this better, let us look at a simple example.

Let us assume that the underlying asset here is a 10 kg bag of apples that have not been harvested yet. Technically, the underlying asset does not even exist, so it has no financial value. However, it is still possible to assign a price to it. Suppose that a farmer enters into a forward contract to sell the 10 kg bag of apples at a price of $20 in 3 months' time when the apples will be harvested. The farmer does this because he fears that the price of apples may go down in the future, resulting in a loss for him. So in order to set off or hedge the potential loss, the farmer enters into a forward contract with a buyer who agrees to buy the 10 kg bag of apples at the $20 price determined today. This means that 3 months from now, the forward contract will be executed at $20 regardless of the price in the future. In this manner both the buyer and seller transfer the risks to each other.

Forward contracts are often customized and trade over the counter.

Future Contracts

A futures contract is a legal agreement to buy or sell a particular commodity, or security at a predetermined price at a specified time in the future. Futures contracts are standardized for quality and quantity in order to facilitate trading on an organized exchange.  In addition, unlike forwards, the profit and loss of a futures contract is settled daily.

Despite the differences, the underlying principles for both futures and forwards are the same. The parties enter into a contract to buy or sell a particular underlying asset at a fixed price in the future, and the value of the contract is determined as the underlying asset is realized.

Option Contracts

An options contract is an agreement between a buyer and seller that gives the buyer of the option the right but not the obligation to buy or sell a particular asset at a later date at an agreed-upon price. Options contracts are often used in securities, commodities, and real estate transactions.

In principle, options are similar to forwards and futures but the difference is its holder has a right, but not an obligation to buy or sell the underlying asset. A call option gives the buyer the right to buy the asset at a predetermined price at or before maturity. A put option allows the holder to sell at a predetermined price at or before expiration.

Going back to our original example, suppose that the farmer has bought a put option that allows him to sell apples at $20. Three months later, if the price of 10 kg bag of apples becomes $24, then in this situation the farmer would have the option of not executing the contract at $20 and instead of selling the 10 kg bag of apples at the market price of $24. However, if the price of the apples falls down to $15, then the farmer can exercise the put option and sell the apples at the contractual price of $20.

Black-Scholes option pricing model

There are different models for valuing options. The earliest model is called the Black-Scholes option pricing model which provides an analytical, closed-form formula for valuing a European option. The model requires 5 important input parameters: spot price, strike price, volatility, risk-free rate, maturity.

Binomial option pricing model

Binomial option model is used to value American style options. The model relies on the assumption that for the next time period, a stock can move up, or down with certain probabilities. The major advantage of the binomial model is that it’s relatively simple. To value an option using this method, a tree of possible values of the underlying assets is built first. Then the option value is determined by calculating its payoffs at maturity and rolling back to time zero.

Swaps

A swap is a derivative contract through which two parties can exchange the cash flows or liabilities from two different financial instruments. The most common type of swap is interest rate swap, however, there exist other types such as commodity and currency swaps.

Interest rate swaps are used to manage and transfer interest rate risks. Let’s take a look at an example, a parent company operating in the USA has a subsidiary in Europe. The parent in the USA has to pay a fixed-rate loan in dollars whereas the subsidiary based in Europe has to pay a variable rate loan in Euro. The parent wants to pay a variable rate based on its cash flow situation whereas the subsidiary wants the fixed-rate loan because of the certainty of payments. Thus, both the parent and subsidiary will enter into an interest rate swap where the parent will end up paying the variable-rate euro loan and the subsidiary will end up paying the fixed-rate dollar loan.

An interest rate swap can be valued by decomposing it into fixed-rate and floating-rate bonds. Essentially, the value of each leg is determined by calculating the Net Present Value of future cash flows. An alternative way to value an interest rate swap is to view it as a series of Forward Rate Agreements.

Article Source Here: Derivative Pricing and Valuation

Monday, January 20, 2020

Are Collateralized Loan Obligations the New Debt Bombs? Part Two

In a previous post, we discussed the risks of Collateralized Loan Obligations, a type of complex credit derivatives.  Since then, the trend in securitizing loans is still upward. Nowadays, not only performing loans but also non-performing loans are being securitized and sold to investors.derivative valuation of illiquid load, corporate bond, debt

A non-performing loan is a loan that is in default or close to being in default. Depending on the terms of the contract, a loan can become non-performing after being in default for 90 days. Recently, independent.ie reported

Non-banks - including vulture funds - that have amassed billions of euro of non performing loan (NPL) portfolios are likely to securitise some of those loan either to lower their own financing costs or simply to raise cash...This trend already appears to be underway, with Scope noting a €419.8m deal by Lone Star in the third quarter of last year when it raised funds by borrowing against the value of portfolio of performing and non-performing loans. Read more

Securitization is a proactive measure that allows a financial institution to transfer the risks of a portfolio of non-performing loans.

The massive bad-loan sales in recent years began with boom era commercial property and developer loans that have now largely been removed from bank balance sheet. Lenders here now have what the agency called “relatively granular NPL stock” mainly of SME loans and residential mortgages. These are significantly easier to securitise than CRE portfolios, and if the “No Consent, No Sale” bill became law, so called synthetic securitisation remains a viable risk-transfer mechanism. Synthetic securitisation involves banks buying complex financial derivatives to insure against the risk of borrower defaults.

However, there are many issues associated with managing the risks of these non-performing loans, notably the lack of standard definitions and valuation methodology.  A solid regulatory framework should be developed to ensure market transparency and to facilitate risk management.

Originally Published Here: Are Collateralized Loan Obligations the New Debt Bombs? Part Two