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.
Example
>>> cerebro = bt.Cerebro()
>>> cerebro.addobserver(bt.observers.TimeReturn, timeframe=bt.TimeFrame.Days)
- class backtrader.observers.timereturn.TimeReturn[source]¶
Bases:
ObserverThis observer stores the returns of the strategy.
Params:
timeframe(default:None) IfNonethen the complete return over the entire backtested period will be reportedPass
TimeFrame.NoTimeFrameto consider the entire dataset with no time constraintscompression(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_fundmodein the broker documentationSet it to
TrueorFalsefor 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()[source]¶
Update the time return value for the current period.
Gets the return value from the analyzer for the current time key.
- frompackages = ()¶
- packages = ()¶