统计指标绘图
通过matplotlib绘制4幅图:
资金曲线图
资金回撤图
每日盈亏图
每日盈亏分布图
- def show_chart(self, df: DataFrame = None):
- """"""
- if not df:
- df = self.daily_df
- if df is None:
- return
- plt.figure(figsize=(10, 16))
- balance_plot = plt.subplot(4, 1, 1)
- balance_plot.set_title("Balance")
- df["balance"].plot(legend=True)
- drawdown_plot = plt.subplot(4, 1, 2)
- drawdown_plot.set_title("Drawdown")
- drawdown_plot.fill_between(range(len(df)), df["drawdown"].values)
- pnl_plot = plt.subplot(4, 1, 3)
- pnl_plot.set_title("Daily Pnl")
- df["net_pnl"].plot(kind="bar", legend=False, grid=False, xticks=[])
- distribution_plot = plt.subplot(4, 1, 4)
- distribution_plot.set_title("Daily Pnl Distribution")
- df["net_pnl"].hist(bins=50)
- plt.show()