backtrader.observers.timereturn module

TimeReturn Observer Module - Time-based returns tracking.

This module provides the TimeReturn observer for tracking strategy returns over different time periods.

Classes:

TimeReturn: Observer that tracks returns over time periods.

示例

>>> cerebro = bt.Cerebro()
>>> cerebro.addobserver(bt.observers.TimeReturn, timeframe=bt.TimeFrame.Days)
class backtrader.observers.timereturn.TimeReturn[源代码]

基类:Observer

This observer stores the returns of the strategy.

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>
plotlines = <backtrader.metabase.plotlines_obj object>
__init__(*args, **kwargs)

Wrapped __init__ that properly handles observer initialization

next()[源代码]

Update the time return value for the current period.

Gets the return value from the analyzer for the current time key.

frompackages = ()
packages = ()