As indicated by the title, I am using these codes to solve the question indicated above, so basically, there are two arrays, mid_call and strike that are iterated using i, and for each mid_call(i) and k(i), there should be a corresponding root, sigma. However, whenever I try to run the program, i always get this error:
Error using @(sigma, k) s.*normcdf((log(s./(q_tau.k))+tausigma.^2/2)./(sqrt(tau).*sigma)) - q_tau.*k.*normcdf(((log(s./(q_tau.k))+tausigma.^2/2)./(sqrt(tau).*sigma))-sqrt(tau).*sigma)- mid_call(i) Not enough input arguments
I will be forever grateful for your help!
Start of the code:
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
I know this is quite a long question but any help would be extremely appreciated!
d? I did not find it in your code. Also,fneeds to be called with two arguments,f = @(sigma, k). However, you only call it with one:f_lo = f(sigma_lo);, ' f_hi = f(sigma_hi);',f_new = f(sigma_new);. In all three cases,kis missing. - Nemesis