[R-SIG-Finance] GARCH MIDAS model

Chris Urlaub Uniraf at gmail.com
Thu Apr 10 11:14:51 CEST 2014


Hi,

I'm trying to implement the GARCH MIDAS model proposed by Engle, Ghysels and
Sohn (2013) in R. Since I just started using R for programming I cannot find
out what's wrong with my programming code. After simulation I get the
following error messages:

Error in optim(param, loglikely, method = "BFGS", hessian = T) : 
  non-finite finite-difference value [4]
In addition: There were 50 or more warnings (use warnings() to see the first
50)

I don't know how to interpret this error messages and the warnings do not
help me either. 
For better understanding I post the code, I programmed. There I use beta
weightings, three lags and generated a mini artificial data set with 24
monthly return data and 8 quarterly unemployment rates.

###GARCH MIDAS###

################
###parameters###
################

y_mini = rnorm(24, 0.0004, 0.016)     # pseudo monthly returns
x_mini=c(0.3779791,3.1863575,-0.3611527,2.2541529,1.7124367,-2.6186178,0.7241506,
4.5503754) #pseudo quarterly data
mpq=length(y_mini)/length(x_mini) #months per quarter
N=length(y_mini) #number of months (i=1,...,24)
T_q=length(x_mini) #number of quarters  (t=1,...,8)
maxlag=4 #use actually 3 lags since the weight of the last lag is zero by
construction
#############################
###Log Likelyhood function###
#############################

loglikely=function(param){
  mu=param[1]
  alpha=param[2]
  beta=param[3]
  m=param[4]
  theta=param[5]
  w_1=param[6]
  w_2=param[7]
  
###beta weighting function###

  phi=phi_nominator=rep(0,maxlag)
  phi_denominator=0
  
  for (k in seq(1:maxlag)) {
    
   
phi_denominator=phi_denominator+((k/maxlag)^(param[6]-1))*((1-k/maxlag)^(param[7]-1))
    phi_nominator[k]=((k/maxlag)^(param[6]-1))*((1-k/maxlag)^(param[7]-1))
    
  }
  
  phi <<- phi_nominator/phi_denominator
  
###tau-specification###
  
  tau=rep(0,T)
  
  for (t in maxlag:T){
    
    tau_sum=rep(0,(maxlag-1))
    
    for (k in 1:(maxlag-1)){
      
      tau_sum[k] = phi[k]* x_mini[t-k]
    }
    
    tau[t]=param[4]+param[5]*sum(tau_sum)
  }
  tau<<-tau

###GARCH component###

  g=rep(0,N)
  g[(maxlag-1)*mpq]=1
  
  for(t in maxlag:T){
    
    for(i in ((t-1)*mpq):((t-1)*mpq+mpq-1)) {
      g[i + 1] <- (
        1-param[2]-param[3] +
          param[2] * (((y_mini[i] - param[1]) ^ 2)/tau[t]) +
          param[3]* g[i])
    }
  }
  g<<-g
  
##LL function##
  L=0
  
  for (t in maxlag:T){
    
    for(i in ((t-1)*mpq+1):((t-1)*mpq+mpq)) {
      
     
LL=-0.5*(log(2*pi)-0.5*log(g[i]*tau[t])-0.5*(((y_mini[i]-param[1])^2)/(g[i]*tau[t])))
      L=L+LL
    }
  }
L
}

### MLE ###
start = param= c(0.1,0.1,0.1,0.1,0.1,0.1,0.1)

estResults <- optim(param, loglikely, method="BFGS", hessian=T)
param <- estResults$par
hess <- estResults$hessian




Is anyone familiar with this and could give me a clue?

Any help would be appreciated!

Thanks,

Chris



--
View this message in context: http://r.789695.n4.nabble.com/GARCH-MIDAS-model-tp4688514.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list