1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-18 18:04:31 +08:00

fix exchange bug

This commit is contained in:
wangwenxi.handsome
2021-08-15 14:17:26 +00:00
committed by you-n-g
parent f67b99a30e
commit 222c2fd21a
2 changed files with 23 additions and 22 deletions

View File

@@ -116,7 +116,7 @@ class PandasQuote(BaseQuote):
raise ValueError(f"fields must be None, str or list") raise ValueError(f"fields must be None, str or list")
def _if_single_data(self, start_time, end_time): def _if_single_data(self, start_time, end_time):
if end_time - start_time < np.timedelta64(1, 'm'): if end_time - start_time < np.timedelta64(1, "m"):
return True return True
if start_time.hour == 11 and start_time.minute == 29 and start_time.second == 0: if start_time.hour == 11 and start_time.minute == 29 and start_time.second == 0:
return True return True
@@ -152,10 +152,10 @@ class NumpyQuote(BaseQuote):
# lru # lru
self.muti_lru = {} self.muti_lru = {}
self.max_lru_len = 256
def _to_numpy(self, quote_df): def _to_numpy(self, quote_df):
"""convert dataframe to numpy. """convert dataframe to numpy."""
"""
quote_dict = {} quote_dict = {}
date_dict = {} date_dict = {}
date_list = {} date_list = {}
@@ -187,8 +187,8 @@ class NumpyQuote(BaseQuote):
# get muti row data # get muti row data
else: else:
# check lru # check lru
if (start_time, end_time, fields, method) in self.muti_lru: if (stock_id, start_time, end_time, fields, method) in self.muti_lru:
return self.muti_lru[(start_time, end_time, fields, method)] return self.muti_lru[(stock_id, start_time, end_time, fields, method)]
start_id = bisect.bisect_left(self.dates_list[stock_id], start_time) start_id = bisect.bisect_left(self.dates_list[stock_id], start_time)
end_id = bisect.bisect_right(self.dates_list[stock_id], end_time) end_id = bisect.bisect_right(self.dates_list[stock_id], end_time)
@@ -196,16 +196,17 @@ class NumpyQuote(BaseQuote):
return None return None
# it used for check if data is None # it used for check if data is None
if fields is None: if fields is None:
return self.data[stock_id][start_id: end_id] return self.data[stock_id][start_id:end_id]
agg_stock_data = self._agg_data(self.data[stock_id][start_id: end_id, self.columns[fields]], method) agg_stock_data = self._agg_data(self.data[stock_id][start_id:end_id, self.columns[fields]], method)
# result lru # result lru
self.muti_lru[(start_time, end_time, fields, method)] = agg_stock_data if len(self.muti_lru) >= self.max_lru_len:
self.muti_lru = self.muti_lru[64:]
self.muti_lru[(stock_id, start_time, end_time, fields, method)] = agg_stock_data
return agg_stock_data return agg_stock_data
def _agg_data(self, data, method): def _agg_data(self, data, method):
"""Agg data by specific method. """Agg data by specific method."""
"""
if method == "sum": if method == "sum":
return data.sum() return data.sum()
if method == "mean": if method == "mean":
@@ -237,7 +238,7 @@ class NumpyQuote(BaseQuote):
bool bool
True means one piece of data to obtaine. True means one piece of data to obtaine.
""" """
if end_time - start_time < np.timedelta64(1, 'm'): if end_time - start_time < np.timedelta64(1, "m"):
return True return True
if start_time.hour == 11 and start_time.minute == 29 and start_time.second == 0: if start_time.hour == 11 and start_time.minute == 29 and start_time.second == 0:
return True return True