function [MLE,loglik,exitflag,output,lambda,grad,hessian] = MLAPDGARCH(par0);
global GARCH_SERIES;
% ML_APD_GARCH.M        Constructs the ML estimates for a GARCH(1,1) process 
%   with APD innovations:
%       Y[t] = mu + sig[t]*eta[t] where
%       sig[t]^2 = alpha0 + alpha1*sig[t-1]^2 + alpha2*(Y[t-1]-mu)^2 and
%       eta[t] is IID APD distributed with mean zero and unit variance (the pdf
%       of eta[t] is given by Equation (3) in Komunjer (2006))
%
% The objective function is APDGARCHLogLik.m.
%
% Inputs:    
%       GARCH_SERIES = GARCH(1,1) time series studied (GLOBAL variable)
%       par0 = starting values for the optimization
% Outputs:
%       MLE = estimates
%       loglik = optimal value of the log-likelihood (max of the vector function)
%       exitflag = CV code
%
% References:
%   [1] Komunjer, I. (2006): "Asymmetric Power Distribution: Theory and 
%   Applications to Risk Measurement", Journal of Applied Econometrics (forthcoming)
%
% Author: Ivana Komunjer - UCSD (komunjer@ucsd.edu)
% Version: 2.1        Date: 09/11/2006


options = optimset('Display','iter','MaxFunEvals',800,'TolCon',1e-6,'TolFun',1e-6);

% par = [alpha00; alpha10; alpha20; mu0; alpha0; lda0];
% Linear inequality constraints A.x <= b on the parameters of the model
delta = 0.0001; % some small number
A = zeros(10,6);
A(1,2) = -1;                % alpha1 > 0
A(2,2) = 1;                 % alpha1 < 1
A(3,3) = -1;                % alpha2 > 0
A(4,3) = 1;                 % alpha2 < 1
A(5,2) = 1; A(5,3) = 1;     % alpha1 + alpha2 < 1
A(6,1) = -1;                % alpha0 > 0
A(7,5) = -1;                % alphaAQ > 0
A(8,5) = 1;                 % alphaAQ < 1
A(9,6) = -1;                % ldaAQ > 0.5
A(10,6) = 1;                % ldaAQ < 5;
b = [-delta;1-delta;-delta;1-delta;1-delta;-1e-6;-delta;1-delta;-0.5-delta;5-delta];
[MLE,loglik,exitflag,output,lambda,grad,hessian] = ...
    fmincon(@APDGARCHLogLik,par0,A,b,[],[],[],[],[],options);

