Risk of a Mix
returns has one row per day and one column per asset. weights is the share of money in each asset. The mix earns returns @ weights each day.
Return the sample standard deviation of those daily earnings (divide by days minus 1). This equals the square root of w C w, where C is the sample covariance matrix of the columns.
Example 1
returns [[0.01,0.03],[0.03,0.01],[0.02,0.05]]
weights [0.5,0.5]
returns 0.008660254037844387
The mix earns 0.02, 0.02 and 0.035 on the three days. Their sample standard deviation is about 0.00866.
Constraints
2 <= days <= 60,2 <= assets <= 6- The weights are not negative and add up to 1
- The answer is greater than 0
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Row SharesMedium
- Sort by First ColumnMedium
- Subtract Row MinimumMedium
- Unit VectorsMedium
- Best Square BlockHard
- Crossing AboveHard
- Current StreakHard
- Finished SudokuHard