You are on page 1of 87

金融商品設計 Coding HW

110071511 郭家豪
Week 2
BS
function [c,p] = bs(S0,X,r,T,sigma)
d1 = (log(S0/X)+(r+1/2*sigma^2)*T)/(sigma*sqrt(T));
d2 = d1 - sigma*sqrt(T);
c = S0*normcdf(d1)-X*exp(-r*T)*normcdf(d2);
p = X*exp(-r*T)*normcdf(-d2)-S0*normcdf(-d1);
end
pv
function x = pv(y,Ct,n)
x=0;
d=1+y;
for i=1:n
x=x+Ct(i)/d;
d=d*(1+y);
end
end
Week 3
Plotbond_price
Ct = [10 10 110];
n = 3;
bond_p = [];
r = [0 : 0.05 :0.5];
for i = 1: length(r)
x = pv(r(i),Ct,n);
bond_p = [bond_p x]
end
plot(r,bond_p);
title('bond price');
xlabel('r');
ylabel('bond price');
axis([0 0.5 40 130]);
grid on ;
Plot_optoins
X = 50 ;
c=2;
p=2;
St = 40 : 0.5 : 60 ;

% long call % long put


subplot(2,2,1); subplot(2,2,3);
plot(St, max(0,St-X)-c); plot(St, (max(0,X-St)-p));
title('long call'); title('long put');
xlabel('S'); xlabel('S');
ylabel('profit'); ylabel('profit');
axis([40 60 -10 10]); axis([40 60 -10 10]);

% short call % short put


subplot(2,2,2); subplot(2,2,4);
plot(St, -(max(0,St-X)-c)); plot(St, -(max(0,X-St)-p));
title('short call'); title('short put');
xlabel('S'); xlabel('S');
ylabel('profit'); ylabel('profit');
axis([40 60 -10 10]); axis([40 60 -10 10]);
Plot_longPut_BS
X = 50 ;
r = 0.01 ;
T = 10 ;
sigma = 0.1 ;
St = [40:0.5:60];
for i = 1 : length(St)
[call(i) , put(i)] = bs(St(i),X,r,T,sigma);
end
plot(St, max(X-St,0),"--black");
hold on;
plot (St, put,"*blue");
title('long put');
xlabel('S');
ylabel('profit');
axis([40 60 0 10]);
BLS_TheGreekLetter
% Gamma % vega
x = 50; call_gamma = blsgamma(s,x,r,t,sig,div); call_vega = blsvega(s,x,r,t,sig,div);
r =0.05; subplot(2,2,3); subplot(2,2,4);
t = 0.5; plot(s,call_gamma,'-'); plot(s,call_vega,'-');
sig = 0.2; title('Gamma vs. S'); title('Vega vs. S');
div = 0; xlabel('S'); xlabel('S');
s = 30:120 ; ylabel('Gamma'); ylabel('Vega');
legend('Gamma'); legend('Vega');
% Delta
[call_delta, puut_delta] = blsdelta(s,x,r,t,sig,div);
subplot(2,2,1); % Theta
plot(s,call_delta,'-'); call_theta = blstheta(s,x,r,t,sig,div);
title('Delta vs. S'); subplot(2,2,2);
xlabel('S'); plot(s,call_theta,'-');
ylabel('Delta'); title('Theta vs. S');
legend('Delta'); xlabel('S');
ylabel('Theta');
legend('Theta');
BLS_TheGreekLetter
BLS_TheGreekLetter_with_Time_variation

x = 50;
r =0.05;
t = 0.1:0.1:2;
sig = 0.2;
div = 0;
s = 50 ;

% Delta
[call_delta, puut_delta] = blsdelta(s,x,r,t,sig,div);
plot(t,call_delta,'-');
title('Delta vs. T');
xlabel('T');
ylabel('Delta');
legend('Delta');
Week 4
Protective_call
c = 2;
X = 100;
S0 = 90:1:110;
plot(S0, -(S0-100),"--");
hold on;
call_payoff = max(0, S0-X)
plot(S0, call_payoff-c, ".");
plot(S0, -(S0-100)+call_payoff-c);
grid on;
title('protective call');
xlabel("S0");
ylabel('profit');
Covered_put

p = 2;
X = 105;
S0 = 92:1:112;
plot(S0, -(S0-105), "--");
hold on;
put_payoff = max(0, 105-S0);
plot(S0, -put_payoff+p, ".");
plot(S0, -(S0-X)-put_payoff+p);
grid on;
title("covered put");
xlabel("S0");
ylabel("profit");
BullSpreadCall_mispricing1
c1 = 3; c2 = 4;
X1 = 100; X2 =105;
S0 = 95:1:110;

%此處先假設為long
c1_profit = max(S0-X1,0)-c1
c2_profit = max(S0-X2,0)-c2

plot(S0, c1_profit, "--");


hold on;
plot(S0, -c2_profit, ".");
plot(S0, c1_profit-c2_profit);
grid on;
title("Bull spread");
xlabel("S0");
ylabel("profit");
plot(S0, zeros(1,16), "black");
BullSpreadCall_mispricing2
c1 = 5; c2 = 1;
X1 = 100; X2 =103;
S0 = 95:1:110;

%此處先假設為long
c1_profit = max(S0-X1,0)-c1
c2_profit = max(S0-X2,0)-c2

plot(S0, c1_profit, "--");


hold on;
plot(S0, -c2_profit, ".");
plot(S0, c1_profit-c2_profit);
grid on;
title("Bull spread");
xlabel("S0");
ylabel("profit");
plot(S0, zeros(1,16), "black");
BullSpread_put
p1 = 1; p2 = 3;
X1 = 100; X2 = 103;
S0 = 95:1:110;

%此處先假設為long
p1_profit = max(X1-S0,0)-p1
p2_profit = max(X2-S0,0)-p2

plot(S0, p1_profit, "--");


hold on;
plot(S0, -p2_profit, ".");
plot(S0, p1_profit-p2_profit);
grid on;
title("Bull spread");
xlabel("S0");
ylabel("profit");
plot(S0, zeros(1,16), "black");
BearSpread_put
p1 = 2; p2 = 3 ;
X1 = 100; X2 = 103;
S0 = 95:1:110;

%此處先假設為long
p1_profit = max(X1-S0,0)-p1
p2_profit = max(X2-S0,0)-p2

figure(2)
plot(S0, -p1_profit, "--");
hold on;
plot(S0, p2_profit, ".");
plot(S0, -p1_profit+p2_profit);
grid on;
title("Bear spread");
xlabel("S0");
ylabel("profit");
plot(S0, zeros(1,16), "black");
BearSpread_Call
c1 = 3; c2 = 1;
X1 = 100; X2 =103;
S0 = 95:1:110;

%此處先假設為long
c1_profit = max(S0-X1,0)-c1
c2_profit = max(S0-X2,0)-c2

figure(1)
plot(S0, -c1_profit, "--");
hold on;
plot(S0, c2_profit, ".");
plot(S0, -c1_profit+c2_profit);
grid on;
title("Bear spread");
xlabel("S0");
ylabel("profit");
plot(S0, zeros(1,16), "black");
Butterfly_mispricing1
c1 = 5.5; c2 = 4; c3 = 1; plot(S0, c1_profit, "--");
X1 = 95; X2 = 100; X3 = 105; hold on;
S0 = 90:1:110; plot(S0, -2*c2_profit, "*");
% 理論c1+c3-2c2 > 0 才合理 plot(S0, c3_profit, ".");
% 執行價需對稱 plot(S0, c1_profit-2*c2_profit+c3_profit)
grid on;
c1_profit = max(S0-X1,0)-c1; title("butterfly spread");
c2_profit = max(S0-X2,0)-c2; xlabel("S0");
c3_profit = max(S0-X3,0)-c3; ylabel("profit");
plot(S0,zeros(1,21),"black");
Butterfly_mispricing2

c1 = 10; c2 = 3; c3 = 2; plot(S0, c1_profit, "--");


X1 = 95; X2 = 100; X3 = 105; hold on;
S0 = 90:1:110; plot(S0, -2*c2_profit, "*");
plot(S0, c3_profit, ".");
c1_profit = max(S0-X1,0)-c1; plot(S0, c1_profit-2*c2_profit+c3_profit)
c2_profit = max(S0-X2,0)-c2; grid on;
c3_profit = max(S0-X3,0)-c3; title("butterfly spread");
xlabel("S0");
ylabel("profit");
plot(S0,zeros(1,21),"black");
Condor

c1 = 7; c2 = 4; c3 = 2 ;c4 = 1; plot(S0, c1_profit, "--");


X1 = 95; X2 = 98; X3 = 102; X4 = 105; hold on;
S0 = 90:1:110; plot(S0, -c2_profit, "*");
%{ plot(S0, -c3_profit, ".");
Butterfly 是賣兩個同執行價的call plot(S0, c4_profit, "x");
Conder 是賣兩個不同執行價的call plot(S0, c1_profit-c2_profit - …
且執行價樣需對稱 c3_profit+c4_profit);
%}

c1_profit = max(S0-X1,0)-c1; grid on;


c2_profit = max(S0-X2,0)-c2; title("Conder spread");
c3_profit = max(S0-X3,0)-c3; xlabel("S0");
c4_profit = max(S0-X4,0)-c4; ylabel("profit");
plot(S0,zeros(1,21),"black");
DigonalSpread
c1 = 4; c2 = 3;
S0 = 90:1:110;
X1 = 97; X2 = 100;
r = 0.02; T = 0.1; sigma = 0.2;

c1_profit = max(S0-X1,0)-c1;
% 計算尚未到期call價格
for i = 1: length(S0)
[C(i),P(i)] = bs(S0(i), X2, r, T, sigma);
end
% 畫圖
plot(S0, -c1_profit);
hold on;
plot(S0, C-c2, "--");
plot(S0, C-c2-c1_profit);
title('Digonal Spread');
xlabel("S0");
ylabel('profit');
Week 5
Butterfly_Spread_andBS
clear;
c1 = 5; c2 = 2.5; c3 = 2; % 畫圖
X1 = 92; X2 = 100; X3 = 108; plot(S0, c1_profit - 2*c2_profit + c3_profit);
S0 = 85:1:115; hold on;
r = 0.02; T1 = 0.05; T2 = 0.1; sigma = 0.2; plot(S0, C11-2*C21+C31-c1+2*c2-c3,'--');
plot(S0, C12-2*C22+C32-c1+2*c2-c3,'.');
c1_profit = max(S0-X1,0)-c1; plot(S0,zeros(1,length(S0)),'black');
c2_profit = max(S0-X2,0)-c2; grid on;
c3_profit = max(S0-X3,0)-c3; title('butttfly spread');
xlabel('S0');
% 算 call 價格 ylabel('profit');
for i = 1:length(S0) legend({'t=0','t=0.5','t=0.1'},'Location','SouthEast');
[C11(i),P11(i)] = bs(S0(i),X1,r,T1,sigma);
[C21(i),P21(i)] = bs(S0(i),X2,r,T1,sigma);
[C31(i),P31(i)] = bs(S0(i),X3,r,T1,sigma);
[C12(i),P12(i)] = bs(S0(i),X1,r,T2,sigma);
[C22(i),P22(i)] = bs(S0(i),X2,r,T2,sigma);
[C32(i),P32(i)] = bs(S0(i),X3,r,T2,sigma);
end
Butterfly_Spread_andBS
CBOE1

clear; % 畫圖
S = 100; % 現在股價 figure(1);
S0 =85:1:115; % 到期日股價 plot(S0,stockIndex_profit-call_profit,'--blue'); % BXM
hold on;
X1 = 100*0.98; % call 執行價 2% out-of-money plot(S0,-put_profit,'--green'); % short put
X2 = S; % put 執行價 at-the-money plot(S0,stockIndex_profit-call_profit-put_profit,'-red');
title('CBOE')
r = 0.01; T = 1; sigma = 0.2; xlabel("S0");
c = 5; p = 4; ylabel("profit");
grid on;
stockIndex_profit = S0 - S; plot(S0, zeros(1,length(S0)),'-black');
call_profit = max(S0-X1,0)-c; legend({'BXM','short put','CBOE'},'Location','SouthEast');
put_profit = max(X2-S0,0)-p;
CBOE1
CBOE2

clear; figure(2);
S = 100; % 現在股價 plot(S0, stockIndex_profit,'--blue');
S0 =85:1:115; % 到期日股價 hold on;
plot(S0,-(call_profit+put_profit),'--green')
X1 = 100*0.98; % call 執行價 2% out-of-money plot(S0, stockIndex_profit-(call_profit+put_profit), '-red');
X2 = S; % put 執行價 at-the-money title('CBOE')
xlabel("S0");
r = 0.01; T = 1; sigma = 0.2; ylabel("profit");
c = 5; p = 4; grid on;
plot(S0, zeros(1,length(S0)),'-black');
stockIndex_profit = S0 - S; legend({'stock index','short
call_profit = max(S0-X1,0)-c; strangle','CBOE'},'Location','SouthEast');
put_profit = max(X2-S0,0)-p;
CBOE2
Week 6
LatticeEurPut
function [price, lattice] = LatticeEurPut(S0, X, r, T, sigma, N)

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
% 二項樹
p = (exp(r*deltaT)-d)/(u-d);
lattice = zeros(N+1, N+1);
for j = 0:N
lattice(N+1, j+1) = max(0, (X - S0*(u^j)*(d^(N-j))));
end
for i = N-1:-1:0
for j = 0:i
lattice(i+1, j+1)= exp(-r*deltaT)*...
( p*lattice(i+2,j+2)+(1-p)*lattice(i+2,j+1) );
end
end
price = lattice(1,1);
CompAmLatticeBLS_Call
% 變數設定 % 畫圖
S0 = 50; figure(2)
X = 50; plot(1:N, ones(1,N)*BlsC);
r = 0.1; hold on;
sigma = 0.4; plot(1:N, LatticeC);
T = 5/12; title('CallpriceCompare');
N = 50; xlabel("N");
q = 0; ylabel('call price');
legend({'BS','CRR trees'},'Location','SouthEast');
% 用BS和二項樹算put的價格
[BlsC,BlsP] = blsprice(S0, X, r, T, sigma)
LatticeC = zeros(1,N);
for i = 1:N
LatticeC(i) = LatticeAmCall(S0, X, r, T, sigma, q, i);
end
CompLatticeBLS_Put
% 變數設定 % 畫圖
S0 = 50; plot(1:N, ones(1,N)*BlsP);
X = 50; hold on;
r =0.1; plot(1:N, LatticeC);
sigma = 0.4; title('PUTpricre__Compare');
T = 5/12; xlabel("N");
N = 50; ylabel('put price');
legend({'BS','CRR trees'},'Location','SouthEast');
% 用BS和二項樹算put的價格
[BlsC,BlsP] = blsprice(S0, X, r, T, sigma)
LatticeC = zeros(1,N);
for i = 1:N
LatticeC(i) = LatticeEurPut(S0, X, r, T, sigma, i);
end
LatticeC
CompAmEur_Call
% 變數設定 % 畫圖
S0 = 50; plot(1:N, LatticeAm_C);
X = 50; hold on;
r = 0.1; plot(1:N, LatticeEur_C);
sigma = 0.4; title('CallpricreCompare');
T = 5/12; xlabel("N");
q = 0.1; % q 要夠大,美式才會提早執行 ylabel('call price');
N = 50; legend({'Am','Eur'},'Location','SouthEast');

% 算美式和歐式call的價格
LatticeAm_C = zeros(1,N);
LatticeEur_C = zeros(1,N);
for i = 1:N
LatticeAm_C(i) = LatticeAmCall_q(S0, X, r, T, sigma, q, i);
end

for i = 1:N
LatticeEur_C(i) = LatticeEurCall_q(S0, X, r, T, sigma, q, i);
end
Week 7
LatticeEurCallDiv_D
function [price, lattice ] = LatticeEurCallDiv_D(S0, X, r, T, sigma,
N, D, tau)
% tau 為第幾期發股利
% 歐式選擇權皆為從最後一期算回來,中間不需要比較,
所以不用分發股利前後

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ;
S0a = S0-D*exp(-r*tau*deltaT); % 將未來的股利折現到現在
先扣掉
LatticeEurCallDiv_D

% 建二項樹 % 倒數第二行折現回來
lattice = zeros(N+1, N+1);
for i = N-1:-1:0
% 寫最後一行 for j = 0:i
% 第一列為全部下跌狀況, 股價由低排到高 lattice(i+1, j+1) = ...
for j = 0:N exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1)) ;
lattice(N+1, j+1) = max ( 0, S0a*(u^j)*(d^(N-j))-X ); end
end end

price = lattice(1,1);
LatticeEurPutDiv_D

function [price, lattice ] = LatticeEurPutDiv_D(S0, X, r, T, sigma,


N, D, tau)
% tau 為第幾期發股利
% 歐式選擇權皆為從最後一期算回來,中間不需要比較,
所以不用分發股利ㄐ前後

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ;
S0a = S0-D*exp(-r*tau*deltaT); % 將未來的股利折現到現在
先扣掉
LatticeEurPutDiv_D

% 建二項樹 % 倒數第二行折現回來
lattice = zeros(N+1, N+1);
for i = N-1:-1:0
% 寫最後一行 for j = 0:i
% 第一列為全部下跌狀況, 股價由低排到高 lattice(i+1, j+1) = ...
for j = 0:N exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1)) ;
lattice(N+1, j+1) = max ( 0, X-S0a*(u^j)*(d^(N-j)) ); end
end end

price = lattice(1,1);
LatticeAmPutDiv_D

function [price, lattice ] = LatticeAmPutDiv_D(S0, X, r, T, sigma,


N, D, tau)
% tau 為第幾期發股利

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ;
S0a = S0-D*exp(-r*tau*deltaT); % 將未來的股利折線到現在
先扣掉
LatticeAmPutDiv_D

% 建二項樹 % 發股利前
lattice = zeros(N+1, N+1); for i = tau-1:-1:0
% 寫最後一行 for j = 0:i
% 第一列為全部下跌狀況, 股價由低排到高 lattice(i+1, j+1) = max( X -S0a*(u^j)*(d^(i-j))-D*exp(-
for j = 0:N r*(tau-i)*deltaT),...
lattice(N+1, j+1) = max ( 0, X-S0a*(u^j)*(d^(N-j)) ); exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
end j+1)) );
end
% 發股利(tau)之後到 倒數第二行 End
for i = N-1:-1:tau
for j = 0:i price = lattice(1,1);
lattice(i+1, j+1) = max( X-S0a*(u^j)*(d^(i-j)),...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
j+1)) );
end
end
LatticeAmCallDiv_D

function [price, lattice ] = LatticeAmCallDiv_D(S0, X, r, T, sigma,


N, D, tau)
% tau 為第幾期發股利

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ; % u-d 要括號不然會先除u
S0a = S0-D*exp(-r*tau*deltaT);
LatticeAmCallDiv_D
% 發股利前
% 建二項樹
for i = tau-1:-1:0
lattice = zeros(N+1, N+1);
for j = 0:i
lattice(i+1, j+1) = max( S0a*(u^j)*(d^(i-j))+D*exp(-r*(tau-
% 寫最後一行
i)*deltaT)-X,...
% 第一列為全部下跌狀況, 股價由低排到高
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
for j = 0:N
j+1)) );
lattice(N+1, j+1) = max ( 0, S0a*(u^j)*(d^(N-j))-X );
end
end
end
% 發股利(tau)之後到 倒數第二行
price = lattice(1,1);
for i = N-1:-1:tau
for j = 0:i
lattice(i+1, j+1) = max( S0a*(u^j)*(d^(i-j))-X,...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
j+1)) );
end
end
LatticeEurCallDiv_P
function [price, lattice ] = LatticeEurCallDiv_P(S0, X, r, T, sigma,
N, div, tau)
% tau 為第幾期發股利
% 歐式選擇權第幾期發股利沒差

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ; % u-d 要括號不然會先除u
LatticeEurCallDiv_P
% 建二項樹 % 發股利前
lattice = zeros(N+1, N+1); %{
for i = tau-1:-1:0
% 寫最後一行 for j = 0:i
% 第一列為全部下跌狀況, 股價由低排到高 lattice(i+1, j+1) = ...
for j = 0:N exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1)) ;
lattice(N+1, j+1) = max ( 0, S0*(u^j)*(d^(N-j))*(1-div)-X ); end
end end
%}
% 發股利(tau)之後到 倒數第二行
price = lattice(1,1);
for i = N-1:-1:0
for j = 0:i
lattice(i+1, j+1) = ...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1));
end
end
LatticeEurPutDiv_P

function [price, lattice ] = LatticeEurPutDiv_P(S0, X, r, T, sigma,


N, div, tau)
% tau 為第幾期發股利
% 歐式選擇權第幾期發股利沒差,但這邊還是分開寫,買
權那邊有合在一起

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ; % u-d 要括號不然會先除u
LatticeEurPutDiv_P

% 建二項樹
lattice = zeros(N+1, N+1); % 發股利前
for i = tau-1:-1:0
% 寫最後一行 for j = 0:i
% 第一列為全部下跌狀況, 股價由低排到高 lattice(i+1, j+1) = ...
for j = 0:N exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1)) ;
lattice(N+1, j+1) = max ( 0, X-S0*(u^j)*(d^(N-j))*(1-div) ); end
end end

% 發股利(tau)之後到 倒數第二行 price = lattice(1,1);

for i = N-1:-1:tau
for j = 0:i
lattice(i+1, j+1) = ...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2, j+1));
end
end
LatticeAmPutDiv_P

function [price, lattice ] = LatticeAmPutDiv_P(S0, X, r, T, sigma,


N, div, tau)
% tau 為第幾期發股利

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ; % u-d 要括號不然會先除u
LatticeAmPutDiv_P
% 建二項樹 % 發股利前
lattice = zeros(N+1, N+1); for i = tau-1:-1:0
for j = 0:i
% 寫最後一行 lattice(i+1, j+1) = max( X-S0*(u^j)*(d^(i-j)),...
% 第一列為全部下跌狀況, 股價由低排到高 exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
for j = 0:N j+1)) );
lattice(N+1, j+1) = max ( 0, X-S0*(u^j)*(d^(N-j))*(1-div) ); end
end end

% 發股利(tau)之後到 倒數第二行 price = lattice(1,1);

for i = N-1:-1:tau
for j = 0:i
lattice(i+1, j+1) = max( X-S0*(u^j)*(d^(i-j))*(1-div),...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
j+1)) );
end
end
LatticeAmCallDiv_P

function [price, lattice ] = LatticeAmCallDiv_P(S0, X, r, T, sigma,


N, div, tau)
% tau 為第幾期發股利

% 變數設定
deltaT = T/N;
u = exp(sigma*sqrt(deltaT));
d = 1/u;
p = ( exp(r*deltaT)-d )/ (u-d) ; % u-d 要括號不然會先除u
LatticeAmCallDiv_P
% 建二項樹 % 發股利前
lattice = zeros(N+1, N+1); for i = tau-1:-1:0
for j = 0:i
% 寫最後一行 lattice(i+1, j+1) = max( S0*(u^j)*(d^(i-j))-X,...
% 第一列為全部下跌狀況, 股價由低排到高 exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
for j = 0:N j+1)) );
lattice(N+1, j+1) = max ( 0, S0*(u^j)*(d^(N-j))*(1-div)-X ); end
end end

% 發股利(tau)之後到 倒數第二行 price = lattice(1,1);

for i = N-1:-1:tau
for j = 0:i
lattice(i+1, j+1) = max( S0*(u^j)*(d^(i-j))*(1-div)-X,...
exp(-r*deltaT)*(p*lattice(i+2,j+2)+(1-p)*lattice(i+2,
j+1)) );
end
end
Week 9
TriEurPut
lattice = zeros(N+1, 2*N+1);
function [price, lattice] = TriEurPut(S0, X, r, T, sigma, N, lamda)
for j = 1:N+1
lattice(N+1, j) = max(0, X - S0*d^(N-j+1));
deltaT = T/N;
end
u = exp(lamda*sigma*sqrt(deltaT));
for j = N+2:2*N+1
d = 1/u;
lattice(N+1, j) = max(0, X - S0*u^(j-N-1));
pu = 1/(2*lamda^2) + (r-
end
sigma^2/2)*sqrt(deltaT)/(2*lamda*sigma);
for i = N-1:-1:0
pm = 1-1/(lamda^2);
for j = 1 : 2*i+1
pd = 1-pu-pm;
lattice(i+1, j) = exp(-r*deltaT)*...
( pd*lattice(i+2, j) + pm*lattice(i+2, j+1) + ...
pu*lattice(i+2, j+2));
end
end

price = lattice(1,1);
TriAmPut
function [price, lattice] = TriAmPut(S0, X, r, T, sigma, N, lamda) % 有N期要計算,再加上第零期,所以矩陣有N+1行
% 矩陣從(1,1)開始,所以每一期在矩陣的表示皆要+1
deltaT = T/N; for i = N-1:-1:0
u = exp(lamda*sigma*sqrt(deltaT)); for j = 1 : 2*i+1 % 因為u和d互為倒數,下面當(i-j+1)小於
d = 1/u; 零時,表示上漲
pu = 1/(2*lamda^2) + (r- lattice(i+1, j) = max( X - S0*d^(i-j+1), exp(-r*deltaT)*...
sigma^2/2)*sqrt(deltaT)/(2*lamda*sigma); ( pd*lattice(i+2, j) + pm*lattice(i+2, j+1) + pu*lattice(i+2,
pm = 1-1/(lamda^2); j+2))...
pd = 1-pu-pm; );
end
lattice = zeros(N+1, 2*N+1); end
for j = 1:N+1
lattice(N+1, j) = max(0, X - S0*d^(N-j+1)); price = lattice(1,1);
end
for j = N+2:2*N+1
lattice(N+1, j) = max(0, X- S0*u^(j-N-1));
end
CompPut_Bls_Bin_Tri
S0 = 50; plot(1:N, ones(1,N)*BlsP, 'black');
X = 50; hold on;
r = 0.04879; plot(1:N, C1, 'b');
sigma = 0.2; plot(1:N, C2, 'red');
T = 7/12; title('PutpricreCompare');
q = 0; xlabel("N");
N = 70; ylabel('put price');
lamda = 1.41421; legend({"BS", 'Bin','Tri'}, 'Location','SouthEast')

[BlsC, BlsP] = blsprice(S0, X, r,T, sigma);


C1 = zeros(1, N);
C2 = zeros(1, N);
for i = 1:N
[C1(i), tree1] = LatticeEurPut(S0, X, r, T, sigma, i);
[C2(i), tree2] = TriEurPut(S0, X, r, T, sigma, i,lamda);
end
Week 10
AssetPaths
% 模擬資產價格路徑
function SPaths = AssetPaths(S0, mu, sigma, T, NSteps, NRepl) % NRepl 表模擬幾條

SPaths = zeros(NRepl, 1+NSteps); % column 第一行為原始價格,所以加一


SPaths(:, 1) = S0;
dt = T/NSteps;
nudt = (mu - 0.5*sigma^2)*dt;
sidt = sigma* sqrt(dt);

for i = 1:NRepl
for j = 1: NSteps
SPaths(i, j+1) = SPaths(i, j)* exp(nudt+sidt*randn);
end
end
AssetPaths1

function SPaths = AssetPaths1(S0, mu, sigma, T, NSteps, NRepl) % NRepl 表模擬幾條

dt = T/NSteps;
nudt = (mu - 0.5*sigma^2)*dt;
sidt = sigma* sqrt(dt);

Increments = nudt + sidt*randn(NRepl, NSteps); % 建一個隨機項矩陣


LogPaths = cumsum([log(S0)* ones(NRepl,1), Increments], 2); % 設定維度維2, 返回行的累積和
SPaths = exp(LogPaths);

x = [log(S0)* ones(NRepl,1), Increments];


% 觀察用, matlab 合併矩陣可以直接用[A, B], A、B 為兩個矩陣
MCPath

randn('seed', 0);
paths = AssetPaths(50, 0.1, 0.3, 1, 365, 10);

length(paths)
size(paths)

for i = 1:10
plot(1:length(paths),paths(i,:))
hold on
end
BlsMC if type == 0
DiscPayoff = exp(-r*T) * max( 0 , …
S0*exp(nuT+siT*randn(NRepl,1)) - X);
% 利用幾何布朗運動算未來股價ST的數字,根據公式推導 [Price, VarPrice, CI] = normfit(DiscPayoff)
T 數值可以很大,不影響結果,所以直接讓S0一步到ST elseif type == 1
DiscPayoff = exp(-r*T) * max( 0 , X - ….
function [Price, CI] = BlsMC(S0,X,r,T,sigma,NRepl, type) S0*exp(nuT+siT*randn(NRepl,1)) );
% 一步到ST, 所以不用設NSteps [Price, VarPrice, CI] = normfit(DiscPayoff)
% type = 0 表 Call elseif type == 2
% = 1 表 Put stimu_list = S0*exp(nuT+siT*randn(NRepl,1));
% = 2 表 ANCall for i = 1:length(stimu_list)
if stimu_list(i) - X < 0
nuT = (r - 0.5*sigma^2)*T; stimu_list(i) = 0;
siT = sigma * sqrt(T); end
end
DiscPayoff = exp(-r*T)*stimu_list;
[Price, VarPrice, CI] = normfit(DiscPayoff)
end
CompAssetPath
% 比較 AssetPaths、 AssetPaths1 兩個方法的速度
tic,paths = AssetPaths(50,0.1,0.3,1,10,10); toc % tic + toc
用來計算花費時間

tic,paths1 = AssetPaths1(50,0.1,0.3,1,10,10); toc


CompBlsMC_Call
% CompBlsMC.m Compare Call blsprice and BlsMC1000 and Ans:
BlsMC200000 Bls
MC1000
S0=50; CI1000
X=52; MC200000
r=0.1; CI200000
T=5/12;
sigma=0.4;
NRepl1=1000;
NRepl2=200000;

Bls=blsprice(S0,X,r,T,sigma);
randn('seed',0);
[MC1000, CI1000] = BlsMC(S0,X,r,T,sigma,NRepl1, 0);
randn('seed',0);
[MC200000, CI200000] = BlsMC(S0,X,r,T,sigma,NRepl2, 0);
CompBlsMC_Put
% CompBlsMC.m Compare Put blsprice and BlsMC1000 and Ans:
BlsMC200000 Put;
MC1000;
S0=50; CI1000;
X=52; MC200000;
r=0.1; CI200000;
T=5/12;
sigma=0.4;
NRepl1=1000;
NRepl2=200000;

[Call, Put] =blsprice(S0,X,r,T,sigma);


randn('seed',0);
[MC1000, CI1000] = BlsMC(S0,X,r,T,sigma,NRepl1, 1);
randn('seed',0);
[MC200000, CI200000] = BlsMC(S0,X,r,T,sigma,NRepl2, 1);
ANCall
function Call = ANCall(S0, X, r, T, sigma,q)

%{
Exotic Options- Assets or Nothing
ANCall = ST , if ST > K
= 0 , others
ANCall = S0*e^(-qT)*N(d1)
%}

d1 = ( log(S0/X)+(r-q+0.5*sigma^2)*T ) / ( sigma*sqrt(T) );
d2 = d1 - sigma*sqrt(sigma);

Call = S0*exp(-q*T)*normcdf(d1);
CompBlsMC_ANCall
% CompBlsMC.m Compare ANCall and CallMC1000 and Ans:
CallMC200000
AN
S0=50; MC1000
X=52; CI1000
r=0.1; MC200000
T=5/12; CI200000
sigma=0.4;
q = 0.05;
NRepl1=1000;
NRepl2=200000;

AN = ANCall(S0,X,r,T,sigma,q);
randn('seed',0);
[MC1000, CI1000] = BlsMC(S0,X,r,T,sigma,NRepl1, 2);
randn('seed',0);
[MC200000, CI200000] = BlsMC(S0,X,r,T,sigma,NRepl2, 2);
Week 13
MCIntergration
% MCIntergration 將積分視為一個均勻(0,1)的分配
% 此題對e^x做積分, 從0積到2
answer = exp(2)-1;

rand("seed", 122); % 設均勻(0,1)的種子


N = 1000;
meanexp = zeros(1, N); % 做一個list放模擬不同次數的結果
for i = 1:N
meanexp(i) = mean(2*exp(rand(1, i)));
% 使用公式 r = a + (b-a).*rand(N,1) 生成区间 (a,b) 内的 N 个
随机数
end
ans_MC = 2*meanexp;

plot(1:N, ans_MC)
hold on;
plot(1:N, ones(1,N)*answer)
SallieMae_AmPut % 最後一年
for j = 0:N
lattice(N+1, j+1) = max(9.25, X(5) - S0*(u^j)*(d^(N-j)) );
end
for i = N-1 :-1:N-n+1
for j = 0:i
function [price, lattice] = SallieMae_AmPut(S0, X, r, T, sigma, q, lattice(i+1, j+1)= max( X(5) - S0* u^j * d^(i-j) ,...
N) exp(-r*deltaT)*( p*lattice(i+2,j+2)+(1-
% 標的資產為日幣,因此,價格為多少美元可以買1日幣, p)*lattice(i+2,j+1) )...
S0、X的值必<1 );
% 變數設定 end
deltaT = T/N; end
n = N/5; for peroid = 1:4 % 有多個執行價,所以要分不同層去跑
for i = N-peroid*n :-1:N-(peroid+1)*n+1
u = exp(sigma*sqrt(deltaT));
for j = 0:i
d = 1/u; lattice(i+1, j+1)= max( X(5-peroid) - S0* u^j * d^(i-j) ,...
p = ( exp((r-q)*deltaT)-d) /(u-d); exp(-r*deltaT)*( p*lattice(i+2,j+2)+(1-
p)*lattice(i+2,j+1) )...
% 二項樹 );
lattice = zeros(N+1, N+1); end
end
end
lattice(1,1) = max( X(1)-S0,...
exp(-r*deltaT)*( p*lattice(2,2)+(1-p)*lattice(2,1) ) );
price = lattice(1,1);
SallieMae_Pricing

SallieMae_AmPut(1/133, [1/131.75 1/131.75 1/129.5 1/127 1/124.5], 0.01, 1, 0.5, 0, 500)


Week 14
HaltonBox_OptoinsPrices
% Halton + Box Muller 得到標準常態分佈,在計算Options Prices

function [call, put] = HaltonBox_OptoinsPrices(S0, X, r, T, sigma, Npoints, Base1, Base2)


% Npoints 表模擬幾次,要幾個隨機項

nuT = (r - 0.5*sigma^2) * T;
siT = sigma *sqrt(T);

% Use Halton 生成 standard normals % Box Muller


H1 = GetHaltonSeq(ceil(Npoints/2), Base1); VLog = sqrt(-2 * log (H1));
H2 = GetHaltonSeq(ceil(Npoints/2), Base2); Norm1 = VLog.* cos(2*pi*H2);
Norm2 = VLog.* sin(2*pi*H2);
Norm = [Norm1; Norm2]; % [ ; ] 把兩個接起來

% Calculate Options price


payoff_call = exp(-r*T)* max(0, S0*exp(nuT + siT*Norm) - X );
call = mean(payoff_call); % 將折現後的 call price 取平均
payoff_put = exp(-r*T)* max(0, X - S0*exp(nuT + siT*Norm)) ;
put = mean(payoff_put);
randBox_OptoinsPrices
% Random + Box Muller 得到標準常態分佈,在計算Options Prices

function [call, put] = randBox_OptoinsPrices(S0, X, r, T, sigma, Npoints)


% Npoints 表模擬幾次,要幾個隨機項

nuT = (r - 0.5*sigma^2) * T;
siT = sigma *sqrt(T);
% Box Muller
VLog = sqrt(-2 * log (H1));
% Use rand 生成 standard normals
Norm1 = VLog.* cos(2*pi*H2);
H1 = rand(ceil(Npoints/2), 1);
Norm2 = VLog.* sin(2*pi*H2);
H2 = rand(ceil(Npoints/2), 1);
Norm = [Norm1; Norm2]; % [ ; ] 把兩個接起來

% Calculate Options price


payoff_call = exp(-r*T)* max(0, S0*exp(nuT + siT*Norm) - X ) ;
% 將折現後的 call price 取平均
call = mean(payoff_call);
payoff_put = exp(-r*T)* max(0, X - S0*exp(nuT + siT*Norm));
put = mean(payoff_put);
Haltoncdf_OptoinsPrices
% Halton + cdf法 得到標準常態分佈,在計算Options Prices % Calculate Options price
payoff_call = exp(-r*T)* max(0, S0*exp(nuT + siT*Norm) - X ) ;
function [call, put] = Haltoncdf_OptoinsPrices(S0, X, r, T, sigma, % 將折現後的 call price 取平均
Npoints, Base) call = mean(payoff_call);
% Npoints 表模擬幾次,要幾個隨機項 payoff_put = exp(-r*T)* max(0, X - S0*exp(nuT + siT*Norm));
put = mean(payoff_put);
nuT = (r - 0.5*sigma^2) * T;
siT = sigma *sqrt(T);

% Use rand 生成 standard normals


H1 = GetHaltonSeq(ceil(Npoints), Base);

% cdf
Norm = norminv(H1);
% 因為H1的值介於0到1之間,可以視為一個標準常態的cdf,
藉由norminv 找到標準常態上對應的X
randcdf_OptoinsPrices
% Random + cdf法 得到標準常態分佈,在計算Options Prices

function [call, put] = randcdf_OptoinsPrices(S0, X, r, T, sigma, Npoints)


% Npoints 表模擬幾次,要幾個隨機項
nuT = (r - 0.5*sigma^2) * T;
siT = sigma *sqrt(T);

% Use rand 生成 standard normals


H1 = rand(ceil(Npoints), 1);

% cdf
Norm = norminv(H1);
% 因為H1的值介於0到1之間,可以視為一個標準常態的cdf,藉由norminv 找到標準常態上對應的X

% Calculate Options price


payoff_call = exp(-r*T)* max(0, S0*exp(nuT + siT*Norm) - X ) ; % 將折現後的 call price 取平均
call = mean(payoff_call);
payoff_put = exp(-r*T)* max(0, X - S0*exp(nuT + siT*Norm));
put = mean(payoff_put);
Comp_getsOptoinsPrice_method
% 利用各種方法得出的隨機項,使用Monte Carlo 計算選擇權價格,比較與BS的差異
S0 = 50;
X = 52;
r = 0.01;
T = 5/12;
sigma = 0.4;
NRepl = 5000;

Base11 = 2; Base12 = 7;
Base21 = 11; Base22 = 7;
Base31 = 2 ; Base32 = 4;

% benchmark
[call, put] = blsprice(S0, X, r, T, sigma);

% Halton_Box
[Halton_Box27_call, Halton_Box27_put] = HaltonBox_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base11, Base12);
[Halton_Box117_call, Halton_Box117_put] = HaltonBox_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base21, Base22);
[Halton_Box24_call, Halton_Box24_put] = HaltonBox_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base31, Base32);
Comp_getsOptoinsPrice_method
% Halton_cdf
[Halton_cdf2_call, Halton_cdf2_put] = Haltoncdf_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base11);
[Halton_cdf7_call, Halton_cdf7_put] = Haltoncdf_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base12);
[Halton_cdf4_call, Halton_cdf4_put] = Haltoncdf_OptoinsPrices(S0, X, r, T, sigma, NRepl, Base32);

% rand_Box
[rand_Box_call, rand_Box_put] = randBox_OptoinsPrices(S0, X, r, T, sigma, NRepl);

% rand_cdf
[rand_cdf_call, rand_cdf_put] = randcdf_OptoinsPrices(S0, X, r, T, sigma, NRepl);

% 結論: Halton + BoX(27) 組出來的隨機項算得的價格與BS最接近,但當兩個Base 不互質時,結果變最差


Week 15
DOPutMCCV % compute parameters
StockVals = S0*exp(nuT+siT*randn(NPilot,1));
for i = 1:NPilot
crossed = any (StockVals(i)<=Sb);
function [P,Cl,NCrossed] = …
DOPutMCCV(S0,x,r,T,sigma,Sb,NRepl,NPilot) % 未跨過,傳統put
if crossed == 0
nuT = (r - 0.5*sigma^2) * T; Payoff1(i) = max(0,x-StockVals(i));
siT = sigma * sqrt(T); % 跨過
else
Payoff1 = zeros(NPilot,1); Payoff1(i) = 0;
Payoff2 = zeros(NRepl,1); NCrossed = NCrossed+1;
NCrossed = 0; end
end

OptionVals = exp(-r*T) * Payoff1;

MatCov = zeros(2,2);
MatCov = cov(StockVals, OptionVals);
VarY = S0^2 * exp(2*r*T) * (exp(T * sigma^2) - 1);
c = - MatCov(1,2) / VarY;
ExpY = S0 * exp(r*T);
DOPutMCCV
% simulation
NCrossed = 0;
NewStockVals = S0*exp(nuT+siT*randn(NRepl,1));

for i=1:NRepl
crossed = any(NewStockVals(i) <= Sb);

if crossed == 0
Payoff2(i) = max(0, x -NewStockVals(i));
else
Payoff2(i) = 0;
NCrossed = NCrossed + 1;
end
end
NewOptionVals = mean(exp(-r*T) * Payoff2);

ControlVars = NewOptionVals + c * (NewStockVals - ExpY);


[P,VarPrice,Cl] = normfit(ControlVars);
UOCall
function Call = UOCall(S0,X,r,T,sigma,Sb)
% Up-and-out call ,當逼調資產價格高過Sb就Out,等於0

a = (Sb/S0) ^ (-1+(2*r/sigma^2)) ;
b = (Sb/S0) ^ ( 1+(2*r/sigma^2)) ;

d1 = (log(S0/X ) + (r + sigma^2/2)*T) / (sigma*sqrt(T));


d2 = (log(S0/X ) + (r - sigma^2/2)*T) / (sigma*sqrt(T));
d3 = (log(S0/Sb) + (r + sigma^2/2)*T) / (sigma*sqrt(T));
d4 = (log(S0/Sb) + (r - sigma^2/2)*T) / (sigma*sqrt(T));
d5 = (log(S0/Sb) - (r - sigma^2/2)*T) / (sigma*sqrt(T));
d6 = (log(S0/Sb) - (r + sigma^2/2)*T) / (sigma*sqrt(T));
d7 = (log(S0*X/Sb^2) - (r - sigma^2/2)*T) / (sigma*sqrt(T));
d8 = (log(S0*X/Sb^2) - (r + sigma^2/2)*T) / (sigma*sqrt(T));

Call = S0 * (normcdf(d1) -normcdf(d3) -b *(normcdf(d6)-normcdf(d8)) )...


-X*exp(-r*T) * (normcdf(d2) -normcdf(d4) -a *(normcdf(d5)-normcdf(d7)) );
UOCallMC
function [Call,Cl,NCrossed] = UOCallMC(S0,x,r,T,sigma,Sb,NSteps,NRepl)
% Generate asset paths
Payoff = zeros(NRepl,1);
NCrossed = 0;

for i = 1:Nrepl % simulation


Path = AssetPaths1(S0,r,sigma,T,NSteps,1); % path 一次一條
crossed = any (Path>=Sb);

% 未跨過,傳統put
if crossed == 0
Payoff(i) = max(0,Path(NSteps+1)-x); % 從S0開始往前走n步,共n+1個值
else % 跨過
Payoff(i) = 0;
NCrossed = NCrossed+1;
end
End

[Call,aux,Cl] = normfit(exp(-r*T)*Payoff);
UOCallMCCond

function [Cuo,Cl,NCrossed] = UOCallMCCond(S0,x,r,T,sigma,Sb,NSteps,NRepl)


% Cuo 為 Up-and-Out Call
% Up-and-Out Call 利用 Monte Carlo + 透過條件期望值相同、條件變異數下降的方式,降低Variaince

dt = T/NSteps;
[Call,Put] = blsprice(S0,x,r,T,sigma);

% Generate asset paths and payoff for the Up-and-in option


% 透過Call - (Up-and-in Call), 計算Up-and-Out Call,因為 Up-and-in 比較好算
NCrossed = 0;
Payoff = zeros(NRepl,1);
Times = zeros(NRepl,1); % 記錄跨過去時點用
StockVals = zeros(NRepl,1); % 紀錄跨過去時點的現貨價格,用來計算剩餘時間call的價格 (看不懂先往下)
UOCallMCCond
for i = 1:NRepl
Path = AssetPaths1(S0,r,sigma,T,NSteps,1);
tcrossed = min(find(Path>=Sb));

if not(isempty(tcrossed))
NCrossed = NCrossed+1;
Times(NCrossed) = (tcrossed-1)*dt;
StockVals(NCrossed) = Path(tcrossed);
end
end

if (NCrossed>0)
[Caux,Paux] = blsprice(StockVals(1:NCrossed),x,r,T-Times(1:NCrossed),sigma);
% 計算當跨過去時,尚有剩餘時間的歐式買權價格,因為當跨過去之後就視為正常的call了
Payoff(1:NCrossed) = exp(-r*Times(1:NCrossed)) .* Caux;
% 有一排不同時間點的call價格,根據時點折現
end

[Cuo,aux,Cl] = normfit(Call - Payoff); % 計算Up-and-Out Call


UOCallMCCondIS
function [Cuo,Cl,NCrossed] = UOCallMCCondIS(S0,x,r,T,sigma,Sb,NSteps,NRepl,bp)

% Monte Carlo + 條件變異數 + Important Sampling

dt = T/NSteps;
nudt = (r-0.5*sigma^2)*dt;
b = bp*nudt;
sidt = sigma * sqrt(dt);

[Call,Put] = blsprice(S0,x,r,T,sigma);

% Generate asset paths and payoff for the down and in option
NCrossed = 0;
Payoff = zeros(NRepl,1);
Times = zeros(NRepl,1);
StockVals = zeros(NRepl,1);
ISRatio = zeros(NRepl,1);
UOCallMCCondIS
for i = 1:NRepl

% generate normal
vetZ = nudt -b +sidt*randn(1,NSteps);
LogPath = cumsum([log(S0),vetZ]);
Path = exp(LogPath);

tcrossed = min(find(Path>=Sb));
if not(isempty(tcrossed))
NCrossed = NCrossed+1;
TBreach = tcrossed-1;
Times(NCrossed) = TBreach*dt;
StockVals(NCrossed) = Path(tcrossed);

ISRatio(NCrossed) = exp(TBreach * b^2/2/sigma^2/dt +...


b/sigma^2/dt *sum(vetZ(1:TBreach)) - TBreach * b/sigma^2*(r-sigma^2/2));
end
end
UOCallMCCondIS

if (NCrossed>0)
[Caux,Paux] = blsprice(StockVals(1:NCrossed),x,r,T-Times(1:NCrossed),sigma);
Payoff(1:NCrossed) = exp(-r*Times(1:NCrossed)) .* Caux .* ISRatio(1:NCrossed);
end

[Cuo,aux,Cl] = normfit(Call - Payoff);

You might also like