Skip to main content

backtrader_plotting

Plotting addon for backtrader to support Bokeh (and maybe more).

This is in an early development state. Expect bugs, heavy restructuring and commit reordering. Currently this is Python >=3.6 only.

Feel free to test it and play with it. I am happy about feedback, critics and ideas: https://community.backtrader.com/topic/813/bokeh-integration-interactive-webbrowser-plotting

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 invoke Bokeh.plot_result. This function also supports passing a cerebro result object as it is generated in optimization:

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

This will start a Bokeh application (standalone webserver) displaying all optimization results.

NOTE: When using this feature with optreturn=True then your package of backtrader has to contain this change of mine: https://github.com/verybadsoldier/backtrader/commit/f03a0ed115338ed8f074a942f6520b31c630bcfb

Metadata

Release files for backtrader-plotting 0.5.3

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 0.5.3
File Size Uploaded Provenance Actions
backtrader_plotting-0.5.3.tar.gz 19.6 kB Without provenance Details for backtrader_plotting-0.5.3.tar.gz

Built distribution (wheel)

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

Total release size: 47.4 kB

Release files / backtrader_plotting-0.5.3.tar.gz

Download URL backtrader_plotting-0.5.3.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ae1319a57bbc8026aadd42013da5c24ef0ea999ca7245f654d4d00837be33e6c
BLAKE2b-256 checksum
How to use checksums
84e96493ec0b2a014e2feac4c4fd130c24d5bc9150fe63fdf70e3a6cb6864016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

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

Download URL backtrader_plotting-0.5.3-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d07085ae985ca445abc3b76f2c50a815db98ace5ff9814ea46e5b8879b7c366
BLAKE2b-256 checksum
How to use checksums
9859021fc7a07caf17080a25bd2405e75413117d81fe5d07077b19ac92bc0e9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

Security for backtrader-plotting 0.5.3

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