Sub topic 16
Covariance and correlation
This chapter assumes you can compute an expected value, a variance and a standard deviation for a discrete distribution, as covered in the previous chapter. It also assumes you can do basic algebra with square roots. The goal is to measure how two returns move together and to carry that measure into portfolio risk.
Why a joint measure is needed
Variance describes one asset on its own. A portfolio holds several assets, and its risk depends on how their returns move relative to each other. Two assets can each be volatile, yet if one tends to rise when the other falls, holding both is much calmer than holding either one.
Covariance and correlation measure that co-movement. Both are built from deviations from the mean, the same ingredient as variance.
Covariance
Covariance is the expected value of the product of two deviations from their means:
Cov(A, B) = E[(A − E[A]) × (B − E[B])]
- If A and B tend to be above their means together, or below their means together, the products are mostly positive and covariance is positive.
- If one tends to be above its mean when the other is below, the products are mostly negative and covariance is negative.
- If there is no consistent pattern, the positive and negative products offset and covariance is near zero.
Covariance of a variable with itself is its variance: Cov(A, A) = Var(A).
Covariance from a probability model
When you are given scenarios with probabilities, weight each product of deviations by its probability. This mirrors the variance calculation from the previous chapter.
probs = [0.2, 0.5, 0.3]
ret_a = [0.00, 0.08, 0.15]
ret_b = [0.06, 0.02, 0.10]
mean_a = sum(p * r for p, r in zip(probs, ret_a))
mean_b = sum(p * r for p, r in zip(probs, ret_b))
cov = sum(p * (a - mean_a) * (b - mean_b)
for p, a, b in zip(probs, ret_a, ret_b))
var_a = sum(p * (a - mean_a) ** 2 for p, a in zip(probs, ret_a))
var_b = sum(p * (b - mean_b) ** 2 for p, b in zip(probs, ret_b))
corr = cov / (var_a ** 0.5 * var_b ** 0.5)
print(round(mean_a, 4), round(mean_b, 4)) # 0.085 0.052
print(round(cov, 6)) # 0.00088
print(round(corr, 4)) # 0.4834The covariance is positive, so the two assets tend to move in the same direction. The value 0.00088 is hard to interpret on its own, which leads to correlation.
Covariance from historical data
With observed returns, use the sample covariance. It divides by n − 1, not n, for the same reason the sample variance does.
a = [1, 3, 5, 7] # returns in percent
b = [2, 1, 5, 4]
n = len(a)
mean_a = sum(a) / n
mean_b = sum(b) / n
sample_cov = sum((x - mean_a) * (y - mean_b) for x, y in zip(a, b)) / (n - 1)
sample_var_a = sum((x - mean_a) ** 2 for x in a) / (n - 1)
sample_var_b = sum((y - mean_b) ** 2 for y in b) / (n - 1)
corr = sample_cov / (sample_var_a ** 0.5 * sample_var_b ** 0.5)
print(round(sample_cov, 4)) # 3.3333
print(round(corr, 4)) # 0.7071The units of covariance are the product of the units of the two variables, here percent squared. That is why its size is hard to judge.
Correlation
The correlation coefficient rescales covariance by the two standard deviations:
ρ(A, B) = Cov(A, B) / (σA × σB)
The result is unit-free and always lies between −1 and +1.
| Correlation | Meaning |
|---|---|
| +1 | Perfect positive linear relationship |
| Between 0 and +1 | Tend to move together, imperfectly |
| 0 | No linear relationship |
| Between −1 and 0 | Tend to move in opposite directions |
| −1 | Perfect negative linear relationship |
Rearranged, the same formula gives Cov(A, B) = ρ × σA × σB. You will use this on the exam whenever a question gives correlation and standard deviations but the formula asks for covariance.
The n − 1 factors cancel in the sample ratio, so you get the same correlation whether you use sample or population covariance, as long as you use the matching standard deviations.
Using covariance in portfolio risk
For two assets with weights w1 and w2, the portfolio variance is:
σp² = w1²σ1² + w2²σ2² + 2 w1 w2 Cov(1, 2)
The last term is where co-movement enters. Substituting Cov = ρσ1σ2 gives the correlation form. The expected return is simply the weighted average, since it does not depend on co-movement.
w1, w2 = 0.6, 0.4
sd1, sd2 = 0.20, 0.10
def portfolio_sd(rho):
cov = rho * sd1 * sd2
variance = (w1 * sd1) ** 2 + (w2 * sd2) ** 2 + 2 * w1 * w2 * cov
return variance ** 0.5
weighted_average_sd = w1 * sd1 + w2 * sd2
print(round(weighted_average_sd, 4)) # 0.16
for rho in [1.0, 0.3, 0.0, -1.0]:
print(rho, round(portfolio_sd(rho), 4))
# 1.0 0.16
# 0.3 0.1374
# 0.0 0.1265
# -1.0 0.08At ρ = +1, portfolio standard deviation equals the weighted average of the two, so there is no diversification benefit. Any ρ below +1 gives a lower figure. This is the diversification effect: the lower the correlation, the larger the reduction in risk.
Common errors
- Reading covariance size as strength. A covariance of 0.00088 or 3.33 says nothing about strength because it depends on units and volatility. Only the sign is interpretable. Use correlation to judge strength.
- Mixing sample and population divisors. If the question gives a list of observed returns, divide by n − 1. If it gives scenarios with probabilities, weight by the probabilities and do not divide by anything else.
- Averaging standard deviations. The portfolio standard deviation is not the weighted average of the asset standard deviations unless ρ = +1.
- Forgetting the factor of 2. The covariance term appears twice, once for each ordering of the pair, so it is 2 w1 w2 Cov.
- Squaring the weights incorrectly. The first two terms use (w × σ)², so the weight is squared along with the standard deviation.
Worked check
Suppose two assets have σ1 = 20%, σ2 = 10% and ρ = 0.3.
- Covariance: 0.3 × 0.20 × 0.10 = 0.006.
- Weighted variances with weights 0.6 and 0.4: (0.12)² + (0.04)² = 0.0144 + 0.0016 = 0.016.
- Covariance term: 2 × 0.6 × 0.4 × 0.006 = 0.00288.
- Portfolio variance: 0.016 + 0.00288 = 0.01888.
- Portfolio standard deviation: √0.01888 ≈ 13.74%.
This matches the code output above and sits below the 16% weighted average.
Exercise
Two assets have standard deviations of 15% and 25%, and their covariance is 0.01875. What is their correlation, and what does it say about diversification?
Show answer
Correlation = 0.01875 / (0.15 × 0.25) = 0.01875 / 0.0375 = 0.5. The correlation is positive but below 1, so combining the assets reduces portfolio standard deviation below the weighted average of 15% and 25%, though not as much as a lower correlation would.
Exercise
A portfolio holds 50% of asset X (standard deviation 12%) and 50% of asset Y (standard deviation 8%). The correlation between them is −0.5. Calculate the portfolio standard deviation.
Show answer
Cov = −0.5 × 0.12 × 0.08 = −0.0048. Variance = (0.5 × 0.12)² + (0.5 × 0.08)² + 2 × 0.5 × 0.5 × (−0.0048) = 0.0036 + 0.0016 − 0.0024 = 0.0028. Standard deviation = √0.0028 ≈ 5.29%, well below the 10% weighted average.
Exercise
Returns on two assets have a correlation of exactly zero in a large sample. Can you conclude the returns are independent?
Show answer
No. Zero correlation rules out a linear relationship only. The returns could still be related in a nonlinear way, such as one being the square of the other, so they would be dependent despite having zero correlation.