What is Backtesting?
Backtesting is a process of evaluating an investment strategy by analyzing the historical data. This type of analysis is important for any investor who wants to make sure their strategy has been successful in the past. There are 3 main steps to backtesting:
- Choose a time frame
- Input your trading rules and assumptions and execute your trading strategy.
- Analyze the results.
Some traders will only do one-time testing on their system before they trade live with real money, while others may test a few different strategies over multiple periods of time. What’s more crucial than how many tests you run or what type you run is that you find a way to keep track of all your trades so that when it comes down to it you can see which ones were the best.
What is backtesting and why do it?
Backtesting is a statistical analysis technique that uses historical data to backtest trading strategies. The idea behind backtesting is simple: if we can find an algorithm or a trading strategy, which has traded successfully in the past then why not use it to trade in the future?
Backtesting can be used to backtest trading strategies for stocks, options, futures, crypto and more. We want backtests that are not just accurate but also realistic so we need to have data generated by real market conditions in order to test our algos on the same environment they will trade under after being implemented. It’s more than just backtesting though, backtesting is the first step of algorithmic trading.
Types of backtests
- Using historical data - The standard backtest that tests the algorithm on historical data.
- Live or what is called paper trading - Allows you to backtest on live data without causing any real money transactions in the process. In paper trading, you'll have fake money to conduct transactions based on real-time information.
What to consider when backtest?
What is it that you want to backtest? Is this algorithm going to be used as a stand alone algo or part of a strategy with other components such as technical analysis tools. Does the backtested strategy have multiple entry signals for entries and exits?
Backtesting environment - the backtest must be run in an environment that accurately reflects current market conditions to provide proper results. You can't backtest your algorithm on data from 2000 if you're looking for realistic signals today, it just doesn't work like that!
Backtesting frequency - backtests are run using daily, weekly or monthly bars depending on the timeframe you're looking to backtest over. A backtest of a system that trades every 15 minuets requires more frequent price updates than one that uses hourly prices for instance.
Can a strategy succeed in backtesting but fail in live trading?
Absolutely, backtesting is a simulation and not real life trading. There are many reasons why backtests can succeed but the most common one I see is that traders don't backtest on realistic data, or they overfit their algorithm to the backtest results.
I think most retail (or indie) algo traders wonder if their algorithm got lucky.
It's a good question, backtesting is just running your algo on historical data to see how it would have performed in the past. As with any backtest you need to be very careful about what results you present and not cherry pick ones that show great returns! I've seen backtests of strategies where people only focus on one or two backtests out of the hundreds they ran and show amazing returns. Avoid this!
Backtesting is a great way to test your algorithm, but in reality you're going to need more than that if you want to make money trading with it long term. You'll also benefit from having other elements such as risk management built into your strategy so don't stop backtesting but make sure you don't rely on backtests alone.
Remember backtests are based on historical data and in the real world we don't have a crystal ball. The backtest doesn’t know about anything that has happened or will happen in the future so it is important not to look ahead when evaluating backtested strategies. What if another pandemic happens?
Can a strategy fail in backtesting but succeed in live trading?
The odds of this happening is less than backtests succeeding in backtesting but failing live. But, I would say it's also possible.
Conclusion
Backtesting is a great way of testing algorithmic trading strategies before deploying your algorithms in a real environment using real funds. At the same time, backtest results are not 100% accurate - they show how an algorithm might have performed in past market conditions and on certain data, but backtests are not conclusive. There are many things you need to consider when backtesting your algo, but the most important thing is ensuring that your backtest environment reflects current market conditions as closely as possible - this ensures accurate results. Things like commission costs, latency issues and data feed errors can all impact backtest results.