1
$\begingroup$

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)
est=constrOptim(c(0.0000029,0.095,0.0888),LogLik, grad=NULL, ui,ci,hessian=TRUE)
$\endgroup$
3
  • 1
    $\begingroup$ Can you tell a bit more about your setup? It seems to me that any positive value should be in the permitted region. $\endgroup$ – Bob Jansen Mar 12 '16 at 17:08
  • $\begingroup$ 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. $\endgroup$ – Nils Mar 13 '16 at 10:20
  • 1
    $\begingroup$ 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. $\endgroup$ – Bob Jansen Mar 13 '16 at 12:57
1
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ I'm trying an garch(1,1) estimation on the Dax to forecast the volatility. $\endgroup$ – Nils Mar 14 '16 at 10:04
  • $\begingroup$ OK, and what are you using as the source of these formulas? Did you derive them yourself? $\endgroup$ – Bob Jansen Mar 14 '16 at 10:06
  • $\begingroup$ The formulas can be found in every text about which is about an introduction in econometrics. This is where I found them. $\endgroup$ – Nils Mar 14 '16 at 12:36
  • $\begingroup$ Not in mine, which book are you using? These details can matter. $\endgroup$ – Bob Jansen Mar 14 '16 at 12:42
  • $\begingroup$ @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). $\endgroup$ – Ric Jul 12 '16 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.