Repository files navigation

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/

Installation

pip install backtrader_plotting

Quickstart

frombacktrader_plottingimportBokehfrombacktrader_plotting.schemesimportTradimo<yourbacktradercode>b=Bokeh(style='bar', plot_mode='single', scheme=Tradimo())
cerebro.plot(b)

Minimal Example

importdatetimeimportbacktraderasbtfrombacktrader_plottingimportBokehclassTestStrategy(bt.Strategy):
params= (
('buydate', 21),
('holdtime', 6),
)
defnext(self):
iflen(self.data) ==self.p.buydate:
self.buy(self.datas[0], size=None)
iflen(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 datefromdate=datetime.datetime(2000, 1, 1),
# Do not pass values after this datetodate=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

About

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

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); })();
Skip to content

Repository files navigation

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/

Installation

pip install backtrader_plotting

Quickstart

frombacktrader_plottingimportBokehfrombacktrader_plotting.schemesimportTradimo<yourbacktradercode>b=Bokeh(style='bar', plot_mode='single', scheme=Tradimo())
cerebro.plot(b)

Minimal Example

importdatetimeimportbacktraderasbtfrombacktrader_plottingimportBokehclassTestStrategy(bt.Strategy):
params= (
('buydate', 21),
('holdtime', 6),
)
defnext(self):
iflen(self.data) ==self.p.buydate:
self.buy(self.datas[0], size=None)
iflen(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 datefromdate=datetime.datetime(2000, 1, 1),
# Do not pass values after this datetodate=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

About

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

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages