2

I'm trying to estimate the parameters of the following function:

u = log(x) - ω - φ*(log(h)) - δ1*z - δ2*(z^2-1)

I'm using the function fminsearch in matlab with the following codes:

data = xlsread('return_oc_out.xlsx');
a = data(:,25);

kernel = xlsread('RK_out.xlsx');
rkAA= kernel(:,25);

startingVals = [0.1 0.05 0.9 0.3];
T = size(a,1);

options = optimset('fminsearch');
options.Display = 'iter';
estimates = fminsearch(@residuiRK, startingVals, options, rkAA, h, a);
[ll, lls, u]=residuiRK(estimates, rkAA, h, a);

the function residuiRK has the following code:

function [ll, lls, u] = residuiRK(parameters, x_rk, h, data)
omega = parameters(1);
phi = parameters(2);
delta1 = parameters(3);
delta2 = parameters(4);

mu = mean(data);
T = size(data,1);
eps = data-mu;
z= eps./sqrt(exp(h));

lxRK=log(x_rk);
u = zeros(T,1);
for t = 1:T 
u(t) = lxRK(t) - omega - phi*h(t) - delta1*z(t) - delta2*(z(t).^2-1);
end 
lls = 0.5*(log(2*pi) + log(exp(h))+eps.^2./exp(h));
ll = sum(lls);

The problem is: the fminsearch returns the estimated parameters equal to the starting values that I insert. Why there is this problem? I will be very grateful if someone could explain it. Thank you

1 Answers1

0

You should call your function like

[estimates, ~, exitflag, output] = fminsearch(...)

to diagnose your function call. exitflag should be 1 if the tolerance was reached, otherwise something wrong happened. output is a structure that you can consult to see the run summary of your fminsearch() call.

Also, your function call seems weird. You want to optimize over the parameters argument of residuiRK function, right? Then, why not passing the rest of arguments to your fminsearch minimized function? Like this:

estimates = fminsearch(@(x) residuiRK(x,rkAA,h,a), startingVals, options);

Later edit

So, based on the new info, apparently the exitflag of fminsearch() call is 1. Which means that the maximum coordinate difference between current best point and other points in simplex is less than or equal to options.TolX, and corresponding difference in function values is less than or equal to options.TolFun.

Your function might vary too slowly around startingVal. You could try to increase/decrease your tolerances. This can be done by modifying the options struct:

options = optimset('fminsearch');
options.Display = 'iter';
options.TolX = <some number>   % the default value is 0.0001
options.TolFun = <some number> % the default value is 0.0001

Try different values an see what happens to your values. If nothing happens, then apparently you guessed the minimum's position from the start. :-)

  • CST-link I had diagnose the fminsearch with exitflag and it results to be 1. I want to estimate the parameters of the function ResiduiRK and then, put into the function ResiduiRK the estimated parameters to have the residuals of the function. I tried with your last code but it doesn't work – user3553802 Jun 26 '14 at 12:57
  • @user3553802 It doesn't work as in "it throws an error" or it doesn't work as in "it gives the same parameters back"? –  Jun 26 '14 at 13:02
  • CST-link it gives this error : Error in ==> fminsearch at 205 fv(:,1) = funfcn(x,varargin{:}); – user3553802 Jun 26 '14 at 13:20
  • @user3553802 Modified my answer with some more suggestions. –  Jun 26 '14 at 13:36
  • I tried to modify with your suggestions but I still have the same problem.. The estimates are always the same of the starting values :( – user3553802 Jun 26 '14 at 13:58
  • Any values I impose in option.TolX and option.TolFun don't change the estimates and the message is that the x satisfies the termination criteria and the F(x) satisfies the convergence criteria. Maybe the problem is another.. – user3553802 Jun 26 '14 at 14:06
  • @user3553802 Sorry. Without some data with which I can see how `residuiRK` works, I'm afraid my "guessing game" is not a very good one. :-) –  Jun 26 '14 at 14:14