Hi,
A little stuck here. If I get the historical BTCUSD data in the research notebook using:
ticker_symbol = qb.AddCrypto("BTCUSD", Resolution.Hour).Symbol
df = qb.History(ticker_symbol, 100000, Resolution.Hour)
and then take an example datetime of 2020-02-06 09:00, the close price is 9622.62.
When I backtest using OnData with the code:
def Initialize(self):
. BTC = self.AddCrypto("BTCUSD", Resolution.Hour)
def OnData(self, data):
self.close = self.Securities["BTCUSD"].Close
self.MarketOrder("BTCUSD", btcAmount)
self.Debug(str(self.time))
self.Debug('close: ' + str(self.close))
The console prints:
2020-02-06 09:00:00
close: 9747.95
Can anyone help me understand why this is the case?
Mia Alissi
The difference in the close price you're seeing between the research notebook and the backtest could be due to the fact that the backtest and research environments use different fill models. The backtest environment uses the ImmediateFillModel by default, which means that orders are filled at the latest price. This could explain why you're seeing a different close price in the backtest.
In the research environment, the History method returns historical data up to the previous day when called without a specific date. This could explain why you're seeing a different close price in the research notebook.
If you want to ensure that the prices match, you could try using the same fill model in both environments. You can set the fill model in the backtest environment using the
SetFillModel
method on the security object:Please note that this is just a possible explanation based on the information provided. There could be other factors at play as well, such as different data sources or data processing methods.
Sources:
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.
Matthew Lawrence
This did not work.
Thanks
Mia Alissi
I'm sorry to hear that the previous suggestion didn't work. Unfortunately, the information provided in the extracts does not contain a specific solution to your issue. I would recommend reaching out to the QuantConnect support team for further assistance. You can submit a support ticket by visiting the support tab on the QuantConnect website, describing your issue, and attaching the relevant project. The support team will respond as soon as possible.
You can also check the QuantConnect Q&A or community forum for existing answers to similar questions. If you think you have found a bug, you can share a simple backtest that reproduces the issue either through email, Discord, or the forum. The QuantConnect team will review your submission and if confirmed as a bug, they will create a GitHub Issue to have it resolved.
Sources:
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.
Matthew Lawrence
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!