backtrader.commissions package¶
Commission Schemes Module - Predefined commission configurations.
This module provides pre-configured commission schemes for common trading instruments like stocks and futures. These schemes extend the base CommInfoBase with default parameters.
- Classes:
CommInfo: Base commission scheme with percentage-based commission. CommInfoFutures: Futures commission scheme. CommInfoFuturesPerc: Futures with percentage commission. CommInfoFuturesFixed: Futures with fixed commission. CommInfoStocks: Stock commission scheme. CommInfoStocksPerc: Stocks with percentage commission. CommInfoStocksFixed: Stocks with fixed commission.
示例
Setting commission scheme: >>> cerebro = bt.Cerebro() >>> comminfo = bt.commissions.CommInfoStocks(commission=0.001) >>> cerebro.broker.addcommissioninfo(cominfo)
- class backtrader.commissions.CommInfo[源代码]¶
基类:
CommInfoBaseBase commission scheme with percentage-based commission.
- class backtrader.commissions.CommInfoFutures[源代码]¶
基类:
CommInfoBaseFutures commission scheme.
- params = (('stocklike', False),)¶
- class backtrader.commissions.CommInfoFuturesPerc[源代码]¶
-
Futures commission scheme with percentage-based commission.
Commission is calculated as a percentage of the trading volume.
- params = (('commtype', 0),)¶
- class backtrader.commissions.CommInfoFuturesFixed[源代码]¶
-
Futures commission scheme with fixed per-contract commission.
Commission is a fixed amount per contract traded.
- params = (('commtype', 1),)¶
- class backtrader.commissions.CommInfoStocks[源代码]¶
基类:
CommInfoBaseStock commission scheme with stock-like asset behavior.
Uses stock-like margin and position handling.
- params = (('stocklike', True),)¶
- class backtrader.commissions.CommInfoStocksPerc[源代码]¶
-
Stock commission scheme with percentage-based commission.
Commission is calculated as a percentage of the trading volume.
- params = (('commtype', 0),)¶
- class backtrader.commissions.CommInfoStocksFixed[源代码]¶
-
Stock commission scheme with fixed per-share commission.
Commission is a fixed amount per share traded.
- params = (('commtype', 1),)¶
- class backtrader.commissions.OptionPremiumCommInfo[源代码]¶
基类:
CommInfoBasePremium option accounting over neutral, source-bound SDK rule facts.
This class retains Backtrader's ordinary premium, value, PnL and fee math. Contract and fee facts arrive through an SDK-issued
InstrumentExecutionRulesSnapshotscoped to an explicit neutral hedge class and must pass its route-bound currentness check before use. Fee cash calculations additionally require verified currency provenance. The snapshot is accounting evidence, not a write capability. Seller margin remains unavailable until a neutral pre-fee margin fact can be consumed without double counting.- stocklike¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- commtype¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- percabs¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- option_type¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- instrument_key¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- hedge_class¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- execution_rules_snapshot_port¶
Advanced parameter descriptor with type checking and validation.
This descriptor replaces the metaclass-based parameter system with a more modern and maintainable approach. It provides:
Automatic type checking and conversion
Value validation
Default value handling
Documentation support
Python 3.6+ __set_name__ support
- refresh_execution_rules_snapshot()[源代码]¶
Explicitly replace the pinned snapshot through its selected SDK port.
- 返回类型:
None
- getoperationcost(size, price, is_buy=None, *, side=None, role='open')[源代码]¶
Return premium cost or an approved opening seller margin.
Return the premium transaction value for any execution side.
Opening short risk uses a separately sourced margin value in
getoperationcost(). A broker fill's executed value is always the traded premium, regardless of whether that fill opens or closes a long or short position.
- cashadjust(size, price, newprice)[源代码]¶
Premium-style options settle through execution; no mark cash flow.
- get_margin(price)[源代码]¶
Returns the actual margin/guarantees needed for a single item of the asset at the given price. The default implementation has this policy:
Use param
marginif paramautomarginevaluates toFalseUse param
mult*priceifautomargin < 0Use param
automargin*priceifautomargin > 0
- exception backtrader.commissions.OptionAccountingError[源代码]¶
基类:
ValueErrorRaised when option accounting facts are missing or inconsistent.