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.set_start_date(2006, 1, 1)  
    self.set_end_date(2018, 8, 1)    
    self.set_cash(100000)          
    self.add_equity("OEF", Resolution.DAILY)
    self.vix = self.add_data(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 on_data(self, data):
    if not data.contains_key(self.vix): return
    self.window.add(self.securities[self.vix].price)
    if not self.window.is_ready: return
    history_close = [i for i in self.window]

    if self.securities[self.vix].price > np.percentile(history_close, 90):
        self.set_holdings("OEF", 1)
    elif self.securities[self.vix].price < np.percentile(history_close, 10):
        self.set_holdings("OEF", -1)


Reference

  1. Quantpedia Premium - VIX Predicts Stock Index Returns