Portfolio Variance and Covariance Matrix

We level up from single-stock picking to full portfolio selection — figuring out how to compute a portfolio's μ and σ using the covariance matrix.

In the previous chapter we learned that when an asset comes with a given $\mu$ and $\sigma$, people pick the asset that maximizes their utility, each according to their own utility function.

So this time, following up on the previous chapter (the one about ‘asset selection’), let’s bump it up one dimension to “portfolio selection”.

Let me briefly touch on what a ‘portfolio’ is before we go on. The dictionary meaning of portfolio is “a collection of financial assets, such as securities, owned by an investment institution (or an investor)"~

Out in our world, all kinds of assets get used as investment targets: land, buildings, real estate, stocks, bonds, gold, paintings, etc. etc. Anything can be an investment target. So a portfolio is the group of assets that bundles all of these together.

But then, why do hoomans invest in such a wide variety of assets???

You know the saying: “Don’t put all your eggs in one basket.” In other words, the fundamental reason for investing in such a variety of assets is to reduce risk through ‘diversified investing’.

But here, let’s set aside the broad-sense portfolio for a moment and think about a (narrow-sense) portfolio that contains ‘various stocks’. That’s what we need in order to talk about portfolio theory in finance.

Then, suppose we have two portfolios like these:

The first portfolio: stock 1, stock 3, stock 5, and so on

The second portfolio: stock 2, stock 4, stock 6, and so on

With two kinds of portfolios like these in front of us, which portfolio should we choose~~~~?

That’s what we’re about to discuss.

Ack!!! But surprisingly, the answer comes out really clean. For each portfolio, compute $\mu$ and $\sigma$, then choose the portfolio whose $\mu$ and $\sigma$ maximize your own utility…. that’s all there is to it.

Ah, so! We have to know the $\mu$ and $\sigma$ of the portfolio first, before we can even figure out which one maximizes our utility. This is how portfolio theory begins.

So first, very simply: let’s assume a simple portfolio like stock 1, stock 2 as a list and then gradually raise the dimension from there.

Argh! Earlier, for an individual stock stock i, we learned how to set up a probability distribution through scenario analysis and, based on that, compute the $\mu$ and $\sigma$ of the individual stock. But what about something bundled together like a portfolio: stock 1, stock 2 (a portfolio)?

How do we measure the expected return of the portfolio, and the risk of the portfolio?

For an individual stock stock i, we already covered how to derive μ_i and σ_i, so let’s say μ_1, μ_2, σ_1 and σ_2 are all~~~~ already computed.

The expected return of a portfolio

First, the expected return of the portfolio is

The expected return of the two-stock portfolio: μ_p = w_1 μ_1 + w_2 μ_2

computed like this.

Here $w_i$ is the investment weight: the share of all the invested assets making up the portfolio that went into $\text{stock}_i$. For example, say you spread 10 million won across $\text{stock}_1$ and $\text{stock}_2$, with 4 million going into $\text{stock}_1$ and the remaining 6 million into $\text{stock}_2$. Then $w_1 = 0.4$ (40%) and $w_2 = 0.6$ (60%). (So of course $w_1 + w_2 = 1$ holds.)

That formula for the expected return of such a portfolio seems to make sense somehow: each expected return just gets weighted by its investment ratio, and then everything is added up.

So generalizing looks easy, too. If the portfolio holds $n$ stocks instead of 2, it just becomes the sum over i of w_i μ_i … easy~

The variance of a portfolio

But the standard deviation of a portfolio gives us something to chew on. Let me just throw the formula at you first. For a portfolio of 2 stocks, the variance of the portfolio is

The variance of a two-stock portfolio: σ_p² = w_1² σ_1² + w_2² σ_2² + 2 w_1 w_2 Cov(return_1, return_2)

they say it’s calculated like this. (Those pieces are, respectively, the return standard deviation of $\text{stock}_1$, the return standard deviation of $\text{stock}_2$, and the covariance.)

Ah… actually, the formula that expresses the more fundamental definition is

The more fundamental definition: σ_p² = sum over i,j of w_i w_j Cov(return_i, return_j), where Cov(X, Y) = sum of p_i (X_i − mean of X)(Y_i − mean of Y) = ρ_XY σ_X σ_Y, with Cov(X, Y) the covariance and ρ_XY the correlation coefficient

Pretty overwhelming, right…… yeah…. same for me…. I’ll explain every single piece~

Why!!!! does the variance of a portfolio have to look so insanely messy….?

It’s simple. If you know the calculation rules for variance, it’s easy to understand. Say we know $\mathrm{Var}(X)$ and $\mathrm{Var}(Y)$. Let’s work out $\mathrm{Var}(X+Y)$. Since variance means the average of the squared deviations,

Var(X) is the average of (X_i − mean of X) squared, and Var(Y) is the average of (Y_i − mean of Y) squared

it would be like this, right????

Then, thinking along the same lines for $\mathrm{Var}(X+Y)$,

Var(X+Y) is the average of ((X+Y)_i − mean of X+Y) squared

it would be like this, right??

But let’s go more general: say the coefficients of $X$ and $Y$ aren’t 1 but each has its own coefficient, $a$ and $b$.

Var(aX+bY) is the average of ((aX+bY)_i − mean of aX+bY) squared

Notation, for example: $E(X)$ is the mean of $X$, and $E(X+Y)$ is the mean of $X+Y$. We used this notation back in high school, you remember, right? I’ll go with this notation.

Var(aX+bY) expanded step by step with the E notation, ending with a² E((X_i − mean of X)²) + b² E((Y_i − mean of Y)²) + 2ab E((X_i − mean of X)(Y_i − mean of Y)); the two variance terms are red and the covariance term is blue

The red part is the average of squared deviations, so you can see each one is the variance of $X$ and the variance of $Y$ (times $a^2$ and $b^2$). And the blue part is what we called “the definition of covariance” earlier. So the equation above comes out like this:

The result: Var(aX+bY) = a² σ_X² + b² σ_Y² + 2ab Cov(X, Y)

Okay okay okay, so now we can confidently say this~

Var(X+Y) = σ_X² + σ_Y² + 2 Cov(X, Y) and Var(aX+bY) = a² σ_X² + b² σ_Y² + 2ab Cov(X, Y)

That is, the ‘variance of a portfolio’ is the variance of the portfolio’s return, so

The portfolio variance as the variance of the weighted stock returns, expanded to w_1² σ_1² + w_2² σ_2² + 2 w_1 w_2 Cov(return_1, return_2)

And that’s why it was defined this way!!!!

It feels a bit weird that I keep writing out ‘return’ ‘return’ like this. I was worried about confusing it with $\mu$ (the mean of returns, a.k.a. the expected return), so I just spelled out ‘return’ — but from now on I’ll write $R$ in place of ‘return’.

$\mu$ is clearly different from $R$ — it’s the ‘mean of returns (expected return)’ — so you mustn’t mix them up~ $R$ is the return in each scenario, and when I write $R_1$, it means the return from $\text{stock}_1$ in each scenario!!

Okay, so let’s say the portfolio has 3 stocks: $\text{stock}_1$, $\text{stock}_2$, $\text{stock}_3$.

The three-stock portfolio variance expanded step by step, ending with w_1² σ_1² + w_2² σ_2² + w_3² σ_3² + 2 w_1 w_2 Cov(R_1, R_2) + 2 w_1 w_3 Cov(R_1, R_3) + 2 w_2 w_3 Cov(R_2, R_3), with a note that the squaring step is skipped

Whoa, messy~ But now we kind of get a feel for what the form looks like for $n$ stocks, too.

The same derivation started for n stocks: σ_p² = Var(w_1 R_1 + … + w_n R_n)

Aaaah~ So this is why the variance of a portfolio

(aA + bB + … + nN) squared

was related to a form like this~

So now,

The portfolio variance as a double sum: σ_p² = sum over i,j of w_i w_j Cov(R_i, R_j)

I think you can see why this definition was thrown at us, right? hehehe

Maybe not yet. I did skip over a few things… I’ll fill in all those gaps and wrap up.

This notation The double-index sum symbol, i,j bugs me a little. It’s easy, though: it’s really the same thing as The sum over i,j is the same as the sum over i of the sum over j. Let’s take $n = 4$ or so and expand The sum over i,j of a_i b_j carefully once, so you can get the feel.

The double sum for n = 4 written out: all sixteen terms a_i b_j

Once you see the pattern, whenever an expression like The sum over i,j up to n shows up, I just think of it as “don’t worry about duplicates, just plug in everything.”

(Actually, you can sum this idea up in one word, ‘array’ — and a 2-dimensional array is a matrix, which we can do operations on.)

Covariance and the correlation coefficient

And just in case, let me briefly mention covariance before moving on. The covariance here is an index that tells you what kind of relationship the returns of two stocks have, under what kind of relationship they move~ I’ll copy and paste this part.

— copy-paste warning —

Covariance of a stock and a bond: Cov(r_s, r_B) = sum of p_i (r_s(i) − mean of r_s)(r_B(i) − mean of r_B)

That’s the formula, and if I pick it apart a little to explain it,

The covariance formula picked apart: it is a weighted sum of the products of the two deviations from the mean, where the red factor is the stock’s deviation and the blue factor is the bond’s

The covariance formula again: Cov(r_s, r_B) = sum of p_i (r_s(i) − mean of r_s)(r_B(i) − mean of r_B)

Ah, so now the meaning of this formula should feel a little more real. It’s a weighted sum, yes, a weighted sum — but one where each term is multiplied by the tendency of how far the values sit from their means. So knowing the Cov value, we can read it like this:

“Oh, the Cov value is (+) positive?! Then the returns of the stock and the bond generally move in the same direction.”

“Oh, the Cov value is (−) negative??!! Then the returns of the stock and the bond generally flow in opposite directions!!”

And the key point: interpreting the size of the Cov value is…. a bit ambiguous. What’s ambiguous? A (−) Cov value, however big, doesn’t tell you how strong the opposing movement of the two returns actually is. There needs to be a standard for whether a Cov value is big or small, right?

So we normalize it. We normalize it by their standard deviations, and that number is called the correlation coefficient. You write it like this:

The correlation coefficient: ρ_sB = Cov(r_s, r_B) / (σ_s σ_B)

Calculated this way, the maximum size of that value is 1, so it falls into this inequality: −1 ≤ ρ_sB ≤ 1, you see. Only when it’s written this way can we read it like: “Oho, so it’s a negative relationship~ (or a positive one), a big~ (or a small~) one!”

— end of copy-paste —

And one more thing!

The portfolio variance as a double sum: σ_p² = sum over i,j of w_i w_j Cov(R_i, R_j)

When this formula was for $n = 2$, we said it becomes this….

For n = 2: σ_p² = w_1² σ_1² + w_2² σ_2² + 2 w_1 w_2 Cov(return_1, return_2)

So then, I think it’d be better to show a form like Cov(R_i, R_i) once. Let’s compute it exactly as the definition says~

Cov(R_i, R_i) from the definition: the sum of p_k (R_i,k − mean of R_i) squared, which is σ_i²

So

The portfolio variance as a double sum, again: σ_p² = sum over i,j of w_i w_j Cov(R_i, R_j)

this formula is also written, organized, like this~

The double sum split into the terms with i = j and the terms with i ≠ j: σ_p² = sum of w_i² σ_i² + sum of w_i w_j Cov(R_i, R_j)

The covariance matrix

Finally, let me mention the ‘covariance matrix’, which I haven’t touched on above, and wrap up. Take the formula right above…. the one from before we organized it,

The portfolio variance as a double sum, before it is split: σ_p² = sum over i,j of w_i w_j Cov(R_i, R_j)

and let me expand it out like a dummy, brute-force style.

The double sum written out term by term, for every pair of i and j

That’s how it expands. Now I take this brute-force expanded formula and — Equal~ — drop an (=) right there, and write it in matrix form:

The same sum as a matrix product: the row of weights, the matrix of covariances, the column of weights

and say it equals that massive pile of terms above….. Isn’t that 100% legit, no-cap, can’t-deny??? If you expand the matrix out, you get the sum form of that massive list of terms up there… uuuuugh

We call this

The covariance matrix: Cov(R_i, R_j) in row i and column j

matrix the covariance matrix~

And of course, using the forms of the covariance and correlation coefficient definitions, we can also express that covariance matrix in terms of ‘variances and correlation coefficients’!!! Since the relationship between covariance and the correlation coefficient is a normalization relationship,

Cov(R_i, R_j) = ρ_ij σ_i σ_j

we said they’re related like this, right? So that covariance matrix can equivalently be

The covariance matrix with variances on the diagonal (σ_i²) and ρ_ij σ_i σ_j everywhere else

written like this.

Ah, but honestly,

The two orders give the same product: ρ_1,2 σ_1 σ_2 = ρ_2,1 σ_2 σ_1

aren’t these obviously the same value?!? Measuring the correlation between 1 and 2 and measuring the correlation between 2 and 1 — of course they’d come out the same, lol. That is, since ρ_i,j σ_i σ_j = ρ_j,i σ_j σ_i holds, the covariance matrix above has no choice but to be a symmetric matrix.

(Also, since the variance of any portfolio can’t be negative, the covariance matrix has to be positive semi-definite.)

But those $\sigma_1$ through $\sigma_n$ up there could all~ be 1.

When could that be, you ask?

If we assume returns follow the standard normal distribution, then all~ those $\sigma_1$ through $\sigma_n$ can be 1. This shows up in Financial Engineering Programming #22 (Cholesky Decomposition), where the covariance matrix

The correlation matrix: ones on the diagonal and ρ_ij elsewhere, the same as its mirror image

was written like this, and that’s how it became a “Correlation Matrix”~

There’s so much more to talk about, but I’ll cut it here. I’ll continue right~ into the next post.


Heads-up. The figures here are the original notes, slips and all. A few things to watch for:

  • In the small summary of $Var(aX+bY)$, the first term should be $a^2E\left((X_i-\bar X)^2\right)$; the $a^2$ is missing there, while the next line, $a^2\sigma_X^2 + b^2\sigma_Y^2 + 2ab\,Cov(X,Y)$, has it.
  • In the expanded double sum, the second row should read $w_2w_1Cov(R_2,R_1) + w_2w_2Cov(R_2,R_2) + \cdots$ and the last row $w_nw_1Cov(R_n,R_1) + \cdots + w_nw_nCov(R_n,R_n)$; the picture keeps $R_1$ as the first argument in every row.

Comments

Discussion happens via GitHub Discussions. You'll need a GitHub account to comment.