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[源代码]

基类:TimeFrameAnalyzerBase

This analyzer calculates the CalmarRatio timeframe which can be different from the one used in the underlying data Params:

  • timeframe (default: None) If None the timeframe of the first data in the system will be used

    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

    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. See set_fundmode in the broker documentation

    Set it to True or False for 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.

on_dt_over()[源代码]

Calculate Calmar ratio when timeframe period ends.

Updates maximum drawdown and calculates Calmar ratio as annualized return divided by maximum drawdown.

stop()[源代码]

Finalize the analysis when backtest ends.

Triggers one final Calmar ratio calculation.