Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
"VXX Short Master v1.0" (REQUESTING HELP/COLLAB)

Hi all,

I created a simple model using Pine Script and the Strategy Tester on TradingView to short the VIX by short selling its ETN form, VXX, in order to take advantage of the contango and time decay effects. I call it "VXX Short Master v1.0" because it is still very basic right now but I do plan on adding a lot more parameters and risk management methods to improve later versions. However, I tried to replicate the model as an algorithm here on Quantopian using Python and I'm having trouble getting the results to match. Since TradingView's Strategy Tester is still in beta, I wouldn't be surprised if there turns out to be errors in its calculations. I don't have a programming background so I would really appreciate any help at all from the Quantopian community :-)

Here's a link to my model on TradingView: https://www.tradingview.com/chart/0qdR7LdX/

The model operates on a daily interval. It only uses 1 parameter, the William's VIX Fix (WVF) indicator, to trigger short/cover signals. You can read more about the WVF here: https://www.ireallytrade.com/newsletters/VIXFix.pdf

TRADING RULES:
WVF(28) cross> 14 = SHORT
WVF(28) crosss< 14 = COVER

There can only be 1 open position at any time and every trade uses 100% of the account's available balance. Initial cash is $1,000,000. Slippage and commissions are currently not factored into the model on TradingView.

As you can see, from March 2009 until now, my Quantopian version's gross return is only 1,800% while my TradingView version shows a gross return of almost 3,200%! This discrepancy is too large to ignore so it'd be really interesting to get to the bottom of this. Either my codes on here are wrong, TradingView is wrong, or Quantopian is wrong (which I highly doubt).

Please note that VXX only started trading in 2009 so theoretically speaking, shorting it from inception until now in 1 trade would have only made you 99.99% in gross return.

Thanks ahead!
~Kory

55 responses

Great a new volatility strategy:

I have two questions:
so you are creating a synthetic vix of the etf that represents the vix. So a vix of the vix, the volatility of the volatilty. Can you tell me what the theory is behind that. Should we not involve the original SPY on which' volatility the vix is modelled?

Second question is: using a fixed number is always a bit dangerous, better use a zscore or something that normalises the anomalies.

Hi Pete,

1) Precisely. I am using the derivative (WVF) of a derivative (VXX) of a derivative (VIX) to generate trade signals. We know that the VIX is good for measuring volatility and the index itself is range-bound, unlike its ETF cousin VXX which will decay toward 0 in the long run. Since it is range-bound, similar to the RSI indicator, the VIX could arguably be used as a momentum oscillator to trigger trade signals because we know that VIX going over a certain threshold means that there is higher volatility in the market (e.g., VIX > 15 = buy VXX and VIX < 15 = sell VXX). The problem is the VIX index isn't a very reliable momentum oscillator (or at least I just haven't figured out how to effectively use it as one).

But what about inverse VIX?

As far as I know, there isn't any official inverse VIX index that is range-bound. There's XIV, the inverse VIX ETF, but no inverse VIX index. And so, I decided to synthesize one by applying the 28-day WVF formula onto VXX. The end product is what I use as an oscillator to trigger trade signals to short VXX. As you can see, the WVF of VXX looks very similar to a momentum oscillator. Technically speaking, this should be considered a momentum-based volatility strategy. Since everything here is ultimately derived from the original VIX which is modeled on the S&P 500 index options' implied volatility, we don't need to involve SPY because it's theoretically already built-in.

Here are some visualizations for context:
- http://imgur.com/Bdx9pgw
- http://imgur.com/tmkzUE1

2) Yes I am aware that using a fixed value as the threshold to trigger trades can be dangerous during abnormal periods. I am working on other versions that use moving averages and std. deviation bands as the trade trigger instead of a fixed value.

As a volatility trader I can give you a few tips:

  • you are shorting VXX and holding overnight. This is REALLY dangerous - not only will a black swan even completely wipe you out, it could also cause you to owe more (a lot more!) than you have in your account. You might want to consider switching to long XIV instead of short VXX (even though its not as profitable).
  • you need to reduce your beta - it is way too high right now. A recession will probably wipe you out.
  • you need to change your algo to run in minute mode to make it more accurate.

Hi Mohammad,

1) This algorithm is more of a proof of concept. In my v2.0 of this algo, I do have it go long XIV instead of short VXX to prevent a Black Swan blow up, so worst case scenario is I will only lose my entire account but I won't owe my broker money. I also incorporated a trailing stop loss at -10%. Please see the backtest below (Note: XIV only started trading in December 2010 so this backtest's time period is shorter).

2) My v2.0 below has a lower beta of 0.75. I am still working on reducing it further by adding additional tactical overlays.

3) I am currently working on converting the algorithm to minutely mode. However, I still want the algorithm to operate only on a daily chart so what I'm trying to do is code the algorithm to only take price data input at the second to last minute of each trading session and based on the output, execute the trade at the last minute of the trading session. But since I'm not a programmer, I'm having trouble doing so (please help if you can! Thanks).

Version 2.0

I attempted to get your algo working in minute mode, sticking to a leverage of 1.0, cancelling orders EOD etc, and starting the backtest on a less favorable date. Just for another perspective.

You're so awesome Simon, thanks! I've been trying to figure out what you just did for a whole week! Can't wait until I get better at Python.

I realized now that my version is not the same algo, your buy/sell is a sort of ratchet, so that if the position is stopped out, it doesn't re-enter until it re-crosses from below. I'll update.

Here's another approach to try and replicate the ratchet without using additional state in context (which I find pretty error-prone). I haven't confirmed that this strategy is still doing what you want though.

Note also that this one has a minutely intraday stop, which will change things of course.

Simon,

I noticed that the algo trades at the open of the day based on the WVF value at the close of that same day. Is there look-ahead bias or am I wrong?

This is an interesting strategy, Kory. Remember that shorting VXX comes with borrowing fees, though if your strategy works as well as it might, those fees will be negligible. And if it works using XIV, even better. I'm curious to see what happens with leveraged VIX etfs. Thanks for sharing.

Taylor,

You're welcomed! I'm working on another one that's even better and it also trades VIX ETFs. Will post in a few days.

It doesn't have access to the WVF value of the close of the day; as long as you are not using fetch_csv, and assuming there are no bugs, you cannot create an algo with lookahead bias in Quantopian. It's a plus.

In fact, in the morning, the "1d" "close" price is the close of the day up to that minute only. Since that's probably not what we want, I do the [:-1] to strip off that stub day data, and we are in fact using only the final close of the previous day.

Simon.

I see. Thanks for the explanation. Also, I noticed that the algo is still holding positions overnight even though you coded it to cancel all positions by EOD.

It's not cancelling positions, it's just cancelling orders.

Hello Kory/Simon,
Excellent work. I am very interested in the work being done here as I have been doing some similar work on UVXY and SVXY for about 2 months now. Thus far my best results have been with simple moving averages and crossovers. But, my returns are being eaten up by trading too often. It looks like you have a better balance than I do.
I am currently trying to identify the mechanics behind the large difference of returns between your algo and Simon's. In the process I noticed that your second algo double sells on some occasions when the elif WVF <= 14 is activated at the same time as the stop loss. I have attached a working backtest where a simple fix is implemented by adding and thus resetting the "context.stop_price = 0" in the elif command when XIV is liquidated. This has the effect of stopping your algo from going short XIV, but also reduces returns.
I added a line in the WVF at 14 so it is easier to visualize where the crossovers occur at.
I would be curious to hear suggestions from others on how VXX could also be utilized; whether that is simply going long when WVF is below 14 or otherwise (I think some work with slopes might work here). When your algo was unintentionally shorting XIV a similar impact as going long VXX was had (elevating your returns), and therefore I believe some added return might be found by rotating between XIV and VXX.
I also noticed that Simon's second algo fails to capitalize on large swings in XIV/WVF in early 2016. Specifically, it misses the move upwards in late Feb despite the WVF crossing above 14. I still haven't found out why this happens, but I suspect this isn't the only occurrence and may be contributing to the lower returns of that algo. I hesitate to cherry pick dates for the purpose of increasing an algo's gains (it's a slippery slope) but I feel this is worth further examination.

Hi Darth Xanther,

Thank you for your improvement! I noticed the double selling too and actually had another member help me fix it with the same solution you posted. I'm working on a new hedged version where the algo will hold TLT when the WVF is below 14 and 80% XIV + 20% VXX when WVF is above 14. I think this should lower beta and also, theoretically, soften a Black Swan blow up. Will keep you updated.

It is interesting that you mentioned playing VIX ETFs using moving averages because that was also my first approach (probably everyone else's, too). But I knew that there had to be a better method than using basic moving averages. When I first worked on this algo, I actually used the EMA crossover strategy below as a benchmark that I needed to beat. I just tweaked it a little to make it more similar to the algo from your last post.

Short VXX (Long XIV) w/ EMA crossover using 5-day EMA and 10-day EMA on VXX.

Hi all,

This is the un-hedged version where the algo will hold 100% XIV when WVF crosses over 14 (with a -10% trailing stop) and 100% TLT when WVF crosses below 14. I still need to figure out how to make the algo hold 100% TLT when the trailing stop for XIV is hit without double buying TLT when WVF crosses below 14 right after the stop loss is hit.

And this is the hedged version where the algo will hold 80% XIV + 20% VXX when WVF crosses over 14 (with a -10% trailing stop for XIV, which will exit both XIV and VXX when hit) and 100% TLT when WVF crosses below 14. I still need to figure out how to make the algo hold 100% TLT when the trailing stop for XIV is hit without double buying TLT when WVF crosses below 14 right after the stop loss is hit.

@Kory: I found minute-mode working pretty strange comparing to daily mode.

Do you think it is resulted from slippage or other factor?

As you can only live trade when you did a minute test and the perf in Daily and Minute is always very different I would recommend not using Daily mode at all. just my two cents (BTW quantopian 2 has ditched Daily entirely)

Hi all,

So I've found out why the daily mode worked so well compared to the minutely mode. The trailing stop loss is executed incorrectly in daily mode; it's only accurately executed in minutely mode. Here's the final minutely version that rotates between 100% XIV and 100% TLT when the WVF oscillator crosses above/below 14 with no trailing stop loss (you can set the trailing stop loss yourself by editing line 10).

Here's the same algo as above but instead of holding 100% XIV when the WVF oscillator crosses over 14, it hedges by holding 80% XIV and 20% VXX to mitigate Black Swan risk. This version reduces performance but if a Black Swan event occurs and causes the 80% XIV portion to drop to $0, at least the 20% VXX portion might increase by 200-300% or more (just a guesstimate).

Hello,

Interesting strategy, thanks for sharing with us.

In the last iteration, the drawdown november-january is way too high unfortunately. But I see the trailing stop logic is not used right?
So far I prefer the hedged version of it.

I see that the WVF paper suggest 22 days lookback, why did you choose 28?
I guess it's a personal observation but did you try to optimize it on live / backtest (versus the fact to fall in overfitting) ?

How about the choice of trading $TLT when $VIX is low?

Hi Mat,

Originally, I created this strategy as something to "gamble" on. There's a very high potential for profit but also extremely high risk. You are trading the VIX, after all, so it'd be naive to expect little volatility or drawdown. In its current form, the algorithm is probably way too intense for the average investor. Personally, I designed this strategy as an alternative to going to Vegas. I figured it'd be a better idea to put just $3,000-5,000 into this thing and let it ride indefinitely versus losing all that money at the MGM Grand :-)

I chose 28 days because like 22 days or 14 days, 28 days is a popular look back period (see here: http://bit.ly/1XtuGWC). The author of that paper said on page 30 that he chose 22 days because that's the maximum number of trading days in a month.

I made the algorithm trade TLT when the WVF for VXX crosses below 14 because that indicates increasing momentum for VXX, ergo, decreasing momentum for SPY, ergo, potential momentum increase for TLT which is often treated as a "safe haven" asset.

Also, I think using SPY as a benchmark for this strategy is a bit unrealistic. A better benchmark is XIV in my opinion. Here's the hedged version vs XIV. As you can see, the algorithm's growth vs XIV is comparable but it is much less volatile and more consistent than XIV thanks to hedging with 20% VXX and "hiding out" in TLT when market volatility picks up.

Kory,
Did you get your original question answered?

As you can see, from March 2009 until now, my Quantopian version's gross return is only 1,800% while my TradingView version shows a gross return of almost 3,200%! This discrepancy is too large to ignore so it'd be really interesting to get to the bottom of this. Either my codes on here are wrong, TradingView is wrong, or Quantopian is wrong (which I highly doubt).

Hi Andrew,

When Quantopian updated to v2.0, I had to re-tweaked my codes here and everything worked fine after.

Based on Kory Hoang's the first version, I modified a little and try to use ZIV/TVIZ as the underlying asset. The different ratio of ZIV and TVIZ will allow us to get different Beta.

The major purpose of this version is to maintain a small beta and also get reasonable alpha. Therefore I involved a ratio, to control the short percent of volatility, and reduce big drawdown in crash time like 2015-08-24, but still it does not work well. Many anyone have good idea on this.

Meanwhile, somehow I found this version worked badly before 2012, do not know why.

Anyone has tried to introduce VIX futures term structure?

Another consideration is how to model VXX/XIV (if the position is VXX short or leveraged XIV long) for events like 09.11. Another source of risk is the ETF itself - the counterparty. I can easily imaging a situation when the issuer stops/pauses and the stock deviates from the NAV significantly. I suspect that an adequate hedge which removes risk of blow off will eat significant part of the profits.

@Blue Theoretically 911 won't stop the finance system from running. The 2015 meltdown will cause a significant loss for most of the volatility trading system
@ Kory Hoang Shorting VXX is dangerous. The 2015 crash might trigger a margin call if holding VXX Short position.
I am not sure if the issuer of VXX/XIV will take action to pause trading when a Black Swan event occurs

@Eric K
The issuer of VXX can fail if liquidity in the futures markets drops and it is impossible to roll the open positions.

Imaging that there are 1000 VXX shares and all are sold short. Imagine that there are 10 futures behind the ETF - 5 in the front month and 5 in the next month. Imagine that a day comes to roll but the market ask size is exactly 1 future. There is no counter-party willing to sell 5 VIX futures no matter what the price is. For example, the hedge funds are leveraged and do not have sufficient funds or lack ways to hedge the VIX futures by shorting of SPX because the market does not functions, shorts unavailable, etc. In this case VXX issuer has no other choice but to call the shares back. If anyone is long VXX this is fine - they get the current market price or some weighted average price. For unlucky shorters it means closing the position without a chance to recover the losses. If such an unlucky shorter hedged the VXX short by selling a deep in money put it makes the situation even worse because the short put position is now naked. The only hedge for VXX short is long call.

I did not run tests, but I suspect that VXX calls most of the time overestimate historical volatility. VXX calls pricing is very rich. And the reason for this is very simple - lot of players short stocks, SPX, VXX, UVXY and need these calls. The call writers can not give good estimation of kurtosis and must overestimate it with hope that if whatever "swan" lands the profits generated in better times will compensate the rare , but inevitable drawdown. I suspect that buyers of VXX calls have a model too which is backtested. Their goal is to reduce volatility by paying a small portion of the potential upside. They keep a small long exposure to VIX which improves Sharpe and limits worst case. For example, a short/long fund is contractually obliged to limit the drawdown. It would not surprise me if buying VXX calls is the cheapest way to hedge short positions against systematic risk.

Long reading, ah? I hope I have made it clear why when you short VIX you shall ask yourself a question why people who buy VIX calls (or VXX) are not necessary stupid.

@ Blue Maybe you r right. Hedging is too complicated for me . I suspect that buyers of VXX calls have a model too which is backtested . Options is too Complicated for me. If hedging is needed, why not just allocating more money as cash ? SHORTING VXX, LONG XIV, OR DOING A COMBINATION OF BOTH,which one is more favorable to you to prepare for balck swan event?

They are not stupid, but their reasoning can be wildly varied. Some have to place those trades to fine tune specific VAR. Those that 'have' to are the same as those market participants who are forced to rebalance massive portfolios to specific benchmarks because of quarterly weighting changes.

You have: "informed", "Uninformed" and "Informed and fully aware they're being scalped".

The nature of a Black Swan is that it's difficult to predict. If it was predictable, there wouldn't be an event.
'

If hedging is needed, why not just allocating more money as cash ? SHORTING VXX, LONG XIV, OR DOING A COMBINATION OF BOTH,which one is more favorable to you to prepare for black swan event?

That is what I would do. If you are short VXX as opposed long XIV you would have to set aside more cash to try to assess your greatest likely loss. While unpredictable in both theory and practice you might come up with some figure you are reasonably comfortable with. Assume that the vix might go as high as 120? 150? Whatever. And make sure you have the cash to cover the loss from your entry point up to the forecast high.

Far better for mere mortals to trade long XIV and let others assume the risk of unlimited liability. That way you know your maximum loss. So operate a rebalancing strategy. XIV may well go to zero so each week or month rebalance: 80 / 20 cash/ XIV, 50/50....whatever.

There is still a risk of ruin but it will have been lessened.

For reasons which are to me totally inexplicable some have maintained short VXX at a leverage of x1 is more profitable than long XIV. Looks like nonsense.

This forum is littered with systems and posts on trading volatility. Some good, some bad, some indifferent, some downright dumb. Whatever your rules are for entry and ext of longs or shorts of the vix (futures or options) or the vix etfs they will not work all the time. They will not protect you (or not always at any rate) from fast markets, gaps, closures, illiquidity, jihadists and general disaster. The only thing that will protect you is caution and common sense. Not betting the ranch, rebalancing in a sensible ratio, not accepting unlimited liability.

Agreed Anthony: I have developed more vola systems then my accounts could hold but in the end, the ones that give reasonable returns in a reliable fashion are systems that bet only 20-30% of the bank

For reasons which are to me totally inexplicable some have maintained short VXX at a leverage of x1 is more profitable than long XIV. Looks like nonsense.

It's not nonsense - it's actually true. Constantly having to trade the underlying options that make up these ETFs makes it expensive in terms of commissions. So you have a constant and slow drain on the ETFs.
If you are long XIV, you have a constant drain, and if you are short VXX you also have a constant drain.
Note that being LONG means the drain is to your disadvantage, but being SHORT it is actually to your advantage.

Therefore assuming all else is equal, maintaining a short VXX at a leverage of x1 should be more profitable than long XIV.

Even 5 minutes work in a spreadsheet should convince you this is complete nonsense. However I have no wish to appear rude or to press the point.

Mohammad Forouzani is absolutely right. The constant head wind in XIV makes it rather hard for longs to make money without some timing of the volatility.

Consider this on a "buy and hold" basis with no attempt at market timing. Buying XIV at inception and holding it to date requires one single transaction- a purchase. Which would return a CAGR of around 30%.

If you short vxx at -1x leverage you are going to have to carry out daily rebalancing with all the costs entailed. You are going to have to pay stock borrowing costs.

When you factor these in will you be able to compete with, equal or even exceed the simple buy and hold performance of XIV?

I doubt it.

Long XIV is not equivalent to short VXX because these ETNs represent compounded daily percent change in future volatility expectations, as opposed to volatility itself, the key word being "compounded".

For example, from 1/2/14 to 8/1/16, a long XIV position was net flat, whereas a short VXX position gave a 77% total return.

On the other hand, from 1/2/12 to 12/31/13, long XIV returned 400% while short VXX only returned 92%.

This seems mysterious, but it's just the basic math of daily compounding with and without large drawdowns. (You need a 100% return to recover from a 50% drawdown, etc.)

To fully understand the mechanics of this, deriving both ETN's price series from VX futures individual contract data (free at CBOE) is a good exercise.

If you do that exercise you find the returns are identical. I have done the exercise. Simulate a long position in futures for the period. Simulate a short position for the period. Short the simulated long position. Simple stuff if you do not include borrowing costs and slippage. And if you correctly calculate the roll.

And CSI data is much more helpful. You need a line up of contracts not a simple front month. That way you can assess the roll accurately.

I gave two examples of non-identical returns.

How are you calculating the shorts on vxx out of interest? How are you arranging the compounding of the short position? Are you redeeming the position and reinvesting each day? Or increasing the short? Or ....?

What costs of stock borrowing are you including?

I simply looked up the split-adjusted prices on the dates in question and compared them. The key point is that in one date range XIV did much better while in the other VXX did much better. This clearly illustrates that they're not mirror images of one another (which is also evident from how they're derived).

Yes but that was not my question. You are talking of shorting VXX. Did you account for the cost of maintaining the short and constantly adjusting the number of shares shorted? If you did not then you are comparing apples to oranges. XIV includes all such costs, a cursory glance at the VXX charts and assuming no cost of going short does not.

More to the point if you leave all such costs aside and merely look at futures prices and create a concatenated series you can derive something which looks very like XIV if you short and very like VXX if you go long. If you then simulate shorting the bogus equity curve of vxx you will find it equates to the simple bogus equity curve of XIV.

That is all I'm trying to say.

But again I would point out that the gap in performance between B&H of XIV and a simulation of shorting VXX will be greatly lessened once you take costs into account.

It is pointless to look at charts of the two. Shorting VXX will entail significant extra costs which is already accounted for in XIV. You did not take such costs into account.

Another factor which may account for some of the difference is that (I think!) one fund states it is based on total return, the other excess return. That can make quite a difference but I would need to check the prospectus again.

In the prospectuses for IVOP and XIV, there are some disconcerting discussions about termination events. In the case of IVOP, it occurs if its value drops below $10 and for XIV it is triggered if the daily percentage drop exceeds 80%.

Continue here:
https://sixfigureinvesting.com/2011/06/ivo-and-xiv-termination-events/

i don't think it is possible to short VXX because it is very hard to borrow... but you can create synthetic short using options.

@Jude, I had an algo in IB that shorted TVIX without any problem. I don´t think VXX would be an issue. However, if the trend accelerates, it may become a problem and short might be restricted.