The intuition: a backtest is a story told by its data
A backtest asks, "What would this rule have done in the past?" The answer is only meaningful if the past in your dataset resembles the past as it was actually lived. If the data has been tidied, shortened or filtered in ways that favour the strategy, the result describes a world that never existed.
Four problems account for most data-driven errors:
- Survivorship bias: the dataset contains only securities that survived.
- Unadjusted corporate actions: splits, dividends and mergers distort prices.
- Non-point-in-time information: the data includes facts that were not yet known.
- Bad ticks and gaps: errors, missing bars and misaligned timestamps.
This lesson takes each in turn, then works through a numerical example.
Survivorship bias
Suppose you download the current constituents of a stock index and test a strategy over the past 20 years. Every company in that list is, by construction, still listed and still large enough to be in the index today. The companies that went bankrupt, were delisted or shrank out of the index are missing.
That is a problem because the strategy is being tested on a group that has already been selected by its future success. Any rule that tends to hold losers, such as buying beaten-down stocks, will look better than it was, because the losers that never recovered have been deleted from history.
What a clean universe needs
- Delisted securities with their full price history, including the final price and the reason for exit (bankruptcy, acquisition, voluntary delisting).
- Historical index membership, so that the universe on each date matches what was investable on that date.
- Delisting returns. A stock that fell 90% before being removed must show that loss, not simply vanish with its last quoted price ignored.
Corporate action adjustments
Prices change for reasons unrelated to investor performance.
- Splits: in a 2-for-1 split, a share priced at 100 becomes two shares priced at 50. An unadjusted series shows a 50% overnight crash that no investor experienced.
- Dividends: when a stock pays a dividend, the price typically drops by roughly that amount on the ex-date. A price-only series records a small loss and ignores the cash received.
- Mergers, spin-offs and rights issues: these change share counts and values in ways that need explicit handling.
The standard remedy is to use adjusted prices (or total-return series) so that the series reflects what a holder actually earned. Check the method your data vendor uses, and be consistent. Mixing adjusted and unadjusted data in one test is a common source of silent error.
A subtle point: adjusted prices are retroactively changed, so an old adjusted price may differ from the number that was visible on screen back then. That matters if your rule uses an absolute price level, such as "only buy stocks above 10" or a lot-size or minimum-price filter. For those rules, use the as-traded price.
Point-in-time data
Point-in-time (PIT) data stores each value as it was known on each date. This matters most for fundamentals and index membership.
- Company earnings are often restated later. A database that holds only the final restated number lets the backtest act on information that was not available at the time.
- Annual results are published weeks or months after the period ends. If a backtest uses December figures on 31 December, it has assumed an instant publication that never happened.
- Sector and index classifications change over time. Using today's labels on old data leaks the future.
This connects directly to the lesson on look-ahead bias. Point-in-time data is the data-level defence; careful signal timing is the logic-level defence.
Timestamps, gaps and bad ticks
Timestamps
- Confirm the time zone of every series. Mixing an exchange-local timestamp with UTC can shift a signal by a full trading day.
- Decide whether a daily bar's close is available before you trade on it. A rule that computes a signal from today's close and also trades at today's close assumes you could act on information at the instant it formed.
- Be careful with markets that close at different times when combining them. A signal built from a market that closes later than the one you trade can leak information.
Gaps
Missing days arise from holidays, trading halts, vendor outages or illiquid securities that did not trade. Forward-filling a missing price is sometimes reasonable, but it can make an illiquid asset look smoother and less risky than it really was.
Bad ticks
A bad tick is an erroneous price, such as a stray 10 instead of 100. A strategy that reacts to price jumps will treat it as a huge move, and may record a spectacular but fictional profit.
Practical checks:
- Flag daily moves beyond a chosen threshold and inspect them manually.
- Compare against a second source for the flagged points.
- Check for prices of zero, negative values, or volume with no price change.
- Write down the cleaning rules and apply them consistently, rather than deleting only the errors that hurt.
Worked example: how a biased universe inflates results
All figures here are hypothetical and rounded.
Imagine a universe of 100 stocks at the start of a 10-year test. A simple rule buys the 20 cheapest stocks by some measure and holds them equally weighted for the decade.
Full historical universe (the honest test):
- 20 cheap stocks are selected.
- Over 10 years, 12 of them grow at an average of 8% a year.
- 5 stagnate at 0% a year.
- 3 fail and are delisted at a total loss of 100%.
Compute final value per 100 invested. Each stock starts with 5.
- 12 stocks: growth factor 1.08^10 ≈ 2.16, so 12 × 5 × 2.16 ≈ 129.6
- 5 stocks: 5 × 5 × 1 = 25
- 3 failed stocks: 0
Total ≈ 154.6 from 100, which is a 10-year gain of about 54.6%, or roughly 4.5% a year.
Survivor-only universe (the biased test):
The three failed stocks are absent from the downloaded data, so the tester's 20 picks are drawn only from survivors. Say the rule now picks 20 survivors made up of 12 growers and 8 stagnators, giving:
- 12 × 5 × 2.16 ≈ 129.6
- 8 × 5 × 1 = 40
Total ≈ 169.6, a gain of about 69.6%, or roughly 5.4% a year.
The bias added about one percentage point a year in this toy case, from nothing more than missing failures. In real datasets the size of the effect depends on the market, the time period and the strategy, and it tends to be larger for strategies that favour small, cheap or distressed companies.
Now add a corporate action error. One of the growers split 2-for-1 midway and the data is unadjusted. The backtest sees a 50% overnight drop. If the strategy has a stop rule, it may exit at the "crash" and re-enter later, producing trades that never happened. If it is a mean-reversion rule, it may buy the "crash" and record a large fictional rebound. Either way, the results are corrupted in a way that has nothing to do with the idea being tested.
Common mistakes
- Using today's index list for historical tests. Reconstruct membership as of each date.
- Treating a delisting as a missing value. Delistings carry real returns, often negative.
- Mixing adjusted and unadjusted series in the same pipeline.
- Trusting a single data source without any cross-check.
- Cleaning selectively. Removing only the bad ticks that hurt results introduces a bias of its own.
- Ignoring publication lags for fundamental data.
- Assuming free data is clean. Free sources are often fine for learning, but they frequently omit delisted names and adjust inconsistently.
A data-quality checklist
- Does the universe include delisted securities and historical index membership?
- Are splits, dividends and other corporate actions adjusted consistently?
- Are fundamentals point-in-time, with realistic publication lags?
- Are all timestamps in a known time zone, and is each signal tradable after it forms?
- Have outliers, gaps and zero or negative prices been flagged and handled by written rules?
- Has a second source confirmed a sample of key data points?
Try this
Take a hypothetical universe of 50 stocks over 5 years. Suppose 40 survive with an average return of 6% a year, and 10 fail with a total loss of 100%. Assume equal weights and no rebalancing.
- Compute the final value of 100 invested across all 50 stocks.
- Compute the final value if the 10 failures are removed from the data.
- Convert both to annualised returns and note the gap.
Then write one sentence on how the gap would change if the failures lost only 50% instead of 100%. Keep the working so you can compare it with your own real datasets later.