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):
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 varianceportfolio_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.