LSQNONLIN does not iterate with multiple parameters

I use lsqnonlin to solve for three unknown parameters a0, a1, a2. However, it only takes one iteration and - independently of which initial parameters I choose - the initial values of x0 are also the solution (local minimum).
This is my lsqnonlin-solver code:
fun = @(x)myfun(x, r, S0, date, exdates, types, strikes, ImpliedVol, d, midprices)
x0 = [0.5 0.2 -0.03] % Problem holds for other intial values
x = lsqnonlin(fun,x0,[],[],options)
And this is the function to solve:
function F = myfun(x, r, S0, date, exdates, types, strikes, ImpliedVol, d, ...
midprices)
s = height(ImpliedVol);
a0 = repmat(x(1),s,1);
a1 = repmat(x(2),s,1);
a2 = repmat(x(3),s,1);
Vola = a0 + a1 .* ImpliedVol(:,2); + a2 .* (ImpliedVol(:,2).^2);
Vola(Vola < 0.01) = 0.01;
Vola(Vola > 1) = 1;
ImpliedVolData = [ImpliedVol Vola];
m = 1;
F(1) = optByLocalVolFD(r,S0,date,exdates(m,1),types(m,1),strikes(m,1),...
ImpliedVolData,...
'DividendYield',d,'InterpMethod','spline') - midprices(m,1);
m = 2;
F(2) = optByLocalVolFD(r,S0,date,exdates(m,1),types(m,1),strikes(m,1),...
ImpliedVolData,...
'DividendYield',d,'InterpMethod','spline') - midprices(m,1);
m = 3;
F(3) = optByLocalVolFD(r,S0,date,exdates(m,1),types(m,1),strikes(m,1),...
ImpliedVolData,...
'DividendYield',d,'InterpMethod','spline') - midprices(m,1);
m = 4;
F(4) = optByLocalVolFD(r,S0,date,exdates(m,1),types(m,1),strikes(m,1),...
ImpliedVolData,...
'DividendYield',d,'InterpMethod','spline') - midprices(m,1);
Interestingly, it will solve for only one unknown parameter, e.g.
ImpliedVolData = [ImpliedVol a0], x0 = 0.5
Any ideas, how I get lsqnonlin working to solve for three (or more) unknown parameters?

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Optimization Toolbox 的更多信息

产品

版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by