1 year ago
#365310
gillesfg
fmincon function in Matlab
I wrote the following formula in order to solve a minimization problem. But when I run the code, I always get the following error:
Error using barrier Objective function is undefined at initial point. Fmincon cannot continue.
function out = Objectivefunction(x,r,q,K,T,S0,type,marketprice)
%loss function to find optimal heston parameters
%rho = x(5);
%kappa = x(2);
%theta = x(4);
%eta = x(3);
%vol0 = x(1);
%sigma0 = sqrt(vol0);
integration_rule = 1;
Price = zeros(length(T),1);
diffr = zeros(length(T),1);
%FFTCarrMadanHeston(kappa, eta, theta, rho, sigma0, K, T, S0, r, q, type, integrationrule)
%price using FFT
for t = 1:length(T)
Price(t,:) = FFTCarrMadanHeston(x(2), x(3), x(4), x(5), sqrt(x(1)), K(t), T(t), S0, r(t), q, type(t), integration_rule);
diffr(t,:) = marketprice(t) - Price(t);
%diffr(t,:) = (abs(marketprice(t) - Price(t)))/Price(t);
end
out = sqrt(sum((diffr).^2)/length(marketprice));
end
% calibration
v0 = 0.0654; %
kappa0 = 0.6067;
eta0 = 0.0707;
theta0 = 0.2928;
rho0 = -0.7571;
x0 = [v0,kappa0,eta0,theta0,rho0];
x0;
% computation of the interest rate for each maturity
r = spline(interest_rate(:,1), interest_rate(:,2), T);
T = T/360; % maturity in years
%calibration parameters
A = [];
b = [];
Aeq = [];
beq = [];
e = 1e-5;
lb = [e e e e -.999]; % Lower bound on the estimates
ub = [100 10 10 10 .999]; % Upper bound on the estimates
optimpar = fmincon(@(x)Objectivefunction(x,r,q,K,T,S0,type,marketprice), x0, A,b, Aeq, beq, lb, ub);
I do get an outcome when I calculate the value of the objective function in the intitial point. However, once I do it in the fmincon function , it doesn't work anymore
matlab
optimization
calibration
0 Answers
Your Answer