backtrader.analyzers.transactions module¶
Transactions Analyzer Module - Transaction logging.
This module provides the Transactions analyzer for recording all transactions (order executions) during backtesting.
- Classes:
Transactions: Analyzer that records transaction history.
示例
>>> cerebro = bt.Cerebro()
>>> cerebro.addanalyzer(bt.analyzers.Transactions, _name='txn')
>>> results = cerebro.run()
>>> print(results[0].analyzers.txn.get_analysis())
- class backtrader.analyzers.transactions.Transactions[源代码]¶
基类:
AnalyzerThis analyzer reports the transactions occurred with each every data in the system
It looks at the order execution bits to create a Position starting from 0 during each next cycle.
The result is used during next to record the transactions
Params:
Headers (default:
True)Add an initial key to the dictionary holding the results with the names of the datas
This analyzer was modeled to facilitate the integration with
pyfolio, and the header names are taken from the samples used for it:'Date', 'amount', 'price', 'sid', 'symbol', 'value'
- - Get_analysis
Returns a dictionary with returns as values and the datetime points for each return as keys
- params = (('headers', False), ('_pfheaders', ('date', 'amount', 'price', 'sid', 'symbol', 'value')))¶
- __init__(*args, **kwargs)[源代码]¶
Initialize the Transactions analyzer.
- 参数:
*args -- Positional arguments.
**kwargs -- Keyword arguments for analyzer parameters.
- start()[源代码]¶
Initialize the analyzer at the start of the backtest.
Sets up the results structure and initializes position tracking for each data feed.