def markowitz_r_spe_bl(funddfr, P, eta, alpha, bounds): rf = Const.rf final_risk = 0 final_return = 0 final_ws = [] final_ws = list(1.0 * np.ones(len(funddfr.columns)) / len(funddfr.columns)) final_sharp = -np.inf final_codes = [] codes = funddfr.columns return_rate = [] for code in codes: return_rate.append(funddfr[code].values) if eta.size == 0: risks, returns, ws = fin.efficient_frontier_spe(return_rate, bounds) else: risks, returns, ws = fin.efficient_frontier_spe_bl( return_rate, P, eta, alpha, bounds) for j in range(0, len(risks)): if risks[j] == 0: continue sharp = (returns[j] - rf) / risks[j] if sharp > final_sharp: final_risk = risks[j] final_return = returns[j] final_ws = ws[j] final_sharp = sharp return final_risk, final_return, final_ws, final_sharp
def markowitz_r_spe_bl(self, funddfr, P, eta, alpha, bounds): final_risk = 0 final_return = 0 final_ws = [] final_ws = list(1.0 * np.ones(len(funddfr.columns)) / len(funddfr.columns)) final_sharpe = -np.inf final_codes = [] codes = funddfr.columns return_rate = [] for code in codes: return_rate.append(funddfr[code].values) if eta.size == 0: risk, ret, ws = fin.efficient_frontier_spe(return_rate, bounds) else: risk, ret, ws = fin.efficient_frontier_spe_bl(return_rate, P, eta, alpha, bounds) for j in range(len(risk)): if risks[j] == 0: continue sharpe = (ret[j] - Const.rf) / risk[j] if sharpe > final_sharp: final_risk = risk[j] final_return = ret[j] final_ws = ws[j] final_sharpe = sharpe # final_res = np.append(final_ws, np.array([final_risk, final_ret, final_sharpe])) return final_ws