Error: Not enough input arguments. from (n1 = normcdf(d1.*CP);)
1 次查看(过去 30 天)
显示 更早的评论
function ab = debug
clear; clc;
N = 30000; % number of simulations
NC = 2; % number of options
T = 1/252; % Intial Time
S0=100; % Initial Stock Price
X = [1.2 0.8]*100; %Call and Put Options
M = [30 30]/252; %Time to maturity
H =[4 -1]; %Portfolio Weights
sigma = 0.0032;
r = 0.01;
mu = 0.2;
q = 0.0;
H0 = bs(S0, X, r, q, sigma, M) * H(1); % initial portfolio value S0=1
HP = bs(X, r, q, sigma, M) * H(2); % initial portfolio value S0=1
% errs = randn(N,1); % normal errors
errs = trnd(3,N,1)/sqrt(3); % t-distributed errors
ST =S0* exp(mu*T + sigma*sqrt(T)*errs); % final asset price
%ST= S0*exp(( mu-sigma^2/2)*T + sigma*sqrt(T)*errs);
C = zeros(N,NC);
P = zeros(N,NC);
for i=1:NC;
C(:,i) = bs(X(i)./ST,r,sigma,M(i)-T); % final put option values
P(:,i) = bs(X(i)./ST,r,sigma,M(i)-T); % final put option values
end
sims = C*H(1) + P*H(2);
VaR_S10=S0*sigma*norminv(0.1); %Stock Value at Risk
VaR_S5=S0*sigma*norminv(0.05);
VaR_S1=S0*sigma*norminv(0.01);
%H = bs(X, r, sigma, M) .* H / H0; % H is now portfolio _weights_
% Portfolio Delta for Call
H0Delta = bsdelta(X, r, sigma, M) * H(1); % initial portfolio delta
mP = H0 + H0 * mu * H0Delta * T;
sP = sqrt( H0.^2 * sigma.^2 * H0Delta.^2 * T);
DVaR10_c = mP + norminv(0.1) * sP;
DVaR5_c = mP + norminv(0.05) * sP;
DVaR1_c = mP + norminv(0.01) * sP;
%D_ES = mean(sims) > DVaR10;
%Portfolio Delta for Put
HPDelta = bsdelta(X, r, sigma, M) * H(2)'; % initial portfolio delta
mP = HP + HP * mu * H0Delta * T;
sP = sqrt( HP.^2 * sigma.^2 * HPDelta.^2 * T);
DVaR10_p = mP + norminv(0.1) * sP;
DVaR5_p = mP + norminv(0.05) * sP;
DVaR1_p = mP + norminv(0.01) * sP;
%D_ES = mean(sims) > DVaR10;
%
%PORTFOLIO DELTA
P_DVaR10=DVaR10_c + DVaR10_p;
P_DVaR5=DVaR5_c + DVaR5_p;
P_DVaR1=DVaR1_c + DVaR1_p;
% Portfolio delta-gamma Call
H0Gamma = bsgamma(X, r, sigma, M) * H(1); % initial portfolio gamma
mPG = mP + .5 * H0.^2 * sigma.^2 * H0Gamma *T;
sPG = sqrt( sP.^2 + .75 * H0.^4 * sigma.^4 * H0Gamma.^2 * T.^2 );
DGVaR10_c =mPG + norminv(0.1)*sPG;
DGVaR5_c = mPG + norminv(0.05)*sPG;
DGVaR1_c = mPG + norminv(0.01)*sPG;
%DG_ES = mean(sims) > DGVaR10;
%
% Portfolio delta-gamma Put
HPGamma = bsgamma(X, r, sigma, M) * H(2); % initial portfolio gamma
mPG = mP + .5 * HP.^2 * sigma.^2 * HPGamma *T;
sPG = sqrt( sP.^2 + .75 * HP.^4 * sigma.^4 * HPGamma.^2 * T.^2 );
DGVaR10_p =mPG + norminv(0.1)*sPG;
DGVaR5_p = mPG + norminv(0.05)*sPG;
DGVaR1_p = mPG + norminv(0.01)*sPG;
%DG_ES = mean(sims) > DGVaR10;
%PORTFOLIO DELTA-GAMMA
P_DGVaR10 = DGVaR10_c + DGVaR10_p;
P_DGVaR5 = DGVaR5_c + DGVaR5_p;
P_DGVaR1 = DGVaR1_c + DGVaR1_p;
% disp(' initial MC10%VaR MC5%VaR MC1%VaR')
% disp([H0, SimVaR10, SimVaR5, SimVaR1])
disp(' initial D10%VaR D5%VaR D1%VaR')
disp([H0, DVaR10, DVaR5, DVaR1])
disp(' initial DG10%VaR DG5%VaR DG1%VaR')
disp([H0, DGVaR10, DGVaR5, DGVaR1])
subplot(2,1,1);
normplot(sims); % normal distribution plot
%b = mP-3*sP:6*sP/100:mP+3*sP;
subplot(2,1,2);
hist(sims,100);
figure (2)
plot(sims);
xlabel('sample paths')
ylabel('ST')
% BLACK-SCHOLES FORMULA FOR CALL
function y = bs(S0, x, r, q, sig, t, CP)
% The simple Black-Scholes European call option Price
d1 = ( log(S0./x) + ( r-q + .5*sig.^2 ) .*t ) ./ sig ./sqrt(t);
d2 = d1 - sig.*sqrt(t);
n1 = normcdf(d1.*CP);
n2 = normcdf(d2.*CP);
y = CP.*(S0.*exp(-q.*t).*n1 - x.*exp(-r.*t).*n2);
%if(flag == -1)
%y = -y;
% elseif (flag == -1)
% y=x.*n2.*exp(-q.*t)-n1; %Put Option Price
%end
0 个评论
采纳的回答
Walter Roberson
2016-8-22
Your lines
H0 = bs(S0, X, r, q, sigma, M) * H(1); % initial portfolio value S0=1
HP = bs(X, r, q, sigma, M) * H(2); % initial portfolio value S0=1
call bs with first 6 and then 5 input arguments. But you have
function y = bs(S0, x, r, q, sig, t, CP)
so your function expects 7 input arguments. As soon as the function tries to use the value of the CP parameter you are going to have an error because you did not pass in enough parameters.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Portfolio Optimization and Asset Allocation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!