backtrader.reports.charts module

Report-specific chart generator.

Generates static charts for reports, distinct from interactive plotting.

class backtrader.reports.charts.ReportChart[源代码]

基类:object

Report-specific chart generator.

Generates static charts for reports, including: - Equity curve chart (with buy-and-hold comparison line) - Return bars chart (automatic period detection) - Drawdown area chart

figsize

Default chart size

dpi

Chart resolution

__init__(figsize=(10, 3), dpi=100)[源代码]

Initialize the chart generator.

参数:
  • figsize -- Chart size (width, height)

  • dpi -- Chart resolution

plot_equity_curve(dates, values, benchmark_dates=None, benchmark_values=None, title='Equity Curve')[源代码]

Plot equity curve chart.

参数:
  • dates -- List of dates

  • values -- List of equity values

  • benchmark_dates -- List of benchmark dates (optional)

  • benchmark_values -- List of benchmark values (optional, e.g., buy-and-hold)

  • title -- Chart title

返回:

matplotlib.figure.Figure or None

plot_return_bars(dates, values, period='auto', title=None)[源代码]

Plot return bars chart.

参数:
  • dates -- List of dates

  • values -- List of equity values

  • period -- Period ('auto', 'daily', 'weekly', 'monthly', 'yearly')

  • title -- Chart title

返回:

matplotlib.figure.Figure or None

plot_drawdown(dates, values, title='Drawdown')[源代码]

Plot drawdown area chart.

参数:
  • dates -- List of dates

  • values -- List of equity values

  • title -- Chart title

返回:

matplotlib.figure.Figure or None

save_to_file(fig, filename, format='png')[源代码]

Save chart to file.

参数:
  • fig -- matplotlib figure object

  • filename -- Output filename

  • format -- Image format ('png', 'jpg', 'svg', 'pdf')

to_base64(fig, format='png')[源代码]

Convert chart to base64 encoding.

参数:
  • fig -- matplotlib figure object

  • format -- Image format

返回:

base64 encoded image data

返回类型:

str

close_all()[源代码]

Close all charts and release memory.