Each of the paths above is an independent ±1 random walk Xₙ. When p = 0.5 the process is a martingale: the conditional expectation of the next value, given everything so far, equals the current value.
E[Xₙ₊₁ | ℱₙ] = Xₙ (fair game, p = 0.5)
τ = first n with |Xₙ| ≥ B (stopping time)
Optional Stopping Theorem:
E[Xτ] = E[X₀] = X₀ when E[τ] < ∞
Every path is stopped the instant it first hits the barrier ±B — that random time τ is the classic "gambler stops when he wins or loses B" stopping rule. The optional stopping theorem says that even though individual paths end at ±B, the average across many independent copies must still sit at the starting value X₀ = 0, because stopping cannot manufacture expected profit from a fair game.
- p slider — away from 0.5 the process becomes a sub/super-martingale (a biased random walk); the sample mean then visibly drifts instead of hovering at X₀, showing why the fairness condition is essential to the theorem.
- Barrier ±B — sets the stopping rule; a wider barrier means longer expected stopping times τ but the same E[Xτ] = X₀ at p = 0.5.
- Sample-mean plane (yellow) — the live average of all path values, plotted against the dashed reference plane at X₀ = 0.
This is the same mathematics behind fair-game casino analysis, sequential hypothesis testing (Wald's identity), and pricing path-dependent options where the discounted price process is required to be a martingale under the risk-neutral measure.