def tq_usrDatXed(qx, dfu): df2 = zdat.df_kcut8tim(dfu, '', qx.btTim0Str, qx.btTim9Str) # clst = qx.stkCodeLst nlst = list(map(lambda x: x + '_num', clst)) mlst = list(map(lambda x: x + '_money', clst)) dlst = list(df2.columns) #+['stk-val'] xlst = dlst + nlst + mlst #print('xlst',xlst) # df3 = pd.DataFrame(columns=xlst) df3[dlst] = df2 # dfq = qx.trdLib dfq = zdat.df_kcut8tim(qx.trdLib, '', qx.btTim0Str, qx.btTim9Str) #dfq=dfq[dfq.index>=qx.btTim0St] #dfq=dfq[dfq.index<=qx.btTim9Str] # for xsgn in nlst: dfq[xsgn] = 0 # for xtim, row in dfq.iterrows(): upools = row['upools'] #print(xtim,'#',upools) for xcod in upools: xnum = tq_usrPoolsGet(upools, xcod, 'num9') df3.ix[xtim, xcod + '_num'] = xnum # # df3 = df3.fillna(method='pad') # for xcod in clst: mss, nss = xcod + '_money', xcod + '_num' df3[mss] = df3[xcod] * df3[nss] # df3['stk-val'] = df3[mlst].sum(axis=1) df3['total'] = df3['stk-val'] + df3['cash'] # # #print('df3.tail()') #print(df3.tail()) x = df3.tail(1) x2 = x['total'].values[0] k = round(x2 / qx.usrMoney0 * 100, 2) # return df3, k
def tq_usrDatXedFill(qx, dfu): #df2=zdat.df_kcut8tim(dfu,'',qx.btTim0Str,qx.btTim9Str) #df2=dfu[dfu.index>=tim0Str] #df2=df2[df2.index<=tim9Str] #print('df2.tail()') #print(df2.tail()) # #xcod=qx.wrkInxCod #df=qx.inxPools[xcod] # df9 = pd.DataFrame() clst = qx.stkCodeLst mlst = list(map(lambda x: x + '_money', clst)) # #df=qx.wrkInxDat ksgn = qx.priceSgn df9['inx'] = qx.wrkInxDat[ksgn] df9['cash'] = dfu['cash'] # for xcod in clst: nss, mss = xcod + '_num', xcod + '_money' #nss=xcod+'_num' #df9[xcod],df9[nss],df9[mss]=dfu[xcod],dfu[nss],dfu[mss] df = qx.stkPools[xcod] df9[xcod], df9[nss] = df[ksgn], dfu[nss] df9[mss] = df9[xcod] * df9[nss] # df9 = df9.fillna(method='pad') df9[mss] = df9[xcod] * df9[nss] df9['stk-val'] = df9[mlst].sum(axis=1) df9['total'] = df9['stk-val'] + df9['cash'] # df9 = zdat.df_kcut8tim(df9, '', qx.btTim0Str, qx.btTim9Str) # xlst = ['inx', 'total'] + clst #df9[xlst]=df9[xlst] df = df9[xlst] df.index = pd.DatetimeIndex(df.index) # return df
#7 chk.dat print('\n7.1 tq_pools_chk') ztq.tq_pools_call(qx,ztq.tq_pools_chk) print('\n#7.2,plot inx -->tmp/tmp_.html') xinx,df=qx.wrkInxCod,qx.wrkInxDat hdr,fss='k线图-inx '+xinx,'tmp/tmp_'+xinx+'.html' df2=df.tail(100) zdr.drDF_cdl(df2,ftg=fss,m_title=hdr) print('\n#7.3,plot stk-->tmp/tmp_.html') xcod,df=qx.wrkStkCod,qx.wrkStkDat hdr,fss='k线图-stk '+xcod,'tmp/tmp_'+xcod+'.html' df2=df.tail(100) zdr.drDF_cdl(df2,ftg=fss,m_title=hdr) #8 print('\n#8.1,stk.merge') df9=ztq.tq_usrPoolsMerge(qx) print('\n#8.2,dat,cut') df2=zdat.df_kcut8tim(df9,'',tim0Str,tim9Str) zt.prDF('\n#df2',df2) print('\n#8.3,rebase') dfx=df2.rebase() zt.prDF('\n#dfx',dfx) print('\n#8.4,plot,rebase') dfx.plot()