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)
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jared Broad
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!