Quant from Scratch by QuantWright

Introduction to Quant Finance · Lesson 5

The bell curve

What ordinary luck looks like, and how to tell when a result is out of the ordinary.

Know the basics? Read the lesson notes

One ball, sixteen pegs

A ball falls through a board with 16 rows of pegs. At each peg it bounces right or left, 50–50, like a fair coin.

Think of each peg as one simulated trade with no edge, which means it makes nothing on average: right wins 1, left loses 1. Where the ball lands is its result, the total of its 16 trades. Sixteen steps of +1 or −1 always add up to an even number, so the columns are 2 apart. Drop it.

One ball, 16 pegs (simulated)

A bounce to the right adds 1, a bounce to the left takes 1 away. Each column at the bottom is one possible result.

Ball#1
Rights–
Lefts–
Result–

Ball #1 went right 4 times and left 12 times: 4 − 12 = −8. Drop a few more if you like. Each one is 16 random steps of +1 or −1, added up.

Now 1,000 balls

Nobody aims these balls, and every bounce is 50–50. You're about to drop 1,000 of them. Where do you think most will land?

Keep your guess in mind. On the next screen you drop all 1,000.

Drop all 1,000

The same board, 1,000 balls, each with its own 16 bounces. Drop them and watch where they pile up.

1,000 balls, 16 pegs each (simulated)

Each dot is one ball, resting in the column of its result.

Balls landed0
In the middle column (0)–
Furthest left–
Furthest right–

Most land near the middle because wins and losses cancel out. Few land far away, because getting there takes a long run of one side: +12 needs 14 rights and only 2 lefts.

Why the middle fills up

Each ball's 16 bounces are one path down the board. Every bounce can go two ways, so there are 2 × 2 × 2 … sixteen times over, which is 65,536 possible paths, all equally likely. Pick a column to see how many of those paths end there.

How many of the 65,536 paths end in each column

The height of each bar is the number of paths that end in that column. Tap or drag across the columns.

Column–
Paths that end here–
Share of all paths–
Our balls that landed here–

Only one path ends at +16: right, right, right, sixteen times. 12,870 paths end at 0: any mix of 8 rights and 8 lefts, in any order. Counting them is the one step to take on trust here. The middle fills up because there are far more ways to get there.

The share of paths is also the chance that a ball lands there. 12,870 out of 65,536 is 19.6%, and 190 of our 1,000 balls (19.0%) landed in the middle column.

Fewer pegs, more pegs

Does the shape depend on there being 16 pegs? Here are the same 1,000 balls, stopped after their first few bounces. Slide from 1 peg to 16.

The same 1,000 balls after their first few pegs

Bars: how many of our 1,000 balls ended on each result, counted one by one. Dotted line: the smooth bell these counts approach.

Possible results–
Balls on the most common result–

With 1 peg there are only two places to land. With a few, you get a rough hill. By 16 it is close to the smooth bell: high in the middle, falling away evenly on both sides. It also gets wider as the pegs add up. With only 1,000 balls the bars are a little rough; more balls would follow the smooth bell more closely.

This hill is called the bell curve. A distribution is simply where results land and how often, so the bell curve is one shape a distribution can take. The bell shows up whenever many small, separate random pushes add up, even when each push on its own looks nothing like a bell.

How wide is ordinary luck?

Two numbers describe a bell. The mean is the average result: the middle of the hill. With no edge, it's 0. The standard deviation is how far a typical ball lands from the middle: the width of the hill.

The width doesn't grow as fast as the pegs, because a peg that sends a ball right is often cancelled by one that sends it left. Measured on our 1,000 balls, the typical distance from the middle is 1 after 1 peg, about 2 after 4 pegs, about 3 after 9 and about 4 after 16.

See the pattern: the distance multiplied by itself gives the number of pegs (2 × 2 = 4, 3 × 3 = 9, 4 × 4 = 16). 4 is called the square root of 16, written √16 = 4. So the standard deviation of our 16-peg board is about 4. If the board had 64 pegs, what would it be?

Rights and lefts partly cancel, so the width grows like the square root: 8 × 8 = 64, so √64 = 8, not 64. It would be 64 only if every bounce went the same way.
Rights and lefts partly cancel, so the width grows like the square root: 8 × 8 = 64, so √64 = 8, not 32.
Rights and lefts partly cancel, so the width grows like the square root: 8 × 8 = 64, so √64 = 8.
Our balls stop at 16 pegs, so 64 is the pattern carried on, not something measured here.

Between the lines

Now measure the hill in standard deviations. One counting rule holds from here to the end of the lesson: a ball counts by where it came to rest. A line at an even number runs down the middle of that column, so half of that column's balls rest on each side of it.

Drag the two lines out from the middle and watch how many balls rest between them. Try ±4 (± means plus or minus: ±4 is 4 either side of 0), one standard deviation each side, then ±8, two.

1,000 balls and two lines, the same distance from the middle

Coloured: the balls resting between the lines.

In standard deviations–
Balls resting between the lines–

One standard deviation each side, ±4: 645 of 1,000, about two thirds. Two standard deviations, ±8: 955, about 95 in 100. These count both sides; the "past the line" counts below are one side only.

This is what ordinary luck looks like on this board: most results land within one standard deviation of the middle, and almost all within two.

A result to judge

Picture a strategy that makes 16 trades, each winning or losing 1, and finishes at +4: 10 wins and 6 losses. It looks good. If it had no edge at all, how often would luck alone get it past +4? On the board: how often does a no-edge ball come to rest past the +4 line?

Keep your guess in mind. On the next screen you count it on the board.

Count it on the board

Each ball is one no-edge strategy that could have happened. Drag the marker to +4 to colour every ball resting past it. Then try +12.

No-edge balls past the marker

Coloured: the balls resting right of the marker, by the same rule as the lines.

From the middle–
Balls resting past the marker–

Past +12, three standard deviations out (12 ÷ 4 = 3), only 1 ball in 1,000 rests: the one ball in the +12 column happened to come to rest on the line's right side. That is what unusual looks like.

So, on a bell: luck alone lands past one standard deviation above the middle about 1 time in 6, and past three about 1 or 2 times in 1,000.

Theory

Why the bell keeps appearing

The bell has a textbook name: the normal distribution. It keeps appearing because of a result called the central limit theorem: add up many small, separate random effects and the total comes out close to a normal distribution, whatever each effect looks like on its own. Each peg on the board is one such effect.

Two numbers pin down the bell of a total. With no edge, its mean is 0. Its standard deviation comes from the swing of one trade and the number of trades:

σtotal = σ × √n
σtotal
the standard deviation of the total: how far luck typically puts it from the mean (σ is the Greek letter sigma)
σ
the standard deviation of one trade. A trade that is always +1 or −1 lands exactly 1 from its average of 0, so its σ is 1
n
the number of trades (pegs) added up
Worked example: your board

Each peg is +1 or −1, so σ = 1, and there are n = 16 pegs: σtotal = 1 × √16 = 1 × 4 = 4. Your 1,000 balls measured 3.97.

Holds when
  • each trade's result doesn't change the next one's (the trades are independent);
  • no single trade is huge compared with the rest;
  • there are enough trades. For +1 or −1 steps, 16 was enough; lopsided trades need more.
Breaks when

Real prices have more extreme days than a bell allows (lesson A6, Fat tails), and trades that move together spread out wider than σ × √n (lesson A11, Correlation).

Try it on new numbers. We count money in R, a fixed unit of money, like €10. A strategy makes 25 trades, each winning or losing 2R, with no edge, so its σ is 2R. What is the standard deviation of its total?

σ × √n = 2R × √25 = 2R × 5 = 10R.
σ × √n = 2R × √25 = 2R × 5 = 10R. Doubling every trade's size doubles the spread: 5R for trades of 1R, 10R for trades of 2R.
Theory

How far is far: the z-score

To judge a result, measure its distance from the mean in standard deviations. That distance is called the z-score:

z = (x − μ) ÷ σtotal
x
the result you are judging
μ
the mean of the no-edge bell: 0 here (μ is the Greek letter mu)
σtotal
the standard deviation of the total, from the last step

On a normal distribution, the share of results within each distance is always the same. This is the 68–95–99.7 rule: about 68 in 100 land within one standard deviation of the mean, 95 within two and 99.7 within three. On one side only, about 16 in 100 (1 in 6) land past +1, about 2 in 100 past +2, and about 1 or 2 in 1,000 past +3. In between, the chance shrinks smoothly: past +1.5 about 1 in 15, past +2.5 about 1 in 160. Your 1,000 balls came close: 645 within ±4 and 955 within ±8.

Worked example: the +4 strategy

z = (4 − 0) ÷ 4 = 1. Past one standard deviation on one side happens about 1 time in 6, and on the board 180 of the 1,000 balls rested past the +4 line.

Holds when
  • the result is a total of many separate trades, so the bell applies;
  • μ and σtotal come from the no-edge bell, not from the result itself.
Breaks when

Fat tails make far z-scores more common than the rule says (lesson A6, Fat tails), and trying many strategies and keeping the best makes a high z-score easy to find by luck (lesson B7, The best of many).

A rule made +18R over 36 trades, each winning or losing 1R, with no trading costs. Against the no-edge bell, what is its z-score, and what does it say?

σtotal = 1R × √36 = 6R, so z = (18 − 0) ÷ 6 = 3: past three standard deviations, which luck alone reaches about 1 or 2 times in 1,000.
σtotal = 1R × √36 = 6R, so z = (18 − 0) ÷ 6 = 3, not 0.5 (that would be dividing 18 by 36, the number of trades).
18 is the result in R, not in standard deviations. σtotal = 1R × √36 = 6R, so z = 18 ÷ 6 = 3: rare for luck, not impossible.
Rare for luck isn't proof of an edge. If this was the best of many rules tried, the best-of-many lesson (B7) shows why the bar has to go up.

What this means for a backtest

A backtest runs a trading rule over past prices to see what it would have made. Its total is a sum of many small random effects too, one per trade. Three things follow. Turn them over one at a time.

  1. With no edge, results pile into a bell around 0.

    Each trade's luck is one peg. A backtest of 100 trades with no edge is a ball dropped through 100 pegs: its total lands somewhere on a bell centred on 0.

Practice 1 of 3

A friend's backtest

The situationA friend backtested a rule over 100 trades. Each trade won or lost 1R, with no trading costs (fees and the cost of getting in and out). You haven't seen the result yet.

If the rule had no edge, how far from 0 would luck typically put the total? Type the standard deviation, in R.

Hint: on the board, 16 pegs gave a typical distance of √16 = 4. Here each trade is one peg.

100 trades are 100 pegs, so the typical distance from 0 is √100 = 10R.
Each trade is one peg, and the typical distance grows with the square root of the pegs: √100 = 10R. Wins and losses mostly cancel, so it's far less than 100R.
Practice 2 of 3

"That's clearly an edge"

The situationThe same friend shows you the result: +12R over those 100 trades. They say it's clearly an edge.

Using your last answer, what do you tell them?

+12R ÷ 10R = 1.2 standard deviations, a little past one. Luck alone lands past one standard deviation about 1 time in 6, and a little further than that is only a bit rarer, so it is not well past luck.
Three standard deviations would be +30R (3 × 10R). +12R is 1.2, a little past one, which luck alone reaches often.
+12R ÷ 10R = 1.2 standard deviations. Luck alone lands past one standard deviation about 1 time in 6, and a little further than that is only a bit rarer: everyday luck.
That doesn't prove the rule has no edge either. It means this result can't tell edge and luck apart.
Practice 3 of 3

Two of your own backtests

The situationYou tested two rules, once each. Every trade won or lost 1R. Rule A made +20R over 400 trades. Rule B made +15R over 25 trades.

Which result would be harder for pure luck to produce?

Making more isn't the test. Over 400 trades luck's typical distance is √400 = 20R, so +20R is 1 standard deviation: luck gets past that about 1 time in 6. Over 25 trades it's √25 = 5R, so +15R is 3: luck gets past that about 1 or 2 times in 1,000.
Over 25 trades luck's typical distance is √25 = 5R, so +15R is 3 standard deviations: luck gets past that about 1 or 2 times in 1,000. Over 400 trades it's √400 = 20R, so +20R is just 1: luck gets past that about 1 time in 6.
Each needs its own bell. Over 400 trades the typical distance is √400 = 20R, so +20R is 1 standard deviation; over 25 trades it's √25 = 5R, so +15R is 3. B's is much harder for luck.
Harder for luck isn't the same as proven. 25 trades is still a small test, and trading costs would pull both results down.
✓

Lesson done

Add up many small random pushes and the results pile into the same hill, the bell curve. Its middle (the mean) and its width (the standard deviation) show what ordinary luck looks like. To judge a result, ask how many standard deviations it sits from the middle of the no-edge bell.

Real trades vary in size and sometimes swing far more than a bell allows, so treat this as the clean case.

Key ideas

Distribution
where results land, and how often
Normal distribution
the bell curve; the shape of a total of many small, separate random effects (the central limit theorem)
Mean (μ)
the average result, the middle of the bell; 0 with no edge
Standard deviation (σ)
how far a typical result lands from the mean: the width of the bell (precisely, the square root of the average squared distance from the mean)
z-score
a result's distance from the mean, in standard deviations

Formulas

σtotal = σ × √n  ·  z = (x − μ) ÷ σtotal

The 68–95–99.7 rule: within 1, 2 and 3 standard deviations of the mean land about 68, 95 and 99.7 results in 100. Past +1 on one side: about 1 in 6.

Lesson notes

The bell curve is the hill that results pile into when many small random pushes are added up. Its middle (the mean) and width (the standard deviation: how far a typical result lands from the middle) show what ordinary luck looks like. To judge a result, count its standard deviations from the middle of the no-edge bell (no edge: no advantage, nothing made on average).

A board of coin flips

A ball falls through 16 rows of pegs, bouncing right or left, 50–50, like a fair coin. Treat each peg as a simulated trade with no edge: right wins 1, left loses 1. The ball's result is the total of its 16 trades, from −16 to +16 in steps of 2. The lesson's first ball went right 4 times and left 12: 4 − 12 = −8.

Why the middle fills up

16 bounces make 2 × 2 × … sixteen times over = 65,536 equally likely paths. One path ends at +16 (all rights). 12,870 end at 0: any mix of 8 rights and 8 lefts (counting them is taken on trust). So the chance of landing at 0 is 12,870 ÷ 65,536 = 19.6%. In the lesson's simulation of 1,000 balls, 190 landed there.

The bell and its width

A distribution is where results land and how often. By 16 pegs the 1,000 balls form a smooth hill, high in the middle: the bell curve. It appears whenever many small, separate random pushes add up, though real prices have more extreme days. With no edge its mean, the average result, is 0.

The standard deviation is its width. In the lesson's simulation it was 2 after 4 pegs, 2.92, about 3, after 9 and 3.97, about 4, after 16. Each distance times itself gives the pegs (4 × 4 = 16), so it is the square root of the pegs: √16 = 4. Rights and lefts partly cancel, so 64 pegs give √64 = 8, not 64. The 1,000 balls stopped at 16 pegs, so the 64-peg figure follows from the rule and was not measured.

Between the lines

A ball comes to rest somewhere inside its column, so balls in the column on a line fall on either side of it. These are counts from the lesson's simulation of 1,000 balls. ± means plus or minus. Within ±4, one standard deviation each side, rested 645 of the 1,000 balls, about two thirds. Within ±8, two standard deviations, 955, about 95 in 100. On one side only, 180 rested past +4, about 1 in 6. Past +12, three standard deviations out (12 ÷ 4 = 3), only 1 did.

Judging a backtest

A backtest runs a trading rule over past prices to see what it would have made; its total is a sum of small random effects too, one per trade. With trades of 1R (R is a fixed unit of money, like €10) and no edge, the typical distance from 0 is √16 = 4R after 16 trades, √100 = 10R after 100 and √400 = 20R after 400. Judge a result by its standard deviations from 0, not its size.

Formula: the standard deviation of a total

σtotal = σ × √n
σtotal
the standard deviation of the total: how far luck typically puts it from the mean (σ is the Greek letter sigma)
σ
the standard deviation of one trade. A trade that is always +1 or −1 lands exactly 1 from its average of 0, so its σ is 1
n
the number of trades (pegs) added up
Worked example: the lesson's board

Each peg is +1 or −1, so σ = 1, and there are n = 16 pegs: σtotal = 1 × √16 = 1 × 4 = 4. The lesson's 1,000 balls measured 3.97.

Holds whenBreaks when

Real prices have more extreme days than a bell allows (lesson A6, Fat tails), and trades that move together spread out wider than σ × √n (lesson A11, Correlation).

Formula: the z-score

A result's distance from the mean, in standard deviations, is its z-score. On a normal distribution (the bell's textbook name), about 68 in 100 land within one standard deviation, 95 within two and 99.7 within three: the 68–95–99.7 rule. One side only: past +1 about 1 in 6, past +2 about 2 in 100, past +3 about 1 or 2 in 1,000.

z = (x − μ) ÷ σtotal
x
the result you are judging
μ
the mean of the no-edge bell: 0 here (μ is the Greek letter mu)
σtotal
the standard deviation of the total, from the last formula
Worked example: a result of +4

The strategy makes 16 trades of 1R with no edge and finishes at +4 (10 wins, 6 losses). z = (4 − 0) ÷ 4 = 1. Past one standard deviation on one side happens about 1 time in 6, and on the board 180 of the 1,000 balls rested past the +4 line.

Holds whenBreaks when

Fat tails make far z-scores more common than the rule says (lesson A6, Fat tails), and trying many strategies and keeping the best makes a high z-score easy to find by luck (lesson B7, The best of many).

One more worked example

Made-up round numbers

A rule makes 64 trades, each winning or losing 2R, with no edge and no trading costs. It finishes at +24R.

Spread of one trade: σ = 2R.

Spread of the total: σtotal = 2R × √64 = 2R × 8 = 16R.

Mean with no edge: μ = 0.

z-score: z = (24 − 0) ÷ 16 = 1.5.

Luck alone gets past +1.5 standard deviations about 1 time in 15, so this is not far out for luck.

Common mistakes

Check yourself

  1. A rule makes 100 trades of 1R each with no edge. How far from 0 does luck typically put the total?
    Answerσtotal = σ × √n = 1R × √100 = 10R.
  2. The same rule finishes at +12R. What is its z-score, and what does it say?
    Answerσtotal = 1R × √100 = 10R, so z = (12 − 0) ÷ 10 = 1.2. Luck passes one standard deviation about 1 time in 6, so a little further is everyday luck. That doesn't prove there is no edge.
  3. Rule A made +20R over 400 trades, rule B +15R over 25, each trade 1R. Which is harder for luck with no edge?
    AnswerRule B. z = x ÷ (1R × √n): A is 20 ÷ 20 = 1, B is 15 ÷ 5 = 3. Luck passes 1 about 1 time in 6, and 3 about 1 or 2 times in 1,000.
  4. On the 16-peg board, what is the chance a ball lands at 0?
    Answer12,870 of the 65,536 paths end there: 12,870 ÷ 65,536 = 19.6%.
  5. A rule makes 36 trades of 2R each with no edge and finishes at +24R. What is its z-score?
    Answerσtotal = 2R × √36 = 12R, so z = (24 − 0) ÷ 12 = 2: luck passes that about 2 times in 100.

Try it yourself

Run the simulation. Every ball and number in this lesson comes from one Python script with a fixed random seed (below). Change the number of pegs or balls and see what moves.

Build a board by hand. This board of pegs is called a Galton board, after Francis Galton. Flip a coin 16 times and write down heads minus tails: that's one ball. Do it 20 times and tally the results, and a rough hill appears. A spreadsheet goes faster: 16 cells of =IF(RAND()<0.5,1,-1) and their sum make one ball; copy the row down 1,000 times.

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

As a 92-second video: Backtesting from Scratch, Part 5, the normal distribution. Same balls, same numbers.

Going further: the same bell from lopsided steps

Coin steps are symmetric: +1 or −1. Try a lopsided trade instead. It wins 3R a quarter of the time and loses 1R the other three quarters. On average it makes nothing (3 × ¼ − 1 × ¾ = 0), but one trade on its own looks nothing like a bell: two bars, far apart and uneven. Add more of them together.

The total of N lopsided trades with no edge

Bars: the exact chance of each total, from counting. Dotted line: a smooth bell with the same middle and width.

Trades added up

One trade: two bars. Four: a hill that still leans, with a long tail to the right. By 64 the bars sit close to the bell. This is the central limit theorem from the theory step, now with steps that look nothing like a bell: add up enough of them and the total still comes out close to a normal distribution. How many is "enough" depends on how lopsided the steps are. Steps with rare, very large wins need many more.

For the precise: how the lesson countsPaths: the number of paths with k rights out of 16 is C(16, k) = 16! ÷ (k! × (16 − k)!); for the middle, C(16, 8) = (16 × 15 × … × 9) ÷ (8 × 7 × … × 1) = 12,870. Measured spread of our balls after 1, 4, 9 and 16 pegs: 1.0, 2.0, 2.92 and 3.97. The counting rule: a ball's landing point is its result plus a uniform draw between −1 and +1, so a line through a column's middle splits that column about in half (a tie shared out half and half). With that rule, counting paths gives 66.8% within ±4 and 95.1% within ±8 (our balls: 64.5% and 95.5%), and 16.6% past +4 and 0.12% past +12 (our balls: 180 and 1; 175 rest past −4, and 645 + 180 + 175 = 1,000). A smooth bell gives 68.3% and 95.4% within one and two standard deviations, 15.9% past one and 0.13% past three. Counting whole columns instead gives different figures: 79.0% within ±4, 97.9% within ±8, 22.7% at +4 or better (237 of our balls: 133 in the +4 column and 104 above it) and 0.21% at +12 or better. The practice questions' exact chances, counted as "at least that total": +12R or better over 100 trades 13.6%, +20R or better over 400 trades 17.1%, +15R or better over 25 trades 0.20%.
For the preciseBoard: a ball's result is 2K − 16 with K ~ binomial(16, ½), so P(result = 2k − 16) = C(16, k) / 65,536. Mean 0, standard deviation √16 = 4; in general √n for n pegs. Our 1,000 balls: mean −0.02, standard deviation 3.97 (dividing by 1,000). The landing point inside a column is the result plus a uniform draw between −1 and +1. Lopsided trade: mean 0, standard deviation √3 ≈ 1.73 per trade, √(3n) for n trades; the total of n trades is 4W − n with W ~ binomial(n, ¼).

Honest notes

Where this comes from