backtrader.bokeh.app module¶
Bokeh Application Core Classes
Provides integration between Backtrader and Bokeh
- class backtrader.bokeh.app.FigurePage[源代码]¶
基类:
objectFigure Page
Manages a group of related charts and data sources.
- __init__(strategy=None)[源代码]¶
Initialize a FigurePage.
- 参数:
strategy -- Strategy instance associated with this figure page.
- class backtrader.bokeh.app.Figure[源代码]¶
基类:
objectSingle Figure
Wraps a Bokeh figure.
- class backtrader.bokeh.app.BacktraderBokeh[源代码]¶
基类:
objectBacktrader Bokeh Application
Provides the following features: - Create and manage figure pages - Generate Bokeh models - Data processing and formatting
- 参数:
style -- Chart style, 'bar' or 'candle'
scheme -- Theme instance
use_default_tabs -- Whether to use default tabs
filter -- Data filter configuration
示例
app = BacktraderBokeh(style='candle', scheme=Blackly()) figid, figurepage = app.create_figurepage(strategy) panels = app.generate_model_panels()
- params = (('style', 'bar'), ('scheme', None), ('use_default_tabs', True), ('filter', None))¶
- __init__(**kwargs)[源代码]¶
Initialize BacktraderBokeh application.
- 参数:
**kwargs -- Keyword arguments for configuration: - style: Chart style ('bar' or 'candle') - scheme: Theme instance for styling - use_default_tabs: Whether to use default tabs - filter: Data filter configuration
- create_figurepage(strategy, filldata=True, start=None, end=None, preserveidx=False, fill_gaps=False)[源代码]¶
Create a figure page.
- 参数:
strategy -- Strategy instance
filldata -- Whether to fill data
start -- Start index for data slicing
end -- End index for data slicing
preserveidx -- Keep original index values in source
fill_gaps -- Unused currently, for future compatibility
- 返回:
(figid, figurepage)
- 返回类型:
- get_figurepage(figid)[源代码]¶
Get figure page.
- 参数:
figid -- Figure page ID
- 返回:
FigurePage instance or None
- get_last_idx(figid)[源代码]¶
Get last data index of figure page.
- 参数:
figid -- Figure page ID
- 返回:
Last index
- 返回类型:
- generate_data(figid=None, start=None, end=None, back=None, preserveidx=False, fill_gaps=False)[源代码]¶
Generate chart data.
- 参数:
figid -- Figure page ID
start -- Start index
end -- End index
back -- Number of bars to look back
preserveidx -- Whether to preserve original index
fill_gaps -- Whether to fill gaps
- 返回:
pandas.DataFrame
- build_model(figurepages=None)[源代码]¶
Build a bokeh model from figure pages.
- 参数:
figurepages -- Iterable of (figid, figurepage) tuples. Defaults to all.
- 返回:
Tabs model or None
- build_full_model(figurepage=None, figurepages=None)[源代码]¶
Build a Tabs model with chart panels plus the extra tabs.
Extra tabs (Performance/Analyzer/Metadata/Config/Log/Source) are attached to a single figure page. This is the reusable build path used by both
plot()and the cerebro-compatibleBokehPlotadapter; it performs no display and writes no file.- 参数:
figurepage -- FigurePage to attach the extra tabs to. If
None, the most recently created figure page is used, or the extra tabs are skipped when no figure page exists.figurepages -- Iterable of
(figid, figurepage)tuples for the chart panels. Defaults to all accumulated figure pages.
- 返回:
Bokeh
Tabsmodel, orNoneif bokeh is unavailable or no panels could be generated.