backtrader.commissions 源代码
#!/usr/bin/env python
"""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.
Example:
Setting commission scheme:
>>> cerebro = bt.Cerebro()
>>> comminfo = bt.commissions.CommInfoStocks(commission=0.001)
>>> cerebro.broker.addcommissioninfo(cominfo)
"""
from ..comminfo import CommInfoBase
[文档]
class CommInfo(CommInfoBase):
"""Base commission scheme with percentage-based commission."""
pass # clone of CommissionInfo but with xx% instead of 0.xx
[文档]
class CommInfoFutures(CommInfoBase):
"""Futures commission scheme."""
params = (("stocklike", False),)
[文档]
class CommInfoFuturesPerc(CommInfoFutures):
"""Futures commission scheme with percentage-based commission.
Commission is calculated as a percentage of the trading volume.
"""
params = (("commtype", CommInfoBase.COMM_PERC),)
[文档]
class CommInfoFuturesFixed(CommInfoFutures):
"""Futures commission scheme with fixed per-contract commission.
Commission is a fixed amount per contract traded.
"""
params = (("commtype", CommInfoBase.COMM_FIXED),)
[文档]
class CommInfoStocks(CommInfoBase):
"""Stock commission scheme with stock-like asset behavior.
Uses stock-like margin and position handling.
"""
params = (("stocklike", True),)
[文档]
class CommInfoStocksPerc(CommInfoStocks):
"""Stock commission scheme with percentage-based commission.
Commission is calculated as a percentage of the trading volume.
"""
params = (("commtype", CommInfoBase.COMM_PERC),)
[文档]
class CommInfoStocksFixed(CommInfoStocks):
"""Stock commission scheme with fixed per-share commission.
Commission is a fixed amount per share traded.
"""
params = (("commtype", CommInfoBase.COMM_FIXED),)