backtrader.bokeh.analyzers package

Bokeh analyzers module.

Provides the following analyzers: - LivePlotAnalyzer: Live plotting analyzer - RecorderAnalyzer: Data recording analyzer

class backtrader.bokeh.analyzers.LivePlotAnalyzer[源代码]

基类:Analyzer

Live plotting analyzer.

Provides real-time plotting functionality based on Bokeh Server, including: - WebSocket real-time data push - Pause/resume functionality - Forward/backward navigation - Data lookback control

参数:
  • scheme -- Theme instance, defaults to Tradimo

  • style -- Chart style, 'bar' or 'candle'

  • lookback -- Amount of historical data to retain

  • address -- Server address

  • port -- Server port

  • title -- Title

  • autostart -- Whether to auto-start the server

示例

cerebro.addanalyzer(LivePlotAnalyzer,

scheme=Blackly(), lookback=100, port=8999)

params = (('scheme', None), ('style', 'bar'), ('lookback', 100), ('address', 'localhost'), ('port', 8999), ('title', None), ('autostart', True))
__init__(**kwargs)[源代码]

Initialize live plot analyzer.

参数:

**kwargs -- Keyword arguments overriding default parameters: - scheme: Theme instance (defaults to Tradimo) - style: Chart style ('bar' or 'candle') - lookback: Number of bars to retain in display - address: Server address (default: 'localhost') - port: Server port (default: 8999) - title: Chart title (default: 'Live {StrategyName}') - autostart: Whether to auto-start server (default: True)

start()[源代码]

Start from backtrader.

Starts the Bokeh Server.

stop()[源代码]

Stop from backtrader.

next()[源代码]

Receive new data from backtrader.

Updates all connected clients.

get_analysis()[源代码]

Return analysis results.

返回:

Empty dict (this analyzer is for plotting, does not produce analysis data)

返回类型:

dict

class backtrader.bokeh.analyzers.RecorderAnalyzer[源代码]

基类:Analyzer

Data recording analyzer.

Records OHLCV data and indicator data during strategy execution.

参数:
  • indicators -- Whether to record indicator data

  • observers -- Whether to record observer data

示例

cerebro.addanalyzer(RecorderAnalyzer, indicators=True)

# Get data after running result = cerebro.run() recorder = result[0].analyzers.recorderanalyzer data = recorder.get_analysis()

params = (('indicators', True), ('observers', False))
__init__()[源代码]

Initialize recorder analyzer.

Sets up storage for data sources, indicators, and observers based on parameter configuration.

start()[源代码]

Analyzer start.

next()[源代码]

Record data for each bar.

stop()[源代码]

Analyzer stop.

get_analysis()[源代码]

Return recorded data.

返回:

Dictionary containing data, indicators and observers

返回类型:

OrderedDict

get_dataframe(data_name=None)[源代码]

Convert data to pandas DataFrame.

参数:

data_name -- Data source name, None means first data source

返回:

pandas.DataFrame or None

Submodules