calculate_risk.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Mercury 作者: ruyiqf 项目源码 文件源码
def draw(self, title):
        import matplotlib
        import matplotlib.pyplot as plt
        import matplotlib.image as mpimg
        from matplotlib import gridspec
        plt.style.use('ggplot')
        red = '#aa4643'
        blue = '#4572a7'
        black = '#000000'
        figsize = (18,6)
        f = plt.figure(title, figsize=figsize)
        gs = gridspec.GridSpec(10,8)
        font_size = 12
        value_font_size = 11
        label_height, value_height = 0.8, 0.6
        fig_data = [
            (0.00, label_height, value_height, 'Max Down', '{0:.3%}'.format(self._max_drawdown), red, black),
            (0.30, label_height, value_height, 'Sharpe', '{0:.3}'.format(self._sharpe), red, black),
            (0.60, label_height, value_height, 'Volatility',  '{0:3%}'.format(self._volatility), red, black)]

        ax = plt.subplot(gs[:3, :-1])
        ax.axis('off')
        for x, y1, y2, label, value, label_color, value_color in fig_data:
            ax.text(x, y1, label, color=label_color, fontsize=font_size)
            ax.text(x, y2, value, color=value_color, fontsize=value_font_size)

        ax = plt.subplot(gs[4:,:])
        ax.get_xaxis().set_minor_locator(matplotlib.ticker.AutoMinorLocator())
        ax.get_yaxis().set_minor_locator(matplotlib.ticker.AutoMinorLocator())
        ax.grid(b=True, which='minor', linewidth=.2)
        ax.grid(b=True, which='major', linewidth=1)
        ax.plot(self._ret_df['net_worth'], label='strategy', alpha=1, linewidth=2, color=red)
        vals = ax.get_yticks()
        ax.set_yticklabels(['{:3.2f}%'.format(x*100) for x in vals])
        leg = plt.legend(loc='upper left')
        leg.get_frame().set_alpha(0.5)
        plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号