Backtesting means running a trading strategy on past prices to see what it would have done. You write down exact rules, such as “buy when the 50-day average crosses above the 200-day”, replay history day by day, and record every trade the rules would have made. The result is an equity curve and a few numbers: yearly return, worst drawdown and Sharpe ratio.
A backtest cannot tell you what will happen next. It can show you, cheaply, that a strategy would have failed before you put money on it.
How a backtest works, step by step

- Write rules a computer can follow. “Buy SPY when its 14-day RSI drops below 30, sell when it rises above 70” is testable. “Buy when the market looks cheap” is not.
- Get clean price data. Use prices adjusted for dividends and splits, covering both rising and falling markets.
- Decide when trades fill. If your signal uses today’s close, the earliest honest fill is the next price after it, such as tomorrow’s close.
- Charge costs. Every buy and sell pays fees and slippage. We use 0.1% per side for liquid ETFs.
- Replay history and compare. Run the rules over the whole period and compare the result with simply holding the same asset over the same dates.
An example
We backtested the golden cross on the S&P 500 (SPY) from December 31, 1993 to October 9, 2026: hold SPY while the 50-day average is above the 200-day, otherwise wait in cash. Signals were taken at the close, trades filled at the next close, and each side cost 0.1%.
- Golden cross: 10.12% a year, worst drawdown −33.72%, Sharpe 0.77, 61 trades.
- Holding SPY: 10.91% a year, worst drawdown −55.19%, Sharpe 0.65.
So the rule gave up a little return and avoided a lot of the worst fall. The same test also shows a weakness: from November 2016 onward, the golden cross earned 11.05% a year against 15.49% for SPY. You can see this and six other rules on our famous strategies experiments page.
Five ways a backtest misleads
1. Look-ahead bias
The test uses information that was not available at the time, for example trading at today’s close on a signal that needs today’s close. The fix is to fill on the next price. You can check for it by changing prices after a cut-off date: if results before that date change, the test is reading the future.
2. Missing or wrong costs
A strategy that trades often can look great with zero costs and lose money with real ones. Double your costs and rerun. If the result does not change at all, costs are not in your code. We caught exactly this in a strategy written by an AI coding agent.
3. Hindsight in the asset list
Testing on today’s top stocks, or on the leveraged ETFs that we now know did well, builds the answer into the test. The list should come from a rule you could have applied on the start date.
4. Overfitting from many tries
Try enough settings and one will look excellent by chance. If you tested 100 versions, the best one is not evidence of anything on its own. The deflated Sharpe ratio (Bailey and López de Prado, 2014) adjusts for the number of tries. Our guide on how to read a backtest explains it.
5. One period, one asset
A result that comes from one coin, one stock or one lucky year is fragile. Remove the biggest contributor, move the start date, and keep a final period you test only once, after all the tuning is done.
In our own audit of 20 strategies built by AI agents, 19 failed at least one of these checks. The 20th failed on how its leveraged profits were booked. The details are in why 20 AI-built trading strategies failed our backtest audit.
What a good backtest result looks like
- It runs long enough to include at least one bad market for the asset.
- It is compared with holding the same asset over the same dates.
- It reports the worst drawdown next to the return.
- It still holds up at double the costs.
- It says how many versions were tried before this one.
The backtest checklist turns this into questions you can answer for any strategy. The backtest metrics calculator works out CAGR, drawdown and Sharpe from your own numbers.
Common questions
Is backtesting the same as paper trading? No. A backtest replays the past in seconds. Paper trading runs the rules on live prices without real money, so it takes weeks or months, but it cannot see the future by accident.
Do I need to code to backtest? Not for simple rules. Spreadsheets and charting platforms can test moving-average or RSI rules. Code helps once rules involve several assets or position sizing.
How long should a backtest be? Long enough to include falling markets for that asset. For US stocks that means including 2008 or 2022. For crypto, include 2018 and 2022.
Educational material. Test with small amounts first. We are not liable for losses or software errors.
📊 Empirical Strategy Audit — Mathematical backtests, friction analysis, and regime risk decompositions.
▶ Subscribe to Avalon Quant⚠️ Not financial advice. This guide is for educational purposes only; trading can lose money, and past results do not guarantee future ones.


