[R] Optim (fct): Parameters=LowerBounds!?

barb mainzel89 at hotmail.com
Mon Apr 30 17:30:24 CEST 2012


Hey,

i am trying to do the MLE for Garch and have a problem with the optim
function. 

Initally i tried optim with Method=BFGS. Reading trhough the forum i found
out 
i would neet bounds. So i went on with Method=L-BFGS-B.
But now my parameters equal the lower bounds. 

> out <- optim(par=initial, fn=LogLik.GARCH,X=X, P=1, Q=1, method =
> "L-BFGS-B",lower =c(0.01,0.01,0.01), upper =c(0.99,0.99,0.99))
> out
-----------------------------------
*$par
[1] 0.01 0.01 0.01*
[...]
$convergence
[1] 0

*$message
[1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <=
PGTOL"*-----------------------------------



I got the Logli from
"http://www-wiwi.uni-regensburg.de/images/institute/vwl/tschernig/lehre/I_Optimization.R"
[[elided Hotmail spam]]
{
c <- PAR[1]          # Konstante in GARCH Gleichung
a <- PAR[2:(P+1)]          # ARCH Parameter
g <- PAR[(P+2):(P+Q+1)]    # GARCH Parameter

n <- length(X)       # Stichprobengröße
h_sq <- rep(var(X),n)      # Vektor der bedingten Varianzen (am Anfang:
unbedingte Var.)
ll <- numeric(n)           # Vektor der (MINUS) Log Likelihoods pro
Beobachtung

# Unzulässige Parameterwerte ausschließen (-> Inf als Wert)
if (sum(a)+sum(g)>1) return(NA) # Instabil -> nicht zugelassen
if (any(PAR<0)) return(NA)      # Nichtnegativität verletzt -> nicht
zugelassen

# Iterativ Bedingte Varianz und minus Likelihood berechnen
for (i in (max(P,Q)+1):n)  {
    h_sq[i] <- c+sum(X[i-(1:P)]^2*a)+sum(h_sq[i-(1:Q)]*g)
    ll[i] <- -0.5*(log(2*pi)+log(h_sq[i])+X[i]^2/h_sq[i])     # minus
Likelihood
 }

# Bedingte Varianzen im Global Environment speichern 
h_sq <<- h_sq

# Funktionswert = Log Likelihood
return(sum(ll))
}



--
View this message in context: http://r.789695.n4.nabble.com/Optim-fct-Parameters-LowerBounds-tp4598504.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list