From 3c060ed434113a2f3b41ab4f5ed17edc1ef5ef8c Mon Sep 17 00:00:00 2001 From: binz <123@123.com> Date: Wed, 29 May 2024 21:37:41 +0800 Subject: [PATCH] =?UTF-8?q?Bug:=20=E4=BF=AE=E6=AD=A3=E7=BB=A7=E7=BB=AD?= =?UTF-8?q?=E5=9B=9E=E6=B5=8B=E6=97=B6=E6=9C=80=E6=96=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E5=88=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spread_backtest.py | 2 ++ trader.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/spread_backtest.py b/spread_backtest.py index 3b700c1..86aaaa4 100644 --- a/spread_backtest.py +++ b/spread_backtest.py @@ -20,6 +20,8 @@ class Spread_Backtest(): start: str, end: str ): + # 更新可回测时间 + self.trader.update_avaliable_date() # 确定回测的开始和结束时间 if len(self.trader.account_history) > 0: bkt_start = max(start, self.trader.avaliable_date.index.min(), self.trader.account_history['date'].max()) diff --git a/trader.py b/trader.py index 7c88c6b..8f580cf 100644 --- a/trader.py +++ b/trader.py @@ -190,6 +190,13 @@ class Trader(Account): else: self.today_data['close'] = DataLoader(self.today_data['basic'].data[['close_post']].rename(columns={'close_post':'price'})) + def update_avaliable_date(self): + """ + 更新可执行日期 + """ + # 可执行日期 + self.avaliable_date = pd.Series(index=[f.split('.')[0] for f in os.listdir(self.data_root['basic'])]).sort_index() + def get_weight(self, date, total_weight, next_position): """ 计算个股仓位