Hello,
When running a backtest, I often find that there is a little “adjustment” period right at the end of backtesting execution. I am running this in US Futures data from Algoseek, specifically in ES_Mini data.
For context, this is a backtest from Jan 1 2020 to Jul 24 2024. It closes fine and the results look believable. But the PnL's have a larger deviation (130k at close of last candle vs 150k as net profit) at final backtesting calculation.
Looking online, there does seem to be instances where backtesting can deviate but they are for different scenarios (specifically, most forum posts detail differences in different backtests with the same code on the same data or on live vs historical data).
profit shows 150k; final bar closes at 130k
Mia Alissi
Hello Shengdi,
The discrepancy you're observing between the final bar close and the net profit could be due to a variety of factors. Here are a few possibilities:
Data Differences: Different data sources can have different close prices, which can impact the final results of a backtest. This is due to the fact that each data source may capture different aspects of the market. For example, some data sources may capture high frequency, low volume flickers that some retail providers don't capture. This can lead to differences in the reported prices for the same asset at the same time. In the case of QuantConnect, the data used is real and often more accurate than some retail providers (source).
Brokerage Limitations: If the brokerage model that you use in backtesting is not the same brokerage that you use in live trading, deviations may occur between backtesting and live trading (source).
Tick Slice Sizes: In backtesting, we collect ticks into slices that span 1 millisecond before injecting them into your algorithm. In live trading, we collect ticks into slices that span up to 70 milliseconds before injecting them into your algorithm. This difference in slice sizes can cause deviations between your algorithm's live and OOS backtest equity curves (source).
If you've checked all these factors and the discrepancy still exists, it might be worth reaching out to the QuantConnect community or support for further assistance.
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.
Shengdi Lin
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!