Covariance

Lesson 9 of 20, about 17 minutes

What you will learn

  • Explain what covariance measures about two variables
  • Understand why the covariance is positive when variables move together and negative when they move oppositely
  • Calculate a covariance from paired data
  • See why covariance's size is hard to interpret, which sets up correlation

Everything so far described one variable at a time: its center and its spread. But one of the key ideas in portfolio investing is about two variables at once, namely how two assets move together. If two stocks tend to rise and fall at the same time, holding both does little to reduce risk. If one tends to rise when the other falls, they offset each other. Covariance is the first measure of this joint movement, and understanding why its sign works is the whole point of this lesson.

Covariance, clearly explained (StatQuest)

The go-to intuition video for why covariance is positive versus negative. It is a bit long, so focus on how the product of deviations creates the sign.

The idea: do they move together?

Covariance measures the direction in which two variables move relative to each other. A positive covariance means that when one variable is above its mean, the other tends to be above its mean too, so they move in the same direction. A negative covariance means they tend to move in opposite directions, one above its mean while the other is below. A covariance near zero means there is no consistent tendency either way. The key question covariance answers is simple: when one goes up, does the other tend to go up, down, or neither?

Why the sign works: the product of deviations

Here is the mechanism, and it is worth slowing down for. For each pair of observations, you take the deviation of the first variable from its mean and the deviation of the second variable from its mean, and you multiply them. Watch what the sign of that product does. If both variables are above their means, both deviations are positive, and a positive times a positive gives a positive product. If both are below their means, both deviations are negative, and a negative times a negative also gives a positive product. So whenever the two move together, in either direction, the product is positive. But if one is above its mean while the other is below, one deviation is positive and the other negative, and their product is negative. Covariance is the average of these products, so it comes out positive when the variables tend to move together and negative when they tend to move oppositely. The sign is not arbitrary. It falls straight out of multiplying the deviations.

Key terms

Covariance
The average of the products of the two variables' deviations from their means. Measures the direction of joint movement.
Deviation product
The deviation of one variable times the deviation of the other. Positive when they move together, negative when they move oppositely.
Positive covariance
The two variables tend to be above or below their means at the same time.
Negative covariance
When one is above its mean, the other tends to be below it.

The formula in symbols

Formula
Cov(X, Y) = Σ[(x − meanX)(y − meanY)] / N
  • x, y = a paired observation of the two variables
  • meanX, meanY = their two averages
  • Σ = add up over all the pairs
  • N = number of pairs

In plain words: for each pair, multiply the two deviations from their means, add up all those products, and divide by the number of pairs. The worked example below does exactly this for two periods.

Worked example

Why two assets that move together have positive covariance

Over two periods, Asset X returned 2 percent then 8 percent (mean 5 percent), and Asset Y returned 1 percent then 5 percent (mean 3 percent). Find the covariance.

  1. Period 1 deviations. X is 2 minus 5, which is negative 3. Y is 1 minus 3, which is negative 2. Both below their means.
  2. Period 1 product. Negative 3 times negative 2 is positive 6.
  3. Period 2 deviations and product. X is 8 minus 5, which is 3. Y is 5 minus 3, which is 2. Both above their means. Product is 3 times 2, which is positive 6.
  4. Average the products. 6 plus 6 is 12, divided by 2 periods is 6.
Result: The covariance is positive 6.

Why it matters: In both periods the two assets were on the same side of their means, so both products were positive, and the covariance came out positive. That is what moving together looks like.

Calculation

Compute a covariance

Over two periods, Asset X returned 2 percent then 8 percent (mean 5 percent), and Asset Y returned 6 percent then 2 percent (mean 4 percent). What is the covariance? (Multiply the paired deviations and average over the 2 periods.)

Need a hint?

Period 1: X is negative 3, Y is positive 2. Period 2: X is positive 3, Y is negative 2. Multiply each pair, then average.

The problem with covariance: its size

Covariance nails the direction of the relationship, but its size is almost impossible to interpret. The magnitude depends on the units and scale of the variables, so a covariance of 6 in one problem and 600 in another do not tell you which relationship is stronger. If you measured the same returns in decimals instead of percents, the covariance would change dramatically even though the underlying relationship did not. So covariance answers do they move together, but it cannot tell you how strongly in any comparable way. That is a real limitation, and it is exactly the gap the next lesson fills.

Covariance and correlation (zedstatistics)

Covers covariance and its sign, then bridges naturally into correlation, the next lesson. Watch for why we need to standardize the covariance.

Decision scenario

Predict the sign

Two airline stocks tend to rise together when travel demand is strong and fall together when it is weak. Without any calculation, what sign would you expect their covariance to have, and why?

Covariance in finance

In finance, covariance measures how two assets' returns move together, and it is the raw ingredient of portfolio risk. Two stocks with positive covariance amplify each other's swings, giving little protection when combined. Two with negative covariance offset each other, cushioning a portfolio. This is the seed of diversification, which you will build fully later in this unit. But because covariance's size is not comparable across pairs, we almost always convert it into a standardized number that is easy to read and compare. That number is correlation, and it is next.

Reflection

Explain the sign

In your own words, explain why the covariance comes out positive when two variables move together and negative when they move oppositely. Refer to the product of the deviations.

Write an answer before comparing it with the model response.

Covariance tells you the direction two assets move together, but not the strength in any comparable way. The next lesson fixes that by standardizing covariance into correlation, a number always between negative one and positive one.

Quiz

This lesson ends with a 5-question quiz. Create a free account or sign in to take it, save your progress and earn points.