def VecCycleIndicators(stockcode = None,Cycle = 'D'): dftotal = ts.get_k_data(stockcode, ktype=Cycle) totalrows = len(dftotal) if(totalrows <100): print('Insufficiennt Data for Analyze' ) return None startIndex = 0 colNames = ['date',Cycle+'-smadir',Cycle+'-macddir',Cycle+'-light',Cycle+'-bandratio', Cycle+'-upband',Cycle+'-lowband',Cycle+'-valuerel',Cycle+'-rsi'] dfIndicator = DataFrame([],columns=colNames) while(startIndex + 100 <= totalrows): print(startIndex) df = dftotal[:startIndex + 100] dates = df['date'].values closes = df['close'].values lows = df['low'].values highs = df['high'].values date = dates[-1] smadir = ta.SMA_Direction(dates, closes) macddir = ta.MACD_Direction(dates, closes) lightcolor = trpscr.ImpluseLight(smadir,macddir) rsi = ta.get_cur_rsi(dates,closes) uppenetrationCounter, downpenetrationCounter, bandratio, upband, lowband \ = ta.envelop_ratio(dates, highs, lows, closes) value_re = ta.SMAValueZone_GX(dates, closes) s = Series([date,smadir,macddir,lightcolor,bandratio,upband,lowband,value_re,rsi],index = colNames) dfIndicator = dfIndicator.append(s,ignore_index=True) startIndex += 1 FileName = stockcode + Cycle +'.csv' FilePath = os.path.join(DataRoot,FileName) dfIndicator.to_csv(FilePath) return dfIndicator
def sz50Daily(): codelist = DI.get_stockcode_list('sz50') colNames = [ 'stockcode', 'smadir', 'uppenetrationCounter', 'downpenetrationCounter', 'macddir', 'bandratio', 'upband', 'lowband', 'value_re' ] filterdf = DataFrame([], columns=colNames) filepath = os.path.join(os.getcwd(), 'data', 'list') for stockcode in codelist['code']: df = ts.get_k_data(stockcode, ktype='D') dates = df['date'].values closes = df['close'].values lows = df['low'].values highs = df['high'].values smadir = ta.SMA_Direction(dates, closes) macddir = ta.MACD_Direction(dates, closes) uppenetrationCounter, downpenetrationCounter, bandratio, upband, lowband\ = ta.envelop_ratio(dates,highs,lows,closes) #print(stockcode,uppenetrationCounter, downpenetrationCounter, bandratio, upband, lowband) value_re = ta.SMAValueZone_GX(dates, closes) s = Series([ stockcode, smadir, uppenetrationCounter, downpenetrationCounter, macddir, bandratio, upband, lowband, value_re ], index=colNames) filterdf = filterdf.append(s, ignore_index=True) filterdf.to_csv(filepath + '.csv')