Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
verybadsoldier edited this page Dec 29, 2019 · 15 revisions

Welcome to the backtrader_plotting wiki!

Bokeh Options

The class Bokeh accepts the following options:

  • scheme - a scheme object for rendering
  • filename - output filename
  • plotconfig - a Python dictionary with individual plot options as described below
  • inmemory - do not actually write an output file (plotted objects are returned by the call to cerebro.run)
  • tabs - the tab mode. Available modes single and multi. In single mode all datas and indicators will be placed in one tabe titled Plots. In multi mode they will go into individual tabs titled Datas and Indicators. Nevertheless tab group can still be modified using option plottab

Plotting Options

Available Options: Lots of backtrader's built-in options are supported. A (probably incomplete) list:

  • subplot
  • plotmaster
  • plotname
  • plot/ plotskip
  • plotabove - not supported. Please use plotorder instead.
  • plothlines
  • plotyhlines
  • plotyticks

Addition Parameters: backtrader_plotting also features some extra plotting parameters:

  • plotid - assigns an identifier to a plot object. Used to reference it in the late plot configuration.
  • plottab - name of a tab this object should be plotted to. Allows to define custom tabs. If not provided then objects will be plotted by category (Datas or Indicators). Only allowed for data and indicator object. Does only apply for plot master objects.
  • plotaspectratio - assigns a custom aspect ratio
  • plotorder - an integer defining the order of the objects inside a tab. All objects default to 0. Can only be used on data masters. Objects are ordered with smaller numbers first.

Labels

Every plottable glyph will have a lable which consits of these parts:

{label} ({parameters}) @{datas}

label- Either the classname or the plotname if provided

parameters - a stringified list of the object parameters

datas - a list of all datas this object works on

Plot Configuration

When using backrader_plotting then plotting configuration can be done totally separately from strategy configuration. The plotting can be configured in the code after the backtest finished running like this:

    plotconfig = {
        'id:ind#0': dict(
            subplot=True,
        ),
    }
    b = Bokeh(style='bar', plot_mode='single', scheme=Tradimo(), plotconfig=plotconfig)
    cerebro.plot(b)

plotconfig is a dictionary. Every key is an expression that selects one or more entities which plot configuration has to be configured. Each value is another dictionary with attributes that will be assigned to the selected objects.

The key has to be in one of these formats:

  • id:<plotid> - Selects the entitiy with the specified plotid
  • #:<type>-<n> - Selects the n-th object of type. Type can bei i for indicators, o for observers or d for datas
  • r:<regex> - A regular expression matching the label of one or more objects

Additional Plotting Attributes

plotaspectratio Global aspect ratio can be set on the scheme applying to all figures. Individual aspect ratios for specific figures can be overriden though by setting plotaspectratio on a object. It needs to be applied to a plot master object. It will not hae an effect when applied to a slave object.

Clone this wiki locally