Variance & Covariance Cheat Sheet

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 — average squared deviation from the mean
Var(X) = E[(X μ)2]    μ = E[X]
Covariance — average product of deviations
Cov(X, Y) = E[(X μX)(Y μY)]
Sum of squared deviations (the un-averaged version)
SS = Σ (xi μ)2    Var = SSn

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

Variance from the definition
Var(X) = E[(X μ)2] = E[X2] (E[X])2

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:

1n Σ(xi x)2 = 1n Σ(xi2 2xix + x2)

Average term by term. The key is that x is a constant (already computed), so it pulls out of the sums:

  • First term: (1/nxi2 = E[X2]
  • Middle term: (1/n)Σ(2xix) = 2x · (1/nxi = 2x · x = 2(E[X])2
  • Last term: (1/nx2 = 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:

E[X2] 2(E[X])2 + (E[X])2 = E[X2] (E[X])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.

Covariance from the definition
Cov(X, Y) = E[(X μX)(Y μY)] = E[XY] E[X]E[Y]

Average of the products minus the product of the averages.

Variance is covariance with itself
Cov(X, X) = Var(X)
Scaling rule for variance
Var(aX) = a2 · Var(X)

Constants pull out as their square.

Scaling rule for covariance
Cov(aX, bY) = ab · Cov(X, Y)
Shifting rule for covariance
Cov(X + c, Y) = Cov(X, Y)

Adding a constant doesn’t change covariance.

Covariance with a constant is zero
Cov(X, c) = 0

Constants don’t co-vary.

Variance of a sum
Var(X + Y) = Var(X) + Var(Y) + 2 · Cov(X, Y)
Variance of a weighted sum (the workhorse)
Var(aX + bY) = a2 Var(X) + b2 Var(Y) + 2ab · Cov(X, Y)

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.

Worked example. Two assets: σX = 20%, σY = 10%, ρ = 0.3. Equal weights a = b = 0.5.
  • 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%
Compare to the naive weighted-average vol, 0.5·20% + 0.5·10% = 15%. The cross term (with ρ < 1) is what pulls portfolio vol below the average of the two vols. That gap is the diversification benefit.
Variance of a difference (spread variance / pair-trading formula)
Var(X Y) = Var(X) + Var(Y) 2 · Cov(X, Y)

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.

Bilinearity of covariance
Cov(X, A + B) = Cov(X, A) + Cov(X, B)

Same in the first slot by symmetry.

Where it’s used. This is the move that lets you compute an asset’s covariance with a whole portfolio without re-deriving anything. Say a portfolio P = 0.5A + 0.5B and you want how asset A co-moves with the portfolio it sits in:
Cov(A, P) = Cov(A, 0.5A + 0.5B) = 0.5 Var(A) + 0.5 Cov(A, B)
Distribute across the sum, pull the weights out. That number — an asset’s covariance with its own portfolio — is its marginal contribution to portfolio risk, and it’s exactly what you FOIL out when you expand Var(w1X1 + … + wnXn) into the full covariance matrix. Bilinearity is the engine under every portfolio-variance calculation.
Variance of a binomial
Var(H) = np(1p)   where H = Σ Xi

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 (1p). Mean is E[X] = p. Plug into the squared-deviation definition — deviations are (1p) for heads and (0p) = p for tails, each weighted by its probability:

Var(X) = p(1p)2 + (1p)p2

Factor out p(1p): the bracket is (1p) + p = 1, so

Var(X) = p(1p)

(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:

Var(H) = Σ Var(Xi) = n · p(1p)

The np(1p) isn’t handed to you — it falls out of one Bernoulli’s p(1p) times n, because independence kills the covariances.

Standard deviation scaling
StDev(aX) = |a| · StDev(X)
Correlation definition
ρ = Cov(X, Y)σX · σY

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.

  1. 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.
  2. Expand squares and products. Pure algebra on the random variables. FOIL out any binomials. No expectations yet.
  3. 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.
  4. Group matching terms. Line up the things that share factors (a2 terms together, ab terms together, b2 terms together, etc.).
  5. 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

Interview problem: E[H · T] for n coin flips

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]:

E[H · T] = E[H] · E[T] + Cov(H, T)
Independent → Cov = 0 → naive split exact. Locked → Cov ≠ 0 → you need the term.

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:

Cov(H, 100 H) = Cov(H, 100) + Cov(H, H)
First term is covariance with a constant → 0. Second term, pull out the 1 (scaling rule, ab = 1 · (1) = 1):
= 0 Cov(H, H) = Var(H)
So Cov(H, T) = Var(H). Now it’s earned, not asserted.

Step 5 — Var(H) is the binomial variance. H is the count of heads in n flips, so Var(H) = np(1p) = 100 · 0.5 · 0.5 = 25.

Step 6 — land it.

E[H · T] = 2,500 25 = 2,475

Where n(n1) comes from. Keep everything in symbols instead of plugging in. E[H] = np and E[T] = n(1p), so E[H]·E[T] = n2p(1p), and Var(H) = np(1p). Then:

E[H · T] = n2p(1p) np(1p) = p(1p)[n2 n] = n(n1)p(1p)
The n2 is the naive product, the n is the variance shortfall, and factoring out p(1p) leaves n(n1). Sanity check: 100 · 99 · 0.25 = 2,475. ✓

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.

Two-stock equal-weight portfolio with equal variances σ2 and correlation ρ

Start from the workhorse with a = b = 0.5:

Var(P) = 0.25 Var(X) + 0.25 Var(Y) + 2(0.5)(0.5) Cov(X, Y)

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 σ):

Var(P) = 0.25σ2 + 0.25σ2 + 0.5ρσ2 = 0.5σ2 + 0.5ρσ2

Factor out 0.5σ2:

Var(P) =  σ2(1 + ρ)2
Why this is the instructive form. Weights are fixed (50/50) and both vols are fixed (σ). The only thing left moving is ρ. So the entire diversification effect is carried by the single factor (1 + ρ)/2 — a clean dial from 0 to 1 that multiplies the single-name variance. Sweep ρ and read what correlation actually does:
ρ Var(P) σP (vol) vs. one stock
+1σ2σno benefit — identical names
+0.50.75σ20.87σ13% vol cut
00.5σ20.71σ29% vol cut (the √½ case)
−0.50.25σ20.5σhalf the vol
−100risk fully cancels
The variance scales linearly in ρ, but the thing you feel — vol, σP = σ√((1+ρ)/2) — scales as the square root, so the first chunk of decorrelation buys more than the last. Going from ρ = 1 to ρ = 0.5 already takes 13% off your vol. You do not need negative correlation to diversify; anything below +1 helps. Negative correlation is just the strong form, and ρ = −1 is the perfect hedge where the two positions cancel outright.

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.”

Two-stock unequal-weight portfolio with equal variances σ2 and correlation ρ
Var(P) = σ2 [1 2w(1w)(1ρ)]

Diversification benefit is the product of a weight piece (2w(1w), 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.

Two-stock unequal-variance portfolio → inverse-variance weighting

Now drop the equal-variance assumption. Keep σX2 and σY2 separate. Weights w and (1w):

Var(P) = w2σX2 + (1w)2σY2 + 2w(1w)ρσXσY

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:

2wσX2 2(1wY2 + 2(12w)ρσXσY = 0

Divide by 2, expand, collect the w terms on the left and constants on the right, factor w out:

wX2 + σY2 2ρσXσY) = σY2 ρσXσY
w* =  σY2 ρσXσYσX2 + σY2 2ρσXσY

The denominator is Var(X Y) — the spread variance from earlier. The numerator is σY2 Cov(X, Y).

The payoff — set ρ = 0 (independent names):
w* = σY2σX2 + σY2 = 1/σX21/σX2 + 1/σY2
That’s inverse-variance weighting: each asset’s weight is its inverse variance over the sum of inverse variances. The quieter asset gets more money. This is the result behind Kalman filters, weighted least squares, and meta-analysis — anywhere you optimally combine noisy estimates, you weight by precision (1/variance). It’s also the “optimal” cousin of the inverse-vol risk-parity heuristic, which ignores correlations.

Intuition — hold σX fixed at 20% (σX2 = 0.04), turn the σY knob:

σY σY2 w* on X
000
10%0.010.20
20%0.040.50
40%0.160.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 = σX2w* = 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.

Three-variable portfolio variance → why the matrix shows up

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:

Var(aX + bY + cZ) = a2Var(X) + b2Var(Y) + c2Var(Z) + 2ab Cov(X,Y) + 2ac Cov(X,Z) + 2bc Cov(Y,Z)

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.

The double-sum / matrix form. Organize every term into a grid indexed by asset pairs. With weights wi and returns ri:
Var(P) = Σi Σj wi wj Cov(ri, rj) = wΣw
Reading the double sum: the outer Σ over i and the inner Σ over j together form every ordered pair (i, j). For each pair you drop in one term, wiwjCov(ri, rj), and add them all up. For n = 3 that’s 3 × 3 = 9 cells:
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)
Sum all nine cells and you get the six-term formula above. Two things to see:
  • Diagonal (i = j, shaded): Cov(ri, ri) = Var(ri), so the diagonal is the n variance terms.
  • Off-diagonal (ij): 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.
So Σ is the covariance matrix: variances down the diagonal, covariances off it. wΣw just says “sweep every cell of the grid, weight it, sum it.” The n + nC2 count is the matrix — diagonal plus (doubled) upper triangle. You’ve already discovered why the matrix form is inevitable; it’s just bookkeeping for the term explosion.
Figure — the double sum is the matrix: one sweep, three views
Var(P) = Σi Σj wiwj Cov(ri, rj) an instruction for sweeping a grid: for every row i, for every column j, add that cell inner Σ over j → picks the column X (j=1) Y (j=2) Z (j=3) outer Σ over i → picks the row X (i=1) Y (i=2) Z (i=3) w1² Var(X) w1w2 Cov(X,Y) w1w3 Cov(X,Z) w2w1 Cov(X,Y) w2² Var(Y) w2w3 Cov(Y,Z) w3w1 Cov(X,Z) w3w2 Cov(Y,Z) w3² Var(Z) Diagonal (i = j): Cov(ri, ri) = Var(ri) — the 3 variance terms. Twin cells (i,j) & (j,i): identical — every covariance is visited twice. That double-count is the ×2 you wrote by hand. The grid supplies it for free. add all 9 cells = wT Σ w Σ is the covariance matrix: variances on the diagonal, covariances off it. n assets = the same sweep on an n×n grid. Nothing new happens; the grid just grows.
Figure — three forms of the same variance, and where the 2s go
① ALGEBRAIC — you write the 2s by hand a²Var(X) + b²Var(Y) + c²Var(Z) 2ab Cov(X,Y) + 2ac Cov(X,Z) + 2bc Cov(Y,Z) ② MATRIX — the 2s vanish into the symmetry Var(P) = wT Σ w,   where Σ = Var(X) Cov(X,Y) Cov(X,Z) Cov(X,Y) Var(Y) Cov(Y,Z) Cov(X,Z) Cov(Y,Z) Var(Z) Each covariance sits in two matched-color cells (mirrored across the diagonal). Summed, the two cells are the 2 from Stage 1. Variances (diagonal, purple) have no mirror — that’s why they’re never doubled. ③ DOUBLE SUM — the matrix written in math Var(P) = Σ n i=1 Σ n j=1 wiwj Cov(ri, rj) Cov(ri, ri) = Var(ri) — covariance with itself is just variance, so the diagonal needs no special case. Both sums run 1 to n, so the sweep is n² terms. 10 assets → 100 terms, not 20. That quadratic blow-up is exactly why the compact matrix form earns its keep.
Notation you’ll see in practice: wΣw. You’ll run into this constantly in risk models, optimizers, and quant papers. It’s the same portfolio variance, packaged as a matrix operation. Reading it piece by piece:
  • 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.
So wΣw is row-of-weights × matrix × column-of-weights, which multiplies out to a single number — the portfolio variance. It’s identical to the double sum, and in a spreadsheet it’s literally =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.

1.  Variance as average squared deviation
2.  Var(X) = E[X2] (E[X])2 — from the definition
3.  Cov(X, Y) = E[XY] E[X]E[Y] — from the definition
4.  Var(aX) = a2·Var(X)
5.  Cov(aX, bY) = ab·Cov(X, Y)
6.  Cov(X + c, Y) = Cov(X, Y) and Cov(X, c) = 0
7.  Var(X + Y) = Var(X) + Var(Y) + 2·Cov(X, Y)
8.  Var(aX + bY) — the full weighted-sum workhorse
9.  Two-stock equal-weight portfolio variance → the (1+ρ)/2 diversification factor
10. Two-stock unequal-weight portfolio variance (equal variances)
11. Var(X Y) — spread variance / pair-trading formula
12. Variance of a binomial = np(1p)
13. Two-stock unequal-variance portfolio → inverse-variance weighting
14. Var(aX + bY + cZ) — three variables, and the n + nC2 term count
15. General n-asset portfolio variance — the wΣw matrix form

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.

Leave a Reply