Principal Component Analysis and Factor Extraction › Mathematical Foundation of PCA
Quantitative FinanceAll chapters Principal Component Analysis and Factor Extraction › Mathematical Foundation of PCAOne section · Sections in this chapter3 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
PCA turns a set of correlated variables into uncorrelated principal components, ordered by the amount of variance they explain. The step is linear and orthogonal, meaning it preserves distances and angles while rotating the coordinate system to align with directions of maximum variance. This section develops the mathematical framework that makes this step possible, starting from the raw data and building toward the eigenvalue problem that lies at the heart of PCA.
Setting Up the Problem
Suppose we have observations of variables, organized in an data matrix . Each row represents one observation (e.g., one day's yield curve), and each column represents one variable (e.g., the yield at a specific maturity). This matrix structure provides a natural way to organize our data: reading across a row shows us the complete cross-section of variables at one point in time, while reading down a column reveals the time series of a single variable.
The first step is to center the data by subtracting the column means. Centering is essential because PCA seeks directions of maximum variance, and variance is measured relative to the mean. Without centering, the first principal component would simply point toward the overall mean of the data rather than capturing the directions of greatest spread. Let denote the -dimensional vector of column means. The centered data matrix is:
where:
- : centered data matrix
- : original data matrix
- : vector of ones of size
- : vector of column means
In this expression, the outer product creates an matrix where every row is identical to the transpose of the mean vector. Subtracting this from the original data ensures that each column of the resulting matrix has mean zero.
The sample covariance matrix is then:
where:
- : sample covariance matrix
- : number of observations
- : centered data matrix
To understand why this formula produces the covariance matrix, consider what happens when we multiply by . The result is a matrix where the entry equals the sum of products of the centered values for variables and across all observations. Dividing by (rather than ) gives us the unbiased sample covariance, correcting for the fact that we have estimated the means from the same data. This symmetric positive semi-definite matrix captures how the variables co-move. The diagonal elements are variances; the off-diagonal elements are covariances.
Eigendecomposition and Principal Components
As we discussed in Part I's treatment of linear algebra, any symmetric matrix can be decomposed into its eigenvalues and eigenvectors. This spectral theorem is the mathematical foundation of PCA, and gives the key insight that allows us to find orthogonal directions of maximum variance. For the covariance matrix:
where:
- : covariance matrix
- : diagonal matrix of eigenvalues
- : orthogonal matrix of eigenvectors
- : -th eigenvector (column of )
- : total number of variables
The eigenvalues are ordered from largest to smallest, which reflects the need for each direction for explaining variance. Because the covariance matrix is positive semi-definite (a property inherited from its construction as scaled by a positive constant), all eigenvalues are non-negative. The eigenvectors form an orthonormal basis, meaning they are mutually perpendicular and each has unit length. This orthogonality matters because it ensures that the principal components are uncorrelated.
The -th principal component is defined as the projection of the centered data onto the -th eigenvector:
where:
- : vector of scores for the -th principal component
- : centered data matrix
- : -th eigenvector (loading vector)
This projection operation computes a weighted sum of the original variables for each observation, where the weights come from the eigenvector. The result is an -dimensional vector of principal component scores, with one score for each observation. The eigenvector is called the -th loading vector because it specifies how each original variable contributes to the component. A large positive loading means that variable contributes strongly and positively to the component; a large negative loading means it contributes strongly but in the opposite direction.
Why Eigendecomposition Maximizes Variance
The first principal component is the linear combination of the original variables with maximum variance. This is more than a convenient property; it is the defining characteristic of PCA. To see why finding this direction of maximum variance corresponds to finding the first eigenvector, consider finding the unit vector that maximizes the variance of .
The variance of the projection is:
where:
- : projection vector (weights)
- : covariance matrix
- : centered data matrix
- : number of observations
This derivation reveals a key connection: the variance of any linear combination of our variables equals a quadratic form in the covariance matrix. The quadratic form measures how the covariance structure "stretches" the unit vector . Our goal is to find the direction that experiences maximum stretching.
We want to maximize this subject to . The constraint is necessary because without it, we could increase variance indefinitely by scaling . By restricting ourselves to unit vectors, we focus on finding the direction of maximum variance rather than an arbitrarily long vector. Using Lagrange multipliers (recall our optimization discussion from Part I), we set:
where:
- : Lagrangian function
- : Lagrange multiplier (eigenvalue)
- : projection vector
- : covariance matrix
The Lagrangian incorporates our constraint through the multiplier , which will turn out to have a deep interpretation as the eigenvalue. Taking the derivative with respect to and setting it to zero:
where:
- : gradient of the Lagrangian with respect to
- : covariance matrix
- : projection vector
- : Lagrange multiplier (eigenvalue)
The gradient of the quadratic form equals because of the symmetry of , and the gradient of equals . This yields the eigenvalue equation:
where:
- : covariance matrix
- : eigenvector
- : eigenvalue
This equation has a geometric interpretation. The covariance matrix acts as a linear transformation that stretches and rotates vectors. An eigenvector is special because when acts on it, the result points in the same direction as the original vector, merely scaled by the eigenvalue . These are precisely the directions along which the covariance structure exhibits pure stretching without rotation.
Substituting this into the variance definition:
where:
- : variance of the projected data
- : projection vector
- : covariance matrix
- : eigenvalue
This result shows that the variance of the projection onto an eigenvector exactly equals the corresponding eigenvalue. To maximize variance, we choose the eigenvector with the largest eigenvalue. This eigenvector points in the direction of greatest spread in our data.
For subsequent components, we impose the additional constraint of orthogonality to previously selected directions. This sequential optimization produces the full set of eigenvectors, ordered by decreasing eigenvalue. The second principal component is the direction of maximum variance among all directions perpendicular to the first, and so on. Because the eigenvectors of a symmetric matrix are automatically orthogonal, the eigendecomposition provides exactly what we need.
Variance Explained
The eigenvalues have a direct interpretation: equals the variance of the -th principal component. This is not a coincidence but follows directly from the derivation above. When we project our data onto the -th eigenvector, the resulting variance equals . The total variance in the data equals the sum of all eigenvalues (which also equals the trace of the covariance matrix):
where:
- : -th eigenvalue (variance of -th component)
- : trace of the covariance matrix
- : total number of variables
This identity reflects a fundamental property of the eigendecomposition: the trace of a matrix (the sum of its diagonal elements) equals the sum of its eigenvalues. Since the diagonal elements of the covariance matrix are the variances of individual variables, the total variance is conserved when we rotate to the principal component basis. PCA does not create or destroy variance; it merely redistributes it across orthogonal directions.
The proportion of variance explained by the first components is:
where:
- : cumulative proportion of variance explained
- : number of retained components
- : variance of the -th component
- : total number of variables
This metric guides the choice of how many components to retain. In financial applications, it's common to retain enough components to explain 90-95% of variance, though the appropriate threshold depends on the application. For yield curve modeling, where the first three components typically explain over 99% of variance, the choice is clear. For equity returns, where variance is more dispersed, the decision requires more judgment about the tradeoff between parsimony and fidelity.