What Is Covariance? Meaning, Formula, and Use in Finance

By Markets & Investing DeskUpdated Nov 10, 2026

Covariance
Illustration · Fintrev

Definition

Covariance measures how the returns of two assets move together relative to their own averages. A positive value means they tend to rise and fall together, and a negative value means they tend to move in opposite directions.

Key takeaways

  • Covariance shows whether two assets' returns tend to move in the same direction (positive) or in opposite directions (negative).
  • Its size depends on the units and volatility of the inputs, so it cannot be compared across asset pairs the way correlation can.
  • It underpins modern portfolio theory, the portfolio variance formula, the covariance matrix and the beta used in the capital asset pricing model (CAPM).
  • It is computed from historical data and captures only linear relationships.

Covariance is a statistical measure of how two variables move together relative to their own averages. In finance, those variables are usually the returns of two assets. A positive covariance means the two returns tend to be above their averages at the same time and below their averages at the same time. A negative covariance means one tends to be above its average when the other is below. A covariance near zero means there is no consistent linear pattern between the two.

Covariance gives the direction of a relationship, not its strength. Strength is measured by correlation, which is covariance rescaled to a range of -1 to +1.

How covariance works

For each period in a sample, covariance asks two questions: how far was asset X’s return from its average, and how far was asset Y’s return from its average? It multiplies those two deviations together.

  • If both returns were above their averages, both deviations are positive and the product is positive.
  • If both were below their averages, both deviations are negative and the product is again positive.
  • If one was above and the other below, the product is negative.

Adding these products across all periods and dividing by the number of observations (or one fewer, for a sample) gives the covariance. Periods where the assets moved together push the result up. Periods where they diverged pull it down. Large deviations count for more than small ones, because the deviations are multiplied rather than just counted.

The covariance formula

The sample covariance formula, used for a sample of historical returns, is:

Cov(X, Y) = Σ [(Xᵢ − X̄) × (Yᵢ − Ȳ)] ÷ (n − 1)

where:

  • Xᵢ and Yᵢ = the returns of assets X and Y in period i
  • X̄ and Ȳ = the average returns of X and Y over the sample
  • n = the number of periods in the sample
  • Σ = the sum across all periods

The population covariance uses the same numerator but divides by n instead of n − 1. Dividing by n − 1 (known as Bessel’s correction) adjusts for the fact that the sample means are themselves estimated from the same data. In finance, historical returns are almost always treated as a sample of a larger, unobserved set of outcomes, so the n − 1 version is the usual choice. The difference shrinks as the number of observations grows.

Covariance is commonly written as Cov(X, Y) or σ_XY. It is symmetric: Cov(X, Y) equals Cov(Y, X).

Reading the sign and size

The sign is the main piece of information covariance conveys on its own:

  • Positive covariance: the returns tend to be high together and low together. On a scatter chart, the points slope upward from left to right.
  • Negative covariance: an above-average return on one asset tends to pair with a below-average return on the other. The scatter points slope downward.
  • Covariance near zero: there is no clear linear pattern.

The magnitude is harder to read. A covariance of 4 is not necessarily “stronger” than a covariance of 0.5, because the number scales with how volatile each asset is and with the units used. Returns entered as percentages give a covariance 10,000 times larger than the same returns entered as decimals.

How to calculate covariance: a worked example

The following uses hypothetical monthly returns for two stocks, A and B, to show the mechanics.

Month Stock A return Stock B return
1 2% 1%
2 −1% −2%
3 3% 2%
4 0% 1%
5 1% 3%

Step 1: Calculate each average. Stock A: (2 − 1 + 3 + 0 + 1) ÷ 5 = 1%. Stock B: (1 − 2 + 2 + 1 + 3) ÷ 5 = 1%.

Step 2: Find each month’s deviation from the average. Stock A: 1, −2, 2, −1, 0. Stock B: 0, −3, 1, 0, 2.

Step 3: Multiply the paired deviations. Month 1: 1 × 0 = 0 Month 2: −2 × −3 = 6 Month 3: 2 × 1 = 2 Month 4: −1 × 0 = 0 Month 5: 0 × 2 = 0

Step 4: Sum the products. 0 + 6 + 2 + 0 + 0 = 8.

Step 5: Divide by n − 1. 8 ÷ 4 = 2.

The sample covariance is 2, in units of percent squared (%²). Expressed with decimal returns (0.02, −0.01 and so on), the same calculation gives 0.0002. The population covariance, dividing by 5, would be 1.6 %².

The positive result says the two stocks tended to move above and below their averages together over these five months. Notice that most of the result comes from month 2, when both stocks fell well below their averages. A single large joint move can dominate a small sample, which is one reason analysts prefer longer data series.

If you start from prices, convert them to returns first: each period’s return is (ending price − starting price) ÷ starting price, the same simple-return logic used in return on investment. Raw price levels trend over time and can show a large covariance even between unrelated assets.

Calculating covariance in Excel

In Microsoft Excel, place each asset’s returns in its own column, then use:

  • =COVARIANCE.S(array1, array2) for the sample covariance (divides by n − 1)
  • =COVARIANCE.P(array1, array2) for the population covariance (divides by n)

Each array is a range of cells, such as B2:B6 and C2:C6, and the two ranges must contain the same number of observations. The older COVAR function returns the population version.

How covariance is used in finance

Portfolio risk and diversification

Covariance is central to modern portfolio theory (MPT) because portfolio risk depends not only on each holding’s volatility but on how the holdings move relative to each other. For a two-asset portfolio, the portfolio variance formula is:

σ²ₚ = w₁²σ₁² + w₂²σ₂² + 2w₁w₂Cov(1, 2)

where w₁ and w₂ are the portfolio weights, σ₁² and σ₂² are each asset’s variance, and Cov(1, 2) is the covariance between them.

Using the hypothetical stocks above, Stock A has a sample variance of 2.5 %² and Stock B 3.5 %². In a 50/50 portfolio:

σ²ₚ = (0.25 × 2.5) + (0.25 × 3.5) + (2 × 0.5 × 0.5 × 2) = 0.625 + 0.875 + 1.0 = 2.5 %²

That is a portfolio standard deviation of about 1.58% per month, assuming the historical figures hold. Now suppose, hypothetically, the covariance had been −2 instead of +2 with the same individual variances. The last term becomes −1.0, portfolio variance falls to 0.5 %², and the standard deviation drops to about 0.71%. The holdings are identical in volatility; only their co-movement changed.

This is the mathematical basis of diversification. Assets with high positive covariances with each other add little risk reduction, while combining assets with low or negative covariances lowers portfolio variance for a given level of expected return. Repeating this calculation across many combinations of weights produces the efficient frontier, the set of portfolios with the lowest risk for each level of expected return.

The covariance matrix

With more than two assets, the pairwise covariances are arranged in a covariance matrix. Each row and column represents an asset. The diagonal entries are the variances of each asset, the off-diagonal entries are the covariances between pairs, and the matrix is symmetric.

The number of unique covariances grows quickly: a portfolio of n assets has n(n − 1) ÷ 2 distinct pairs. Ten assets require 45 covariances; 100 assets require 4,950. Portfolio variance for any number of holdings is calculated by combining the weight vector with this matrix, which is why the covariance matrix is a core input in portfolio optimization and risk models.

Beta and the CAPM

In the capital asset pricing model, a security’s beta measures its sensitivity to the overall market, or its systematic risk. Beta is defined directly from covariance:

β = Cov(asset return, market return) ÷ Var(market return)

A beta above 1 means the asset has historically moved more than the market; below 1, less. Beta then feeds into the CAPM’s expected return, and the gap between an actual return and that CAPM-implied return is the basis of alpha.

Covariance vs. variance

Both describe how data points are spread around a mean and share the same structure. The difference is the number of variables:

  • Variance measures how widely a single asset’s returns are dispersed around its own average. It is always zero or positive.
  • Covariance measures how the deviations of two assets’ returns line up with each other. It can be positive, negative or zero.

Variance is the special case of covariance in which both variables are the same: Var(X) = Cov(X, X). Its square root is the standard deviation, the most widely used measure of an asset’s volatility and the risk denominator in the Sharpe ratio.

Covariance vs. correlation

Correlation standardizes covariance so it can be compared across any pair of assets:

Correlation (ρ) = Cov(X, Y) ÷ (σ_X × σ_Y)

Dividing by the product of the two standard deviations removes the units and confines the result to the range −1 to +1. In the worked example, the standard deviations are about 1.58% and 1.87%, so correlation is 2 ÷ (1.58 × 1.87) ≈ 0.68.

Covariance Correlation
What it shows Direction of co-movement Direction and strength of linear co-movement
Range Unbounded −1 to +1
Units Product of the two variables’ units None
Comparable across pairs No Yes

The two always share the same sign. A correlation close to +1 or −1 indicates a strong linear relationship; one close to zero, a weak one. Covariance is the raw ingredient in portfolio variance and beta, while correlation is the easier figure for comparing how closely two assets track each other.

Limitations of covariance

  • Scale dependence. A larger covariance does not mean a closer relationship, so comparing covariances across asset pairs is misleading without converting to correlation.
  • Linear relationships only. Two variables can be strongly related in a nonlinear way and still have a covariance of zero. For example, if Y equals X² and X is spread evenly around zero, Y depends entirely on X, yet their covariance is zero. A zero covariance means no linear relationship, not independence.
  • Backward-looking. Relationships between assets can shift as economic conditions change, so a past covariance is an estimate of future co-movement, not a promise of it.
  • Sensitivity to the sample. The result changes with the time window, the return frequency (daily, weekly, monthly) and the presence of outliers.
  • Estimation burden. Large portfolios require thousands of pairwise estimates, and errors in those estimates carry through to optimized portfolio weights.

FAQs

Should daily, weekly or monthly returns be used?

Any frequency works, but both assets must use the same periods aligned on the same dates, and the result applies to that frequency: a covariance from daily returns is not directly comparable with one from monthly returns. Match the frequency to the horizon of the analysis, and use enough observations that a few unusual periods do not dominate the estimate.

The Bottom Line

Covariance matters most to investors building or analyzing portfolios, since it drives portfolio variance, the covariance matrix and CAPM beta. Its sign tells you whether two assets tend to move together, but its size depends on units and volatility, so convert it to correlation before comparing pairs. Because it relies on historical data and captures only linear relationships, treat any covariance as an estimate of future co-movement.

About this page

Written by Markets & Investing Desk

The Markets & Investing Desk covers investing guides, the financial dictionary, companies, people, economics and market data.

Published
Last updated

Spotted an error? Tell the editors. This page is general information, not financial advice.