Skip to content

Commit eaca031

Browse files
committed
Add dividend tax rate configuration and update StockPosition handling
- Introduced `dividend_tax_rate` configuration in `__init__.py` to support fixed tax rate for dividends. - Updated `AccountMod` to assign `dividend_tax_rate` to `StockPosition`, ensuring proper handling of dividend taxation. - Adjusted dividend calculation in `StockPosition` to account for the new tax rate, enhancing accuracy in financial computations.
1 parent 68fce95 commit eaca031

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

rqalpha/mod/rqalpha_mod_sys_accounts/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"stock_t1": True,
2222
# 是否开启自动分红再投资
2323
"dividend_reinvestment": False,
24+
# 红利税,暂只支持固定税率
25+
"dividend_tax_rate": 0.0,
2426
# 当持仓股票退市时,是否按照退市价格返还现金
2527
"cash_return_by_stock_delisted": True,
2628
# 股票下单因资金不足被拒时改为使用全部剩余资金下单

rqalpha/mod/rqalpha_mod_sys_accounts/mod.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def start_up(self, env, mod_config):
3535
# type: (Environment, Any) -> None
3636

3737
StockPosition.dividend_reinvestment = mod_config.dividend_reinvestment
38+
StockPosition.dividend_tax_rate = mod_config.dividend_tax_rate
3839
StockPosition.cash_return_by_stock_delisted = mod_config.cash_return_by_stock_delisted
3940
StockPosition.t_plus_enabled = mod_config.stock_t1
4041

rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class StockPosition(Position):
5151
__instrument_types__ = INST_TYPE_IN_STOCK_ACCOUNT
5252

5353
dividend_reinvestment = False
54+
dividend_tax_rate: float = 0.
5455
cash_return_by_stock_delisted = True
5556
t_plus_enabled = True
5657

@@ -202,7 +203,7 @@ def _handle_dividend_book_closure(self, trading_date, data_proxy):
202203
dividends = self._get_dividends_or_splits(self._all_dividends, trading_date, "ex_dividend_date") # type: ignore[reportIncompatibleVariableOverride]
203204
if dividends is None or len(dividends) == 0:
204205
return
205-
dividend_per_share: float = (dividends["dividend_cash_before_tax"] / dividends["round_lot"]).sum()
206+
dividend_per_share: float = (dividends["dividend_cash_before_tax"] / dividends["round_lot"]).sum() * (1 - self.dividend_tax_rate)
206207
self._avg_price -= dividend_per_share
207208
# 前一天结算发生了除息, 此时 last_price 还是前一个交易日的收盘价,需要改为 除息后收盘价, 否则影响在before_trading中查看盈亏
208209
self._last_price -= dividend_per_share # type: ignore

0 commit comments

Comments
 (0)