edgekit

Random walks & Brownian motion

The simple random walk is the fruit fly of probability: simple enough to compute with exactly, rich enough to exhibit recurrence, first passages, reflection symmetry, and the shockingly lopsided arcsine law. Rescale it and it becomes Brownian motion, the continuous backbone of every diffusion model of prices. This chapter derives the walk’s classical results, passes to the limit, and works the barrier-hitting formulas that are really questions about stop-losses in disguise.

Intuition — one walk, three questions

Everything here is about a fair coin’s running sum, and three questions about it keep recurring. Does it come back? (Recurrence — yes in 1D, barely; no in 3D.) When does it first reach a level? (First passage — the reflection principle counts the paths.) Where has it spent its time? (The arcsine law — almost never half-and-half.) Each answer transfers verbatim to Brownian motion, where combinatorics is replaced by two martingales, and , and one symmetry: reflection.

The simple random walk#

Let be iid with , and . Then , — the spread — and is both a Markov chain (previous chapter) and a martingale (martingales & optional stopping). Exact probabilities are binomial counts: to end at level after steps you need up-steps, so

the asymptotics by Stirling’s formula. Worked example: , already close to the Stirling estimate . That decay is slow — and it decides the walk’s fate.

Proof sketch — recurrent in 1D and 2D, transient in 3D (Pólya)

Let be the expected number of visits to the origin. Each return probability contributes an indicator, so ; and if the probability of ever returning is , the number of visits is geometric with mean . Hence: recurrent () iff the sum diverges. In dimensions the local CLT gives (each coordinate must separately return, costing apiece). So the sum behaves like : divergent for (harmonic and worse), convergent for . A drunk man finds his way home; a drunk bird may be lost forever — in 3D the return probability is only about . Note the fine print in 1D: return is certain, but the expected return time is infinite — recurrence without positive recurrence.

The reflection principle#

The walk’s deepest symmetry: fix a level and let be its first-passage time. Any path that touches and finishes below it can be reflected about the level after its first touch, producing an equally likely path finishing the mirrored distance above. Reflection is a bijection on paths, so it is an equality of probabilities:

and since , adding to both sides gives the first-passage / running-maximum law with :

A random walk path that touches a barrier level and its mirror image reflected about the barrier after the first touch, illustrating the path bijection
The reflection principle: after the first touch of level a, flip the rest of the path about a. The map is a bijection between paths that touch a and end below it and paths that end above it — so the maximum of the walk has a distribution expressible entirely in terms of the endpoint.

Worked example (by hand). Probability a fair walk reaches within 4 steps: . Check directly: hit at step 2 (UU, probability ) or first hit at step 4 (UD UU or DU UU, probability ) — total . The reflection count agrees with brute force.

The same trick proves the ballot theorem, met via martingales in the stopping chapter: if candidate A receives votes and B receives , the probability A leads throughout the count is — reflect the bad paths that touch zero to count them. And for hitting one barrier before another, the martingale route is fastest: for a fair walk (or Brownian motion) started at 0 with barriers , optional stopping on gives , so

— inversely proportional to distance: twice as far means half as likely to be hit first.

Leads and the arcsine law#

Intuition says a fair game spends about half its time in the lead. It does not. Let be the number of steps (out of ) the walk spends positive. The arcsine law says the fraction converges in distribution to the arcsine distribution:

a U-shaped density: the most likely outcomes are that one side leads nearly the whole time, and the balanced 50/50 split is the least likely. The mechanism is recurrence-in-slow-motion — sign changes require returns to zero, and returns are rare (), so the walk gets stuck on one side for long stretches. The same law governs the location of the maximum and the last zero of the path.

Quant lens — lucky streaks and track records
The arcsine law is the null model of performance streaks. Two strategies flipping the same fair coin will typically show one “dominating” the other for most of a backtest — with zero true edge. A trader up on the year for 10 straight months, a fund ahead of its benchmark since inception: under pure chance these are the typical outcomes, not the surprising ones. Before reading skill into a persistent lead, price in the U-shape — and then run the honest tests in why backtests lie and the multiple-comparison corrections in multiple testing & paradoxes.
arcsine_sim.py
import numpy as np

rng = np.random.default_rng(11)
reps, n = 50_000, 1_000
steps = rng.choice([-1, 1], size=(reps, n))
S = np.cumsum(steps, axis=1)

# fraction of time strictly positive
frac = (S > 0).mean(axis=1)
print((frac <= 0.10).mean())   # ~ (2/pi) arcsin(sqrt(0.1)) = 0.205
print((0.45 <= frac).mean() - (frac > 0.55).mean())
                               # middle decile ~ 0.064 -- rarest region!

# reflection-principle check: P(max of walk >= a) = 2P(S_n > a) + P(S_n = a)
a = 40
print((S.max(axis=1) >= a).mean())                       # empirical
print(2*(S[:, -1] > a).mean() + (S[:, -1] == a).mean())  # reflection formula

From walk to Brownian motion#

Speed the walk up and shrink its steps in the diffusive ratio — steps per unit time, each of size — and Donsker’s invariance principle says the whole path

converges to Brownian motion — the CLT (see LLN & CLT) upgraded from a single sum to entire trajectories. Because the limit forgets the step distribution (any finite-variance step works), every path formula proved for the walk by counting — reflection, arcsine, ballot — passes to BM, usually in cleaner form. Recall the definition from the stochastic processes tutorial: ; independent increments; ; continuous paths.

Several sample paths of Brownian motion diverging from zero, with a shaded band widening like the square root of time
Brownian motion: the diffusive limit of the fair random walk. Increments over time t are N(0, t), so the fan of paths widens like sqrt(t) — the continuous version of Var(S_n) = n.

One structural property deserves its own heuristic: quadratic variation. Chop into slices; each squared increment has mean and variance of order , so the sum of squares has mean and vanishing variance:

A smooth function has zero quadratic variation; BM has a deterministic, positiveone. This is the precise sense in which “” holds, the identity that powers Itô’s lemma and the volatility-drag derivation in the tutorial chapter — and it is why realised variance is computed by summing squared returns.

Hitting times and barriers#

Now the barrier toolkit, with barriers and . Optional stopping (conditions verified in martingales & optional stopping) applied to the martingale gave above. The second martingale gives the expected exit time.

Proof — E[tau] = ab via the martingale W_t^2 − t

is a martingale: using independent increments, , so subtracting elapsed time restores the fair game. Optional stopping at (justified by localisation — stop at , use boundedness of before exit, let ):

The product form is the memorable part: symmetric barriers at take expected time (time scales as distance squared — diffusive scaling again), and widening one barrier lengthens the game only linearly in the other. The identical argument with handles the discrete walk, giving in steps.

Worked example (by hand). Barriers at and : hit the near barrier first with probability , and time units. In trading dress: a stop 1R below entry and a target 2R above, on a driftless price, is hit-target with probability — the “win rate” of a 2:1 reward-to-risk stop pair is forced to when there is no edge, so payoff asymmetry alone creates nothing. That is the optional stopping theorem talking.

For the one-barrier question — how likely is BM to have touched level by time — reflection returns, now as a symmetry of the strong Markov property: a path that touches before is equally likely to finish above or below (the post-touch increment is symmetric). With :

with no discrete correction — continuous paths cannot sit exactly on the barrier at the end with positive probability. Differentiating in gives the first-passage density of (the Lévy distribution, ), whose tail is so heavy that : BM hits every level eventually, but the expected wait is infinite — the continuous echo of null recurrence.

Brownian paths absorbed at an upper barrier with the heavy-tailed first-passage time density and the reflection identity for the running maximum
First passage to a barrier: P(M_t >= a) = 2 P(W_t >= a) by reflection, and the first-passage time has the heavy-tailed Levy density a/sqrt(2 pi t^3) exp(-a^2/2t). Hitting is certain, yet the expected hitting time is infinite.

Drift changes everything. For the symmetric martingale is replaced by the exponential martingale , and optional stopping gives

exponentially tilted toward the drift: even a small dominates the barrier odds over long horizons, because drift grows like while noise grows like . With zero variance the process is a deterministic line and hits only the barrier on the drift’s side — the formula’s limit. These barrier identities price knock-outs, model stop-loss survival, and underlie drawdown mathematics on the simulated GBM paths shown below.

Many simulated geometric Brownian motion price paths starting from one point, fanning out into a right-skewed log-normal cloud, with the mean path above the median path
Geometric Brownian motion — exp of a drifted BM — is where these hitting results earn money: barrier-option knock-out probabilities, stop-loss survival curves, and drawdown distributions are all first-passage calculations on the log-price.

Practice problems#

Problem 1 — Does the walk return to zero?

A fair simple random walk starts at 0. What is the probability it eventually returns to 0? What about the walk on ?

Solution. Let be the return probability. The number of visits to 0 is geometric with mean , but that mean also equals — so is infinite and : the 1D walk is recurrent. The follow-up trap: the expected return time is infinite (the return-time distribution has a tail), so “it always comes back” and “on average it never comes back” are simultaneously true. In 3D the return probabilities decay like , the sum converges, and the return probability drops to — transience. Mean-reversion claims for a market price are claims about which regime it is in; recurrence of a fair walk is not an edge, because the wait is unbudgetable.

Problem 2 — Expected time to exit [−a, a]

A fair simple random walk starts at 0. Find the expected number of steps until .

Solution. is a martingale: . Optional stopping at the exit time (bounded increments, and since exit happens with positive probability in each block of steps): . But always, so . First-step analysis from the Markov chapter confirms it: solving with gives . Diffusive scaling in one line: doubling the range quadruples the time. For asymmetric barriers the same argument yields .

Problem 3 — P(BM hits 1 before −2)

Standard Brownian motion starts at 0. What is the probability it reaches before ? And the expected time until it hits one of them?

Solution. Stop the martingale at the two-barrier exit . With : , so — the general with . Then gives . Sanity checks worth running: the answer depends only on the barrier ratio (BM is scale-invariant: is again BM), and as , — with the lower barrier removed, recurrence guarantees hitting eventually, though (Problem 1’s moral) in infinite expected time.

Problem 4 — Distribution of the maximum of BM

Find the distribution of , and compute and .

Solution. By reflection at the first touch of (strong Markov + symmetry): . Equivalently — the running maximum has the same law as the absolute endpoint, a genuinely surprising identity. Numbers: , double the endpoint probability . And (the folded-normal mean from the zoo). Quant reading: over any horizon, the expected high-water mark of a driftless account is about — noise alone manufactures impressive-looking peaks, which is the correct null when admiring an equity curve’s best point.

Problem 5 — How long is the lead?

Two people flip a fair coin 1,000 times; A scores on heads, B on tails. Which is more likely: the running score is tied in share of time-in-lead (each leads about 50%), or one player leads more than 90% of the time?

Solution. The lopsided outcome wins, and it is not close. By the arcsine law the fraction of time A leads has density , minimised at and blowing up at the edges. Quantitatively,

while . A 9-to-1 domination is six times likelier than a near-even split. The mechanism to narrate: leads change only at zeros of the walk, zeros arrive at rate , so a 1,000-flip game has only ~25 expected ties — the lead is sticky. This is the standard counter-question to “my strategy has beaten the benchmark almost all year”: under the no-edge null, that is the modal outcome, not evidence.

Next: the tools are assembled — counting, conditioning, indicators, martingales, walks. Now the victory lap: the classic brainteasers of the quant canon, each solved fast and solved rigorously. Probability brainteasers.