def max_sharpe(self):
if not self.w:<EOL><INDENT>self.solve()<EOL><DEDENT>w_sr, sr = [], []<EOL>for i in range(len(self.w) - <NUM_LIT:1>):<EOL><INDENT>w0 = np.copy(self.w[i])<EOL>w1 = np.copy(self.w[i + <NUM_LIT:1>])<EOL>kargs = {"<STR_LIT>": False, "<STR_LIT:args>": (w0, w1)}<EOL>a, b = self.golden_section(self.eval_sr, <NUM_LIT:0>, <NUM_LIT:1>, **kargs)<EOL>w_sr.append(a * w0 + (<NUM_LIT:1> - a) * w1)<EOL>sr.append(b)<EOL><DEDENT>self.weights = w_sr[sr.index(max(sr))].reshape((self.n_assets,))<EOL>return dict(zip(self.tickers, self.weights))<EOL>
Get the max Sharpe ratio portfolio