Load the VIX as a separate series stamped with the time each value became known, join it to the traded instrument's bars "as of" that time, and trade the instrument, not the index. The common mistake is joining the VIX by date, which lets each day's trade see that day's VIX close before it exists.
What the VIX is
The Cboe Volatility Index is computed from S&P 500 option prices and reflects the market's expected volatility over the next 30 days. It cannot be bought directly. Strategies use it as a signal to time another instrument, such as an S&P 500 ETF or futures, or trade VIX futures and the products built on them, which behave quite differently from the index.
Common rules
- Level filter. Hold equities while the VIX is below a level such as 20, and step aside when it rises above a higher one such as 30. Two levels avoid trading back and forth around one.
- Spike reversal. Buy equities after the VIX jumps far above its recent average, betting that fear fades.
- Term structure. Compare the VIX with a longer-dated measure such as VIX3M; a VIX above it signals stress.
Getting the timing right
- Stamp each value when it was known. The VIX close is published after the stock market close. A daily file stamped with the date, joined to that day's bars, gives every bar of the day the evening's value.
- Use the traded instrument's prices for fills. The VIX only decides; fills, costs and results come from the instrument.
- Mind the history's start. The current VIX methodology dates from 2003; earlier values were back-calculated.
How Reamer Research handles it
Reamer Research attaches a non-price series to a ticker and shows each value only from the first bar at or after its time stamp, as exogenous data. This configured object reads it with d.exogenous:
import json
import reamer_research as rr
class VixTiming:
lookback = 1
def __init__(self, ticker='SPY', calm=20.0, stressed=30.0, qty=10):
self.ticker, self.calm, self.stressed, self.qty = ticker, calm, stressed, qty
def on_bar(self, d):
raw = d.exogenous(self.ticker)
if raw is None: # no VIX value known yet
return None
vix = json.loads(raw)['vix']
if d.position(self.ticker) == 0 and vix < self.calm:
return rr.buy_market(self.qty, ticker=self.ticker)
if d.position(self.ticker) > 0 and vix > self.stressed:
return rr.close_position(ticker=self.ticker)
# {time it became known: value}; VIX closes stamped at 21:15 UTC
vix = {'2024-03-01 21:15': {'vix': 13.1}, '2024-03-04 21:15': {'vix': 13.5}}
result = rr.backtest(VixTiming(), {'SPY': 'data/SPY.bin'}, exogenous={'SPY': vix})
exogenous= takes a dictionary of times and values per ticker, or a sidecar file built once with rr.write_exogenous or the kit's bin/reamer-exo-build. A value stamped after the close reaches the strategy on the next session's first bar, so the order it triggers fills after that. The same rule runs as a function on_bar(data) or a class as well. The VIX here is data attached to one ticker, so the run is a one-ticker run.
Limits to know
- VIX data is yours to bring. The kit includes fetchers for Alpaca and Databento bars; the VIX history comes from your own source.
- Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to check the join; years of history need a licence.
A $20 month includes the full kit, so you can test your own VIX rule on your own data and cancel if it does not fit.