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
评论列表
文章目录