Hi everyone,
I am trying to build a simple futures backtest that ranks and go long/short commodities by their Log Return every n month.
I am able to get the backtest to work but now I am running into two issues that I think might be related:
- All my orders are being filled at stale price
2. Occasionally there is no price for a contract:
No price for KE14H12 even though it is mapped to a continuous contractI searched for some possible explanations in the forum and it seems like I am trying to place an order at the same time the data slice is emitted which prevents the order to get to the latest data.
I'm not sure how to go about fixing this yet, so would really appreciate any help/guidance
Hiếu Ngô
I have tried to reduce the data resolution to minute but still no luck
One thing I have not tried is to place an order one minute after the timeslice happen, which I'm not sure how to do
If anyone has any ideas or suggestions on this, I would be very grateful
Derek Melchin
Hi Hiếu Ngô,
The issue occurs because the algorithm receives SymbolChangedEvents and 1AM while it receives the daily trade bars at 19:00 or 20:00. If the algorithm tries to place an order when it receives SymbolChangedEvents, the order will fill at stale prices.
To fix the issue, we need to replace
with
and we need to replace
with
See the attached backtest for reference. These changes fix the rebalance timing so it only occurs when there is Futures TradeBar data in the current Slice. However, the algorithm still needs further work to move the contract roll-over logic to when the Slice contains the trade bar data for the Future contracts we are rolling between.
Best,
Derek Melchin
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ếu Ngô
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!