Error using barrier - fmincon - Objective function is undefined at initial point. Fmincon cannot continue.
14 次查看(过去 30 天)
显示 更早的评论
Hi there,
I've been implementing a MLE of a garch process to obtain the real values of the parameters in the model. All works fine, but whenever I had the leverage effect variable theta in my code, it gets me Error using barrier - Objective function is undefined at initial point. Fmincon cannot continue.
I'm pretty sure it has to do with the constraint in the fmincom function, but I've tried everything
Here's the code
clear all
clc
W = readtable('Chapter1Data.xls','Range','D4:D1257');
R = table2array(W);
x0 = [0.000005, 0.1, 0.85, 0.5];
x = fmincon(@(x)esgarch(x,R),x0,[0 1 1 1],[1],[],[],[0, 0, 0, 0],[1000,1,1,1]);
X = sprintf('Values of the estimated parameters : (omega, alpha, beta, theta) = (%8d %8d %8d %8d)', x(1),x(2),x(3),x(4));
disp(X)
function likelih = esgarch(xhat,R)
T = size(R,1);
sigma_0 = var(R);
omega = xhat(1);
alpha = xhat(2);
beta = xhat(3);
theta = xhat(4);
likelih = 0;
for j = 1 : T
likelih = likelih - 0.5 * log(sigma_0) - 0.5 * R(j,1)^2 / sigma_0;
sigma_0 = omega + alpha * (R(j,1)-theta*sigma_0)^2 + beta * sigma_0;
end
likelih = -likelih;
end
5 个评论
Walter Roberson
2021-2-17
Objective function is undefined at initial point. Fmincon cannot continue.
That message is ONLY given if the very first call to the function fails.
The initial point would have been moved to fit in the ub lb if needed, and to fit the linear constraints if needed. If you made a mistake in the constraints like wrong number of entries it would have said so. If no points fit the constraints it would have said so. The constraints are not your problem for this error message!
You get this error message if your function returns nan or inf or complex when it is run on the initial point x0. Try running your function on x0 and see what you get
回答(1 个)
Math O'Connor
2021-2-17
4 个评论
Walter Roberson
2021-2-17
In the code that runs you have
sigma_0 = omega + alpha * R(j)^2 + beta * sigma_0;
In the code that does not you have
sigma_0 = omega + alpha * (R(j,1)-theta*sigma_0)^2 + beta * sigma_0;
Notice the (R(j)-theta*sigma_0)^2 . Expand that out and you have
omega + alpha * R(j)^2 - 2*alpha*theta*sigma_0 + alpha*theta^2*sigma_0^2 + beta * sigma_0
%which is
omega + alpha * R(j)^2 + (beta - 2*alpha*theta) * sigma_0 + alpha*beta^2*sigma_0^2
If alpha*beta^2*sigma_0^2 > 1 then you have set up a feedback loop that will cause sigma_0 to grow in size according to its square.
Your initial alpha is 0.1, your initial beta is 0.85, so alpha*beta^2 is 0.07225 . But your sigma_0 = var(R ) is over 6000.
So... conditions are right for sigma_0 to expand rapidly. By the time you have reached the 8th datapoint, the (R(j,1)-thta*sigma_0)^2 reaches infinity.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!