Why your covariance matrix is lying, and how shrinkage fixes it
A portfolio optimiser takes your covariance matrix at its word. Give it the sample covariance of 100 stocks estimated on 250 days, and it will find combinations that look nearly riskless in the data, because noise has made some directions look much quieter than they are. Then it bets heavily on exactly those directions. The fix is to stop trusting the sample matrix so much.
Pure noise still has a spread-out spectrum
Take 100 assets that are truly independent with variance 1, so the true covariance is the identity and every eigenvalue is exactly 1. Estimate the covariance from T = 250 days and compute the eigenvalues of the sample matrix. They don’t cluster around 1. They spread from about 0.14 to 2.7.
That is the Marchenko–Pastur law. As N and T grow with fixed, the histogram of sample eigenvalues converges to a known density supported on . With q = 0.4, that is [0.135, 2.665]. Even with four times as many days as assets, the smallest sample eigenvalue understates the true variance by a factor of 7.
Why does this matter? The eigenvectors with small eigenvalues are portfolios the data says are very low risk. The optimiser loves them. But their low variance is mostly luck in this particular sample.
Eigenvalues of a sample covariance when the truth is the identity
Min-variance portfolio risk vs shrinkage α (× best possible)
In the left panel, compare T = 125, 250 and 1,000. The spread shrinks as T grows, but slowly: even with 10 times more data than assets (q = 0.1), the eigenvalues still range from about 0.47 to 1.73.
The optimiser underestimates risk and then takes too much
The minimum-variance portfolio, , uses only the covariance matrix, so it isolates the problem. When the true covariance is the identity and returns are normal, there are clean results for large N and T:
With q = 0.4, that’s 0.77× and 1.29×. The portfolio believes it is 23% safer than the best possible portfolio, and is in fact 29% riskier. As q approaches 1 (as many assets as days) both go badly wrong, and at q ≥ 1 the sample matrix can’t be inverted at all.
The right panel uses a more realistic truth: volatilities ranging from 0.7 to 1.4 and a correlation of 0.1 between every pair. The blue curve is the true risk of the min-variance portfolio built with shrinkage α. With α = 0 it is about 1.29× the best possible. Shrinking brings it down to about 1.12× around α = 0.4, after which the target’s own bias takes over and the risk climbs again. The dashed grey curve is what each portfolio thinks its risk is. It sits below the truth everywhere.
Shrinkage: a weighted average of noisy and wrong
The sample covariance S is unbiased but noisy. A simple target F, such as the average variance times the identity, is very stable but biased: it ignores all correlations and differences in volatility. A weighted average,
trades some bias for a lot less variance. It also pulls the extreme eigenvalues towards the middle: every eigenvalue becomes , so the near-zero directions the optimiser loved are no longer near zero.
The question is how much to shrink. Ledoit and Wolf (2004) found the α that minimises the expected squared (Frobenius) error between and the true Σ, and showed it can be estimated from the data:
- Numerator: how noisy S is. Each day’s outer product is a one-observation estimate of Σ; their average spread around S, divided by T, estimates the variance of S.
- Denominator: how far S is from the target. If S is already close to F, there’s little to lose by shrinking.
In the right panel’s setting the Ledoit–Wolf α averages about 0.27 and brings the risk to 1.13× the best possible, close to the 1.12× of the best α in hindsight. It isn’t exactly at the minimum because it optimises the error of the matrix, not the risk of the portfolio, but it gets most of the benefit with no tuning.
import numpy as np
def ledoit_wolf(X):
"""Ledoit–Wolf shrinkage towards mu * I. X is T x N (rows = observations)."""
T, N = X.shape
Xc = X - X.mean(axis=0)
S = Xc.T @ Xc / T
mu = np.trace(S) / N
F = mu * np.eye(N)
d2 = np.sum((S - F) ** 2) # distance from target
b2 = sum(np.sum((np.outer(x, x) - S) ** 2) for x in Xc) / T**2 # noise in S
alpha = min(b2, d2) / d2
return alpha * F + (1 - alpha) * S, alpha
# sklearn.covariance.LedoitWolf gives the same estimator.Other ways to clean a covariance matrix
- Better targets. The constant-correlation matrix, or a single-factor (market) model, keep more structure than μI and usually work better for stocks. When one strong market factor dominates, μI is a poor target and the Ledoit–Wolf α comes out small.
- Eigenvalue clipping. Replace every eigenvalue inside the Marchenko–Pastur band by their average, and keep the ones above it as real signal.
- Factor models. Impose structure directly: Σ = BΩBᵀ + D with a few factors. Far fewer parameters to estimate.
- Nonlinear shrinkage (Ledoit–Wolf 2017) shrinks each eigenvalue by its own amount, and does better than linear shrinkage when N is large.
Where people slip in interviews
- “More assets is fine as long as T > N.” The noise depends on N/T. At N/T = 0.5 the sample matrix is badly distorted even though it’s invertible.
- Trusting in-sample risk. An optimised portfolio’s in-sample risk is biased down, because the optimiser picked the directions that looked quietest.
- Thinking shrinkage biases the answer, so it’s worse. It does add bias, but it removes much more variance. The total error goes down.
- Shrinking correlations but not volatilities, or vice versa, without thinking. Shrinking towards μI also pulls volatilities together. Shrinking the correlation matrix towards its average leaves volatilities alone.
Try these before you open the answer
Warm-up500 stocks, 2 years of daily data (504 days). Can you invert the sample covariance matrix?Show answer
Barely. N = 500 < T = 504, so the matrix is full rank, but q ≈ 0.99 puts the smallest eigenvalues near times the true scale. The inverse is dominated by noise.
MPWith N = 50 and T = 200, where does Marchenko–Pastur put the sample eigenvalues when the truth is the identity?Show answer
RiskTruth is the identity, N = 100, T = 400. By what factors are the min-variance portfolio's in-sample and true risk off from the best possible?Show answer
q = 0.25. In-sample , true .
EigenvaluesS has eigenvalues 0.1 and 3.0, the average variance is μ = 1.55, and you shrink with α = 0.3. What are the eigenvalues of the shrunk matrix?Show answer
The target is a multiple of I, so eigenvectors don’t change: , and . The ratio of largest to smallest falls from 30 to about 4.8.
LimitsWhat does the Ledoit–Wolf α do as T grows with N fixed? Why?Show answer
It goes to 0. The noise term (numerator) shrinks like 1/T, while the distance from S to the target converges to the distance from Σ to the target, which stays fixed. With lots of data, trust the data.
StretchWhy does the min-variance optimiser make in-sample risk too low, even though S is an unbiased estimate of Σ?Show answer
For any fixed w, is unbiased for . But the optimiser picks the w that minimises , and the minimum of noisy estimates is biased down. It’s the same selection effect as picking the best of many backtests.
The risk ratios were checked over 100 simulated samples for each setting. The figure computes the eigenvalues and the Ledoit–Wolf α in your browser on a fresh sample each time.