# We've got you covered

We are here to guide you in making tough decisions with your hard earned money. Drop us your details and we will reach you for a free one on one discussion with our experts.

or

Call us on: +917410000494

- The Orientation Note
- A Brief note on The Risk (Part 01)
- A Brief note on The Risk (Part 02)
- A Brief note on The Risk (Part 03)
- A Brief note on The Risk (Part 04)
- The Equity Curve
- The Expected Returns
- The Portfolio Optimization
- The Portfolio Optimization (Part 02)
- The Value at Risk
- The Position sizing for Active Trader
- The Position sizing for Active Trader (Part 02)
- The Position sizing for Active Trader (Part 03)
- The Kelly’s Criterion
- Understanding Trading Biases
- Understanding Trading Biases (Part 02)

Let's start this chapter by briefly recapping our discussions so far.

This module began with a discussion about the two types of risk that market participants are exposed to when they purchase stocks - the systematic and unsystematic risks. After understanding the fundamental differences between these two types, we moved on to understand **risk from an investment perspective**. We discussed two key concepts in our discussion about portfolio risk, or portfolio variance. **Variance** refers to the difference in a stock's returns from its average returns. **Covariance** is the difference in a stock's returns relative to other stocks. We discussed variance and co variance primarily with regard to a two-stock portfolio. However, we found that an equity portfolio typically contains multiple stocks. **matrix algebra** is required to calculate the variance co variance, and the correlation in a multi-stock portfolio.

That's it.

This chapter will discuss how to calculate the variance co variance of multiple stocks. We will also introduce matrix multiplication and other concepts. The 'variance-covariance' matrix is not enough to provide much information. We need to create the correlation matrix in order to make sense of all this. After this step is completed, the correlation matrix results can be used to calculate the **portfolio variation**. Our ultimate goal is to calculate the portfolio variance. Portfolio variance is the measure of the risk that one is exposed to when there are a certain number of stocks in a portfolio.

This stage should be a wake-up call for you to realize that we are looking at risk from the whole portfolio perspective. We will also be discussing 'asset allocation', and how it affects portfolio returns and risk. We'll also briefly discuss "value at risk". This will be explained in detail shortly. We will soon explain this in greater detail

We will also examine risk from the trader's point of view. How to identify trading risk and how to minimize it.

Before we move on, let me briefly mention the 'Variance Covariance Matrix'. To clarify, is it the 'variance Covariance matrix'? Or is it both a variance matrix AND a covariance matrix? Is it only one matrix, i.e. the 'Variance Covariance Matrix'?

Is it only one matrix, the 'Variance Covariance matrix? If there are five stocks, the matrix should contain information about the variance of each stock. It should also include the covariance between the stock 1 and 4. We will soon use an example to show you more.

It is important to have a basic understanding of matrix operations. Khan Academy has a wonderful video that explains matrix multiplication.

Let's continue from the previous chapter and let us calculate the Variance Covariance matrix, followed by the correlation matrix, for a portfolio that has multiple stocks. A portfolio with high conviction and diversification typically has around 10-15 stocks. To demonstrate the variance covariance matrix calculation, I would have loved to have a larger portfolio. However, excel is cumbersome and a novice could be intimidated by the size of the matrix. I have decided to keep a 5-stock portfolio.

My portfolio is made up of the following five stocks:

- Cipla
- Idea
- Wonderla
- PVR
- Alkem

A portfolio of five stocks will have a variance covariance matrix that is 5x5. If there are more than five stocks in a portfolio, the variance covariance matrix size will be **k x**.

This is the formula for creating a variance covariance matrix.

(Image 1)

Where?

k = Number of stocks in the portfolio

n = Number of observations

X is the excess return matrix n x. This will be explained in detail shortly

X T = Transpose matrix for X

This is a brief explanation of the formula. This will help you to better understand the process of its implementation.

We first calculate the **n x k excess returns matrix**, then multiply this matrix by its transpose matrix. This is called a matrix multiplication, and the result will be a **k x k** matrix. Then we divide each element by n. n is the number of observations. After this division, the resulting matrix is a **k x k variance matrix**.

One step from our final goal, generating the k x K variance covariance matrix, is generating the correlation matrix.

Let's use this formula to generate the variance covariance matrix of the five stocks above. This is done using MS Excel. I have the closing prices of the five stocks each day for the past 6 months.

**Step 1** Calculated daily returns. You should be familiar with this. I won't go into detail about how to calculate daily returns. This is an excel snapshot.

**(image 2**

As you can see, the closing price of the stock has been aligned and I have also calculated the daily returns. The formula for calculating the daily return has been indicated.

**Step 2** Calculate the average daily return for each stock. This can be done using excel's 'average' function.

**(image 3**

**Step 3** Setup the excess return matrix.

The excess return matrix refers to the difference in stock's daily returns over its average return. This was done in the previous chapter, when we discussed covariance between two stock.

The excess return matrix has been set up in the following manner -

**(image 4**

The resulting matrix has **n x**size. **_n** is the number of observations (127) and **_k** the number stock (5). In our example, the matrix size is 127x5. This matrix has been denoted as X.

**Step 4** To create a k-x k matrix, generate the **X T X** operation.

It may sound extravagant, but it's not.

X T is a new matrix that is created by interchanging rows and columns from the original matrix X. A transpose matrix is one that has rows and columns interconnected to create a new matrix. It's denoted as X T. Now, we want to multiply the original matrix by its transpose. This is denoted as TX.

This operation will produce a matrix that is k x K. k denotes how many stocks are in the portfolio. This will be 5x5.

This can be done in Excel in one go. To create the kxk matrix, I'll use the following functions steps.

List the stocks in columns and rows.

**(image 5**

Use the function = 'MMULT - (transpose X), Remember that X is the excess return matrix.

**(image 6).**

You must ensure that the k x K matrix is highlighted when you apply this formula. After you have completed the formula, you will need to highlight it. will be hit by pressing ctrl+shift+enter . You can use ctrl+shift+enter for all array functions in Excel.

Excel will then present you with a gorgeous k x K matrix once you press ctrl+shift+enter. In this example, it looks like this.

**(image 7).**

Step 5 - The last step to create the variance covariance matrix. Now we need to divide each element in the X T X matrix with the total number of observations, i.e. n.

**(image 8**

**We start again by creating the layout of k x K matrix -**

**(image 9**

After the layout has been set, you can select all the cells in X T and then divide it by n, i.e. 127. This is an array function, so you will need to press CTRL+shift+enter instead of just entering.

**(image 10**

**After you press control shift enter, the 'Variance-Covariance' matrix will appear. The matrix's numbers will be very small so don't worry. Here's the variance co variance matrix.**

**(image 11).**

**Let's take some time to get to know the 'Variance - Covariance matrix' better. Let's say I want to find the covariance among two stocks, Wonderla or PVR. To do this, I just need to look for Wonderla on my left and then in the same row look for PVR. This is the covariance of the two stocks. The same has been highlighted in yellow.**

**(image 12** **)**

The matrix indicates that Wonderla and PVR have a covariance of 0.000034. This is the same covariance as Wonderla and PVR.

You will also notice the blue number. This number corresponds to Cipla or Cipla. This value represents Cipla and Cipla. This is the covariance between Cipla & Cipla. And, as you can see, covariance of a stock within itself, is nothing more than variance!

This is precisely why the matrix is called " **Variance-Covariance Matrix**", because it gives us both values.

Here's the hard truth: the variance and covariance matrix is useless on its own. These numbers are very small and difficult to interpret. The 'Correlation Matrix is what we really need.

Let's now discuss how to generate the correlation matrix and work towards estimating portfolio variance. This is our ultimate goal. Before we close this chapter, however, there are a few tasks that you can do.

- Get the latest 1 year data on 5 stocks or more.
- Calculate the Variance-Covariance matrix for the same
- Find the variance value for a stock. Use the = 'Var() function in excel to determine if the returns are identical.

- X is a matrix that provides an excess return.
- The excess return matrix simply refers to the difference in daily return over the average daily return.
- X T is the transpose for X
- Variable is the number of observations within the data set. If you have 6 months of data, n is 128. For one year, n would be 252.
- The excess return matrix is a matrix of the size (n x k), where k is how many stocks
- Divide the matrix product of X TX by N to get the variance covariance matrix
- The variance covariance matrix has the dimensions k x.k
- Stock 1's covariance with stock 1 is its variance
- We will find the correlation matrix using the variance covariance matrix.