1
votes

I have a problem with the lsqnonlin function in Octave.

My code:

% Heston calibration, local optimization (Matlab’s lsqnonlin)
% Input on data.txt
% Data = [So, t, k, r, mid price, bid, ask]
clear all
global data; global cost; global finalcost;
load data.txt
% Initial parameters and parameter bounds
% Bounds [v0, Vbar, vvol, rho, 2*a*vbar - vvol^2]
% Last bound include non-negativity constraint and bounds for mean-reversion
x0 = [.5,.5,1,-0.5,1];
lb = [0, 0, 0, -1, 0];
ub = [1, 1, 5, 1, 20];
% Optimization: calls function costf.m:
tic;
x = lsqnonlin(@costf,x0,lb,ub);
toc;
% Solution:
Heston_sol = [x(1), x(2), x(3), x(4), (x(5)+x(3)^2)/(2*x(2))]
x
min = finalcost

the problem occurs after calling :

x = lsqnonlin(@costf,x0,lb,ub);

it returns:

error: 'fields2cell' undefined near line 75 column 14 error: called from jacobian_constants at line 75 column 12 nonlin_residmin at line 413 column 5 nonlin_residmin at line 98 column 25 lsqnonlin at line 264 column 21

Has anyone already bumped into such a problem? If yes, how did you solve it?

1
fields2cell belongs to the struct package. It means that you need to install/upgrade and load the struct package. If it doesn't work upgrade your octave installation. - rahnema1

1 Answers

0
votes

I had the same error. Just had to reinstall the struct package:

pkg install -forge struct

I guess something was wrong with it.