backtrader.bokeh.app module

Bokeh Application Core Classes

Provides integration between Backtrader and Bokeh

class backtrader.bokeh.app.FigurePage[源代码]

基类:object

Figure Page

Manages a group of related charts and data sources.

__init__(strategy=None)[源代码]

Initialize a FigurePage.

参数:

strategy -- Strategy instance associated with this figure page.

set_cds_columns_from_df(df)[源代码]

Set CDS columns from DataFrame.

参数:

df -- pandas DataFrame

get_cds_streamdata_from_df(df)[源代码]

Get stream data from DataFrame.

参数:

df -- pandas DataFrame

返回:

Stream data dictionary

返回类型:

dict

get_cds_patchdata_from_series(series)[源代码]

Get patch data from Series.

参数:

series -- pandas Series

返回:

(patch_data, stream_data)

返回类型:

tuple

class backtrader.bokeh.app.Figure[源代码]

基类:object

Single Figure

Wraps a Bokeh figure.

__init__(scheme=None)[源代码]

Initialize a Figure.

参数:

scheme -- Theme/scheme instance for styling the figure.

get_cds_streamdata_from_df(df)[源代码]

Get stream data from DataFrame.

get_cds_patchdata_from_series(series, fill_nan=None)[源代码]

Get patch data from Series.

fill_nan()[源代码]

Return columns that need NaN filling.

class backtrader.bokeh.app.BacktraderBokeh[源代码]

基类:object

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

Create a figure page.

参数:
  • strategy -- Strategy instance

  • filldata -- Whether to fill data

返回:

(figid, figurepage)

返回类型:

tuple

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

返回类型:

int

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

update_figurepage(filter=None)[源代码]

Update figure page.

参数:

filter -- Filter configuration

generate_model_panels()[源代码]

Generate model panels.

返回:

Panel list

返回类型:

list

plot(strategy=None, show=True, filename=None)[源代码]

Bindto strategy and generate static chart.

参数:
  • strategy -- Strategy instance

  • show -- Whether to show chart

  • filename -- Save filename

返回:

Bokeh model or None