backtrader.observers.logreturns module

LogReturns Observer Module - Log returns tracking.

This module provides observers for tracking log returns of the strategy or a data feed.

Classes:

LogReturns: Observer that tracks log returns. LogReturns2: Alternative log returns observer.

Example

>>> cerebro = bt.Cerebro()
>>> cerebro.addobserver(bt.observers.LogReturns)
class backtrader.observers.logreturns.LogReturns[source]

Bases: Observer

This observer stores the log returns of the strategy or a

Params:

  • timeframe (default: None) If None then the complete return over the entire backtested period will be reported

    Pass TimeFrame.NoTimeFrame to consider the entire dataset with no time constraints

  • compression (default: None)

    Only used for sub-day timeframes to, for example, work on an hourly timeframe by specifying “TimeFrame.Minutes” and 60 as compression

  • fund (default: None)

    If None, the actual mode of the broker (fundmode - True/False) will be autodetected to decide if the returns are based on the total net asset value or on the fund value. See set_fundmode in the broker documentation

    Set it to True or False for a specific behavior

Remember that at any moment of a run the current values can be checked by looking at the lines by name at index 0.

plotinfo = <backtrader.metabase.plotinfo_obj object>
__init__(*args, **kwargs)

Wrapped __init__ that properly handles observer initialization

next()[source]

Update log return value for the current period.

Gets the log return from the analyzer.

frompackages = ()
packages = ()
class backtrader.observers.logreturns.LogReturns2[source]

Bases: LogReturns

Extends the observer LogReturns to show two instruments

__init__(*args, **kwargs)

Wrapped __init__ that properly handles observer initialization

next()[source]

Update log return values for both data feeds.

Updates logret1 from parent and logret2 for second feed.

frompackages = ()
packages = ()