Variance & Covariance Cheat Sheet
Starting points (where every derivation begins)
Everything below is derived from these definitions. They’re the raw material — average squared deviation for variance, average product of deviations for covariance. When a derivation feels stuck, come back here and plug in.
Variance is just SS divided by n (or n−1 for a sample). Same object, before you average.
The move in every derivation: plug into one of these, expand the square or product (pure algebra), apply E using linearity, then recognize the Var/Cov patterns that fall out. The computational forms below (E[X2] − (E[X])2, E[XY] − E[X]E[Y]) are results of doing this, not starting points.
The identities
Average of the squares minus the square of the average. Worth showing where that second form comes from, since every later grind reuses this exact collapse. Start from the deviation definition and expand the square:
Average term by term. The key is that x is a constant (already computed), so it pulls out of the sums:
- First term: (1/n)Σxi2 = E[X2]
- Middle term: (1/n)Σ(−2xix) = −2x · (1/n)Σxi = −2x · x = −2(E[X])2
- Last term: (1/n)Σx2 = x2 = (E[X])2 (averaging a constant returns the constant)
Put them together — and notice the last term carries a coefficient of 1, not 2:
The −2 and +1 combine to −1. That collapse — middle and last terms both becoming (E[X])2 and partially cancelling — is the same move behind every Var/Cov identity on this sheet.
Average of the products minus the product of the averages.
Constants pull out as their square.
Adding a constant doesn’t change covariance.
Constants don’t co-vary.
Here a and b are the amounts held of each asset. They’re portfolio weights when they sum to 1. Var(X+Y) above is just this formula with a = b = 1 — one unit of each, no weighting lever. The weights are what turn a raw sum into a portfolio.
- Var(X) = 0.04, Var(Y) = 0.01
- Cov(X, Y) = ρ · σX · σY = 0.3 · 0.2 · 0.1 = 0.006
- Var(P) = 0.25·0.04 + 0.25·0.01 + 2·0.5·0.5·0.006 = 0.01 + 0.0025 + 0.003 = 0.0155
- σP = √0.0155 ≈ 12.4%
Same as Var(X+Y) but cross term flips sign. When X and Y are highly correlated, spread variance is small — the math behind why pair trades work.
Same in the first slot by symmetry.
Derived in two steps, both from scratch.
Step 1 — variance of a single flip. One flip X is 1 with probability p, 0 with probability (1−p). Mean is E[X] = p. Plug into the squared-deviation definition — deviations are (1−p) for heads and (0−p) = −p for tails, each weighted by its probability:
Factor out p(1−p): the bracket is (1−p) + p = 1, so
(Peaks at p = 0.5, value 0.25 — the fair coin is the most uncertain, most variance per flip.)
Step 2 — n flips. Write H as a sum of n independent single flips, H = X1 + … + Xn. Variance of a sum adds the pairwise Cov terms, but independent flips have Cov(Xi, Xj) = 0, so every cross term drops. The n identical variances just add:
The np(1−p) isn’t handed to you — it falls out of one Bernoulli’s p(1−p) times n, because independence kills the covariances.
When ρ = 1: Cov(X, Y)2 = Var(X) · Var(Y).
The derivation recipe
Every identity in this neighborhood comes out of the same five moves. When you see a Var or Cov of something built from linear combinations of random variables, this is the procedure.
- Plug into the definition. Use Var(Z) = E[Z2] − (E[Z])2 or Cov(X, Y) = E[XY] − E[X]E[Y] depending on what you’re computing.
- Expand squares and products. Pure algebra on the random variables. FOIL out any binomials. No expectations yet.
- Apply E using linearity. Distribute E across sums, pull constants out of expectations. This is the step that does the most work. Always handle linearity first when you have the chance — squaring is not linear, so you simplify E first and let the square wrap what’s left.
- Group matching terms. Line up the things that share factors (a2 terms together, ab terms together, b2 terms together, etc.).
- Factor and recognize. Pull out shared factors and spot the patterns: (E[X2] − (E[X])2) is Var(X), and (E[XY] − E[X]E[Y]) is Cov(X, Y).
The reason this recipe always closes: variances and covariances are quadratic in the underlying random variables, so expanding any square or product of linear combinations only generates more variances and covariances. Step 5 is recognition, not computation. There’s nowhere else for the algebra to land.
Two applications
Flip a fair coin n = 100 times. H = heads, T = tails. Find E[H · T]. Worked slowly, because the one-line answer hides about six moves.
Step 1 — first reach, and why it fails. The instinct is E[H · T] = E[H] · E[T] = 50 · 50 = 2,500. But splitting a product of expectations like that is only legal when the two variables are independent. Check the precondition: H + T = 100, so knowing H pins down T exactly. Not independent. The naive split is off by a correction.
Step 2 — name the correction. That correction is what covariance is. Rearranging Cov(X, Y) = E[XY] − E[X]E[Y]:
Step 3 — get the sign first. H + T = 100, so when H is above its mean, T is forced below. They move opposite, always. So Cov(H, T) is negative, and the true answer lands below 2,500.
Step 4 — compute Cov(H, T) via substitution. Since T = 100 − H, write Cov(H, T) = Cov(H, 100 − H) and split with bilinearity:
Step 5 — Var(H) is the binomial variance. H is the count of heads in n flips, so Var(H) = np(1−p) = 100 · 0.5 · 0.5 = 25.
Step 6 — land it.
Where n(n−1) comes from. Keep everything in symbols instead of plugging in. E[H] = np and E[T] = n(1−p), so E[H]·E[T] = n2p(1−p), and Var(H) = np(1−p). Then:
The through-line: the answer falls short of E[H]·E[T] by exactly Var(H), because Cov(H, T) = −Var(H) whenever H and T sum to a constant.
Start from the workhorse with a = b = 0.5:
Impose equal variances Var(X) = Var(Y) = σ2, and write the cross term with correlation, Cov(X, Y) = ρσ2 (since Cov = ρ · σX · σY and both vols are σ):
Factor out 0.5σ2:
| ρ | Var(P) | σP (vol) | vs. one stock |
|---|---|---|---|
| +1 | σ2 | σ | no benefit — identical names |
| +0.5 | 0.75σ2 | 0.87σ | 13% vol cut |
| 0 | 0.5σ2 | 0.71σ | 29% vol cut (the √½ case) |
| −0.5 | 0.25σ2 | 0.5σ | half the vol |
| −1 | 0 | 0 | risk fully cancels |
The whole two-name diversification story lives in that (1 + ρ)/2 factor. Same vols, same weights, and correlation alone moves you from “no benefit” to “risk gone.”
Diversification benefit is the product of a weight piece (2w(1−w), maxed at w = 0.5) and a correlation piece (1−ρ). Need both to get benefit. With equal variances, equal weighting is optimal — any tilt from 50/50 sacrifices diversification.
Now drop the equal-variance assumption. Keep σX2 and σY2 separate. Weights w and (1−w):
Minimize over w. Var(P) is an upward parabola in w (positive coefficient on w2), so the critical point is the min. Differentiate term by term and set to zero:
Divide by 2, expand, collect the w terms on the left and constants on the right, factor w out:
The denominator is Var(X − Y) — the spread variance from earlier. The numerator is σY2 − Cov(X, Y).
Intuition — hold σX fixed at 20% (σX2 = 0.04), turn the σY knob:
| σY | σY2 | w* on X |
|---|---|---|
| 0 | 0 | 0 |
| 10% | 0.01 | 0.20 |
| 20% | 0.04 | 0.50 |
| 40% | 0.16 | 0.80 |
| ∞ | ∞ | → 1 |
X’s weight is driven by Y’s variance, not its own. The noisier the alternative, the more you pile into X. Three anchors: σY2 = 0 → w* = 0 (Y is riskless, hold only Y); σY2 = σX2 → w* = 0.5 (equal variances recover equal weighting); σY2 → ∞ → w* → 1 (Y is pure noise, flee into X). The cleanest limit: if σX2 = 0, then w* = 1 — a riskless X takes the whole book. Precision is just quietness, and you trust the quiet estimate more.
Same Form A grind, one more variable. Expand (aX + bY + cZ)2, apply E, subtract the squared-mean term. Every squared term becomes a variance, every cross term a covariance:
Counting the terms. For n assets you always get:
- n variance terms — one per asset (the ai2 Var pieces)
- nC2 = n(n−1)/2 covariance pairs — one per distinct pair
Total = n + nC2. For n = 3: 3 + 3 = 6. For n = 100: 100 variances + 4,950 covariance pairs. The cross terms grow as n2, which is exactly why nobody writes portfolio variance longhand past n = 3 — you switch to the matrix form.
| X (j=1) | Y (j=2) | Z (j=3) | |
|---|---|---|---|
| X (i=1) | a2Var(X) | ab Cov(X,Y) | ac Cov(X,Z) |
| Y (i=2) | ab Cov(X,Y) | b2Var(Y) | bc Cov(Y,Z) |
| Z (i=3) | ac Cov(X,Z) | bc Cov(Y,Z) | c2Var(Z) |
- Diagonal (i = j, shaded): Cov(ri, ri) = Var(ri), so the diagonal is the n variance terms.
- Off-diagonal (i ≠ j): each unordered pair appears twice — cell (X,Y) and cell (Y,X) are identical — and those two copies are exactly where the factor of 2 on each covariance comes from. You never write the 2 by hand; the grid double-counts it for you.
- w — the weight vector, weights stacked in a column.
- w⊤ — “w transpose,” the same weights laid flat as a row. Transpose just tips a column over into a row.
- Σ — the covariance matrix (the grid above). Watch out: this capital-sigma is the matrix, not a summation sign. Variances on the diagonal, covariances off it.
=MMULT(MMULT(TRANSPOSE(w), Σ), w).
Why bother, when the double sum already shows everything? Three practical reasons, none of them “it’s more correct.” It doesn’t grow — three symbols whether n is 2 or 2,000, where the double sum for 500 names is 250,000 terms. It’s how software actually computes portfolio variance (one fast matrix op). And optimization only speaks matrix: the minimum-variance weights come out as Σ−11 normalized, and the inverse Σ−1 has no double-sum spelling. The two-asset inverse-variance weighting derived above is Σ−1 for n = 2 — the matrix form is how that generalizes. For understanding, the double sum is enough; this is the notation for doing things with it.
The ladder
Each rung is built from the one before it — the definition first, then the algebra of scaling and adding, then portfolios, then the jump to the matrix. Nothing is assumed that wasn’t derived earlier.
Is this one lesson in a math course?
No. This would be roughly half a semester of a first probability course, or a full chapter and a half of a more applied stats book.
Rough mapping to a standard curriculum:
- Variance from the definition, E[X2] identity: one lecture, plus a problem set
- Covariance and the product identity: one lecture
- Scaling rules, bilinearity, variance of a sum: one to two lectures
- Portfolio variance, weighted sums, correlation: one lecture in the probability course, or the opening week of a finance/portfolio-theory course
- Binomial variance, applications: another lecture or two
So this is the equivalent of maybe four to six lectures of material, plus the problem sets that go with them. The reason it feels like a lot is that this sheet does the whole pipeline — derivation, intuition, numerical examples, applications — for each piece, instead of showing a formula and moving on.
The trade-off is real: this is slower but produces durable understanding. A typical math course shows you Var(aX + bY) on day one, leaves the “why it’s that and not something else” fuzzy, and you pattern-match for the rest of the semester. Done this way, when σ2 · (1+ρ)/2 turns up in a textbook two years later, you see the bilinearity FOIL behind it instead of recognizing a memorized formula.
That’s the trade. Slower, but it sticks.
