You are on page 1of 17

Homework03

103071509


LatticeEurPut.m
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 , S0*(u^j)*(d^(N-j)) - X);
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);

>> [price, lattice] = LatticeEurPut(100,100,0.02,1,0.2,10)


price =
8.7207
lattice =
8.7207
0
0
0
0
0
0
0
0
0
0
5.0843 12.3919
0
0
0
0
0
0
0
0
0
2.5144 7.6744 17.1587
0
0
0
0
0
0
0
0
0.9490 4.0897 11.2897 23.0962
0
0
0
0
0
0
0
0.2082 1.6936 6.5021 16.1223 30.1623
0
0
0
0
0
0
0 0.4172 2.9767 10.0533 22.2557 38.1893
0
0
0
0
0
0
0 0.8361 5.1292 15.0174 29.5828 46.9483
0
0
0
0
0
0
0 1.6755 8.6033 21.4913 37.7925 56.2917
0
0
0
0
0
0
0 3.3577 13.8831 29.1852 46.5507 66.2576
0
0
0
0
0
0
0 6.7286 21.0929 37.3941 55.8933 76.8869
0
0
0
0
0
0
0 13.4839 28.7860 46.1515 65.8584 88.2227

CompLatticeBLSPut.
m

% CompLatticeBLSPut.m
S0 = 60;
X = 60;
r = 0.05;
sigma = 0.4;
T = 0.5;
N=60;
BlsP = blsprice(S0,X,r,T,sigma);
LatticeP = zeros(1,N);
for i=(1:N)
LatticeP(i) = LatticeEurPut(S0,X,r,T,sigma,i);
end
plot(1:N, ones(1,N)*BlsP);
hold on;
plot(1:N, LatticeP)


LatticeEurPut vs.BLS
S0 = 50;
X = 50;
r = 0.1;
sigma = 0.4;
T = 5/12;
N=50;
BlsP = blsprice(S0,X,r,T,sigma);
LatticeP = zeros(1,N);
for i=(1:N)
LatticeP(i) = LatticeEurPut(S0,X,r,T,sigma,i);
end
plot(1:N, ones(1,N)*BlsP);
hold on;
plot(1:N, LatticeP);
title('LatticeEurPut v.s BLS')

LatticeAmCall
vs.BLS
S0 = 50;
X = 50;
r = 0.1;
sigma = 0.4;
T = 5/12;
N=50;
BlsC = blsprice(S0,X,r,T,sigma);
LatticeC = zeros(1,N);
for i=(1:N)
LatticeC(i) = LatticeAmCall(S0,X,r,T,sigma,i);
end
plot(1:N, ones(1,N)*BlsC);
hold on;
plot(1:N, LatticeC);
title('compare LatticeAmCall to bls')

LatticeAmCall vs. LatticeEurCall


%LatticeAmC-LatticeEurC
S0=50;
X=50;
r=0.1;
sigma=0.4;
T=5/12;
N=100;
BlsC=blsprice(S0,X,r,T,sigma);
LatticeAmC=zeros(1,N);
LatticeEurC=zeros(1,N);
for i=(1:N)
LatticeAmC(i)=LatticeAmCall(S0,X,r,T,sigma,i);
LatticeEurC(i)=LatticeEurCall(S0,X,r,T,sigma,i);
end
plot(1:N,LatticeAmC-LatticeEurC);
ylabel('LatticeAmC-LatticeEurC')
grid

Bull spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,50,0.05,T,0.
3);
[C2,P2]=blsprice(S0,60,0.05,T,0.
3);
plot(S0,C1-C2);
hold on;
End

%Bull_spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,40,0.05,T,0.5);
[C2,P2]=blsprice(S0,50,0.05,T,0.5);
plot(S0,P1-P2);
hold on;
end

Bear spread
%Bear_spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,40,0.05,T,0.
5);
[C2,P2]=blsprice(S0,50,0.05,T,0.
5);
plot(S0,C2-C1);
hold on;
end

%Bear_spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,40,0.05,T,0.5);
[C2,P2]=blsprice(S0,50,0.05,T,0.5);
plot(S0,P2-P1);
hold on;
end

Butterfly
spread
%Butterfly_spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,40,0.05,T,0
.5);
[C2,P2]=blsprice(S0,50,0.05,T,0
.5);
[C3,P3]=blsprice(S0,60,0.05,T,0
.5);
plot(S0,C1-2*C2+C3);
hold on;
end

%Butterfly_spread
S0=30:1:90;
for T=2:-0.25:0
[C1,P1]=blsprice(S0,40,0.0
5,T,0.5);
[C2,P2]=blsprice(S0,50,0.0
5,T,0.5);
[C3,P3]=blsprice(S0,60,0.0
5,T,0.5);
plot(S0,P1-2*P2+P3);
hold on;
end

You might also like