Hi everyone!
I've got a question with market on open orders. Attached is a simple strategy that buys SPY with a market on open order. If you run the backtest, you'll notice that the market on open order was filled at 9.31, not 9.30 like I thought it would. Why is this?
Best regards
Fred Painchaud
Hi Li,
It is so because on minute resolution, your algorithm receives the first 1m TradeBar AFTER the first minute, so at 9h31 if market opens at 9h30. This is so to avoid look-ahead bias. It is absolutely paramount to avoid look-ahead bias if we want backtesting results to be somewhat meaningful.
F
P.S. If you think about it, if your algorithm gets the close price (or high, or low) of the minute DURING that minute, it sees in the future as then, the bar is not finished yet……..
Li Cheng
Hi Fred, thanks for answering my question!
I think I understand what you mean, if the algorithm is subscribed to minute resolution, then even if the order was filled at say 9::30:05 am, it will be noted as filled at 9:31 am because we're receiving minute bars.
After reading your response, I've decided to test with second resolution instead, and it turns out that you were right, the order was filled at 9:30:01.
Li Cheng
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!