Please help with fmincon function
이전 댓글 표시
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
end
yt = 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);
end
sqrtht = 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.
댓글 수: 4
dav
2013년 11월 10일
the cyclist
2013년 11월 10일
I suggest you edit your question to give it a more meaningful title that might catch the eye of someone who knows about these functions.
dav
2013년 11월 10일
If my code works fine I should get estimates 0.1 and 0.4 ( which I used to create the data)
What happens when you run fmincon with 0.1 and 0.4 as your initial guess? What is the final value for opt in that case and what was it for
theta =
0.0002
-13.4557
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!