ARMA(1,1)-GARCH(1,1)的最大似然估计

时间:2013-04-05 07:21:16

标签: r optimization volatility

关于ARMA(1,1)-GARCH(1,1)的一些标准教科书(例如Ruey Tsay的金融时间序列分析),我尝试编写一个R程序来估计ARMA的关键参数(1, 1)-GARCH(1,1)模型,用于英特尔的股票收益。由于一些随机的原因,我无法破译我的R程序有什么问题。 R包fGarch已经给了我答案,但我的自定义函数似乎没有产生相同的结果。

我想建立一个R程序,帮助估计基线ARMA(1,1)-GARCH(1,1)模型。然后我想调整这个基线脚本以适应不同的GARCH变体(例如EGARCH,NGARCH和TGARCH)。如果您能在这种情况下提供一些指导,我将不胜感激。下面的代码是R脚本,用于估算英特尔股票收益的ARMA(1,1)-GARCH(1,1)模型的6个参数。无论如何,我很高兴知道你的想法和见解。如果您有类似的示例,请随时在R中分享您现有的代码。非常感谢您提前。

艾米丽

# This R script offers a suite of functions for estimating  the volatility dynamics based on the standard ARMA(1,1)-GARCH(1,1) model and its variants.
# The baseline ARMA(1,1) model characterizes the dynamic evolution of the return generating process. 
# The baseline GARCH(1,1) model depicts the the return volatility dynamics over time.
# We can extend the GARCH(1,1) volatility model to a variety of alternative specifications to capture the potential asymmetry for a better comparison:
# GARCH(1,1), EGARCH(1,1),  NGARCH(1,1), and TGARCH(1,1).

options(scipen=10)

intel= read.csv(file="intel.csv")
summary(intel)

raw_data= as.matrix(intel$logret)

library(fGarch)
garchFit(~arma(1,1)+garch(1,1), data=raw_data, trace=FALSE)


negative_log_likelihood_arma11_garch11=
function(theta, data)
{mean =theta[1]
 delta=theta[2]
 gamma=theta[3]
 omega=theta[4]
 alpha=theta[5]
 beta= theta[6]

 r= ts(data)
 n= length(r)

 u= vector(length=n)
 u= ts(u)
 u[1]= r[1]- mean

 for (t in 2:n)
 {u[t]= r[t]- mean- delta*r[t-1]- gamma*u[t-1]}

 h= vector(length=n)
 h= ts(h)
 h[1]= omega/(1-alpha-beta)

 for (t in 2:n)
 {h[t]= omega+ alpha*(u[t-1]^2)+ beta*h[t-1]}

 #return(-sum(dnorm(u[2:n], mean=mean, sd=sqrt(h[2:n]), log=TRUE)))
 pi=3.141592653589793238462643383279502884197169399375105820974944592
 return(-sum(-0.5*log(2*pi) -0.5*log(h[2:n]) -0.5*(u[2:n]^2)/h[2:n]))
}


#theta0=c(0, +0.78, -0.79, +0.0000018, +0.06, +0.93, 0.01)
theta0=rep(0.01,6)
negative_log_likelihood_arma11_garch11(theta=theta0, data=raw_data)


alpha= proc.time()
maximum_likelihood_fit_arma11_garch11=
nlm(negative_log_likelihood_arma11_garch11,
    p=theta0,
    data=raw_data,
    hessian=TRUE,
    iterlim=500)
#optim(theta0, 
#      negative_log_likelihood_arma11_garch11,
#      data=raw_data,
#      method="L-BFGS-B",
#      upper=c(+0.999999999999,+0.999999999999,+0.999999999999,0.999999999999,0.999999999999,0.999999999999),
#      lower=c(-0.999999999999,-0.999999999999,-0.999999999999,0.000000000001,0.000000000001,0.000000000001),
#      hessian=TRUE)

# We record the end time and calculate the total runtime for the above work.
omega= proc.time()
runtime= omega-alpha
zhours = floor(runtime/60/60)
zminutes=floor(runtime/60- zhours*60)
zseconds=floor(runtime- zhours*60*60- zminutes*60)
print(paste("It takes ",zhours,"hour(s)", zminutes," minute(s) ","and ", zseconds,"second(s) to finish running this R program",sep=""))


maximum_likelihood_fit_arma11_garch11

sqrt(diag(solve(maximum_likelihood_fit_arma11_garch11$hessian)))

0 个答案:

没有答案