Safest Mix
cov is the covariance matrix of some assets' yearly returns, in percent squared. A mix puts a share w[i] of the money in asset i; its variance is w @ cov @ w. Shares cannot be negative and must add up to 1. Return the smallest variance any mix can have. Answers within 0.01% are accepted.
Example 1
cov [[100.0,0.0],[0.0,100.0]]
returns 50.0
Two unrelated assets with the same variance: half in each halves the variance.
Example 2
cov [[400.0,0.0],[0.0,100.0]]
returns 80.0
A fifth in the wild asset and four fifths in the calm one.
Example 3
cov [[100.0,150.0],[150.0,400.0]]
returns 100.0
The second asset only adds risk here, and selling it short is not allowed, so everything goes into the first.
Constraints
- 2 to 6 assets
covis symmetric and positive definite
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More SciPy problems
- Smallest Total MissHard
- Volume Over a TriangleHard
- Area Under the PointsBeginner
- Chance of at MostBeginner
- City Block DistanceBeginner
- Percent at or BelowBeginner
- Standard ErrorBeginner
- Standard ScoresBeginner