Quant Memo
Core

Stationary Distributions and Ergodicity

The long-run 'settled' behavior of a random process that keeps moving forever — why a single long simulation can stand in for averaging over many independent ones.

Prerequisites: Markov Chains, Continuous-Time Markov Chains

Backtest a mean-reverting strategy over one long historical stretch, or run it on many independent short samples and average — do you get the same answer? For most well-behaved random processes the answer is yes, and the two ideas that guarantee it are a stationary distribution (the process's long-run "resting" probabilities over its states) and ergodicity (the guarantee that time-averaging one long run gives the same answer as averaging across many independent runs).

An analogy: a well-shuffled deck's resting habits

Imagine repeatedly shuffling a deck of cards. After enough shuffles, the probability that the top card is any particular card settles down to a fixed number (1/52 for a fair deck) and stops changing no matter how many more times you shuffle — that fixed long-run probability profile is the stationary distribution. Ergodicity is a separate, stronger claim: if you shuffled once and then tracked what fraction of a single extremely long sequence of top cards was the ace of spades, that fraction would also converge to 1/52 — a single long history reveals the same probabilities as many independent snapshots would.

The mathematics, one symbol at a time

For a Markov chain with transition structure PP (discrete) or generator QQ (continuous, see Continuous-Time Markov Chains), a distribution π\pi (a vector of probabilities over the states, summing to 1) is stationary if applying one more step leaves it unchanged:

πP=π(discrete),πQ=0(continuous).\pi P = \pi \quad \text{(discrete)}, \qquad \pi Q = 0 \quad \text{(continuous)}.

In words: if the chain's state probabilities are already π\pi, one more transition step produces exactly π\pi again — the distribution is a fixed point of the dynamics. A chain is ergodic if it is irreducible (every state reachable from every other) and, for discrete chains, aperiodic (it doesn't cycle in a rigid fixed pattern); under these conditions, regardless of the starting state, the chain's distribution converges to a unique π\pi, and time averages along one path converge to expectations under π\pi:

1Tt=1Tf(Xt)  T  Eπ[f(X)].\frac{1}{T}\sum_{t=1}^{T} f(X_t) \; \xrightarrow{T \to \infty} \; \mathbb{E}_\pi[f(X)].

This says: the average of some quantity ff measured along one long trajectory converges to what you'd get averaging ff over the stationary distribution — exactly the guarantee that lets a single backtest substitute for an ensemble of independent ones.

Worked example 1: solving for a stationary distribution by hand

A two-state chain toggles between "trending" (T) and "range-bound" (R) with transition probabilities P(TR)=0.3P(T \to R) = 0.3, P(RT)=0.2P(R \to T) = 0.2 per day (so P(TT)=0.7P(T\to T)=0.7, P(RR)=0.8P(R\to R)=0.8). Solve πP=π\pi P = \pi with π=(πT,πR)\pi = (\pi_T, \pi_R), πT+πR=1\pi_T + \pi_R = 1: πT=0.7πT+0.2πR0.3πT=0.2πRπT=23πR\pi_T = 0.7\pi_T + 0.2\pi_R \Rightarrow 0.3\pi_T = 0.2\pi_R \Rightarrow \pi_T = \tfrac{2}{3}\pi_R. Combined with πT+πR=1\pi_T+\pi_R=1: πR=0.6\pi_R = 0.6, πT=0.4\pi_T = 0.4. In the long run, the market spends 40% of days trending and 60% range-bound — regardless of which state it started in.

Worked example 2: ergodicity in a backtest

Suppose the strategy earns $100 on trending days and −$20 on range-bound days. Using the stationary distribution from example 1, the expected daily P&L under π\pi is 0.4(100) + 0.6(-20) = 40 - 12 = \28. Ergodicity guarantees that a single sufficiently long backtest's *average* daily P&L will converge to this same \28 figure — you don't need to run the market forward many separate times to check the number; one long enough historical run does the job, provided the underlying dynamics genuinely stay stable over that window.

time pi_T = 0.4 start all-trending start all-range
Whatever the starting state, the running fraction of time spent in the "trending" state converges to the same stationary probability — a single long run reveals the same long-run behavior as any other starting point.
T R 0.3 0.2 pi_T = 0.4 pi_R = 0.6
The raw transition rates (left) determine a unique long-run split of time between states (right, the stationary distribution) — solved once from the balance equations, valid forever regardless of the starting state.

What this means in practice

Ergodicity is the quiet assumption behind treating one historical backtest as representative of "the market's typical behavior" — it only holds if the underlying regime dynamics are genuinely stable (irreducible, non-explosive) over the sample window. Stationary distributions themselves show up directly in regime-switching models, PageRank-style ranking algorithms, and any Markov-based simulation used to generate plausible future paths.

A stationary distribution π\pi is a fixed point of the chain's dynamics (πP=π\pi P = \pi); ergodicity is the further guarantee that, for an irreducible chain, a single long trajectory's time-average converges to the expectation under π\pi — letting one long run substitute for many independent ones.

The classic mistake is assuming ergodicity holds for financial time series without checking it — real markets go through structural regime changes (a 2008-style break, a change in market microstructure) that violate the "stable, unchanging dynamics" requirement. When that happens, a long backtest isn't sampling one stationary distribution; it's sampling a mixture of several, and its time-average doesn't correspond to any single regime's true expectation, which quietly invalidates naive "just use a longer backtest" reasoning.

Related concepts

Practice in interviews

Further reading

  • Norris, Markov Chains, ch. 1
  • Grimmett & Stirzaker, Probability and Random Processes, ch. 6
ShareTwitterLinkedIn