Evaluating the Relationships of 2 Stocks by Covariance

In this article

What covariance between two stocks tells you

Covariance measures whether two stocks' returns tend to move in the same direction. A positive covariance means that when one stock's return is above its average, the other's usually is too; a negative covariance means they tend to move in opposite directions; a value near zero means little linear relationship. For portfolio building, pairs with low or negative covariance reduce overall portfolio volatility, which is the basis of diversification.

See it in actionMarketXLS video

Try it in your own spreadsheet

Get the free MarketXLS sample workbook (.xlsx).

No account needed. MarketXLS live data requires a paid plan. Preview workbook

Explore more videos
Evaluating the Relationships of 2 Stocks by Covari - stock data and fundamental analysis in Excel with MarketXLS

Covariance is expressed in squared return units, so its size is hard to compare across pairs. Dividing it by the two stocks' standard deviations gives the correlation coefficient, which always falls between -1 and +1 and is easier to read.

How covariance affects portfolio risk

Covariance changes a portfolio's risk, not its expected return. For a two-stock portfolio with weights w₁ and w₂, portfolio variance is:

w₁²σ₁² + w₂²σ₂² + 2·w₁·w₂·cov(1,2)

A high positive covariance adds to portfolio variance, so the two holdings rise and fall together and diversify each other less. A negative covariance subtracts from variance, so losses in one holding tend to be offset by gains in the other. Expected return is still the weighted average of each stock's expected return.

The covariance formula

The covariance between two return series X and Y is the average product of their deviations from their means:

cov(X,Y) = Σ (Xᵢ − X̄)(Yᵢ − Ȳ) / (n − 1)

where X̄ and Ȳ are the mean returns and n is the number of observations (the n − 1 version is the sample covariance).

How to calculate covariance of two stocks in Excel

  1. Pull daily closing prices for both stocks into two columns. With the MarketXLS add-in, =QM_GetHistory("AAPL") returns a price history table you can reference.
  2. Convert prices to daily returns: =(B3-B2)/B2, copied down for each stock.
  3. Calculate sample covariance with Excel's built-in function: =COVARIANCE.S(returns1, returns2).
  4. For an easier-to-read measure, calculate correlation: =CORREL(returns1, returns2).

Use the same date range and frequency for both stocks, and a long enough window (for example one to three years of daily returns) for a stable estimate. Covariance changes over time and tends to rise during market sell-offs.

Summary

Covariance shows how two stocks move together. Positive covariance adds to portfolio risk; low or negative covariance reduces it. In Excel, compute it from daily returns with COVARIANCE.S, and use CORREL for a scaled version. MarketXLS supplies the price history through formulas, so the calculation updates as new prices arrive. This article is educational and not investment advice.

Related reading:

How to Calculate Stock Beta in Excel
Maximize Your Portfolio Performance with Efficient Frontier
Correlation Matrix (Measuring Portfolio Diversification)

About the authors
Anagh

About Anagh

CTO, MarketXLS

Anagh is the CTO of MarketXLS. He works with Ankur and Robin on the MarketXLS blog, creating articles together about market data and spreadsheet workflows.

Written collaboratively by Anagh, Ankur and Robin.

Important Disclaimer

The information provided in this article is for educational and informational purposes only and should not be construed as investment advice, a recommendation, or an offer to buy or sell any securities. MarketXLS is a financial data platform and is not a registered investment advisor, broker-dealer, or financial planner. Always conduct your own research and consult with a qualified financial professional before making any investment decisions. Past performance is not indicative of future results. Trading and investing involve substantial risk of loss.

Explore MarketXLS in Excel
Download a free sample workbook (.xlsx). MarketXLS is a paid subscription.

See MarketXLS in action

Bring this workflow into Excel.

Book a demo with our team to see how MarketXLS supports your market research.

Ankur
AnkurFounder & CEO, MarketXLS
Book a demo