Skip to main content

backtrader_plotting

Library to add extended plotting capabilities to backtrader (https://www.backtrader.com/). Currently the only available backend is Bokeh (https://bokeh.org/).

Features

  • Interactive plots
  • Interactive backtrader optimization result browser (only supported for single-strategy runs)
  • Highly configurable
  • Different skinnable themes
  • Easy to use

Feel free to test it and play with it. I am happy about feedback, critics and ideas on backtrader forum (and also in GitHub issues): https://community.backtrader.com/topic/813/bokeh-integration-interactive-webbrowser-plotting

Needs Python >= 3.6.

Demos

https://verybadsoldier.github.io/backtrader_plotting/

Quickstart

from backtrader_plotting import Bokeh
from backtrader_plotting.schemes import Tradimo

<your backtrader code>

b = Bokeh(style='bar', plot_mode='single', scheme=Tradimo())
cerebro.plot(b)

Minimal Example

import datetime

import backtrader as bt

from backtrader_plotting import Bokeh


class TestStrategy(bt.Strategy):
    params = (
        ('buydate', 21),
        ('holdtime', 6),
    )

    def next(self):
        if len(self.data) == self.p.buydate:
            self.buy(self.datas[0], size=None)

        if len(self.data) == self.p.buydate + self.p.holdtime:
            self.sell(self.datas[0], size=None)


if __name__ == '__main__':
    cerebro = bt.Cerebro()

    cerebro.addstrategy(TestStrategy, buydate=3)

    data = bt.feeds.YahooFinanceCSVData(
        dataname="datas/orcl-1995-2014.txt",
        # Do not pass values before this date
        fromdate=datetime.datetime(2000, 1, 1),
        # Do not pass values after this date
        todate=datetime.datetime(2001, 2, 28),
        reverse=False,
        )
    cerebro.adddata(data)

    cerebro.run()

    b = Bokeh(style='bar', plot_mode='single')
    cerebro.plot(b)

Plotting Optimization Results

Another way to use this package is to use the OptBrowser to browse a backtrader optimization result:

...
cerebro.optstrategy(TestStrategy, buydate=range(1, 10, 1))
cerebro.addanalyzer(bt.analyzers.SharpeRatio)
...
res = cerebro.run()
bo = Bokeh()
browser = OptBrowser(bo, result)
browser.start()

This will start a Bokeh application (standalone webserver) displaying all optimization results. Different results can be selected and viewed.

It is possible possible to add further user-provided columns. When dealing with huge amounts of optimization results the number of results can be limited and the remaining results can be sorted by a user-provided function to allow for simple selection of the best results.

Documentation

Please refert to the Wiki for further documentation: https://github.com/verybadsoldier/backtrader_plotting/wiki

Metadata

Release files for backtrader-plotting 1.0.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-plotting 1.0.0
File Size Uploaded Provenance Actions
backtrader_plotting-1.0.0.tar.gz 23.2 kB Without provenance Details for backtrader_plotting-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for backtrader-plotting 1.0.0
File Interpreter ABI Platform Actions
backtrader_plotting-1.0.0-py3-none-any.whl Python 3 none any Details for backtrader_plotting-1.0.0-py3-none-any.whl

Total release size: 57.2 kB

Release files / backtrader_plotting-1.0.0.tar.gz

Download URL backtrader_plotting-1.0.0.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c2d39f943ab66985f2a35fdf759af9d9006b02a07979750adb90b072678f1687
BLAKE2b-256 checksum
How to use checksums
3b9c94d4acde705956b363614bc15f0eae3ec1f2a0664574f6d586edf1f70b73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Release files / backtrader_plotting-1.0.0-py3-none-any.whl

Download URL backtrader_plotting-1.0.0-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43f5b957f3909f86109fe89930ecffeb132a02c7ee1946abca76b09e9fe41e2f
BLAKE2b-256 checksum
How to use checksums
15a4db1651daf2af2878a6c8721460c912a8dd15792ff6ef451bbb16d8004971
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

Security for backtrader-plotting 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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