Back to Community
Deployed two XIV/UVXY/TQQQ strategies for paper trading ... will make it live trading after a month

This is the first strategy

Clone Algorithm
282
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: 59343f3dcd45646984426912
There was a runtime error.
34 responses

And this is the second one.

Clone Algorithm
80
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: 59343e064f02b7697d1f0741
There was a runtime error.

If real trading is like the backtesting, wow! Is there overfitting or look ahead bias going on?

What is nokoUrl = 'http://52.15.233.150/noko.csv'? Specifically, is that data going to continue to be available? It looks similar to vixcentral.com page.

I am paper trading the first one, to see what it does.

    # Setting thresholds  
    threshold_vix_too_low = 10.76   # 0  
    threshold_xiv = -0.049          # 1  
    threshold_vxv_xiv = 0.87        # 2  
    threshold_uvxy = 0.049          # 3  
    threshold_macd = -0.55          # 3  
    threshold_vxv_uvxy = 1.3        # 4  
    threshold_vix_high = 19.9       # 5  
    threshold_vc_low = -0.148       # 6  
    threshold_vc_high = 0.046       # 8  
    threshold_vc_high_2 = -0.06     # 8  
    threshold_xiv_ratio = -0.053    # 10  
    threshold_uvxy_ratio = 0.08     # 11  

Good luck

Wonder how much someone would lose if he/she would stick with this algorithms vix_too_low hard coded threshold and VIX eventually goes to 6 or below?

Macro:

To save me the effort of comparing the two algos, what are the differences?

The strategies are excellent but I do share some of Luke's discomfort with the hard-coded thresholds, at least for absolute values such as vix_too_low. It would be great if we could instead use a ratio such as the current level compared to the moving average.

As we are not using Pipeline at all, we can completely switch to US Futures calendar and utilize Futures API provided by Q. VX Futures are available at Q since somewhere from July 2012. So, for backtesting since then, as well as current live trading, we can completely get rid of Futures fetcher from that strange noko.csv site. Hope, at some point we can replace VIX and VXV fetcher with some index API provided by Q.
Otherwise, cleaner code is attached.
Remember to run it on Futures Calendar.
Macro, let me know if attached algo would work for live trading. Hope it will.

Clone Algorithm
97
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: 5938d8f18a0dda6e4775715c
There was a runtime error.

@Igor Tebelev:
Does not work for live trading.
"Futures not allowed for live trading" error upon attempt to paper trade or broker trade.

Crazy! Would love to know: what particular reason Q has for that?

Wow this is amazing. I'm surprised you aren't keeping these strategies to yourself, but hey I'm not complaining, would love an update once you go live. Thanks for sharing.

I've been seeing a lot of vix strategies on here, is there a book anyone would suggest reading to learn about developing these vix strategies ? Thanks !

The blogosphere is more helpful then books. look for VIX or XIV posts on http://quantocracy.com/

BTW: Futures are not tradeable yet but will be soon according to Q. Soon is a stretcheable term though. For now we have to stick with fetcher, as soon as futures are allowed in the live environment (even only as a signal) we can change the code to work with that

^Thanks for the info Peter

It beat long XIV by a couple % points YTD (pretty much by being right 5/17). Add a stop loss, so you don't go from 70% to 48% or 108% to 90% in 2 days each.

Clone Algorithm
42
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: 593e15b5213f07698ff4f9b9
There was a runtime error.

Will this have issues with existing positions in an account?

The algorithms are down 8% and 11% over a month, while XIV is basically flat. The choppy up and down market is leading to a lot of trades, which is a killer. I am not deploying it with real money yet. Will wait for another month.

Thank you Macro Investor for sharing these algorithms; they've taught me a lot.

Are some of the last month's losses due to Case 0? Your fixed threshold (10.76) has worked for much of the history of the VIX but last month instead of dipping below the threshold the VIX lingered.

I added a condition to Case 0 which also requires that the VIX is below a ratio to its 200 SMA. The idea is to adjust to the VIX trend and over the last month it kept the algorithm out of Case 0 almost entirely, ending up more or less flat like XIV. This modification doesn't feel like it's overfitting or adding unneeded complication since it's letting the VIX price action set the level where we look for a spike up.

@Stephen, can you share the ratio or code you added?

@Peter

Here's Macro's algorithm from his first post in this thread with the Case 0 modification.

Clone Algorithm
66
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: 5964283dd161414ddc0973a6
There was a runtime error.

Treat the algo with caution.
Even with the version improved by Stephen, the return of this algo could be to volatile as in year 2013.
From 1/1/2013 to 1/1/2014, this algo returned 93%, while you could earn 107% if you just hold xiv with no transaction. And the DD was about 50%.
It must be frustrating during that year.

Clone Algorithm
10
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: 59653e21b48f374df01e5fa8
There was a runtime error.

I agree that it's a volatile algo (no pun). I don't think I'd trade it live except with leverage at 0.6 or lower which reduces the drawdown.

By the way, the mod I added only affects the last few months. It has no effect in 2013.

Stephen,
Thanks for pointing that out.
I didn't know the mod doesn't work in 2013. Why was that? Because it was already over 200 trading days after XIV release. Actually the 200 moving average was applied on VIX, which was available long time before.

The first condition in Case 0, as written by Macro Investor, requires that VIX is below 10.76. My mod added another VIX criterion to that. However, the first condition was never met in 2013 since VIX stayed above 10.76, and my mod wasn't a factor.

Thank you Macro and all for these great algos!!

I have been live trading at IB the one with the 200sma suggested by Stephen for a couple of weeks.

My concern is regarding the fixed threshold (10.76) of case 0. The VIX has never been this low, and at this levels maybe it's better to try the algo without the case 0 at all. I have backtested it without this case, and it still yields an awesome performance from 2012 till now. And of course last weeks perform much better without case 0. If VIX continues to be at this levels, holding UVXY will not be a good thing...

Case 0 was reached a few times in the past (in my backtests), and those cases worked well also without the case 0.

What do you think?

Ron,

Case 0 is not working well in current market. How are we sure the other cases would still work? They are not well tested in this low volatility environment.

How was your backtest performance in 2017? YTD of xiv is 100%.

Hi Zheng,

The performance YTD with case 0 is 95.7%, compared with the performance without case 0 which is 60.4%.

So far so good. The problem started when the VIX began to be at the levels of the last weeks (something that has never happened in the backtest).

Since I am live trading with IB (starting 7/13), I've been 11% up, but then I got in case 0, being now up 3.2%. Without the case 0, at this levels of VIX, I would have been 11.8% up.

I think there is a good chance for the VIX to keep going down in this environment. In this case, it will be better to remove case 0, or substitute it for another mean reversion indicator (not hardcoded).

Any suggestions?

Any suggestions?

Don't trade any algorithm with hardcoded buy/sell levels. It's only a matter of time until it blows up your account

^ Luke is right in general. You can keep modifying the thresholds to give better performance but really its the performance based on the period you are testing on. The market is dynamic so you need dynamic thresholds.

The only case that uses a fixed price level is case 0 which I attempted to make dynamic/adaptive by combining it with an r200MA threshold. All the other cases use ratios compared to fixed thresholds, making them somewhat adaptive since the ratio is the relationship of the prices rather than the prices themselves. I agree that in theory dynamic thresholds could be more robust but testing would be required to confirm that in practice.

When making changes, especially ones that add to the complexity of the algorithm, I always worry about unintentionally overfitting. Having said that I think it's certainly worthwhile to experiment with.

Dear Stephen,

Thank you for your answer an for your contributions to the algo.

My point is that the theory behind this algo is the contango and backwardation effect. There is no fundament (in my opinion) for a different behave when vix is “too low” or “too high”. This is a mean reversion assumption, that was fitted with the backtesting, setting the hardcoded thresholds. I agree that your r200MA makes it somewhat adapttive, but its still tied to the hardcoded vix too low. Adding to that, we do not have data to backtest the VIX at the actual levels, nor below 9 or even less.

There is also a negative effect of holding a leveraged ETF when it is volatile and goes up and down.

I feel more confortable taking away this improvement from the algo. Backtesting the algo without the vix too low or too high cases, also delivers high performance (with a big DD too).

I will try it live, without this limit cases, with a small amount of my trading capital (5% to 10%).

@Stephen,

I am shutting down the server for noko.csv today due to Quantopian's upcoming end of support for live trading. Use the futures calendar for VX1 and VX2 futures prices. Here is a code sample:

def initialize(context):  

    context.vx1 = continuous_future('VX', offset=0, roll='calendar', adjustment=None)  
    context.vx2 = continuous_future('VX', offset=1, roll='calendar', adjustment=None)  
    context.vx3 = continuous_future('VX', offset=2, roll='calendar', adjustment=None)

def ordering_logic(context, data):  
    # Calculating the contango ratio of the front and second month VIX Futures settlements  
    v1_close = data.history(  
        assets=context.vx1,  
        fields='price',  
        bar_count=360,  
        frequency='1m'  
        )[175]  
    v2_close = data.history(  
        assets=context.vx2,  
        fields='price',  
        bar_count=360,  
        frequency='1m'  
        )[175]  
    v3_close = data.history(  
        assets=context.vx3,  
        fields='price',  
        bar_count=360,  
        frequency='1m'  
        )[175]

    schedule_function(ordering_logic,  
                      date_rule=date_rules.every_day(),  
                      time_rule=time_rules.market_close(minutes=180),  
                      half_days=True,  
                      calendar=calendars.US_EQUITIES)

Thanks Honver. The code you provided is very helpful although I notice that the VX futures values returned from Quantopian don't quite match the data from vixcentral.com. For example the Quantopian data might have 12.6 while vixcentral.com has 12.625. I suspect it may have something to do with the difference between the futures and equities calendars?

The difference is due to what time the data is being sampled from. Vixcentral uses the last close, but the Quantopian data uses the bar that is specified from the combination of the frequency and [barsAgo] parameters.

I see... that makes sense.

My algo is based on daily data, using the previous day's VX futures close:

v1_close = data.history(  
    assets=context.vx1,  
    fields='close',  
    bar_count=2,  
    frequency='1d'  
    )[0]

And that's the VX1 close that I'm finding differs slightly from the vixcentral data.

My backtest has the US Futures calendar selected (apparently required in order to access the futures data) but I'm trading equities. So that my trades happen during equities market hours I'm using calendar=calendars.US_EQUITIES as a parameter for schedule_function().