动态对冲跌落障碍期权

时间:2019-02-16 10:46:42

标签: options montecarlo portfolio simulate

我想通过计算向下和向外障碍看涨期权的近似复制投资组合并绘制理论和实际投资组合值来说明三角套期保值。

我制作了一个单独的函数来计算价格和期权的差额,并尝试生成实际值和理论值的图表。但是由于矩阵尺寸问题,我无法做到。我尝试使用“。^”和“。*”修复它们,但仍然无法正常工作。

%function for calculating the price and the delta
function [Cdao, Cdao_delta]= downAndOutV(S,E,r,sigma,B,T)
%tau > 0
tau=T;
power1 = -1+(2*r)/(sigma^2);
power2 = 1+(2*r)/(sigma^2);
d1 = (log(S/E)+(r+0.5*sigma^2)*(tau))/(sigma*sqrt(T));
d2 = d1-sigma*sqrt(T);
d3 = (log(S/B)+(r+0.5*sigma^2)*(T))/(sigma*sqrt(T));
d4 = (log(S/B)+(r-0.5*sigma^2)*(T))/(sigma*sqrt(T));
d5 = (log(S/B)-(r-0.5*sigma^2)*(T))/(sigma*sqrt(T));
d6 = (log(S/B)-(r+0.5*sigma^2)*(T))/(sigma*sqrt(T));
d7 = (log(E*S/(B^2))-(r-0.5*sigma^2)*(tau))/(sigma*sqrt(tau));
d8 = (log(E*S/(B^2))-(r+0.5*sigma^2)*(tau))/(sigma*sqrt(tau));
d9 = (log(B^2/(S*E))+(r+0.5*sigma^2)*(tau))/(sigma*sqrt(tau));
Nd1 = 0.5*(1+erf(d1/sqrt(2)));
Nd2 = 0.5*(1+erf(d2/sqrt(2)));
Nd3 = 0.5*(1+erf(d3/sqrt(2)));
Nd4 = 0.5*(1+erf(d4/sqrt(2)));
Nd5 = 0.5*(1+erf(d5/sqrt(2)));
Nd6 = 0.5*(1+erf(d6/sqrt(2)));
Nd7 = 0.5*(1+erf(d7/sqrt(2)));
Nd8 = 0.5*(1+erf(d8/sqrt(2)));
Nd9 = 0.5*(1+erf(d9/sqrt(2)));
%a = (B/S).^power1;
%b = (B/S).^power2;
a = (B/S)^power1;
b = (B/S)^power2;
if (E > B)
    %Cdao = S.*(Nd1-b.*(1-Nd8))-E*exp(-r*T)*(Nd2-a.*(1-Nd7));
    %Cdao_delta = Nd1 - ((B/S).^(2*r/sigma^2 - 1)).*(-(B^2/S.^2).*Nd9 - ((2*r-sigma^2)/(sigma^2*S)).*(S.*(b.*(1-Nd8))-E*exp(-r*T)*(a.*(1-Nd7))));
    Cdao = S*(Nd1-b*(1-Nd8))-E*exp(-r*T)*(Nd2-a*(1-Nd7));
    Cdao_delta = Nd1 - ((B/S)^(2*r/sigma^2 - 1))*(-(B^2/S^2)*Nd9 - ((2*r-sigma^2)/(sigma^2*S))*(S*(b*(1-Nd8))-E*exp(-r*T)*(a*(1-Nd7))));
else 
    Cdao = S*(Nd3-b*(1-Nd6))-E*exp(-r*T)*(Nd4-a*(1-Nd5));
    Cdao_delta = Nd1 - ((B/S)^(2*r/sigma^2 - 1))*(-(B^2/S^2)*Nd9 - ((2*r-sigma^2)/(sigma^2*S))*(S*(b*(1-Nd6))-E*exp(-r*T)*(a*(1-Nd5))));
end
end

                          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
randn('state',100)
clf

%Problem parameters
Szero=100; E=100; sigma=0.3; r=0.1; T=0.2; B=85;
Dt=1e-3; N=T/Dt; M=1e4; t = [0:Dt:T];%tau=T-t;
%Szero = 1; sigma = 0.35;r = 0.03; mu = 0.02; T = 5; E = 2; 
Dt = 1e-2;N = T/Dt;t = [0:Dt:T];
%

S = zeros(N,1);
asset = zeros(N,1);
cash = zeros(N,1);
portfolio = zeros(N,1);
Value = zeros(N,1);


[Cdao, Cdao_delta]= downAndOutV(S,E,r,sigma,B,T-t(1));

S(1)=Szero;
asset(1)=Cdao_delta;
Value(1)=Cdao;
cash(1)=1;
portfolio(1)=asset(1)*S(1)+cash(1);

for i=1:N
S(i+1)=S(i)*exp((mu-0.5*sigma^2)*Dt+sigma*sqrt(Dt)*randn);
%S(i+1) = S(i)*cumprod(exp((r-0.5*sigma^2)*Dt+sigma*sqrt(Dt)*randn));
%Smax = max(Svals);
portfolio(i+1)=asset(i)*S(i+1)+cash(i)*(1+r*Dt);
%[C,Cdelta,P,Pdelta]=ch08(S(i+1),E,r,sigma,T-t(i+1));
[Cdao, Cdao_delta]= downAndOutV(S,E,r,sigma,B,T-t(i+1));
asset(i+1)=Cdao_delta;
cash(i+1)=cash(i)*(1+r*Dt)-S(i+1)*(asset(i+1)-asset(i));
Value(i+1)=Cdao;
end

Vplot=Value-(Value(1)-portfolio(1))*exp(r*t)';
plot(t(1:5:end),Vplot(1:5:end),'bo')
hold on
plot(t(1:5:end),portfolio(1:5:end),'r-','LineWidth',2)
xlabel('Time'),ylabel('Portfolio')
legend('Theoretical Value','Actual value')
grid on

我想要一个看起来像这样的图: plot

0 个答案:

没有答案