Skip to main content

Plotting package for Backtrader (Bokeh)

Project description

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
  • Live trading support (needs custom backtrader - refer to the Wiki for further information)
  • Data replaying support
  • Interactive backtrader optimization result browser (only supported for single-strategy runs)
  • Customziable tab panels
  • Highly configurable
  • Different skinnable themes
  • Easy to use

Needs Python >= 3.6.

Demos

Find runnable function demonstrations in folder demos or try the live demos here: https://verybadsoldier.github.io/backtrader_plotting/

Installation

pip install 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backtrader_plotting-2.0.0.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

backtrader_plotting-2.0.0-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file backtrader_plotting-2.0.0.tar.gz.

File metadata

  • Download URL: backtrader_plotting-2.0.0.tar.gz
  • Upload date:
  • Size: 50.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for backtrader_plotting-2.0.0.tar.gz
Algorithm Hash digest
SHA256 47fb4bc9613dfc85c24be233a4f7de520e53400e91752efc7ba332d00cfc8947
MD5 7b437a0bd539dc46af8d5c2ecc170e2b
BLAKE2b-256 83d359c0fdc438b7f50ed6223c33686d5b77a74744e0d102069bf85387b55d9b

See more details on using hashes here.

File details

Details for the file backtrader_plotting-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: backtrader_plotting-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 60.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for backtrader_plotting-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 424b4571cd79a4ae4521d265bf8174748064fdf54a702c882ccd02e0ac29ee4d
MD5 f937612545d460ed02ae6d07a07a5e7c
BLAKE2b-256 d54468f488afdbe8a1d4612da2e2781fb698a3855f44b98b5549c151d79a8d42

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page