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)

示例

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[源代码]

基类: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__()[源代码]

Initialize the scheme with default parameters.

get_color(name, default=None)[源代码]

Get color configuration.

参数:
  • name -- Color name

  • default -- Default value

返回:

Color value

set_color(name, value)[源代码]

Set color configuration.

参数:
  • name -- Color name

  • value -- Color value

copy()[源代码]

Create a copy of the theme.

返回:

New theme instance

class backtrader.bokeh.Blackly[源代码]

基类:Scheme

Dark theme.

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

class backtrader.bokeh.Tradimo[源代码]

基类: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[源代码]

基类: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

示例

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)[源代码]

Initialize tab.

参数:
  • app -- BacktraderBokeh application instance

  • figurepage -- Figure page instance

  • client -- Client instance (optional)

is_useable()[源代码]

Public interface: Check if tab is useable.

返回:

Whether tab is useable

返回类型:

bool

get_panel()[源代码]

Public interface: Get Bokeh Panel.

返回:

Bokeh Panel instance

返回类型:

Panel

property strategy

Get strategy instance.

property scheme

Get theme instance.

backtrader.bokeh.register_tab(tab_class)[源代码]

Register a custom tab.

参数:

tab_class -- Tab class that inherits from BokehTab

backtrader.bokeh.get_registered_tabs()[源代码]

Get all registered custom tabs.

backtrader.bokeh.get_datanames(strategy)[源代码]

Get names of all data sources in strategy.

参数:

strategy -- Strategy instance

返回:

List of data source names

返回类型:

list

backtrader.bokeh.get_strategy_label(strategy)[源代码]

Get strategy label.

参数:

strategy -- Strategy instance

返回:

Strategy label

返回类型:

str

backtrader.bokeh.sanitize_source_name(name)[源代码]

Sanitize data source name, remove illegal characters.

参数:

name -- Original name

返回:

Sanitized name

返回类型:

str

Subpackages

Submodules