状态空间就是"state spcae",是环境输入给RL代理的当前信息。
当下的研究大多使用这三种设定方式:
1、OHCLV data
2、financial technical indicators
3、结合一二后进行深度学习进行特征选择。
OHCLV数据可以使用tushare进行提取;
安装方式为:
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
financial technical indicators我们通过使用python中的TA包 进行提取;
安装方式为:
pip install python-ta==1.0
OHCLV转化为技术指标:
df = data.copy()
print("Loaded CSV...")
df = add_all_ta_features(df, "open", "high", "low", "close", "volume", fillna=True)
print("Added TA Features...")
df = df.reset_index(drop=True)
深度学习进一步进行特征提取的方法众多,常用的有RNN,LSTM,CNN等。需要注意的是强化学习一般不使用高层数的神经网络,容易导致混乱而无法收敛的问题。RNN与LSTM的实现在我的其他文章中有所讲解。
版权声明:本文为weixin_47178719原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。