‹ Backtest Strategies Lesson 9 of 17
Contents Lesson 9 of 17

5 min read · professional

Transaction costs, and why the default is on

Unit 1 put a cost line on your first chart while it was still flat. This lesson gives it a number and shows what it does to a strategy that trades.

What the number stands for

costBps: 10 is one tenth of one percent, charged per trade — so a round trip costs twenty. It is not a commission; it is a bundle of everything that makes your realised price worse than the price on the chart:

  • the broker's fee, whatever it is on your account;
  • half the bid-ask spread, because you buy at the ask and the chart plots the close;
  • exchange and regulatory fees;
  • and, on anything but the smallest order, the fact that your own buying moves the price.

Ten basis points is a defensible retail default for liquid US large caps and it is what this course uses. It is a choice, not a fact. On a thin small cap it is optimistic by a factor of several, and on FX majors it is pessimistic. The honest move is to state it in the report rather than to find the perfect number.

The arithmetic that kills most strategies

Cost scales with turnover, and turnover is the thing beginners never count.

A rule trading 50 round trips a year at 10 bps each way pays 50 × 20 = 1000 bps of notional turnover cost, before it has made anything. A rule doing a round trip every day pays roughly 250 of them — 5000 bps.

Those are notional figures, added up. Applied properly they compound against a shrinking balance, so the actual equity drag is slightly less: 1 − 0.999¹⁰⁰ = 9.5% and 1 − 0.999⁵⁰⁰ = 39.4%. The difference is not the point — the point is that both numbers are larger than any equity edge you are likely to find.

This is why the cost line went on the chart before the strategy existed. The gap between the gross and net curves is not a detail at the end; on most rules it is the whole result.

Where costs enter the code

At the position change, not at the end:

if (position.units !== previous.units) {
  equity *= 1 - params.costBps / 10_000;
}

Two mistakes to avoid. Do not subtract a total at the end — costs compound against a shrinking balance and the order matters. And do not charge for holding; a position held for a year costs the same to open as one held for a day, which is precisely why holding longer is how most rules survive costs at all.

Print the number that makes it real

Alongside net return, print total cost as a percentage of starting equity and cost as a fraction of gross return.

That second one is the sentence that ends arguments: "the strategy made 14% gross and paid 11% of it in costs." A person looking at a net number alone will keep believing the edge is real and the costs are a nuisance. The fraction tells them which is which.

The finance behind it

What a trade costs in practice, itemised, before you decide what to put in costBps: What does a trade really cost?

Try it now

Run your strategy at 0, 5, 10 and 25 bps and put the four net returns in a row. If the result flips sign somewhere in that range, you do not have a strategy — you have a cost assumption, and the honest report says so.