Learn / Track I / lesson 4 of 4
Linear algebra for portfolios
Vectors of weights, covariance matrices and eigenvectors — the compact language every portfolio and risk model is written in.
Once you hold more than two assets, writing out every variance and covariance by hand stops working. Linear algebra packs it all into a few symbols.
Weights, returns and the covariance matrix
Stack asset returns into a vector with mean . Portfolio weights are a vector . The covariance matrix has variances on the diagonal and covariances off it:
Then the portfolio’s expected return and variance are
That second formula is the matrix version of the variance rule for sums. Every cross term is in there.
Correlation
Correlation rescales covariance to lie between and :
If is the diagonal matrix of volatilities and the correlation matrix, then . Separating volatility from correlation is useful because they behave differently: volatility is fairly predictable, correlation is noisy and jumps towards 1 in a crisis.
Positive semi-definiteness
A valid covariance matrix must satisfy for every , since variance cannot be negative. When you build from pieces (different data windows, hand-edited correlations), this can break, and an optimiser will happily “find” a portfolio with negative risk. Always check the smallest eigenvalue.
Eigenvectors and principal components
Because is symmetric, it can be decomposed as
where the columns of are orthogonal eigenvectors and is the diagonal matrix of eigenvalues. Each eigenvector is a portfolio; its eigenvalue is that portfolio’s variance; and these portfolios are uncorrelated with one another. This is principal component analysis (PCA).
- In a basket of stocks, the first component is close to equal-weighted — “the market” — and often explains 30–50% of total variance.
- In a yield curve, the first three components are level, slope and curvature, and together explain well over 95% of moves.
- In crypto, the first component is essentially “BTC beta”; most altcoins load heavily on it.
Why this matters for strategies
- Risk decomposition. The contribution of asset to portfolio variance is . These contributions sum to , which is how risk-parity portfolios are built.
- Hidden concentration. Ten strategies that each look different may all load on the same first principal component. PCA tells you how many independent bets you really have.
- Stat-arb. Residuals after removing the top components are often more mean-reverting than raw prices — the basis of PCA-based pairs and basket trading.
Inverting a sample covariance matrix estimated from too little data. With assets you need far more than observations; otherwise the smallest eigenvalues are pure noise, and (used by mean-variance optimisation) amplifies exactly that noise. Use shrinkage (Ledoit–Wolf) or factor models.