def bt_init_data(qx): ksgn, df = qx.priceSgn, qx.wrkStkDat df = df.sort_index(ascending=True) # if ksgn == 'avg': df[ksgn] = df[zsys.ohlcLst].mean(axis=1) else: df[ksgn] = df[ksgn] # df['dprice'] = df[ksgn] df['dpricek'] = df[ksgn].shift(-1) #trd-price.next,day # df['xtim'] = df.index df = zdat.df_xtim2mtim(df, 'xtim', qx.priceDateFlag) # df = zta.mul_talib(zta.MA, df, ksgn, zsys.ma100Lst_var) # #df=df.round(2) #df=df.dropna() #qx.stkPools[xcod]=df.round(2) qx.wrkStkDat = df.round(3) # return qx
#1 读取数据 fss = 'data/600663.csv' print('\n#1,fss', fss) df = pd.read_csv(fss, index_col=0) df = df.sort_index(ascending=True) print(df.tail()) #2 计算时间衍生参数 # df['xtim'] = df.index df['xyear'] = df['xtim'].apply(zstr.str_2xtim, ksgn='y') df['xmonth'] = df['xtim'].apply(zstr.str_2xtim, ksgn='m') df['xday'] = df['xtim'].apply(zstr.str_2xtim, ksgn='d') # df['xday_week'] = df['xtim'].apply(zstr.str_2xtim, ksgn='dw') df['xday_year'] = df['xtim'].apply(zstr.str_2xtim, ksgn='dy') #df['xday_month']=df['xtim'].apply(zstr.str_2xtim,ksgn='dm') df['xweek_year'] = df['xtim'].apply(zstr.str_2xtim, ksgn='wy') # print('\n#2,dateLst:', zsys.dateLst) print('\ndf.tail') print(df.tail()) #3 计算时间衍生参数,使用ztools_data库函数 df = pd.read_csv(fss, index_col=0) df = df.sort_index(ascending=True) df['xtim'] = df.index df2 = zdat.df_xtim2mtim(df, 'xtim', True) print('\n#3,df2.tail') print(df2.tail())
df = df.sort_index(ascending=True) print(df.tail()) #2 计算时间衍生参数 # df['xtim'] = df.index df['xyear'] = df['xtim'].apply(zstr.str_2xtim, ksgn='y') df['xmonth'] = df['xtim'].apply(zstr.str_2xtim, ksgn='m') df['xday'] = df['xtim'].apply(zstr.str_2xtim, ksgn='d') # df['xday_week'] = df['xtim'].apply(zstr.str_2xtim, ksgn='dw') df['xday_year'] = df['xtim'].apply(zstr.str_2xtim, ksgn='dy') #df['xday_month']=df['xtim'].apply(zstr.str_2xtim,ksgn='dm') df['xweek_year'] = df['xtim'].apply(zstr.str_2xtim, ksgn='wy') # # df['xhour'] = df['xtim'].apply(zstr.str_2xtim, ksgn='h') df['xminute'] = df['xtim'].apply(zstr.str_2xtim, ksgn='t') # print('\n#2,timeLst:', zsys.timeLst) print('\ndf.tail') print(df.tail()) #3 计算时间衍生参数,使用ztools_data库函数 df = pd.read_csv(fss, index_col=0) df = df.sort_index(ascending=True) df['xtim'] = df.index df2 = zdat.df_xtim2mtim(df, 'xtim', False) print('\n#3,df2.tail') print(df2.tail())