backtrader.bokeh package

Backtrader Bokeh Module

Provides Bokeh-based live plotting functionality, including: - Real-time data push and chart updates - Extensible tab system - Navigation controls (pause/play/forward/backward) - Theme system (black/white themes) - Memory optimization (lookback control)

Example

import backtrader as bt from backtrader.bokeh import LivePlotAnalyzer, Blackly

cerebro = bt.Cerebro() cerebro.adddata(data) cerebro.addstrategy(MyStrategy)

# Add live plot analyzer cerebro.addanalyzer(LivePlotAnalyzer,

scheme=Blackly(), lookback=100)

cerebro.run()

class backtrader.bokeh.Scheme[source]

Bases: object

Bokeh plotting theme base class.

Defines all plotting-related style parameters. Subclasses can customize styles by overriding the _set_params method.

Attribute categories: - Color configuration: barup, bardown, volup, voldown, etc. - Background configuration: background_fill, body_background_color, etc. - Grid configuration: grid_line_color, etc. - Text configuration: axis_text_color, etc. - Crosshair: crosshair_line_color, etc. - Chart configuration: plot_sizing_mode, plot_height, etc.

__init__()[source]

Initialize the scheme with default parameters.

get_color(name, default=None)[source]

Get color configuration.

Parameters:
  • name – Color name

  • default – Default value

Returns:

Color value

set_color(name, value)[source]

Set color configuration.

Parameters:
  • name – Color name

  • value – Color value

copy()[source]

Create a copy of the theme.

Returns:

New theme instance

class backtrader.bokeh.Blackly[source]

Bases: Scheme

Dark theme.

Dark background with light text, suitable for night use or dark interfaces.

class backtrader.bokeh.Tradimo[source]

Bases: Blackly

Light theme.

Light background with dark text, suitable for daytime use or light interfaces. Inherits from Blackly to maintain consistent parameter structure.

class backtrader.bokeh.BokehTab[source]

Bases: object

Tab base class.

Abstract base class for creating custom tabs. Subclasses must implement _is_useable and _get_panel methods.

_app

BacktraderBokeh application instance

_figurepage

Figure page instance

_client

Client instance (optional, for live mode)

_panel

Bokeh Panel instance

Example

class MyCustomTab(BokehTab):
def _is_useable(self):

return True

def _get_panel(self):

from bokeh.models import Div div = Div(text=’<h1>My Content</h1>’) return div, ‘My Tab’

__init__(app, figurepage, client=None)[source]

Initialize tab.

Parameters:
  • app – BacktraderBokeh application instance

  • figurepage – Figure page instance

  • client – Client instance (optional)

is_useable()[source]

Public interface: Check if tab is useable.

Returns:

Whether tab is useable

Return type:

bool

get_panel()[source]

Public interface: Get Bokeh Panel.

Returns:

Bokeh Panel instance

Return type:

Panel

property strategy

Get strategy instance.

property scheme

Get theme instance.

backtrader.bokeh.register_tab(tab_class)[source]

Register a custom tab.

Parameters:

tab_class – Tab class that inherits from BokehTab

backtrader.bokeh.get_registered_tabs()[source]

Get all registered custom tabs.

backtrader.bokeh.get_datanames(strategy)[source]

Get names of all data sources in strategy.

Parameters:

strategy – Strategy instance

Returns:

List of data source names

Return type:

list

backtrader.bokeh.get_strategy_label(strategy)[source]

Get strategy label.

Parameters:

strategy – Strategy instance

Returns:

Strategy label

Return type:

str

backtrader.bokeh.sanitize_source_name(name)[source]

Sanitize data source name, remove illegal characters.

Parameters:

name – Original name

Returns:

Sanitized name

Return type:

str

Subpackages

Submodules