考虑到针对股票市场的噪音特性,我们尝试使用变分自编码器(VAE)对价格数据进行重构,并且考虑到股票数据的时序性,我们在自编码器网络中加入LSTM网络提升表现。
第一步:获取数据:
pip install tushare
#获取使用接口
def get_token():
ts.set_token("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
pro=ts.pro_api()
return pro
##获取数据列表
def get_data_list(cursor,sql,conn):
cursor.execute(sql)
res=cursor.fetchall()
conn.commit()
ts_codes_list=list(res)
ts_codes_list=[",".join(list(x)) for x in ts_codes_list]
return ts_codes_list
##获取数据
def get_data(ts_codes_list,pro):
daily=pd.DataFrame(columns=["ts_code","trade_date","open","close","high","low","volume"]) ##获取相应的列信息
for i in range(0,len(ts_codes_list),100):
j=i+100
if(j>=len(ts_codes_list)):
j=len(ts_codes_list)
name=",".join(ts_codes_list[i:j])
part= pro.daily(ts_code=name, trade_date=get_date())[["ts_code","trade_date","open","close","high","low","volume"]]
daily=pd.concat([daily,part],ignore_index=True)
daily["trade_date"]=daily["trade_date"].apply(get_date_format)
return daily
使用stockstats库进行对OHCLV的转换。
```python
from stoc