Kerry Back
\[\sum_{i=1}^n w_i^2 \sigma_i^2 + 2 \sum_{i=1}^n \sum_{j=i+1}^n w_iw_j \sigma_{ij}\]
\[\frac{\sigma^2}{n} + \frac{n-1}{n} \rho \sigma^2\]
import numpy as np
sd1, sd2, sd3 = 0.1, 0.15, 0.12
corr12, corr13, corr23 = 0.5, 0.7, 0.6
w1, w2, w3 = 0.2, 0.3, 0.5
S = np.diag([sd1, sd2, sd3])
R = np.identity(3)
R[0, 1] = R[1, 0] = corr12
R[0, 2] = R[2, 0] = corr13
R[1, 2] = R[2, 1] = corr23
C = S @ R @ S
w = np.array([w1, w2, w3])
portvar = w @ C @ w