Each of the paths on the chart is an independent ±1 random walk Xₙ, plotted step n on the horizontal axis against value Xₙ on the vertical axis. 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 (dashed guide lines) — 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 line (yellow) — the live average of all path values, plotted against the dashed reference line at X₀ = 0.
- Drag to pan, scroll to zoom — the chart is a real 2D viewport: drag anywhere on the canvas to pan, scroll/pinch to zoom in on a stretch of steps or out to see the whole bundle.
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.