Introduction to Quant Finance · Lesson 2
Random walks
Why a running total of coin flips looks like a price chart, and why its spread grows with the square root of time.
Know the basics? Read the lesson notesOne coin a day
Picture a made-up price that starts at €100. Every day a fair coin (heads and tails equally likely) decides its move: heads, it goes up €1; tails, it goes down €1. Nothing else moves it. Take a few days one at a time, then walk the rest.
Walk #1: a made-up price, one coin flip a day (simulated)
Heads: up €1. Tails: down €1. The dashed line is the €100 it started at.
Walk #1 had 193 heads and 207 tails, so it ended at €100 + 193 − 207 = €86. The price on any day is the start plus every step so far. A running total of random steps like this is called a random walk.
Walk again
Same coin, same rules, new flips. Press Walk again to see what other walks of 400 days look like.
Walks of 400 days, each from €100 (simulated)
The newest walk is coloured; earlier ones stay in grey.
Walk #3 climbed from €93 on day 55 to €136 on day 360. Walk #4 fell from €120 on day 160 to €100 on day 340. On a chart, one looks like an uptrend and the other like a long slide from day 160 to day 340, yet every day of every walk was the same fair coin.
A coin has no memory, so a run of heads says nothing about the next flip. But the run stays in the running total, and nothing pulls the price back to €100. A walk keeps whatever luck it had, and luck that piles up one way looks like a trend.
1,000 walks at once
One walk tells you little. Here are 1,000, each with its own, separate coin flips, all starting at €100. To say how far they spread, the numbers under the chart show the typical distance from €100: square each walk's distance from €100 (multiply it by itself, so €3 below counts like €3 above) and average those squares. Then take the square root, the number that, multiplied by itself, gives that average: √100 = 10 because 10 × 10 = 100.
1,000 walks, the first 100 days (simulated)
Each faint line is one walk. Darker means more walks pass there.
On day 1 every walk is exactly €1 away, so the typical distance is €1. On day 25 it is €5.03, and by day 100 it is €9.94: some walks are much further out, some are back at €100.
Four times as long
On day 100 the typical distance is about €10. Now the same 1,000 walks keep going to day 400: four times as many days. How far from €100 will a typical walk be on day 400?
Twice as far, not four times
Here are the same walks on day 100. Keep them walking.
1,000 walks, 400 days (simulated)
The coloured curves sit the typical distance above and below €100, worked out from the day number: you'll see how in a moment.
Look at the pattern. On day 25 the typical distance is about €5, on day 100 about €10, on day 400 about €20. And 5 × 5 = 25, 10 × 10 = 100, 20 × 20 = 400: the typical distance is close to the square root of the number of days, written √days. The curves are €100 plus and minus √day. They mark the typical distance, not a limit: about 3 walks in 10 end further out (the next lesson, the bell curve, shows why).
Why not four times? Many of the extra days cancel each other: an up day undoes a down day. Only the part that doesn't cancel moves the walk away (the theory card shows why).
Bigger steps
So far every step was €1. Give the same 1,000 walks, with the same coin flips, bigger or smaller steps and watch the fan.
The same 1,000 walks with a different step size (simulated)
Curves: €100 plus and minus the step size × √day. Walks that leave the chart keep going off it.
With €2 steps, the typical distance on day 400 is €39.49, twice the €19.75 with €1 steps (to within rounding), because every move is twice as big. So the typical distance is about the step size × the square root of the number of days.
A strong uptrend
From the 1,000 walks, take the 100 that rose the most between day 250 and day 400. Each climbed between €18 and €36 in those 150 days. On a chart, every one of them looks like a strong uptrend.
The 100 walks that rose most from day 250 to day 400 (simulated)
Each line is one walk's change in price since day 250.
What will these 100 walks do over the next 100 days?
The next 100 days
The same 100 walks, with the same coin as before. Let them walk to day 500.
The same 100 walks, days 250 to 500 (simulated)
Grey: the climb you picked them for. Coloured: what came next.
The climb said nothing about what came next. Each day is still a fair coin, so the walks don't keep rising, and nothing pulls them back down either. They just spread out again from wherever they had got to.
A support level
Chart readers draw support: a level the price keeps falling to and bouncing up from. Here is walk #1 again. Slide the line and count its touches: days the price fell to the line and went up the next day. Touches count only if they are at least 10 days apart, so one wobble isn't counted many times.
Walk #1 and a level of your choice (simulated)
Dots mark the touches.
At €95, walk #1 fell to the line and turned up 11 times. A chart reader would call that strong support. But the coin has no idea where €95 is. In 400 days walk #1 never left the 15 levels from €86 to €100, so it kept landing on the same ones.
This is not a fluke of walk #1: every one of the 1,000 walks has a level it touched at least 3 times, and 920 have one it touched 5 times or more.
The random walk and the square-root rule
A random walk is a running total of random steps. When each step is the same size, as likely up as down, and doesn't depend on the steps before it, the typical distance from the start grows with the square root of the number of steps. This is the square-root rule (for prices, the square-root-of-time rule). The typical distance is the square root of the average squared distance; squaring makes a distance below the start count like one above, so they don't cancel.
- Pn
- the price after n steps; P0 is where it started
- x1 … xn
- the steps, each +s or −s
- s
- the step size
- n
- the number of steps (days)
- dn
- the typical distance from the start after n steps: the square root of the average squared distance (the next lesson gives it its textbook name)
Why the square root: take a walk that is D above the start (D is negative below it). One more step takes it to D + s or D − s, equally likely. Squared, those are D×D + 2×D×s + s×s and D×D − 2×D×s + s×s, which average D×D + s×s. So each step adds s×s to the squared distance on average: after n steps the average squared distance is n×s×s, and its square root is s × √n. Averaged over every possible walk, this is exact; a real fan of 1,000 walks only comes close (€19.75 against €20).
Two €1 steps: HH, HT, TH and TT end at +2, 0, 0 and −2. Squared: 4, 0, 0, 4, which average 2 (= 2 steps × 1 × 1). The typical distance is √2 ≈ €1.41. Your fan: s = €1 and n = 400, so 1 × √400 = €20; the 1,000 walks measured €19.75.
- each step ignores the ones before it (the steps are independent);
- up and down are equally likely, so the steps average 0;
- the steps have the same typical size (if sizes differ, use their typical size for s).
Steps that lean one way add a drift, a steady push that grows with n, faster than √n (lesson A1, Expectancy). Real daily moves come in calm and wild spells, so the typical size changes over time (lesson C2, Volatility clustering).
A made-up price moves €2 a day, up or down on a fair coin. What is its typical distance from the start after 49 days?
What this means for your backtest
A backtest runs a trading rule over past prices to see what it would have made. Three things follow from this lesson. Turn them over one at a time.
- A trend on a chart is not evidence on its own.
Coin flips drew a €43 climb over 305 days. A rule that "rides trends" has to do better than it would on coin walks, where riding the past climb told you nothing.
- A level drawn after the fact will always find touches.
Every one of the 1,000 coin walks had a level touched 3 times or more. Test a level rule on prices it wasn't drawn on.
- Luck's range grows with the square root of time.
An account trading a rule with no advantage (it makes nothing on average) behaves like a random walk when the trades are independent and similar in size: each trade adds or takes away. After 4 times as many trades, luck then typically puts it about twice as far from where it started.
A friend's coin-flip strategy
After 100 trades, how far from where it started will the account typically be? Type the typical distance in euros.
Hint: the step size is €50 and there are 100 steps. Typical distance = step size × √steps.
Four times as many trades
What is luck's typical distance after 400 trades?
"This market trends and respects levels"
What does the chart alone show?
Lesson done
Add up random steps and you get a random walk: a line that climbs, falls and keeps returning to the same levels, all by chance. Its typical distance from the start grows with the square root of time, so four times as long means about twice as far. A trend or a support level on a chart is not evidence on its own.
Key ideas
- Random walk
- a running total of random steps: the price is the start plus every step so far
- Independent steps
- each step ignores the ones before it, like a fair coin
- Typical distance
- the square root of the average squared distance from the start (named in the next lesson)
- Square root (√)
- the number that, multiplied by itself, gives the number: √400 = 20
- Square-root rule
- with independent, same-size steps that average 0, the typical distance grows with √steps
- Support
- a level a price keeps falling to and bouncing up from; coin walks draw them too
Formulas
Pn = P0 + x1 + … + xn · dn = s × √n
4 times the steps: 2 times the distance. 9 times the steps: 3 times.