Good morning everyone,
Maybe my question is quite naive but I would like to have the opinion of the more experts. For a couple of months I have been running an algorithm based on kslearn, and when I do the backtests of the last two months it generates a profit of approximately 7.45%. Instead the real results are a net loss of -2.45%.
Why these differences between backtest and live results?
Thanks a lot guys
Without your contribution it would be impossible for me to learn
Mia Alissi
There could be several reasons why you're seeing differences between your backtest and live trading results. Here are a few possibilities:
Different Backtest Parameters: If you don't start your backtest and live deployment on the same date with the same holdings, deviations can occur between backtesting and live trading. To avoid issues, ensure your backtest parameters are the same as your live deployment. source
Spread, Slippage, and Unmodelled Fees: Differences between backtesting and live trading can be due to factors like spread, slippage, and unmodelled fees. For example, for US equities, if the spread of the stocks is wide, this can mean different fill positions. Depending on the speed of your algorithm, the time it takes for the brokerage to place the trade might be significant and the market might have moved by the time it's filled, resulting in different prices. Also, sometimes the brokerages attach extra fees like data and interest, which are not included in your backtest model. source
Tick Slice Sizes: In backtesting, QuantConnect collects ticks into slices that span 1 millisecond before injecting them into your algorithm. In live trading, they 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
Borrowing Costs: If your algorithm takes short positions, deviations can occur between backtesting and live trading because QuantConnect does not currently simulate the cost of borrowing shorts in backtests. source
Data Differences: Historical data can be quite different between different sources. There is sometimes a big difference in some equity prices between QC historical data (QuantQuote) and what your broker is showing for that point in time. So if you are backtesting and live trading on different data streams, the backtesting results may not be that valid. source
To better understand the differences, you might want to add more logging to your algorithm in live mode to gather information to compare against backtest. If you continue to have issues, you can contact support@quantconnect.com with the live deployment attached. source
As for your code, without knowing the specific error or issue you're encountering, it's hard to provide specific advice. However, the code you provided seems to be following the general structure of a QuantConnect algorithm. If you're encountering specific issues, you might want to provide more details or error messages.
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.
Roberto Coccaro
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!