0

I am running an optimization procedure using Fminsearch. It would be too complicated to post all the code here (and I cannot share everything for confidentiality), but I'll give a good description and hopefully you can give me some general ideas on why this issue is happening.

Basically, I have data on option prices and implied volatility for a given time period. Separately, I have divided this data into blocks of x weeks. For each of these blocks, I use fminsearch to solve for a set of x parameters that minimizes the mean-squared error of a very complicated function. Sorry that I cannot give more details here.

I have set the options as such:

`options = optimset('MaxFunEvals',5000, 'TolFun', 1e-2);`

When I run the fminsearch for each block, the code is:

[a,fval,exitflag,options] = fminsearch(fun,x0,options)

The problem is that the optimization always stops prematurely. It does not respect my set maximum number of iterations, nor my set tolerance level. It always exits before, with fval >> TolFun and number of iterations << MaxFunEvals.

If useful to know, the fminsearch is embedded within a defined function, which I call as I loop through the blocks of weeks:

function [mu,fval,exitflag,options] = estimate(mu_prev, strike, close, m, n, call_prices, x1, options)
    t2 = tic;
 
    pen_fun = @(x) ...;
    [a,fval,exitflag,options] = fminsearch(pen_fun,x1,options);
    toc(t2)

Any ideas?

I've tried to move the options within the loop or within the function, but to no avail

  • Have you looked at the outputs `exitflag` or `options` (note that the latter is overwriting your `optimset` options)? Those should tell you why `fminsearch` is exiting. Also, note that `'MaxFunEvals'` is a maximum, not a minimum, so it's natural for that not to be achieved if other exit conditions are met. Similarly, `'TolFun'` won't be met, if, for example, the default value of `'TolX'` is what results in exit. More [here](https://www.mathworks.com/help/matlab/math/setting-options.html#bt00l89-1). – horchler May 24 '23 at 12:22
  • It tells me "MaxFunEvals" condition met at 600, but I've set 5000 as max. – mirtilla May 24 '23 at 15:10
  • Based on MaxFunEvals, you have just few variables, correct? Few suggestions you can try: increase MaxIterations; use PlotFcns to see current value of variables, step size or other information. What are the typical values of variables? Your function might not be continuous and it might get stuck in a local minimum, so try different initial points or different optimization methods (global optimization). – Mario Malic May 25 '23 at 08:48
  • Thanks to both, I will spend a couple of days trying these iterations (each minimization is quite time-intensive) and will let you know. Thanks! – mirtilla May 26 '23 at 06:49

0 Answers0