观察者参考#
基准#
- class backtrader.observers.Benchmark(*args, **kwargs)#
This observer stores the returns of the strategy and the return of a reference asset which is one of the datas passed to the system.
Params:
timeframe(default:None) IfNonethen the complete return over the entire backtested period will be reportedcompression(default:None)Only used for sub-day timeframes to for example work on an hourly timeframe by specifying “TimeFrame.Minutes” and 60 as compression
data(default:None)Reference asset to track to allow for comparison.
备注
this data must have been added to a
cerebroinstance withaddata,resampledataorreplaydata._doprenext(default:False)Benchmarking will take place from the point at which the strategy kicks in (i.e.: when the minimum period of the strategy has been met).
Setting this to
Truewill record benchmarking values from the starting point of the data feedsfirstopen(default:False)Keepint it as
Falseensures that the 1st comparison point between the value and the benchmark starts at 0%, because the benchmark will not use its opening price.See the
TimeReturnanalyzer reference for a full explanation of the meaning of the parameterfund(default:None)If
Nonethe 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. Seeset_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
Remember that at any moment of a
runthe current values can be checked by looking at the lines by name at index0.
经纪人#
- class backtrader.observers.Broker(*args, **kwargs)#
This observer keeps track of the current cash amount and portfolio value in the broker (including the cash)
Params: None
经纪人 - 现金#
- class backtrader.observers.Cash(*args, **kwargs)#
This observer keeps track of the current amount of cash in the broker
Params: None
经纪人 - 现值#
- class backtrader.observers.Value(*args, **kwargs)#
This observer keeps track of the current portfolio value in the broker including the cash
Params:
fund(default:None)If
Nonethe 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. Seeset_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
买卖#
- class backtrader.observers.BuySell(*args, **kwargs)#
This observer keeps track of the individual buy/sell orders (individual executions) and will plot them on the chart along the data around the execution price level
- Params:
barplot(default:False) Plot buy signals below the minimum and sell signals above the maximum.If
Falseit will plot on the average price of executions during a barbardist(default:0.0151.5%) Distance to max/min whenbarplotisTrue
回撤#
- class backtrader.observers.DrawDown(*args, **kwargs)#
This observer keeps track of the current drawdown level (plotted) and the maxdrawdown (not plotted) levels
Params:
fund(default:None)If
Nonethe 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. Seeset_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
时间回报 ******.. autoclass:: TimeReturn
交易#
- class backtrader.observers.Trades(*args, **kwargs)#
This observer keeps track of full trades and plot the PnL level achieved when a trade is closed.
A trade is open when a position goes from 0 (or crossing over 0) to X and is then closed when it goes back to 0 (or crosses over 0 in the opposite direction)
- Params:
pnlcomm(def:True)Show net/profit and loss, i.e.: after commission. If set to
Falseif will show the result of trades before commission
对数收益#
- class backtrader.observers.LogReturns(*args, **kwargs)#
This observer stores the log returns of the strategy or a
Params:
timeframe(default:None) IfNonethen the complete return over the entire backtested period will be reportedPass
TimeFrame.NoTimeFrameto consider the entire dataset with no time constraintscompression(default:None)Only used for sub-day timeframes to for example work on an hourly timeframe by specifying “TimeFrame.Minutes” and 60 as compression
fund(default:None)If
Nonethe 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. Seeset_fundmodein the broker documentationSet it to
TrueorFalsefor a specific behavior
Remember that at any moment of a
runthe current values can be checked by looking at the lines by name at index0.
对数收益2 *** ** ** ** **
- class backtrader.observers.LogReturns2(*args, **kwargs)#
Extends the observer LogReturns to show two instruments
基金净值 *** ** ** **
- class backtrader.observers.FundValue(*args, **kwargs)#
This observer keeps track of the current fund-like value
Params: None
基金份额 ******.. 自动类:: FundShares