栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

强化学习中量化交易的状态空间设置

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

强化学习中量化交易的状态空间设置

状态空间就是"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的实现在我的其他文章中有所讲解。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/293959.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号