DS Concepts DS Languages

Leverage Effect using VIX and Python: FA13

 

Leverage Effect using VIX and Python

Hi All! Today, in the part 13 of Financial Analytics series, we will be learning about an alternative method of identifying Leverage Effect using VIX and Python. If you’re new to this series, we suggest that you start from here.

What is VIX?

  • VIX is also called as CBOE Volatility Index.
  • It was created by Chicago Board Options Exchange, hence the name CBOE Volatility Index.
  • It is a metric that gives us an indication as to how the volatility of the market is expected to be in the coming 30 days.
  • Basically, it is a 30-day forward-looking volatility expectation of the market.
  • It is a good indicator of markets’ risk and how the sentiments of investors are currently.
  • It is a bi-product of price inputs of S&P 500 index options.
  • People also refer to it as “Fear Gauge” or “Fear Index”.

Leverage Effect using VIX and Python

Let’s implement this using Python. The stock ticker I’ve chosen in this case-study is MSFT (Microsoft Corporation). Let’s fetch VIX and MSFT Adjusted Price data using yfinance library of Python.

In [1]:
# Importing libraries
import pandas as pd
import yfinance as yf
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
In [2]:
# Downloading MSFT and VIX data from yfinance from 1st January 2010 to 31st March 2020
StockData = yf.download( ['MSFT', '^VIX'],
                        start = '2010-01-01',
                        end = '2020-03-31',
                        progress = False)
In [3]:
# Checking first five rows of the StockData
StockData.head()
Out[3]:
Adj Close Close High Low Open Volume
MSFT ^VIX MSFT ^VIX MSFT ^VIX MSFT ^VIX MSFT ^VIX MSFT ^VIX
Date
2009-12-31 23.925440 21.680000 30.480000 21.680000 30.990000 21.830000 30.480000 19.889999 30.980000 19.959999 31929700 0
2010-01-04 24.294369 20.040001 30.950001 20.040001 31.100000 21.680000 30.590000 20.030001 30.620001 21.680000 38409100 0
2010-01-05 24.302216 19.350000 30.959999 19.350000 31.100000 20.129999 30.639999 19.340000 30.850000 20.049999 49749600 0
2010-01-06 24.153070 19.160000 30.770000 19.160000 31.080000 19.680000 30.520000 18.770000 30.879999 19.590000 58182400 0
2010-01-07 23.901886 19.059999 30.450001 19.059999 30.700001 19.709999 30.190001 18.700001 30.629999 19.680000 50559700 0
In [4]:
# Choosing only Adj Close
StockData = StockData['Adj Close']
StockData.head()
Out[4]:
MSFT ^VIX
Date
2009-12-31 23.925440 21.680000
2010-01-04 24.294369 20.040001
2010-01-05 24.302216 19.350000
2010-01-06 24.153070 19.160000
2010-01-07 23.901886 19.059999
In [5]:
# Renaming the columns
StockData = StockData.rename(columns = {'MSFT': 'Adj Close', '^VIX': 'VIX'})
StockData.head()
Out[5]:
Adj Close VIX
Date
2009-12-31 23.925440 21.680000
2010-01-04 24.294369 20.040001
2010-01-05 24.302216 19.350000
2010-01-06 24.153070 19.160000
2010-01-07 23.901886 19.059999
In [6]:
# Calculating log returns and volatility returns

## Log returns calculation
StockData['Log Returns'] = np.log(StockData['Adj Close']/StockData['Adj Close'].shift(1))

## Volatility returns calculation
StockData['Volatility Returns'] = np.log(StockData['VIX']/StockData['VIX'].shift(1))

# Dropping null values
StockData = StockData.dropna()

StockData.head()
Out[6]:
Adj Close VIX Log Returns Volatility Returns
Date
2010-01-04 24.294369 20.040001 0.015302 -0.078660
2010-01-05 24.302216 19.350000 0.000323 -0.035038
2010-01-06 24.153070 19.160000 -0.006156 -0.009868
2010-01-07 23.901886 19.059999 -0.010454 -0.005233
2010-01-08 24.066734 18.129999 0.006873 -0.050024
In [7]:
# Obtaining correlation co-efficient between Log Returns and Volatility Returns
corrCoeff = StockData['Log Returns'].corr(StockData['Volatility Returns'])
corrCoeff
Out[7]:
-0.5758395592182721

We can see that negative correlation lies between Log Returns and Volatility Returns series. That is, if one increases, the other decreases.

In [8]:
# Plotting Log Returns and Volatility Returns on a scatter plot 
# Fitting a regression line on the plot
fig, ax = plt.subplots()
fig.set_size_inches(20, 15)
sns.regplot(x='Log Returns', y='Volatility Returns', data=StockData,
                 line_kws={'color': 'Gray'}, ax = ax)
ax.set(title=f'MSFT Log Returns vs. VIX ($\\rho$ = {corrCoeff:.2f})',
       ylabel='VIX log returns',
       xlabel='MSFT log returns')
Out[8]:
[Text(0, 0.5, 'VIX log returns'),
 Text(0.5, 0, 'MSFT log returns'),
 Text(0.5, 1.0, 'MSFT Log Returns vs. VIX ($\\rho$ = -0.58)')]

 

regplot

Result

We can see that in the above figure, we have negative slope between MSFT log returns and VIX log returns. Thus, as MSFT log returns increase, the Volatility log returns decrease. Thus, Leverage Effect is identified here.

So guys, with this, I conclude this tutorial. Please don’t forget to check out and subscribe to our YouTube channel.
Stay tuned!

 

 

One thought on “Leverage Effect using VIX and Python: FA13

Leave a Reply

Back To Top
%d bloggers like this: