2. The covariance matrix
Level 7: Linear algebra and portfolio optimization
Two assets that on their own are anything but safe can be combined into a portfolio with almost no risk.
To understand why, and to be able to compute it, you need a new object. In the theory course you already met the correlation between two assets: a number between -1 and 1 that summarizes whether they move together, in opposite directions, or with no apparent relationship.
From a single number to a complete table
The covariance matrix is the natural generalization of that idea when you have more than two assets.
Instead of a single number, you need a complete table. That table captures how each asset moves relative to all the others, all at once.
How to read the table from the inside
Imagine a 3-asset portfolio, for which the covariance matrix is a table with 3 rows and 3 columns:
- The cell in row 1, column 1 is the variance of asset 1, that is, its own covariance with itself.
- The one in row 2, column 2 is the variance of asset 2, and so on along the whole diagonal.
- Off the diagonal, the cell in row 1, column 2 is the covariance between asset 1 and asset 2.
That off-diagonal cell is an unnormalized version of the correlation you already know: the covariance divided by the product of the two volatilities is, exactly, the correlation.
And there is a property of this table worth retaining from the start, because it always holds. By construction, this table is symmetric: the covariance between asset 1 and asset 2 is the same as between asset 2 and asset 1.
Why a list of correlations is not enough
Here is why this table, and not a list of pairwise correlations, is the right tool for computing the real risk of a multi-asset portfolio.
The variance of a portfolio is not the weighted average of the individual variances, just as the portfolio return was not the simple average of the returns.
You have to add up the contribution of every possible pair of assets. For each of those pairs, three things come into play:
- How much asset i weighs.
- How much asset j weighs.
- How much i and j move together.
And that has to be done for every possible pair, including each asset with itself.
With 3 assets there are already several different terms to combine. With 500 assets, the number of distinct cross-covariances is 500 times 499 divided by 2, that is, 124,750 pairs.
That is precisely why a computer is indispensable as soon as you go beyond a handful of assets. It is not that the formula is conceptually hard, it is that there are far too many numbers to combine by hand.
Why diversification reduces risk, with numbers
This table also explains, with numbers, something the theory course could only show you intuitively: why diversification reduces risk.
Suppose two assets with the same volatility but a correlation of -1, meaning they move in exactly opposite directions. Then there is a specific combination of weights that cancels the portfolio risk almost entirely, even though neither asset on its own is safe.
That combination is inversely proportional to their volatilities, and it is not necessarily 50/50.
It is an extreme and unrealistic case in real markets, but it makes the mechanics clear. Portfolio risk depends on two things:
- How much each asset moves on its own.
- How much they move together.
That second effect is captured exclusively by the covariance matrix.
With many assets, the off-diagonal rules
When the number of assets grows, something happens that is worth internalizing. The off-diagonal terms, the cross-covariances, start to weigh far more in the final result than the diagonal ones, the individual variances, simply because there are vastly more of them.
With 500 assets there are 500 variances but 124,750 cross-covariances.
That is the mathematical reason, not just the intuitive one, behind a well known fact. In a highly diversified portfolio, what most determines total risk is no longer how volatile each stock is on its own, but the average correlation among all of them.
Think of a market phase where correlations rise and everything falls at once, as in March 2020. The risk of a 500-asset portfolio shoots up even though no individual stock has become more volatile, because what has changed is the whole matrix, not the diagonal.
The matrix is not known: it is estimated
Finally, and before moving on to the examples with figures, one uncomfortable subtlety is worth pointing out. This matrix is not known, it is estimated from historical data.
And the more assets you put into the portfolio, the more cells there are to estimate, with the same limited amount of historical data available. There are 124,750 of them just for the cross-covariances of 500 assets.
That tension is one of the central threads of the rest of this level, and it has two opposing faces:
- More assets, more potential diversification.
- More assets, more parameters estimated with error.
A concrete example with three assets
A concrete example helps fix the idea. Suppose an annualized covariance matrix for three assets, with these values on the diagonal:
- 0.04 for asset A.
- 0.09 for B.
- 0.01 for C.
That corresponds to volatilities of 20%, 30% and 10% respectively, because volatility is the square root of variance.
Off the diagonal are the three cross-covariances:
- Between A and B it is 0.018.
- Between A and C it is -0.002.
- Between B and C it is 0.003.
With these numbers you already have all the information the next step, Markowitz optimization, needs. It is enough to compute the risk of any possible combination of weights across A, B and C, without looking at the raw historical data again.