Just The Markets

Rules First, Money Later: Test a Trading Strategy · Lesson 2 of the course

Backtest Costs and Biases: Slippage, Survivorship, Look-Ahead

Backtesting bias and unpaid costs are the usual reasons a strategy that tested well loses money live. Each one can be found and charged for before you trade.

AI-assisted, reviewed by the Just The Markets human editor: Beth Rue → About 14 minutes Published

  1. 01Turning a Trading Idea Into Rules a Backtest Can Run
  2. 02Backtest Costs and Biases: Slippage, Survivorship, Look-Ahead
  3. 03Reading Backtest Results: Expectancy, Drawdown and Streaks
  4. 04From Backtest to Live: Paper Trading and Small Size

In this lesson you will learn to

  • Charge commissions and slippage against a backtest and see what share of the account they take
  • Recognize survivorship bias, look-ahead bias and overfitting in a test setup
  • Adjust a rule set and its data so the test only uses what was known at the time

Two hundred trades a year at $10 each, commission and slippage together, is $2,000, and on a $50,000 account that is 4% gone before the strategy has made a cent.

A hypothetical rule set that shows a gross gain of 6% a year in a spreadsheet that charges nothing for trading nets about 2% once those costs go in, and one that shows 3% gross is a loser. Costs are the simplest thing a backtest gets wrong and the easiest to fix. The biases are harder, because the data itself is tilted in your favor.

Costs: commission and slippage

Commission is the easy half. The fee schedule gives the round-trip cost. Subtract it from every trade.

Slippage takes more thought. A backtest that buys “at the close” assumes you got the closing price exactly. Live, you get the fill. It is usually a little worse. Stops are worse still: a stock that gaps through your stop fills at the open, which the rules from the previous lesson already handle, but a spreadsheet will fill at the stop price unless told otherwise.

Charge a flat amount per trade to start. Refine it once you have real fills.

Frequency multiplies all of it. Twenty trades a year at $10 costs $200. That is small on $50,000. The same $10 at 200 trades is the $2,000 above. Short holding periods and small average gains are where costs do the most damage.

Survivorship bias

Suppose you test on the stocks that trade today. Every company that went bankrupt, was taken over, or was delisted during your test period is missing from the data. Your strategy never had the chance to buy them.

For a pullback strategy this matters more than most. The rules buy stocks after three down days. Some of the stocks that fell for three days kept falling until they were delisted, and those trades, many of them losses, are exactly the ones a survivors-only data set drops. The backtest looks better than the strategy would have been.

The fix is data that includes delisted stocks. Not every source has it. Where yours does, use it. Where it does not, the result is flattered by an unknown amount. Note that.

Look-ahead bias

Look-ahead bias is any rule that uses information not yet available when the trade was placed. The obvious form uses a day’s close to trade at its open. Subtler forms are easy to miss:

  • Buying at the close on a signal computed from that same close. You can only do this live if you calculate the signal a few minutes before the bell and send a closing order, and your fill will not always match the official close. Entering at the next day’s open is the stricter test.
  • Using company data, such as earnings, that was revised after the fact. The number in the current database may not be the one published then.
  • Choosing the universe from a list drawn up at the end of the test period.

Each one leaks a little of the future into the past. Small leaks add up.

Overfitting

The previous lesson ended on it. Every setting you tune against the same history, a 50-day average tried as 45, a ten-day exit tried as eight, fits the rule a little more closely to the past and a little less to anything else. A rule set with many tuned settings can match history almost perfectly and still have no edge at all, because what it learned was the particular sequence of moves in that stretch of data, and that sequence will not repeat.

Keep the settings few. Pick round values you could justify before seeing the data. Then hold back a section of history the rules never saw and test on it once; out-of-sample testing is the only part that counts argues why that single run matters most, and how to run a walk-forward test repeats it across several windows. The stock trading hub covers the rest.

Now the trade list is worth reading. Reading backtest results turns it into expectancy, drawdown and the losing streaks you should expect.

Check your understanding

Lesson quiz

  1. 1A strategy makes 150 trades a year with $12 of commission and slippage on each, in a $60,000 account. What share of the account do costs take each year?
    Show the answer

    B: 3%. 150 trades at $12 each is $1,800, and $1,800 divided by $60,000 is 3% of the account.

  2. 2A backtest runs only on the stocks that make up an index today. Which bias does that build in?
    Show the answer

    A: Survivorship bias. Today's members are the survivors; companies that fell out or were delisted during the test are missing, along with the trades in them.

  3. 3A rule buys at Monday's open whenever Monday's close is above the 50-day average. What is wrong with it?
    Show the answer

    C: It uses a price that was not known when the order went in. Monday's close does not exist at Monday's open, so the rule is using future information, which is look-ahead bias.

People also ask

How much slippage should I assume in a backtest?

There is no standard figure. It depends on the stocks, the order type and the size of the order against normal volume. A practical approach is to watch your own fills on a few small live trades, compare them with the prices the backtest would have used, and charge at least that gap on every simulated trade.

What is survivorship bias in a stock backtest?

It is the error of testing only on companies that still trade today. Stocks that were delisted, taken over or went bankrupt during the test period drop out of the data, so the trades a strategy would have taken in them, often losing ones, never appear in the result.