FastPrepEqual-Weight Portfolio Variance

Equal-Weight Portfolio Variance

The D.E. Shaw Group logoThe D.E. Shaw Group● EasyFULLTIMEPHONE SCREEN
Learn

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) → double

Examples

Example 1

n = 4rho = 0.0return = 0.25

Four independent unit-variance assets with equal weights have variance 4 * (1/4)^2 = 1/4.

Example 2

n = 4rho = 0.2return = 0.4

The four diagonal covariance terms and twelve ordered off-diagonal terms give (4 + 12 * 0.2) / 16 = 0.4.

Constraints

  • 1 <= n <= 10^6.
  • rho is finite and 0 <= rho <= 1.
  • All asset variances are 1, and all weights are exactly 1/n.

More The D.E. Shaw Group problems

See The D.E. Shaw Group hiring insights
public double portfolioVariance(int n, double rho) {
    // Write your code here.
}
n4
rho0.0
expected0.25
Checking account…