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.CtpOptionPremium[源代码]¶
基类:
CommInfoBaseCommission and value rules for explicit premium-style CTP options.
- 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
- open_commission_by_money¶
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
- open_commission_by_volume¶
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
- close_commission_by_money¶
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
- close_commission_by_volume¶
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
- close_today_commission_by_money¶
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
- close_today_commission_by_volume¶
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
- close_yesterday_commission_by_money¶
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
- close_yesterday_commission_by_volume¶
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
- seller_margin_evidence¶
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
- evidence_scope¶
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
- 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.
- backtrader.commissions.ComminfoCtpOptionPremium¶
CtpOptionPremium的别名
- backtrader.commissions.CtpOptionComminfo¶
CtpOptionPremium的别名
- class backtrader.commissions.CtpOptionSellerMarginEvidence[源代码]¶
基类:
objectTyped form of one account-bound seller margin observation.
source_kind='synthetic'is intentionally supported for offline contract tests only. It is retained as provenance and is never inferred from the futuresFixedMargin/MiniMargin/Royaltyfields.- __init__(account_fingerprint, trading_day, connection_generation, instrument_id, exchange_id, hedge_flag, currency, price_basis, expiry, source_hash, expires_at_utc, total_margin, quantity=1.0, source_kind='sdk')¶
- exception backtrader.commissions.OptionAccountingError[源代码]¶
基类:
ValueErrorRaised when option cost or evidence cannot be established safely.
- backtrader.commissions.validate_seller_margin_evidence(evidence, *, expected_scope=None, now=None)[源代码]¶
Validate and normalize an account-bound seller margin observation.