Premium problem100. Variance of a Weighted Combination

Medium Locked

Given weights w and the covariance matrix covariance of a random vector XX, return Var(w⊤X)\mathrm{Var}(w^{\top}X).

Var(w⊤X)=w⊤Σw\mathrm{Var}(w^{\top}X) = w^{\top}\Sigma w

The off-diagonal terms are the point: correlated inputs can make a portfolio or an ensemble far riskier than summing individual variances suggests.

Input

w = [0.5, 0.5]
covariance = [[1.0, 0.0], [0.0, 1.0]]

Output

0.5

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)