1 Star 0 Fork 14

Alex/stock_robot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cvt_helper.py 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
邹吉华 提交于 2023-04-12 16:27 . 1.6
import numpy as np
import const as cst
from stock_info import StockSceneInfo
PRICE_CHANGE_LIMIT = 0.1
def vtor(v:np.float64,s:np.float64)->np.float32:
if s == 0:
return 0
return (v - s) / s / PRICE_CHANGE_LIMIT / 2 + 0.5
#return np.float32(s/(v+s))
def rtov(r:np.float32,s:np.float64)->np.float64:
return (r - 0.5) * PRICE_CHANGE_LIMIT * 2 * s + s
'''
if r != 0 :
return s/np.float64(r)-s
else:
return 0
'''
def parse_action(standard,action):
buy_action = action[1]
sell_action = action[0]
sell_price = rtov(sell_action,standard) #价格
buy_price = rtov(buy_action,standard)
return buy_price,sell_price
#获取obs
def get_obs(stock):
obs = np.zeros(shape=(cst.HISTORY_DATA_COUNT*cst.STOCK_FIELD_COUNT,),dtype=np.float32)
for j in range(len(stock)):
item : StockSceneInfo = stock[j]
obs[cst.STOCK_FIELD_COUNT*j+0] = item.Open
obs[cst.STOCK_FIELD_COUNT*j+1] = item.High
obs[cst.STOCK_FIELD_COUNT*j+2] = item.Low
obs[cst.STOCK_FIELD_COUNT*j+3] = item.Close
obs[cst.STOCK_FIELD_COUNT*j+4] = item.Deal
obs[cst.STOCK_FIELD_COUNT*j+5] = np.float32(item.Turn) #变成0到1区间
if item.IsST:
obs[cst.STOCK_FIELD_COUNT*j+6] = np.float32(0)
else :
obs[cst.STOCK_FIELD_COUNT*j+6] = np.float32(1)
return obs
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/alexford/stock_robot.git
[email protected]:alexford/stock_robot.git
alexford
stock_robot
stock_robot
master

搜索帮助