Linear Algebra

Lesson 11 of 11

Principal Component Analysis

Principal components as eigenvectors of the covariance matrix, computing them with the SVD, choosing how many to keep, and the level, slope and curvature of the yield curve.

The direction of maximum variance

Stack nn observations of pp variables into a data matrix XX (n×pn \times p) and subtract each column's mean. The sample covariance matrix is

Σ=1n−1XTX\Sigma = \frac{1}{n-1} X^T X

Project every row onto a unit vector w\mathbf{w} and each observation becomes a single number. The column of those numbers, XwX\mathbf{w}, has variance

Var(Xw)=wTΣ w\text{Var}(X\mathbf{w}) = \mathbf{w}^T \Sigma\, \mathbf{w}

PCA asks which unit w\mathbf{w} makes this as large as possible. Σ\Sigma is symmetric, so the spectral theorem hands us an orthonormal eigenbasis q1,…,qp\mathbf{q}_1, \dots, \mathbf{q}_p with eigenvalues λ1≥⋯≥λp≥0\lambda_1 \ge \dots \ge \lambda_p \ge 0. Write w=∑ciqi\mathbf{w} = \sum c_i \mathbf{q}_i with ∑ci2=1\sum c_i^2 = 1. Then wTΣw=∑λici2\mathbf{w}^T\Sigma\mathbf{w} = \sum \lambda_i c_i^2, a weighted average of the eigenvalues, which is largest when all the weight sits on λ1\lambda_1. The best direction is the top eigenvector and the variance it captures is λ1\lambda_1. The best direction orthogonal to that one is q2\mathbf{q}_2, and so on down the list. These eigenvectors are the principal components.

Example: two stocks with daily return covariance Σ=(5222)\Sigma = \begin{pmatrix} 5 & 2 \\ 2 & 2 \end{pmatrix} in %2\%^2. Trace 7 and determinant 6 give eigenvalues 6 and 1. The first PC is (2,1)/5(2,1)/\sqrt{5} with variance 6. For comparison, the first stock alone, w=(1,0)\mathbf{w} = (1,0), gives 5, and the equal-weight direction (1,1)/2(1,1)/\sqrt{2} gives (5+2+2+2)/2=5.5(5+2+2+2)/2 = 5.5. No unit direction beats 6, and that single line carries 6/7≈86%6/7 \approx 86\% of the total variance.