This commit is contained in:
2026-09-07 13:34:26 +08:00
parent ad9245abdd
commit 359f9ae2e4
23 changed files with 2260 additions and 513 deletions

View File

@@ -28,20 +28,28 @@ class CostSchedule:
DEFAULT = CostSchedule()
def buy_cost(price: float, qty: float, sch: CostSchedule = DEFAULT) -> tuple[float, float, float]:
"""买入成本。返回 (成交价, 佣金, 过户费)。买入无印花税。"""
def buy_cost(price: float, qty: float, sch: CostSchedule = DEFAULT,
is_fund: bool = False) -> tuple[float, float, float]:
"""买入成本。返回 (成交价, 佣金, 过户费)。买入无印花税。
is_fund=True 为场内基金ETF免过户费仅佣金 + 滑点。
"""
fill_price = price * (1 + sch.slippage_rate)
gross = fill_price * qty
commission = max(gross * sch.commission_rate, sch.commission_min)
transfer_fee = gross * sch.transfer_fee_rate
transfer_fee = 0.0 if is_fund else gross * sch.transfer_fee_rate
return fill_price, commission, transfer_fee
def sell_cost(price: float, qty: float, sch: CostSchedule = DEFAULT) -> tuple[float, float, float, float]:
"""卖出成本。返回 (成交价, 佣金, 过户费, 印花税)。"""
def sell_cost(price: float, qty: float, sch: CostSchedule = DEFAULT,
is_fund: bool = False) -> tuple[float, float, float, float]:
"""卖出成本。返回 (成交价, 佣金, 过户费, 印花税)。
is_fund=True 为场内基金ETF免印花税、免过户费现行规则仅佣金 + 滑点。
"""
fill_price = price * (1 - sch.slippage_rate)
gross = fill_price * qty
commission = max(gross * sch.commission_rate, sch.commission_min)
transfer_fee = gross * sch.transfer_fee_rate
stamp_duty = gross * sch.stamp_duty_rate
transfer_fee = 0.0 if is_fund else gross * sch.transfer_fee_rate
stamp_duty = 0.0 if is_fund else gross * sch.stamp_duty_rate
return fill_price, commission, transfer_fee, stamp_duty