How to backtest a trading strategy without fooling yourself

A step-by-step method for backtesting a stock strategy, the six biases that make bad strategies look good, and the spreadsheet layout and formulas to run one honestly.

By the Jordan team · · 6 min read

A backtest applies a trading rule to historical prices and records what would have happened: every entry, every exit, every gain and loss. It is the cheapest way to find out that an idea does not work.

It is also the easiest way to convince yourself that a bad idea does work. A backtest is only as honest as its assumptions. This guide walks through a method that keeps it honest, using a simple stock rule as the example.

Toggle the entry price
Signal from the day’s close, bought at that day’s open
78% win rate average +2.1% per trade, 412 trades
Same signal, bought at the next day’s open
51% win rate average +0.2% per trade, 412 trades

The rule only knows its signal after the close, so buying at that morning’s open uses a price from before the signal existed.

Hypothetical backtest results, for illustration only. Past results, not a forecast. Not financial advice.

Step 1: Write the rule down completely

Before touching data, write the strategy so precisely that two people would produce identical trades from it. A complete rule specifies:

  • Universe. Which stocks are eligible? ("Every stock that was in the S&P 500 on the signal date, 2015 to 2024.")
  • Signal. What triggers a trade, using only information available at that moment? ("The stock closes above its 200-day average after closing below it the day before.")
  • Entry price. Exactly which price you pay: the next day's open, the next close, a limit price?
  • Exit. When and at what price you leave. ("Sell at the close 20 trading days later.")
  • Size. How much per trade.
  • Costs. Commissions, the bid-ask spread and slippage, per trade.

Vague rules let you make decisions with hindsight, often without noticing.

Step 2: Collect complete data

Gather every stock in the universe as it was at each date, including the ones that were later acquired, delisted or went bankrupt. A dataset that only contains survivors produces a backtest that only contains winners.

For each signal you need the fields the rule uses, dated, plus the prices you would have traded at. In a spreadsheet, one row per signal is the cleanest layout.

Column Example
Ticker ABC
Signal date 2023-03-14
Signal (1 = rule fires) 1
Entry: next day's open 48.20
Exit: close 20 days later 50.05
Round-trip cost 0.10%

Step 3: Apply the rule row by row

Add a column that computes, for each row, what the trade returned after costs:

G2  Return     =IF(C2=1, E2/D2 - 1 - F2, "")

E2/D2 − 1 is the gain or loss from the entry price to the exit price. Subtract the round-trip cost and you have the net return of one trade.

Step 4: Summarize

Put the results in summary cells:

Trades           =COUNTIF(C:C, 1)
Win rate         =COUNTIFS(C:C, 1, G:G, ">0") / COUNTIF(C:C, 1)
Expectancy       =AVERAGEIFS(G:G, C:C, 1)
Worst trade      =MINIFS(G:G, C:C, 1)

Expectancy, the average net return per trade, is the single most important number. If it is not clearly positive after costs, nothing else matters.

The six biases that break backtests

1. Lookahead bias

Using information that was not available when the trade would have been made. The classic example is a rule that reads the day's closing price and then "buys" at that same morning's open. The signal didn't exist yet at the open, so the backtest is trading on the future.

Fix: For every input, ask "could I have known this at the moment I trade?" If the signal comes from a close, the earliest honest entry is the next open.

2. Survivorship bias

Testing only on stocks that still exist. A backtest run on today's index members ignores every company that was dropped from the index, acquired or went bankrupt, and those are disproportionately the losers.

Fix: Build the universe as it was at each point in time, including everything that later disappeared.

3. Overfitting (data snooping)

Trying many variations and keeping the one that looked best. With enough parameters, any dataset can be fit perfectly, and the "strategy" is just a description of past noise.

Fix: Limit the number of variations you try, prefer simple rules with few parameters, and keep test data untouched (step 5).

4. Ignoring costs

Commissions, bid-ask spreads and slippage are paid on every trade. A strategy that earns 0.1% per trade before costs and pays 0.15% in costs loses money, and the more often it trades, the faster it loses.

Fix: Model the costs of the broker and stocks you would actually trade, and assume you buy at the ask and sell at the bid, not at the midpoint.

5. Unrealistic fills

Assuming you could trade any size at the quoted price. Small, thinly traded stocks move when you trade in them.

Fix: Cap position size relative to average daily volume, and treat results that depend on large trades in illiquid stocks with suspicion.

6. Small samples

Twenty trades can show almost any win rate by chance. Results driven by a handful of big winners are fragile.

Fix: Report the number of trades with every result, and compute how much the result changes if you remove the best few trades.

Step 5: Split the data

Divide your history into two parts before you start:

  • In-sample (design) data. Typically the earlier 60 to 70%. Explore, tune and design here.
  • Out-of-sample (test) data. The rest. Run the final rule on it once.

If the out-of-sample result is much worse than in-sample, the strategy was probably fitted to noise. A stricter variant is walk-forward testing: design on years 1–3, test on year 4; design on years 2–4, test on year 5; and so on.

Step 6: Judge the result

A good backtest report answers these questions:

Metric What it tells you
Number of trades Whether the sample is big enough to mean anything
Expectancy after costs Whether the rule makes money at all after costs
Win rate and average win/loss How the result is delivered (many small wins vs. few big ones)
Maximum drawdown The worst peak-to-trough loss you would have lived through
Result without top 5 trades How dependent the result is on luck
Out-of-sample vs. in-sample Whether the result survived data it was not designed on

Win rate on its own is misleading. A rule that takes 1% profits quickly and lets losses run to 10% can win 88% of the time and still lose money, because each loss costs ten times what each win earns.

Backtesting in a spreadsheet vs. code

Code scales to millions of rows and complex logic. Spreadsheets are slower but make every step inspectable, which is exactly where backtests fail: a hidden lookahead, a missing cost, a filter that dropped the losers. For many daily-frequency questions, a spreadsheet holds the full dataset comfortably.

In Jordan, you can describe the rule in a sentence. Jordan brings the price history onto a sheet, from a connected brokerage or a file you import, adds the signal and return columns as formulas, and builds the summary, showing you each change for review first. Because the data is in cells, you can audit any row.

Frequently asked questions

How much historical data do I need for a backtest?

Enough trades for the result to be distinguishable from luck. As a rough guide, a few hundred trades lets you detect a meaningful effect; a few dozen rarely does. More important than calendar length is covering different conditions, such as rising and falling markets and calm and volatile periods.

What is a good win rate for a trading strategy?

There is no good win rate in isolation. What matters is win rate combined with the average size of wins and losses, which together give expectancy. Trend-following strategies are often profitable with win rates below 40%.

Why did my strategy work in the backtest but not live?

The usual causes are lookahead bias, survivorship bias, overfitting, underestimated costs, fills that were not achievable, or a change in the market since the test period. Paper trading or very small live positions help reveal these gaps before they become expensive.

What is walk-forward analysis?

Walk-forward analysis repeatedly designs a strategy on one window of history and tests it on the period immediately after, then rolls both windows forward. It shows whether a strategy keeps working on genuinely unseen data rather than on one lucky split.

Build this analysis in Jordan

Describe it in a sentence. Jordan brings in the data, writes the formulas and shows you every change before it lands.

Join early access

Keep reading