r - Maximum likelihood estimation for ARMA(1,1)-GARCH(1,1) -
following standard textbooks on arma(1,1)-garch(1,1) (e.g. ruey tsay's analysis of financial time series), try write r program estimate key parameters of arma(1,1)-garch(1,1) model intel's stock returns. random reason, cannot decipher wrong r program. r package fgarch gives me answer, customized function not seem produce same result.
i build r program helps estimate baseline arma(1,1)-garch(1,1) model. adapt baseline script fit different garch variants (e.g. egarch, ngarch, , tgarch). appreciated if provide guidance in case. code below r script estimating 6 parameters of arma(1,1)-garch(1,1) model intel's stock returns. @ rate, glad know thoughts , insights. if have similar example, please feel free share extant code in r. many in advance.
emily
# r script offers suite of functions estimating volatility dynamics based on standard arma(1,1)-garch(1,1) model , variants. # baseline arma(1,1) model characterizes dynamic evolution of return generating process. # baseline garch(1,1) model depicts the return volatility dynamics on time. # can extend garch(1,1) volatility model variety of alternative specifications capture potential asymmetry better comparison: # garch(1,1), egarch(1,1), ngarch(1,1), , 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 (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) (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) # record end time , calculate total runtime 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) finish running r program",sep="")) maximum_likelihood_fit_arma11_garch11 sqrt(diag(solve(maximum_likelihood_fit_arma11_garch11$hessian)))
Comments
Post a Comment