

#Covariance matrix series
Once we have the de-meaned price series, we establish the covariance of different stocks by multiplying the transpose of the de-meaned price series with itself and divide it by 'm' (number of data points), this gives us the covariance matrix: This is will give us the matrix with de-meaned scores, or a measure of how far a data point is from its mean. Step 3 - Demeaning the Pricesįirst, we subtract the mean stock price from the close prices of the corresponding stock.
#Covariance matrix how to
Let us understand how to create a de-meaned series.

This will create a new de-meaned stock price which will help in comparing how one stock's movement from its mean is dependent on another’s movement from it’s mean. So to make the comparison of stocks movements even, we subtract the mean of the stock price from the stock price. To compare two stocks with two completely different price ranges, we need to first establish a common base. Our ultimate aim is to understand how one stock’s behaviour is related to that of another’s. Next, we save all the means of 'n' stocks in a matrix called 'M' as follows: Using this data, we will first compute the average price for each stock.įor example, the mean price for stock 'S 1' is given as follows: We will combine this stock data in a single matrix and name it as 'S': Step 2 - Calculating the Average Price of StockĪs you can see each stock consists of the past ‘m’ days close prices. Let us say that the ‘n’ stocks in our portfolio (S 1,S 2,…S n) have closed price as given below. Let us understand in a stepwise manner how to calculate the covariance for 'n' different stocks in the portfolio. Conversely if one increases while the other decreases then the covariance will be negative.If the two variables increase and decrease simultaneously then the covariance value will be positive.Let us understand what Covariance is and how to calculate it for multiple stocks.Ĭovariance is a measure of the joint variability of two random variables.


Let us understand how portfolio analysis works.
