02 — Covariance, Correlation and Diversification¶
Learning objectives¶
Compute portfolio variance from the two-asset expanded formula by hand; see how correlation changes portfolio volatility, from a perfect hedge at rho=-1 to no diversification benefit at all at rho=+1; explain why correlation, not just individual volatility, determines how much diversification actually helps.
Free learning pack¶
- MIT OCW Portfolio Theory I–III https://ocw.mit.edu/courses/15-401-finance-theory-i-fall-2008/pages/video-lectures-and-slides/portfolio-theory/
- CFA Portfolio Risk and Return Part I https://www.cfainstitute.org/insights/professional-learning/refresher-readings/2026/portfolio-risk-return-part-1
resources/portfolio_foundations.mdreference/concepts/covariance.md
Do not search for more material until these are insufficient.
PREDICT¶
Two 50/50 assets have volatilities 20% and 10%. What happens to portfolio volatility as correlation moves from +1 to -1? At the extreme of rho=-1, can portfolio volatility go below the lower of the two individual volatilities?
HAND CALCULATION¶
Use rho=0.25.
sigma_p^2 = w1^2*sigma1^2 + w2^2*sigma2^2 + 2*w1*w2*rho*sigma1*sigma2
import numpy as np
vol_a, vol_b, rho = 0.20, 0.10, 0.25
w1 = w2 = 0.5
# MANUAL FIRST: type the expanded variance formula.
variance = None
portfolio_vol = None
print(variance, portfolio_vol)
# CHECK (uncomment after your attempt):
# assert np.isclose(variance, 0.015)
# assert np.isclose(portfolio_vol, 0.1225, atol=1e-4)
Experiment¶
Vary correlation from -1 to +1 and plot portfolio volatility. Confirm
the two extremes match closed forms you can check by hand: at
rho=-1, sigma_p = |w1*sigma1 - w2*sigma2| (a partial hedge); at
rho=+1, sigma_p = w1*sigma1 + w2*sigma2 (no diversification benefit
at all — volatility is just the weighted average).
import matplotlib.pyplot as plt
# MANUAL FIRST:
# for rhos = np.linspace(-1, 1, 101), compute portfolio_vol at each rho
# (same formula as above, with rho varying) and collect into `vols`.
rhos = np.linspace(-1, 1, 101)
vols = None
# CHECK (uncomment after your attempt):
# assert np.isclose(vols[0], abs(w1 * vol_a - w2 * vol_b), atol=1e-3), "rho=-1 endpoint"
# assert np.isclose(vols[-1], w1 * vol_a + w2 * vol_b, atol=1e-3), "rho=+1 endpoint"
fig, ax = plt.subplots(figsize=(7, 5))
ax.plot(rhos, vols, color="#1f6feb", linewidth=2)
ax.axhline(vol_a, color="#9AA2AE", linestyle="--", linewidth=1, label=f"asset A alone ({vol_a:.0%})")
ax.axhline(vol_b, color="#9AA2AE", linestyle=":", linewidth=1, label=f"asset B alone ({vol_b:.0%})")
ax.set_xlabel("correlation (rho)")
ax.set_ylabel("portfolio volatility")
ax.set_title("Portfolio volatility vs. correlation, 50/50 weights")
ax.legend()
plt.show()
Reference¶
reference/concepts/covariance.md
reference/concepts/portfolio_volatility.md
Promote¶
Use src/pm/risk.py (portfolio_variance, portfolio_volatility) only
after your own implementation.
Test¶
pytest tests/test_risk.py
ORAL CHECK¶
Why is ten highly correlated bonds potentially less diversified than three low-correlated assets? Looking at your plot: at what correlation does the diversification benefit disappear entirely, and why does that make sense given the formula?
Try /tutor covariance for an adaptive walkthrough.