How to tell if options are cheap with volatility cones
How to tell if options are cheap with volatility cones
How to tell if options are cheap with volatility cones
In today’s issue, I’m going to show you how to build realized volatility cones using Python.
The hardest part of options trading is determining if they are cheap or expensive. Whether you buy or sell an option, you’re exposed to the volatility of the underlying. That’s why it’s important to compare volatility to its recent levels.
Volatility cones can help you do this.
I’m going to show you how using Python. We’ll grab price data, compute realized volatility, and do some charting with Matplotlib.
Let's get started.
Step 1: Import the required libraries
I’m using Jupyter Notebook. I want to plot my charts inline, so I call %matplotlib inline first.
We’ll start by importing the libraries we need.
1%matplotlib inline
2
3import math
4import yfinance as yf
5import numpy as np
6import matplotlib.pyplot as plt
Step 2: Setup the variables
Next, we’ll setup some variables we’ll use later. These are all Python lists. windows defines the number of days I want to use to compute volatility. quantiles defines the percentage of the top and bottom 25% of values. The last few lists are where we accumulate data to plot.
1windows = [30, 60, 90, 120]
2quantiles = [0.25, 0.75]
3
4min_ = []
5max_ = []
6median = []
7top_q = []
8bottom_q = []
9realized = []
Let’s get some data.
1data = yf.download("JPM", start="2020-01-01", end="2020-12-31")
As usual, we’ll use yfinance to get stock data - in this case, JPM. You can use any stock and any price range you want.
Step 3: Realized volatility
Realized volatility is a measurement of how much the price or returns of stock vary. It’s used to optimize portfolios, detect regime changes, and price derivatives. The most common way to measure realized volatility is the standard deviation.
If you’d like to check out other ways to compute realized volatility, you can do that here (for free).
1def realized_vol(price_data, window=30):
2
3 log_return = (price_data["Close"] / price_data["Close"].shift(1)).apply(np.log)
4
5 return log_return.rolling(window=window, center=False).std() * math.sqrt(252)
The next step is to loop through each of the windows and compute realized volatility over each time frame. estimator is a pandas DataFrame. That’s why it’s so easy so compute the min, max, median, and quantiles. Magic.
1for window in windows:
2
3 # get a dataframe with realized volatility
4 estimator = realized_vol(window=window, price_data=data)
5
6 # append the summary stats to a list
7 min_.append(estimator.min())
8 max_.append(estimator.max())
9 median.append(estimator.median())
10 top_q.append(estimator.quantile(quantiles[1]))
11 bottom_q.append(estimator.quantile(quantiles[0]))
12 realized.append(estimator[-1])
Step 4: Plot the results
The last step is to create a chart that plots the volatility cone.
1# create the plots on the chart
2plt.plot(windows, min_, "-o", linewidth=1, label="Min")
3plt.plot(windows, max_, "-o", linewidth=1, label="Max")
4plt.plot(windows, median, "-o", linewidth=1, label="Median")
5plt.plot(windows, top_q, "-o", linewidth=1, label=f"{quantiles[1] * 100:.0f} Prctl")
6plt.plot(windows, bottom_q, "-o", linewidth=1, label=f"{quantiles[0] * 100:.0f} Prctl")
7plt.plot(windows, realized, "ro-.", linewidth=1, label="Realized")
8
9# set the x-axis labels
10plt.xticks(windows)
11
12# format the legend
13plt.legend(loc="upper center", bbox_to_anchor=(0.5, -0.1), ncol=3)
The first 6 lines create the lines on the chart. The other two align the x-axis labels and format the legend.
Step 5: Analyze the results
The y-axis is the realized volatility over each time frame. The x-axis is time frame we use to compute the realized volatility.
There are three conclusions you can draw from this chart:
- Over the 30-day window, there is a spike in realized volatility. Realized volatility spikes usually correspond to a drop in the stock price. This should tell us to explore the stock price to see what happened.
- Realized volatility (the dashed line) is close to the lowest it’s been across all time frames. This is a data point to support a case to get long volatility (i.e. options are cheap).
- Realized volatility is mean reverting. You can see this in the cone shape of the chart. This is a data point to support a case to get long volatility.