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








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.


Here's the algo I'm broadcasting adapted from QT (link/attribution in code). I noticed it's trying to issue some too large orders at some points I don't really care to spend time figuring out why, and the code could use a cleanup. Also, if someone wanted to use this, carefully investigating slippage (particularly ensuring TLT and XIV have different values) is a necessity and possibly optimizing the order execution.

1


(Also, a disclaimer, with XIV it's good to familiarize with the the fact you could lose 100% of your investment overnight in some extreme circumstance... you're making money taking on tail risk.)

0

@Petter,

>>you could lose 100% of your investment overnight in some extreme circumstance...

Yes. But I think maybe this is a little bit exaggerated? :-)

As Alex said: But you can easily re-construct (using pandas or even Excel) VXX and XIV back to 1990 by using their underlying indices...

If it's really could be re-constructed, one knows how to do the risk-management in his algo, right? And I think this is at least much 'saver' than doing PUT or SHORT.

0

Sure, just pointing out so nobody puts 100% of their capital into something like this. :-)

As for assuming the future will be same as the past, I don't recommend it in this case. Shorting volatility is a lot more popular now than in the past, which may lead to bigger kickbacks.

0

Good reading from time on time regarding the subject of risks in volatility, if somewhat gloomy.

0

Has anyone adapted any of the QT algorithms in below and successfully backtested in QC?

 

https://www.quantopian.com/posts/vix-trading-algorithm-return-150-percent-a-year-over-past-5-years-but-has-50-percent-drawdown-from-2015-meltdown
0

I messed around with a ML version of something similar on QT but concluded the 'amazing' results in backtests were classical overfitting or out of date market inefficiencies. My ML version wanted to be long XIV mostly (go figure). These guys seem to arrive at something similar with better analysis than mine. That's not to say there isn't some signal in that data, but a few decision tree like rules or some linear classifier/regressor isn't going to cut it.

0

Much of the gains from strategies in the previous link are via UVXY, has anyone implemented a volatility strategy in QC with UVXY?

0

With UVXY? You will short it or long it?

0

Caveat: Shorting UVXY is easy in the same way that being long XIV is "easy" - algos that do either on average will likely work for some time for that reason.

Also, the backtest will not take into account short interest paid and by default IB's leverage limitation (IIRC now effectively cancelling out leverage you get versus XIV) isn't represented.

0

Be careful about shorting something this volatile.  I mentioned this in another post, but: you can not only lose your shirt but also your house by shorting something that has the potential to climb instantly for no reason.  XIV has some protections in place to prevent it from climbing too rapidly (if one decides to thumb through the prospectus) but who knows the circumstances in which that would happen.

0

I would like to implement a similar strategy as Alex did above, but selling call spreads or buying put options on UVXY, to limit risk. However if I simply add 

option = self.AddOption("UVXY")

in Initialize to be able to trade options, I get the following error once the backtest hits March 20, 2012:

 

Runtime Error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for `System.Collections.Generic.KeyValuePair<QuantConnect.Symbol,QuantConnect.Data.BaseData>.KeyValuePair(QuantConnect.Symbol, QuantConnect.Data.BaseData)' has some invalid arguments

0

turboDZyl -- Please avoid necro-posting or thread hijacking. If you have an issue with your specific algorithm post a new discussion and attach the backtest. To reference the original thread post a link to it in your new discussion.

Related image

1

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.


Given Quantopian's abandonment of personal automated trading I'm not surprised the refugees come over here. Especially since Python is now possible. What I would really need to trade VIX algorithmically is an automatically generated front month concatenated futures contract also showing spot VIX so as to be able to compute my favoured measure of contango/backwardation.

Although presumably one could just keep taking in the individual front month contract.

The big worry on XIV of course is a termination event. While VXX may seem unlikley to terminate (although I have not checked the prospectus) it is designed to go bust anyway and will just have another price consolidation (reverse split). I guess the bigger worry however is that the managers may not be unable to purchase futures contracts (to rebalance) during a spike in vol since the vast short brigade will be competing to gain cover and reverse their shorts.

Nonetheless a safer route to long XIV may just be deep ITM VXX puts.

I much look forward to working on Quantconnect now it has integrated Python.

I must say that my VIX adventure so far is a simple monthly rebalance between an inverse VIX fund such as XIV and a geared bond fund based on simple inverse volatility. Maximum drawdown on back testing is vastly reduced but of course the low correlation may not hold and XIV may suffer a liquidation event.

However, provided a liquidation event only occurs once in a blue moon, the method should enable one to survive. And you need to be ready with an alternative way to short VIX. Shorting VIX options seems hopeless. I can find little joy there although theoretically of course the options are based on futures. Nonetheless trading monthly VIX puts does not produce anywhere like the performance of a monthly short of the futures front month.

Perhaps I have made an error somewhere.

Anyway, I'm a Quantopian refugee although I have to say I had not been active there for about a year.  I suggested they "offer bread today not jam tomorrow" and they seem to have heeded me as regards their competition. Nonetheless Quantopian is of little interest now that you can no longer trade using their framework. Especially since few have interest in the model they want to trade – a very low beta long short US equity approach.

0

No, you can not go back to 1990 by using indices. 

While the VIX index itself goes back as far as 1990, futures on the VIX only commenced in 2004 and options in 2006. Without futures there is no contango/backwardation and no XIV or VXX.

The S&P Index on which XIV is basd only goes back 10 years. What you need to do it to use the actual futures contracts to simulate XIV and VXX and you need to interpolate the front ans second month as per the index.  The first chart below is the drawdown chart obtained by maintaining a 1x short position in the VIX front month futures contract since 2004. No interpolation applied.  The second chart is the drawdown of the S&P 500 VIX Short Term Futures Inverse Daily Index TR since 2007. As you can see the drawdown for XIV in the last crash would have been close to 90%. Not pretty!

0

My implementation for C#.

The main problem that I see with Pairs Trading is that it's not clear when spread between correlated assets is enough to open positions. Prices of assets are often different and to compare them we need to normalize them, but usually after normalization we cannot compare actual prices because they are measured in abstract units, e.g. logarithms. Will it be enough to compensate commision if divergence is equal to 0.35 or 0.25? In my strategy I tried to use difference between fast and slow MAs, but it's also an approximation, and thus strategy has losses, because when MAs converge it doesn't mean that actual prices converged too.

Idea with RSI proposed by author also looks like an aproximation and also gives loses, maybe someone has a better idea for indicator that can display divergence between correlated assets?

1


@Anthony FJ Garner: you're right, I was imprecise - thanks for clarifying here.

 

Unfortunately, I've just learnt that European retail investors cannot puchase more XIV shares from 1st Jan 2018. 

Long explanation: under the coming MIFID 2, the XIV is classified as a PRIIP ("Packaged Retails Investment and Insurance Product") and its issuer must publish a Key Information Document (KID) before private investors can make further purchases (we are, of course, allowed to keep or sell the shares we already own). The issuer of the XIV (Credit Suisse) apparently does not intend to publish a KID and this is the real issue.

I guess this is a good execuse (new regulations) for CS to constraint or limit some recent buying pressure on the ETN.

0

Alex

How about SVXY? I usually register myself as a professional investor - I had better check I did so with IB. I wonder how that affects dealing in the derivatives. Not that there are any in XIVs case but of couse you could always buy VXX puts.

Regulators in general are not the brightes or most constructive of people.

0

Anthony. 

I don't know about SVXY. I've only received a communication from my pension provider regarding XIV (since in my portfolio), but nothing yet from IB. Perhaps you are right and regulations does not apply to me as professional. Worst case my solution is shorting VX futures - less granular and more risky (since being long XIV had at least the the beaty to have a bound loss, not a luxury you have with short futures). 

Definetely something worth checking with IB.

  

0

Totally agree re shorting the futures - madness. If XIV becomes impossible (and also SVXY) I shall buy VXX puts. If those get banned well....um...its pointless using VIX options. Despite the fact they are linked to the relevant futures contract extracting the contango seems impossible from my back testing. I must triple check my back tester but....The returns using VIX options suck compared to using futures or the futures related ETFs.

Despite my scepticism I have also begun disaster insurance for my short VIX products using LEAPS going out two years, deep OTM. At least its some protection against a complete bust. Its a good strategy but it will be interesting to live throgh the coming shitstorm and survive....

0

Another idea for VIX strategy, low DD, high performance.. 

https://collective2.com/details/106901765
1

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