def SMA_dataPre(qx, xnam0, ksgn0): ''' 简单均线策略数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' :ivar xcod (int): 股票代码 ''' zwx.sta_dataPre0xtim(qx, xnam0) #----对各只股票数据,进行预处理,提高后期运算速度 ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 d20['dprice'] = d20['open'] * d20[ksgn] / d20['close'] d20['kprice'] = d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'] # d = qx.staVars[0] d20 = zwta.MA(d20, d, ksgn) d = qx.staVars[1] d20 = zwta.MA(d20, d, ksgn) # zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) #--- fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def tur10_dataPre(qx,xnam0,ksgn0): ''' 海龟策略:tur10, 数据预处理函数 说明 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice']=d20['close'] d20['kprice']=d20['dprice'] # d=qx.staVars[0];ksgn='xhigh0';d20[ksgn]=pd.rolling_max(d20['high'],d) d=qx.staVars[1];ksgn='xlow0';d20[ksgn]=pd.rolling_min(d20['low'],d) d20['xhigh']=d20['xhigh0'].shift(1) d20['xlow']=d20['xlow0'].shift(1) # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def kdj10_dataPre(qx,xnam0,ksgn0): ''' KDJ策略 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc,qx.priceBuy=ksgn0,ksgn0,ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice']=d20['close'] d20['kprice']=d20['dprice'] # d=qx.staVars[0];#d2=qx.staVars[1]; d20=zwta.STOD(d20,d,'close'); d20['stod1n']=d20['stod'].shift(1) d20['stok1n']=d20['stok'].shift(1) # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- #fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' fss=os.path.join('tmp',qx.prjName+'_'+xcod+'.csv') d20.to_csv(fss)
def BBANDS_dataPre(qx,xnam0,ksgn0): ''' 布林带数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close';'close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice']=d20[ksgn] d20['kprice']=d20['dprice'] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['open'].shift(-1) # dnum=qx.staVars[0]; d20=zwta.BBANDS_UpLow(d20,dnum,ksgn) #--- zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' fss=os.path.join('tmp',qx.prjName+'_'+xcod+'.csv') d20.to_csv(fss)
def rsi10_dataPre(qx, xnam0, ksgn0): ''' RSI策略, 数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx, xnam0) #----对各只股票数据,进行预处理,提高后期运算速度 ksgn, qx.priceCalc, qx.priceBuy = ksgn0, ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice'] = d20['close'] d20['kprice'] = d20['dprice'] # d = qx.staVars[0] #d2=qx.staVars[1]; d20 = zwta.RSI(d20, d) #d20['macd1n']=d20['macd'].shift(1) #d20['msign1n']=d20['msign'].shift(1) # zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) #--- fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def BBANDS_dataPre(qx,xnam0,ksgn0): ''' 布林带数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close';'close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice']=d20[ksgn] d20['kprice']=d20['dprice'] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['open'].shift(-1) # dnum=qx.staVars[0]; d20=zwta.BBANDS_UpLow(d20,dnum,ksgn) #--- zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def rsi10_dataPre(qx, xnam0, ksgn0): ''' RSI策略, 資料預處理函數 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx, xnam0) #----對各檔股票資料,進行預處理,提高後期運算速度 ksgn, qx.priceCalc, qx.priceBuy = ksgn0, ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # 計算交易價格kprice和策略分析採用的價格dprice,kprice一般採用次日的開盤價 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice'] = d20['close'] d20['kprice'] = d20['dprice'] # d = qx.staVars[0] #d2=qx.staVars[1]; d20 = zwta.RSI(d20, d) #d20['macd1n']=d20['macd'].shift(1) #d20['msign1n']=d20['msign'].shift(1) # zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) #--- fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def BBANDS_dataPre(qx, xnam0, ksgn0): ''' 布林帶資料預處理函數 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx, xnam0) ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close';'close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice'] = d20[ksgn] d20['kprice'] = d20['dprice'] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['open'].shift(-1) # dnum = qx.staVars[0] d20 = zwta.BBANDS_UpLow(d20, dnum, ksgn) #--- zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def CMA_dataPre(qx,xnam0,ksgn0): ''' 均线交叉策略数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice']=d20[ksgn] d20['kprice']=d20['dprice'] #d20['kprice']=d20['dprice'].shift(-1) # d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn);k0ma='ma_%d' %qx.staVars[0] #d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn);k1ma='ma_%d' %qx.staVars[1] # #d20['ma1n']=d20[k0ma].shift(1) d20['ma2n']=d20[k0ma].shift(2) #d20['dp1n']=d20['dprice'].shift(1) d20['dp2n']=d20['dprice'].shift(2) #--- d20=np.round(d20,3); zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def SMA_dataPre(qx, xnam0, ksgn0): ''' 簡單均線策略資料預處理函數 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' :ivar xcod (int): 股票代碼 ''' zwx.sta_dataPre0xtim(qx, xnam0) #----對各檔股票資料,進行預處理,提高後期運算速度 ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # 計算交易價格kprice和策略分析採用的價格dprice,kprice一般採用次日的開盤價 d20['dprice'] = d20['open'] * d20[ksgn] / d20['close'] d20['kprice'] = d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'] # d = qx.staVars[0] d20 = zwta.MA(d20, d, ksgn) d = qx.staVars[1] d20 = zwta.MA(d20, d, ksgn) # zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) #--- fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def rsi10_dataPre(qx,xnam0,ksgn0): ''' RSI策略, 数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc,qx.priceBuy=ksgn0,ksgn0,ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice']=d20['close'] d20['kprice']=d20['dprice'] # d=qx.staVars[0];#d2=qx.staVars[1]; d20=zwta.RSI(d20,d); #d20['macd1n']=d20['macd'].shift(1) #d20['msign1n']=d20['msign'].shift(1) # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def tur10_dataPre(qx,xnam0,ksgn0): ''' 策略.数据预处理函数 说明 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] d20['dprice']=d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['kprice']=d20['dprice'] # d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def SMA_dataPre(qx,xnam0,ksgn0): ''' 简单均线策略数据预处理函数 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' :ivar xcod (int): 股票代码 ''' zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 d20['dprice']=d20['open']*d20[ksgn]/d20['close'] d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'] # d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def VWAP_dataPre(qx, xnam0, ksgn0): ''' vwap 資料預處理函數,vwap策略,成交量加權平均價 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx, xnam0) # ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close';'close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice'] = d20[ksgn] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'].shift(-1) d20['kprice'] = d20['open'].shift(-1) # #d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); #d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # #d20=zwta.MA(d20,qx.staMA_short,'adj close'); #d20=zwta.MA(d20,qx.staMA_long,'adj close'); #ksma='ma_'+str(qx.staMA_long); #d20['ma1n']=d20[ksma].shift(1) #d20['ma1n']=d20[ksma] # #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] #d20['dprice']=d20['adj close'] #d20['kprice']=d20['dprice'] #vwap,基於成交量的加權平均價 #vwap = (prices * volume).sum(n) / volume.sum(n) #sum函數自動忽略NaN值 #vwapWindowSize,threshold #qx.staVarLst=[15,0.01]# nwin = qx.staVars[0] d20['vw_sum'] = pd.rolling_sum(d20['dprice'] * d20['volume'], nwin) d20['vw_vol'] = pd.rolling_sum(d20['volume'], nwin) d20['vwap'] = d20['vw_sum'] / d20['vw_vol'] #--- zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def VWAP_dataPre(qx,xnam0,ksgn0): ''' vwap 数据预处理函数,vwap策略,成交量加权平均价 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); # ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close';'close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice']=d20[ksgn] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'].shift(-1) d20['kprice']=d20['open'].shift(-1) # #d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); #d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # #d20=zwta.MA(d20,qx.staMA_short,'adj close'); #d20=zwta.MA(d20,qx.staMA_long,'adj close'); #ksma='ma_'+str(qx.staMA_long); #d20['ma1n']=d20[ksma].shift(1) #d20['ma1n']=d20[ksma] # #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] #d20['dprice']=d20['adj close'] #d20['kprice']=d20['dprice'] #vwap,基于成交量的加权平均价 #vwap = (prices * volume).sum(n) / volume.sum(n) #sum函数自动忽略NaN值 #vwapWindowSize,threshold #qx.staVarLst=[15,0.01]# nwin=qx.staVars[0]; d20['vw_sum']=pd.rolling_sum(d20['dprice']*d20['volume'],nwin); d20['vw_vol']=pd.rolling_sum(d20['volume'],nwin); d20['vwap']=d20['vw_sum']/d20['vw_vol'] #--- zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' fss=os.path.join('tmp',qx.prjName+'_'+xcod+'.csv') d20.to_csv(fss)
def VWAP_dataPre(qx,xnam0,ksgn0): ''' vwap 数据预处理函数,vwap策略,成交量加权平均价 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx,xnam0); # ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close';'close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice']=d20[ksgn] #d20['kprice']=d20['dprice'].shift(-1) #d20['kprice']=d20['dprice'].shift(-1) d20['kprice']=d20['open'].shift(-1) # #d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); #d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # #d20=zwta.MA(d20,qx.staMA_short,'adj close'); #d20=zwta.MA(d20,qx.staMA_long,'adj close'); #ksma='ma_'+str(qx.staMA_long); #d20['ma1n']=d20[ksma].shift(1) #d20['ma1n']=d20[ksma] # #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] #d20['dprice']=d20['adj close'] #d20['kprice']=d20['dprice'] #vwap,基于成交量的加权平均价 #vwap = (prices * volume).sum(n) / volume.sum(n) #sum函数自动忽略NaN值 #vwapWindowSize,threshold #qx.staVarLst=[15,0.01]# nwin=qx.staVars[0]; d20['vw_sum']=pd.rolling_sum(d20['dprice']*d20['volume'],nwin); d20['vw_vol']=pd.rolling_sum(d20['volume'],nwin); d20['vwap']=d20['vw_sum']/d20['vw_vol'] #--- zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def tim0Trade_dataPre(qx,xnam0,ksgn0): zwx.sta_dataPre0xtim(qx,xnam0); #------- ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] d20['dprice']=d20[ksgn] #d20['kprice']=d20['dprice'].shift(-1) d20['kprice']=d20['dprice'] # d=qx.staVars[0];d20=zwta.MA(d20,d,ksgn); d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn); # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
def tur10_dataPre(qx, xnam0, ksgn0): ''' 海龜策略:deal_stock_num, 資料預處理函數 說明 當今天的收盤價,大於過去n個交易日中的最高價時,以收盤價買入; 買入後,當收盤價小於過去n個交易日中的最低價時,以收盤價賣出。 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' ''' #zwsta.zwx.sta_dataPre0xtim(qx,xnam0); zwx.sta_dataPre0xtim(qx, xnam0) #----對各檔股票資料,進行預處理,提高後期運算速度 ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] # 計算交易價格kprice和策略分析採用的價格dprice,kprice一般採用次日的開盤價 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice'] = d20['close'] d20['kprice'] = d20['dprice'] # d = qx.staVars[0] ksgn = 'xhigh0' d20[ksgn] = pd.rolling_max(d20['high'], d) d = qx.staVars[1] ksgn = 'xlow0' d20[ksgn] = pd.rolling_min(d20['low'], d) d20['xhigh'] = d20['xhigh0'].shift(1) d20['xlow'] = d20['xlow0'].shift(1) # zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) #--- fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def CMA_dataPre(qx, xnam0, ksgn0): ''' 均線交叉策略資料預處理函數 Args: qx (zwQuantX): zwQuantX數據包 xnam0 (str):函數標籤 ksgn0 (str): 價格列名稱,一般是'adj close' ''' zwx.sta_dataPre0xtim(qx, xnam0) #----對各檔股票資料,進行預處理,提高後期運算速度 ksgn, qx.priceCalc = ksgn0, ksgn0 #'adj close'; for xcod in zw.stkLibCode: d20 = zw.stkLib[xcod] #---------------dprice,kprice #d20['dprice']=d20['open']*d20['adj close']/d20['close'] d20['dprice'] = d20[ksgn] d20['kprice'] = d20['dprice'] #d20['kprice']=d20['dprice'].shift(-1) # d = qx.staVars[0] d20 = zwta.MA(d20, d, ksgn) k0ma = 'ma_%d' % qx.staVars[0] #d=qx.staVars[1];d20=zwta.MA(d20,d,ksgn);k1ma='ma_%d' %qx.staVars[1] # #d20['ma1n']=d20[k0ma].shift(1) d20['ma2n'] = d20[k0ma].shift(2) #d20['dp1n']=d20['dprice'].shift(1) d20['dp2n'] = d20['dprice'].shift(2) #--- d20 = np.round(d20, 3) zw.stkLib[xcod] = d20 if qx.debugMod > 0: print(d20.tail()) fss = 'tmp\\' + qx.prjName + '_' + xcod + '.csv' d20.to_csv(fss)
def tur10_dataPre(qx,xnam0,ksgn0): ''' 海龟策略:deal_stock_num, 数据预处理函数 说明 当今天的收盘价,大于过去n个交易日中的最高价时,以收盘价买入; 买入后,当收盘价小于过去n个交易日中的最低价时,以收盘价卖出。 Args: qx (zwQuantX): zwQuantX数据包 xnam0 (str):函数标签 ksgn0 (str): 价格列名称,一般是'adj close' ''' #zwsta.zwx.sta_dataPre0xtim(qx,xnam0); zwx.sta_dataPre0xtim(qx,xnam0); #----对各只股票数据,进行预处理,提高后期运算速度 ksgn,qx.priceCalc=ksgn0,ksgn0; #'adj close'; for xcod in zw.stkLibCode: d20=zw.stkLib[xcod]; # 计算交易价格kprice和策略分析采用的价格dprice,kprice一般采用次日的开盘价 #d20['dprice']=d20['open']*d20[ksgn]/d20['close'] #d20['kprice']=d20['dprice'].shift(-1) d20['dprice']=d20['close'] d20['kprice']=d20['dprice'] # d=qx.staVars[0];ksgn='xhigh0';d20[ksgn]=pd.rolling_max(d20['high'],d) d=qx.staVars[1];ksgn='xlow0';d20[ksgn]=pd.rolling_min(d20['low'],d) d20['xhigh']=d20['xhigh0'].shift(1) d20['xlow']=d20['xlow0'].shift(1) # zw.stkLib[xcod]=d20; if qx.debugMod>0: print(d20.tail()) #--- fss='tmp\\'+qx.prjName+'_'+xcod+'.csv' d20.to_csv(fss)
# -*- coding: utf-8 -*- #zwQuant import zwSys as zw import zwQTBox as zwx import zwBacktest as zwbt #======================= rss='dat\\' #rss='\\zwdat\\cn\\day\\' xlst=['600401'] #600401,*ST海润 qx=zwbt.bt_init(xlst,rss,'inx',10000); #读取大盘指数 qx.stkInxCode,qx.stkInxName,qx.stkInxCName='000001','sh001','上证指数' zwx.stkInxLibRd(qx) #切割大盘指数 #zwx.stkInxLibSet8XTim(qx,qx.xtim0,qx.xtim9) qx.staVars=[0,'',''] zwx.sta_dataPre0xtim(qx,'inx') #输出大盘指数 print(zw.stkInxLib)