Calibrating VIX option data to model - lsqnonlin problem

5 views (last 30 days)
Im new to MatLab and in the process of learning it. Currently im trying to calibrate VIX option market data to Mean-reverting volatility process. To begin with im just trying to get an output without errors.
I have coded this script and the following function: ___________________________________________________________________________ clear all
global K; global T; global r; global market;
%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;
[x,resnorm]=lsqnonlin(@myfun,x0); ___________________________________________________________________________
function F=myfun(bet,rev,V,sig)
global K; global T; global r; global market;
F=(market-model); ___________________________________________________________________________
This is the complete error i receive: Error using myfun (line 5) Not enough input arguments.
Error in lsqnonlin (line 197) initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in meanrev (line 15) [x,resnorm]=lsqnonlin(@myfun,x0); Caused by: Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.
Can someone help?

Accepted Answer

Richard Crozier
Richard Crozier on 4 Jun 2012
lsqnonlin does not know that myfun takes 4 arguments, it expects it to just take one. You can get around this using an 'anonymous' function call like so:
[x,resnorm]=lsqnonlin(@(argthatchanges) myfun(argthatchanges,rev,V,sig), x0);
Note that I don't know which of your argument your actually solving for, so you may need to change about. Read about anonymous functions to understand better how this works.
Incidentally it is good programming practice to avoid the use of global variables unless absolutely necessary.
Martin on 5 Jun 2012
To the question regarding weights i guess i could just take sqrt(w_i)*(Market-Model) and then when running the lsqnonlin it would look as i want it?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by