QuantRocket logo

Disclaimer

Moonshot Backtest With VIX Filter

The trading strategy implementation in first_last.py includes a MIN_VIX parameter, which, if set, applies the VIX filter from the previous notebook:

if self.MIN_VIX:
    # Query VIX at 15:30 NY time (= close of 14:00:00 bar because VIX is Chicago time)
    vix = get_prices("vix-30min", 
                     fields="Close", 
                     start_date=signals.index.min(), 
                     end_date=signals.index.max(), 
                     times="14:00:00")
    # extract VIX and squeeze single-column DataFrame to Series
    vix = vix.loc["Close"].xs("14:00:00", level="Time").squeeze()
    # reshape VIX like signals
    vix = signals.apply(lambda x: vix)
    signals = signals.where(vix >= self.MIN_VIX, 0)

Edit the parameter in the strategy file and re-run the backtest, or set it on-the-fly as shown below:

And view the performance:


Back to Introduction