TradeAlmanac
Sign in

Backtest

A test of trading rules on historical data: how a portfolio would have behaved if past decisions had been made according to those rules.

A backtest is a calculation that runs a rule written down in advance through a price archive step by step, producing a history of trades and portfolio value that never existed in reality. It does not predict the future and does not prove that an idea works: it only shows what this rule would have done in a specific past under specific assumptions.

How the calculation works

First, the idea is translated into a formal condition: what counts as an entry signal, what counts as an exit signal, and what share of capital goes into a position. The calculation then moves along a timeline — by days, weeks or candles — and at each step the algorithm has access only to what was known by the end of that step. Breaking this order is exactly what look-ahead bias means: financial statements that enter the calculation before they were published, or a trade at a day's closing price when the signal for it comes from that very close.

Trades are executed at a price that was achievable at that moment, net of commissions and the spread; the more often a rule trades, the more the outcome depends on execution costs and therefore on portfolio turnover. The resulting curve is compared not with zero but with a benchmark: a rule that simply tracks the market adds nothing to it.

An example using the site's data

Take the rule "hold while the price is above its average over the past few months, exit when it falls below" and a one-year period for a single stock.

The chart shows where the rule would have triggered an entry and where an exit. Every reversal inside a narrow range turns into a pair of unnecessary trades, and it is these, not the rare large moves, that determine the gap between the curve on the chart and a real account.

Where backtests are misread

The main sleight of hand is calling the result of the calculation the strategy's return. It is the return of one scenario over one stretch of history, not an expected value. The same reasoning explains why a backtest is meaningless on a window in which the market stayed in one state throughout: a rule tuned to a long rally will not meet the conditions that break it in such a window, and its weakness will remain invisible — precisely what turns parameter selection into strategy overfitting.

The second common case is carrying the result over to a rule that a person will not be able to stick to when trading by hand. The calculation executes every signal without hesitation, whereas live execution depends on discipline; the gap between what was planned and what was done is visible only in a trading journal, not in the backtest.

How to read the number

The value of the result is determined by how honest the conditions are: whether commissions and the spread were taken into account, whether the security traded at all on that day, and whether the algorithm knew only what was known at the time of the decision.

When the metric lies

Related terms