Bug: 修复position_ratio > 1时仓位计算函数缺失untradable_list导致计算错误的问题

This commit is contained in:
binz 2024-06-12 01:34:59 +08:00
parent 10e926bf28
commit 158316aebc
1 changed files with 3 additions and 2 deletions

View File

@ -497,9 +497,10 @@ class Trader(Account):
next_position = pd.DataFrame({'stock_code': next_margin_list + next_normal_list})
next_position['date'] = date
# 融资融券数量
margin_num = len(next_margin_list)
next_position['weight'] = self.get_weight(date, 1 + (margin_num / self.num), next_position)
next_position['weight'] = self.get_weight(date, 1 + (margin_num / self.num), untradable_list, next_position)
next_position['margin_trade'] = 0
next_position = next_position.set_index(['stock_code'])
next_position.loc[next_margin_list, 'margin_trade'] = 1
@ -633,7 +634,7 @@ class Trader(Account):
if cur_pos['weight'].sum() == 0:
pnl = 0
else:
cash = 1 - cur_pos['weight'].sum()
cash = max(0, 1 - cur_pos['weight'].sum())
pnl = ((cur_pos['end_weight'].sum() + cash) / (cur_pos['weight'].sum() + cash)) - 1
self.account *= 1+pnl
self.account_history = self.account_history.append({