Historical stock backtesting for your own trading rules

A backtest runs a trading rule over prices that already happened and records every trade it would have made. Done carefully, it tells you whether an idea deserves more study before you risk money on it. Kereon's Strategies page builds the rule from plain conditions, charges the costs you set and compares the result with simply holding the same stocks.

Join the waitlist · Tour the Strategies page

How strategy backtesting works

A strategy is a set of rules: when to buy, when to sell, how much to put in each position and which stocks to trade. You can start from one of twenty templates or write the rules from 122 indicators, run them over one stock's daily history or over every stock a numeric filter admits, and set the commission and slippage each trade should pay.

The test then steps through the history one day at a time. Each rule reads only the data available on that day, so the test never trades on information it could not have had, and every trade and the account's value are recorded as it goes.

Reading the results

Return alone says little about a strategy. The summary sets it against simply holding the same stocks, and the full statistics describe the ride as well as the destination.

Compound annual growth rate
The yearly rate that would turn the starting value into the ending value.
Maximum drawdown
The largest fall from a peak to a later low: the loss you would have had to sit through.
Sharpe and Sortino ratios
Return per unit of volatility, and per unit of downside volatility only.
Profit factor and win rate
Gross profit divided by gross loss, and the share of trades that made money.
Number of trades
With too few trades the result may be luck; the statistics are only as reliable as the sample behind them.

Does the result hold up?

A strategy that looks good on one stretch of history may simply fit that stretch. Kereon's robustness tests deal the same trades in a different order to show how much of a result was the sequence, and rerun the rule under other settings to see whether a small change breaks it.

Optimize tries the rule's own settings over a range and recommends a setting only when it holds up out of sample. A walk-forward test goes further: it tunes the settings on one period, tests them on the next, and repeats the process across the whole history.

Common backtesting mistakes

Most misleading backtests fail in one of a few familiar ways.

Look-ahead bias
Using information that was not available at the time, such as a figure revised after the fact.
Survivorship bias
Testing only companies that still exist today, which leaves out the failures. Kereon's filtered tests pick from today's listed companies, and the Strategies page says so.
Overfitting
Tuning a rule until it matches the past perfectly, so that it describes noise rather than a real effect.
Ignoring costs
Commissions, spreads and slippage can turn a profitable rule into a losing one, especially when it trades often.

See it in Kereon

  • Build & test. The whole test on one screen: the stocks, the buy and sell rules, the money and the costs.
  • Summary. The strategy against simply holding the same stocks.
  • All statistics. Every number the test computed.

Every picture on this page is Kereon running on a simulated market: the companies are real, but every price, figure, filing and person in them is simulated.

Questions

What is backtesting?

Backtesting is the process of testing a trading or investment rule on historical data to see how it would have performed. It measures past behavior; it does not predict future results.

How many trades does a backtest need?

There is no fixed number, but a result built on a handful of trades says very little. Dozens of trades across different market conditions give the statistics a chance to mean something.

What is walk-forward testing?

Walk-forward testing tunes a strategy's settings on one period of history and tests them on the period that follows, then moves forward and repeats. It shows whether the settings work on data they were not fitted to.

Does a good backtest mean a strategy will work?

No. A backtest is hypothetical: it shows what a rule would have done on prices that already happened, under the test's costs and assumptions. Markets change, and past performance does not guarantee future results.

Which costs does a Kereon backtest include?

Every trade pays the commission and slippage you set for the test, so a rule that trades often is charged for it.

Terms in the glossary

Read next