这是一个创建于 1538 天前的主题,其中的信息可能已经有所发展或是发生改变。
money = 0
stock=0
pos = 0
df_tst['pnl']=0
df_tst['trade_times']=0
df_tst['pos']=0
df_tst['stock']=0
df_tst['money']=0
pnl=0
tt=0
for i,n in df_tst.iterrows():
if n.deal>0:
tt = tt + 1
if pos>0:
pnl = pos*n.open - stock
if pos<0:
pnl = pos*n.open - stock
money = money + pos*n.open#平仓
stock = 0
pos = 0
pos = pos + 100
money = money - 100*n.open
df_tst.pos.loc[i] = pos
df_tst.pnl.loc[i] = pnl
df_tst.money.loc[i] = money
df_tst.stock.loc[i] = pos*n.open
df_tst.trade_times.loc[i] = tt
if n.deal<0:
tt = tt + 1
if pos<0:
pnl = pos*n.open - stock
if pos>0:
pnl = pos*n.open - stock
money = money + pos*n.open#平仓
stock = 0
pos = 0
pos = pos - 100
money = money + 100*n.open
df_tst.pos.loc[i] = pos
df_tst.pnl.loc[i] = pnl
df_tst.money.loc[i] = money
df_tst.stock.loc[i] = pos*n.open
df_tst.trade_times.loc[i] = tt
else:
if pos>0:
pnl = pos*n.open - stock
stock = pos*n.open
if pos<0:
pnl = pos*n.open - stock
stock = pos*n.open
df_tst.pos.loc[i] = pos
df_tst.pnl.loc[i] = pnl
df_tst.money.loc[i] = money
df_tst.stock.loc[i] = stock
df_tst.trade_times.loc[i] = tt
|
|
1
yellowtail 2020-09-08 10:31:42 +08:00
咋发出有格式的代码,捉急
|