示例#1
0
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
示例#2
0
def df_xed_ailib(df, ksgn='avg', fgDate=True):
    #   xed.avg
    df = df.sort_index(ascending=True)
    if ksgn == 'avg':
        df[ksgn] = df[zsys.ohlcLst].mean(axis=1)
    else:
        df[ksgn] = df[ksgn]
    #   xed.time
    df['xtim'] = df.index
    df = df_xtim2mtim(df, 'xtim', fgDate)
    #   xed.ma.xxx
    df = zta.mul_talib(zta.MA, df, ksgn, zsys.ma100Lst_var)
    #
    #   xed.xavg.xxx,predict,y_data
    df = df_xed_nextDay(df, ksgn, 'x' + ksgn, 10)
    #
    df = df.round(2)
    df = df.dropna()
    #
    return df
示例#3
0
def stk2data_pre8FN(fss):
    if not os.path.exists(fss):
        return None
    #
    df = pd.read_csv(fss, index_col=0)
    df['avg'] = df[zsys.ohlcLst].mean(axis=1)
    #
    df['avg'] = df[zsys.ohlcLst].mean(axis=1)
    df, avg_lst = zdat.df_xshift(df, ksgn='avg', num9=10)
    #print('avg_lst,',avg_lst)
    #
    mv_lst = [2, 3, 5, 10, 15, 20, 30, 50, 100, 150, 200]
    #ma_lst=[2,3,4,5,6,7,8,9,10,15,20,30,40,50,60,80,100,120,150,180,200,250,300]
    df = zta.mul_talib(zta.MA, df, ksgn='avg', vlst=mv_lst)
    ma_lst = zstr.sgn_4lst('ma', mv_lst)
    #
    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['xweekday'] = df['xtim'].apply(zstr.str_2xtim, ksgn='w')
    tim_lst = ['xyear', 'xmonth', 'xday', 'xweekday']
    #
    df['price'] = df['avg']
    df['price_next'] = df[avg_lst].max(axis=1)
    #涨跌幅,zsys.k_price_change=1000
    df['price_change'] = df['price_next'] / df['price'] * 100
    #df['ktype']=df['price_change'].apply(zt.iff2type,d0=100)
    #def dat2type(d,k9=2000,k0=0):
    #fd>120
    #
    df = df.dropna()
    #df['ktype']=round(df['price_change']).astype(int)
    #df['ktype']=df['kprice'].apply(zt.iff2type,d0=100)
    #df['ktype']=df['price_change'].apply(zt.iff3type,v0=95,v9=105,v3=3,v2=2,v1=1)
    #
    df = df.round(3)
    return df
示例#4
0
#----------

#1 读取数据
fss = 'data/600663.csv'
print('\nfss', fss)
df = pd.read_csv(fss, index_col=0)
df = df.sort_index(ascending=True)
print(df.tail())

#2 计算avg均值数据
df['avg'] = df[zsys.ohlcLst].mean(axis=1).round(2)
print('\n#2,df')
print(df.tail())

#3
df2 = zta.mul_talib(zta.MA, df, ksgn='avg', vlst=zsys.ma100Lst_var)
print('\n#3,ma_lst,', zsys.ma100Lst_var)
print('\ndf2.head')
print(df2.head())
print('\ndf2.tail')
print(df2.tail())

#4 绘制价格曲线图
hdr, fss = '价格曲线图-ma均线', 'tmp/tmp_.html'
print('\n#4 fss,', fss)
vlst = list(map(lambda x: 'ma_' + str(x), zsys.ma100Lst_var))
print('vlst,', vlst)
xlst = ['avg'] + vlst
print('xlst,', xlst)
df3 = df2.tail(60)
zdr.drDF_mul_xline(df3, fss, m_title=hdr, xlst=xlst)
import ztools_tq as ztq
import ztools_draw as zdr
import ztools_data as zdat


#----------

#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 计算衍生参数
vlst=list(range(1,10))
print('\n#2 vlst,',vlst)

# ma100Lst_var=[2,3,5,10,15,20,25,30,50,100]
df=zta.mul_talib(zta.ROC,df, ksgn='close',vlst=zsys.ma100Lst_var)
print(df.head())
#
print('\n#3 roc01')
close_d0=df['close'][0]
close_d1=df['close'][1]
roc1=(close_d1 - close_d0)/close_d0
print('close_d0,d1:',close_d0,close_d1)
print('roc1:',roc1)