Re: [R] Using nlminb for maximum likelihood estimation

2010-12-06 Thread Ben Bolker
Joonas - as_trix85 hotmail.com> writes: > > > I'm trying to estimate the parameters for GARCH(1,1) process. > Here's my code: > > loglikelihood <-function(theta) { > > h=((r[1]-theta[1])^2) > p=0 > > for (t in 2:length(r)) { > h=c(h,theta[2]+theta[3]*((r[t-1]-theta[1])^2)+theta[4]*h[t-1]) >

[R] Using nlminb for maximum likelihood estimation

2010-12-06 Thread Joonas - as_trix85
I'm trying to estimate the parameters for GARCH(1,1) process. Here's my code: loglikelihood <-function(theta) { h=((r[1]-theta[1])^2) p=0 for (t in 2:length(r)) { h=c(h,theta[2]+theta[3]*((r[t-1]-theta[1])^2)+theta[4]*h[t-1]) p=c(p,dnorm(r[t],theta[1],sqrt(h[t]),log=TRUE)) } -sum(p) } The