创建熊猫系列每月退货热图的实用程序
monthly-returns-heatmap的Python项目详细描述
monthly returns heatmap是一个用于创建 熊猫系列的月度回报热图。
快速启动
让我们为SPY创建一个退货热图 (标准普尔500指数蜘蛛ETF)。
首先,让我们从google finance下载spy的每日收盘价。
frompandas_datareaderimportdataprices=data.get_data_google("SPY")['Close']returns=prices.pct_change()
下一步,我们将导入monthly_returns_heatmap,并绘制每月返回热图:
importmonthly_returns_heatmapasmrhreturns.plot_monthly_returns_heatmap()# mrh.plot(returns) # <== or using direct call
仅获取热图数据(不绘制)
heatmap=prices.get_monthly_returns_heatmap()# heatmap = mrh.get(returns) # <== or using direct callprint(heatmap)# prints:MonthJanFebMarApr...DecYear20100.0000000.0311950.0565290.015470...0.06127120110.0233000.034737-0.0048070.030413...0.00311720120.0454980.0431370.028129-0.006751...0.00175920130.0511900.0127590.0333750.019212...0.0203872014-0.0352480.0455160.0038650.006951...-0.0080122015-0.0296290.056205-0.0200800.009834...-0.0230962016-0.049787-0.0019100.0629430.003941...0.01429320170.0178950.039292-0.0030870.009926...0.000000
获取参数(可选)
- is_prices-如果使用的数据是价格数据而不是返回数据,则设置为True。
- compounded-如果不希望计算使用复合返回,则设置为False。
- eoy-设置为True以添加具有总年度回报的年终列
绘图参数(可选)
- title-热图标题(默认为"Monthly Returns (%)")
- title_color-热图标题颜色(默认为"black")
- title_size-热图标题字体大小(默认为12)
- annot_size-返回框的字体大小(默认为10)
- figsize-热图图形大小(默认为None)
- cmap-颜色映射(默认为"RdYlGn")
- cbar-显示颜色栏?(默认为True)
- square-force squere返回框?(默认为False)
- is_prices-如果使用的数据是价格数据而不是返回数据,则设置为True。
- compounded-如果不希望计算使用复合返回,则设置为False。
- eoy-设置为True以添加具有总年度回报的年终列
安装
使用pip:
安装monthly_returns_heatmap。$ pip install monthly_returns_heatmap --upgrade --no-cache-dir
要求
- Python>;=3.4
- Pandas(经测试可与>;=0.18.1一起使用)
- Matplotlib(经测试可与>;=1.5.3一起工作)
- Seaborn(经测试可与>;=0.7一起工作)
法律事务
monthly returns heatmap在gnu lesser通用公共许可v3.0下分发。有关详细信息,请参见发行版中的LICENSE.txt文件。
P.S.
请给我一张便条,上面有你的任何反馈。
ran唤醒