1
$\begingroup$

I'm relatively new to this field and would like to ask a couple of questions.

I'm doing some analysis and I would like to compare/plot VIX vs historical volatility of SPX. I have daily VIX and SPX data. So the first thing I tried to do was to compute historical volatility, I came up with the following function

from numpy import sqrt,mean,log,diff
def get_historical_volatility(df, days):
    close = df['Close']
    r = diff(log(close))
    volatility = []
    for index in range(days, len(r)):
        range_r = r[index-days:days+index]
        r_mean = mean(range_r)
        diff_square = [(range_r[i]-r_mean)**2 for i in range(0,len(range_r))]
        std = sqrt(sum(diff_square)*(1.0/(len(range_r)-1)))
        volatility.append(std*sqrt(252)*100)
    return volatility

Does this function look right?

How many days should I use for historical volatility calculation in order to compare it to VIX? 30 or 21 (average trading days per month)?

This is the current plot I get when plotting VIX vs Historical volatility of 30 days.

enter image description here

Is there any tool/data provider where could I get the historical volatility of SPX so I could compare it with the results I have got?

$\endgroup$
1
  • 1
    $\begingroup$ (1) I would recommend 21 trading days, (2) I would recommend r_mean = 0.0 instead of r_mean = mean(range_r) The use of a short term mean introduces unnecessary noise into the estimate of std deviation. (3) Visually your chart looks reasonable (historical vol has been declining while vix remains elevated) $\endgroup$ – noob2 Sep 27 '20 at 12:08
2
$\begingroup$

Echoing @noob2 's comments. Additionally, one of the things you might want to be aware of is there is a time to maturity difference between VIX and your calculation of historical volatility. While you are using a constant time frame (30 day) for your volatility calculation, VIX utilizes the near term options contracts for its calculation. As options have an expiration, there is a roll down effect as each day the options have one less day of time left, until the VIX calculation rolls over into the next near term contract. At this point, the time jumps by difference between the maturity of the two contracts. This may or may not make a difference for the intended purpose of your study.

A detailed explanation of the calculation can be found on the CBOE website, http://www.cboe.com/products/vix-index-volatility/vix-options-and-futures/vix-index/the-vix-index-calculation).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.