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[源代码]¶
基类:
AnalyzerSQN 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.
- notify_fee_correction(order, trade, delta, currency)[源代码]¶
Apply a late provider fee to a closed trade's net P&L (iteration 60).
tradealready carries the correctedpnlcomm; the stored value of that closed trade is replaced so the SQN atstopuses it. A trade still open needs nothing (its correctedpnlcommis used when it closes); a trade this analyzer never saw closed (for example one of an earlier process after a restart) is left alone.