Library replacing original matlibplot used by backtrader
Project description
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.dev1
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
# 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for backtrader_plotly-1.5.0.dev1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 470216cc277417ae1c3915bcf4d35b06e0e7a92fe454c83ea850ffbd73ff3495 |
|
MD5 | 7fa728e66531aecf58351e650cc0c26d |
|
BLAKE2b-256 | 883f40dc583296a183b7aa271ef339d27aac807da4bd0e5e99ea4191a8cf98b1 |
Close
Hashes for backtrader_plotly-1.5.0.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda6aff80285d3b958404c428225796edb361a03b1a1fcb78b3b67e5894aadd8 |
|
MD5 | 9244a847c05a58e76373a2878dd8e788 |
|
BLAKE2b-256 | cbdc596c95a612755bac8b66a439a07fd8690ea0c66f6ff65493d8526fa71deb |