Quant Memo
Core

The Law of Total Variance

Why a portfolio's overall risk splits cleanly into "risk within each regime" plus "risk from switching between regimes" — the identity behind regime-based risk models and hierarchical forecasting.

Prerequisites: Independence and Product Measures

Total portfolio variance seems like it should come purely from day-to-day price wiggles. But regimes matter too — a strategy might be calm within any given market regime (say, low-vol vs high-vol) yet still show large overall variance simply because it behaves very differently across regimes. The law of total variance is the exact identity that splits total variance into these two separate sources, and it is the reason "average within-group variance" is never the whole risk story.

The analogy: variance within classrooms versus variance between classrooms

Imagine measuring the height of every student in a school, split across ten classrooms. Some spread comes from ordinary kid-to-kid variation within any one classroom. But some spread also comes from the fact that a fifth-grade classroom's average height is simply different from a first-grade classroom's average height — spread between classroom averages. Add a student's classroom-level average height back to the picture, and total height variance in the whole school splits cleanly into "how much kids vary around their own classroom's average" plus "how much classroom averages vary from each other." Neither piece alone tells the whole story; you need both.

Writing it down

Let XX be the quantity you care about (say, a strategy's daily return) and YY the "grouping" variable (say, which volatility regime today falls into). The law of total variance says

Var(X)=E[Var(XY)]+Var(E[XY]).\operatorname{Var}(X) = E\big[\operatorname{Var}(X \mid Y)\big] + \operatorname{Var}\big(E[X \mid Y]\big) .

Read the two terms in words. The first term, E[Var(XY)]E[\operatorname{Var}(X\mid Y)], is the average within-group variance: for each fixed regime Y=yY=y, compute how much XX wiggles inside that regime, then average that wiggle across regimes, weighted by how likely each regime is. The second term, Var(E[XY])\operatorname{Var}(E[X\mid Y]), is the variance of the group means: compute each regime's average return, then measure how much those regime-averages themselves spread out. Total variance is the sum of "typical spread inside a group" and "spread of the group centers" — nothing is double-counted, and nothing is left out.

low-vol regime high-vol regime within-group spread (each cluster) between-group spread (dashed line)
Each cluster's own spread is "within-group variance"; the distance between the two circled cluster centres is "between-group variance." Total variance is the sum of both.

Worked example 1: two regimes, computed by hand

Suppose daily returns come from two regimes, each equally likely (P(Y=calm)=P(Y=stormy)=0.5P(Y=\text{calm}) = P(Y=\text{stormy}) = 0.5). In "calm," returns average 0%0\% with variance 11 (in %² units). In "stormy," returns average 2%-2\% with variance 99. Compute the two pieces.

Within-group term: E[Var(XY)]=0.5×1+0.5×9=0.5+4.5=5.0E[\operatorname{Var}(X\mid Y)] = 0.5 \times 1 + 0.5 \times 9 = 0.5 + 4.5 = 5.0.

Between-group term: first find the overall mean, E[X]=0.5×0+0.5×(2)=1E[X] = 0.5\times 0 + 0.5 \times(-2) = -1. The group means are 00 and 2-2; their variance around the overall mean 1-1 is 0.5×(0(1))2+0.5×(2(1))2=0.5(1)+0.5(1)=1.00.5 \times (0-(-1))^2 + 0.5 \times (-2-(-1))^2 = 0.5(1) + 0.5(1) = 1.0.

Total: 5.0+1.0=6.05.0 + 1.0 = 6.0. Check it directly by computing Var(X)\operatorname{Var}(X) from the full mixture — a two-point mixture of normals with those means and variances gives exactly Var(X)=6.0\operatorname{Var}(X) = 6.0 by the same decomposition, confirming the identity holds exactly, not approximately.

Worked example 2: why ignoring the between term understates risk

A risk manager estimates "typical" daily variance by averaging each regime's variance, getting 5.05.0 from example 1, and reports that as the portfolio's variance. The true total variance is 6.06.0 — a 20% underestimate. The missing 1.01.0 is entirely due to regime-switching risk: even if each regime were perfectly calm internally, the fact that the mean return jumps between 0%0\% and 2%-2\% as regimes change is itself a source of variance that a within-group-only estimate silently drops. Doubling the mean gap — say calm at 0%0\% and stormy at 4%-4\% instead of 2%-2\% — would quadruple the between-group term to 4.04.0, since it is a squared distance, while leaving the within-group term at 5.05.0 unchanged, so total variance would jump to 9.09.0.

What this means in practice

Regime-switching risk models, hierarchical Bayesian forecasts, and factor models that pool data across sectors or time periods all rely on this decomposition to separate "noise within a bucket" from "risk from which bucket you're in." A model that only estimates within-group variance — common when volatility is calibrated separately per regime without accounting for how regimes themselves shift — systematically understates total risk, exactly as in worked example 2.

Total variance always equals average within-group variance plus the variance of the group means: Var(X)=E[Var(XY)]+Var(E[XY])\operatorname{Var}(X) = E[\operatorname{Var}(X\mid Y)] + \operatorname{Var}(E[X\mid Y]). Both pieces are needed; neither one alone equals total variance.

The classic mistake is estimating risk purely from within-group variance — computing volatility separately inside each known regime and stopping there — while ignoring that the regime means themselves differ. This silently drops the between-group term, which can be a large share of total variance, as worked example 2 shows. Any time a model conditions on a regime, sector, or time bucket, check whether the conditioning variable's own mean shifts meaningfully — if it does, the "average within-group variance" is understating true risk.

Related concepts

Practice in interviews

Further reading

  • Casella & Berger, Statistical Inference (ch. 4.4)
  • Blitzstein & Hwang, Introduction to Probability (ch. 9)
ShareTwitterLinkedIn