Creating a Likelihood Function
- From: david.grad@xxxxxxxxx
- Date: 10 Jul 2006 14:33:28 -0700
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)
.
- Follow-Ups:
- Re: Creating a Likelihood Function
- From: Arthur
- Re: Creating a Likelihood Function
- Prev by Date: input filename automatically
- Next by Date: Re: interfacing parallel port
- Previous by thread: input filename automatically
- Next by thread: Re: Creating a Likelihood Function
- Index(es):
Relevant Pages
|
Loading