如标题所示,我正在使用这些代码来解决上面指出的问题,所以基本上,有两个数组,mid_call和strike,使用i迭代,对于每个mid_call(i)和k(i),应该有是相应的根,sigma。但是,每当我尝试运行该程序时,我总是会收到此错误:
使用@(sigma, k) s.*normcdf((log(s./(q_tau.k ))+tau sigma.^2/2)./(sqrt(tau).*sigma)) 时出错 - q_tau.* k.*normcdf(((log(s./(q_tau.k ))+tau sigma.^2/2)./(sqrt(tau).*sigma))-sqrt(tau).*sigma)- mid_call (i) 没有足够的输入参数
我将永远感谢您的帮助!
代码开始:
mid_call = 47.4350,37.7800,28.4400,19.6800,11.8800,5.6150,1.7250,0.3150,0.0600
iv_list = [];
tol = 1.e-8;
maxit = 50;
for i = 1:1:9
tau = 5/12;
q_tau = 1.0000;
s = 197.07;
strike = 150:10:230;
k = strike(i);
syms sigma;
d = @(sigma, k) (log(s./(q_tau.*k))+tau*sigma.^2/2)./(sqrt(tau).*sigma);
f = @(sigma, k) s.*normcdf((log(s./(q_tau.*k))+tau*sigma.^2/2)./(sqrt(tau).*sigma)) - q_tau.*k.*normcdf(((log(s./(q_tau.*k))+tau*sigma.^2/2)./(sqrt(tau).*sigma))-sqrt(tau).*sigma)- mid_call(i);
%starting value
sigma_lo = zeros(size(mid_call(i)));
sigma_hi = 10*ones(size(mid_call(i)));
f_lo = f(sigma_lo);
f_hi = f(sigma_hi);
% can we vectorize this?
if sign(f_lo)==sign(f_hi), disp('*** Error: solution not bracketed'), end
%let's rollllll
for it = 1:maxit
sigma_new = (sigma_lo + sigma_hi)/2; % cut interval in half
f_new = f(sigma_new);
diff_x = max(abs(sigma_lo - sigma_hi));
diff_f = max(abs(f_new));
[it sigma_new];
if max(diff_x,diff_f) < tol, break, end
if sign(f_new)==sign(f_lo)
sigma_lo = sigma_new;
f_lo = f_new;
else
sigma_hi = sigma_new;
f_hi = f_new;
end
end
iv_list(end+1) = sigma_new ;
end
我知道这是一个很长的问题,但任何帮助将不胜感激!