Error with fmincon- too many input arguments

Hello, could you please help me solve with this question. I have build a function to calculate the likelihood function of a heston model.
function [ vix_likelihood_heston ] = likelihood_heston(vix, para_heston )
%Calculate the likelihood function of vix model using heston model
n = length(vix);
L = zeros(n,1);
c = zeros(n,1);
u = zeros(n,1);
v = zeros(n,1);
J = zeros(n,1);
mu = zeros(n,1);
for i = 1:n
c(i) = (2*para_heston(1))/(para_heston(3)*(1 - exp ( - para_heston(1)* (vix(i,7)/360))));
u(i) = c(i) * vix(i,8) * exp(- para_heston(1) * (vix(i,7)/360));
v(i) = c(i) * vix(i,9);
q = (2 * para_heston(1) * para_heston(2)/(para_heston(3)^2))-1;
mu(i) = sqrt(4*u(i)*v(i));
J(i) = besselj(q,mu(i));
L(i) = log(c(i)*exp(-u(i)-v(i))*((v(i)/u(i))^(q/2))*J(i));
end
vix_likelihood_heston = -sum(L);
end
I have test the function with initial parameters and it did return the value.
When I try to use the fmincon:
para_hes = fminsearch(@likelihood_heston,para0_hes,[],[],[],[],vix_in);
It shows the error:
Error using likelihood_heston
Too many input arguments.
Error in fminsearch (line 200) fv(:,1) = funfcn(x,varargin{:});
My function is attached.
I want to ask how to solve this problem?
Many thanks

 Réponse acceptée

Stephan
Stephan le 30 Juil 2018
Modifié(e) : Stephan le 30 Juil 2018
Hi,
you want to use fmincon - which accepts the inputs:
x = fmincon(fun,x0,A,b)
x = fmincon(fun,x0,A,b,Aeq,beq)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
what could even work with your code, if you would not use fminsearch instead, which only accepts the inputs:
x = fminsearch(fun,x0)
x = fminsearch(fun,x0,options)
x = fminsearch(problem)
Since you work with this input:
para_hes = fminsearch(@likelihood_heston,para0_hes,[],[],[],[],vix_in);
it is a normal thing, that fminsearch doesnt like this.
Best regards
Stephan

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by