输入参数为([50,28],[60,30],[0.04,0.05],[1,1],[4.02,3.66],[1,1]),想要得到两个价格的值,但是为什么输出却什么都没有呢?!
function [implied_volstility,step] =solveForVolViaBisection(S,K,r,T,P,c_p)
%Difine the d1 and d2 formulas of Black-Scholes Model.
d1=@(S,K,r,T,sigma)(log(S./K)+(r+sigma.^2./2).*T)./(sigma.*sqrt(T));
d2=@(S,K,r,T,sigma)d1(S,K,r,T,sigma)-sigma.*sqrt(T);
%Difine the call price formula of Black-Scholes Model.
Call_price=@(S,K,r,T,sigma)S.*normcdf(d1(S,K,r,T,sigma))-K.*exp(-r.*T).*normcdf(d2(S,K,r,T,sigma));
%Difine the put price formula of Black-Scholes Model.
Put_price=@(S,K,r,T,sigma)K.*exp(-r.*T).*normcdf(-d2(S,K,r,T,sigma))-S.*normcdf(-d1(S,K,r,T,sigma));
if (c_p==1)
optVol=@(sigma) Call_price(S,K,r,T,sigma);
else
optVol=@(sigma) Put_price(S,K,r,T,sigma);
end
low=-100000000;
high=100000000;
tolerance=.000000001;
for i = 1:1000;
mid=(low+high)./2;
delta = optVol(mid)-P;
if delta<zeros(size(P))
low=mid;
else
high=mid;
end
mid=(low+high)./2;
delta = optVol(mid)-P;
if(abs(delta) < tolerance)
implied_volstility=mid
step=i
break;
% method has converged sufficiently; we are done
end
end
end
matlab 输入参数为矩阵后,程序没有结果,为什么呢??
答案:1 悬赏:60 手机版
解决时间 2021-03-20 10:28
- 提问者网友:富士山上尢
- 2021-03-19 17:45
最佳答案
- 五星知识达人网友:三千妖杀
- 2021-03-19 18:36
运行提示:Output argument "implied_volstility" (and maybe others) not assigned during call to "solveForVolViaBisection".
从程序看,输出implied_volstility在程序结束时,没有赋值。程序中虽有
if(abs(delta) < tolerance)
implied_volstility=mid;
step=i;
break;
% method has converged sufficiently; we are done
end
但条件没有满足,没执行。
从程序看,输出implied_volstility在程序结束时,没有赋值。程序中虽有
if(abs(delta) < tolerance)
implied_volstility=mid;
step=i;
break;
% method has converged sufficiently; we are done
end
但条件没有满足,没执行。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯