TradeRecorder#

tradingstrategy.frameworks.backtrader.TradeRecorder Python class in Trading Strategy framework.

class TradeRecorder[source]#

Bases: Analyzer

Record all trades during the backtest run so that they can be analysed.

__init__()#

Methods

__init__()

create_analysis()

Meant to be overriden by subclasses.

get_analysis()

Returns a dict-like object with the results of the analysis

next()

Invoked for each next invocation of the strategy, once the minum preiod of the strategy has been reached

nextstart()

Invoked exactly once for the nextstart invocation of the strategy, when the minimum period has been first reached

notify_cashvalue(cash, value)

Receives the cash/value notification before each next cycle

notify_fund(cash, value, fundvalue, shares)

Receives the current cash, value, fundvalue and fund shares

notify_order(order)

Receives order notifications before each next cycle

notify_trade(trade)

Receives trade notifications before each next cycle

pprint(*args, **kwargs)

Prints the results returned by get_analysis using the pretty print Python module (pprint)

prenext()

Invoked for each prenext invocation of the strategy, until the minimum period of the strategy has been reached

print(*args, **kwargs)

Prints the results returned by get_analysis via a standard Writerfile object, which defaults to writing things to standard output

start()

Invoked to indicate the start of operations, giving the analyzer time to setup up needed things

stop()

Invoked to indicate the end of operations, giving the analyzer time to shut down needed things

Attributes

csv

frompackages

packages

create_analysis()[source]#

Meant to be overriden by subclasses. Gives a chance to create the structures that hold the analysis.

The default behaviour is to create a OrderedDict named rets

stop()[source]#

Invoked to indicate the end of operations, giving the analyzer time to shut down needed things

notify_trade(trade)[source]#

Receives trade notifications before each next cycle

Parameters:

trade (Trade) –

get_analysis()[source]#

Returns a dict-like object with the results of the analysis

The keys and format of analysis results in the dictionary is implementation dependent.

It is not even enforced that the result is a dict-like object, just the convention

The default implementation returns the default OrderedDict rets created by the default create_analysis method

Return type:

dict