Back to Community
Using VIX as an indicator

This is a simple script I'm trying to complete that notes a MA crossover based on the VIX. I'm having a time importing historical VIX data and getting it to work. I've searched the forum and tried to implement other examples, like from here, but to no avail. They are either not what I'm looking for or they are over my head. Is it possible to import and format it so that it could be used similarly like a data object? I'd love to be able to expand this concept and apply it to other indicators in a similar fashion. I have used AAPL as a placeholder for the VIX data in the backtest so it could finish. Any help or guidance is appreciated.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 581b46a875ce6e1315bf907c
There was a runtime error.
3 responses

Dave,
Looks like the post
https://www.quantopian.com/posts/stale-vix-pipeline-feed
shows two ways to get at VIX.

I modified that code slightly (changed target of "out[:] =" in CustomFactor to fix a bug.
Also used record() to plot custom data...click on two versions of VIX to see is_match series...slight mismatch only in two places.

Hopefully, this will help you.
alan

Clone Algorithm
3
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 581bc8d2ed1ed20f348565c8
There was a runtime error.

Alan,

Thanks for your code, it looks accurate. My problem is that I don't know how to use it. My python skills are on the novice side and I don't know how to take your code and obtain two moving averages, or any other indicator, for the VIX.

Dave,

You may create custom factor in pipeline or create two moving averages as in this sample.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 581c049ff3ffb90f2724a191
There was a runtime error.