backtrader.analyzers.vwr module

VWR Analyzer Module - Variability-Weighted Return calculation.

This module provides the VWR (Variability-Weighted Return) analyzer, an alternative to the Sharpe ratio using log returns.

Classes:

VWR: Analyzer that calculates VWR metric.

示例

>>> cerebro = bt.Cerebro()
>>> cerebro.addanalyzer(bt.analyzers.VWR, _name='vwr')
>>> results = cerebro.run()
>>> print(results[0].analyzers.vwr.get_analysis())
class backtrader.analyzers.vwr.VWR[源代码]

基类:TimeFrameAnalyzerBase

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 first data in 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

params = (('tann', None), ('tau', 0.2), ('sdev_max', 2.0), ('fund', None))
__init__(*args, **kwargs)[源代码]

Initialize the VWR analyzer.

参数:
  • *args -- Positional arguments.

  • **kwargs -- Keyword arguments for analyzer parameters.

start()[源代码]

Initialize the analyzer at the start of the backtest.

Sets the fund mode and initializes lists to track period start and end values.

stop()[源代码]

Calculate the VWR metric when backtest ends.

VWR = rnorm100 * (1 - (sdev_p / sdev_max)^tau) where sdev_p is the standard deviation of period returns.

notify_fund(cash, value, fundvalue, shares)[源代码]

Update the current period end value from fund notification.

参数:
  • cash -- Current cash amount.

  • value -- Current portfolio value.

  • fundvalue -- Current fund value.

  • shares -- Number of fund shares.

on_dt_over()[源代码]

Handle timeframe boundary crossing.

Moves the current period end value to be the next period's start value and creates a new placeholder.

backtrader.analyzers.vwr.VariabilityWeightedReturn

VWR 的别名