交易成本模型¶
台股手續費、證交稅和選用的滑價,套用在每一筆模擬成交上。
cjtrade.pkgs.models.cost
¶
Transaction cost model for Taiwan Stock Exchange.
Cost components: - Commission (手續費): 0.1425% per side, minimum NT$20, with broker discount - Transaction tax (證交稅): 0.3% on SELL only (0.1% for ETFs, symbol starts with "0") - Slippage: optional price adjustment to simulate market impact
Usage::
from cjtrade.pkgs.models.cost import CostModel
# Default: full-rate commission, standard tax, no slippage
cm = CostModel()
# Online broker at 六折 discount, with 0.05% slippage
cm = CostModel(commission_discount=0.6, slippage_model="fixed_pct", slippage_pct=0.0005)
CostModel(commission_rate=0.001425, commission_discount=1.0, min_commission=20.0, stock_tax_rate=0.003, etf_tax_rate=0.001, slippage_model='none', slippage_pct=0.0005)
dataclass
¶
Parametrisable transaction-cost model for Taiwan stock trading.
Attributes:
| Name | Type | Description |
|---|---|---|
commission_rate |
float
|
Statutory maximum rate: 0.1425% per side. |
commission_discount |
float
|
Broker discount multiplier (1.0 = no discount; 0.6 = 六折). |
min_commission |
float
|
Minimum charge per order in TWD (default NT$20). |
stock_tax_rate |
float
|
Transaction tax (證交稅) applied on SELL for ordinary stocks (0.3%). |
etf_tax_rate |
float
|
Transaction tax on SELL for ETFs (0.1%; symbols starting with |
slippage_model |
'none' | 'fixed_pct' | 'fixed_tick'
|
|
slippage_pct |
float
|
Fractional slippage per side (used only when
|
effective_rate()
¶
Return the commission rate after applying the broker discount.
Source code in src/cjtrade/pkgs/models/cost.py
75 76 77 | |
calc_commission(value)
¶
Return the commission for a trade of value TWD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Notional of the trade. |
required |
Returns:
| Type | Description |
|---|---|
float
|
At least |
Source code in src/cjtrade/pkgs/models/cost.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
calc_tax(value, side, symbol)
¶
Return transaction tax for a trade. Zero for BUY; non-zero for SELL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Notional of the trade. |
required |
side
|
str
|
Only |
required |
symbol
|
str
|
Symbols starting with |
required |
Returns:
| Type | Description |
|---|---|
float
|
Rounded to 2 decimals. |
Source code in src/cjtrade/pkgs/models/cost.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
apply_slippage(price, side)
¶
Return price adjusted for slippage (adverse to the trader).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
price
|
float
|
Unadjusted price. |
required |
side
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
float
|
Unchanged for |
Source code in src/cjtrade/pkgs/models/cost.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
buy_total(price, qty, symbol='')
¶
Return (adj_price, notional, commission, tax) for a BUY.
tax is always 0.0 for BUY; included for API symmetry.
notional is computed from the slippage-adjusted adj_price.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
price
|
float
|
Unadjusted price. |
required |
qty
|
int
|
Number of shares. |
required |
symbol
|
str
|
Unused for BUY; accepted for symmetry with |
''
|
Source code in src/cjtrade/pkgs/models/cost.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
sell_total(price, qty, symbol='')
¶
Return (adj_price, notional, commission, tax) for a SELL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
price
|
float
|
Unadjusted price. |
required |
qty
|
int
|
Number of shares. |
required |
symbol
|
str
|
Decides the tax rate (see |
''
|
Source code in src/cjtrade/pkgs/models/cost.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |