Introduction

The VIX Index is the weighted average of the implied volatilities computed from a total of eight near-the-money, nearby and second nearby American Option contracts on the underlying S&P100 index. The Index is calculated on an intraday basis by the CBOE. The extreme levels of the VIX Index are a strong indicator of Equity Index returns. One could anticipate that the higher the fear in the markets, indicated by the VIX Index, the higher the subsequent returns on the broad Equity Index. In this algorithm, we will explore if the VIX Index is the forward-looking indicator of future stock Index returns.

Method

To assess if the implied volatility turns out to be relevant trading signals for long and short positions, we must first define what we mean by large or small implied volatility levels. At any given time, we create 20 equally spaced percentiles for the history close price of VIX in the last two years. By 20 equally spaced percentiles, it means the 5%, 10%, . . . , 95% percentiles. Then the current VIX index price is compared to these percentiles and ranked accordingly.

We import the daily VIX data from the VIX Daily Price dataset. The correspondent stock Index is S&P100 Index. We use the iShares S&P 100 ETF OEF In the first step, we create a rolling window to save the historical VIX price. A history request is used to initialize the rolling window.

def Initialize(self):
    self.SetStartDate(2006, 1, 1)  
    self.SetEndDate(2018, 8, 1)    
    self.SetCash(100000)          
    self.AddEquity("OEF", Resolution.Daily)
    self.vix = self.AddData(CBOE, "VIX", Resolution.Daily).Symbol
    self.window = RollingWindow[float](252*2)
    hist = self.History([self.vix], 1000, Resolution.Daily)
    for close in hist.loc[self.vix]['close']:
        self.window.Add(close)

The rolling past 2-year history of the VIX Index is then split to create 20 equally spaced percentiles. The algorithm goes long on the Equity Index if the VIX Index on the current day is higher than on any other day during the rolling 2-year window or if the VIX Index value is in the highest 2 percentile boxes. If the VIX Index on the current day is lower than on any other day during the rolling 2-year window or if the VIX Index value is in the lowest two percentile boxes. The algorithm goes short on the Equity Index.

def OnData(self, data):
    if not data.ContainsKey(self.vix): return
    self.window.Add(self.Securities[self.vix].Price)
    if not self.window.IsReady: return
    history_close = [i for i in self.window]

    if self.Securities[self.vix].Price > np.percentile(history_close, 90):
        self.SetHoldings("OEF", 1)
    elif self.Securities[self.vix].Price < np.percentile(history_close, 10):
        self.SetHoldings("OEF", -1)


Reference

  1. Quantpedia Premium - VIX Predicts Stock Index Returns

Author