We can calculate an efficient frontier using scipy.optimize.minimize and the historical estimates for asset returns, standard deviations, and the covariance matrix. The code can be found in the efficient_frontier subfolder of the repo for this chapter and implements the following sequence of steps:
- The simulation generates random weights using the Dirichlet distribution, and computes the mean, standard deviation, and SR for each sample portfolio using the historical return data:
def simulate_portfolios(mean_ret, cov, rf_rate=rf_rate, short=True): alpha = np.full(shape=n_assets, fill_value=.01) weights = dirichlet(alpha=alpha, size=NUM_PF) weights *= choice([-1, 1], size=weights.shape) returns = weights @ ...