btplotting provides plotting for backtests, optimization results and live data from backtrader.
btplotting
Library to add extended plotting capabilities to backtrader (
btplotting is based on the awesome backtraderplotting (
btplotting is a complete rework of backtrader_plotting with the live client in focus. Besides this, a lot of issues are fixed and new functionality is added. See the list below for differences.
What is different:
Basic:
- No need for custom backtrader
- Different naming / structure
- Data alignment which allows to generate data for different data sources.
- Support for replay data
- Different filtering of plot objects
- Every figure has its own ColumnDataSource, so the live client can patch without
- Plotting looks very similar to backtraders own plotting (order, heights, etc.)
- Allows to generate custom columns, which don't have to be hardcoded.
- This is being used to generate color for candles, varea values, etc.
- Save images of strategy or a single data (for example save an image of data when
Plotting:
- Datas, Indicators, Observer and Volume have own aspect ratios, which can be configured in live client
- Only one axis for volume will be added when using multiple data sources on one figure
- Volume axis position is configureable in scheme, by default it is being plotted on the right side
- Linked Crosshair across all figures
- skipnan, fillgt, fill_lt, fill support
- Plot objects can be filtered by one or more datanames or by plot group
- Custom plot group, which can be configured in app or in live client by providing all
Tabs:
- Default tabs can be completely removed
- New log panel to also include logging information
- Can be extended with custom tabs (for example order execution with live client, custom analysis, etc.)
(Live plotting is broken at the moment)
- Navigation in live client (Pause, Backward, Forward)
- Live plotting is done using an analyzer, so there is no need to use custom backtrader
- Live plotting data update works in a single thread and is done by a DataHandler
- Data update is being done every n seconds, which is configureable
Features
- Interactive plots
- Interactive
backtraderoptimization result browser (only supported for single-strategy runs) - Highly configurable
- Different skinnable themes
- Easy to use
How to use
- Add to cerebro as an analyzer:
from btplotting import BacktraderPlottingLive
...
...
cerebro = bt.Cerebro() cerebro.addstrategy(MyStrategy) cerebro.adddata(LiveDataStream()) cerebro.addanalyzer(BacktraderPlottingLive) cerebro.run() cerebro.plot()
- If you need to change the default port or share the plotting to public:
cerebro.addanalyzer(BacktraderPlottingLive, address="*", port=8889)
Jupyter
In Jupyter you can plot to a single browser tab with iplot=False:
plot = btplotting.BacktraderPlotting()
cerebro.plot(plot, iplot=False)
You may encounters TypeError: <class 'main.YourStrategyClass'> is a built-in class error.
To remove the source code tab use:
plot = btplotting.BacktraderPlotting()
plot.tabs.remove(btplotting.tabs.SourceTab)
cerebro.plot(plot, iplot=False)
Demos
Installation
pip install git+https://github.com/happydasch/btplotting
Sponsoring
If you want to support the development of btplotting, consider to support this project.
- BTC: 39BJtPgUv6UMjQvjguphN7kkjQF65rgMMF
- ETH: 0x06d6f3134CD679d05AAfeA6e426f55805f9B395D