Equal-Weight Portfolio Variance
Problem statement
A portfolio contains n assets. Every asset return has variance 1, and every asset has portfolio weight 1/n. Every pair of distinct asset returns has the same correlation rho. Return the variance of the weighted portfolio return.
For this exercise, assume 0 <= rho <= 1. The value rho = 0 is the independent-assets baseline; positive values model the common positive-correlation follow-up. The covariance of distinct unit-variance returns is therefore rho.
Return a floating-point number. Answers are accepted within relative or absolute tolerance 10^-6.
Function
portfolioVariance(n: int, rho: double) → doubleExamples
Example 1
n = 4rho = 0.0return = 0.25Four independent unit-variance assets with equal weights have variance 4 * (1/4)^2 = 1/4.
Example 2
n = 4rho = 0.2return = 0.4The four diagonal covariance terms and twelve ordered off-diagonal terms give (4 + 12 * 0.2) / 16 = 0.4.
Constraints
1 <= n <= 10^6.rhois finite and0 <= rho <= 1.- All asset variances are
1, and all weights are exactly1/n.