backtrader.analyzers.leverage module¶
Leverage Analyzer Module - Gross leverage calculation.
This module provides the GrossLeverage analyzer for calculating the gross leverage (ratio of used capital to portfolio value).
- Classes:
GrossLeverage: Analyzer that calculates gross leverage.
示例
>>> cerebro = bt.Cerebro()
>>> cerebro.addanalyzer(bt.analyzers.GrossLeverage, _name='lev')
>>> results = cerebro.run()
>>> print(results[0].analyzers.lev.get_analysis())
- class backtrader.analyzers.leverage.GrossLeverage[源代码]¶
基类:
AnalyzerThis analyzer calculates the Gross Leverage of the current strategy on a timeframe basis
Params:
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_analysis
Returns a dictionary with returns as values and the datetime points for each return as keys
- params = (('fund', None),)¶
- __init__(*args, **kwargs)[源代码]¶
Initialize the GrossLeverage analyzer.
- 参数:
*args -- Positional arguments.
**kwargs -- Keyword arguments for analyzer parameters.
- start()[源代码]¶
Initialize the analyzer at the start of the backtest.
Sets the fund mode based on parameters or broker settings.