Plotting package for Backtrader (Bokeh, Plotly)
Project description
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file backtrader_plotting-0.4.tar.gz.
File metadata
- Download URL: backtrader_plotting-0.4.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02c8cb4cb979bea59bdedc3c43f07cc63be5393fd524fcd2e9eb8ffd819e120c
|
|
| MD5 |
408bdf0d4c1184d04bf311ae88332ba4
|
|
| BLAKE2b-256 |
2ab10c886456e38a91fd8fa69e0546b525f533f2795d93114ad9b3f25f6cf4f3
|
File details
Details for the file backtrader_plotting-0.4-py3-none-any.whl.
File metadata
- Download URL: backtrader_plotting-0.4-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beb7aad22e56c6c8596fd0d7140c2dd2f944dddd1fa83faf85eba85edc77c6a0
|
|
| MD5 |
152d719f5659d852a343d5d385aa9a42
|
|
| BLAKE2b-256 |
eb7daf6a572089507c33d979b08613a339f47abe3938da25b1532af3c24d006a
|