def bt_init(rdat, codLst, inxLst, tim0Str, tim9Str='', priceSgn='avg', prjNam='TQ01'): ''' [输入参数] rdat,数据目录,一般日线数据是 rdatCN='/zDat/cn/day/' codLst,股票池代码列表 inxLst,指数池代码列表 vlst,bt回溯初始化变量参数列表 [btTim0Str='',btTim9Str=''] ''' # #---set.bt.var # set time #qx.btTim0Str,qx.btTim9Str=vlst[0],vlst[1] qx = ztq.tq_init(rdat, codLst, inxLst, priceSgn, prjNam) #tq_init(rs0,codLst,inxLst=['000001'],priceSgn='avg',priceDFlag=True,prjNam='TQ001'): # # ztq.tq_pools_call(qx, bt_init_data) qx = bt_init_tim(qx, tim0Str, tim9Str) # #b2=ztq.tq_trdObjInit(qx,0) #qx.trdLib=qx.trdLib.append(b2.T,ignore_index=True) qx.trdLib = pd.DataFrame(columns=zsys.qx_trdName, index=['ID']) #所有交易记录清单列表 qx.trdLib.dropna(inplace=True) # qx.usrPools = {} #用户持有的股票资产数据 字典格式 # qx.usrMoney0, qx.usrMoney, qx.usrTotal = zsys.qx_bt_money0, zsys.qx_bt_money0, zsys.qx_bt_money0 qx.usrLevel = 5 qx.usrMoney0nil = qx.usrMoney0 * qx.usrLevel # #qx.trd_mode,qx.trd_nilFlag=1,False ztq.tq_usrPoolsInit(qx, addFg=False) # xtim, qx.trdCnt = qx.btTim0Str, 0 qx.trdLib = pd.DataFrame(columns=zsys.qx_trdName, index=['ID']) #所有交易记录清单列表 qx.trdLib.dropna(inplace=True) ''' r1=pd.Series(zsys.qx_trdNil,index=zsys.qx_trdName); r1['cash'],r1['time']=qx.usrMoney0,qx.btTim0Str r1['ID']=ztq.tq_usrIDSet(qx) qx.trdLib=qx.trdLib.append(r1.T,ignore_index=True) ''' #ztq.tq_usr2trdLib010(qx,xtim,'cash',0,0,0,qx.usrMoney0) # return qx
def bt_main_1day_pools(qx): ztq.tq_usrPoolsInit(qx, addFg=True) trdFg = False for xcod in qx.stkCodeLst: qx.wrkStkCod = xcod qx.wrkStkDat = qx.stkPools[xcod] # bt_main_1code(qx) if qx.wrkStkNum != 0: trdFg = True # if trdFg: ztq.tq_usr2trdLib(qx) # return qx
def bt_main(qx): #bt 8 code # #ztq.tq_pools_call(qx,bt_init_dadattmain_1day1code) # reverse 升序 qx.btTimLst.sort(reverse=False) for tc, xtim in enumerate(qx.btTimLst): #for xtim in range(qx.btTimLst): #xtim=qx.btTimLst[tc] print(tc, xtim) # qx.wrkTimStr, qx.wrkTim = xtim, arrow.get(xtim) # qx = bt_main_1day_pools(qx) # #ztq.tq_prTrdlib(qx) #ztq.tq_prUsrPools(qx.usrPools,'qx.usrPools') # ztq.tq_usrPoolsInit(qx, addFg=True) return qx