Error using barrier. Objective function is undefined at initial point. Fmincon cannot continue.
이전 댓글 표시
Error using barrier. Objective function is undefined at initial point. Fmincon cannot continue.
Anyone can give me an idea how to solve it? Running code as attach. Thank you very much.
fit_S_powerAGARCH_N
%=========================================================================
% Estimating the standard AGARCH-X Models by QMLE
%=========================================================================
function fit_S_powerAGARCH_N( )
clear all
clc
addpath D:\work\Econometrics\econ
%ss = RandStream('mt19937ar','Seed',1);
%RandStream.setGlobalStream(ss);
rand('seed',00);
%data=xlsread('taux1.xlsx');
data=xlsread('empirics.xlsx');
y1=data(:,7);
%n=size(y1)
x1=data(:,8);
x2=data(:,9);
%n=size(x2)
x3=data(:,10);
%nn=size(x3)
delta=1.0;
%r1=100*price2ret(y1); r1=r1-mean(r1);
%r2=100*price2ret(y2);r2=r2-mean(r2);
%print -deps D:\Recherches\Log_PGarch\Gmail\plot9.eps
r=y1;
%options=optimset('MaxFunEvals',500,'Maxiter',500,'Display','iter');
ops = optimset( 'LargeScale','off','Display','off');
start=rand(1,7);%.25*[0.019 0.0450 0.115 0.872 2.943 0.051 0.028];%20.9*
[theta,lf1,~,~,~,hess]=fminunc(@(b) neglog(b,r,x1,x2,x3),start,ops)
a=real(theta)
h(1)=r(1);%2;%*sqrt(var(r));
%mu=mean(abs(r));
nobs=length(r);
for j = 2:nobs
%h(j)=exp(0.5*a(1))*(abs(r(j-1)))^a(2)*h(j-1)^a(3);
h(j) = a(1)+a(2)*(max(r(j-1),0)).^delta+a(3)*(max(-r(j-1),0)).^delta+a(4)*h(j-1)+a(5)*x1(j-1)+a(6)*x2(j-1)+a(7)*x3(j-1);
%h(j) = a(1)+(a(2)+a(3))*abs(r(j-1)).^delta+a(4)*h(j-1)+a(5)*x1(j-1)+a(6)*x2(j-1)+a(7)*x3(j-1);
end
plot(h)
hold on
plot(0.11*r.^2)
%print -deps D:\Recherches\Log_PGarch\Gmail\plot10.eps
%pause
%save('egarch100_d1.mat','theta1')
end
%-------------------------------------------------------------------------
% Likelihood function for a logGARCH(1,1) model
%-------------------------------------------------------------------------
function logt = neglog(b,y,m1,m2,m3)
%b = abs(b);
nobs = length(y);
%yy=yy';
delta=1.0;
v = y;
u1=m1;
u2=m2;
u3=m3;
h = abs(v)+log(2*abs(v)+1)+exp(2.5)*ones(nobs,1);
%h = 4*ones(nobs,1);
for j = 2:nobs
%h(j)=exp(0.5*b(1))*(abs(v(j-1)))^b(2)*h(j-1)^b(3);
h(j) = b(1)+b(2)*(max(v(j-1),0)).^delta+b(3)*(max(-v(j-1),0)).^delta+b(4)*h(j-1)+b(5)*m1(j-1)+b(6)*m2(j-1)+b(7)*m3(j-1);
%h(j) = b(1)+0.5*(b(2)+b(3))*abs(v(j-1)).^delta+b(4)*h(j-1)+b(5)*m1(j-1)+b(6)*m2(j-1)+b(7)*m3(j-1);
end
%logl= - 0.5*log(2*pi) - 0.5*log(h.^2) - 0.5*(v./h).^2;
logl = - 0.5.*log(2.*pi) -(1./delta).*log(h) - 0.5.*(v./(h).^(1./delta)).^2;
logt = -mean(logl);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Statistics and Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!