Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

HW 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Homework11

103071509


SIGN
function [ payoff, lattice ] = SIGN_bit( S0, K, r, T, sigma, N )
deltaT = T/N;
u = exp( sigma * sqrt(deltaT) );
d = 1/u;
p = ( exp( r * deltaT ) - d ) / ( u - d );
for i = 0 : N
P = S0 * u^(N-i) * d^(i);
S(i+1) = 10;
if P > K
S(i+1) = 10 * (1+(P-K)/K);
end
end
for i = N : -1 : 1
for j = 0 : i-1
S(j+1) = max(10, exp(-r*deltaT) * ( S(j+1)*p + S(j+2)*(1-p) ) );
end
lattice(1:i,i) = S(1:i);
end
payoff = S(1);
end

%CompSIGN
S = 400;
K = 336.69;
r = 0.1;
sigma = 0.2;
T = 1;
N = 5000;
for i = 1:200
bit(i) = SIGN_bit(i+300,K,r,sigma,T,N);
end
plot(301:500,bit)
for i = 1:200
bit(i) = SIGN_bit(S,i+300,r,sigma,T,N);
end
plot(301:500,bit)


European Call (Explicit)
% EuCallExpl1.m
function price =
EuCallExpl1(S0,X,r,T,sigma,Smax,dS,dt)
% set up grid and adjust increments if
necessary
M = round(Smax/dS);
dS = Smax/M;
N = round(T/dt);
dt = T/N;
matval = zeros(M+1,N+1);
vetS = linspace(0,Smax,M+1)';
vetj = 0:N;
veti = 0:M;
% set up boundary conditions
matval(:,N+1) = max(vetS-X,0);
matval(1,:) =0;
matval(M+1,:) = Smax-X*exp(-r*dt*(N-vetj));
% set up coefficients
a = 0.5*dt*(sigma^2*veti - r).*veti;
b = 1- dt*(sigma^2*veti.^2 + r);
c = 0.5*dt*(sigma^2*veti + r).*veti;

% solve backward in time


for j=N:-1:1
for i=2:M
matval(i,j) = a(i)*matval(i-1,j+1) +
b(i)*matval(i,j+1)+ ...
c(i)*matval(i+1,j+1);
end
End
% find closest point to S0 on the grid and return price
% possibly with a linear interpolation
idown = floor(S0/dS);
iup = ceil(S0/dS);
if idown == iup
price = matval(idown+1,1);
else
price = matval(idown+1,1) + ...
(S0 -(idown+1)*dS)*(matval(iup+1,1) matval(iup,1))/dS;
end

S0=50;
X=50;
r=0.1;
T=5/12;
sigma1=0.4;
sigma2=0.3;
Smax=100;
dS1=2;
dS2=1.5;
dS3=1;
dT=5/1200;
[c01,p04]=blsprice(S0,X,r,T,sigma1);
Exps01=EuCallExpl1(S0,X,r,T,sigma1,Smax,dS1,dT);
[c02,p03]=blsprice(S0,X,r,T,sigma2);
Exps02dS2=EuCallExpl1(S0,X,r,T,sigma2,Smax,dS1,dT);
ExpdS15=EuCallExpl1(S0,X,r,T,sigma2,Smax,dS2,dT);
ExpdS1=EuCallExpl1(S0,X,r,T,sigma2,Smax,dS3,dT);
c01
Exps01
c02
Exps02dS2
ExpdS15
ExpdS1

c01 =
6.1165
Exps01 =
-3.5813e+04
c02 =
4.8851
Exps02dS2 =
4.8697
ExpdS15 =
252.2526

% CompExpl3D.m Compare blsprice and BlsHalton


S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.3;
Smax=100;
dS=2;
dt=5/1200;
[ExpdS1,matval,vetS,vetT]=EuCallExplall(S0,X,r,T,sigma,Smax,dS,dt);
matval
ExpdS1
mesh(vetT,vetS,matval);
ylabel('Stock price'); xlabel('Time'); title('European Call Option,
Explicit Method');

% CompExpl3D.m Compare blsprice and BlsHalton


S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.3;
Smax=100;
dS=1;
dt=5/1200;
[ExpdS1,matval,vetS,vetT]=EuCallExplall(S0,X,r,T,sigma,Smax,dS,dt);
matval
ExpdS1
mesh(vetT,vetS,matval);
ylabel('Stock price'); xlabel('Time'); title('European Call Option, Explicit
Method');


European Call (Implicit)
% EuCallImpl.m
function price =
EuCallImpl(S0,X,r,T,sigma,Smax,dS,dt)
% set up grid and adjust increments if necessary
M = round(Smax/dS);
dS = Smax/M;
N = round(T/dt);
dt = T/N;
matval = zeros(M+1,N+1);
vetS = linspace(0,Smax,M+1)';
vetj = 0:N;
veti = 0:M;
% set up boundary conditions
matval(:,N+1) = max(vetS-X,0);
matval(1,:) = 0;
matval(M+1,:) =Smax-X*exp(-r*dt*(N-vetj));
% set up the tridiagonal coefficients matrix
a = 0.5*(r*dt*veti-sigma^2*dt*(veti.^2));
b = 1+sigma^2*dt*(veti.^2)+r*dt;
c = -0.5*(r*dt*veti+sigma^2*dt*(veti.^2));

coeff = diag(a(3:M),-1) + diag(b(2:M)) +


diag(c(2:M-1),1);
[L,U] = lu(coeff);
% solve the sequence of linear systems
aux = zeros(M-1,1);
for j=N:-1:1
aux(1) = - a(2) * matval(1,j);
%matval(2:M,j) = U \ (L \ (matval(2:M,j+1) +
aux));
matval(2:M,j) = coeff \ (matval(2:M,j+1) + aux);
end
% find closest point to S0 on the grid and return
price
% possibly with a linear interpolation
idown = floor(S0/dS);
iup = ceil(S0/dS);
if idown == iup
price = matval(idown+1,1);
else
price = matval(idown+1,1) + ...
(S0 - idown*dS)*(matval(idown+2,1) matval(idown+1,1))/dS;
end

% CompBlsImpl.m Compare blsprice and


BlsHalton

% CompBlsImpl.m Compare blsprice and


BlsHalton

S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.4;
Smax=100;
dS=2;
dT=5/2400;
[c,p]=blsprice(S0,X,r,T,sigma);
Impl=EuCallImpl(S0,X,r,T,sigma,Smax,dS,dT);

S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.4;
Smax=100;
dS=0.5;
dT=5/2400;
[c,p]=blsprice(S0,X,r,T,sigma);
Impl=EuCallImpl(S0,X,r,T,sigma,Smax,dS,dT);

c
Impl

c
Impl

c=

c=

6.1165
Impl =

6.1165
Impl =

5.6977

5.7185

% CompImpl3D.m Compare blsprice and BlsHalton


S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.3
Smax=100;
dS=2;
dT=5/1200;
[ExpdS1,matval,vetS,vetT]=EuCallImplall(S0,X,r,T,sigma,Smax,dS,dT);
matval
ExpdS1
mesh(vetT,vetS,matval);
ylabel('Stock price'); xlabel('Time'); title('European Call Option, Implicit
Method');

% CompImpl3D.m Compare blsprice and BlsHalton


S0=50;
X=50;
r=0.1;
T=5/12;
sigma=0.3
Smax=100;
dS=0.5;
dT=5/1200;
[ExpdS1,matval,vetS,vetT]=EuCallImplall(S0,X,r,T,sigma,Smax,dS,dT);
matval
ExpdS1
mesh(vetT,vetS,matval);
ylabel('Stock price'); xlabel('Time'); title('European Call Option,
Implicit Method');

You might also like