Extremely strange results for getting filled on /ES with past market data

Back

Not sure if it's my code, or the way past Futures data is stored but the fills on my eventual Market Orders are rediculous and nowhere near the Last. Here is a small piece of Debugged order data from the backtest:

2016-01-05 00:22:00 LONG, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 2011.0, 36.32538906449194
2016-01-05 01:14:00 LONG EXIT, Ask: 2012.5, FillPrice: 2007.0
2016-01-05 01:15:00 LONG, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 2007.5, 31.28034666509519
2016-01-05 01:37:00 Out of long for 400
2016-01-05 01:41:00 SHORT, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 2012.75, 67.1066477408343
2016-01-05 03:23:00 Out of short for 400
2016-01-05 03:27:00 LONG, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 2006.0, 31.341624501096778
2016-01-05 04:06:00 LONG EXIT, Ask: 2012.5, FillPrice: 2001.75
2016-01-05 04:08:00 LONG, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 2002.5, 34.431038796859944
2016-01-05 04:21:00 LONG EXIT, Ask: 2012.5, FillPrice: 1997.5
2016-01-05 04:25:00 LONG, Bid: 2012.25, Ask: 2012.5, Last: 2012.25, FillPrice: 1998.75, 36.02152848749718
2016-01-05 05:12:00 LONG EXIT, Ask: 2012.5, FillPrice: 1994.25

You can see the fill prices are just off and its causing the algorithm to lose BIG. Where is the mistake in my code? 

Update Backtest








 
0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Valen,

The algorithm is showing accurate fill prices. The reason it appears to be consistently filling outside the spread is because of the way the algorithm references the front contract. Since we have set the futures filter to return the front month contract only, the contract chain in OnData only contains this contract. Retrieving it with

contract = chain.Contracts.values()[0]

ensures we have the latest data for this contract. If we update the debug messages to output the bid and ask prices of this contract, the fills are as we would expect.

Additionally, we need to create the RSI indicator without the canonical symbol. We can do this in Initialize with

self.rsi = RelativeStrengthIndex(14, MovingAverageType.Wilders)

See the attached backtest which shows these alterations.

Best,
Derek Melchin

1

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Ok that makes sense. The for loop painting the TradeBars out seemed strange. Thanks a lot for the reply!

0

Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed