algorithmic-trading · Lesson 5

Backtesting: Testing a Strategy on History

How replaying a strategy on past prices helps you sanity-check it — and the three biases that make a backtest quietly lie to you.

6 min readIntermediateSean ShaReviewed by Sean ShaUpdated: July 2026
Backtesting: Testing a Strategy on History — illustration of a friendly person in a cozy kitchen reviewing a well-worn recipe notebook beside

Educational purposes only. This content does not constitute investment advice. Read our disclaimer

StockCram is not a broker-dealer, investment adviser, or financial institution. All content is for educational and informational purposes only and should not be construed as personalized investment advice. Consult a qualified financial professional before making investment decisions. Past performance does not guarantee future results.

TL;DR

Backtesting means replaying a fully written-out set of rules against historical prices to estimate how the strategy would have behaved — usually judged by its equity curve (account value over time) and its worst drawdown. It's a genuine reality check, but never a crystal ball: a backtest describes the past, it does not predict the future. Three classic biases make it lie — look-ahead bias, survivorship bias, and overfitting — and a suspiciously perfect curve is a reason for doubt, not celebration.

What Backtesting Actually Is

Once your strategy is written out as precise rules, the obvious next question is: would this have worked? Backtesting answers a narrower version of that — it replays your fully specified rules against historical prices and records what the strategy would have done had it been running back then. Think of it like rewinding a game tape and letting your playbook call every move, so you can see how it would have scored. No real money changes hands; the computer just steps through the past, day by day, applying your rules exactly.

Backtesting infographic: replay written rules on past prices with no real money, read the equity curve and worst drawdown, then hunt for the leak. A backtest describes the past, not the future — a too-good curve signals overfitting.
Backtesting replays a strategy on historical prices to estimate how it would have behaved, judged by its equity curve and drawdown. It describes the past, never the future — and a too-good curve is a warning, not a win.

The two numbers people fixate on are the equity curve — a line of your account's value over time — and the drawdown, the worst peak-to-trough drop along that line. A rising equity curve looks like success; the drawdown tells you how much pain you'd have sat through to get it. Both are just descriptions of one particular slice of history.

The One-Sentence Version

A backtest is a dress rehearsal on old footage: it estimates how your rules would have behaved on the past, using no real money — helpful for catching obvious problems, but it's a description of history, not a forecast.

A Reality Check, Not a Crystal Ball

Here's the trap that catches almost everyone: a great backtest feels like proof the strategy will keep working. It isn't. Markets change — the crowd, the rules, the interest-rate backdrop, the very patterns a strategy leans on. A rule that shone across the last decade can still fail tomorrow, because tomorrow is not drawn from the same deck as yesterday.

Say it plainly

A backtest describes the past; it does not predict the future. It can tell you a strategy already failed on history (useful — you can discard it), but a strategy that succeeded on history has proven only that: it succeeded on history. Past results never guarantee future ones.

Reading an Equity Curve

To make this concrete, here's the shape people hope to see when they run a backtest — an account value that climbs over time, with a couple of scary dips along the way. Watch what happens to the line, and keep in mind these are made-up numbers meant only to show the shape:

An illustrative backtest equity curve (stylized — not real performance)

Illustrative only — invented numbers to show the shape of an equity curve, not a real or expected result. A smooth, mostly rising curve like this is exactly what an overfitted strategy also produces, which is why the picture alone proves nothing.

An illustrative backtest equity curve (stylized — not real performance)Illustrative only — invented numbers to show the shape of an equity curve, not a real or expected result. A smooth, mostly rising curve like this is exactly what an overfitted strategy also produces, which is why the picture alone proves nothing.10000120001400016000180002000010000Yr 111800Yr 213500Yr 315200Yr 414600Yr 516900Yr 618300Yr 717500Yr 8Account value ($)

Notice the dip from Year 4 to Year 5, and again at the end — those wobbles are the drawdowns, the stretches where the strategy was underwater. Now here's the uncomfortable part: a curve this clean is also exactly what you get when a strategy has been quietly tuned to fit the past too well. The prettiness of the line tells you nothing about whether the underlying idea is real. So before you trust a curve like this, it pays to practice interrogating one — which is exactly what the rest of this lesson does.

Exercise: Spot the Broken Backtest

Backtests don't lie on purpose — they faithfully report what you asked. The lie sneaks in through how you set the test up. Below are four backtests that each look fantastic. For each, ask what's wrong here? before opening the reveal. Three of the flaws are the classic biases every serious backtester hunts for; the fourth is the friction that quietly eats a strategy alive.

Vignette 1 · The strategy that's never wrong

The setup. A momentum rule buys each morning, and the backtest is an almost unbroken rising line — calling the direction right on roughly 90% of days, with barely a losing week in a decade.

What's wrong here? A ~90% daily hit rate should feel impossible. Where is the foresight coming from?

The flaw: look-ahead bias

The code used each day's closing price to place a trade at the open — using information it couldn't have known at that moment — it saw the answers early. That is look-ahead bias, and it's a bug: the strategy peeked at the future. The fix is to feed the test only data that was actually available at each point in time.

Vignette 2 · The basket that never breaks

The setup. You backtest a rule that just holds the biggest companies over the last 20 years. The equity curve barely dips — even the worst crashes look like gentle speed bumps.

What's wrong here? Real decades contain real disasters. Why does this one look so much safer than the market you lived through?

The flaw: survivorship bias

The dataset only included companies that survived to today. The ones that went bust or were delisted were silently deleted, so the past looks safer than it was. That is survivorship bias — a bad dataset, the corpses swept off the field before the test began. The fix is a dataset that includes the losers and delisted names, not just today's winners.

Vignette 3 · The flawless ten-year run

The setup. After trying a hundred parameter combinations, you keep the one whose backtest turns an illustrative $10,000 into $40,000 over ten years with barely a dip.

What's wrong here? No bug, no bad data — so why should near-perfection make you more suspicious, not less?

1

You went fishing for the winner

Testing a hundred combinations and keeping the best means you searched a whole sea of settings and landed the luckiest one for this single history.

2

It memorized noise, not a pattern

The strategy learned the random luck of one particular decade by heart instead of a real, repeatable edge. That is overfitting — subtler and the hardest to catch, because nothing looks broken.

3

How to guard against it

Keep rules simple, use few adjustable knobs, and check the strategy on data it never saw during design — the defense covered next.

Vignette 4 · The tireless money machine

The setup. A rule that trades hundreds of times a day produces a smooth curve, minting a sliver of profit on nearly every round trip.

What's wrong here? The logic checks out and the data is honest. So what did the simulation forget to charge?

The flaw: ignoring trading costs and slippage

The backtest assumed every trade filled at the exact price it wanted, for free. Real trading pays commissions and slippage — the gap between the price you expected and the price you actually got. On a handful of trades that's a rounding error; across hundreds of trades a day those tiny costs compound and can erase the entire edge. The fix is to subtract realistic costs and slippage from every simulated trade.

How Careful Backtesters Fight Back

The main defense is out-of-sample testing: you split your history in two, design and tune the strategy on the first chunk, then run it once on the second chunk it has never seen. If the strategy only shines on the data it was tuned on and falls apart on the held-back data, you've caught overfitting red-handed. Alongside that, the quiet discipline is keeping rules simple — the fewer knobs you can twist, the less room there is to accidentally memorize noise. A strategy with two sensible rules is far harder to overfit than one with fifty fiddly parameters.

Even a clean out-of-sample result is still history. The next step, covered later in this course, is paper trading — running the strategy forward on live markets with fake money, so it faces prices that hadn't happened yet when it was built. That's the closest thing to an honest test before any real capital is ever at risk.

The Real Lesson: Distrust the Perfect Curve

That's the mindset shift this lesson is really about. A gorgeous backtest is not a trophy — it's a prompt to ask what did I get wrong? The more perfect the curve, the harder you should look for the leak, because in noisy markets, near-perfection is far more often a sign of a mistake than of a genuine discovery.

Educational use only

Educational content only. StockCram isn't a broker or adviser, and we have no affiliation with any institution or tool we mention. Nothing here is a recommendation to trade in any particular way.

Key Takeaways

  • Backtesting replays rules on history - It steps a fully written strategy through past prices with no real money, judged mainly by its equity curve (account value over time) and worst drawdown.
  • It describes the past, not the future - A backtest can prove a strategy already failed, but a strategy that succeeded on history has only proven it succeeded on history. Markets change.
  • Three biases make it lie - Look-ahead bias (using data it couldn't have known), survivorship bias (testing only on survivors), and overfitting (memorizing noise) all flatter a strategy.
  • A too-good curve is a red flag - Out-of-sample testing and simple rules are the defenses. The more perfect a backtest looks, the harder you should hunt for the leak behind it.

Continue Learning

Frequently Asked Questions

Backtesting is replaying a fully written-out trading strategy against historical prices to estimate how it would have behaved, without risking real money. The computer steps through the past day by day, applies your rules exactly, and records the results — usually shown as an equity curve of account value over time and the worst drawdown along the way.

No. A backtest describes one slice of the past; it does not predict the future. Markets change, so a rule that worked across the last decade can still fail tomorrow. A backtest is genuinely useful for spotting strategies that already failed on history, but success on history only proves success on history — never future results.

Overfitting is tuning a strategy's rules and settings until the past looks nearly perfect — so the strategy has memorized the random noise of one particular history instead of learning a real, repeatable pattern. The classic tell is a backtest that looks too good to be true. It usually collapses the moment it meets data it wasn't tuned on.

Look-ahead bias is when a strategy uses information it couldn't have known at the time — like using a day's closing price to decide a trade placed earlier that day. Survivorship bias is testing only on companies or funds that survived, silently ignoring the ones that went bust, which makes the past look safer and more profitable than it actually was.

The main defense is out-of-sample testing: design and tune the strategy on one chunk of history, then run it once on a held-back chunk it never saw. Keeping rules simple, with few adjustable knobs, also reduces the room to overfit. Later, forward or paper trading on live markets with fake money tests the strategy against prices that hadn't happened when it was built.

Share