Covariance and correlation — the math of diversification
▸ Pretest — guess, even if you don't know
Two stocks each have 20% annual volatility. You put half your money in each. Their returns are uncorrelated. What's the portfolio's volatility?
Covariance: do they move together?
Volatility (A2-02) describes one return series in isolation. Portfolios live or die by a different question: when stock A has a bad day, what does stock B tend to do? Covariance is that question as a number:
In words: "the covariance of X and Y equals the expected value of (X minus its mean) times (Y minus its mean)." reads "mu sub X" — the mean of X; is the mean of Y. So: take each day's deviation of X from its mean, multiply it by that same day's deviation of Y from its mean, and average the products.
Read the inside term day by day for two stocks. On a day when both are above their means, the product of deviations is positive × positive — positive. Both below: negative × negative — positive again. One up, one down: the product is negative. Covariance averages these products:
- Positive covariance — they tend to be on the same side of their means together (two US banks).
- Near zero — no linear tendency either way (a tech stock and wheat futures, roughly).
- Negative — one tends to be up when the other is down (equities and long-dated Treasuries, in some regimes).
Note . In words: the covariance of X with itself is the average squared deviation of X — which is exactly the variance from A1-04. Variance is covariance with yourself.
Correlation: covariance you can interpret
Covariance has awkward units (return × return). Its magnitude also scales with each asset's volatility, so "Cov = 0.0002" is uninterpretable on its own. The fix: normalize — divide out both assets' scales so what's left is a pure number:
In words: correlation — written , the Greek letter "rho" — equals the covariance divided by the product of the two standard deviations. And rho always lands between minus 1 and plus 1, inclusive.
Concrete: if Cov = 0.0002 and both assets have daily volatility 0.02 (2%), then — a strong positive relationship, now visible.
The bounds are a theorem (Cauchy–Schwarz, a classical inequality of mathematics), not a convention. means an exact increasing straight-line relationship; an exact decreasing one; means no linear relationship. A perfect U-shape can have — correlation only sees lines. Typical daily-return correlations: two large-cap US stocks 0.3–0.6; a stock with its own sector ETF 0.7–0.9.
The sample versions replace expectations with plain averages over your data, using the same Bessel correction as A2-02. One gotcha: numpy's np.cov uses ddof=1 by default, unlike np.std, which defaults to ddof=0:
cov_xy = np.cov(x, y)[0, 1] # 2x2 matrix; off-diagonal is Cov(x, y)
corr_xy = cov_xy / (x.std(ddof=1) * y.std(ddof=1))
The payoff: portfolio variance
From A1-04, for portfolio weights and (ordinary fixed numbers — the fractions of your money in each asset):
In words: the variance of the portfolio "a of X plus b of Y" is: a-squared times X's variance, plus b-squared times Y's variance, plus a cross term — 2 times a times b times the covariance of X and Y.
Everything about diversification — spreading money across assets to reduce risk — hides in that last term. Work the pretest example properly. Take and (half your money in each). The first two terms give . The covariance is , so the cross term depends entirely on the correlation:
| Correlation | Portfolio variance | Portfolio volatility |
|---|---|---|
The lesson of the table: diversification is a correlation play, not a headcount play. At you get nothing — you own one asset wearing two tickers. Real diversification benefit only appears as drops below 1. That's why a portfolio of 30 highly correlated tech stocks is far less diversified than 5 genuinely unrelated return streams.
Two honest warnings
Correlation is not causation — and it isn't stable either. The first half is A1-05's conditional-is-not-causal trap, in linear clothing. The second half: financial correlations are estimated from a window of data, and they drift across regimes — market environments — just like volatility in A2-02.
"Correlations go to 1 in a crash." The trading floor version is exaggerated but points at something real. Measured correlations between risky assets rise sharply in crises. Assets that looked pleasantly independent in calm markets fall together when everyone deleverages — sells positions to pay down borrowed money — at once. (One technical caveat: correlation measured only during high-volatility periods is mechanically higher even if the true relationship never changed. So part of the effect is a measurement artifact — but the economic core is real.) The practical consequence is brutal: diversification measured in calm markets overstates the protection you'll have in the storm, which is precisely when you need it. Never size positions assuming calm-period correlations hold in a tail event — one of the rare, extreme days out in the far end of the distribution.
Forward pointer: regression beta (A2-06) is . In words: beta equals the covariance of the stock's return with the market's return, divided by the variance of the market's return — covariance rescaled by the market's variance alone, instead of by both standard deviations. Correlation and beta are the same object under two different normalizations.
Try it
Implement corr(x, y): the sample correlation of two equal-length arrays — sample covariance (np.cov uses ddof=1 by default) divided by the product of the two sample standard deviations (std with ddof=1).
⧉ Review cardDefine covariance and give the sign intuition.
⧉ Review cardWhat is correlation and why use it instead of covariance?
⧉ Review cardWhat is Var(aX + bY), and where does diversification live in it?
⧉ Review cardWhat happens to correlations between risky assets in a crisis?
⧉ Review cardHow does beta relate to covariance and correlation?
Map it
On paper, draw a concept map connecting: variance, covariance, correlation, Var(aX+bY), diversification, crisis correlation, and beta. Draw a labelled arrow for each relationship (e.g., which normalization turns covariance into correlation? into beta? which term of the portfolio-variance formula does diversification act through?).
◈ Calibration check
Could you compute a sample correlation from scratch and explain, with the formula, why diversification fails at correlation +1?
1 = guessing · 5 = could teach it
⏻ End of lesson
Mark it read to book its 5 review cards into your deck.
Sources & further reading
- bookWasserman (2004), All of Statistics — §3
- bookBodie, Kane & Marcus (2014), Investments, 10e — §6, 7