plotter – Strategy plotter

class pyalgotrade.plotter.Subplot

Bases: object

addCallback(label, callback, defaultClass=<class 'pyalgotrade.plotter.LineMarker'>)

Add a callback that will be called on each bar.

Parameters:
  • label (string.) – A name for the series values.
  • callback – A function that receives a pyalgotrade.bar.Bars instance as a parameter and returns a number or None.
addDataSeries(label, dataSeries, defaultClass=<class 'pyalgotrade.plotter.LineMarker'>)

Add a DataSeries to the subplot.

Parameters:
addLine(label, level)

Add a horizontal line to the plot.

Parameters:
  • label (string.) – A label.
  • level (int/float.) – The position for the line.
class pyalgotrade.plotter.InstrumentSubplot(instrument, plotBuySell)

Bases: pyalgotrade.plotter.Subplot

A Subplot responsible for plotting an instrument.

class pyalgotrade.plotter.StrategyPlotter(strat, plotAllInstruments=True, plotBuySell=True, plotPortfolio=True)

Bases: object

Class responsible for plotting a strategy execution.

Parameters:
  • strat (pyalgotrade.strategy.BaseStrategy.) – The strategy to plot.
  • plotAllInstruments (boolean.) – Set to True to get a subplot for each instrument available.
  • plotBuySell (boolean.) – Set to True to get the buy/sell events plotted for each instrument available.
  • plotPortfolio (boolean.) – Set to True to get the portfolio value (shares + cash) plotted.
buildFigure(fromDateTime=None, toDateTime=None)

Builds a matplotlib.figure.Figure with the subplots. Must be called after running the strategy.

Parameters:
  • fromDateTime (datetime.datetime) – An optional starting datetime.datetime. Everything before it won’t get plotted.
  • toDateTime (datetime.datetime) – An optional ending datetime.datetime. Everything after it won’t get plotted.
Return type:

matplotlib.figure.Figure.

getInstrumentSubplot(instrument)

Returns the InstrumentSubplot for a given instrument

Return type:InstrumentSubplot.
getOrCreateSubplot(name)

Returns a Subplot by name. If the subplot doesn’t exist, it gets created.

Parameters:name (string.) – The name of the Subplot to get or create.
Return type:Subplot.
getPortfolioSubplot()

Returns the subplot where the portfolio values get plotted.

Return type:Subplot.
plot(fromDateTime=None, toDateTime=None)

Plots the strategy execution. Must be called after running the strategy.

Parameters:
  • fromDateTime (datetime.datetime) – An optional starting datetime.datetime. Everything before it won’t get plotted.
  • toDateTime (datetime.datetime) – An optional ending datetime.datetime. Everything after it won’t get plotted.

Previous topic

stratanalyzer – Strategy analyzers

Next topic

optimizer – Parallel optimizers

This Page