Introduction to Quant Finance · Lesson 4
Probability with coins
What a streak does and doesn't mean: after five heads in a row, is tails due?
Know the basics? Read the lesson notesFive heads in a row
A coin is fair when heads and tails are equally likely. A chance says how often something happens if you repeat it many times. A fair coin's chance of heads is 1 in 2, written ½ or 50%: about half of all flips.
This fair coin has just landed heads five times in a row. What is the chance that the next flip is heads?
The last five flips
Ask 10,000 flips
A computer flipped a simulated fair coin 10,000 times (simulated: made by a computer). Press play. Every time the five flips just before were all heads, it looks at the next flip and counts it.
10,000 simulated flips
Each square is one flip, in rows of 100: dark for heads, light for tails. Orange: the flips that came right after five heads (neighbouring ones join into a bar). The bars count what they were.
Five heads in a row came up 319 times. The next flip was heads 165 times and tails 154 times: 51.7% heads, about half. It isn't exactly half because only 319 flips are counted, and luck moves a share that small by a few points either way (51.7% is normal for this). The reason it is exactly ½ comes on the theory card.
The coin has no memory. Each flip is a fresh 50–50, whatever came before. Flips like these are called independent: one result doesn't change the chance of the next. So the answer is exactly ½, whatever came before.
Then why does a streak feel rare?
A streak is a run of the same face, heads or tails, for as long as it lasts. Before the first flip, a streak of five heads needs five things to happen. A sequence is one particular order of H and T, like HHT. Each square below is one sequence the flips can make, all equally likely. Each extra flip splits every sequence into two, one ending in heads and one in tails, so the all-heads square gets half as big each time.
The figure also checks your 10,000 flips in windows: any few flips in a row (for five, flips 1 to 5, then 2 to 6, and so on). Slide to 5 flips.
Every way a few flips can go
Each square is one equally likely sequence of flips. Coloured: the one where every flip is heads.
Five flips can go 2 × 2 × 2 × 2 × 2 = 32 ways, and one of them is all heads: 1 in 32, about 3.1%. Of your 9,996 windows of five, 319 were all heads: 3.19%.
So five heads in a row is rare, counted before you start. That rareness is what makes the next flip feel special.
Six heads, or five heads then tails?
Counted from before the first flip, which is more likely: six heads (HHHHHH), or five heads and then a tails (HHHHHT)?
Believing that tails is "due" after a run of heads has a name: the gambler's fallacy. It costs money when someone acts on it, betting more after a run of losses because a win "must" be coming: the bigger bet faces the same 50–50.
How long do streaks get?
In T H H H T, the three heads are a streak of 3, and each T on its own is a streak of 1. In your 10,000 flips, how long do you think the longest streak was?
Count every streak
Press Count. The first bar counts every streak in your 10,000 flips, the next those of 2 or more, then 3 or more, and so on.
Streaks in 10,000 simulated flips, by length
Each bar: how many streaks were at least that long.
Each bar is about half the one before. The first, 4,967 streaks, is about half the 10,000 flips, because a new streak starts each time the face changes, which happens on about half the flips (the theory card shows why). Then 2,530 of 2 or more, 1,237 of 3 or more. The reason is the halving from earlier: a streak goes one flip longer only if the next flip matches it, a 50–50. The bars run out at 12: your longest streak was 12 tails in a row, from flip 2,121.
These bars count every streak. Earlier you counted windows of five that were all heads (319), so the numbers differ. (Both are expected to land near 312, but they count different things.)
So the answer is about 12. Nothing was wrong with the coin: 10,000 flips give a long streak many chances to start.
Spot the real coin
Here are two sequences of 100 flips, read left to right, row by row. One is the first 100 of your 10,000 flips. The other was written by a made-up recipe that copies a habit people show when they make up "random" flips by hand: it avoids long runs, and never lets a streak pass 3. Which one is the real coin?
Two sequences of 100 flips
H: heads, T: tails. After you answer, each one's longest streak is coloured.
Sequence A
Sequence B
A real coin's 100 flips give a long streak many chances to start. Never going past 3 in a row is the giveaway of a made-up sequence.
For the precise: how often 100 real flips do this
In 10,000 fresh sequences of 100 simulated fair flips, 80.3% had a streak of 6 or more (exactly, counting every case: 80.7%), and the longest streak averaged 6.98. Sequence A switches face 51 times in 99 chances, sequence B 46 times; a fair coin switches about half the time, so on this count alone the two are hard to tell apart. The streaks give it away.Independent chances multiply
Two events (things that can happen, like heads on flip 1 and heads on flip 2) are independent when one happening doesn't change the chance of the other. Then the chance that both happen is the chance of the first times the chance of the second: the multiplication rule. It's the halving you saw in the squares. For k independent events with the same chance p, all happening means p multiplied by itself k times.
Why the next flip keeps its chance: of the sequences that start with five heads, the share that goes on with a sixth is (½)6 ÷ (½)5 = ½, which is p. Expecting a streak to end, or to go on, because of the flips before it is the gambler's fallacy.
- P(…)
- the chance of what is in the brackets, from 0 (never) to 1 (always)
- A, B
- two independent events
- p
- the chance of one event, as a share: ½ for heads, 0.6 for a trading rule that wins 60% of its trades
- k
- how many in a row
- pk
- p multiplied by itself k times: (½)3 = ½ × ½ × ½ = ⅛
Five heads in a row: (½)5 = 1 ÷ 32 = 0.03125, about 3.1%. Your flips: 319 of 9,996 windows of five, 3.19%.
HHHHHH and HHHHHT: (½)6 = 1 ÷ 64 each. The next flip after five heads: ½. Yours came up heads 165 times in 319, 51.7%.
- the events are independent: one result doesn't change the next one's chance;
- the chance p stays the same every time.
Results move together, as trades in the same market at the same time can, or a rule's chances shift as markets change.
Try it on new numbers. A made-up rule wins 60% of its trades, each independent of the others. What is the chance that its next three trades all win?
How long the longest streak gets
The multiplication rule also counts streaks. In H H T H there are three streaks: HH, T and H. The first flip starts one, and so does each flip that differs from the one before it (flips 3 and 4 here). So a new streak starts wherever the face changes, which happens on about half the flips: chance ½. It reaches length k or more if the next k − 1 flips match it: chance (½)k−1. Together that is ½ × (½)k−1 = (½)k for each flip, so over n flips you expect about n × (½)k streaks of k or more.
The longest streak, also called the longest run, is about the length where you expect just one (“expect” means the average over many repeats): n × (½)k = 1, so 2k = n. Streaks longer than that are too rare to expect even once. The power of 2 that gives n (210 = 1,024, so for 1,024 it is 10) is called the logarithm base 2 of n, written log₂ n.
- n
- the number of flips (or of trades that win or lose 50–50)
- k
- a streak length
- log₂ n
- the power of 2 that gives n: 210 = 1,024, so log₂ 1,024 = 10
Streaks of 5 or more: 10,000 × (½)5 = 10,000 ÷ 32 = 312.5. You counted 309.
Longest: 213 = 8,192 and 214 = 16,384, so log₂ 10,000 is between 13 and 14 (13.3 on a calculator's log₂ key). Your longest was 12.
The rule is a rough guide: the real longest streak varies from run to run, so expect a figure within about 1 or 2 of it.
- the flips are independent and 50–50;
- there are many of them (dozens or more), since it counts streaks on average.
Wins and losses aren't 50–50: then a losing streak goes on with the loss rate's chance instead of ½. Results that cluster together give longer streaks than this.
For the precise: closer than log₂ n
On 200 fresh sequences of 10,000 simulated flips, the longest streak averaged 13.88. Counting every case exactly (the script does), the average longest streak of heads or tails is 6.98 in 100 flips, 10.30 in 1,000 and 13.62 in 10,000: about log₂ n + ⅓. The longest streak of heads alone is about one shorter, about log₂ n − ⅔ (Schilling, 1990).Try it on new numbers. About how long would you expect the longest streak to be in 1,000 flips of a fair coin?
Hint: find the power of 2 closest to 1,000.
What this means when you test a rule
A backtest runs a trading rule over past prices to see what it would have done, trade by trade. Its wins and losses come in streaks too. Turn over three habits, one at a time.
- A losing streak doesn't make a win due.
If the trades are independent, the next trade has the same chance after any streak. "It's due" is the gambler's fallacy.
- Expect long streaks.
A rule that wins half its trades shows a streak of about 10 of the same result over 1,000 trades (log₂ 1,000 ≈ 10). That alone doesn't mean the rule broke or found something.
- Compare streaks with a coin's.
Before reading meaning into streaks, count those of some length or more and set the count beside n × (½)k. For streaks of 6 or more in 1,000 trades of a 50–50 rule: 1,000 ÷ 64 ≈ 16. A count near 16 is what a coin gives (anything from about 9 to 23 is ordinary); only one far above it, such as 40, more than double what a coin gives, is worth a second look.
Six losses in a row
What is the chance that its next six trades all lose? Answer in %.
Hint: the chance of one loss is 0.4. Multiply it by itself six times, then turn the share into a percent.
"It runs hot and cold"
About how many streaks of 5 or more would 1,000 flips of a fair coin give?
Hint: n × (½)k, with n = 1,000 and k = 5. (½)5 = 1 ÷ 32.
Seven losses in a row
What is the chance that the next trade wins?
Lesson done
Independent events have no memory: after any streak, the next fair flip is still 50–50. Streaks themselves are normal, because each extra flip only halves the chance, so in n flips the longest is about log₂ n. Expecting a streak to end because it has gone on long is the gambler's fallacy.
Key ideas
- Chance (probability)
- how often something happens if you repeat it many times, from 0 (never) to 1 (always)
- Fair coin
- heads and tails equally likely: ½ each
- Independent
- one result doesn't change the chance of the next
- Multiplication rule
- for independent events, the chance that all happen is the product of their chances
- Streak (run)
- a run of the same result, for as long as it lasts
- Gambler's fallacy
- expecting a streak to end (or go on) because of the results before it
- log₂ n
- the power of 2 that gives n; about the longest streak in n fair flips
- Backtest
- a trading rule run over past prices to see what it would have done, trade by trade
Formulas
P(A and B) = P(A) × P(B) · P(k in a row) = pk
streaks of k or more ≈ n × (½)k · longest streak ≈ log₂ n