In this article, we will explore the most widely used volatility estimators in trading. We will explain both their advantages and limitations, and provide any other relevant information. Additionally, to put these concepts into practice, we will present an implementation in the Python programming language.
It is important to note that the choice of volatility estimator may vary depending on the asset and the time frame being analyzed. It is not appropriate to evaluate an asset using the "close to close" (C2C) volatility approach, which captures the full daily volatility, when dealing with a trade that has lasted only a few minutes in the market. For these cases, a more appropriate volatility estimator is needed.
The ultimate goal of this article is to achieve a better understanding of the decision methods for using an estimator.
Volatility Estimators: Close to Close (C2C)
To begin with the estimators, the starting point is the "Close to Close" (C2C) volatility estimator, which incorporates in its calculation the variation from the previous day's close to the current day's close. It is based on a fixed time interval function, where each point has the same duration, which is the most common way to measure volatility.
It is the most natural and intuitive way to measure an asset's volatility. Although it is not clearly defined who first formulated the notion of volatility or this estimator, one of the names closely associated with the study of volatility since its beginnings is Louis Bachelier, a French mathematician who in 1900 presented his Theory of Speculation. In this theory, Bachelier included the use of differences between closing prices as a volatility indicator, among other methods.
Later, around 1960, Paul Samuelson and Robert C. Merton, in their research, focused on creating a financial option valuation method that has endured to this day, known as the Black-Scholes method. One of the most disruptive contributions of this model's publication was considering volatility as a crucial factor in determining an option's price. This revolutionary approach recognized that the volatility of the underlying asset plays a fundamental role in the valuation of financial options.
Another relevant name in the development of the mathematical formulation of volatility is Robert Engle, who developed the ARCH (Autoregressive Conditional Heteroskedasticity) model in the 1980s. The ARCH model represented a significant advance in volatility modeling. This approach allowed capturing and modeling the changing fluctuations in volatility over time, recognizing the heteroskedastic nature of volatility in financial data. The ARCH model and its subsequent extensions have been widely used in estimating and predicting volatility in financial markets.
Close to Close Formula
Where:
- $N$ – Number of days in the sample
- $x$ – Daily return
$$\sigma_{PK} = \sqrt{\frac{1}{4\ln 2} \cdot \frac{1}{N} \sum_{i=1}^{N} \left[\ln\left(\frac{H_i}{L_i}\right)\right]^2}$$
$$\sigma_{GK} = \sqrt{\frac{1}{N}\sum_{i=1}^{N}\left[\frac{1}{2}\left(\ln\frac{H_i}{L_i}\right)^2 - (2\ln 2 - 1)\left(\ln\frac{C_i}{O_i}\right)^2\right]}$$
Estimator Considerations
This formula is widely used due to its simplicity in calculation, although it does not take into account certain dynamics that typically occur in financial markets. The two key assumptions are:
- Returns do not necessarily have autocorrelation between them (no need to assume trend or mean reversion).
- Some assets trade in discrete time (fixed intervals), this allows leveraging a volatility variance structure, which is only possible if participating in the pre-market auction offered by the broker, generally 15 minutes before opening.
The first assumption is generally reliable, but the second assumption is inaccurate in approximately 99% of cases, as discrete or fixed time intervals are rarely used. An illustrative example is the case of traders who only trade at market close or open, or at similar liquidity moments. These traders are usually interested in taking positions with the day closed, as in the case of volswaps/varswaps.
Python Code Estimator
We are going to create code that calculates the Close to Close volatility of an asset, over a given period. To do this, we will use basic Python libraries:
- pandas: As the foundation of everything. We will use dataframes and building functions for simplicity, stability, and fluency.
- numpy: We will use matrices to agilely transform data, having full integration with pandas, simplifying all the work for the user.
- yfinance: We will download daily close data, necessary for calculating our close to close volatility from Yahoo, using the yfinance library. It has full integration with pandas.
Thanks to these libraries, we can perform the calculations in a few simple lines.
### QUANTARMY 2023 - [jcx@QA]#
### GNU PUBLIC LICENSE CODE
#IMPORTS
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import yfinance as yf
#INPUTS
T = 100
s = 'GME'
#Descarga de datos
data = yf.download(s)[['Adj Close']].dropna()
#Calculo de la volatilidad Close to Close (C2C)
data['c2c'] = np.sqrt(252) * pd.DataFrame.rolling(np.log(data.loc[:, 'Adj Close'] / data.loc[:, 'Adj Close'].shift(1)),
window=T).std().values
In the imports section, we load all necessary libraries. In the inputs section, we select the period (T) for volatility calculation and the asset (s) we want to calculate.
Subsequently, we call yf.download to download the 'Adj Close' column of ticker s, in this case 'GME'. Additionally, we specify that we want to remove NA values.
Once we have a dataframe in time series format with the adjusted closing prices of asset s, we create a new column called 'C2C' where we perform the mathematical calculations. We start by calculating the logarithm of the ratio of yesterday's close to today's close. Then, we apply a rolling window of T days and calculate its standard deviation using .std(). The .values ending is included to avoid index issues and only include numerical values in the calculation.
Results
Calculation of Close to Close volatility with the code explained above.