Skip to main content

backtrader_plotly

Plot backtrader's result using plotly instead of the default matplotlib

This is an experimental package, and it is done by replacing original matplotlib method calls.

Installation

$ pip install backtrader-plotly==1.5.0

Features

  • Support for Multiple Strategies Plotting (Added from 1.5.0.dev1)

  • Support for Filled Area Plotting and Toggling (Added from 1.4.0)

  • New Scheme Arguments (Added from 1.3.0)

    Additional scheme arguments are added to provide extra control

    Name of Argument Default Value Description
    decimal_places 5 It is used to control the number of decimal places of price shown on the plot. For instance, forex price usually consists of 5 decimal places.
    max_legend_text_width 16 It is used to limit the legend text width to prevent it from occupying the page.

Usage

Complete Working Example Here

# import the package after installation
from backtrader_plotly.plotter import BacktraderPlotly
from backtrader_plotly.scheme import PlotScheme
import plotly.io

# do whatever you want with `backtrader`
import backtrader as bt

# for instance
cerebro = bt.Cerebro()

# add strategies
cerebro.addstrategy(IchimokuStrategy)
cerebro.addstrategy(SMACrossStrategy)

# after adding data and strategy
cerebro.run()

# define plot scheme with new additional scheme arguments
scheme = PlotScheme(decimal_places=5, max_legend_text_width=16)

figs = cerebro.plot(BacktraderPlotly(show=False, scheme=scheme))

# directly manipulate object using methods provided by `plotly`
for i, each_run in enumerate(figs):
    for j, each_strategy_fig in enumerate(each_run):
        # open plot in browser
        each_strategy_fig.show()

        # save the html of the plot to a variable
        html = plotly.io.to_html(each_strategy_fig, full_html=False)

        # write html to disk
        plotly.io.write_html(each_strategy_fig, f'{i}_{j}.html', full_html=True)

Metadata

Release files for backtrader-plotly 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backtrader-plotly 1.5.0
File Size Uploaded
backtrader_plotly-1.5.0.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backtrader-plotly 1.5.0
File Interpreter ABI Platform
backtrader_plotly-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.0 kB

Release files / backtrader_plotly-1.5.0.tar.gz

Download URL backtrader_plotly-1.5.0.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
84594b90ea2c34e842320194143f8cf1afe500294a207b521216fb46c4ba2a8f
BLAKE2b-256 checksum
How to use checksums
a6c453091c09b7e02cbce736b9fc671e9b7c4b08e69706f3ce809efeb9dda6e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / backtrader_plotly-1.5.0-py3-none-any.whl

Download URL backtrader_plotly-1.5.0-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ff95c4ad9a2f311c6f1811d72c1cc673e4bcc7b3ebecb6ad0d77a253a8c95f5
BLAKE2b-256 checksum
How to use checksums
1ee320540d07df8bd3742a5f61cfe9ac1d1a29832f496568b941b09ae4f25c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page