Day 22. Positive-Definite Matrices & Variance–Covariance Matrices
Random vectors, their covariance matrices, and the rules for the variance of any linear combination.
- ●Compute means and covariance matrices of random vectors and the variance of any linear combination a′X.
- ●Prove Var(AX + b) = AΣA′ and that every covariance matrix is positive semi-definite.
- ●Use the Cholesky factor to simulate correlated variables.
- ●Compute standard errors of sums and differences of correlated coefficient estimates.
Theory
Random vectors
For a random vector , the mean vector is and the variance–covariance matrix is
is symmetric. Its correlation matrix is with .
The two rules you will use every week
They give the variance of a portfolio, a contrast between treatment arms, a cumulative event-study effect, or a predicted value : just plug in .
Positive (semi-)definiteness
Because is a variance, it can never be negative: every covariance matrix is PSD. It is PD unless some combination of the variables is constant (e.g. shares that sum to one). A symmetric matrix that is not PSD (e.g. a "correlation matrix" assembled pairwise from different samples) cannot be the covariance matrix of anything.
Cholesky factor and simulation
A PD matrix factors as with lower-triangular (the Cholesky factor). If , then
This is how simulations generate correlated covariates, errors or potential outcomes.
Sample covariance
With the centred data matrix (), , which is PSD by Day 17.
Part 1 · Warm-up
Let .
Exercise 1 · Variance of a sum
Find .
Show solution
: .
Exercise 2 · Variance of a difference
Find .
Show solution
: .
Exercise 3 · Correlation
Find the correlation between and .
Show solution
.
Exercise 4 · A valid covariance matrix?
Can be a covariance matrix?
Show solution
Step 1. No.
Step 2. Its determinant is , so it has a negative eigenvalue; equivalently the implied correlation is 2.
Step 3. For , : a negative variance.
Exercise 5 · Cholesky by hand
Find the Cholesky factor of .
Show solution
Step 1. Write , so .
Step 2. Match to : .
Step 3. .
Step 4. .
Answer: .
Part 2 · Proofs
Exercise 6 · Variance of a linear combination
Prove .
Show solution
, a scalar equal to its own transpose. So
Exercise 7 · Linear transformations
Prove .
Show solution
, so .
Exercise 8 · Covariance matrices are PSD
Prove that every covariance matrix is positive semi-definite.
Show solution
For any , (Exercise 6).
Exercise 9 · Simulating with Cholesky
Prove that if then has mean and covariance .
Show solution
, and by Exercise 7, . (A linear function of normals is normal, so .)
Exercise 10 · What PD implies about entries
Show that a PD matrix has positive diagonal entries and .
Show solution
Take (the th unit vector): . The 2×2 leading block is also PD, so its determinant (product of its eigenvalues) is positive: .
Part 3 · Applied
Exercise 11 · Portfolio risk
Two assets have return sds 10% and 20% and correlation 0.3. With weights , find the portfolio sd.
Show solution
Step 1. Covariance: , so .
Step 2. .
Step 3. sd .
Answer: portfolio sd ≈ 11.35%.
Exercise 12 · Minimum-variance weights
For the same assets, find the weight that minimises portfolio variance (with ).
Show solution
Step 1. Variance as a function of : .
Step 2. Set and solve:
Step 3. Plug in: .
Answer: about 89.5% in the less risky asset (Day 26 derives the general version with a Lagrange multiplier).
Exercise 13 · Are two effects different?
A regression gives and with , , . Test .
Show solution
Step 1. Contrast : .
Step 2. SE ; estimate .
Step 3. , .
Answer: not significantly different. Ignoring the covariance would give SE instead.
Exercise 14 · A cumulative effect
An event study estimates three post-period effects, each with variance 0.01 and pairwise covariance 0.005. Find the SE of their sum.
Show solution
Step 1. The sum is , so its variance is = the sum of all entries of .
Step 2. Diagonal: . Off-diagonal: 6 entries × 0.005 = 0.03.
Step 3. Total 0.06, SE .
Answer: 0.245; assuming independence would give 0.173, far too small.
Exercise 15 · An impossible set of survey correlations
A report on a household survey lists pairwise correlations computed from different sub-samples: income–education 0.9, income–health 0.9, and education–health −0.9. Could these be the correlations of three real variables?
Show solution
Step 1. A valid correlation matrix must be PSD, so its determinant (the product of the eigenvalues) cannot be negative.
Step 2. Cofactor expansion of :
Step 3. Negative, so has a negative eigenvalue (−0.8, from the code).
Answer: impossible. If income is strongly correlated with both education and health, those two cannot be strongly negatively correlated. Pairwise estimates from different samples can produce such incoherent matrices.
Verify in Python
import numpy as np
S = np.array([[4, 2], [2, 9.]])
for a in ([1, 1], [1, -1]):
a = np.array(a); print("Var(a'X) for a =", a, ":", a @ S @ a)
L = np.linalg.cholesky(S); print("Cholesky L =\n", L.round(3))
rng = np.random.default_rng(22)
Z = rng.normal(size=(2, 200_000)); X = (L @ Z).T
print("simulated covariance:\n", np.cov(X.T).round(2))
w = np.array([0.6, 0.4]); Sig = np.array([[100, 60], [60, 400.]])
print("portfolio sd:", round(np.sqrt(w @ Sig @ w), 2))
V = np.array([[0.01, 0.005, 0.005], [0.005, 0.01, 0.005], [0.005, 0.005, 0.01]])
print("SE of cumulative effect:", round(np.sqrt(np.ones(3) @ V @ np.ones(3)), 3))
R = np.array([[1, 0.9, 0.9], [0.9, 1, -0.9], [0.9, -0.9, 1]])
print("eigenvalues of the 'correlation matrix':", np.linalg.eigvalsh(R).round(3))
Key takeaways
- and give the variance of any linear combination.
- Covariance matrices are PSD; a matrix that is not PSD cannot describe real data.
- Cholesky factors turn independent normals into correlated ones, the basis of most simulation studies.
Simulation Lab: Covariance Ellipses & a′Σa
Open full screen →Correlated draws built with a Cholesky factor, their covariance ellipses, and the variance of any linear combination.
500 draws made from independent normals with the Cholesky factor L. The ellipses are the 1- and 2-sd contours; their axes are the eigenvectors of Σ. The orange direction a gives a combination a′X whose variance is a′Σa.