visualizer.py 文件源码

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

项目:Odin 作者: JamesBrofos 项目源码 文件源码
def monthly_returns(self, fund, ax=None):
        if ax is None:
            ax = plt.gca()

        # Compute the returns on a month-over-month basis.
        history = fund.history
        monthly_ret = self.__aggregate_returns(history, 'monthly')
        monthly_ret = monthly_ret.unstack()
        monthly_ret = np.round(monthly_ret, 3)
        monthly_ret.rename(
            columns={1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr',
                     5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug',
                     9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'},
            inplace=True
        )

        # Create a heatmap showing the month-over-month returns of the portfolio
        # or the fund.
        sns.heatmap(
            monthly_ret.fillna(0) * 100.0, annot=True, fmt="0.1f",
            annot_kws={"size": 12}, alpha=1.0, center=0.0, cbar=False,
            cmap=cm.RdYlGn, ax=ax
        )
        ax.set_title('Monthly Returns (%)', fontweight='bold')
        ax.set_ylabel('')
        ax.set_yticklabels(ax.get_yticklabels(), rotation=0)
        ax.set_xlabel('')

        return ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号