统计指标绘图

通过matplotlib绘制4幅图:

  • 资金曲线图

  • 资金回撤图

  • 每日盈亏图

  • 每日盈亏分布图

  1. def show_chart(self, df: DataFrame = None):
  2. """"""
  3. if not df:
  4. df = self.daily_df
  5.  
  6. if df is None:
  7. return
  8.  
  9. plt.figure(figsize=(10, 16))
  10.  
  11. balance_plot = plt.subplot(4, 1, 1)
  12. balance_plot.set_title("Balance")
  13. df["balance"].plot(legend=True)
  14.  
  15. drawdown_plot = plt.subplot(4, 1, 2)
  16. drawdown_plot.set_title("Drawdown")
  17. drawdown_plot.fill_between(range(len(df)), df["drawdown"].values)
  18.  
  19. pnl_plot = plt.subplot(4, 1, 3)
  20. pnl_plot.set_title("Daily Pnl")
  21. df["net_pnl"].plot(kind="bar", legend=False, grid=False, xticks=[])
  22.  
  23. distribution_plot = plt.subplot(4, 1, 4)
  24. distribution_plot.set_title("Daily Pnl Distribution")
  25. df["net_pnl"].hist(bins=50)
  26.  
  27. plt.show()