alphas are ending up as not-a-number
techbackpack opened this issue · 5 comments
with certain option montages, the calculated value for the alphas is ending up NaN. this in turn is causing strange optimization behavior. most of the time the optimizer does not crash, however the warnings are continuously presented. on occasion the calibration routine halts completely. i have attempted a numerical analysis on the data but have had no luck so far.
the following code + workspace zip file will replicate the warning:
xoptP = lsqnonlin(@(x) Heston1993KahlJaeckelLordRev3(PC+1, S,K,T,t,r,q,x(1),x(2),x(3),x(4),x(5)) - MarketPrice(:,2),...
startparameters, ... %start values
... % v0,theta,rho,kappa,sigma
[ eps eps -1+eps eps eps ], ... % lower bound for parameter vector
[ 100 100 +1-eps 100 100 ], ... % upper bound for parameter vector
options);
optimizer status:
Norm of First-order
Iteration Func-count f(x) step optimality
0 6 836.793 1.1e+05
1 12 183.198 0.0511948 3.27e+04
2 18 19.5157 0.0481355 3.69e+03
3 24 13.8879 0.218201 2.43e+03
4 30 13.8879 0.418154 2.43e+03
5 36 8.22993 0.104539 434
6 42 4.2232 0.209077 124
7 48 1.37073 0.311223 53.4
8 54 0.827855 0.3201 41
9 60 0.53483 0.268784 27
10 66 0.278322 0.255432 10.2
Exiting fzero: aborting search for an interval containing a sign change
because NaN or Inf function value encountered during search.
(Function value at 1.71 is -Inf.)
Check function or try again with a different starting value.
349 warning(message('MATLAB:integral:NonFiniteValue'));
You could attempt a calibration using fminsearch instead of fzero (for the optimal alpha) or manually enter an alpha, but I haven't yet found away to properly calibrate for your (put?) option prices.
I have modified the file: Heston1993KahlJaeckelLordRev3.m to include an exception, please see:
if(isnan(alphas(ind)))
% using fzero here instead of fminsearch
alphas(ind) = fzero( @(a) psi(a,K(ind), F(ind), kappa, theta, rho, sigma, tau(ind), v0), alpha0,optimset('Display','off'));
end
if isnan(alphas(ind))
alphas(ind)=alpha0;
end
This appears to be mostly sufficient.
That's a possible fix. But did you succeed in calibrating for your option prices? I got very high RMSEs with a custom alpha.
At first I did not. Then I changed some of the parameter bounds and had better luck.
Also, I changed the fix to read:
if(isnan(alphas(ind)))
% using fzero here instead of fminsearch
try
alphas(ind) = fzero( @(a) psi(a,K(ind), F(ind), kappa, theta, rho, sigma, tau(ind), v0), alpha0,optimset('display','off'));
catch
alphas(ind)=alpha0;
end
Init params are set to:
[ v0 theta rho kappa sigma]
startparameters = [0.20^2 0.20^2 0.00 1.00 1.00];
[ eps eps -1+eps eps eps ], ... % lower bound for parameter vector
[ 100 100 +1-eps 100 100 ], ... % upper bound for parameter vector
Thanks for sharing! I added the try-catch clause to the function.