Lesson 7.1: Random walks, Brownian motion and martingales
Learn how a random walk becomes Brownian motion, why its paths have infinite length but finite quadratic variation, and what martingales are.
By the end of this lesson you will be able to build Brownian motion as the limit of a scaled random walk, state its defining properties, explain why a Brownian path has infinite total variation but a quadratic variation equal to elapsed time, define a martingale and check the three that matter in finance, use the reflection principle to find the probability that a path touches a level, and use a martingale to solve a gambler's ruin problem. You will show that the sum of squared increments of a simulated Brownian path is 1.00 however finely it is cut, while the sum of absolute increments grows from 8.0 to 25.2 to 79.8 as the cut goes from 100 to 1,000 to 10,000 steps, that a price with 20 per cent volatility has a 50 per cent chance of touching a level 10 per cent above it within six months but only a 25 per cent chance of finishing there, and that a gambler who starts with 30 and stops at 0 or 100 reaches 100 with probability 0.30. You should have read Modules 1 to 6. The mathematics is the normal distribution, expectations and limits. This course is education about how markets and research work, not investment advice.
Module 6 used the Black–Scholes formula as a given. Module 7 opens the box. To understand why the formula has the form it does, and to price anything that Black–Scholes does not cover, you need the mathematics of continuous random motion. This is the part of the course that is closest to pure mathematics, and the one that rewards patience most. We build it in four steps: Brownian motion and martingales in this lesson, Itô's lemma and the derivation of Black–Scholes in Lesson 7.2, risk-neutral pricing in Lesson 7.3 and binomial trees in Lesson 7.4. Each step uses simulations you can run to check the claims.
The random walk
Start with the simplest model of an unpredictable path. A random walk adds up independent random steps. In a simple symmetric random walk, each step is +1 or −1 with equal probability, like a coin toss. After n steps the position is
Sn = X₁ + X₂ + ... + Xn
where each X is ±1. Because the steps are independent and have mean 0 and variance 1:
The expected position is zero, E[Sn] = 0.
The variance adds, Var(Sn) = n, so the standard deviation is √n.
This square-root law is the same one you used to annualise volatility in Lesson 1.3. After 100 steps the position has a standard deviation of 10, so the chance of being 10 or more above the start is about 1 − Φ(1) = 15.9 per cent, with Φ the standard normal distribution function. By the central limit theorem the distribution of Sn is close to normal when n is large.
From a random walk to Brownian motion
To model a price moving continuously, make the steps smaller and more frequent. Take a time interval [0, t], cut it into n pieces of length Δt = t ÷ n and let each step be ±√Δt, so the step size shrinks with the square root of the interval. The position at time t is the sum of n steps, and its variance is n × Δt = t, for every n. The scaling is chosen so that the variance stays fixed as the steps get finer. In the limit n → ∞, the random walk converges to Brownian motion, written Bt or Wt, named after the botanist Robert Brown, who watched pollen jiggle in water. Norbert Wiener built it rigorously in 1923, which is why it is also called the Wiener process. That the limit exists and does not depend on the details of the steps is the content of Donsker's theorem, a functional version of the central limit theorem.
Brownian motion: the definition
A process Bt, for t ≥ 0, is a standard Brownian motion if:
1. B₀ = 0.
2. Independent increments. For times 0 ≤ s < t, the change Bt − Bs is independent of everything that happened up to time s.
3. Normal increments. Bt − Bs is normally distributed with mean 0 and variance t − s. So Bt itself is N(0, t).
4. Continuous paths. The path t → Bt is continuous.
Properties follow at once. The covariance of Bs and Bt is the smaller of s and t. The process is self-similar: B{ct} has the same distribution as √c × Bt, so zooming in on a Brownian path in time by a factor c and in size by √c gives a path that looks the same, a fractal. And the increment over a short time dt is of size √dt, which is much larger than dt when dt is small. This is the feature that makes the calculus different. If you cut a year into a thousand days, a day's move is about √(1 ÷ 1000) = 3.2 per cent of the scale of the year's move, not 0.1 per cent.
To model a price you add drift and volatility: Xt = μ t + σ Bt, called arithmetic Brownian motion, has mean μ t and variance σ² t. Lesson 7.2 turns this into the geometric version used for prices.
Two ways to measure the length of a path
Ordinary calculus rests on the idea that, zoomed in far enough, a curve looks like a straight line. A Brownian path never does. To see how it differs, measure two things over [0, 1], cutting the interval into n pieces of size 1 ÷ n and adding up the increments ΔB:
The total variation: the sum of |ΔB|, the length of the path travelled up and down.
The quadratic variation: the sum of (ΔB)², the sum of the squared moves.
For a smooth function, the total variation is finite however finely you cut it, and the quadratic variation goes to zero, because each squared piece is tiny. For Brownian motion the opposite happens. Each |ΔB| has an average size of √(2 ÷ π) × √(1 ÷ n), so the sum of n of them is √(2n ÷ π), which grows without limit as n increases. The sum of squares is n × (1 ÷ n) = 1 on average, with a standard deviation that shrinks as 1 ÷ √n.
We checked this by simulation. For each of three fineness levels we generated 2,000 Brownian paths on [0, 1] and averaged.
Steps n · Sum of squared increments (mean) · Standard deviation of that sum · Sum of absolute increments (mean) · Theory √(2n ÷ π)100 · 0.998 · 0.143 · 7.97 · 7.98
1,000 · 0.999 · 0.045 · 25.22 · 25.23
10,000 · 1.000 · 0.014 · 79.79 · 79.79
The quadratic variation is 1, the length of the time interval, and it becomes more certain as the cut becomes finer: it is, in the limit, not random at all. The total variation, the length of the path, is 80 with 10,000 steps and keeps growing: a Brownian path has infinite length over any interval. So a Brownian path is continuous but is nowhere smooth. This is why the rules of ordinary calculus fail, and why Kiyosi Itô's calculus, with its famous rule (dB)² = dt, is needed. We write it formally as [B, B]t = t: the quadratic variation of Brownian motion up to time t is t. It is the single most important fact about Brownian motion for finance, and it appears again in Lesson 7.2.
The quadratic variation has a financial reading. Take a share whose daily log returns have a variance of σ² ÷ 252. The sum of the squared daily returns over a year, the realised variance, converges to σ² as the observations get more frequent. That is why realised volatility can be measured from price data without knowing the drift, and why the variance swap of Lesson 6.4 is well defined.
Martingales: the mathematics of a fair game
A process Mt is a martingale if, given everything known up to time s, its expected value at a later time t equals its value at s:
E[Mt | information at s] = Ms, for s < t.
A martingale is a fair game: its best forecast of the future is the present. The word comes from a betting system, but the concept is the foundation of pricing, since in the right setting a price is a martingale. Examples:
1. Brownian motion Bt. Its increments have mean zero and are independent of the past, so E[Bt | Bs] = Bs.
2. Bt² − t. Brownian motion squared is not a martingale, since E[Bt²] = t grows. But subtracting t, the variance accumulated so far, removes the trend: E[Bt² − t | Bs] = Bs² − s. This is the compensated square, and it is the reason (dB)² = dt.
3. The exponential martingale exp(σ Bt − σ² t ÷ 2). The moment generating function of a normal variable with variance t gives E[exp(σ Bt)] = exp(σ² t ÷ 2). The factor exp(−σ² t ÷ 2) removes exactly that growth, so the product is a martingale, with expected value 1 at every time.
Worked example 1. Take σ = 0.5 and t = 1. Then E[exp(0.5 × B₁)] = exp(0.125) = 1.1331, and E[exp(0.5 B₁ − 0.125)] = 1. In a simulation of 20,000 Brownian paths the average of exp(0.5 B₁ − 0.125) came out at 0.993, within the sampling error of 1, while the sample average of B₁² − 1 was −0.007, close to its expected value of 0. The second example is the one to remember: the −σ²t/2 that compensates the exponential reappears in Lesson 7.2 as the correction that turns the drift of a price into the drift of its logarithm.
A discounted price is the object that finance wants to be a martingale: if there is no arbitrage, the price of an asset divided by a risk-free bank account is a martingale under a particular probability measure, which Lesson 7.3 builds. Everything about risk-neutral pricing is a statement about martingales.
The optional stopping idea and gambler's ruin
A martingale is a fair game, and a natural question is whether a clever stopping rule can turn it into a winning one. Not if the rule is reasonable. The optional stopping theorem says that if you stop a martingale at a stopping time, a time determined by the past without peeking at the future, and the game is bounded in a suitable way, then the expected value at stopping equals the starting value: E[MT] = M₀.
Worked example 2: gambler's ruin. A gambler starts with 30 and plays a fair game, winning or losing 1 at each step, until reaching 0 or 100. The position is a martingale. The gambler stops at 100 with probability p and at 0 with probability 1 − p. By optional stopping, the expected final value equals the start: 100 × p + 0 × (1 − p) = 30, so p = 0.30. The chance of reaching the target is the starting capital divided by the target. The expected length of the game, from a second martingale, is the product of the distances to each end: 30 × 70 = 2,100 steps. The mathematics explains a hard fact about fair casinos and about trading: with a modest bankroll and a distant target, ruin is far more likely than success, even though each bet is fair.
The theorem needs care. Doubling after each loss until you win looks like a certain profit, but it fails the boundedness condition: it needs unlimited capital and can wipe you out. It is the logic of the short-volatility strategy of Lesson 4.2.
The reflection principle: how likely is a path to touch a level?
A question that matters for stop-losses, barrier options and risk limits is: what is the probability that a Brownian path reaches a level a at some time before T? The answer comes from a symmetry argument. Take a path that touches a before T. Reflect the part of the path after the first touch in the line at height a. The reflected path is also a Brownian path, with the same probability. A path that touches a and finishes above a has a reflection that finishes below a, and a path that finishes below a but touched a is reflected to one that finishes above. So the paths that touch a are exactly those that finish above a, counted twice:
P(max of B on [0, T] ≥ a) = 2 × P(BT ≥ a) = 2 × (1 − Φ(a ÷ √T))
For a = 1 and T = 1: P(B₁ ≥ 1) = 15.9 per cent, so the probability of touching 1 at some time is 31.7 per cent. In simulation with 1,000 steps and 20,000 paths, the maximum reached 1 in 30.2 per cent of paths, a little lower, because a discrete path can cross the level between observations and be missed. A correction due to Broadie, Glasserman and Kou shifts the barrier up by 0.5826 × √Δt, which gives 30.8 per cent, closer to the simulation. Continuous monitoring catches more crossings than daily or hourly monitoring, which matters when pricing and when backtesting stop-losses.
For a price, apply the result to the logarithm. Take a share with a volatility of 20 per cent and a horizon of six months, so σ√T = 0.2 × √0.5 = 0.1414. For a level 10 per cent above the price, the log distance is ln 1.10 = 0.0953, which is 0.674 standard deviations. Ignoring drift, the probability of finishing above the level is 1 − Φ(0.674) = 25.0 per cent, and the probability of touching it at some point is twice that, 50.0 per cent. It is a fact worth keeping in mind when setting stop-losses: a stop placed 10 per cent from the price is hit half the time over six months even when the market has no trend at all.
Level above the price · Distance in standard deviations · Chance of finishing above · Chance of touching+2.5% · 0.18 · 43.1% · 86.1%
+5% · 0.35 · 36.5% · 73.0%
+10% · 0.67 · 25.0% · 50.0%
+15% · 0.99 · 16.2% · 32.3%
+20% · 1.29 · 9.9% · 19.7%
Check it with your own numbers.
Why this matters in practice
Realised volatility can be estimated from the quadratic variation, from many observations over a short time, without needing the drift.
Pricing is built on martingales: in Lesson 7.3 the price of any derivative is an expected payoff under a measure in which discounted prices are martingales.
Barrier options and stop-losses depend on the probability of touching a level, which is twice that of finishing beyond it for a driftless price, not equal to it.
Simulation of prices uses Brownian increments with variance proportional to the time step. Monitoring frequency and discretisation affect the answer.
Random-walk thinking is the base case for efficient markets: if prices are a martingale, past prices give no help in predicting future ones, the claim that Lessons 2.4 and 5.1 tested against data.
The code below simulates the random walk and Brownian paths, measures the variations, checks the martingales, applies the reflection principle and the gambler's ruin result.
python
import numpy as np
from math import sqrt, pi, exp, log
from scipy.stats import norm
1. a simple random walk: the standard deviation after n steps is sqrt(n)
n = 100
print("random walk, 100 steps: sd", sqrt(n), "| chance of being 10 or more above the start", round(1 - norm.cdf(10 / sqrt(n)), 4))
2. quadratic and total variation of Brownian paths on [0, 1]
rng = np.random.defaultrng(7)
for n in (100, 1000, 10000):
dB = rng.standardnormal((2000, n)) sqrt(1 / n)
qv, tv = (dB 2).sum(axis=1), np.abs(dB).sum(axis=1)
print(f"n={n:>5}: quadratic variation mean {qv.mean():.4f} sd {qv.std():.4f} | total variation mean {tv.mean():.2f} | theory {sqrt(2 n / pi):.2f}")
3. three martingales, and the reflection principle, on 20,000 paths of 1,000 steps
n = 1000
dB = rng.standardnormal((20000, n)) sqrt(1 / n)
B = np.cumsum(dB, axis=1)
print("E[B1]", round(B[:, -1].mean(), 4), "| Var[B1]", round(B[:, -1].var(), 4), "| E[B1^2 - 1]", round((B[:, -1] 2 - 1).mean(), 4))
print("E[exp(0.5 B1 - 0.125)] =", round(np.exp(0.5 B[:, -1] - 0.125).mean(), 4), "(a martingale: should be 1) | E[exp(0.5 B1)] theory", round(exp(0.125), 4))
touch = (B.max(axis=1) >= 1).mean()
print("chance the path touches 1:", round(touch, 4), "| theory", round(2 (1 - norm.cdf(1)), 4),
"| with the barrier correction", round(2 (1 - norm.cdf(1 + 0.5826 sqrt(1 / n))), 4), "| chance B1 >= 1:", round(1 - norm.cdf(1), 4))
4. touching a level above a price: log distance in standard deviations
sigma, T = 0.20, 0.5
for level in (0.025, 0.05, 0.10, 0.15, 0.20):
z = log(1 + level) / (sigma sqrt(T))
print(f"level +{level:.1%}: {z:.2f} sd | finish above {1 - norm.cdf(z):.3f} | touch {2 (1 - norm.cdf(z)):.3f}")
5. gambler's ruin: start 30, stop at 0 or 100, fair game
def ruin(start=30, target=100, trials=2000, seed=3):
r = np.random.defaultrng(seed)
wins = 0
for in range(trials):
x = start
while 0 < x < target:
x += 1 if r.random() < 0.5 else -1
wins += x == target
return wins / trials
print("gambler's ruin: simulated", ruin(), "| theory", 30 / 100, "| expected steps", 30 70)
Common mistakes
Treating Brownian paths as smooth. They have infinite length, and the chain rule of ordinary calculus does not hold, as Lesson 7.2 shows.
Forgetting that variance, not standard deviation, adds. After t years the standard deviation is σ√t, not σt.
Confusing a martingale with a random walk. A random walk with drift is not a martingale, and a martingale need not have independent increments.
Reading "touch" as "finish". For a driftless path the chance of touching a level is twice the chance of finishing beyond it.
Monitoring a barrier daily and comparing with a continuous formula. Discrete monitoring misses crossings, so correct for it.
Believing that a clever stopping rule beats a fair game. Bounded rules do not, and unbounded ones such as doubling can ruin you.
Forgetting the compensating terms. Bt² and exp(σBt) are not martingales on their own: the −t and the −σ²t/2 matter.
Ignoring the √dt scaling in simulation. A time step must scale the standard deviation by √dt, not dt.
Key takeaways
A simple random walk has variance n after n steps. Scaling the steps by √Δt and letting Δt → 0 gives Brownian motion, with B₀ = 0, independent increments, Bt − Bs ~ N(0, t − s) and continuous paths.
Brownian paths are self-similar, continuous and nowhere smooth. Their total variation is infinite, 8.0, 25.2 and 79.8 for 100, 1,000 and 10,000 steps, while their quadratic variation is the elapsed time, 1.00, however finely it is measured.
The rule [B, B]t = t, or (dB)² = dt, is the basis of Itô's calculus, and it lets realised variance be measured from data without the drift.
A martingale is a fair game: E[Mt | information at s] = Ms. Brownian motion, Bt² − t and exp(σBt − σ²t ÷ 2) are martingales, and the last one explains the −σ²/2 of Lesson 7.2.
Optional stopping gives gambler's ruin: starting at 30 with absorbing barriers at 0 and 100, the chance of success is 30 ÷ 100 = 0.30 and the expected length is 2,100 steps.
By the reflection principle, a driftless path touches a level with twice the probability of finishing beyond it: 50 per cent against 25 per cent for a level 10 per cent above a price with 20 per cent volatility over six months.
Monitoring a barrier at discrete times misses crossings, and the correction shifts the barrier by 0.5826σ√Δt.
Check yourself
1. A Brownian motion has run for 4 years. What is the standard deviation of B₄, and the chance that B₄ exceeds 3?
Standard deviation = √4 = 2. P(B₄ > 3) = 1 − Φ(1.5) = 6.7 per cent.
2. Is Bt³ a martingale? Why or why not?
No. By symmetry E[Bt³] = 0, but conditionally E[Bt³ | Bs] = Bs³ + 3(t − s)Bs, which is not Bs³. The correct martingale is Bt³ − 3tBt.
3. A gambler starts with 20 in a fair game with absorbing barriers at 0 and 50. What is the probability of reaching 50, and the expected number of steps?
Probability = 20 ÷ 50 = 40 per cent. Expected steps = 20 × 30 = 600.
4. A share has a volatility of 30 per cent a year. Over three months, what is the chance it touches a level 8 per cent above, ignoring drift?
σ√T = 0.3 × 0.5 = 0.15. The log distance is ln 1.08 = 0.0770, so z = 0.513. P(finish above) = 1 − Φ(0.513) = 0.304, and P(touch) ≈ 0.61.
5. Why does the sum of squared daily returns estimate volatility, while the sum of absolute daily returns does not converge?
The quadratic variation of Brownian motion is finite and equals the variance times time, so the sum of squares converges to a number. The total variation is infinite, so the sum of absolute values grows without limit as the observations get more frequent.
Try this
Set aside forty-five minutes. You need Python and the code in this lesson.
1. Run the code. Check the quadratic and total variations for the three values of n, and that the exponential martingale averages 1.
2. Increase n to 100,000 for the total variation and compare it with √(2n ÷ π).
3. Simulate Brownian motion with drift, Xt = 0.1t + 0.2Bt, for one year, and check that the mean is 0.1 and the variance 0.04.
4. Take daily returns of an index for several years, and compute the realised variance over each month as the sum of squared daily returns. Compare it with the variance of the monthly return.
5. Estimate by simulation the chance that a driftless price with 25 per cent volatility touches a level 7 per cent above within one year, using daily monitoring and then hourly monitoring. Compare with the reflection formula.
6. Use the gambler's ruin simulator to find the starting capital that gives a 90 per cent chance of reaching 100.
7. Write a short note: why a stop-loss close to the price is likely to be hit, how you would test it on historical data, and what monitoring frequency your test uses.
A good result is a table showing total variation growing and quadratic variation staying at 1, an exponential martingale that averages 1, and a comparison of touching and finishing probabilities. The next lesson uses these properties to build the calculus of Brownian motion, Itô's lemma, and from it the geometric Brownian motion of prices and the Black–Scholes equation.
Read more
Steven Shreve's Stochastic Calculus for Finance II: Continuous-Time Models is the standard textbook for this material, and its first chapters cover random walks, Brownian motion and martingales carefully. Bernt Øksendal's Stochastic Differential Equations is a rigorous but readable text. For intuition, Paul Wilmott's Paul Wilmott Introduces Quantitative Finance explains the same ideas with more finance and less proof. Mark Broadie, Paul Glasserman and Steven Kou's 1997 paper "A Continuity Correction for Discrete Barrier Options" in Mathematical Finance derives the barrier shift. William Feller's An Introduction to Probability Theory and Its Applications is the classic for random walks and gambler's ruin.
Tags: Quant Trader Brownian motion Random walk Martingale Quadratic variation