Maximum Likelihood Function of GARCH model using "fmincon" function
Show older comments
Dear Members, I wants to maximize the likelihood function of my GARCH models using "fmincon" function to compare the resutls of garchfit function of Matlab. I write the following codes for this purpose. The codes are given below.
setting for generation of AR-GARCH series
ModelSpecification = garchset('C',.2,'K',0.2, 'GARCH',0.8,'ARCH',[0.15])
The simulation is done by this command
[e1, s1, r] = garchsim(ModelSpecification, 500,1 );
in above setting "r" is our simulated series with AR_GARCH the program for estimation of garch model is
function y=garchmodel(beta)
load r
n=size(r,1);
residuals=zeros(n,1);
residuals(1,1)=r(1,1)-beta(1,1);
sigma=zeros(n,1);
sigma(1,1)=.000000001;
for i=2:n
%rr=(r(i-1)-a)^2;
%sigma(i,1)=c0+c1*rr+c2*sigma(i-1,1);
%ll=ll+(-log(sigma(i,1)+rr/sigma(i,1)));
residuals(i,1)=r(i,1)-beta(1,1);
sigma(i,1)=sqrt(beta(2,1)+beta(3,1)*residuals(i)^2+beta(4,1)*sigma(i-1,1)^2);
end
ll1=-0.5 * ( log(2*pi*(sigma.^2)) + (residuals./sigma).^2 );
y=-sum(ll1);
after we use the "fmincon" function to estimate the parameters of interest by maximization our ll which is "y" with following settings.
function [mn, fv]=minimization1()
beta0=[.0001;.2;.02;0.0];
A = [zeros(1,2) ones(1,1) ones(1,1)];
b = .99;
lb=[-100;1e-10;0;0];
ub=[];
%options = struct('MaxFunEvals', 2000);
options=optimset('Algorithm','sqp','MaxFunEvals', 2000,'MaxIter',500,'Diagnostics','on','Hessian','user-supplied');
%opt = optimset('Display','iter');
[mn, fv]=fmincon(@garchmodel,beta0,A,b,[],[],lb,ub,[],options);
I try my best to find the error so that I can get answers close to the origional values that I have set during simulation of series 'r'
Please help me in this regards, Irfan Malik Pakistan
1 Comment
Answers (0)
Categories
Find more on Conditional Variance Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!