Quant from Scratch by QuantWright

Introduction to Quant Finance · Lesson 1

Expectancy

Why win rate isn't the point: a strategy can win 9 trades in 10 and still go broke.

Know the basics? Read the lesson notes

A strategy that wins 9 trades in 10

A trading strategy is a rule that decides when to trade. This one wins most of its trades: each trade has a 9 in 10 chance to win. The share of trades that win is called the win rate, so this strategy's is 90%. Call it strategy A.

We count money in R: one R is a fixed amount, the same on every trade, like €10. All the trades here are simulated: made by a computer, not real. Each win makes 1R. Each loss costs 10R, because the rule lets a losing trade run a long way before it gives up. The account starts at 100R. Take ten trades.

Strategy A, one simulated account

Account in R. A win adds 1R, a loss takes 10R.

Trades 0  ·  wins 0  ·  account 100R

Ten trades, nine wins: a 90% win rate, and the account is at 99R, below the 100R it started with. One loss took back more than all nine wins.

Which one makes money?

Here is a second strategy, B. It wins less often than it loses, but its wins are twice the size of its losses. Picture each one taking 1,000 trades. Which one ends up above its 100R start at the end?

The two strategies

Strategy Awins 90% · win +1R · loss −10R
Strategy Bwins 40% · win +2R · loss −1R
Keep your answer in mind. Next, each strategy runs 1,000 trades in 10,000 simulated accounts.

10,000 accounts of strategy A

One account can be lucky or unlucky, so give strategy A to 10,000 simulated accounts. Each starts at 100R and takes 1,000 trades. An account that falls to 0R is ruined: it has nothing left, so it stops trading. Press play.

Strategy A: 10,000 simulated accounts, 1,000 trades each

200 of the accounts are drawn. The numbers below count all 10,000.

Trade0
Win rate so far–
Below the 100R start0%
Ruined0%

The win rate ended at 90.0%. Yet after 1,000 trades 85.0% of the accounts are below their start (the ruined ones included), and 65.8%, about 2 in 3, hit zero. The other 19.2% are down but still trading.

On the next screen, the reason.

The reason fits in one line

Take ten typical trades of strategy A: nine wins and one loss, like the ten you took at the start. Add them up. What do the ten trades make together?

That counts only the wins. The one loss takes 10R back: +9R − 10R = −1R.
Right size, wrong sign. The wins bring +9R and the loss takes 10R: +9R − 10R = −1R.
The nine wins bring +9R and the one loss takes 10R: +9R − 10R = −1R.
That counts only the loss. The nine wins add 9R back: −10R + 9R = −1R.

−1R over ten trades is −0.1R a trade. The average result per trade is called expectancy. Written for any strategy, it is one line. The loss rate is the share of trades that lose, 100% minus the win rate, and the average win and average loss are the sizes of the wins and of the losses:

Expectancy = win rate × average win − loss rate × average loss
Strategy A: 0.9 × 1R − 0.1 × 10R = 0.9R − 1R = −0.1R a trade
(Average win: the size of a typical winning trade. Average loss: the size of a typical losing one.)

Over 1,000 trades, −0.1R a trade adds up to −0.1R × 1,000 = −100R: about the whole 100R start. Luck spreads accounts around that: a few end well up, but most hit 0R before trade 1,000 and stop there. A 90% win rate can't fix it, because the 10% that lose cost more than the 90% that win.

Now strategy B

Strategy B wins 40% of its trades, so it loses 60%. Its wins pay 2R and its losses cost 1R. Use the same line: what is its expectancy?

The wins bring 0.4 × 2R = 0.8R. The losses take 0.6 × 1R = 0.6R. 0.8R − 0.6R = +0.2R a trade.
The losses come more often, but each is half the size of a win. Wins: 0.4 × 2R = 0.8R. Losses: 0.6 × 1R = 0.6R. 0.8R − 0.6R = +0.2R.
0.8R is only the wins' part (0.4 × 2R). The losses take 0.6 × 1R = 0.6R back, which leaves +0.2R.
Over 1,000 trades, +0.2R a trade adds up to +0.2R × 1,000 = +200R on average.

10,000 accounts of strategy B

The same test: 10,000 simulated accounts, 100R each, 1,000 trades. Strategy A's accounts stay in the background in light grey. The dashed line is where +0.2R a trade leads on average: 100R + 200R = 300R after 1,000 trades.

Strategy B: 10,000 simulated accounts, 1,000 trades each

200 of the accounts are drawn. The numbers below count all 10,000.

Trade0
Win rate so far–
Below the 100R start0%
Ruined0%

B won only 40.0% of its trades, and none of its 10,000 accounts ended below the start. On average they ended at 299.9R, next to the 300R the dashed line points to.

Build your own

Set a win rate with the first slider. The second slider sets the size of a win and the size of a loss together. The dashed line is the expectancy: where the account heads on average, trade after trade. The solid line is one simulated account taking 250 trades with those settings. Find a setting that wins less than half the time and still makes money on average.

Your strategy, 250 trades

Account in R, starting at 100R. Dashed: the average path. Solid: one simulated account.

Expectancy–
Dashed line at trade 250–
This account–

Found one. Now press Run again a few times: the same settings, different luck. The account wanders around the dashed line, but the line itself moves only when you change the settings.

What would A need?

Strategy A's wins pay 1R and its losses cost 10R, so each loss wipes out ten wins. What win rate would A need just to break even? Break-even means the average trade makes nothing: an expectancy of zero.

90% falls just short: 0.9 × 1R − 0.1 × 10R = −0.1R. Each loss needs ten wins to pay for it, so A needs 10 wins for every loss: 10 of every 11 trades, 90.9%.
Each loss needs ten wins to pay for it, so A needs 10 wins for every loss: 10 of every 11 trades, 90.9%. Its 90% falls just short.
Less than that. Each loss needs ten wins to pay for it, so 10 wins for every loss is enough: 10 of every 11 trades, 90.9%.
The same sum works for B the other way round: one 2R win pays for two 1R losses, so B needs 1 win in every 3 trades: 33.3%.

The chart below puts every strategy on one map. Across is the win rate. Up is how big a win is compared with a loss: at the bottom, 1 : 10 (wins of 1R, losses of 10R, like A); in the middle, 1 : 1; at the top, 10 : 1. The line marks the win rate where the average trade breaks even. It curves because the bigger the wins are compared with the losses, the fewer wins are needed: 90.9% at 1 : 10 (like A), 33.3% at 2 : 1 (like B).

Where the average trade breaks even

Across: the win rate. Up: the size of a win against the size of a loss. On the line, expectancy is zero.

B's 40% clears its line at 33.3%. A's 90% misses its line at 90.9%. A high win rate is only good enough when it clears the line for its own sizes.

Theory

Expectancy, and why it decides the long run

Here is the one line from earlier in the symbols most books use. The average result per trade is the expectancy, also called the expected value, E. Over n trades, the total is about n × E.

Why does an average decide the long run, when every single trade is luck? The law of large numbers: as trades add up, the average result per trade settles toward E. So over enough trades, whether E is below zero or above it decides where most accounts end: below zero, most end down; above zero, most end up.

Set E = 0: p × W = (1 − p) × L = L − p × L, so p × (W + L) = L, which gives the break-even win rate p* = L ÷ (W + L).

E = p × W − (1 − p) × L
total ≈ n × E
p* = L ÷ (W + L)
p
the win rate, as a share (0.9 for 90%); 1 − p is the loss rate
W
the average win, in R
L
the average loss, in R, as a positive size (10, not −10)
E
the expectancy: the average result per trade, in R
n
the number of trades
p*
the break-even win rate: the p at which E = 0
Worked example

Strategy B: E = 0.4 × 2R − 0.6 × 1R = +0.2R. Over n = 1,000 trades, n × E = +200R. Its 10,000 accounts gained 299.9R − 100R = 199.9R on average.

The settling: in 9 of B's accounts in 10 (all but the luckiest and unluckiest 1 in 20), the average per trade was between −0.40R and +1.10R after 10 trades, and between +0.12R and +0.28R after 1,000, close to +0.2R.

Break-even for A: p* = 10 ÷ (1 + 10) = 0.909, or 90.9%. For B: p* = 1 ÷ (2 + 1) = 0.333, or 33.3%.

Holds when
  • trades are independent: one result doesn't change the next one's chances;
  • p, W and L stay the same through the whole run;
  • the account lasts: one that hits 0R stops trading, so its long run never comes.
Breaks when

The account hits 0R first (lesson A19, Ruin). Costs come off every trade and lower E (Costs (lesson A16)). p, W and L measured from only a few trades are estimates, not the true values (Sample size (lesson A10)).

The situationA new rule (made-up numbers): it wins 25% of its trades, its average win is 4R and its average loss 1R. It takes 400 trades.

About how much does it make over the 400 trades, on average, in R?

Hint: first E = p × W − (1 − p) × L, with p = 0.25. Then multiply by n = 400.

E = 0.25 × 4R − 0.75 × 1R = 1R − 0.75R = +0.25R a trade, and n × E = 400 × 0.25R = +100R. It wins only 1 trade in 4, yet its break-even is p* = 1 ÷ (4 + 1) = 20%, and 25% clears it.
E = 0.25 × 4R − 0.75 × 1R = 1R − 0.75R = +0.25R a trade (0.25 alone is the average trade, not the total). Over 400 trades: n × E = 400 × 0.25R = +100R. Its break-even is p* = 1 ÷ (4 + 1) = 20%, and its 25% clears it.

What this means when you test a rule

Running a trading rule over past prices to see what it would have done, trade by trade, is called a backtest. Its report usually lists the number of trades, the win rate, the average win and the average loss. Three habits follow. Turn them over one at a time.

  1. Never judge by the win rate alone.

    Put the win rate, the average win and the average loss into the expectancy line. Here a 90% win rate lost on average and a 40% one made money.

One last check

Two backtests both win 60% of their trades. Can one make money on average while the other loses?

The win rate counts the wins, not their size. Wins of 1R and losses of 1R: 0.6 × 1R − 0.4 × 1R = +0.2R a trade. Wins of 1R and losses of 2R: 0.6R − 0.8R = −0.2R.
Wins of 1R and losses of 1R: 0.6 × 1R − 0.4 × 1R = +0.2R a trade. Wins of 1R and losses of 2R: 0.6R − 0.8R = −0.2R. Same win rate, opposite results.
The number of trades doesn't change the average trade; the sizes do. With 1R wins, 1R losses give +0.2R a trade and 2R losses give −0.2R.
Practice 1 of 3

The 85% signal service

The situationA paid service that sends people trades to copy (made up for this question) advertises “85% winning trades”. Further down, its own results page lists an average win of 0.5R and an average loss of 4R.

Do its own numbers say the average trade makes money?

The win rate leaves out the sizes. The wins bring 0.85 × 0.5R = 0.425R, the losses take 0.15 × 4R = 0.6R: −0.175R a trade.
The wins bring 0.85 × 0.5R = 0.425R and the losses take 0.15 × 4R = 0.6R, so the average trade is −0.175R. With those sizes it would need 88.9% just to break even.
More trades make a negative average add up to more, not less. The average trade is 0.85 × 0.5R − 0.15 × 4R = −0.175R.
A useful question for any high win rate: what is the average loss?
Practice 2 of 3

Your own backtest

The situationYou backtest a rule (made-up numbers for this question). The report: 200 trades, win rate 45%, average win 1.8R, average loss 1R.

What is its expectancy per trade, in R?

Hint: win rate × average win, minus loss rate × average loss. The loss rate is 100% − 45% = 55%, which is 0.55.

0.45 × 1.8R = 0.81R from the wins, 0.55 × 1R = 0.55R to the losses: +0.26R a trade. The trade list agrees: 90 wins × 1.8R = 162R, 110 losses × 1R = 110R, 52R in all over 200 trades, which is 0.26R each.
The wins bring 0.45 × 1.8R = 0.81R and the losses take 0.55 × 1R = 0.55R, so the average trade is +0.26R. Check it on the trade list: 90 wins × 1.8R = 162R, 110 losses × 1R = 110R, 52R in all over 200 trades, 0.26R each.
Practice 3 of 3

Thirty out of thirty

The situationA friend shows you a backtest (made-up numbers): 30 trades, 30 wins, +1R each. Their rule closes a losing trade only once it has lost 20R, and none of the 30 trades got that far.

What do 30 wins out of 30 tell you about the rule's expectancy?

+1R is the average of these 30 trades, but the 20R losses haven't shown up yet. One loss costs 20 wins, so the rule needs 20 wins in every 21 trades just to break even; 30 wins in a row can't show whether it gets there.
One loss costs 20 wins, so this rule only breaks even if it wins 20 trades in every 21: about 95.2%. A rule that wins a little less often than that loses money on average, yet can easily win 30 in a row.
Not necessarily. Above its break-even win rate (about 95.2%) it makes money; below it, it loses. Thirty winning trades can't tell you which side this one is on.
✓

Lesson done

Win rate tells you how often a strategy wins. Expectancy tells you what the average trade pays. Here a 90% win rate with big losses lost money on average, and a 40% win rate with bigger wins made it.

Key ideas

R
a fixed amount of money, the same on every trade; results are counted in it
Win rate / loss rate
the share of trades that win / lose; together they make 100%
Average win / average loss
the size of a typical winning / losing trade
Expectancy (expected value)
the average result per trade
Break-even win rate
the win rate at which the average trade makes nothing: an expectancy of zero
Law of large numbers
as trades add up, the average result per trade settles toward the expectancy
Ruined
an account that falls to 0R: it stops trading
Backtest
a trading rule run over past prices to see what it would have done, trade by trade

E = p × W − (1 − p) × L

total ≈ n × E

p* = L ÷ (W + L)

Lesson notes

Win rate tells you how often a strategy wins. Expectancy tells you what the average trade pays: win rate × average win − loss rate × average loss. A strategy that wins 9 trades in 10 can lose money on average if its losses are big, and one that wins 4 in 10 can make money if its wins are bigger.

A strategy that wins 9 in 10

Money is counted in R: a fixed amount, the same on every trade, like €10. Strategy A wins 9 trades in 10, so its win rate (the share of trades that win) is 90%. Each win makes 1R and each loss costs 10R. The account starts at 100R. In ten trades with nine wins and one loss, the account is at 99R: the loss took back more than all nine wins.

10,000 accounts

Give A to 10,000 simulated accounts (the results of the lesson's simulation, one run, so you cannot rework them by hand), each starting at 100R and taking 1,000 trades. An account that falls to 0R is ruined: it stops trading. The win rate came out at 90.0%, yet after 1,000 trades 85.0% of the accounts were below their start (ruined ones included), and 65.8% had hit zero. The other 19.2% were down but still trading.

The reason in one line

Ten typical trades of A: nine wins and one loss make +9R − 10R = −1R, or −0.1R a trade. The average result per trade is the expectancy. For any strategy, with the loss rate being 100% minus the win rate: expectancy = win rate × average win − loss rate × average loss. For A: 0.9 × 1R − 0.1 × 10R = 0.9R − 1R = −0.1R. Over 1,000 trades that adds up to −0.1R × 1,000 = −100R, about the whole start. The 10% of trades that lose cost more than the 90% that win.

Strategy B

B wins 40% of its trades, so it loses 60%. Its wins pay 2R and its losses cost 1R. Expectancy: 0.4 × 2R = 0.8R from the wins, 0.6 × 1R = 0.6R lost, so +0.2R a trade, or +200R over 1,000 trades. In the same test none of B's 10,000 accounts ended below the start. They averaged 299.9R, next to the 300R (100R + 200R) the expectancy points to.

Direction, not destination

Expectancy says where accounts head on average, not where one lands. With the same settings, one account's balance zigzags but tends to follow a slope of E per trade. That slope changes only when the win rate or the sizes change.

The break-even win rate

Break-even means the average trade makes nothing: an expectancy of zero. Each of A's losses needs ten wins to pay for it, so A needs 10 wins in every 11 trades: 90.9%, and its 90% falls just short. One of B's 2R wins pays for two 1R losses, so B needs 1 win in 3: 33.3%, and its 40% clears it. A high win rate is enough only when it clears the break-even rate for its own sizes.

Formula: expectancy, the long run and break-even

The expectancy is also called the expected value, E. By the law of large numbers, as trades add up the average result per trade settles toward E, so whether E is below or above zero decides where most accounts end. Setting E = 0 gives p × W = (1 − p) × L, so p = L ÷ (W + L): the break-even win rate.

E = p × W − (1 − p) × L
total ≈ n × E
p* = L ÷ (W + L)
p
the win rate, as a share (0.9 for 90%); 1 − p is the loss rate
W
the average win: the average over the winning trades only, in R
L
the average loss: the average over the losing trades only, in R, as a positive size (10, not −10)
E
the expectancy: the average result per trade, in R
n
the number of trades
p*
the break-even win rate: the p at which E = 0
Worked example

Strategy B: E = 0.4 × 2R − 0.6 × 1R = +0.2R. Over n = 1,000 trades, n × E = +200R. Its 10,000 accounts gained 299.9R − 100R = 199.9R on average.

The settling: in 9 of B's accounts in 10 (all but the luckiest and unluckiest 1 in 20), the average per trade was between −0.40R and +1.10R after 10 trades, and between +0.12R and +0.28R after 1,000, close to +0.2R.

Break-even for A: p* = 10 ÷ (1 + 10) = 0.909, or 90.9%. For B: p* = 1 ÷ (2 + 1) = 0.333, or 33.3%.

Holds whenBreaks when

The account hits 0R first (lesson A19, Ruin). Costs come off every trade and lower E (Costs (lesson A16)). p, W and L measured from only a few trades are estimates, not the true values (Sample size (lesson A10)).

One more worked example

New made-up numbers

A rule wins 30% of its trades, with an average win of 3R and an average loss of 1R. It takes 200 trades.

E = 0.3 × 3R − 0.7 × 1R = 0.9R − 0.7R = +0.2R a trade.

Total: n × E = 200 × 0.2R = +40R.

Break-even: p* = 1 ÷ (3 + 1) = 25%, and 30% clears it.

Common mistakes

Check yourself

  1. A rule wins 50% of its trades, with an average win of 3R and an average loss of 2R. What is its expectancy?
    Answer

    E = 0.5 × 3R − 0.5 × 2R = 1.5R − 1R = +0.5R a trade.

  2. A rule wins 70% of its trades, with an average win of 1R and an average loss of 3R. Does the average trade make money?
    Answer

    E = 0.7 × 1R − 0.3 × 3R = 0.7R − 0.9R = −0.2R. Its break-even is 3 ÷ (1 + 3) = 75%, and 70% falls short.

  3. An expectancy of +0.2R a trade: about what does it make over 500 trades?
    Answer

    500 × 0.2R = +100R, on average.

Try it yourself

Run the simulation. Every account and number in this lesson comes from one Python script with a fixed random seed (below). Change the win rate or the sizes of the wins and losses and see what moves.

Work it out by hand. Take any list of trade results in R, add them up and divide by the number of trades: that average is the expectancy. In a spreadsheet, AVERAGE of the results column does it in one cell. Then check it against win rate × average win − loss rate × average loss.

About QuantWright

QuantWright, which publishes this course, sells backtesting software. Its free setup test takes one setup, codes it, backtests it with commission and slippage, two trading costs: the broker's fee, and the gap between the price you wanted and the price you got. Then it emails you the stats. Among them are the number of trades, the win rate, the average win and the average loss: the inputs to the expectancy line. One setup, free, run by hand, so allow a few days; no charts or prices. quantwright.com/test

The code behind every number (Python, seed 20261102)
Loading…

As a 78-second video: Backtesting from Scratch, Part 1, “The 90% win rate that goes broke”. Same simulated accounts, same numbers.

Going further: the average sets the direction, the spread sets the luck

Expectancy is an average, so it says where accounts head, not where any one account lands. How far they scatter depends on how far one trade can land from that average. A's trades are +1R or −10R, 11R apart. B's are +2R or −1R, 3R apart. Over 1,000 trades, A's total typically lands about 104R either side of its −100R average, and B's about 46R either side of +200R. That is how A's luckiest account could end at 396R while B's unluckiest still ended at 147R, and why one account of a rule with rare, big losses says so little about its average.

For the preciseWith p, W and L as on the Theory card, one trade's standard deviation is (W + L)·√(p(1 − p)): A 3.30R, B 1.47R. Over n independent trades it grows by √n: A 104.4R, B 46.5R over 1,000. Without the floor at 0R, A's 1,000 trades add up to less than zero exactly when it wins 909 or fewer (11W − 10,000 < 0), which happens 84.2% of the time (binomial, exact); with the floor, 85.0% of the 10,000 accounts ended below the start. The floor also lifts A's average final account to 35.5R, above the 0R that −100R from a 100R start points to, because a ruined account stops losing. B's average: 299.9R.
For the precise: the drawsSeed 20261102, the same draws as the Short: for each strategy, 10,000 accounts × 1,000 uniform numbers, A's first; a trade wins when its number is below the win rate. The win rate shown counts only trades actually taken (a ruined account takes none): A 89.99%, B 40.00%. After 250 trades, 69.7% of A's accounts were below the start and 12.9% were ruined; the first ruin came at trade 41. The builder above reuses A's first 250 numbers for accounts 1 to 20, so its account 1 at 90% with wins of 1R and losses of 10R is the account you traded at the start, and changing the settings keeps the same luck.

Honest notes

Where this comes from