Loading content...
In quantitative finance, portfolio risk assessment is foundational to investment decisions. One of the most critical metrics for evaluating portfolio risk is the portfolio variance, which measures how much the portfolio's returns are expected to fluctuate around their mean value.
When constructing a portfolio with multiple assets, the total risk is not simply the weighted sum of individual asset risks. Instead, the correlations and covariances between assets play a crucial role—assets that move in opposite directions (negative correlation) can reduce overall portfolio volatility, a principle known as diversification.
The portfolio variance is computed using the formula:
$$\sigma_p^2 = \mathbf{w}^T \Sigma \mathbf{w} = \sum_{i=1}^{n} \sum_{j=1}^{n} w_i w_j \sigma_{ij}$$
Where:
Properties of the Covariance Matrix:
Your Task: Write a Python function that computes the portfolio variance given a covariance matrix of asset returns and a vector of portfolio weights. The function should:
cov_matrix = [[0.1, 0.02], [0.02, 0.15]]
weights = [0.6, 0.4]0.0696For a two-asset portfolio with 60% in Asset A and 40% in Asset B:
Portfolio Variance = w₁²σ₁² + w₂²σ₂² + 2w₁w₂σ₁₂ = (0.6)²(0.1) + (0.4)²(0.15) + 2(0.6)(0.4)(0.02) = 0.036 + 0.024 + 0.0096 = 0.0696
The covariance term (0.02) contributes to the total variance. If assets were negatively correlated, this term would reduce total risk.
cov_matrix = [[0.04, 0.01, 0.005], [0.01, 0.09, 0.02], [0.005, 0.02, 0.16]]
weights = [0.4, 0.35, 0.25]0.0347For a three-asset portfolio (40% Asset A, 35% Asset B, 25% Asset C):
The computation involves all pairwise covariances: • Variance contributions: 0.4²×0.04 + 0.35²×0.09 + 0.25²×0.16 • Covariance contributions: 2×(0.4×0.35×0.01 + 0.4×0.25×0.005 + 0.35×0.25×0.02)
Total: 0.0064 + 0.011025 + 0.01 + 0.0028 + 0.001 + 0.0035 = 0.0347
Despite Asset C having high variance (0.16), its limited weight (25%) and moderate covariances keep the total portfolio variance manageable.
cov_matrix = [[0.1, 0.0, 0.0], [0.0, 0.2, 0.0], [0.0, 0.0, 0.3]]
weights = [0.3333, 0.3333, 0.3334]0.0667This represents three uncorrelated assets (zero covariances) with equal weighting:
Portfolio Variance = w₁²σ₁² + w₂²σ₂² + w₃²σ₃² (no covariance terms since they're all zero) = (0.3333)²(0.1) + (0.3333)²(0.2) + (0.3334)²(0.3) = 0.0111 + 0.0222 + 0.0334 = 0.0667
With zero correlations, diversification benefit comes purely from not putting all eggs in one basket. The portfolio variance (0.0667) is much lower than the highest individual variance (0.3).
Constraints