backtrader.analyzers.calmar module¶
Calmar Ratio Analyzer Module - Calmar ratio calculation.
This module provides the Calmar analyzer for calculating the Calmar ratio (annual return divided by maximum drawdown).
- Classes:
Calmar: Analyzer that calculates Calmar ratio.
示例
>>> cerebro = bt.Cerebro()
>>> cerebro.addanalyzer(bt.analyzers.Calmar, _name='calmar')
>>> results = cerebro.run()
>>> print(results[0].analyzers.calmar.get_analysis())
- class backtrader.analyzers.calmar.Calmar[源代码]¶
-
This analyzer calculates the CalmarRatio timeframe which can be different from the one used in the underlying data Params:
timeframe(default:None) IfNonethetimeframeof the first data in the system will be usedPass
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
If compression is None, then the compression of the first data in the system will be used
None
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. Seeset_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
- - ``get_analysis``
Returns a OrderedDict with a key for the time period and the corresponding rolling Calmar ratio
- - ``calmar`` the latest calculated calmar ratio
- packages = ('collections', 'math')¶
- params = (('timeframe', 7), ('period', 36), ('fund', None))¶
- __init__(*args, **kwargs)[源代码]¶
Initialize the Calmar analyzer.
- 参数:
*args -- Positional arguments.
**kwargs -- Keyword arguments for analyzer parameters.
- start()[源代码]¶
Initialize the analyzer at the start of the backtest.
Sets up the maximum drawdown tracking, value history queue, and fund mode.