Error using barrier - fmincon - Objective function is undefined at initial point. Fmincon cannot continue.

14 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 17 Feb 2021
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
Math O'Connor
Math O'Connor on 17 Feb 2021
Got the same error when trying to run it with x0 :
Error using barrier
Objective function is undefined at initial point.
Fmincon cannot continue.
Error in fmincon (line 848)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn,
...
Error in b (line 9)
x = fmincon(@(x)esgarch(x0,R),x0,[0 1 1 1],[1],[],[],[0,
0, 0, 0],[1000,1,1,1]);

Sign in to comment.

Answers (1)

Math O'Connor
Math O'Connor on 17 Feb 2021
You are absolutely right, but this is what gets me stumped. Basically I have the same data set for the model without leverage and everything is going fine.
My volatility gets updated through the function in the code, and in the leverage-less code, it never gets to sigma_0 = 0, which makes me divide by zero and get as you precised Inf.
So if my function is good, my data is the same, how could I maybe add some precision so I wouldn't maybe get 0, but 0.00000001 which would not yield a Inf value ?
I'm just throwing ideas to the wall, as I've been blocked by this.
  4 Comments
Math O'Connor
Math O'Connor on 17 Feb 2021
As I stated earlier though, the data works for the model without leverage, which makes me think that some values of theta yield a sigma_0 that = 0 and that is the major difference between the two model, as the rest is the same.
Walter Roberson
Walter Roberson on 17 Feb 2021
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.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!