How does functions and lsqnonlin work?

1 Ansicht (letzte 30 Tage)
Martin
Martin am 6 Jun. 2012
I have created a code to calibrate option data to a mean-reverting model. It looks like this: _______________________________________________________________________
clear all
load('callopt.mat');
% K=strike, T=time to expiration in year fraction % Market=market option prices
K=callopt(:,3); T=callopt(:,2); market=callopt(:,10); r=0.01;
x0=(2 2 2 2);
[x,resnorm]=lsqnonlin(@(theta) myfun(theta,K,T,r,market),x02); ___________________________________________________________________
function F=myfun(theta,K,T,r,market)
bet=theta(1); rev=theta(2); V=theta(3); sig=theta(4);
vega=4*rev*bet/(sig^2);
gam=(4*bet)/((sig^2)*(1-exp(-bet*T)));
lambda=vega*exp(-bet*T)*V;
model=exp(-r.*T).*(exp(-bet.*T).*V.*ncx2cdf(gam.*K,vega+4,lambda))+rev.*(1-exp(-bet.*T)).*ncx2cdf(gam.*K,vega+2,lambda)-K.*ncx2cdf(gam.*K,vega,lambda);
F=(market-model);
___________________________________________________________________
The starting guess for my parameters are in x0. My problem is that no matter which number i input as the fourth number (that is the initial guess for sig), then when lsqnonlin is done the answer for sig is always the same as the initial guess. I have a feeling that maybe its because vega and gam is not recalculated for every iteration of lsqnonlin, seeing that sig only appears in vega and gam.
Can someone elaborate how the steps for lsqnonlin are, so that I can understand the process better?

Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by