- When you create subjectval, ensure it properly accumulates the squared differences over all maturities. The way you are constructing subjectval inside the loop might be problematic because it doesn't seem to accumulate properly.
- You need to accumulate the squared differences in a way that subjectval remains a function of beta and sigma. Consider using a nested function or restructuring your code to handle this accumulation correctly.
- Make sure that subjectval is defined as a function that takes beta and sigma as inputs and returns a scalar value. This scalar value should be the sum of squared differences over all option maturities.
Fminsearch error: not enough input arguments.
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Prateekshya
on 8 Oct 2024
Hello Giuliano,
The error you are encountering, "Not enough input arguments," typically arises when MATLAB expects more inputs than are being provided. In your case, it seems the issue is related to how subjectval is being constructed and used within the fminsearch function.
Here is a breakdown of the potential issues and solutions:
Key Issues and Solutions:
I hope this helps!
0 Comments
Walter Roberson
on 8 Oct 2024
[y_ex,fval]=fminsearch(@(beta,sigma) subjectval(beta,sigma),y0)
fminsearch passes a single vector to the object function. You have coded a pair of values. You need something more like
[y_ex,fval]=fminsearch(@(betasigma) subjectval(betasigma(1),betasigma(2)),y0)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!