Hi,
I am trying to estimate parameters of an arch model using MLE.
If my code works fine I should get estimates 0.1 and 0.4 ( which I used to create the data)
However, I am having some issues and the estimates I get are wrong.
Can someone help me with this please. Given below are the codes I used.
% data generation
clc;clear;p=1;T = 3000;ra = zeros(T+2000,1);seed=123;rng(seed);ra = randn(T+2000,1); epsi=zeros(T+2000,1);simsig=zeros(T+2000,1);a0=0.1; a1=0.4;unvar = a0/(1-a1);for i = 1:T+2000 if (i==1) simsig(i) = a0+a1*((a0)/(1-a1)); s=(simsig(i))^0.5; epsi(i) = ra(i) * s; else simsig(i) = a0+ a1*(epsi(i-1))^2; s=(simsig(i))^0.5; epsi(i) = ra(i)* s; end endyt = epsi(2001:T+2000);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ESTIMATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
theta0 = [1;1];A=[0 1];b=0.99999;[theta, opt] = fmincon(@(theta)... lach(theta,yt),theta0,A,b,[],[],0,1);% function lach
function L = lach(theta,y)w = theta(1); alpha = theta(2);y2 = y.^2;[T1,K] = size(y2); ht = zeros(T1,1);ht(1) = sum(y2)/T1;for i=2:T1 ht(i)=w + alpha*y2(i-1);endsqrtht = sqrt(ht);x = y./sqrtht;l = -0.5*log(2*pi) - log(sqrtht) - 0.5*(x.^2);l=-l;L = sum(l);
Also, if you can kindly explain the difference between the following two ways of calling fmincon, that will be highly appreciated.
[theta, opt] = fmincon(@(theta)... lach(theta,yt),theta0,A,b,[],[],0,1);[theta, opt] = fmincon(@lach,theta0,A,b,[],[],0,1);
thanks
- When writing these codes I got some help from codes I found online.
Best Answer