Introduction to Quant Finance · Lesson 16
Costs
How much of a trade's average profit is left after paying to trade?
Know the basics? Read the lesson notesEvery trade comes with a bill
A backtest replays a trading rule on past data. Real trading adds something a backtest can leave out: what you pay just to make a trade. It has three parts; together these are the transaction costs. Tap each one.
The fee your broker, the firm that places your trades, charges for each trade.
At any moment, the price you can buy at is a little higher than the price you can sell at. That gap is the spread. Buy and sell straight away, and you have lost the gap.
The price you actually get is often a little worse than the price you saw when you decided, because the price moves before your order goes through.
All three are paid on every trade, whether it wins or loses. In this lesson they come to $6 a trade together. That is an assumed number, and "one trade" means getting in and getting out again.
One trade, before costs
Here is a simulated trade: made up by a computer, not taken from a market. It risks $100 to make $100, so a win adds $100 and a loss takes $100. It wins 52% of the time. That is its win rate, the share of trades that win.
On average, what does one trade make?
A guess before the bill arrives
The edge is +$4 a trade. How much can one trade cost before that edge is gone, so the average trade makes nothing?
Add the cost
Drag the cost of one trade up from $0. It comes off every trade: a win keeps less than $100, and a loss costs more than $100. The lower chart shows where a $10,000 account ends up after 1,000 such trades on average: $10,000 plus 1,000 times the average trade.
One simulated trade: the edge, the cost, what is left
Dollars per trade. Assumed: risk $100 to make $100, 52% wins. The cost bar starts where the edge ends and reaches left by the cost.
At $4 a trade, the cost equals the edge: the average trade makes $0 and the average account ends where it started. Past $4, the average trade loses money.
At the $6 this lesson assumes, a win keeps $94, a loss costs $106, and the average trade is +$4 − $6 = −$2. Over 1,000 trades, the average account goes from $10,000 to $8,000 instead of $14,000.
For the precise
Average trade after costs = p × W − (1 − p) × L − c, with win rate p = 0.52, win W = $100, loss L = $100 and cost c. The edge vanishes at c = p × W − (1 − p) × L = $4. In R, with 1R = the $100 at risk: edge +0.04R, cost 0.06R, after costs −0.02R. The average trade is also called the expectancy; a result before costs is called gross, and after costs net.One trader, 1,000 trades
Now a simulated trader starts with $10,000 and makes 1,000 of these trades in a year. Each trade has a 52% chance to win, and each one costs $6. Press play and watch two lines: the account before costs (grey) and after costs (coloured).
One simulated trader: the same trades, before and after costs
Account in dollars. Start $10,000. Every trade: +$100 or −$100, then −$6.
This trader won 514 of 1,000 trades. Before costs the account rose $2,800: 514 wins and 486 losses is 28 more wins than losses, at $100 each. After costs it fell $3,200. The last screen's −$2,000 was the average of many traders; this one fell $1,200 further, by bad luck (the theory step measures luck's size).
The gap is 1,000 × $6 = $6,000. It grows by exactly $6 on every trade, win or lose, so the gap between the two lines widens at a steady pace, whatever the trades do.
One trader could be luck. Try 10,000.
Here are 10,000 simulated traders with the same rule, each with their own 1,000 trades. A trader is ahead if the account finished above the $10,000 it started with. Before costs, 88.8% are ahead. Not all: luck still hands some traders a losing run even though the average trade is +$4. Guess what share is still ahead after the $6 cost, then add it.
10,000 simulated traders: where each account finished after 1,000 trades
Each bar counts the traders who finished at that amount. Coloured: ahead. Once the cost is added, the dotted outline shows where they finished before costs.
Every trader kept the same wins and losses and paid the same $6,000, so the whole picture slid $6,000 to the left and kept its shape. A quarter are still ahead, but only by luck: the average trade now loses $2, but a lucky run of wins can still put some traders ahead.
A busy rule pays the bill more often
Same traders, same 52%, same $6 a trade. Now change how many trades they make in a year. Each trade is partly luck. With few trades, luck can beat a small average. With many, the sure part, the number of trades × the average trade, grows faster than luck, which grows only with √n, the square root of the number of trades (lesson A5, The bell curve; more on the theory step), so the average decides: +$4 a trade before costs, −$2 after. If the edge is bigger than the cost, more trades help you. If it's smaller, they hurt. Slide from 250 trades (1 a day, over 250 trading days a year) to 4,000 (16 a day), and watch who is ahead. The Before costs / After costs switch shows both.
More trades in a year, the same cost per trade
Lines: 200 of the simulated traders (coloured if ahead at the end). Dashed: the average of all 10,000 traders. Percentages count all 10,000 traders. Accounts can go below $0 here because the simulation never stops them; a real account would stop at $0.
After costs: 37.3% ahead at 1 trade a day, 25.2% at 4 a day, 9.7% at 16 a day. Before costs it goes the other way: 70.9%, 88.8%, 99.4%.
After costs at 4,000 trades, the dashed average ends at $1,928, not exactly $10,000 − 4,000 × $2 = $2,000: even an average of 10,000 traders keeps a little luck.
That is luck evening out as the trades add up. When the average trade after costs is below zero, every extra trade makes a loss more likely.
The finish line moves
With no cost, a trade that risks $100 to make $100 breaks even, making $0 on average, at a 50% win rate. With a $6 cost, what win rate does it need just to break even?
What is left after costs, and why more trades make it certain
A result before transaction costs is gross; after them, net. Each trade's net is its gross minus its cost, and the cost is paid on every trade, so the costs grow in step with the number of trades. The cost that leaves the average trade at exactly $0, the break-even cost, is the gross edge itself.
Luck spreads each trader's total around that average. From lesson A5 (The bell curve), its typical size, the standard deviation, grows only with √n: four times the trades brings four times the average net total but only twice the luck. So with enough trades the average outgrows the luck: nearly everyone ends ahead if the edge is bigger than the cost, and nearly everyone behind if it is smaller.
- n
- the number of trades
- g
- the gross edge: the average profit of one trade before costs
- p
- the win rate: the share of trades that win
- c
- the cost of one trade, paid win or lose. At c = g the net is $0: the break-even cost
- σtotal
- luck: the standard deviation of a trader's total, how far it typically lands from the average net total
- σ
- the standard deviation (sigma) of one trade's result. For a trade that wins or loses the same amount, σ is about that amount (here $100)
- W, L
- what a win makes and a loss takes, before costs
- p*
- the break-even win rate. After costs a win makes W − c and a loss takes L + c. Break-even: p × (W − c) = (1 − p) × (L + c); the c's cancel in the sum, (W − c) + (L + c) = W + L, so p* = (L + c) ÷ (W + L)
g = 0.52 × $100 − 0.48 × $100 = $4 and c = $6, so each trade nets $4 − $6 = −$2. Over n = 1,000 trades: 1,000 × (−$2) = −$2,000, which is why the average account finished near $8,000 ($7,992 in the simulation). The bill alone was 1,000 × $6 = $6,000. One trader is not the average: card 5's trader finished at −$3,200, not −$2,000. The difference is luck.
With σ ≈ $100, σtotal ≈ $100 × √1,000 ≈ $3,160. To end ahead, a trader needed luck worth more than $2,000, a z-score (how many standard deviations a result sits from the average, lesson A5) of $2,000 ÷ $3,160 ≈ 0.63: less than one standard deviation. Luck clears one standard deviation about 1 time in 6 (about 68 in 100 land within one standard deviation either side, lesson A5, so about 16 in 100 land above it), so this lower bar was cleared more often: by 25.2%.
At 4,000 trades the average is 4,000 × (−$2) = −$8,000, but luck only doubles (√4,000 = 2 × √1,000), to about $6,300. Now a trader needs more than one standard deviation of luck, so fewer than 1 in 6 are ahead: 9.7%.
Break-even win rate: p* = (100 + 6) ÷ (100 + 100) = 53%, card 8's answer.
- every trade pays the same cost (here $6);
- the trades are independent (one trade's result doesn't change the next) and alike, which the √n rule needs (lesson A5);
- g is the rule's true average, not one backtest's lucky estimate.
Big orders move the price against you, so the cost per trade rises with order size (lesson D15, Liquidity and market impact). A gross edge picked as the best of many tries is often luck (The best of many (lesson B7)).
Try it on new numbers. A backtest makes +$10 a trade before costs, over 800 trades. Its costs come to $7 a trade. What is its net total, in dollars?
What this means for your backtest
Three habits follow from everything above. Turn them over one at a time.
- Find the bill.
Every backtest assumes some cost per trade, sometimes zero. Look for commission, spread and slippage in its settings or notes. With all three at zero, you are seeing results before costs.
- Set the average trade against the cost of one trade.
Divide the result before costs by the number of trades: that is the edge. If that average trade isn't clearly bigger than what one trade costs you, the edge doesn't survive, however many trades there are. Compare the cost with the average trade, not with the amount at risk: $6 is small next to $100 and bigger than a $4 edge.
- Charge a little more than you expect.
Costs are estimates. Real ones change with the market, the size of your order and your broker. If an edge survives only at the cheapest cost you can imagine, it is fragile. Run the backtest again at a higher cost and see what is left.
The course seller's result
Before you pay, what does the rule look like after your costs?
Your own rule's finish line
What win rate does it need just to break even? Type a percentage.
Hint: after costs, a win keeps $200 − $10 and a loss costs $200 + $10. Break-even is the loss divided by the win plus the loss.
Two versions of one idea
Which version has more left after costs?
Lesson done
Every trade pays transaction costs, win or lose: commission, the spread and slippage. A backtest's average trade has to be bigger than those costs, and a busy rule whose edge is below its cost loses more surely.
Key ideas
- Transaction costs
- what one trade costs, win or lose: commission, the spread and slippage
- Commission
- the broker's fee for each trade
- Spread
- the gap between the price you can buy at and the price you can sell at
- Slippage
- getting a worse price than the one you saw when you decided
- Edge (gross)
- the average profit of one trade before costs
- Net
- what is left after costs
- Break-even cost
- the cost that leaves the average trade at $0; it equals the gross edge
- Break-even win rate
- the win rate at which the average trade after costs is $0
Formulas
Net total = n × (g − c) · σtotal = σ × √n
Break-even win rate = loss after costs ÷ (win after costs + loss after costs)