Quant Analytics: from scratch to pro · Backtesting done right · Beginner
What a backtest is, and what it is not
A backtest replays a rule on past data to see what it would have done. It is one simulated path, built with hindsight on the table. It can reject weak ideas well; it cannot prove that an idea works.
In this lesson
- Explain what a backtest computes and which parts are simulated
- Turn a list of trade results into an equity curve and a total return
- Say why a backtest is evidence against an idea more than evidence for it
- Compare a backtest with the right benchmark, after costs
Read first: Returns: simple, log and compounded, Risk and return
A backtest is the first question anyone asks of a trading idea: what would it have done? The answer is useful, and it is easy to over-read. This lesson says what the machine computes, so that the later lessons can say how it goes wrong.
What a backtest does
A backtest takes a rule written down in advance, runs it over historical prices as if time were moving forward, and records the trades it would have made. The output is a list of trades, an equity curve (the value of the account over time) and summary numbers.
Three parts are always there:
- Data: the prices, and whatever else the rule reads, as they were known at each date.
- Rule: exact conditions for entering, exiting and sizing a position.
- Simulation of trading: fills, costs and timing. This is the weakest part. Nothing was actually traded.
One path, with hindsight
The past happened once. A backtest is a single path through it, so a good result is one draw. Worse, the person who built the rule had usually seen the data first. Every choice of lookback, threshold or market was made with some knowledge of what followed.
Researchers who count the cost of this show that trying many variants on the same data makes a high in-sample result easy to find, even when nothing real is there (see overfitting). So a backtest works better as a filter than as a proof. A weak result is a good reason to drop an idea. A strong result is a reason to test harder.
Worked example
A rule produces five trades, starting from 10,000. The results are +2%, -1%, +3%, -2% and +1.5%.
Trade results chain by multiplying: 10,000 x 1.02 x 0.99 x 1.03 x 0.98 x 1.015. The final equity is 10,346, a total return of 3.46%.
Now add costs of 0.2% per trade (spread, commission, slippage; see costs in a backtest). Each result falls by 0.2 points, and the final equity is 10,243. The total return is 2.43%. Costs removed 1.02 percentage points from only five trades. A rule that trades often loses much more.
Finally, compare. Over the same dates the price went from 100 to 104, so holding returned 4%. After costs, the rule trailed. A backtest number means little until it sits next to the benchmark for the same period, on the same basis (total return, after costs).
What a backtest can tell you
| It can show | It cannot show |
|---|---|
| The rule runs and is coded as intended | That the result will repeat |
| How the rule behaved in the stress periods in the data | How it behaves in a stress that is not in the data |
| Whether costs and turnover eat the edge | Whether the data was clean and complete |
| Whether the idea is worth testing out of sample | That luck is excluded |
Common mistakes
- Treating the equity curve as a forecast. It is a description of one replay.
- Reporting a return without the benchmark, the dates or the costs.
- Changing the rule after seeing the result, then reporting only the final version.
- Trusting a result built on few trades. See reading a report.
- Forgetting that data may leak the future into the test. See look-ahead bias.
In practice
Write the rule, the data, the dates and the success test before running anything, and keep the result next to the benchmark. A backtest is cheap to run, so the discipline lies in what is decided before and after it. Research on FinUties is where studies built on methods like these are published, with their method and limits stated.
Worked numbers
Each result is recomputed from the formula shown.
| What | Formula | Result |
|---|---|---|
| starting equity | 10000 | 10,000 |
| final equity before costs | start_eq * 1.02 * 0.99 * 1.03 * 0.98 * 1.015 | 10,346 |
| total return before costs | gross_eq / start_eq - 1 | 3.46% |
| final equity with 0.2% cost per trade | start_eq * (1.02 - 0.002) * (0.99 - 0.002) * (1.03 - 0.002) * (0.98 - 0.002) * (1.015 - 0.002) | 10,243 |
| total return after costs | net_eq / start_eq - 1 | 2.43% |
| return lost to costs | gross_ret - net_ret | 1.02 |
| buy-and-hold return, price 100 to 104 | 104/100 - 1 | 4% |
Check yourself
A rule takes five trades with results +2%, -1%, +3%, -2% and +1.5%. Starting from 10,000, what is the final equity before costs?
Multiply, do not add: 10,000 x 1.02 x 0.99 x 1.03 x 0.98 x 1.015 = 10,346, a total return of 3.46%.
The same trades each lose 0.2% to costs. What is the total return now?
Each result falls by 0.2 points: 1.018 x 0.988 x 1.028 x 0.978 x 1.013 gives 10,243, or 2.43%. Costs removed 1.02 percentage points from five trades.
The market itself went from 100 to 104 over the same period. Did the rule add value?
Not on these numbers. Holding returned 4%, the rule 2.43% after costs. The right comparison is with holding the asset, over the same dates, on the same basis.
A backtest looks good. Why is that not proof?
It is one path, tested on data that the designer had already seen. Many variants may have been tried, and a good-looking result among them is expected by chance. It is a reason to test further.
Key terms
Sources
- Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society 61(5), 458-471 (Bailey, Borwein, López de Prado, Zhu), 2014. Accessed 9 Nov 2026
- Advances in Financial Machine Learning. Wiley (Marcos López de Prado), 2018. Accessed 9 Nov 2026