0% found this document useful (0 votes)
76 views

HW 5

The document discusses using Monte Carlo simulation to price European put options. It provides code to calculate the price and confidence interval using the Black-Scholes formula as well as Monte Carlo simulation with different numbers of replications. The results show that as the number of replications increases from 1000 to 200,000, the Monte Carlo price estimate converges closer to the Black-Scholes price. A visualization is also proposed to show how increasing the number of simulations reduces the error compared to the Black-Scholes value.

Uploaded by

api-289065336
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

HW 5

The document discusses using Monte Carlo simulation to price European put options. It provides code to calculate the price and confidence interval using the Black-Scholes formula as well as Monte Carlo simulation with different numbers of replications. The results show that as the number of replications increases from 1000 to 200,000, the Monte Carlo price estimate converges closer to the Black-Scholes price. A visualization is also proposed to show how increasing the number of simulations reduces the error compared to the Black-Scholes value.

Uploaded by

api-289065336
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Malab exercise

101071041

TriEurPut
function [price, lattice] = TriEurPut(S0,X,r,T,sigma,N,lamda)
deltaT = T/N;
u=exp(lamda*sigma * sqrt(deltaT));
d=1/u;
pu=1/(2*lamda^2)+(r-(sigma^2/2))*sqrt(deltaT)/(2*lamda*sigma);
pm=1-1/(lamda^2);
pd=1-pu-pm;
lattice = zeros(N+1,2*N+1);
for j=1:N+1
lattice(N+1,j)=max(0 , X-S0*(d^(N-j+1)) );
end
for j=N+2:2*N+1
lattice(N+1,j)=max(0 , x-S0*(u^(j-N-1)) );
end
for i=N-1:-1:0
for j=1:2*i+1
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);

COMPARE
S0 = 50;
X = 50;
r = 0.04879;
sigma = 0.2;
T = 7/12;
N=70;
lamda=1.41421;
[BlsC,p] = blsprice(S0,X,r,T,sigma);
LatticeC1 = zeros(1,N);
LatticeC2 = zeros(1,N);
for i=(1:N)
[LatticeC1(i),tree1] = LatticeEurPut(S0,X,r,T,sigma,i);
[LatticeC2(i),tree2] = TriEurPut(S0,X,r,T,sigma,i,lamda);
end
plot(1:N, ones(1,N)*p);
hold on;
plot(1:N, LatticeC1);
plot(1:N, LatticeC2);

Q:lamd ?

TriAmPut
function [price, lattice] = TriAmPut(S0,X,r,T,sigma,N,lamda)
deltaT = T/N;
u=exp(lamda*sigma * sqrt(deltaT));
d=1/u;
pu=1/(2*lamda^2)+(r-(sigma^2/2))*sqrt(deltaT)/(2*lamda*sigma);
pm=1-1/(lamda^2);
pd=1-pu-pm;
lattice = zeros(N+1,2*N+1);
for j=1:N+1
lattice(N+1,j)=max(0 , X-S0*(d^(N-j+1)) );
end
for j=N+2:2*N+1
lattice(N+1,j)=max(0 , X-S0*(u^(j-N-1)) );
end
for i=N-1:-1:0
for j=1:2*i+1
lattice(i+1,j) = max(X-S0*u^j*d^(i-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);

compare
S0 = 50;
X = 50;
r = 0.04879;
sigma = 0.2;
T = 7/12;
N=70;
lamda=1.41421;
[BlsC,p] = blsprice(S0,X,r,T,sigma);
LatticeC1 = zeros(1,N);
LatticeC2 = zeros(1,N);
for i=(1:N)
[LatticeC1(i),tree1] = TriAmPut(S0,X,r,T,sigma,i,lamda);
[LatticeC2(i),tree2] = LatticeAmPut(S0,X,r,T,sigma,i);
end
plot(1:N, ones(1,N)*p,'b');
hold on;
plot(1:N, LatticeC1,'c');
plot(1:N, LatticeC2,'m');
legend('blsput','triamput','latticeamput');

Q: ????!

European put/Monte Carlo Simulation


BLSMP
function [Price, CI] = BlsMC(S0,X,r,T,sigma,NRepl)
nuT = (r - 0.5*sigma^2)*T;
siT = sigma * sqrt(T);
DiscPayoff = exp(-r*T) * max( 0 ,X- S0*exp(nuT+siT*randn(NRepl,1)) );
[Price, ~, CI] = normfit(DiscPayoff);

compare
S0=50;
X=52;
r=0.1;
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)
randn('seed',0);
[MC200000, CI200000] =

MC1000 =
5.3861

Bls =
5.1911

CI1000 =
4.9789
5.7933
MC200000 =
5.0722
CI200000 =
5.0439
5.1004

Visualization of the fact that the larger simu


lating numbers, the closer to the bls
Code
S0 = 50;
X = 52;
r = 0.1;
sigma = 0.4;
T = 5/12;
NRepl=100;
[BlsC,p] = blsprice(S0,X,r,T,sigma);
LatticeC1 = zeros(1,1000);
for i=(1:1000)
[LatticeC1(i)] =BlsMC(S0,X,r,T,sigma,NRepl*i)-p;
end
plot(1:1000, LatticeC1,'c');

You might also like