# Starting values for constrOptim() in R

I want to perform a constraint optimization for Maximum Likelihood Estimation in R to forecast volatility of returns. The probleme is that my initial values aren't in the permitted region. Is there something like an EM algorithm which I can use. Somebody an idea how to find the value region?

my code:

library(quantmod)
getSymbols('^GDAXI', src='yahoo', return.class='ts',from="2005-01-01", to="2015-01-31")
GDAXI.DE=GDAXI[ , "GDAXI.Close"]
log_r1=diff(log(GDAXI.DE[39:2575]))

sigma=matrix(nrow=length(log_r1)-1, ncol=1)
for(i in 2:length(log_r1))
{
sigma[i-1]=var(log_r1[1:i])
}

error=matrix(nrow=length(log_r1), ncol=1)
mu=mean(log_r1)
for(i in 1:length(log_r1))
{
error[i]=log_r1[i]-mu
}

sig=var(log_r1)
er=error
Sigma_garch=matrix(nrow=length(sigma), ncol=1)
garch=function(th)
{
omega.0=th[1]
alpha.0=th[2]
beta.0=th[3]
for(i in 1:length(sigma))
{
if(i==1)
{
Sigma_ga=sig
}else
{
Sigma_ga=Sigma_garch[i-1]
}
Sigma_garch[i]=omega.0+alpha.0*er[i]^2+beta.0*Sigma_ga
}
return(Sigma_garch)
}

LogLik=function(th)
{
input=garch(th)
sig=input
for(i in 1:length(sigma))
{
LL=(-1/2)*log(2*pi)-(1/2)*log(sig[i])-(1/2)*er[i]/sig[i]
}
}

ui=matrix(c(diag(1,3),c(0,(-1),(-1))),4,3, byrow = T)
ci=c(0.01,0,0,(-0.99))
theta=c(0.02,0.01,0.95)

• Can you tell a bit more about your setup? It seems to me that any positive value should be in the permitted region. – Bob Jansen Mar 12 '16 at 17:08
• I have a >= 0, b >= 0, w > 0 and a+b < 1. These are the garch specifications. I'm looking at return series. Now I Have to find starting values, but I don't know the region they are in. So need to find that region and don' know how. – Nils Mar 13 '16 at 10:20
• Please show your setup, this is pretty vague. I guess you could do worse than try $\alpha = 0.08, \beta = 0.90$ and $\omega = 0.01$ but it's just guessing. – Bob Jansen Mar 13 '16 at 12:57

Your Log Likelihood function LogLik doesn't work: 1) LL is reset every iteration and 2) the function doesn't return anything, you can try yourself:

> LogLik(c(0.0000029,0.095,0.0888))


This is the reason for the error given by constrOptim, it seems that the function doesn't give a value for the initial vector (or for any value).

I find your code a bit hard to follow and I'm not sure what you're trying to implement so it's hard to give further advice.

• I'm trying an garch(1,1) estimation on the Dax to forecast the volatility. – Nils Mar 14 '16 at 10:04
• OK, and what are you using as the source of these formulas? Did you derive them yourself? – Bob Jansen Mar 14 '16 at 10:06
• The formulas can be found in every text about which is about an introduction in econometrics. This is where I found them. – Nils Mar 14 '16 at 12:36
• Not in mine, which book are you using? These details can matter. – Bob Jansen Mar 14 '16 at 12:42
• @Nils your comment to Bob's attempt to help you is a bit sloppy. Provide details ... programming question are best asked in stackoverflow (but they are quite strict with sloppy questions). – Ric Jul 12 '16 at 6:41