def SMA_sta(qx): ''' 簡單均線策略分析函數 每次買100股 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') xnum = zwx.xusrStkNum(qx, xcod) # ksma = 'ma_%d' % qx.staVars[1] dsma = qx.xbarWrk[ksma][0] # if (dprice > dsma) and (xnum == 0): stknum = 100 #print('buy',xtim,dprice,dsma,xnum); if (dprice <= dsma) and (xnum > 0): stknum = -1 #print('sell',xtim,dprice,dsma,xnum); # return stknum
def VWAP_sta(qx): ''' vwap 成交量加權平均價策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[5,0.01,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode # vwap = zwx.stkGetPrice(qx, 'vwap') if vwap > 0: dprice = zwx.stkGetVars(qx, 'close') kvwap = qx.staVars[1] xnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] dval = xnum * dprice #---- if (dprice > vwap * (1 + kvwap)) and (dval < (dcash * qx.stkKCash)): stknum = 100 if (dprice < vwap * (1 - kvwap)) and (dval > 0): stknum = -100 # if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass return stknum
def SMA_sta(qx): ''' 简单均线策略分析函数 每次买100股 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dprice=zwx.stkGetPrice(qx,'dprice') xnum=zwx.xusrStkNum(qx,xcod); # ksma='ma_%d' %qx.staVars[1] dsma=qx.xbarWrk[ksma][0] # if (dprice>dsma)and(xnum==0): stknum=100; #print('buy',xtim,dprice,dsma,xnum); if (dprice<=dsma)and(xnum>0): stknum=-1; #print('sell',xtim,dprice,dsma,xnum); # return stknum
def CMA_sta(qx): ''' 均線交叉策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[30,'2014-01-01',''] ''' stknum = 0 xcod = qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') dcash = qx.qxUsr['cash'] #duncash=qx.qxUsr['cash']; dnum0 = zwx.xusrStkNum(qx, xcod) #---- kmod = zwx.cross_Mod(qx) # if kmod == 1: if dnum0 == 0: stknum = int(dcash * qx.stkKCash / dprice) elif kmod == -1: stknum = -1 # if stknum != 0: #print(qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(kmod,qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(' ',stknum,dcash,qx.stkKCash,dprice) pass return stknum
def VWAP_sta(qx): ''' vwap 成交量加权平均价策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,0.01,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode # vwap=zwx.stkGetPrice(qx,'vwap') if vwap>0: dprice=zwx.stkGetVars(qx,'close') kvwap=qx.staVars[1]; xnum=zwx.xusrStkNum(qx,xcod); dcash=qx.qxUsr['cash']; dval = xnum * dprice; #---- if (dprice>vwap*(1+kvwap))and(dval<(dcash*qx.stkKCash)): stknum=100; if (dprice<vwap*(1-kvwap))and(dval>0): stknum=-100; # if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass; return stknum
def CMA_sta(qx): ''' 均线交叉策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[30,'2014-01-01',''] ''' stknum=0; xcod=qx.stkCode; dprice=zwx.stkGetPrice(qx,'dprice') dcash=qx.qxUsr['cash']; #duncash=qx.qxUsr['cash']; dnum0=zwx.xusrStkNum(qx,xcod) #---- kmod=zwx.cross_Mod(qx) # if kmod==1: if dnum0==0: stknum=int(dcash*qx.stkKCash/dprice); elif kmod==-1: stknum=-1; # if stknum!=0: #print(qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(kmod,qx.xtim,stknum,'xd',xcod,dprice,dcash) #print(' ',stknum,dcash,qx.stkKCash,dprice) pass; return stknum
def SMA20_sta(qx): ''' 简单均线策略分析函数 每次买90%的资金 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,15,'2015-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dprice = zwx.stkGetPrice(qx, 'dprice') xnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] # ksma = 'ma_%d' % qx.staVars[1] dsma = qx.xbarWrk[ksma][0] # if (dprice > dsma) and (xnum == 0): stknum = int(dcash * qx.stkKCash / dprice) #print('buy',xtim,dprice,dsma,xnum); if (dprice <= dsma) and (xnum > 0): stknum = -1 #print('sell',xtim,dprice,dsma,xnum); # return stknum
def VWAP_sta(qx): ''' vwap 成交量加权平均价策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[5,0.01,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode # vwap=zwx.stkGetPrice(qx,'vwap') if vwap>0: dprice=zwx.stkGetVars(qx,'close') kvwap=qx.staVars[1]; xnum=zwx.xusrStkNum(qx,xcod); dcash=qx.qxUsr['cash']; dval = xnum * dprice; #---- if (dprice>vwap*(1+kvwap))and(dval<(dcash*qx.stkKCash)): stknum=100; if (dprice<vwap*(1-kvwap))and(dval>0): stknum=-100; # if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass; return stknum
def BBANDS_sta(qx): ''' 布林帶策略分析函數 Args: qx (zwQuantX): zwQuantX數據包 預設參數範例: qx.staVars=[40,'2014-01-01',''] ''' stknum = 0 xtim, xcod = qx.xtim, qx.stkCode dup = zwx.stkGetVars(qx, 'boll_up') dlow = zwx.stkGetVars(qx, 'boll_low') #print(xtim,stknum,'xd',xcod,dup,dlow) if dup > 0: dprice = zwx.stkGetPrice(qx, 'dprice') kprice = zwx.stkGetPrice(qx, 'kprice') dnum = zwx.xusrStkNum(qx, xcod) dcash = qx.qxUsr['cash'] #print(xtim,stknum,dnum,'xd',dcash,dprice,'b,%.2f,%.2f' %(dlow,dup)) if (dnum == 0) and (dprice < dlow): stknum = int(dcash / dprice * qx.stkKCash) dsum = stknum * kprice if qx.debugMod > 0: print( xtim, stknum, dnum, '++,%.2f,%.2f,%.2f,$,%.2f,%.2f' % (dprice, dlow, dup, kprice, dsum)) elif (dnum > 0) and (dprice > dup): stknum = -1 dsum = dnum * kprice if qx.debugMod > 0: print( xtim, stknum, dnum, '--,%.2f,%.2f,%.2f,$,%.2f,%.2f' % (dprice, dlow, dup, kprice, dsum)) # if stknum != 0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass return stknum
def BBANDS_sta(qx): ''' 布林带策略分析函数 Args: qx (zwQuantX): zwQuantX数据包 默认参数示例: qx.staVars=[40,'2014-01-01',''] ''' stknum=0; xtim,xcod=qx.xtim,qx.stkCode dup=zwx.stkGetVars(qx,'boll_up') dlow=zwx.stkGetVars(qx,'boll_low') #print(xtim,stknum,'xd',xcod,dup,dlow) if dup>0: dprice=zwx.stkGetPrice(qx,'dprice') kprice=zwx.stkGetPrice(qx,'kprice') dnum=zwx.xusrStkNum(qx,xcod) dcash=qx.qxUsr['cash']; #print(xtim,stknum,dnum,'xd',dcash,dprice,'b,%.2f,%.2f' %(dlow,dup)) if (dnum==0)and(dprice<dlow): stknum = int(dcash /dprice*qx.stkKCash);dsum=stknum*kprice if qx.debugMod>0: print(xtim,stknum,dnum,'++,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) elif (dnum>0)and(dprice>dup): stknum = -1;dsum=dnum*kprice if qx.debugMod>0: print(xtim,stknum,dnum,'--,%.2f,%.2f,%.2f,$,%.2f,%.2f' %(dprice,dlow,dup,kprice,dsum)) # if stknum!=0: #print(xtim,stknum,'xd',xcod,dprice,dcash) pass; return stknum