def savefig(self): returns = self.port.returns model = 'Classic' # 포트폴리오 수익률과 비중 저장 with open( 'returns-{}_{}.pkl'.format(self.risk_profile, self.current_date), 'wb') as f: pl.dump(returns, f) with open('w-{}_{}.pkl'.format(self.risk_profile, self.current_date), 'wb') as f: pl.dump(self.w, f) # Efficient fronter 저장 points = 50 # Number of points of the frontier frontier = self.port.efficient_frontier(model=model, rm=self.rm, points=points, rf=self.rf, hist=True) label = 'Max-return Portfolio' if self.risk_profile == 4 else 'Min-risk Portfolio' mu = self.port.mu # Expected returns cov = self.port.cov # Covariance matrix fig1, ax1 = plt.subplots() ax1 = plf.plot_frontier(w_frontier=frontier, mu=mu, cov=cov, returns=returns, rm=self.rm, rf=self.rf, alpha=0.05, cmap='viridis', w=self.w, label=label, marker='*', s=16, c='r', height=6, width=10, ax=ax1) fig1.savefig('ef-{}_{}.png'.format(self.risk_profile, self.current_date)) fig2, ax2 = plt.subplots(nrows=1, ncols=1) # Plotting efficient frontier composition ax2 = plf.plot_frontier_area(w_frontier=frontier, cmap="tab20", height=6, width=10, ax=None) fig2.savefig('ef_area-{}_{}.png'.format(self.risk_profile, self.current_date))
rf=rf, alpha=0.01, cmap='viridis', w=w, label=label, marker='*', s=16, c='r', height=6, width=10, ax=None) # Plotting efficient frontier composition ax = plf.plot_frontier_area(w_frontier=frontier, cmap="tab20", height=6, width=10, ax=None) rm = 'CVaR' # Risk measure w = port.optimization(model=model, rm=rm, obj=obj, rf=rf, l=l, hist=hist) print(w.T) ax = plf.plot_pie(w=w, title='Sharpe Mean CVaR', others=0.05, nrow=25, cmap="tab20", height=6, width=10, ax=None) points = 50 # Number of points of the frontier