Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rqalpha/mod/rqalpha_mod_sys_accounts/position_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def before_trading(self, trading_date):
raise RuntimeError("direction of stock position {} is not supposed to be short".format(self._order_book_id))
data_proxy = self._env.data_proxy
self._daily_dividend = self._handle_dividend_book_closure(trading_date, data_proxy)
delta_cash += self._handle_dividend_payable(trading_date)
# 需要先执行拆股后再执行分红支付操作,否则当开启分红再投资时,会将当日到账的票也进行拆股
self._daily_split = self._handle_split(trading_date, data_proxy)
delta_cash += self._handle_dividend_payable(trading_date)
return delta_cash

def apply_trade(self, trade):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,42 @@ def after_trading(context):

run_func(config=config, init=init, open_auction=open_auction, handle_bar=handle_bar, after_trading=after_trading)


def test_dividend_reinvestment_and_splits_on_the_same_day():
"""
测试分红再投资和拆股行为在同一天时的逻辑,只要测试点为:在当日分红再投资买入的票不应当参与拆股
"""
config = _config({
"base": {
"start_date": "2017-02-01",
"end_date": "2017-03-10",
"frequency": "1d",
"accounts": {
"stock": 10000000
},
},
"extra": {
"log_level": "error",
},
"mod": {
"sys_accounts": {
"dividend_reinvestment": True
}
}
})

def init(context):
context.s1 = "600816.XSHG"
context.fired = False

def handle_bar(context, bar_dict):
if not context.fired:
order_shares(context.s1, 10000)
context.fired = True
assert get_position(context.s1).quantity == 10000
if context.now.date() == date(2017, 3, 6):
# 1. 每 1 股拆为 2.2 股
# 2. 每 10 股分现金 6 元,总共分 6000 元,再投资买入 400 股
assert get_position(context.s1).quantity == 22400

run_func(config=config, init=init, handle_bar=handle_bar)
Loading