Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
XIV trading based on RSI, ROC and WVF

XIV trading based on RSI, ROC and WVF

13 responses

Usually when you get this kind of performance and use fetch_csv you are accidentally leaking information from the future. Does this still perform if you shift the day used by a day?

Hi James!
Thank you for your comment. I'm kind of a newby in Quiantopian. How would you recommend me doing that? I also thought it was a bit strange to get such high returns.

Hola Sebastian, you can find more information here:
https://www.quantopian.com/posts/how-to-avoid-a-look-ahead-bias
https://www.quantopian.com/posts/function-like-history-but-for-fetch-csv-data

But the best is to avoid fetch anyway. You can use talib to calculate ROC or use the formula:
ROC = [(Close - Close n periods ago) / (Close n periods ago)] * 100

What is the ROC period in your csv? Is there any special reason for you to use this csv file?

Hi Roberto and James, So I did what you two recommended. Indeed the algorithm was leaking future information into the trade.
Turns out, using ROC only decreases the returns as you can see in this backtest:

If, I do not use the ROC to trigger sells in bigger VIX Jumps, the backtest does pretty well I reckon, the only thing that keeps bugging me is the big drawdown in November 2015, but otherwise I believe it performs well. Any suggestions are welcome.

Hi Sebastian, I did some other tests to trigger exits when XIV is going down, but the results using ROC or other similar mechanisms are not very nice. It is probably the case that your algo is already dealing with bad XIV moments. I added also an exit based on VVIX (VIX volatility). I finally tweaked the conditions to allow more profits and reduce risks. You should know that XIV may go easily down -40%/-50% in black swan moments. Also, if XIV goes below -80% is will be liquidated. That´s why I limited the long position on XIV to 50%. The final results are looks quite OK considering that you are only 50% XIV at worst time. It is great that it is relatively consistent in different times/years. You can compare this situation with other algos in this famous vola post.

I added Blue´s code for PvR, but results from here are not the same. We need to check it perhaps with Blue. We are using a bit of intraday leverage, but that should be due to the timing to get the all orders done.

Let me know if you want to collaborate more to develop this also. It looks interesting.

You can see the PvR value is low, it's a measure of returns versus highest risk (in this case cash low [lots of margin in this algo] where the other kind of risk can be shorting, and there's none of that here unless accidental). If you're willing to turn off one of the stocks in the chart to make room for 'record_cash_low' you might find that interesting. You can see where jumps in margin occur. If you go to the trouble of adding track_orders you'll surely see they are happening from unfilled orders

Here's another tool that could be interesting: http://quantopian.com/posts/record-pnl-per-stock. Click stock names in the chart to toggle some off and bring others into scale.

Placing your version into CompareIt, looks like you made quite a few changes (also the start/stop dates are a little different). In PnL within PvR i noticed even with the huge margin this does in fact make tons of profit, if I remember right, just that the margin costs are not modeled. Plus there are limits. We could all benefit from some code that would restrict margin to whatever brokers accept. Maybe it is dynamic based on portfolio? If it is static based on account cash then this code would be impossible unless one is adding cash over the six years, and with PvR only around 200% there are better ways to go. In the prices charted above, you can see drops happening and if you could capture those, my oh my that would be good. Extraordinarily difficult. Suppose for example watching slope every minute if the architecture can handle it without timeouts, or even just price vs max for a given lookback window. The most dramatic might be XIV around July 2011, like 176 to 19 quickly. Ouch.

Hi Robert, Brilliant, thank you so much for your contribution. I would indeed be interested in collaborating with you on this. I will take a look at the changes you made to the Algo.

And as for Blue, you make interesting remarks, I will also look at the tool for the P&L of the stocks. Also, would you mind telling me where the Comparelt tool is? I would be interested in taking a look of that as well.

Cheers guys!

This fails with:

Runtime exception: ImportError: cannot import name yahoo_index_vix

Does anybody have a fix for this?

Bump

Same problem here

Hey guys, the yahoo_index_vix dataset has been removed by Quandl. However, it looks like the dataset isn't being used by the algorithm. Instead, the CBOE version is being used. If you simply remove the line from quantopian.pipeline.data.quandl import yahoo_index_vix, the algo should run.

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.

When do backtest from 2017-01-04 to 2017-10-19, it get very bad result, drawdown is about -40%, while the benchmark is about +120%.
Consider it worked several years, why not it don't work, what's wrong?

Yeah if you are getting that high of a DD now, imagine 08' you will blow your account. Maybe the best thing is to invest after the next massive crash and ride XIV for 5 years to make these returns haha.