Stdev = 样本标准偏差
Ln = 自然对数
Sqrt = 平方根
波动率指数 = Stdev(Ln(P1/P0), Ln(P2/P1), ..., Ln(P30/P29)) *Sqrt(365)
我想用这样的数据在代码中编写这个公式
|Date| |Twap|
0 2013-10-01 123.8187
1 2013-10-02 124.62557999999999
2 2013-10-03 110.758455
3 2013-10-04 113.2481625
.
.
.
118 2014-01-27 874.0466025000001
我试过了:
p = data[['Date','Twap']]
a=np.array([])
def volatility(x):
for i in range(30-1):
np.append(a,np.log(x['Twap'][i+1]/x['Twap'][i]))
p.rolling(window = 30).apply(volatility)
但我收到 KeyError: 'Twap' 我应该怎么做才能继续我的计算 抱歉,如果我的问题很幼稚,我不是程序员