LSQNONLIN does not iterate with multiple parameters
Mostrar comentarios más antiguos
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?
Respuestas (0)
Categorías
Más información sobre Problem-Based Optimization Setup en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!