提交
This commit is contained in:
@@ -22,6 +22,7 @@ class PaperBroker:
|
||||
schedule: CostSchedule = field(default_factory=lambda: DEFAULT)
|
||||
enable_costs: bool = True
|
||||
enable_t_plus_1: bool = True
|
||||
is_fund: bool = False # 场内基金(ETF):免印花税/过户费,仅佣金
|
||||
|
||||
cash: float = field(init=False)
|
||||
holdings: float = 0.0 # 可卖数量
|
||||
@@ -49,7 +50,7 @@ class PaperBroker:
|
||||
return None
|
||||
rate = (
|
||||
self.schedule.commission_rate
|
||||
+ self.schedule.transfer_fee_rate
|
||||
+ (0.0 if self.is_fund else self.schedule.transfer_fee_rate)
|
||||
+ self.schedule.slippage_rate
|
||||
) if self.enable_costs else 0.0
|
||||
affordable_qty = self.cash / (price * (1 + rate))
|
||||
@@ -67,7 +68,7 @@ class PaperBroker:
|
||||
|
||||
def _execute_buy(self, ts, price: float, qty: int) -> Fill:
|
||||
if self.enable_costs:
|
||||
fp, comm, tf = buy_cost(price, qty, self.schedule)
|
||||
fp, comm, tf = buy_cost(price, qty, self.schedule, is_fund=self.is_fund)
|
||||
else:
|
||||
fp, comm, tf = price, 0.0, 0.0
|
||||
cost = fp * qty + comm + tf
|
||||
@@ -85,7 +86,7 @@ class PaperBroker:
|
||||
|
||||
def _execute_sell(self, ts, price: float, qty: int) -> Fill:
|
||||
if self.enable_costs:
|
||||
fp, comm, tf, sd = sell_cost(price, qty, self.schedule)
|
||||
fp, comm, tf, sd = sell_cost(price, qty, self.schedule, is_fund=self.is_fund)
|
||||
else:
|
||||
fp, comm, tf, sd = price, 0.0, 0.0, 0.0
|
||||
proceeds = fp * qty - comm - tf - sd
|
||||
|
||||
Reference in New Issue
Block a user