mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-06 05:51:17 +08:00
fix csi500 end date issue (#1373)
This commit is contained in:
@@ -394,7 +394,7 @@ class CSI500Index(CSIIndex):
|
||||
type: str, value from ["add", "remove"]
|
||||
"""
|
||||
bs.login()
|
||||
today = pd.datetime.now()
|
||||
today = pd.Timestamp.now()
|
||||
date_range = pd.DataFrame(pd.date_range(start="2007-01-15", end=today, freq="7D"))[0].dt.date
|
||||
ret_list = []
|
||||
col = ["date", "symbol", "code_name"]
|
||||
@@ -410,7 +410,8 @@ class CSI500Index(CSIIndex):
|
||||
bs.logout()
|
||||
return pd.concat(ret_list, sort=False)
|
||||
|
||||
def get_data_from_baostock(self, date) -> pd.DataFrame:
|
||||
@staticmethod
|
||||
def get_data_from_baostock(date) -> pd.DataFrame:
|
||||
"""
|
||||
Data source: http://baostock.com/baostock/index.php/%E4%B8%AD%E8%AF%81500%E6%88%90%E5%88%86%E8%82%A1
|
||||
Avoid a large number of parallel data acquisition,
|
||||
@@ -452,13 +453,13 @@ class CSI500Index(CSIIndex):
|
||||
end_date: pd.Timestamp
|
||||
"""
|
||||
logger.info("get new companies......")
|
||||
today = datetime.date.today()
|
||||
today = pd.Timestamp.now().normalize()
|
||||
bs.login()
|
||||
result = self.get_data_from_baostock(today)
|
||||
result = self.get_data_from_baostock(today.strftime("%Y-%m-%d"))
|
||||
bs.logout()
|
||||
df = result[["date", "symbol"]]
|
||||
df.columns = [self.END_DATE_FIELD, self.SYMBOL_FIELD_NAME]
|
||||
df[self.END_DATE_FIELD] = pd.to_datetime(df[self.END_DATE_FIELD].astype(str))
|
||||
df[self.END_DATE_FIELD] = today
|
||||
df[self.START_DATE_FIELD] = self.bench_start_date
|
||||
logger.info("end of get new companies.")
|
||||
return df
|
||||
|
||||
Reference in New Issue
Block a user