1

我试图使用 EWMA 模型预测波动性。我有回报(t-1)和方差(t-1)。n 是天数。对于每个蒙特卡罗模拟 N:

  • t=1:使用以下方法预测方差:var(t+1)=(1-λ)*return(t-1)**2 + λ*variance(t-1) 然后计算 y(t+1)=sqrt (var(t+1))*高斯(0,1.0)

  • t=2:预测 var(t+2)=(1-λ)*y(t+1) + λ * var(t+1)

  • 继续该过程直到 t=n。

然后获得一个(n,N)矩阵,取平均列,以获得平均每日方差。

我想将模拟应用到的数据框:

Date
2015-01-02    0.005735
2015-01-05   -0.024288
2015-01-06    0.007963
2015-01-07    0.005912
2015-01-08    0.011647

代码:

def MC_simulation(y):
    sim_df=pd.DataFrame
    l=0.94
    simulations= 1000
    count=0
    v=df1['variance'][-1]
    v_list=[]
    y_list=[]
    v1=(1 - l)*(y**2) + (l*v)
    v_list.append(v1)
    y1=sqrt(v1)*gauss(0,1.0)
    y_list.append(y1)

for t in range(simulations):

    v1=(1-l)*(y_list[count]**2) + l * v_list[count]
    y1=sqrt(v1)*gauss(0,1.0)
    v_list.append(v1)
    y_list.append(y1)
    count +=1
sim_df= (sum(v_list)/simulations)
return sim_df

def annu(x):
   return x*252

df3=pd.DataFrame()
df3=df1['ret'].apply(MC_simulation)
df3=df3.apply(annu)
df3=df3.to_frame()
df3=df3.rolling(window=63,center=False).mean()
df3=df3.apply(np.sqrt)

图: realized_vol 与预测

我运行此代码的结果似乎不正确。当我将它与已实现的波动性进行对比时,它完全消失了。我确定我的循环是错误的,但我无法弄清楚。

4

0 回答 0