Back to Community
XIV Shotgun - Trading Inverse VIX with WVF

This is my latest incarnation of the original algo that inspired Pete Bakker's "The SPY Who Loves WVF" post.

Apply on daily interval. Buy orders are executed at EOD. Sell orders are executed next day at open.

Securities for Trading:
- XIV (risk-on asset)
- IEF (risk-off asset)

Securities for Data:
- VXX (used for calculating indicators)

Indicators:
- WVF = 100-day William's VIX Fix of VXX's daily close price
- Smoothed WVF 1 = 10-day EMA of WVF
- Smoothed WVF 2 = 30-day EMA of WVF
- RSI = 3-day RSI of VXX's daily close price

Buy Rules (buy XIV, sell IEF):
- If WVF crosses over Smoothed WVF 1 and WVF < Smoothed WVF 2, or
- If WVF crosses over both Smoothed WVF 1 and Smoothed WVF 2, or
- If Smoothed WVF 1 crosses over Smoothed WVF 2

Sell Rules (Sell XIV, buy IEF):
- If WVF crosses under Smoothed WVF 2, or
- If RSI crosses over 50

Take Profit/Stop Loss (XIV only)
- TP = +25%
- SL = -3%

Please feel free to comment and improve this algo. For collaboration request, please email: [email protected] and [email protected]

Clone Algorithm
295
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: 594bf85817d98707e4012562
There was a runtime error.
28 responses

Tearsheet:

Loading notebook preview...
Notebook previews are currently unavailable.

Is it possible to test this algorithm prior to 2010? esp. around 2008. I keep getting NaN error....assuming no data?

I like it. Depending on what you are looking for, this is likely to be attractive to some.

Very cool. Would this algo actually be able to execute the orders right at market close? I suggest having it execute a few minutes before market close and also adding some code for retrying cancel orders just in case.

I noticed that XIV Shotgun purchased XIV at $85.66 at market close 2012-07-12. It has not sold yet. Pretty good cherry pick so far!

Very interesting algo!

  1. It would be very interesting to see, how the algo performed from 2004-2010 because the bullish market from 2011-2017 is ideal for the algo.
  2. Adding position sizing might give some additional safety - any off-market black swan event could wipe out the position, so using for example 33 % position size for the XIV and 100 % for the IEF might make the algo tradeable. Just an idea...

I've just noticed an error while running this. I have the issue of it ordering more XIV than allowed so I set it to only trade 90% then I was able to buy XIV when the next order came through, but still at only 90% it tried to order 1 more share of bonds than I am allowed to purchase. I ran a backtest and it showed that it should have ordered the right amount so I am confused about this issue. Would there be a way if rejected to then order 1 less share until purchase?

Here is a version that can use Robinhood margin. I think it may work for Interactive Brokers with margin. It is using, apparently, IB compatible commissions and slippage.

I think the TarPer function does a reasonable job keeping the orders small enough to not be rejected.

Clone Algorithm
36
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: 597faae6adf3894f1289d092
There was a runtime error.

Hi Kory,

I'm relatively new - still got a steep learning curve. General question: why do you use "Symbol(XIV)" in your code as opposed to using "sid(40516)" (as example - same for other symbols)?

Also @Charles Witt - learned a ton from you in other posts. Appreciate all the responses #QuantopianRockstar

The algorithm navigated this sell of brilliantly. Has anyone found a way to test against and '08 scenario?

Hi Tyler,

I use a different platform called MultiCharts to test and execute my strategies. Quantopian is only one of my research tools. However, I did test this strategy on MultiCharts using synthetic XIV and VXX data found here. You should read this to understand the caveats of using synthetic data. With that said, the strategy survived 2008 but it would have had a 50-60% drawdown.

@Geoff,

No reason. Just preference.

I have an even more aggressive version of this algo that wouldn't have survived 2008 without a bruise neither but it would have grown back a hell of a lot faster and stronger. Here it is:

Clone Algorithm
84
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: 598fd11f98747e50f360d9c8
There was a runtime error.

Is there a way to reduce drawdown by swing trading XIV, and holding a conservative/moderate portfolio in between? Or swing trade XIV as a percentage of your portfolio rather than going all-in?

I might try and get some quick and dirty code together later to see if that is effective.

@Delman Check this out, you might like it. 50% is allocated to a version of XIV Shotgun and the other 50% is allocated to a high yield bond momentum strategy.

Clone Algorithm
100
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: 598ffbcfd2551b50de3bd4e7
There was a runtime error.

@ Kory Hoang it would be very helpful to many users on here if you could backtest Charles Witt strategy back to the 08-09 crisis.

If you can help figure out how to load my own custom synthetic XIV & VXX data into Quantopian then I'll do it

Hey Kory, great algo.. I was just backtesting this yesterday and noticed quite a bit of downtime (ie where leverage is 0). Would it be possible to stick all available cash during these periods into the bond funds, and then sell when the time is right to buy XIV/VXX?

Edit: Also, I was getting slightly better returns with half-day set to True.

Happy to report the original algo has margin average of only $14.28 per day until near the end, almost nothing. (https://www.quantopian.com/posts/margin). Is there some reason one would not want to trade this with real money? (volatility or drawdown or or ?)

@Kern sure. With low trading frequency algos like these, I usually make them park in IEF or TLT when not activated.

@Seahawk I've been trading XIV Shotgun since March along with 6 other algos for our startup's charity fund (www.quantprophet.com/charity)

Congrats. With 7 algos, different start dates and possibly transferring profits out and/or adding to them occasionally it might take a team of accountants to arrive at a percentage in the real market but if there is any way to gage a backtest comparison that'd be cool.

I've had a few hiccups along the way. The biggest problems for me so far are human error and system failure, not actual problems with the strategies themselves. They have been performing very well as expected and slippages have been in line with my assumptions.

My broker's (Interactive Broker) portfolio analytics feature actually calculates my return net of deposits/withdrawals for me so I don't have to worry about that (but I don't often deposit/withdraw from our startup's charity fund anyway).

@Kory, I've played around with your version of the algorithm a little bit, and the only thing I cannot figure out is how to get the leverage at or equal to 1. Even turning down the XIV to Bond ratio, it jumps unexpectedly. Any thoughts?

Will Quantopian allow me to trade different strategies in the same account? Say I could set the cash to 50% and trade 2 strategies this way?

@Tyler, no. You'd have to combine them into one algorithm or open a second brokerage account.

@tyler. If you use IB you can create linked accounts and they consolidate in the master account. The linked account needs its own login. I have 6 Algos like that

I love this algorithm, so I've decided to improve it, simplify it, make it more efficient, and more profitable.
I may have a bug because it was just a quick adjustment, but some bugs could actually make it better :-)

Clone Algorithm
67
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: 5994d7646ded6550eb386255
There was a runtime error.

@Kon Rad, yes your monkeypick (haha) outperforms but you are missing a key component which is volatility, your sharpe is much lower with a DD @ 50%, so I think you are just proving that Kory algo is actually quite efficient... or did I miss your point?