From: Laurent Michaud on
Hello community,

I'm using a Nelson-Siegel parametrization in order to estimate the US government yield curve and I have a problem with fmincon in a loop. At each date t, I have to minimize squared residuals between observed and theoretical yields, so this expression in comprised in own-built function. Furthermore, in my main program I have set a loop which goes this way t=1:size(data) and this loop is meant to include fmincon (that must minimize residuals for each date t). So the loop must run fmincon for each t and fmincon is a minimization of a function with the same shape for each date but whose underlying data change for each date t.

I tried everything but it seems that fmincon is not used in the loop.

Thanks geniuses.
From: Gabo on
Laurent,

Nelson-Siegel models are available off-the-shelf in the Fixed-Income Toolbox:

http://www.mathworks.com/access/helpdesk/help/toolbox/finfixed/fitnelsonsiegelirfunctioncurve.html

If you don't have access to this toolbox, this contribution in the File Exchange may be useful to you:

http://www.mathworks.com/matlabcentral/fileexchange/18160-evaluate-nelson-siegel-function

Now, I don't quite understand what the problem in your code is. I believe the loop you have is over historical data, and for each date you have a full yield curve that you want to approximate with a Nelson-Siegel model. I don't see why the solver wouln't work. You just need to make sure that the data is updated at each iteration before you call the solver, and that the solution you obtain for each date is stored before you move to the next iteration. Keep in mind that you can also use lsqnonlin, which may be simpler to use. Lsqnonlin only takes bound constraints, but it's still useful for Nelson-Siegel with a little bit of algebra.

I hope this helps,
Gabo