how to define a maximum likelihood through @

1 view (last 30 days)
Hi!
I am minimizing a negative maximum likelihood with fmincon. The function is
function [neg_likelihood]=nlh_garchmidasLOG2p(parameter,g1,K,r,X)
% this is negative likihood function
miu=parameter(1);
alpha=parameter(2);
beta=parameter(3);
theta=parameter(4);
w1=parameter(5);
w2=parameter(6);
m=parameter(7);
[T,C]=size(r);
% tau series construction -----------------------------------------------
tau = exp( m + theta * ( X * betapolyn2(K,[(K-1):-1:1]',w1,w2)) ); % function of theta and w
% -----------------------------------------------------------------------
% tau_zero=find(tau<=0);
% L_zero=length(tau_zero);
% if L_zero >0
% tau(tau_zero);
% parameter
% stop
% else
% end
% g series construction --------------------------------------------------
g=zeros(T,1);
g(1)=g1;
for i=2:T
g(i)=(1-alpha-beta)...
+ alpha * ( (r(i-1)-miu)^2 ) / tau(i-1)...
+ beta * g(i-1);
end
% ------------------------------------------------------------------------
% negative likelihood function --------------------------------------
neg_likelihood= T/2*log(2*pi) + (1/2)*sum( ((r-miu).^2)./(tau.*g) ) + (1/2)*sum( log(tau.*g) );
end
Unfortunately fmincon does not produce an accurate hessian, so I am trying to use the function hessian
[hess,err] = hessian(fun,x0)
where fun is the likelihood and x0 is the point from which the function returns the hessian and is composed by the values of the parameters of fun (which in my previous function were 'parameter').
but the problem is that fun must be defined with @ and I don't know how to create it because I find quite complicated the form of the likelihood given that it has parameters and data. Can someone kindly give me an advice and/or show me how to create the likelihood in this other way? Thanks in advance.
Alberto

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!