这是我的数据,我从20170101到20170106交易了三个符号 并记录每个符号重新获利。
label = ['symbol','date','relized']
list = [['S1','20170101',11111],['S1','20170102',12221],['S1','20170103',33445],['S2','20170102',-32421],['S2','20170103',-12211],['S2','20170104',9331],['S2','20170105',62211],['S2','20170106',92211],['S3','20170102',20444]]
df = pd.DataFrame(list,columns=label)
symbol date relized
0 S1 20170101 11111
1 S1 20170102 12221
2 S1 20170103 33445
3 S2 20170102 -32421
4 S2 20170103 -12211
5 S2 20170104 9331
6 S2 20170105 62211
7 S2 20170106 92211
8 S3 20170102 20444
所以,如果今天是20170103,那么总重新为33445 +( - 12211)+20444,
我想做的是,我的初始资本(参数名称:C)是500000,我想计算值R,公式是
R=Std(C + TodayTotalRelized,period=3Days)/Average(Std value of nearly 3 Day, period=3Days)
有什么好方法吗?
答案 0 :(得分:0)
您可以使用滚动功能。
df.rolling(windows=3).std()