How it works...
As mentioned in the introduction, we continued the example from the previous recipe. That is why we had to run Step 1 to Step 4 from the previous recipe, Finding the Efficient Frontier using Monte Carlo simulations (not shown here for brevity), to have all the required data. As an extra prerequisite, we had to import the optimization module from scipy.
In Step 2, we defined two functions, which returned the expected portfolio return and volatility, given historical data and the portfolio weights. We had to define these functions instead of calculating these metrics directly, as we used them in the optimization procedure. The algorithm iteratively tries different weights and needs to be able to use the current values of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access