I was having issues finding target stocks using a different algorithm, so I wanted to ensure the historical data aligned with the prices I expected. Still, there seems to be a mismatch between the data in back testing and actual historical reporting.
Here we checked a few stocks and then looked up what the prices were on those specific days and they don't match. What could be causing this? Is the historical data available for backtesting inaccurate?
Yahoo says FRGT opened May 2nd, 2025 at $12.52, but this script returned $4.68.
(look in the logs to see what prices are being returned for the historic data)
Mia Alissi
Here's a review of 'Ahmed's' code, pinpointing the causes for the observed mismatch between QuantConnect's historical data and reported (e.g., Yahoo) prices:
1. Intraday History Request Timing
self.History(self.Symbol(symbol), 1, Resolution.Daily)at an intraday time like 15:59 or 09:31, QuantConnect will give you the most recent completed daily bar. This means:2. Partial Bars Not Official Closes
3. Symbol Mapping / IPO Date Issues
4. Stale Dictionary Entries
historyis empty for a symbol (e.g., stock not trading yet), the corresponding entry is just skipped, retaining any prior value for that ticker and potentially leading to wrong/stale numbers in your logs.5. DataFrame Indexing
history.loc[symbol]['close'][0]assumes a specific two-level DataFrame index. In practice, for a single symbol, you may need to use.ilocor.atto robustly access the price. Since structure varies by the number of symbols and bars, this can cause silent errors or missed data.6. External Data Differences
Suggestions to Fix and Align Prices:
TimeRules.AfterMarketClose(symbol, 0)(i.e., as soon as the official closing price is available) and fetch the latest completed daily bar.AddEquityand use those in history requests to avoid any symbol mapping issues.ilocindexing for reliability—e.g.,history['close'].iloc[-1].In summary:
Your code samples the “previous day” bars because of when and how the history requests are made. QuantConnect’s prices are accurate, but your scheduling and data-access approach need to account for how completed bars are made available versus the live market session.
Let me know if you'd like corrected code or more specific examples for accessing exactly the prices you’re after!
Sources: Data Preparation - QuantConnect.com, History Responses - QuantConnect.com, US Equities - QuantConnect.com, History Algorithm, Consolidate Hour Bars Into Daily Bars Regression Algorithm
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.
Ahmed Karim
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!