January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to find the Efficient Frontier using optimization with scipy.
import numpy as npimport scipy.optimize as sco
def get_portf_rtn(w, avg_rtns): return np.sum(avg_rtns * w)def get_portf_vol(w, avg_rtns, cov_mat): return np.sqrt(np.dot(w.T, np.dot(cov_mat, w)))
def get_efficient_frontier(avg_rtns, cov_mat, rtns_range): efficient_portfolios = [] n_assets = len(avg_returns) args = (avg_returns, cov_mat) bounds = tuple((0,1) for asset in range(n_assets)) initial_guess = n_assets * [1. / n_assets, ] for ret in rtns_range: constraints = ({'type': 'eq', ...Read now
Unlock full access