Bug: 修正继续回测时最新数据无法获取到的问题 (#9)

This commit is contained in:
binz 2024-05-29 21:37:41 +08:00
parent 74612e5f6e
commit 3c060ed434
2 changed files with 9 additions and 0 deletions

View File

@ -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())

View File

@ -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):
"""
计算个股仓位