FunctionRacerProblemsRace

Risk of a Mix

MediumNumPyPython

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems