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:
![]()
![]()
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
and then gradually raise the dimension from there.
Argh! Earlier, for an individual stock
, 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)?
How do we measure the expected return of the portfolio, and the risk of the portfolio?
For an individual stock
, we already covered how to derive
and
, so let’s say
,
,
and
are all~~~~ already computed.
The expected return of a portfolio
First, the expected return of the portfolio is
![]()
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
… 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
![]()
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

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,

it would be like this, right????
Then, thinking along the same lines for $\mathrm{Var}(X+Y)$,
![]()
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$.

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.

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:

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

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

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$.

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

Aaaah~ So this is why the variance of a portfolio
![]()
was related to a form like this~
So now,

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
bugs me a little. It’s easy, though: it’s really the same thing as
. Let’s take $n = 4$ or so and expand
carefully once, so you can get the feel.

Once you see the pattern, whenever an expression like
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 —

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


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:

Calculated this way, the maximum size of that value is 1, so it falls into this inequality:
, 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!

When this formula was for $n = 2$, we said it becomes this….
![]()
So then, I think it’d be better to show a form like
once. Let’s compute it exactly as the definition says~

So

this formula is also written, organized, like this~

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,

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

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:

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

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,
![]()
we said they’re related like this, right? So that covariance matrix can equivalently be

written like this.
Ah, but honestly,
![]()
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
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

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.