首先,我使用GARCH(1,1)模型模拟数据。现在我想通过最大似然估计使用模拟数据的参数。我用Python编写了一个代码,但是当我运行它时,我获得了与初始化相同的参数值。希望可以有人帮帮我!! 这是我的代码:
###########################################################
### GenrGARCH(dOmega, dAlpha, dBeta, iN):
def GenrGARCH(dOmega, dAlpha, dBeta, iN):
dS2 = dOmega/(1 - dAlpha - dBeta)
vEps = np.random.normal(size=iN);
# Define Time Series Vector
vS2 = np.zeros_like(vEps);
vY = np.zeros_like(vEps);
# Estimation
for t in range(iN):
vY[t] = np.sqrt(dS2) * vEps[t]
vS2[t]= dS2
# Update
dS2 = dOmega + dAlpha * vY[t]**2 + dBeta * dS2
return (vY, vS2)
###########################################################
##### Estimate univariate GARCH(1,1)
def neg_loglike(theta, vY, vS2):
ll = -0.5*(np.log(2*np.pi)) - 0.5*(np.log(vS2)) - 0.5*(np.transpose(vY))**2/vS2;
llvalue = np.mean(ll)
return (theta, vY, vS2)
# Optimization Options
theta_start = np.array([0.1,0.05,0.94])
res = minimize(neg_loglike, theta_start, method = 'Nelder- Mead',
options={'disp': True})
###########################################################
### main
def main():
# Magic numbers
iN = 10000
dOmega = 0.1
dAlpha = 0.05
dBeta = 0.94
# Estimation
(vY, vS2)= GenrGARCH(dOmega, dAlpha, dBeta, iN)
# Output
Output(vY, vS2)
真的希望有人可以帮助我。谢谢!!