分析器参考#

年回报率#

class backtrader.analyzers.AnnualReturn(*args, **kwargs)#

This analyzer calculates the AnnualReturns by looking at the beginning and end of the year

Params:

  • (None)

Member Attributes:

  • rets: list of calculated annual returns

  • ret: dictionary (key: year) of annual returns

get_analysis:

  • Returns a dictionary of annual returns (key: year)

Calmar比率#

class backtrader.analyzers.Calmar(*args, **kwargs)#

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 1st 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 None then the compression of the 1st data of 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

回撤#

class backtrader.analyzers.DrawDown(*args, **kwargs)#

This analyzer calculates trading system drawdowns stats such as drawdown values in %s and in dollars, max drawdown in %s and in dollars, drawdown length and drawdown max length

Params:

  • 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 dictionary (with . notation support and subdctionaries) with drawdown stats as values, the following keys/attributes are available:

  • drawdown - drawdown value in 0.xx %

  • moneydown - drawdown value in monetary units

  • len - drawdown length

  • max.drawdown - max drawdown value in 0.xx %

  • max.moneydown - max drawdown value in monetary units

  • max.len - max drawdown length

时间回撤#

PositionsValue *** ** ** ** ** ** ** .. autoclass:: PositionsValue

PyFolio *** ** ** .. autoclass:: PyFolio

LogReturnsRolling *** ** ** ** ** ** ** **

class backtrader.analyzers.LogReturnsRolling(*args, **kwargs)#

This analyzer calculates rolling returns for a given timeframe and compression

Params:

  • timeframe (default: None) If None the timeframe of the 1st 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 None then the compression of the 1st data of the system will be used

  • data (default: None)

    Reference asset to track instead of the portfolio value.

    备注

    this data must have been added to a cerebro instance with addata, resampledata or replaydata

  • firstopen (default: True)

    When tracking the returns of a data the following is done when crossing a timeframe boundary, for example Years:

    • Last close of previous year is used as the reference price to see the return in the current year

    The problem is the 1st calculation, because the data has** no previous** closing price. As such and when this parameter is True the opening price will be used for the 1st calculation.

    This requires the data feed to have an open price (for close the standard [0] notation will be used without reference to a field price)

    Else the initial close will be used.

  • 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 dictionary with returns as values and the datetime points for each return as keys

PeriodStats *** ** ** ** **

class backtrader.analyzers.PeriodStats(*args, **kwargs)#

Calculates basic statistics for given timeframe

Params:

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

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

  • compression (default: 1)

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

    If None then the compression of the 1st data of the system will be used

  • 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 dictionary containing the keys:

  • average

  • stddev

  • positive

  • negative

  • nochange

  • best

  • worst

If the parameter zeroispos is set to True, periods with no change will be counted as positive

Returns * ** ** 你的任务是把reStructuredText文件翻译成中文,同时保留原有的格式,包括链接和图片等内嵌元素。请注意忽略HTML标签和代码块,但需要翻译代码注释。在翻译reStructuredText链接、reStructuredText图片和reStructuredText标题时要小心。事务分析器 **********

VWR#

class backtrader.analyzers.VWR(*args, **kwargs)#

Variability-Weighted Return: Better SharpeRatio with Log Returns

Alias:

  • VariabilityWeightedReturn

See:

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

    If None then the compression of the 1st data of the system will be used

  • tann (default: None)

    Number of periods to use for the annualization (normalization) of the average returns. If None, then standard t values will be used, namely:

    • days: 252

    • weeks: 52

    • months: 12

    • years: 1

  • tau (default: 2.0)

    factor for the calculation (see the literature)

  • sdev_max (default: 0.20)

    max standard deviation (see the literature)

  • 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 dictionary with returns as values and the datetime points for each return as keys

The returned dict contains the following keys:

  • vwr: Variability-Weighted Return