Bonjour,
j'ai fait le programme d'optimisation suivant mais je n'arrive pas à avoir de résultat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| function F = myfun(lamda)
%--------------------------------------------------------------------------
% @description: Attempt to estimate the parameter of the market price
%model of yields. We do this by using curve fitting to the observed data.
%
% Xdata: - vector of times to maturity .
% ydata - vector of observed yields-to-maturity that correspond to
% the matching value by the yields-to-maturity correspinf to
% the vasicek model wich has the following form:
% R(T) = R(alpha) +(r0 - (beta - R(alpha)) *
% (1- exp (- beta*T))/ (beta *T) +
% ((sigma^2)*(1- exp (- beta*T))^2)/(4*(beta^3)*T).
%
%
%where R(alpha)= (beta - ((lamda * sigma)/ alpha)- ((sigma^2)/ (2*(alpha^2)))
% and T is time to maturity.
%
% xdata = [0.5 1 2 3 5 7 10];
% ydata =[0.079 0.0782 0.0791 0.0793 0.0791 0.0802 0.0798];
%--------------------------------------------------------------------------
xdata = [0.5 1 2 3 5 7 10];
ydata = [0.079 0.0782 0.0791 0.0793 0.0791 0.0802 0.0798];
alpha = 0.035364;
beta = 0.0713;
sigma = 0.0110;
r = 0.012;
Ralpha =@(lamda) (beta -(lamda*sigma)/alpha)-(sigma.^2)/(2*(alpha.^2));
F =@(lamda,xdata,alpha,beta,sigma,r) Ralpha(lamda) +...
((1-exp(-beta*xdata))./(beta*xdata))*(r - Ralpha(lamda))+...
((sigma.^2)./(4*(beta.^3)*xdata).*((1-exp(-xdata)).^2));
lamda0 = - 0.03; % initialisation of the parameter lamda%
[lamda,resnorm] = lsqnonlin(@myfun,lamda0); |
mais en tournant le programme le message d'erreur suivant s'affiche
??? Error using ==> blsprice at 98
Volatilities cannot be negative.
Error in ==> myfun at 2
z = blsprice(36.12,35,0.07,7/52,x) - 2.15;
Error in ==> lsqnonlin at 203
initVals.F = feval(funfcn{3},xCurrent,varargin{:});
Error in ==> fit2 at 44
[lamda,resnorm] = lsqnonlin(@myfun,lamda0);
Caused by:
Failure in initial user-supplied objective function evaluation. LSQNONLIN cannot continue.
je n'ai pas compris où est le problème. est ce que vous pouvez m'aider.
Partager