Back

A simple VIX Strategy

A simple, yet untradable (unstable), VIX Strategy using two ETFs.

It has a simple binary (all or nothing) allocation:

1. long vol (buy VXX), 

2. short vol (buy XIV),

3. none.

Signal is just the standard RSI but used as a momentum (rather than a contrarian) indicator. Levels are also those standard to indicate overbought or oversold securities (i.e. 85, 70, 30, 15).

Strategy is, however, a pie in the sky... a simple daily VIX/VXV ratio signal still more stable/reliable.

Update Backtest








0

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.


I couldn't see you have used any VIX data directly. You use its derivate - futures.

0

In the above strategy, as mentioned, I used the RSI on the ETF that sell the first 3 VIX futures, aptly named 'XIV'. The signal based on hourly data, whilst trading is potentially every 2h. 

I'll post the other version using the the VIX and VXV indices later. Signal and trading frequency will be daily.  

0

Nice! I like digging on the Quantopian forums for various VIX strategies and I've translated a couple I'll consider putting up here. Not all of them work all the time, but maybe one could add the signals of a bunch of them.

My one concern with VIX strategies at the moment is the ever growing popularity of shorting vol and what will happen when another 2008 like disaster arrives. I wrote a new strategy in November last year that would have returned me 150% but I haven't dared trading it (when I did, of course North Korea fired a missile over Japan so I immediately got the stoploss logic tested).

2

Petter, I share your worry: most VIX strategies on Quantopian, unfortunately, won't wistand another 2008 - they tend to sell vol when the VIX is just above 20-25 forgetting that the VIX went well over 90 during 2008... clearly just calibrated on the recent 5-7y benign environment, besides too many parameters (i.e. overfitted). True, in the last few years, simply selling vol (e.g. being long XIV) was a great strategy - but, as you rightly mentioned, the point is to avoid disaster when it strikes (and it will). 

In a nutshell, we need to be mostly short vol - around 8-9 times out of 10 - whilst being out of the market (or long vol) very few times. One risk to avoid is being whipsawed (getting in and out of a position without catching the trend).

The attached code is a simplified strategy - which we may backtest all the way back to, and before, 2008 (using the index underlying the VXX, freely available from S&P DJ website) : it goes short volatility (i.e. long XIV) if the VIX curve is in contago (VIX/VXV < 0.95), and long vol (i.e. long VXX) if curve in backwardation. In addition, it can withstand whipsaw by using a median to filter 1 or 2 day spikes. 

Combined with a momentum strategy, like the earlier one above (which cannot be backtested), may lead to a good strategy.  

0


Hi Alex,

1.

Thanks for the sample code, especially your code for getting the VIX datas. It's complex!

I read a post here "

https://www.quantconnect.com/forum/discussion/2201/vix

" and find there is a much more simple way to get the CBOE datas. But it is in C#. I've asked if the QC has a Python version. But till now no answer.

2.

To what you discuss about the year of 2008. Yes you all are right. Most of the VIX strategies use the XIV. But the inception of XIV is Nov 29, 2010. 

0

Hi Alex,

I try to get the VIX data not from the OnData() as what you do but from a schedule function (see attached code) but fails. Maybe you have an idea? (take out the comment on line 62, 63)

Thanks!

0


I've figured out. 

1

I am very new to this technology.

So I am trying to get VIX value from Quandl. I did the following in the   Initialize function. How can I get the value , (Close value) in OnData slice part ?  Please help out . Thank you

self.quandlCode = "CHRIS/CBOE_VX1"
 self.AddData[QuandlFuture](self.quandlCode, Resolution.Daily)

0

Greetings, interesting stuff. I'm a Quantopian migrant, and a fan of XIV strategies (I coded XIV-Shotgun, and Ballistic-XIV-VXX over on Quantopian). I'm working on porting those algos over to QC, among other things. 

@Alex: Why do you call the algo in your original post a 'pie in the sky'? Is your second algo an example of a 'simple daily VIX/VXV ratio signal' ? Lastly, why do you say that combining the vix/vxv with a momentum strategy cannot be backtested?

@Peter: I see you're trading XIV-Sniper (I saw your broadcast). I've almost finished coding it too here on QC. I was live trading this on Quantopian before they shut down. For small accounts ($1k - $10k), it's a great algo. 

0

Quickly - it is Saturday and I shouldn't be in front of a computer ;-) 

@ Thomas
I used PythonData (for custom data) to get the data straight from the original source (i.e. CBOE).
You can probably use Quandl and get it with less code (1-2 lines vs. 10 or more of mine) - I just prefer the more general/flexible way and, besides, it is more explicit (less error prone) since the close level columns for VIX and VXV are, respectively, 'Close VIX' and just 'Close'. Go figure why,
Glad it is helpful, but it is all thanks to the great examples of @Alexandre Catarino (from QC staff).

It is true that the XIV started traded only in late 2010. But you can easily re-construct (using pandas or even Excel)
VXX and XIV back to 1990 by using their underlying indices.
For example, for the XIV: 
i. go to S&PDJ website: http://us.spindices.com/indices/strategy/sp-500-vix-short-term-futures-inverse-daily-index-tr
ii. download last 10y (late 2007 to now) - if you've got Bloomberg then you can get 1-2 years more for the inverse and likely more for the one underlying the VXX.
iii. subtract the fees/TER of the ETF, if you really want (it won't make much of a difference).

@ Mohamed:
By reconstructing XIV or VXX (as mentioned above), you can now back-test strategies with at most daily trades during 2008:
1. you can definetely get a good idea regarding drawdown/returns for the second strategy I posted above (VIX strategy based on VIX/VXV ratio), BUT
2. wrt the first strategy (based on hourly data) you have to buy VX fut granular data which it makes costly, laborious and - above all - still imprecise (to the point to make it unrealiable for such small timeframe). Not worthy.

I said that the 1st (RIS-based) strategy is a pie in the sky (i.e. unreliable) because it is too dependent on the RSI period: if =6 (like the posted one or some on Quantopian's) performance is great except for the last 1-1.5y, the standard rsi period of 14 instead works marvellously well in the last couple of years but poorly in the 2012-2015 period. What's worse is that the choices in the middle (self._period = 8 to 12) are even more random and non-intuitive. 
In other words, even if there is just a single parameter to optimise there is not a stable interval for the optimum - say great for =8 yet still good for 6 or  10 and so on. On top of that, I have no idea how this strategy could have performed during 2008. Trading this on its own is a too big leap of faith for me.

But I think that not all is lost: if you combine the two simple strategies above (you may want to get a longer RSI period and a shorter median) then you get a much more stable/robust strategy with Sharpe ratios of 1.8-2 and drawdown < 20%. Pretty decent for such an undiversified strategy.
 
If we can get 1 more unrelated strategies to combine, well... A Sharpe of 1.8-2. is achievable with a momentum (RSI) and a contango/backwardation ideas (the two strat above). We need a mean-reverting one, which is more tricky.  
What I would avoid is too many parameters or convoluted strategies with no economic background. I'd rather combine two-three simple strategies and trade the net order. 

Alex

PS: got a question too: does anyone know how to get the live VIX from Interactive Brokers when deploying algos via QC?

3

Forgot to say that by combining the two strategies you get a more stable performance that is much less dependent on the choice of parameters. The point is to combine enough of them to make params of the single almost irrelevant.

0

Alex, thank you for your feedback. I will try to combine the strategies, looks interesting!

0

@Lu Chen:

If you just want to get the VIX values, you can simply use Alex's code:

        vix_open = data["VIX"].Open
        self.Debug("VIX_Data:%s" %ratio_d)

1

@Alex,

I am not sure if there is a "prediction bias" in your algo, excatly to say in your VIX values.

Here I cloned your algo and remove a lot of the codes and just to get and print/Log the VIX_Open. If you run the backtest you can see the VIX_Open is excat the same as from the CBOE csv file as follow:

...

2017-10-03 00:00:00 :VIX_Open: 9.30000

2017-10-04 00:00:00 :VIX_Open: 9.53000

2017-10-05 00:00:00 :VIX_Open: 9.48000

2017-10-06 00:00:00 :VIX_Open: 9.23000

But if do the same in QuantOpian, you get the following:

...

2017-10-03 00:00:00 :VIX_Open: 9.59000

2017-10-04 00:00:00 :VIX_Open: 9.30000

2017-10-05 00:00:00 :VIX_Open: 9.53000

2017-10-06 00:00:00 :VIX_Open: 9.48000

This means, the VIX values from you algo has "prediction bias". Am I right?

0


Hi Thomas,

Clever obsevation. 

I noticed that. That's why I wrote the following comment in the code:

ratio_d = data["VIX"].Open / data["VXV"].Open "# .Close will have look-ahead bias...'

Basically I am assuming that I am able to get the VIX or VXV Open on that day, which is in theory a fair assumptions, and then trade a split second after that. If, instead, I used the Close in my code then it would definetely be wrong since I would be trading on information available only much later in the day  -- try to change the .Open into .Close in 'ratio_d' and see the whopping difference a look-ahead bias makes!).

Quantopian - on the other end - to avoid any risk of look-ahead bias (particularly for Close), is delaying all prices by one day. Safer.

In practice, if we relay only on the CBOE .cvs file then we have to use the previous day Close in live trading (you can easily change the code to do that). This is, incidentally, the reason why I asked in the 'PS' above if anyone knew how to get the 'live' VIX from Interactive Brokers - unfortunately, it appears that live VIX prices are not possible because QC only broadcsts prices from IB and not indices too.

To be double sure just compare Quantopian using .Close (which is the previous day one) and QuantConnect same day Open. I expect the difference to be minimal.

0

Correct Thomas -- you need to adjust for the resolution of the data as the CSV's are daily and we default to minute resolution. Without specifying the width of the bars it assumes a minute/point value and the close values are available immediately vs being delayed 1 day.

self.AddData(CboeVix, "VIX", Resolution.Daily)

0

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 I have adjusted the resolution to daily as you suggested (adding 'Resolution.Daily' for both VIX and VXV in the second algo above). Backtesting is, of course, quicker now (bc OnData runs daily), but the VIX Open still do not seem to be delayed as per Thomas expectations / Quantopian. Am I missing something?

@ Thomas, do you get the new result?

0

@Alex,

Ok, I think I figured out the delay. One has to use the following code to get the VIX except using the Resolution.Daily:

self.Securities['VIX'].Close

Could you have a try?

0

But I notice no matter you use the .Close or .Open, the returned VIX is always the Close. This is somewhat interessting.

0

Complex questions but will try explain it -- 

Time is a continuous span; but time bars like this have a start and end time - denoted in LEAN by Time and EndTime respectively. BaseData is default a continuous flow of time. This means the time you're setting is the time the data will appear in LEAN.

In your case above the time is set as midnight on the date with 4 values on the data - giving you the forward looking bias. Using the current code you really you should set EndTime to be index.EndTime = data.Time.AddDays(1) -- this would reflect the fact its time +1 period; or use data timestamped according to when the data was released / made public.

Perhaps a better way would be inherit from TradeBar class which is designed to be used with periods. In this case you would set OHLC like you do here; and bar.Time = data.Time; but you must also set the bar period: bar.Period = TimeSpan.FromDays(1).

Finally another importing cause for look forward bias in backtesting is misunderstanding of timezones. Make sure your "daily" bars are in the same timezone as your algorithm. If they are UTC days you can have a 4 hour look into the future. This doesn't matter much for US market data like this but custom sources like BTC/Crypto are often internationally focused and you need to set their timezones appropriately.

@Thomas - the value of the VIX bar is whatever you set to index.Value

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed