Back to Community
The Bean Report

EDIT: Updated Version For 5/18/2017 Meetup is Attached

The ability to research and backtest futures data on Quantopian is an amazing milestone. The first futures contract that I wanted to study was the beans, and the attached notebook is what I was able to produce. There are significant issues remaining (closing times of futures v equities, not using precise delivery dates, thin trading on the soybean ETF...etc), but overall I think this notebook provides some good insights and tools to utilize when approaching futures on Quantopian.

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

Attached is the template for converting from Research to the IDE:

Clone Algorithm
26
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: 591cfb0d508d856863f41d0f
There was a runtime error.

well done buddy. Classic work.

question: is there any specific reason why you use only 1Q data to train the model?

@seine

Thanks for the compliment. There were a few reasons why I only tested on 1Q data, but for the purpose of this response I would say that I was just trying to get a model up an running as quick as possible to test paper trading the July beans contract without having to spend much more time coding. I will provide some better reasons in a follow up post.

Thanks to all who attended the Meetup tonight, and thanks to Q for putting on the event. Connie's Pizza was great!

As promised at the meetup, here is an algo that makes trades. I wanted a little more time to rework the ML in the Bean Report before crafting a trading strategy, but here is something that at least attempts to replicate the strategy I was working towards in the notebook...which was to trade the large deltas in the predictions from the stacked model. I plan to update this in the future with something that trades in prior years, and can also be traded in the future.

Also, a disclaimer or sorts....the performance of this backtest is completely engineered. I just thought it would be nice to provide an algo with some basic trading logic.

A description of what it does:

1) Starts in January of 2014, and collects data for 1Q 14, 1Q 15, and 1Q 16.
2) In January of 2017 it continues to collect data, but also starts training the ML models. It makes predictions for May and July Beans
3) Starting in February it starts trading. If the signal delta is less than -0.12, it will short 10 lots of the may beans. if the delta is less than -0.06, it will short 2 lots. If greater than 0.012, it will go long 10 lots of the july beans. if greater than 0.06, it will go long 2 lots of the july beans.

I know the results look good, but remember that this was just a quick test. The sample size is way too small to have any confidence at this point. Hopefully it shows similar results in prior years, and more importantly...the future.

Clone Algorithm
34
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: 591e7b9790ff6767b6721e4c
There was a runtime error.

where is this meetup, again? I live in DC. if the meetup is anywhere close, I would love to join in future meetups.

@seine,

The meetup was in Chicago. Here is the link to the DC group:

https://www.meetup.com/Washington-Algorithmic-Trading/

How can you paper trade futures? Can I create a IB account paper account and use that to test?

@Dennis,

Live trading of futures does not seem to be supported yet per the discussion on this thread:

https://www.quantopian.com/posts/futures-trend-reversion-algo

@Frank
I was trying to convert your Beans code to trade corn and got stuck. Can I post what i have?

@Dennis, Feel free to post.

I have have attached the code. Thanks still learning.

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

@Dennis, it appears you have taken the code from the IDE template and placed within the Research environment. Was this your intention, or was this just a way of posting the code in the forums because you could not run a backtest in the IDE for sharing?

I could not get the code to run for back test I can add the .py file if you prefer.

@ Dennis, I was able to copy and paste the code you provided into the Quantopian IDE. I have not debugged all the issues, but the biggest issue I found immediately was that you were using 'COY' as the symbol for the equity corn product, which did not seem to exist as a Corn ETF. After correcting that issue, I encountered other errors that I did not have time to debug.