Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Futures trend reversion algo

This algo uses recently released Futures API to trade various futures contracts on different asset classes. The logic is relatively simple, and please see the comments in code. It trades intermittently and as a result the average leverage is low, and the maximum gross leverage is currently set to 2 through Optimizer API constraint .

17 responses

Awesome, great example of using futures plus the optimize API.

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.

Cloned. This will save time. Thank you for sharing Naoki!

Why can't this be used in the paper trading on Quantopian? Keep getting the message: There was a problem deploying your algorithm to live trading: Futures not allowed in live trading. The changes I made worked fine throughout the backtests..

Thanks for your help!

Hi Brandon,

Futures trading, while available in research and backtesting, is currently not available for live trading. We're working on enabling a futures based contest and being able to make allocations to futures based strategies. We're also looking into adding futures functionality to Pyfolio.

Thanks for the quick reply!
Do you guys have a timeline on this? Or is it still quite far away?

We currently do not have a timeline for release of live trading for futures. Sorry I can't provide more info at this time. We prefer not to overpromise anything too early, so our next steps will be to complete the features I mentioned earlier and then determine what is the next most important addition.

When running backtest on 2017 data, there is an error:

KeyError: 1074201706  
There was a runtime error on line 69.  

Any tip how to resolve it?

Thank you Naoki for sharing.

I can't really understand what is context.multiplier = 2250. I saw this numer is multiply by the slope to get the weight but why did you choose 2250?

Thanks for your help

Hi Peter, have you had any luck in understanding the error? I get the same but not sure what it refers too

Hello Peter & Matteo,

We identified an issue with ER pricing data that causes the KeyError you mentioned. This is currently in our queue, but unfortunately I cannot offer a timeline for a resolution.

In the meantime, you can avoid this error by removing ER from your universe of tradable futures.

Apologies for any inconvenience.

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.

The Error may have been caused by the fact that the Russell 2000 returned to CME Group July 10th, 2017.
The ticker on many platforms changed from /TF to /RTY

What would it take to get this in plain language "trading rules"?

I can't follow all this complicated code...

The OOS performance of this strategy is flat.

Matt,

I still getting:

There was a runtime error.
KeyError:1074201706

Line: 97 incalc_slopes

    all_prices = data.history(context.futures, 'price', context.window + 1, '1d')  

Any tip how you resolve it?

Vladimir - just drop ER from the futures' list.

hi

many thanks for providing this code!

I ran it and noticed that almost every day it tries to short the JPY futures and it fails to do so:
2007-01-18 23:00 WARN Your order for -26 shares of JEH07 has been partially filled. 1 shares were successfully sold. 25 shares were not filled by the end
2007-01-19 23:00 WARN Your order for -25 shares of JEH07 failed to fill by the end of day and was canceled.

why is that?
is it not liquid enough? for 26 contracts?

and again same problem in 2015
2015-12-01 23:00 WARN Your order for -10 shares of JEZ15 failed to fill by the end of day and was canceled.
2015-12-02 23:00 WARN Your order for -10 shares of JEZ15 failed to fill by the end of day and was canceled.

Including ER still gets the key error. It's been more than a year and half. Third world governments works after than the Quantopian tech support. LOL