小弟初学MATLAB没几天,编了个算权证的公式,可是出现问题,出了inf,计算无法继续.请高手指点,见笑了.
function p = bs(r,t,sigma,s,x)
% This function calculates the value of
% Define varibales
% r--无风险利率 连续复利 单位:年
% t--权证到期时间
% sigma--标的股票波动率
% s--标的股票现价
% x--权证规定的执行价格
r = input('Enter the value of r: ');
t = input('Enter the valur of t: ');
sigma = input('Enter the value of sigma: ');
s = input('Enter the value of s: ');
x = input('Enter the value of x: ');
d1 = (log(s/x)+(r+sigma^2/2)*t)/sigma*sqrt(t)
d2= d1-sigma*sqrt(t)
p=x*exp(-r*t)*normcdf(-d2,0,1)-s*normcdf(-d1,0,1)
??? Input must be real.
Error in ==> erfc at 21
y = erfcore(x,1);
Error in ==> normcdf at 68
p = 0.5 * erfc(-z ./ sqrt(2));
Error in ==> bs at 16
p=x*exp(-r*t)*normcdf(-d2,0,1)-s*normcdf(-d1,0,1)