Fminsearch error: not enough input arguments.

1 view (last 30 days)
First of all, thank you for taking the time to read this question. I am currently trying to calibrate my CEV model to the prices of quoted options to obtain the beta and the volatility of my stock.
Basically, this is my code. I'll explain what it does and what is the problem.
%% Part I
MSFTdata=xlsread('data.xls','option'); MSFTmaturity=MSFTdata(:,2); MSFTstrike=MSFTdata(:,3); MSFTmktprice=MSFTdata(:,4);
MSFTspot=37.81; ZCB_MSFT=zcb_CIR(0,MSFTmaturity,r0,mu,alpha,sigma); %auxiliary variable MSFTrf=-log(ZCB_MSFT)./MSFTmaturity; %risk free rate
%% Part II
% y=[beta sg] % option model prices subjectval=0; %minimizing function m=0; dy=linspace(0.4*MSFTspot,1.6*MSFTspot,xgridpoints);
Part III
for i=1:length(MSFTmaturity)
u=pdeCEVcallHandle(MSFTmaturity(i),xgridpoints,tgridpoints,MSFTspot,MSFTrf(i),MSFTstrike(i));
subjectval=@(beta,sigma) ( pdeval(m,dy,u( beta,sigma ) ,MSFTspot)-MSFTmktprice(i))^2+subjectval(beta,sigma);
end
Part IV
y0=[0.5, 0.2]; format long [y_ex,fval]=fminsearch(@(beta,sigma) subjectval(beta,sigma),y0)
Part I just creates some vectors and variables that I need afterwards.
Part II does the same, but subjectval is the function that I will need to minimize.
Part III is, in my opinion, the tricky one. Basically, pdeCEVcallHandle is a function that takes those parameters and returns a handle function. ( For example y=ax^2+bx+c. You insert a, b, c and obtain a function of x). I already verified if the function is defined correctly and it works perfectly. So does pdeval, which returns the price of a call option given those parameters. Now, subjectval is the function that I want to minimize, which has different pieces, hence the "for" cycle. Summing the pieces I should still obtain a handle function of the two variables beta and sigma.
Part IV simply defines initial conditions and minimizes the function. But this is where the error happens:
Error using @(beta,sigma)subjectval(beta,sigma) Not enough input arguments.
Error in fminsearch (line 191) fv(:,1) = funfcn(x,varargin{:});
I am positive the error is in this part of the program, because the rest works perfectly. Any idea what the problem is? I tried calculating subjectval inserting numbers instead of u(beta,sigma) and it gives a non-zero value. I'm completely clueless about what the error might be. Thank you very much for your time and support.
Giuliano

Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!