def lstm010(qx): #----------------- print(''' 本案例取消 pd,mpl,openCV,sklearn,tf部分基础模块库,api函数接口改了 有兴趣的用户,请自行根据提示信息,修改相关源码 开源项目,函数API接口,参数变化,属于很正常的现象 每次大的版本升级,都会有个别模块库函数API接口变化, 这种因为版本变化,引发的程序代码冲突,称为:版本冲突 所以,使用开源软件,要养成多动手搜索/查看最新版本的软件文档/函数接口餐宿 ''') #----------------- stknum, xcod, df = 0, qx.wrkStkCod, qx.wrkStkDat xtim, ksgn = qx.wrkTimStr, qx.priceSgn dprice = ztq.tq_stkGetPrice(df, 'price', xtim) dp_max = ztq.tq_stkGetPrice(df, 'dprice_max', xtim) dp_min = ztq.tq_stkGetPrice(df, 'dprice_min', xtim) dp_avg = ztq.tq_stkGetPrice(df, 'dprice_avg', xtim) # #dprice=ztq.tq_stkGetPrice(df,ksgn,xtim) d01 = df[xtim:xtim] xdat = d01[zsys.TDS_xlst9].values xdat = xdat.astype(float) rxn, num_in = xdat.shape[0], len(zsys.TDS_xlst9) xdat = xdat.reshape(rxn, num_in, -1) # mx = qx.aiModel['lstm010'] dp_y0 = mx.predict(xdat) #y_pred y2 = dp_y0.flatten()[:] dp_y = y2[0] # if dp_y > 0: qx.wrkStkDat.ix[xtim, 'price_next'] = dprice # kbuy, ksell = qx.staVars[0], qx.staVars[1] # fgBuy = (dp_avg <= (dp_y * kbuy)) fgSell = (dp_avg >= (dp_y * ksell)) # #fgBuy=(dp_min>=(dp_y*kbuy)) #fgSell=(dp_max<=(dp_y*ksell)) # #fgBuy=(dprice>=(dp_y*kbuy)) #fgSell=(dprice<=(dp_y*ksell)) # if fgSell: stknum = sta_sell(qx) if fgBuy and (stknum == 0): stknum = sta_buy(qx) # return stknum
def lstm010(qx): stknum,xcod,df=0,qx.wrkStkCod,qx.wrkStkDat xtim,ksgn=qx.wrkTimStr,qx.priceSgn dprice=ztq.tq_stkGetPrice(df,'price',xtim) dp_max=ztq.tq_stkGetPrice(df,'dprice_max',xtim) dp_min=ztq.tq_stkGetPrice(df,'dprice_min',xtim) dp_avg=ztq.tq_stkGetPrice(df,'dprice_avg',xtim) # #dprice=ztq.tq_stkGetPrice(df,ksgn,xtim) d01=df[xtim:xtim] xdat=d01[zsys.TDS_xlst9].values xdat=xdat.astype(float) rxn,num_in=xdat.shape[0],len(zsys.TDS_xlst9) xdat=xdat.reshape(rxn,num_in,-1) # mx=qx.aiModel['lstm010'] dp_y0 = mx.predict(xdat) #y_pred y2=dp_y0.flatten()[:] dp_y=y2[0] # if dp_y>0: qx.wrkStkDat.ix[xtim,'price_next']=dprice # staVars 策略函数的参数变量列表 kbuy,ksell=qx.staVars[0],qx.staVars[1] # fgBuy=(dp_avg<=(dp_y*kbuy)) fgSell=(dp_avg>=(dp_y*ksell)) # #fgBuy=(dp_min>=(dp_y*kbuy)) #fgSell=(dp_max<=(dp_y*ksell)) # #fgBuy=(dprice>=(dp_y*kbuy)) #fgSell=(dprice<=(dp_y*ksell)) # if fgSell:stknum=sta_sell(qx) if fgBuy and(stknum==0):stknum=sta_buy(qx) # print("***********-------******\n") print(stknum) print("***********-------******\n") return stknum
def avg01(qx): stknum, xcod, df = 0, qx.wrkStkCod, qx.wrkStkDat xtim, ksgn = qx.wrkTimStr, qx.priceSgn # dprice = ztq.tq_stkGetPrice(df, ksgn, xtim) dp_max = ztq.tq_stkGetPrice(df, 'dprice_max', xtim) dp_min = ztq.tq_stkGetPrice(df, 'dprice_min', xtim) dp_avg = ztq.tq_stkGetPrice(df, 'dprice_avg', xtim) # kbuy, ksell = qx.staVars[0], qx.staVars[1] #fgBuy=(dprice<=(dp_min*kbuy)) #fgSell=(dprice>=(dp_max*ksell)) fgBuy = (dprice <= (dp_avg * kbuy)) fgSell = (dprice >= (dp_avg * ksell)) # if fgSell: stknum = sta_sell(qx) if fgBuy and (stknum == 0): stknum = sta_buy(qx) # return stknum
def sta_sell(qx): stknum, xcod = 0, qx.wrkStkCod usr_stkNum = ztq.tq_usrPoolsGet(qx.usrPools, xcod, 'num9') dprice = ztq.tq_stkGetPrice(qx.wrkStkDat, 'dprice', qx.wrkTimStr) # if usr_stkNum > 0: stknum = round(usr_stkNum * qx.trd_sellSize) elif qx.trd_nilFlag: if qx.trd_mode == 1: stknum = qx.trd_buyNum if qx.trd_mode == 2: stknum = round(qx.trd_buyMoney / dprice) # #print('@sta-sell,',dprice,usr_stkNum,stknum,xcod) stknum = -stknum return stknum
def sta_buy(qx): stknum = 0 dprice = ztq.tq_stkGetPrice(qx.wrkStkDat, 'dprice', qx.wrkTimStr) if dprice > 0: if qx.trd_mode == 1: stknum = qx.trd_buyNum if qx.trd_mode == 2: stknum = round(qx.trd_buyMoney / dprice) dcash, dsum = qx.usrMoney, stknum * dprice # if (dcash - dsum) < -qx.usrMoney0nil: stknum = 0 elif (dsum > dcash) and (not qx.trd_nilFlag): if qx.trd_mode == 1: stknum = 0 if qx.trd_mode == 2: stknum = dcash // dprice # return stknum
def bt_main_1code(qx): # xcod, xtim = qx.wrkStkCod, qx.wrkTimStr dprice = ztq.tq_stkGetPrice(qx.wrkStkDat, qx.priceSgn, xtim) # qx.wrkStkNum = 0 if dprice > 0: qx.wrkStkNum = qx.staFun(qx) # if qx.wrkStkNum != 0: usr_stkNum = ztq.tq_usrPoolsGet(qx.usrPools, xcod, 'num9') # dnum, dcash = qx.wrkStkNum, qx.usrMoney qx.usrMoney = dcash - dnum * dprice num9 = usr_stkNum + dnum # ztq.tq_usrPoolsPutAll(qx.usrPools, xcod, num9, dnum) # return qx