Module contents
Lesson 5 of 31Core 115 min

Discrete-time martingales

A martingale formalizes a fair game and is a powerful tool for calculations at random times. Study submartingales and supermartingales, the martingale transform as a discrete precursor of the Itô integral, Doob decomposition, optional stopping and its assumptions, Wald's identity, Doob's maximal inequality, and martingale convergence, with Pólya's urn and gambler's ruin as labs.

After this lesson you can

  • Check whether a process is a martingale, submartingale or supermartingale and construct martingales from Markov chains and likelihoods.
  • Calculate ruin probabilities and expected durations by applying optional stopping to suitable martingales.
  • Identify when optional stopping fails and which assumption is violated in a doubling strategy.
  • Bound a process maximum with Doob's inequality and use it in sequential tests.
  • Apply the convergence theorem to Pólya's urn and likelihood ratios.

Before you start

A fair game and the clock you choose

If a bet is fair, knowing its history does not change the expected gain on the next step. Can a rule that changes bet size and decides when to stop make it favorable? One temptation is to double after each loss: a win would recover everything lost and leave one unit of profit. The figure adds finite capital and table limits to reveal the infrequent losses that offset small gains.

InteractiveDoubling after a loss

Each game uses a fair coin. Bet 1 and double after each loss; the game ends on a win or when the next bet exceeds remaining capital or the table limit.

Net gain by number of bets:

  • Wins one unit
  • Exhausts permitted bets

The first 19 games are shown and, if they contain no loss, one is added when available; this selection makes it visible and does not represent its frequency.

Frequency among simulated games:

0.0 %20.0 %40.0 %60.0 %80.0 %100.0 %Wins 197.1 %Loses 312.9 %

En 2000 games there were 58 losses. The empirical mean fluctuates: a win gives +1 and losing all 5 bets gives −31. The theoretical mean is (1 − 2⁻ʰ) − (2ʰ − 1)2⁻ʰ = 0, with h the number of possible bets.

Without limits, the first win occurs almost surely and its mean time is 2, but accumulated stakes are not integrable and the stopped process is not uniformly integrable. Thus one cannot conclude that expected gain is zero by applying optional stopping without checking its assumptions.

31
16
Possible bets before stopping5
Exact probability of losing all3.125 %
Empirical mean0.072
Theoretical mean0.000
Change capital and table limit. The distribution corresponds to a fair-coin game with bets permitted by those limits. Compare the frequency of small gains with the size of losses and distinguish the theoretical mean from the empirical mean.

Without limits, the first win occurs almost surely and its time has mean 2. However, bets grow without bound and stopped capital does not form a uniformly integrable family: with probability 2−n2^{-n} the first nn bets are lost and cumulative loss is 2n−12^n-1. Finite mean time alone does not justify exchanging stopping and expectation without care. With finite limits, a predictable strategy on fair bets preserves zero expectation; a finite sample of results need not show exactly zero.

The definition requires information and integrability

Checking EMn=EM0\E M_n=\E M_0 is not enough: the condition requires that no available information predict a gain. It does not require independent increments. If square-integrable, martingale increments at different times are uncorrelated by conditioning; lack of correlation does not imply independence.

A submartingale replaces equality with E[Xn+1∣Fn]≥Xn\E[X_{n+1}\mid\mathcal F_n]\ge X_n; a supermartingale uses ≤\le. Both still require adaptation and integrability. A convex function of a martingale is a submartingale when its transform is integrable, by conditional Jensen.

Important examples:

  • If ξi\xi_i are independent, integrable and mean zero, Sn=∑i=1nξiS_n=\sum_{i=1}^n\xi_i is a martingale in its natural filtration. With equally likely ξi=±1\xi_i=\pm1, Sn2−nS_n^2-n is also one.
  • If Zi≥0Z_i\ge0 are independent and EZi=1\E Z_i=1, their product ∏i=1nZi\prod_{i=1}^n Z_i is a nonnegative martingale. A sequential likelihood ratio is an example under the null law, provided the alternative is absolutely continuous with respect to the null at each finite horizon.
  • For X∈L1X\in L^1, Mn=E[X∣Fn]M_n=\E[X\mid\mathcal F_n] is the Doob martingale by the tower property: updating a coherent prediction introduces no conditional drift.
  • If XnX_n is a chain and hh is harmonic, Ph=hPh=h, then h(Xn)h(X_n) is a martingale whenever integrable. The function hh summarizes the solution to the first-step problem.

Betting without seeing the next outcome

A strategy HkH_k is predictable if it is Fk−1\mathcal F_{k-1}-measurable. The martingale transform is

(H ⁣⋅ ⁣M)n=∑k=1nHk(Mk−Mk−1).(H\!\cdot\!M)_n=\sum_{k=1}^{n}H_k(M_k-M_{k-1}).

If HkH_k is bounded and MM integrable, each term is integrable and E[Hk(Mk−Mk−1)∣Fk−1]=HkE[Mk−Mk−1∣Fk−1]=0\E[H_k(M_k-M_{k-1})\mid\mathcal F_{k-1}]=H_k\E[M_k-M_{k-1}\mid\mathcal F_{k-1}]=0. Thus the transform is a martingale. Bets may depend on the entire past but not on the next increment. This is the discrete version of the predictable-integrand idea that will reappear in the Itô integral.

The Doob decomposition writes any adapted integrable process XnX_n as Xn=Mn+AnX_n=M_n+A_n, with A0=0A_0=0 and

An=∑k=1nE[Xk−Xk−1∣Fk−1],Mn=Xn−An.A_n=\sum_{k=1}^n\E[X_k-X_{k-1}\mid\mathcal F_{k-1}],\qquad M_n=X_n-A_n.

AnA_n is predictable and MnM_n is a martingale by construction; the decomposition is unique because the predictable increment of AA is forced by conditional expectation. If XX is a submartingale, AA is increasing almost surely. For a square-integrable martingale, ⟨M⟩n=∑k=1nE[(Mk−Mk−1)2∣Fk−1]\langle M\rangle_n=\sum_{k=1}^n\E[(M_k-M_{k-1})^2\mid\mathcal F_{k-1}] is its predictable quadratic variation and Mn2−⟨M⟩nM_n^2-\langle M\rangle_n is a martingale.

Stopping is not just substituting a letter

The optional stopping theorem guarantees EMτ=EM0\E M_\tau=\E M_0 under sufficient assumptions, for example any of these:

  1. τ\tau is bounded by a deterministic constant.
  2. Eτ<∞\E\tau<\infty and the increments of MM are uniformly bounded.
  3. τ<∞\tau<\infty almost surely and the family (Mn∧τ)(M_{n\wedge\tau}) is uniformly integrable.

In the first case, Mτ−M0=∑k=1N1{τ≥k}(Mk−Mk−1)M_\tau-M_0=\sum_{k=1}^N\mathbf1_{\{\tau\ge k\}}(M_k-M_{k-1}). The indicator is Fk−1\mathcal F_{k-1}-measurable because τ\tau is a stopping time: the previous transform has zero expectation. In the second, ∣Mn∧τ−M0∣≤Cτ|M_{n\wedge\tau}-M_0|\le C\tau gives integrable domination. In the third, almost-sure convergence of Mn∧τM_{n\wedge\tau} to MτM_\tau and uniform integrability allow passage to the limit in L1L^1.

The counterexample is fair SnS_n and τ=inf⁡{n:Sn=1}\tau=\inf\{n:S_n=1\}. This time is finite almost surely and Sτ=1S_\tau=1, but ES0=0\E S_0=0. It does not contradict the theorem: Eτ=∞\E\tau=\infty and the stopped values do not form a uniformly integrable family. Almost-sure stopping is not enough. In the doubling strategy, the limit without capital or table constraints also requires unbounded bets and potentially arbitrary losses.

Ruin and duration by stopping

Let S0=kS_0=k and Sn+1−Sn=±1S_{n+1}-S_n=\pm1 with probabilities pp and q=1−pq=1-p. For 0<k<N0<k<N, stop at τ=inf⁡{n:Sn∈{0,N}}\tau=\inf\{n:S_n\in\{0,N\}\}. On this finite interval Eτ<∞\E\tau<\infty: from every state there is a uniformly positive probability of reaching a boundary within NN steps, and the tail is geometrically bounded by blocks.

If p=q=1/2p=q=1/2, optional stopping for SS gives k=NP(Sτ=N)k=N\Pr(S_\tau=N), so the success probability is k/Nk/N. The martingale Sn2−nS_n^2-n, first applied to τ∧m\tau\wedge m, yields Eτ=k(N−k)\E\tau=k(N-k): the term Sτ∧m2S_{\tau\wedge m}^2 is bounded by N2N^2 and τ∧m\tau\wedge m increases to τ\tau. These steps justify the limit without blindly assuming equality at τ\tau.

If p≠qp\ne q and both are positive, Mn=(q/p)SnM_n=(q/p)^{S_n} is a martingale because p(q/p)+q(p/q)=1p(q/p)+q(p/q)=1. The stopped process is bounded on [0,N][0,N]; optional stopping gives

(q/p)k=P(Sτ=0)+P(Sτ=N)(q/p)N.(q/p)^k=\Pr(S_\tau=0)+\Pr(S_\tau=N)(q/p)^N.

Solving reproduces the first-step formula from the preceding lesson. The exponential martingale must not be used at p=0p=0 or p=1p=1, where the ratio ceases to make sense.

InteractiveThree martingales for an exit

Four of the 400 simulated paths. Each bet adds or subtracts 1 and the game stops at 0 or N.

  • Path 1
  • Path 2
  • Path 3
  • Path 4

Empirical mean of the selected process at the stopped time and theoretical initial value. The last cut’s standard error appears in the readouts.

  • Empirical mean
  • Initial value

Sn∧τS_{n\wedge\tau} is a martingale. Since SτS_\tau is NN with probability hh and 00 under ruin, k=E[Sτ]=Nhk=\mathbb{E}[S_\tau]=Nh and h=k/Nh=k/N.

Exact figures use exit at 0 or N and 0.50 upward probability. For 0 < p < 1 and finite N, exit occurs almost surely and has finite expectation. Stopping identities require justifying the limit from truncated times; they do not follow solely because E[τ] is finite in every problem. The simulation uses a fixed seed. Paths with no exit by the horizon are censored and may exit later: mean truncated time is not full duration.

12
5
0.50
100
Process to stop
Selected processMartingale
Exact probability of reaching N41.67 %
Exact expected exit time35.00
Reach N before horizon162/400 (40.5 %)
No observed exit16/400 (4.0 %)
Mean truncated time33.86
Mean stopped process ± standard error5.090 ± 0.292
Compare the chosen process, stopping equation and resulting probability or duration. The S and S²−n formulas apply to the symmetric game; the exponential permits bias.

Wald’s identities express the same discipline for iid sums: if ξi\xi_i are iid integrable variables and τ\tau is an integrable stopping time with respect to their natural filtration, ESτ=Eτ Eξ1\E S_\tau=\E\tau\,\E\xi_1. If additionally Eξ1=0\E\xi_1=0 and Eξ12<∞\E\xi_1^2<\infty, ESτ2=Eτ Eξ12\E S_\tau^2=\E\tau\,\E\xi_1^2. The first follows by summing E[ξk1{τ≥k}]\E[\xi_k\mathbf1_{\{\tau\ge k\}}]; the indicator depends only on earlier increments, and the sum of its probabilities is Eτ\E\tau. The second uses the isometry of centered increments and the limit at L2L^2.

Control the maximum, not only the endpoint

Doob’s maximal inequality for a nonnegative submartingale states, for λ>0\lambda>0,

P(max⁡0≤k≤nXk≥λ)≤EXnλ.\Pr\left(\max_{0\le k\le n}X_k\ge\lambda\right)\le\frac{\E X_n}{\lambda}.

To prove it, let τ\tau be the first crossing before nn, or nn if none occurs. By bounded stopping of a submartingale, EXn≥EXτ\E X_n\ge\E X_\tau. The crossing event contributes at least λ\lambda times its probability, and the rest is nonnegative. For p>1p>1 and E∣Xn∣p<∞\E|X_n|^p<\infty, the corresponding LpL^p inequality is ∥max⁡k≤nXk∥p≤pp−1∥Xn∥p\|\max_{k\le n}X_k\|_p\le\frac p{p-1}\|X_n\|_p.

If LnL_n is a nonnegative martingale with L0=1L_0=1, the bound holds uniformly over any finite horizon: P(max⁡k≤nLk≥1/α)≤α\Pr(\max_{k\le n}L_k\ge1/\alpha)\le\alpha. Letting nn grow and using continuity of probability for increasing events gives Ville’s inequality for inspection at any time, including an infinite horizon.

InteractiveCrossing an evidence threshold

Under the null each heads has probability 1/2. The ratio L starts at 1 and is multiplied by 1.40 for heads or by 0.60 for tails. Curves show the first 12 of the 2000 simulated paths. To distinguish crossings, the chart visually clips values above 2λ; the count uses full values.

Ratio L by number of tosses:

  • Paths under the null
  • Threshold λ

Observed frequency and theoretical bound:

0.0 %2.0 %4.0 %6.0 %8.0 %10.0 %12.0 %Observed frequency8.6 %Bound 1/λ10.0 %

Frequency counts whether the maximum reaches λ within the first 80 tosses. The Ville–Doob inequality bounds its probability by 1/λ because L is a nonnegative martingale with L₀ = 1. The bound also holds for an unlimited horizon; it is not the observed frequency and need not be tight.

10
70 %
80
Observed crossings through the horizon172 / 2000 (8.60 %)
Theoretical bound 1/λ10.00 %
Estimated Monte Carlo standard error0.63 %
Fix a threshold and compare the frequency of crossings over a finite horizon with the bound 1/λ. Paths are generated under the null hypothesis; the bound is not a simulated frequency.

Convergence and a random limit

The martingale convergence theorem states, in particular, that a submartingale with sup⁡nE∣Xn∣<∞\sup_n\E|X_n|<\infty converges almost surely to an integrable variable. For a<ba<b, define Un(a,b)U_n(a,b) as the number of complete disjoint upcrossings of [a,b][a,b] up to nn. Doob’s upcrossing inequality for a submartingale is

(b−a)EUn(a,b)≤E[(Xn−a)+].(b-a)\E U_n(a,b)\le\E[(X_n-a)^+].

To understand it, Yn=(Xn−a)+Y_n=(X_n-a)^+ is a nonnegative submartingale. A predictable strategy buys when XX reaches aa or less and sells when it reaches bb or more. Each complete crossing contributes at least b−ab-a, and an open purchase has nonnegative value because YY is zero at purchase. Increments of YY while the strategy is not holding a position form another predictable submartingale transform with nonnegative expectation; separating those gains from Yn−Y0Y_n-Y_0 gives the bound. A formal proof using crossing times appears in the MIT notes.

The bound L1L^1 uniformly bounds the right-hand side. By monotone convergence, the total number of crossings of every rational interval is finite almost surely. Thus the path has a limit on the extended real line. Fatou and sup⁡nE∣Xn∣<∞\sup_n\E|X_n|<\infty rule out that limit being infinite with positive probability and also show it is integrable.

Almost-sure convergence does not imply convergence of expectations. A uniformly integrable martingale does converge in L1L^1 and Mn=E[M∞∣Fn]M_n=\E[M_\infty\mid\mathcal F_n]. For example, the nonnegative likelihood ratio under the null converges almost surely, but its limit may have expectation below one if the family is not uniformly integrable.

In Pólya’s urn, start with a,b>0a,b>0 red and blue balls. At each step draw a ball, replace it and add another of the same color. The red proportion Rn/(a+b+n)R_n/(a+b+n) is a bounded martingale, so it converges almost surely and in L1L^1. Its limit has law Beta(a,b)\mathrm{Beta}(a,b); it is random even though each individual path stabilizes. The exact finite-time distribution is not that continuous beta law: the number of added red balls is beta-binomial.

To identify the limiting law, consider a particular sequence of nn draws with rr red. Its probability is (a)r(b)n−r/(a+b)n(a)_r(b)_{n-r}/(a+b)_n, where (a)r(a)_r is the rising product. This expression is also the integral of θr(1−θ)n−r\theta^r(1-\theta)^{n-r} against the beta density: first draw Θ∼Beta(a,b)\Theta\sim\mathrm{Beta}(a,b) and then draw independent colors with red probability Θ\Theta to obtain the same probabilities for all finite sequences. In that construction, the strong law conditional on Θ\Theta makes the proportion converge to Θ\Theta. Since the laws of the complete sequences agree, the urn limit has the stated beta law.

InteractiveUrns settling at different values
One hundred proportions over time
Draws; a point is drawn every 10 steps
  • One line per urn
  • Theoretical mean
Distribution at step 500 and limiting distribution
Red-ball proportion; vertical axis is density
  • Histogram of 100 urns at step 500
  • Limiting beta density(2, 3)

Bars group finite-time proportions and their area sums to 1. The curve is the limiting distribution’s density, not the density of these 100 observations or the exact finite-step distribution. More time brings distributions closer, but each urn has its own random limit; changing the seed changes the sample.

2
3
500
Mean of 100 urns0.438
Theoretical mean at any step0.400
Sample variance0.0470
Theoretical variance at current step0.0396
Theoretical limiting variance0.0400
Seed2605
Change initial counts and observe finite paths and their histogram. The beta curve is the limiting law, not the exact discrete distribution at the displayed horizon.

Lab: ruin, Wald and compensation

Simulate paths until absorption at 00 or NN without discarding long ones. The exact probability is calculated using the exponential martingale. Wald is checked with the sum of centered increments Cτ=(Sτ−k)−(p−q)τC_\tau=(S_\tau-k)-(p-q)\tau, whose variance per step is 4pq4pq. The mean of CτC_\tau should approach zero and the mean of its square 4pqEτ4pq\E\tau; both comparisons fluctuate due to Monte Carlo error.

[ ]Biased ruin and Wald's identitiesBrowser
import numpy as np

rng = np.random.default_rng(26051)
M, N, k, p = 30_000, 10, 3, 0.48
q = 1-p
capital = np.full(M, k, dtype=int)
tiempo = np.zeros(M, dtype=int)
activos = (capital > 0) & (capital < N)
while activos.any():
    idx = np.flatnonzero(activos)
    capital[idx] += np.where(rng.random(len(idx)) < p, 1, -1)
    tiempo[idx] += 1
    activos = (capital > 0) & (capital < N)
exito = (1-(q/p)**k)/(1-(q/p)**N)
centrada = capital - k - (p-q)*tiempo
print('éxito empírico y exacto:', round(np.mean(capital == N), 5), round(exito, 5))
print('media centrada:', round(centrada.mean(), 5))
print('segundo momento centrado:', round(np.mean(centrada**2), 5))
print('Wald: varianza por paso × tiempo medio:', round(4*p*q*tiempo.mean(), 5))
print('tiempo medio:', round(tiempo.mean(), 5))

For ∣Sn∣|S_n| in the fair walk, the conditional expected increment is 11 at Sn−1=0S_{n-1}=0 and 00 at every other integer. Its compensator is the number of visits to zero before each step. The cell calculates residual Mn=∣Sn∣−AnM_n=|S_n|-A_n and checks the mean of its increments grouped by the preceding state. The empirical comparison does not prove the martingale property; the conditional identity proves it for every state.

[ ]Doob decomposition of |S|Browser
rng = np.random.default_rng(26052)
M, pasos = 40_000, 60
estado = np.zeros(M, dtype=int)
compensador = np.zeros(M, dtype=int)
sumas = np.zeros(2)
cuentas = np.zeros(2, dtype=int)
for t in range(pasos):
    cero = estado == 0
    incremento = np.where(rng.random(M) < .5, 1, -1)
    siguiente = estado + incremento
    delta_m = np.abs(siguiente) - np.abs(estado) - cero.astype(int)
    sumas[0] += delta_m[cero].sum()
    sumas[1] += delta_m[~cero].sum()
    cuentas += [cero.sum(), (~cero).sum()]
    compensador += cero
    estado = siguiente
print('media residual condicionada a cero / no cero:', np.round(sumas/cuentas, 6))
print('media de |S|-A:', round(np.mean(np.abs(estado)-compensador), 5))
print('visitas previas a cero medias:', round(compensador.mean(), 5))

Now simulate urns and compare their mean and variance with exact finite-time moments. If c=a+bc=a+b, the final proportion observed after nn draws has expectation a/ca/c and variance nab/[c2(c+1)(c+n)]nab/[c^2(c+1)(c+n)]. The limiting variance is ab/[c2(c+1)]ab/[c^2(c+1)]. Fitting a beta law to the finite distribution is an approximation: finite proportions lie on a discrete grid.

[ ]Pólya's urn and beta approximationBrowser
rng = np.random.default_rng(26053)
a, b, n, M = 2, 3, 500, 20_000
rojas = np.full(M, a, dtype=int)
for t in range(n):
    rojas += rng.random(M) < rojas / (a+b+t)
proporcion = rojas / (a+b+n)
media = proporcion.mean()
varianza = proporcion.var(ddof=1)
escala = media*(1-media)/varianza - 1
ajuste = (media*escala, (1-media)*escala)
var_finita = n*a*b/((a+b)**2*(a+b+1)*(a+b+n))
var_limite = a*b/((a+b)**2*(a+b+1))
print('media empírica y teórica:', round(media, 5), a/(a+b))
print('varianza empírica, finita y límite:', round(varianza, 5), round(var_finita, 5), round(var_limite, 5))
print('beta ajustada por momentos a tiempo finito:', np.round(ajuste, 4))

Lab: valid evidence under repeated inspection

Consider two groups with independent normal observations of variance one. For each pair, Zi=(Xi−Yi)/2Z_i=(X_i-Y_i)/\sqrt2 has law N(0,1)\Normal(0,1) under the null. Under an alternative with mean δ\delta, the likelihood ratio for the first nn observations is exp⁡(δSn−nδ2/2)\exp(\delta S_n-n\delta^2/2), with Sn=∑iZiS_n=\sum_i Z_i. Mixing those ratios with a proper prior δ∼N(0,τ2)\delta\sim\Normal(0,\tau^2) gives another nonnegative martingale under the null:

Ln=11+nτ2exp⁡ ⁣(τ2Sn22(1+nτ2)).L_n=\frac{1}{\sqrt{1+n\tau^2}}\exp\!\left(\frac{\tau^2S_n^2}{2(1+n\tau^2)}\right).

The formula follows by completing the square and integrating a normal density. If stopping at the first Ln≥1/αL_n\ge1/\alpha, Ville controls the crossing probability under the null regardless of how often we inspect. Compare with repeating an ordinary two-sided Welch t-test at nominal level α\alpha at every sample size: its t distribution with Welch degrees of freedom is an approximation, and the rule declaring success at the first significant result does not automatically preserve that level under repeated inspection.

[ ]Sequential crossings under the nullBrowser
from scipy.special import stdtr

rng = np.random.default_rng(26054)
M, horizonte, alpha, tau = 3_000, 100, 0.05, 0.5
x = rng.normal(size=(M, horizonte))
y = rng.normal(size=(M, horizonte))
z = (x-y)/np.sqrt(2)
suma_z = np.cumsum(z, axis=1)
t = np.arange(1, horizonte+1)
log_e = -.5*np.log1p(t*tau**2) + tau**2*suma_z**2/(2*(1+t*tau**2))
cruce_e = (log_e >= np.log(1/alpha)).any(axis=1)

sx, sy = np.cumsum(x, axis=1), np.cumsum(y, axis=1)
sx2, sy2 = np.cumsum(x*x, axis=1), np.cumsum(y*y, axis=1)
n = t[4:]
mx, my = sx[:, 4:]/n, sy[:, 4:]/n
vx = (sx2[:, 4:] - sx[:, 4:]**2/n)/(n-1)
vy = (sy2[:, 4:] - sy[:, 4:]**2/n)/(n-1)
vx, vy = np.maximum(vx, 0), np.maximum(vy, 0)
error2 = (vx+vy)/n
estadistico = (mx-my)/np.sqrt(error2)
grados = (vx+vy)**2/(vx**2/(n-1)+vy**2/(n-1))
p_valor = 2*stdtr(grados, -np.abs(estadistico))
cruce_t = (p_valor < alpha).any(axis=1)
print('cruce de la martingala:', int(cruce_e.sum()), '/', M, 'cota:', alpha)
print('rechazo por t repetido:', int(cruce_t.sum()), '/', M)
print('error estándar de frecuencia con p=alpha:', round(np.sqrt(alpha*(1-alpha)/M), 5))

The evidence test uses the model’s known variance to construct the ratio; Welch’s test estimates variances. The comparison shows the effect of the stopping rule in this experiment; it does not establish a universal difference among all possible tests. Simulated crossing frequency can fall below or above the theoretical bound due to fluctuation; the bound concerns the true probability.

Exercises

NumericAn urn and its limit
A Pólya urn starts with 2 red and 3 blue balls. What is the probability that its limiting red proportion exceeds 0.5?
QuizWhen can we stop?
In which cases do the stated assumptions guarantee E[Mτ]=E[M₀] for an integrable martingale?

More than one answer may be correct.

ProofBounded optional stopping
Prove: Prove E[Mτ]=E[M₀] when τ is a stopping time bounded by N.
0
Write the stopped increment as a sum of increments of M.

Step 1 of 3. Which sum is correct?

ProofDuration of the fair game
Prove: A fair walk starts at k, with 0<k<N, and stops on reaching 0 or N. Prove E[τ]=k(N−k).
0
You already know τ has finite expectation and Sₙ²−n is a martingale.

Step 1 of 3. What do you obtain by stopping S?

ProofThe maximal inequality
Prove: Prove P(maxₖ≤ₙ Xₖ≥λ) ≤ E[Xₙ]/λ for a nonnegative submartingale and λ>0.
0
Stop at the first crossing of λ, or at n if none exists.

Step 1 of 3. Why is the chosen time a bounded stopping time?

CodeDecompose a function of a chain
Implement doob_decomposition(P, f, path). P is a row transition matrix, f a vector of values, and path a trajectory of indices. Return arrays M and A, with A₀=0, increments Aₖ−Aₖ₋₁=(Pf−f)(path[k−1]), and Mₖ=f(path[k])−Aₖ.
import numpy as np

def doob_decomposition(P, f, path):
  pass
Shift+Enter to run
Key idea

A martingale encodes absence of conditional drift relative to available information. Predictable strategies do not create expected gain, but taking a limit at stopping requires assumptions. The maximal inequality controls repeated inspection, and convergence explains both random urn limits and the risk of losing mass in expectation.