Lesson 2 of 15

Portfolio Variance (2-Asset)

Portfolio Variance for Two Assets

While the expected return of a portfolio is simply a weighted average, portfolio variance also depends on how the assets co-move — captured by their correlation.

For two assets with weights w₁, w₂ and standard deviations σ₁, σ₂ (in finance/statistics, σ denotes standard deviation or volatility — not the sigmoid activation function used in ML):

σp2=w12σ12+w22σ22+2w1w2ρ12σ1σ2\sigma_p^2 = w_1^2 \sigma_1^2 + w_2^2 \sigma_2^2 + 2 w_1 w_2 \rho_{12} \sigma_1 \sigma_2

where ρ₁₂ is the correlation between the two assets.

Key Insight: Diversification

  • If ρ = 1 (perfect positive correlation): no diversification benefit
  • If ρ = 0 (uncorrelated): partial diversification
  • If ρ = −1 (perfect negative correlation): maximum diversification — portfolio variance can reach zero

Your Task

Implement:

  • portfolio_variance_2(w1, s1, w2, s2, corr) — returns portfolio variance
  • portfolio_std_2(w1, s1, w2, s2, corr) — returns portfolio standard deviation (square root of variance)

Use only the math module.

Python runtime loading...
Loading...
Click "Run" to execute your code.