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[源代码]

基类:CommInfoBase

Base commission scheme with percentage-based commission.

class backtrader.commissions.CommInfoFutures[源代码]

基类:CommInfoBase

Futures commission scheme.

params = (('stocklike', False),)
class backtrader.commissions.CommInfoFuturesPerc[源代码]

基类:CommInfoFutures

Futures commission scheme with percentage-based commission.

Commission is calculated as a percentage of the trading volume.

params = (('commtype', 0),)
class backtrader.commissions.CommInfoFuturesFixed[源代码]

基类:CommInfoFutures

Futures commission scheme with fixed per-contract commission.

Commission is a fixed amount per contract traded.

params = (('commtype', 1),)
class backtrader.commissions.CommInfoStocks[源代码]

基类:CommInfoBase

Stock commission scheme with stock-like asset behavior.

Uses stock-like margin and position handling.

params = (('stocklike', True),)
class backtrader.commissions.CommInfoStocksPerc[源代码]

基类:CommInfoStocks

Stock commission scheme with percentage-based commission.

Commission is calculated as a percentage of the trading volume.

params = (('commtype', 0),)
class backtrader.commissions.CommInfoStocksFixed[源代码]

基类:CommInfoStocks

Stock commission scheme with fixed per-share commission.

Commission is a fixed amount per share traded.

params = (('commtype', 1),)
class backtrader.commissions.CtpOptionPremium[源代码]

基类:CommInfoBase

Commission 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

premium_style

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

__init__(**kwargs)[源代码]

Initialize CommInfo object

property seller_margin_source_kind: str | None
property seller_margin_is_synthetic: bool
validate_seller_margin_evidence(*, now=None)[源代码]
参数:

now (datetime | None)

返回类型:

dict[str, Any]

seller_margin_status()[源代码]
返回类型:

str

getoperationcost(size, price, is_buy=None, *, side=None, role='open')[源代码]

Return premium cost or an approved opening seller margin.

getpremiumvalue(size, price)[源代码]

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.

getsize(price, cash)[源代码]

Return buyer quantity using premium plus the complete open fee.

getvaluesize(size, price)[源代码]

Return signed option position value at a mark price.

getvalue(position, price)[源代码]

Return signed position value; shorts remain negative.

profitandloss(size, price, newprice)[源代码]

Return linear signed option PnL.

cashadjust(size, price, newprice)[源代码]

Premium-style options settle through execution; no mark cash flow.

get_margin(price)[源代码]

Return only an explicitly sourced seller margin per contract.

accounting_projection(size, price, *, is_buy=True, role='open')[源代码]

Return a reviewable single-leg projection without changing cash.

返回类型:

dict[str, Any]

backtrader.commissions.ComminfoCtpOptionPremium

CtpOptionPremium 的别名

backtrader.commissions.CtpOptionComminfo

CtpOptionPremium 的别名

class backtrader.commissions.CtpOptionSellerMarginEvidence[源代码]

基类:object

Typed 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 futures FixedMargin/MiniMargin/Royalty fields.

account_fingerprint: str
trading_day: str
connection_generation: int
instrument_id: str
exchange_id: str
hedge_flag: str
currency: str
price_basis: Any
expiry: Any
source_hash: str
expires_at_utc: Any
total_margin: float
quantity: float = 1.0
source_kind: str = 'sdk'
as_mapping()[源代码]

Return a plain mapping suitable for validation and serialization.

返回类型:

dict[str, Any]

__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')
参数:
  • account_fingerprint (str)

  • trading_day (str)

  • connection_generation (int)

  • instrument_id (str)

  • exchange_id (str)

  • hedge_flag (str)

  • currency (str)

  • price_basis (Any)

  • expiry (Any)

  • source_hash (str)

  • expires_at_utc (Any)

  • total_margin (float)

  • quantity (float)

  • source_kind (str)

返回类型:

None

exception backtrader.commissions.OptionAccountingError[源代码]

基类:ValueError

Raised when option cost or evidence cannot be established safely.

__init__(code, message=None)[源代码]
参数:
  • code (str)

  • message (str | None)

backtrader.commissions.validate_seller_margin_evidence(evidence, *, expected_scope=None, now=None)[源代码]

Validate and normalize an account-bound seller margin observation.

参数:
返回类型:

dict[str, Any]

Submodules