backtrader.observers.broker module¶
Broker Observer Module - Cash and value tracking.
This module provides observers for tracking broker cash and portfolio value.
- Classes:
Cash: Observer that tracks current cash level. Value: Observer that tracks portfolio value.
示例
>>> cerebro = bt.Cerebro()
>>> cerebro.addobserver(bt.observers.Broker)
- class backtrader.observers.broker.Cash[源代码]¶
基类:
ObserverThis observer keeps track the current amount of cash in the broker
Params: None
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- next()[源代码]¶
Update the cash value for the current period.
Gets current cash amount from the broker.
- frompackages = ()¶
- packages = ()¶
- class backtrader.observers.broker.Value[源代码]¶
基类:
ObserverThis observer keeps track of the current portfolio value in the broker including the cash
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
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- __init__(*args, **kwargs)¶
Wrapped __init__ that properly handles observer initialization
- start()[源代码]¶
Start the Value observer and determine fund mode.
Detects or sets fund mode for value calculation.
- next()[源代码]¶
Update the portfolio value for the current period.
Gets value from broker based on fund mode setting.
- frompackages = ()¶
- packages = ()¶
- class backtrader.observers.broker.Broker[源代码]¶
基类:
ObserverThis observer keeps track of the current cash amount and portfolio value in the broker (including the cash)
Params: None
- alias = ('CashValue',)¶
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- __init__(*args, **kwargs)¶
Wrapped __init__ that properly handles observer initialization
- start()[源代码]¶
Start the Broker observer and configure plotting.
Determines fund mode and configures plot settings.
- next()[源代码]¶
Update cash and value for the current period.
Gets current cash and portfolio value from the broker.
- frompackages = ()¶
- packages = ()¶
- class backtrader.observers.broker.FundValue[源代码]¶
基类:
ObserverThis observer keeps track of the current fund-like value
Params: None
- alias = ('FundShareValue', 'FundVal')¶
- plotinfo = <backtrader.metabase.plotinfo_obj object>¶
- frompackages = ()¶
- packages = ()¶
基类:
ObserverThis observer keeps track of the current fund-like shares
Params: None
Update the fund shares for the current period.
Gets current fund shares from the broker.