  # Portfolio Risk : Variance-Covariance Matrix and Correlation Analysis

Risk (Part 3) – Variance & Covariance Matrix

In this chapter, we will extend the discussion in order to calculate the ‘variance covariance’ of multiple stocks. This will acquaint us with matrix multiplication and other related topics. Nonetheless, the ‘variance covariance’ matrix does not give us much insight. We thus have to establish the correlation matrix to interpret it better. After that, with the help of results from the correlation matrix we can compute portfolio variance. To sum up, our ultimate objective is to determine portfolio variance; it informs us how much risk a person assumes when they hold a certain selection of stocks in their portfolio.

At this point, it is important to recognize our focus on portfolio risk. We will also go over ‘asset allocation’ and how it can affect portfolio returns and risk, as well as providing a brief overview of ‘value at risk’.

We will also delve into the idea of risk from a trader’s point of view. We’ll explore how to detect it and methods to reduce its effects:

– Variance Covariance matrix

Before moving on, I’ve spoken about the ‘Variance Covariance matrix’. In order to avoid any doubt – is it a combination of variance and covariance matrices? Or is it just one matrix, namely the ‘Variance Covariance matrix’?

It certainly can’t be just one matrix. If we look at the case of five stocks, then this matrix will provide information about the variance for each stock, as well as the covariance between stock one and the other four stocks. We’ll explore an example soon and you should find that it clarifies things a great deal.

Continuing from the previous chapter, let us calculate the Variance Covariance matrix and then its correlation matrix for a portfolio with multiple stocks. As this could quickly become a cumbersome affair, I opted to construct a 5 stock portfolio instead of one of the usual 10-15. This would help avoid possible intimidation that may arise from the sheer size of the matrix.

My portfolio consists of the following five stocks –

Cipla

Idea

Wonderla

PVR

Alkem

The size of the variance covariance matrix for a portfolio with ‘k’ stocks is k x k. For example, for a 5 stock portfolio, the matrix will be 5 x 5.

Here’s the formula to create a variance covariance matrix-

Where,

k = number of stocks in the portfolio

n = number of observations

X = this is the n x k excess return matrix. We will understand this better shortly

XT  = transpose matrix of X

This formula can be understood more easily when looking at its application. Here is a brief explanation of what it entails.

We first calculate the n x k excess return matrix, multiply it by its own transpose to get a k x k result. Subsequent division of every element in this matrix by n yields the final variance covariance matrix.

To complete the task, we simply need to generate the k x k variance covariance matrix to obtain our desired correlation matrix.

Let us use this formula to generate the variance covariance matrix for the five stocks mentioned earlier. MS Excel will be utilised for this purpose; the daily closing prices of the five stocks over the past six months have been obtained.

Step 1- Calculating the daily returns should be second nature by now. I’m sure you don’t need me to explain the process – here’s the excel snapshot for your reference.

By examining the closing price, I was able to calculate the daily returns. I utilized a specific formula for this purpose.

Step 2- Using the ‘average’ function in Excel, determine the daily returns of each stock.

Step 3- Set up the excess return matrix

The difference between a stock’s daily return and its average return is known as the excess return matrix. In the preceding chapter, we saw this in action when we examined the covariance between two stocks.

I have organised the extra return matrix like this –

The resulting matrix X is of size n x k, with n being the number of observations (in this case 127) and k being the number of stocks (5).

Step 4- Generate XT X matrix operation should be employed to generate a kxk matrix.

It might sound fancy, but that is not the case.

We now have a new matrix, XT, formed by swapping the rows and columns of the original matrix X. This is referred to as a transpose matrix and denoted as XT. Our goal is to compute the product between X and its transpose, denoted as XT X.

The output of this operation is a k x k matrix, with k being the number of stocks in the portfolio; as there are 5 stocks, this matrix will be 5 x 5.

This can be achieved in one move with Excel, using the following function components to generate a k x k matrix –

Take note that when you use this formula, you have to include the k x k matrix explicitly. Do not attempt to hit ‘enter’ right away. For every array function in Excel, it is important to press ctrl+shift+enter.

When you press ctrl+shift+enter, Excel will produce a splendid k x k matrix – here’s what one looks like.

Step 5 – To complete the variance covariance matrix, each element of the XT X matrix must be divided by the number of observations, n. As a reminder, the formula for the variance covariance matrix is as follows:

To begin, we construct a k x k arrangement.

Once the layout is set, select all of the XT X cells with no deselection and divide them by 127. Keep in mind that as this is still an array function, you must press ctrl+shift+enter instead of just enter.

Hit control shift enter to get the ‘Variance – Covariance’ matrix. The numbers indicated in it will be quite minimal, however there is no need to worry about this. Here’s the matrix –

Take a moment to understand of the ‘Variance-Covariance’ matrix. If we desire to determine the covariance between two stocks, like Wonderla and PVR, we can easily locate Wonderla on the left side and identify the corresponding value in the same row that corresponds to PVR. This particular value represents the covariance between the two stocks. I have highlighted this value in yellow for clarity.

The matrix illustrates that the correlation between Wonderla and PVR is 0.000034, which is the same as the relationship between PVR and Wonderla.

Notice the blue-highlighted number; it is the covariance between Cipla and itself. If you know about statistics, then you understand that this figure merely stands for variance!

It is clear why this matrix is known as the Variance-Covariance Matrix; it provides us with both metrics.

The variance and covariance metrics give us tiny numbers that are not particularly helpful. If we want to get actual value from the data, then we need the ‘Correlation Matrix’.

Let’s look at producing a correlation matrix, and striving to calculate portfolio variance as our ultimate goal.