**Covariance Formula (Table of Contents)**

## What is Covariance Formula?

Covariance formula is one of the statistical formulae which is used to determine the relationship between two variables or we can say that covariance shows the statistical relationship between two variances between the two variables.

The positive covariance states that two assets are moving together give positive returns while negative covariance means returns move in the opposite direction. Covariance is usually measured by analyzing standard deviations from the expected return or we can obtain by multiplying the correlation between the two variables by the standard deviation of each variable.

**Population Covariance Formula**

**Cov(x,y) = Σ ((x**

_{i }– x) * (y_{i}-) / N**Sample Covariance Formula**

**Cov(x,y) = Σ ((x**

_{i }– x) * (y_{i}– ) / (N – 1)Where

**x**Data variable of x_{i }=**y**= Data variable of y_{i}**x**= Mean of x**y**= Mean of y**N**= Number of data variables.

**How the Correlation Coefficient formula is correlated with Covariance Formula?**

**Correlation = Cov(x,y) / (****σ**_{x * }**σ _{y}**)

Where:

**Cov(x,y):**Covariance of x & y variables.**σ**Standard deviation of the X- variable._{x }=**σ**Standard deviation of the Y- variable._{y }=

However, Cov(x,y) defines the relationship between x and y, while and. Now, we can derive the correlation formula using covariance and standard deviation. The correlation measures the strength of the relationship between the variables. Whereas, it is the scaled measure of covariance which can’t be measured into a certain unit. Hence, it is dimensionless.

If the correlation is 1, they move perfectly together and if the correlation is -1 then stock moves perfectly in opposite directions. Or if there is zero correlation then there is no relations exist between them.

### Examples of Covariance Formula

Let’s take an example to understand the calculation of Covariance in a better manner.

4.9 (3,296 ratings)

View Course

#### Covariance Formula – Example #1

**Daily Closing Prices of Two Stocks arranged as per returns. So calculate Covariance.**

Mean is calculated as:

Covariance is calculated using the formula given below

**Cov(x,y) = Σ ((x _{i }– x) * (y_{i} – y) / (N – 1)**

- Cov(x,y) =(((1.8 – 1.6) * (2.5 – 3.52)) + ((1.5 – 1.6)*(4.3 – 3.52)) + ((2.1 – 1.6) * (4.5 – 3.52)) + (2.4 – 1.6) * (4.1 – 3.52) + ((0.2 – 1.6) * (2.2 – 3.52)))
**/**(5 – 1) - Cov(x,y) = ((0.2 * (-1.02)) +((-0.1) * 0.78)+(0.5 * 0.98) +(0.8 * 0.58)+((-1.4) * (-1.32)) / 4
- Cov(x,y) = (-0.204) + (-0.078) + 0.49 + 0.464 + 1.848 / 4
- Cov(x,y) = 2.52 / 4
- Cov(x,y) =
**0.63**

The covariance of the two stock is 0.63. The outcome is positive which shows that the two stocks will move together in a positive direction or we can say that if ABC stock is booming than XYZ is also has a high return.

#### Covariance Formula – Example #2

**The given table describes the rate of economic growth(x _{i}) and the rate of return(y_{i}) on the S&P 500. With the help of the covariance formula, determine whether economic growth and S&P 500 returns have a positive or inverse relationship. Calculate the mean value of x, and y as well.**

Mean is calculated as:

Covariance is calculated using the formula given below

**Cov(x,y) = Σ ((x _{i }– x) * (y_{i} – y) / N**

- Cov(X,Y) = (((2 – 3) * (8 – 9.75))+((2.8 – 3) * (11 – 9.75))+((4-3) * (12 – 9.75))+((3.2 – 3) * (8 – 9.75))) / 4
- Cov(X,Y) = (((-1)(-1.75))+((-0.2) * 1.25)+(1 * 2.25)+(0.2 * (-1.75))) / 4
- Cov(X,Y) = (1.75 – 0.25 + 2.25 – 0.35) / 4
- Cov(X,Y) = 3.4 / 4
- Cov(X,Y) =
**0.85**

#### Covariance Formula – Example #3

**Consider a datasets X = 65.21, 64.75, 65.56, 66.45, 65.34 and Y = 67.15, 66.29, 66.20, 64.70, 66.54. Calculate the covariance between the two data sets X & Y.**

**Solution:**

Mean is calculated as:

Covariance is calculated using the formula given below

**Cov(x,y) = Σ ((x _{i }– x) * (y_{i} – y) / (N – 1)**

- Cov(X,Y) = (((65.21 – 65.462) * (67.15 – 66.176)) + ((64.75 – 65.462) * (66.29 – 66.176)) + ((65.56 – 65.462) * (66.20 – 66.176)) + ((66.45 – 65.462) * (64.70 – 66.176)) + ((65.34 – 65.462) * (66.54 – 66.176))) / (5 – 1)
- Cov(X,Y) = ((-0.252 * 0.974) + (-0.712 * 0.114) + (0.098 * 0.024) + (0.988 * (-1.476)) + (-0.122 * 0.364)) /4
- Cov(X,Y) = (- 0.2454 – 0.0811 + 0.0023 – 1.4582 – 0.0444) / 4
- Cov(X,Y) = -1.8268 / 4
- Cov(X,Y) =
**-0.45674**

### Explanation

Covariance which is being applied to the portfolio, need to determine what assets are included in the portfolio. The outcome of the covariance decides the direction of movement. If it is positive then stocks move in the same direction or move in opposite directions leads to negative covariance. The portfolio manager who selects the stocks in the portfolio that perform well together, which usually means that these stocks are expected, not to move in the same direction.

While calculating covariance, we need to follow predefined steps as such:

**Step 1**: Initially, we need to find a list of previous prices or historical prices as published on the quote pages. To initialize the calculation, we need the closing price of both the stocks and build the list.

**Step 2: **Next to calculate the average return for both the stocks:

**Step 3**: After calculating the average, we take a difference between both the returns ABC, return and ABC’ average return similarly difference between XYZ and XYZ’s return average return.

**Step 4**: We divide the final outcome with sample size and then subtract one.

### Relevance and Uses of Covariance Formula

Covariance is one of the most important measures which is used in modern portfolio theory (MPT). MPT helps to develop an efficient frontier from a mix of assets that forms the portfolio. The efficient frontier is used to determine the maximum return against the degree of risk involved in the overall combined assets in the portfolio. The overall objective is to select the assets that have a lower standard deviation of the combined portfolio rather than individual assets standard deviation. This minimizes the volatility of the portfolio. The objective of the MPT is to create an optimal mix of a higher-volatility asset with lower volatility assets. By creating a portfolio of diversifying assets, so the investors can minimize the risk and allow for a positive return.

While constructing the overall portfolio, we should incorporate some of the assets having negative covariance which helps to minimize the overall risk of the portfolio. Analyst most occasionally prefers to refer to historical price data to determine the measure of covariance between different stocks. And aspects that the same set of a trend will asset prices will continue into the future, which is not possible all the time. By including assets of negative covariance, helps to minimize the overall risk of the portfolio.

### Covariance Formula in Excel (With Excel Template)

Here we will do another example of the Covariance in Excel. It is very easy and simple.

**An analyst is having five quarterly performance dataset of a company that shows the quarterly gross domestic product(GDP). While growth is in percentage(A) and a company’s new product line growth in percentage (B). Calculate the Covariance.**

Mean is calculated as:

Covariance is calculated using the formula given below

**Cov(x,y) = Σ ((x _{i }– x) * (y_{i} – y) / (N – 1)**

- Cov(X,Y) = (((3 – 3.76) * (12 – 16.2)) + ((3.5 – 3.76) * (16 – 16.2)) + ((4 – 3.76) * (18 – 16.2)) + ((4.2 – 3.76) * (15 – 16.2)) +((4.1 – 3.76) * (20 – 16.2))) / (5 – 1)
- Cov(X,Y) = (((-0.76) *(-4.2)) + ((-0.26) * (-0.2)) + (0.24 *1.8) + (0.44 * (-1.2)) + (0.34 *3.8)) / 4
- Cov(X,Y) = (3.192 + 0.052 +0.432 – 0.528 + 1.292) /4
- Cov(X,Y) = 4.44 / 4
- Cov(X,Y) =
**1.11**

### Recommended Articles

This has been a guide to Covariance Formula. Here we discuss how to calculate Covariance along with practical examples and a downloadable excel template. You may also look at the following articles to learn more –