From 158316aebcc0d5332112828c4ad30f3ebafc4d3d Mon Sep 17 00:00:00 2001 From: binz <123@123.com> Date: Wed, 12 Jun 2024 01:34:59 +0800 Subject: [PATCH] =?UTF-8?q?Bug:=20=E4=BF=AE=E5=A4=8Dposition=5Fratio=20>?= =?UTF-8?q?=201=E6=97=B6=E4=BB=93=E4=BD=8D=E8=AE=A1=E7=AE=97=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=BC=BA=E5=A4=B1untradable=5Flist=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trader.py b/trader.py index 277841a..12f6787 100644 --- a/trader.py +++ b/trader.py @@ -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({