backtrader.analyzers.periodstats module¶
Period Statistics Analyzer Module - Basic statistics by period.
This module provides the PeriodStats analyzer for calculating basic statistics (average, standard deviation, etc.) for a given timeframe.
- Classes:
PeriodStats: Analyzer that calculates period statistics.
示例
>>> cerebro = bt.Cerebro()
>>> cerebro.addanalyzer(bt.analyzers.PeriodStats, _name='stats')
>>> results = cerebro.run()
>>> print(results[0].analyzers.stats.get_analysis())
- class backtrader.analyzers.periodstats.PeriodStats[源代码]¶
基类:
AnalyzerCalculates basic statistics for given timeframe
Params:
timeframe(default:Years) IfNonethetimeframeof the first data in the system will be usedPass
TimeFrame.NoTimeFrameto consider the entire dataset with no time constraintscompression(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 first data in 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_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
get_analysisreturns a dictionary containing the keys:averagestddevpositivenegativenochangebestworst
If the parameter
zeroisposis set toTrue, periods with no change will be counted as positive- params = (('timeframe', 8), ('compression', 1), ('zeroispos', False), ('fund', None))¶