parent
083c66abb1
commit
a64a112b46
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
from .DDBLoader import DDBLoader
|
||||
|
||||
|
||||
class DDBEntityLoader(DDBLoader):
|
||||
|
||||
ddb_path = "dfs://daily_stock_ts"
|
||||
ddb_dbname = "db_daily_stock_ts"
|
||||
|
||||
def __init__(self, dtype, **kwargs):
|
||||
pass
|
@ -0,0 +1,52 @@
|
||||
|
||||
from DDBIndexLoader import DDBIndexLoader
|
||||
|
||||
|
||||
class DDBIndexLoaderWind(DDBIndexLoader):
|
||||
|
||||
def __init__(self, dtype, **kwargs):
|
||||
# TODO: 后续版本中,父类的构造函数里可能会增加一些设置项
|
||||
super().__init__(**kwargs)
|
||||
self.dtype = dtype
|
||||
|
||||
if dtype == "concept":
|
||||
self.mem_tbl_name = "mem_idx_daily_concept_wind"
|
||||
self.part_tbl_name ="idx_daily_concept_wind"
|
||||
elif dtype == "kline":
|
||||
self.mem_tbl_name = "mem_idx_daily_kline_wind"
|
||||
self.part_tbl_name ="idx_daily_kline_wind"
|
||||
else:
|
||||
raise NotImplementedError(f"Unsupported `dtype` argument: {dtype}")
|
||||
|
||||
self.make_fields()
|
||||
self.make_calendar_df()
|
||||
|
||||
|
||||
def make_fields(self):
|
||||
if self.dtype == "concept":
|
||||
with self.mssql_engine.connect() as conn:
|
||||
rs = conn.execute("select [WIND_SEC_CODE] from [IndexInfo].[dbo].[Constituents] group by IndexID")
|
||||
self.fields = [index_id for (index_id,) in rs.fetchall()]
|
||||
elif self.dtype == "kline":
|
||||
self.fields = ['open', 'high', 'low', 'close', 'vol', 'amount', 'yclose']
|
||||
|
||||
|
||||
def make_calendar_df(self):
|
||||
# 这里我们使用天软日K先数据表来构造交易日历
|
||||
with self.mssql_engine.connect() as conn:
|
||||
if self.dtype == "concept":
|
||||
stat = "select [StockID], [date] from [StockDaily].[dbo].[DailyKLine] group by [StockID], [date]"
|
||||
elif self.dtype == "kline":
|
||||
stat = "select [StockID], [date] from [IndexDaily].[dbo].[DailyKLine] group by [StockID], [date]"
|
||||
else:
|
||||
raise NotImplementedError(f"Unsupported dtype: {self.dtype}")
|
||||
|
||||
rs = conn.execute(stat)
|
||||
stock_date_list = [(stock_name, date) for stock_name, date in rs.fetchall()]
|
||||
|
||||
self.df_calendar = pd.DataFrame(stock_date_list, columns=['code', 'm_nDate'])
|
||||
self.df_calendar['m_nDate'] = self.make_date(self.df_calendar['m_nDate'])
|
||||
self.df_calendar['code'] = self.tscode_to_windcode(self.df_calendar['code'])
|
||||
|
||||
print('Did make the DataFrame for calendar')
|
||||
print(self.df_calendar.head())
|
Loading…
Reference in new issue