What is a backtest?
Try a rule on past data without using tomorrow’s answer.
The idea
A backtest runs a rule through past data and records what would have happened under stated assumptions.
The program must only use information that was available at each decision. Seeing the future makes the test unfair.
A small example
You have these invented prices:
| Time | Price |
|---|---|
| 1 | 10 |
| 2 | 11 |
| 3 | 12 |
| 4 | 9 |
At time 3, the program may use 10, 11, and 12. It cannot use the 9 from time 4.
Our average at time 3 is 11. The latest price is above it. That observation does not guarantee that the next price will be higher.
Try it
Cover the final row. Calculate the rule using only the first three rows. Then uncover the last row.
Did the next price move in the direction you expected?
Check your answer
The price fell to 9. One example cannot tell us whether the rule is useful overall. It does show why a test needs to separate the decision from what happened afterward.
Later, you will repeat this process over a defined set of observations.