Calculating Covariance for Stocks

What Is Covariance?

Covariance is a statistical measure of the directional relationship between two asset returns. Investors can use this measurement to understand the relationship between two stock returns.

Formulas that calculate covariance can predict how two stocks might perform relative to each other in the future. Applied to historical returns, covariance can help determine if stocks' returns tend to move with or against each other.

Using the covariance tool, investors might even be able to select stocks that complement each other in terms of price movement. This can help reduce the overall risk and increase the overall potential return of a portfolio.

Key Takeaways

  • Covariance is a measure of the relationship between two or more variables. It is closely related to correlation.
  • Investors can use covariance to understand the historical, and therefore the likely future, relationship between the returns of two stocks.
  • Covariance formulas can help investors select stocks that respond to the market in complementary ways, which can protect against risk.

Covariance in Portfolio Management

Covariance applied to a portfolio can help determine what assets to include in the portfolio. It measures whether stocks move in the same direction (a positive covariance) or in opposite directions (a negative covariance).

When constructing a portfolio, a portfolio manager will select stocks that work well together. This usually means these stocks' returns would not move in the same direction. As a result, the investor always has some stocks that are performing well.

Calculating Covariance

Calculating a stock's covariance starts with finding a list of previous returns or "historical returns" as they are called on most quote pages. Typically, you use the closing price for each day to find the return. To begin the calculations, find the closing price for both stocks and build a list. For example:

Daily Return for Two Stocks Using the Closing Prices
Day ABC Returns XYZ Returns
1 1.1% 3.0%
2 1.7% 4.2%
3 2.1% 4.9%
4 1.4% 4.1%
5 0.2% 2.5%

Next, calculate the average return for each stock:

  • For ABC, it would be (1.1 + 1.7 + 2.1 + 1.4 + 0.2) / 5 = 1.30.
  • For XYZ, it would be (3 + 4.2 + 4.9 + 4.1 + 2.5) / 5 = 3.74.

Then, take the difference between ABC's return and ABC's average return and multiply it by the difference between XYZ's return and XYZ's average return.

Finally, divide the result by the sample size and subtract one. If it was the entire population, you could divide by the population size. 

This is represented by the following equation:

Covariance = ( R e t u r n A B C     A v e r a g e A B C )     ( R e t u r n X Y Z     A v e r a g e X Y Z ) ( Sample Size )     1 \text{Covariance}=\frac{\sum{\left(Return_{ABC}\text{ }-\text{ }Average_{ABC}\right)\text{ }*\text{ }\left(Return_{XYZ}\text{ }-\text{ }Average_{XYZ}\right)}}{\left(\text{Sample Size}\right)\text{ }-\text{ }1} Covariance=(Sample Size)  1(ReturnABC  AverageABC)  (ReturnXYZ  AverageXYZ)

Using our example of ABC and XYZ above, the covariance is calculated as:

  • = [(1.1 - 1.30) x (3 - 3.74)] + [(1.7 - 1.30) x (4.2 - 3.74)] + [(2.1 - 1.30) x (4.9 - 3.74)] + …
  • = [0.148] + [0.184] + [0.928] + [0.036] + [1.364]
  • = 2.66 / (5 - 1)
  • = 0.665

In this situation, we are using a sample, so we divide by the sample size (five) minus one.

The covariance between the two stock returns is 0.665. Because this number is positive, the stocks move in the same direction. In other words, when ABC had a high return, XYZ also had a high return.

If the result were negative, then the two stocks would tend to have opposite returns: when one had a positive return, the other would have a negative return.

Finding Covariance With Microsoft Excel

In MS Excel, you use one of the following functions to find the covariance:

  • = COVARIANCE.S() for a sample
  • = COVARIANCE.P() for a population

You will need to set up the two lists of returns in vertical columns as in Table 1. Then, when prompted, select each column. In Excel, each list is called an "array," and two arrays should be inside the brackets, separated by a comma.

Uses of Covariance

Covariance can tell how the stocks move together, but to determine the strength of the relationship, look at their correlation. The correlation should, therefore, be used in conjunction with the covariance, and is represented by this equation:

Correlation = ρ = c o v ( X , Y ) σ X σ Y where: c o v ( X , Y ) = Covariance between X and Y σ X = Standard deviation of X σ Y = Standard deviation of Y \begin{aligned} &\text{Correlation}=\rho=\frac{cov\left(X, Y\right)}{\sigma_X\sigma_Y}\\ &\textbf{where:}\\ &cov\left(X, Y\right)=\text{Covariance between X and Y}\\ &\sigma_X=\text{Standard deviation of X}\\ &\sigma_Y=\text{Standard deviation of Y}\\ \end{aligned} Correlation=ρ=σXσYcov(X,Y)where:cov(X,Y)=Covariance between X and YσX=Standard deviation of XσY=Standard deviation of Y

The equation above reveals that the correlation between two variables is the covariance between both variables divided by the product of the standard deviation of the variables. While both measures reveal whether two variables are positively or inversely related, the correlation provides additional information by determining the degree to which both variables move together.

The correlation will always have a measurement value between -1 and 1, and it adds a strength value on how the stocks move together.

If the correlation is 1, they move perfectly together, and if the correlation is -1, the stocks move perfectly in opposite directions. If the correlation is 0, then the two stocks move in random directions from each other. 

In short, covariance tells you whether two variables change the same way while correlation reveals how a change in one variable affects a change in the other. 

You also may use covariance to find the standard deviation of a multi-stock portfolio. The standard deviation is the accepted calculation for risk, which is extremely important when selecting stocks. Most investors would want to select stocks that move in opposite directions because the risk will be lower, though they'll provide the same amount of potential return.

How Does Covariance Differ From Variance?

Variance measures the dispersion of values or returns of an individual variable or data point about the mean. It looks at a single variable. Covariance instead looks at how the dispersion of the values of two variables corresponds with respect to one another.

Where Is Covariance Used in Finance?

If two stocks have share prices with a positive covariance, they are both likely to move in the same direction when responding to market conditions. If they have negative covariance they tend to move in opposite directions. Covariance is used in modern portfolio theory (MPT), when constructing efficient investment portfolios. In order to achieve the optimal risk-return trade-off one should identify assets that have a low or negative correlation.

How Do Covariance and Correlation Differ?

The correlation coefficient of a pair of variables is derived by taking the covariance and dividing it by the product of each variable's standard deviation:

Correlation (ρ) = cov(X,Y)/(σX σY)

​Correlation is therefore a normalized or rangebound interpretation of how two variables move together.

The Bottom Line

Covariance is a common statistical calculation that can show how two stocks tend to move together. Investors can use it to lower their portfolio risk by selecting stocks that move in opposite directions.

However, because covariance is calculated using historical returns, it can never provide complete certainty about the future. It should not be used on its own to construct a portfolio. Instead, it should be used in conjunction with other calculations such as correlation or standard deviation.

Article Sources
Investopedia requires writers to use primary sources to support their work. These include white papers, government data, original reporting, and interviews with industry experts. We also reference original research from other reputable publishers where appropriate. You can learn more about the standards we follow in producing accurate, unbiased content in our editorial policy.
  1. Microsoft. "COVARIANCE.P Function."

  2. Microsoft. "COVARIANCE.S Function."

Open a New Bank Account
×
The offers that appear in this table are from partnerships from which Investopedia receives compensation. This compensation may impact how and where listings appear. Investopedia does not include all offers available in the marketplace.