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[源代码]¶
基类:
objectBokeh 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.
- class backtrader.bokeh.Blackly[源代码]¶
基类:
SchemeDark theme.
Dark background with light text, suitable for night use or dark interfaces.
- class backtrader.bokeh.Tradimo[源代码]¶
基类:
BlacklyLight 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[源代码]¶
基类:
objectTab 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)
- 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_datanames(strategy)[源代码]¶
Get names of all data sources in strategy.
- 参数:
strategy -- Strategy instance
- 返回:
List of data source names
- 返回类型:
- backtrader.bokeh.get_strategy_label(strategy)[源代码]¶
Get strategy label.
- 参数:
strategy -- Strategy instance
- 返回:
Strategy label
- 返回类型:
- backtrader.bokeh.sanitize_source_name(name)[源代码]¶
Sanitize data source name, remove illegal characters.
- 参数:
name -- Original name
- 返回:
Sanitized name
- 返回类型:
Subpackages¶
- backtrader.bokeh.live package
- backtrader.bokeh.schemes package
- backtrader.bokeh.tabs package
AnalyzerTabConfigTabLogTabMetadataTabSourceTabLiveTabPerformanceTab- Submodules
- backtrader.bokeh.utils package