Creating a Likelihood Function



Hi Everyone,

I'm trying to estimate a QGARCH-M(1,1) model via maximum likelihood
estimation. This is my first time using Matlab and I'm stuck on how to
construct my function. My problem is to maximize the likelihood
funtion

L=-log((k)-2*L*N(t))-0.5*T*log(2*pi)-0.5*log(h(t-1))-0.5*(N(t).^2)/h(t-1)

where N(t) is the error term associated with the time t observation and
is given by

N(t)=(1/(2*L))*((k)-sqrt((k)^2-4*L*(y(t)-mu-(gamma+L)*h(t-1))))

and h(t) is the variance at time t which is given by

h(t) = w + a*(N(t-1)-b)^2 + beta*h(t-1).

I have one 1355x1 matrix of data (which is log excess returns on
stocks, represented here by y(t), and I also need the parameters w,a
and beta to be positive.

I've been trying for a while to make the likelihood funtion. I then
minimize its negative by using the fmincon command and provinding
starting values for the parameters. Right now the problem I run into
is that every time I try to do this I get that the likelihood function
is equal to zero, regardless of the starting values. I can't find the
mistake in my code that's causing this. I'm attaching what I have in
the hopes that someone could help. If you could, it would be really
appreciated, I know it shouldn't be that hard but I've been trying to
figure it out for ages.
Thanks so much,
dave
******
function f = llhdjul10(x,y,h,N,k)
%This is going to be my log likelihood function. I have data on Y,
which
%is a 1355x1 matrix of time series observations (of log excess
returns).

%Here I'm trying to specify the inputs: the parameters in the x matrix
are
%the parameters to be estimated.

L=x(1);
gamma=x(2);
w=x(3);
a=x(4);
b=x(5);
mu=x(6);
beta=x(7);

y=csvread('returns.csv',1,0); %Read in the data
k=(1+2*L*b);
T=size(y,1);


%Introduce the likelihood function(f), the variance function h and the
%error term N:
f=0;
h=zeros(T,1);
N=zeros(T,1);

%I use the unconditional variance of the data as an initial guess for
the variance at time
%0:
h(1:1)=var(y);

%Then I try to create all other T-1 conditional variances:
for t=2:T
h(t)=[w;a;beta]'*[1;(N(t-1)-b)^2;h(t-1)];


%Now I try to make the N(t+1) function

N(t)=(1/(2*L))*((k)-sqrt((k)^2-4*L*(y(t)-mu-(gamma+L)*h(t-1))));

%Try to prevent negative square roots:
D=k^2-4*L*(y(t)-mu-(gamma+L)*h(t-1));
DD=k-2*L*N;
if D<=0
f=-200000000;
elseif DD<=0
f=-200000000;

%Finally, this is my likelihood function that I'm trying to maximize

f=f+log((k)-2*L*N(t))+0.5*T*log(2*pi)+0.5*log(h(t-1))+0.5*(N(t).^2)/h(t-1);
%I'm adding since this is the negative of the likelihood function

end
end
%Note that I have a matrix x0 in the data where I've specified starting
%values for the parameters.

******
I then run
[x,fval,exitflag]=fmincon('llhdjul10',x0,[],[],[],[],lb,[],[])

where lb=[-Inf;-Inf;0;0;-Inf;-Inf;0] (this is to ensue w,a,beta>0)

.



Relevant Pages

  • Re: Comparing fractions (or proportions)
    ... Jack´s response: ... their repective contributions to variance estimate ... What you have to do is to write out the likelihood ... The likelihood function is zero whenever ...
    (sci.stat.math)
  • Re: Linear regression with errors on x & y
    ... error variance, you can compute the ... is all a likelihood function is. ... Once done, compute the hessian matrix ... You can find fminsearchbnd here: ...
    (comp.soft-sys.matlab)
  • Re: Linear regression with errors on x & y
    ... John D'Errico wrote: ... error variance, you can compute the ... is all a likelihood function is. ... Once done, compute the hessian matrix ...
    (comp.soft-sys.matlab)
  • Problem about Variance Component Estimation
    ... effect while Q,G, E are random effect following normal distribution. ... I use REML and fisher scoring method to get the estimation of ... Variance Component first. ... information matrix and derivative of likelihood. ...
    (sci.stat.math)
  • Problem about Variance Component Estimation
    ... effect while Q,G, E are random effect following normal distribution. ... I use REML and fisher scoring method to get the estimation of ... Variance Component first. ... information matrix and derivative of likelihood. ...
    (sci.stat.math)

Loading