backtrader.analyzers.sqn module

SQN Analyzer Module - System Quality Number calculation.

This module provides the SQN (System Quality Number) analyzer, defined by Van K. Tharp to categorize trading systems.

Classes:

SQN: Analyzer that calculates System Quality Number.

示例

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

基类:Analyzer

SQN or SystemQualityNumber. Defined by Van K. Tharp to categorize trading systems.

  • 1.6 - 1.9 Below average

  • 2.0 - 2.4 Average

  • 2.5 - 2.9 Good

  • 3.0 - 5.0 Excellent

  • 5.1 - 6.9 Superb

  • 7.0 - Holy Grail?

The formula:

  • SquareRoot(NumberTrades) * Average(TradesProfit) / StdDev(TradesProfit)

The sqn value should be deemed reliable when the number of trades >= 30

- get_analysis

Returns a dictionary with keys "sqn" and "trades" (number of considered trades)

alias = ('SystemQualityNumber',)
create_analysis()[源代码]

Replace default implementation to instantiate an AutoOrderedDict rather than an OrderedDict

start()[源代码]

Initialize the analyzer at the start of the backtest.

Initializes lists to store trade P&L values for SQN calculation.

notify_trade(trade)[源代码]

Collect P&L from closed trades.

参数:

trade -- The trade object that was closed.

stop()[源代码]

Calculate the System Quality Number when backtest ends.

SQN = sqrt(N) * average(P&L) / std(P&L)

The result is stored in self.rets.sqn along with the number of trades in self.rets.trades.