Lesson 3 of 15

N-Asset Covariance Matrix

N-Asset Covariance Matrix

For a portfolio of N assets, the full variance-covariance structure is captured in an N×N covariance matrix Σ.

The (i, j) entry of Σ is the sample covariance between asset i and asset j:

Σij=1T1t=1T(ri,trˉi)(rj,trˉj)\Sigma_{ij} = \frac{1}{T-1} \sum_{t=1}^{T} (r_{i,t} - \bar{r}_i)(r_{j,t} - \bar{r}_j)

Note: when i = j this reduces to the variance of asset i.

Portfolio Variance

Given weights vector w and covariance matrix Σ, portfolio variance is:

σp2=wTΣw=ijwiwjΣij\sigma_p^2 = \mathbf{w}^T \Sigma \mathbf{w} = \sum_i \sum_j w_i w_j \Sigma_{ij}

Your Task

Implement:

  • cov_matrix(returns_list) — takes a list of return series (each a list of T returns), returns an N×N covariance matrix as a list of lists (sample covariance, divide by T−1)
  • portfolio_variance_n(weights, cov) — computes wᵀ Σ w given a weights list and a covariance matrix (list of lists)
Python runtime loading...
Loading...
Click "Run" to execute your code.