On Tue, 21 Feb 2012, Allin Cottrell wrote:
On Tue, 21 Feb 2012, Dan Běsoň wrote:
> I am trying to write a script for MLE estimation of a CARR model, similar
> to GARCH. It is a MEM model in daily ranges of some instrument, i,e,
>
> Eq. 1: lRng = lambda * epsilon # epsilon is exponentially distributed
> here, giving the shape of LL
> Eq. 2: lambda = a + b*Rng(-1) + c*lambda(-1)
>
> I tried the following code but the algorithm never converges. What should I
> improve?
> scalar a = 0.1
> scalar b = 0.4
> scalar c = 0.4
>
> mle ll = -ln(lambda) + Rng/lambda
Improve here: use the correct loglikelihood!
mle ll = -ln(lambda) - Rng/lambda
> series lambda = mean(Rng)
> series lambda = a + b*Rng(-1) + c*lambda(-1)
>
> params a b c
> end mle
You may also have to constrain all the parameter values to be positive, if
I'm reading the CARR literature correctly. In which case you could, for
example, express lambda as
exp(a) + exp(b)*Rng(-1) + exp(c)*lambda(-1).
Alternatively, you can wrap everything up into a function so that checking
is done automatically inside the function, as in
<hansl>
function series CarrLoglik(series y, matrix theta)
if minc(theta)<0
series ret = NA
else
scalar a = theta[1]
scalar b = theta[2]
scalar c = theta[3]
series lambda = mean(y)
series lambda = a + b * y(-1) + c * lambda(-1)
series ret = -ln(lambda) - y/lambda
endif
return ret
end function
param = {0.1;0.4;0.4}
mle ll = CarrLoglik(Rng, theta)
params theta
end mle
</hansl>
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti