## Covariance Formula

In statistics, the covariance formula is used to assess the relationship between two variables. It is essentially a measure of the variance between two variables. Covariance is measured in units and is calculated by multiplying the units of the two variables. The variance can be any positive or negative values. Following are the interpreted values:

- When two variables move in the same direction, it results in a positive covariance
- Contrary to the above point is two variables in opposite directions, it results in a negative covariance

**Note:** The covariance formula is similar to the correlation formula and deals with the calculation of data points from the average value in a dataset.

## What Is Covariance Formula?

Covariance is a measure of the relationship between two random variables, in statistics. The covariance indicates the relation between the two variables and helps to know if the two variables vary together. In the covariance formula, the covariance between two random variables X and Y can be denoted as Cov(X, Y).

## Covariance formula

## Relation Between Correlation Coefficient and Covariance Formulas

The correlation coefficient formula can be expressed as

Where,

Cov (x,y) is the covariance between x and y

σ_{x }and σ_{y} are the standard deviations of x and y.

Using the above formula which gives the correlation coefficient formula can be derived using the covariance and even vice versa is possible. Covariance is measured in units which can be computed by multiplying the units of the two given variables. The values of the variance are interpreted as follows:

Positive covariance: The two given variables tend to move in the same direction.

Negative covariance: The two given variables tend to move in inverse directions.

But this not so in the case of correlation.

### Formulas for Covariance (Population and Sample)

Here, Cov (x,y) is the covariance between x and y while σ_{x }and σ_{y} are the standard deviations of x and y. Using the above formula, the correlation coefficient formula can be derived using the covariance and vice versa.

### Example Question Using Covariance Formula

**Question:** The table below describes the rate of economic growth (xi) and the rate of return on the S&P 500 (y_{i}). Using the covariance formula, determine whether economic growth and S&P 500 returns have a positive or inverse relationship. Before you compute the covariance, calculate the mean of x and y.

### Applications of Covariance Formula

The covariance formula has applications in finance, majorly in portfolio theory. Thus, the assets can be chosen that do not exhibit a high positive covariance with each other and partially eliminating the unsystematic risk.

## Examples Using Covariance Formula

**Example 1:** Find covariance for following data set x = {2,5,6,8,9}, y = {4,3,7,5,6}

**Solution:**

Given data sets x = {2,5,6,8,9}, y = {4,3,7,5,6} and N = 5

Mean(x) = (2 + 5 + 6 + 8 + 9) / 5

= 30 / 5

= 6

Mean(y) = (4 + 3 +7 + 5 + 6) / 5

= 25 / 5

= 5

Sample covariance Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N – 1)

= [(2 – 6)(4 – 5) + (5 – 6)(3 – 5) + (6 – 6)(7 – 5) + (8 – 6)(5 – 5) + (9 – 6)(6 – 5)] / 5 – 1

= 4 + 2 + 0 + 0 + 3 / 4

= 9 / 4

= 2.25

Population covariance Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N)

= [(2 – 6)(4 – 5) + (5 – 6)(3 – 5) + (6 – 6)(7 – 5) + (8 – 6)(5 – 5) + (9 – 6)(6 – 5)] / 5

= 4 + 2 + 0 + 0 + 3 /

= 9 / 5

= 1.8

**Answer: **The sample covariance is 2.25 and the population covariance is 1.8.

**Example 2:** Using the covariance formula, find covariance for following data set x = {5,6,8,11,4,6}, y = {1,4,3,7,9,12}.

Given data sets x = {5,6,8,11,4,6}, y = {1,4,3,7,9,12} and N = 6

Mean(x) = (5 + 6 + 8 + 11 + 4 + 6) / 6

= 40 / 6

= 6.67

Mean(y) = (1 + 4 + 3 + 7 + 9 + 12) / 6

= 36 / 6

= 6

Using sample covariance formula Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N – 1)

= – 0.4

Population covariance Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N)

= – 0.33

**Answer: **The sample covariance is -0.4 and the population covariance is -0.33.

**Example 3:** Find covariance for following data set x = {13,15,17,18,19}, y = {10,11, 12,14,16} using the covariance formula.

**Solution:**

Given data sets x = {13,15,17,18,19}, y = {10,11,12,14,16} and N = 5

Mean(x) = (13 + 15 + 17 + 18 + 19) / 5

= 82 / 5

= 16.4

Mean(y) = (10 + 11 +12 + 14 + 16) / 5

= 63 / 5

= 12.6

Sample covariance Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N – 1)

= [(16.4 – 13)(12.6 – 10) + (16.4 – 15)(12.6 – 11) + (16.4 – 17)(12.6 – 12) + (16.4 – 18)(12.6 – 14) + (16.4 – 19)(12.6 – 16)] / 5 – 1

= (8.84 + 2.24 – 0.36 + 2.24 + 8.84) / 4

= 21.8 / 4

= 5.45

Population covariance Cov(x,y) = ∑(x_{i} – x ) × (y_{i} – y)/ (N)

= [(16.4 – 13)(12.6 – 10) + (16.4 – 15)(12.6 – 11) + (16.4 – 17)(12.6 – 12) + (16.4 – 18)(12.6 – 14) + (16.4 – 19)(12.6 – 16)] / 5

= (8.84 + 2.24 – 0.36 + 2.24 + 8.84) / 5

= 21.8 / 5

= 4.36

**Answer: **The sample covariance is 5.45 and the population covariance is 4.36.

## FAQs on Covariance Formula

### What Is Covariance Formula in Statistics?

In statistics, the covariance formula helps to assess the relationship between two variables. It is essentially a measure of the variance between two variables. The covariance formula is expressed as,

### How To Use Covariance Formula?

For the given data sets

### What Are the Components of the Covariance Formula?

The Covariance formula for population is

### What Is the Relation Between the Covariance and Correlation Coefficient Formulas?

The correlation coefficient represented as r equals the covariance between the variables divided by the product of the standard deviations of each variable.

### Example of Covariance

John is an investor. His portfolio primarily tracks the performance of the S&P 500 and John wants to add the stock of ABC Corp. Before adding the stock to his portfolio, he wants to assess the directional relationship between the stock and the S&P 500.

John does not want to increase the unsystematic risk of his portfolio. Thus, he is not interested in owning securities in the portfolio that tend to move in the same direction.

John can calculate the covariance between the stock of ABC Corp. and S&P 500 by following the steps below:

**1. Obtain the data.**

First, John obtains the figures for both ABC Corp. stock and the S&P 500. The prices obtained are summarized in the table below:

**2. Calculate the mean (average) prices for each asset.**

**3. For each security, find the difference between each value and mean price.**

**4. Multiply the results obtained in the previous step.**

**5. Using the number calculated in step 4, find the covariance.**

In such a case, the positive covariance indicates that the price of the stock and the S&P 500 tend to move in the same direction.

## Types of Covariance

The covariance equation is used to determine the direction of the relationship between two variables–in other words, whether they tend to move in the same or opposite directions. This relationship is determined by the sign (positive or negative) of the covariance value.

### Positive Covariance

A positive covariance between two variables indicates that these variables tend to be higher or lower at the same time. In other words, a positive covariance between variables* x *and *y *indicates that *x* is higher than average at the same times that *y* is higher than average, and vice versa. When charted on a two-dimensional graph, the data points will tend to slope upwards.

### Negative Covariance

When the calculated covariance is less than zero, this indicates that the two variables have an inverse relationship. In other words, an *x *value that is lower than average tends to be paired with a *y *that is greater than average, and vice versa.

## Covariance vs. Variance

Covariance is related to variance, a statistical measure for the spread of points in a data set. Both variance and covariance measure how data points are distributed around a calculated mean. However, variance measures the spread of data along a single axis, while covariance examines the directional relationship between two variables.

In a financial context, covariance is used to examine how different investments perform in relation to one another. A positive covariance indicates that two assets tend to perform well at the same time, while a negative covariance indicates that they tend to move in opposite directions. Most investors seek assets with a negative covariance in order to diversify their holdings.

## Covariance vs. Correlation

Covariance is also distinct from correlation, another statistical metric often used to measure the relationship between two variables. While covariance measures the direction of a relationship between two variables, correlation measures the strength of that relationship. This is usually expressed through a correlation coefficient, which can range from -1 to +1.

While the covariance does measure the directional relationship between two assets, it does not show the strength of the relationship between the two assets; the coefficient of correlation is a more appropriate indicator of this strength.

A correlation is considered to be strong if the correlation coefficient has a value that is close to +1 (positive correlation) or -1 (negative correlation). A coefficient that is close to zero indicates that there is only a weak relationship between the two variables.

## Example of Covariance Calculation

Assume an analyst in a company has a five-quarter data set that shows quarterly gross domestic product (GDP) growth in percentages (x) and a company’s new product line growth in percentages (y). The data set may look like:

- Q1: x = 2, y = 10
- Q2: x = 3, y = 14
- Q3: x = 2.7, y = 12
- Q4: x = 3.2, y = 15
- Q5: x = 4.1, y = 20

The average x value equals 3, and the average y value equals 14.2. To calculate the covariance, the sum of the products of the x_{i} values minus the average x value, multiplied by the y_{i} values minus the average y values would be divided by (n-1), as follows:

Cov(x,y) = ((2 – 3) x (10 – 14.2) + (3 – 3) x (14 – 14.2) + … (4.1 – 3) x (20 – 14.2)) / 4 = (4.2 + 0 + 0.66 + 0.16 + 6.38) / 4 = 2.85

Having calculated a positive covariance here, the analyst can say that the growth of the company’s new product line has a positive relationship with quarterly GDP growth.

## The Bottom Line

Covariance is an important statistical metric for comparing the relationships between multiple variables. In investing, covariance is used to identify assets that can help diversify a portfolio.

## What Is Covariance vs. Variance?

Covariance and variance are both used to measure the distribution of points in a data set. However, variance is typically used in data sets with only one variable, and indicates how closely those data points are clustered around the average. Covariance measures the direction of the relationship between two variables. A positive covariance means that both variables tend to be high or low at the same time. A negative covariance means that when one variable is high, the other tends to be low.

## What Is the Difference Between Covariance and Correlation?

Covariance measures the direction of a relationship between two variables, while correlation measures the strength of that relationship. Both correlation and covariance are positive when the variables move in the same direction, and negative when they move in opposite directions. However, a correlation coefficient must always be between -1 and +1, with the extreme values indicating a strong relationship.

## What Does a Covariance of 0 Mean?

A covariance of zero indicates that there is no clear directional relationship between the variables being measured. In other words, a high *x *value is equally likely to be paired with a high or low value for *y*.

#### Covariance Formula – Example #1

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

Mean is calculated as:

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

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

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

- 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**

✅ Math Formulas ⭐️⭐️⭐️⭐️⭐

## Để lại một phản hồi