backtrader.reports.charts module

Report-specific chart generator.

Generates static charts for reports, distinct from interactive plotting.

class backtrader.reports.charts.ReportChart[source]

Bases: 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)[source]

Initialize the chart generator.

Parameters:
  • figsize – Chart size (width, height)

  • dpi – Chart resolution

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

Plot equity curve chart.

Parameters:
  • 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

Returns:

matplotlib.figure.Figure or None

plot_return_bars(dates, values, period='auto', title=None)[source]

Plot return bars chart.

Parameters:
  • dates – List of dates

  • values – List of equity values

  • period – Period (‘auto’, ‘daily’, ‘weekly’, ‘monthly’, ‘yearly’)

  • title – Chart title

Returns:

matplotlib.figure.Figure or None

plot_drawdown(dates, values, title='Drawdown')[source]

Plot drawdown area chart.

Parameters:
  • dates – List of dates

  • values – List of equity values

  • title – Chart title

Returns:

matplotlib.figure.Figure or None

save_to_file(fig, filename, format='png')[source]

Save chart to file.

Parameters:
  • fig – matplotlib figure object

  • filename – Output filename

  • format – Image format (‘png’, ‘jpg’, ‘svg’, ‘pdf’)

to_base64(fig, format='png')[source]

Convert chart to base64 encoding.

Parameters:
  • fig – matplotlib figure object

  • format – Image format

Returns:

base64 encoded image data

Return type:

str

close_all()[source]

Close all charts and release memory.