Five Backtest Invariants Worth Enforcing In Code

A backtest has one job: answer what would have happened if you had run this strategy, knowing only what you knew at the time. Every bug in a backtest is a leak in that second clause, and leaks are asymmetric. A backtest that accidentally sees the future does not produce a random error. It produces a better number. That asymmetry is why I now write backtest invariants as tests rather than as care.…