You are on page 1of 20

1

MATLAB for Finance

u
d

C=f(S,t)

9 European Option Pricing


Jens Carsten Jackwerth
University of Konstanz
jens.jackwerth@uni-konstanz.de

MATLAB for Finance

Motivation

C=f(S,t)

European Option Pricing

Black Scholes Model

MATLAB for Finance

u
d

European Binomial Put Option Pricing

C=f(S,t)

Right, but not the obligation to sell a share at the strike price
K.
European put option: stock price S=50; strike price K=55;
time t=0.5; steps n=2; volatility =0.20; interest rate return
r=0.05
Up move:
Down move:

ue

0.2 0.5

1
0.9048
u

Risk-neutral probability:

qu

1.1052

1 r n d

0.5363

ud

MATLAB for Finance

European Binomial Put Option Pricing II

C=f(S,t)

Stock price development:

Put payoff

Terminal prices
after 2 steps:

0=max[0;55-61.1]

61.1=50*u2
55.3

5.4
50=50*u0

50

2.3
5=max[0;55-50]
9.1

45.2

14.1=max[0;55-40.9]
40.9=50*u-2

5 * qu 14.1 * (1- qu)

1 r n
t

MATLAB for Finance

European Binomial Put Option Pricing III

C=f(S,t)

Terminal prices
after n steps

Put payoff in
the different states

50*un

max{55-50*un,0}

=p1n+1

50*un-2

max{55-50*un-2,0}

=p2n+1

50*un-4

max{55-50*un-4,0}

=p3n+1
length: n+1

50*u-n+4

max{55-50*u-n+4,0}

=pn-1n+1

50*u-n+2

max{55-50*u-n+2,0}

=pnn+1

50*u-n

max{55-50*u-n,0}

=pn+1n+1

=P(:,n+1)

MATLAB for Finance

European Binomial Put Option Pricing IV

C=f(S,t)

Using the function max with two input arguments (vectors of


the same length, or one is scalar), e.g. max(X,Y), it returns a
vector with the same length as the input arguments as
follows:
X=[1;2;3],Y=[3;2;1]
X=
1
2
3
Y=
3
2
1

max(X,Y)
ans=

max(X,2)
ans=
3
2
3

2
2
3

MATLAB for Finance

European Binomial Put Option Pricing V

C=f(S,t)

Receiving the put payoff price vector in the last column


of the square (n+1 n+1) matrix P:
n number of steps, K strike price, S stock price, u up move factor.

%up move factor u:


u=exp(sigma*sqrt(T/n));
%creating P:
P=zeros(n+1,n+1);
%Defining the last column of P:
P(:,n+1)=(K-(u.^(n:-2:-n)*S))';
% max{p_ij,0}:
P(:,n+1)=max(P(:,n+1),0);

MATLAB for Finance

European Binomial Put Option Pricing VI

C=f(S,t)

Going step-wise back to obtain the value of the European


option:

MATLAB for Finance

u
d

C=f(S,t)

European Binomial Put Option Pricing


VII

Going one step back:

P(1:end-1,n+1)

p1n

max{55-50*un,0}

max{55-50*un,0}

=p1n+1

p2n

max{55-50*un-2,0}

max{55-50*un-2,0}

=p2n+1

p3n

max{55-50*un-4,0}

max{55-50*un-4,0}

=p3n+1

pn-1n

max{55-50*u-n+4,0}

max{55-50*u-n+4,0}

=pn-1n+1

pnn

max{55-50*u-n+2,0}

max{55-50*u-n+2,0}

=pnn+1

max{55-50*u-n,0}

max{55-50*u-n,0}

pn-2n

=pn+1n+1

P(2:end,n+1)

10

MATLAB for Finance

u
d

C=f(S,t)

Example: Black Scholes Binomial Model


European Put Option

function price=put_binomial(S, K, sigma , T , n, r)


%The function call_binomial calculates the value of an European option with the binomial model.
%S_0 is the current value of the underlying asset, sigma its standard deviation, t the number of
%years until maturity and n the number of steps.
u=exp(sigma*sqrt(T/n));
q_u=((1+r)^(T/n)-1/u)/(u-1/u);
q_d=1-q_u;
P(:,n+1)=(K-(u.^(n:-2:-n)*S))';
P(P(:,n+1)<0,n+1)=0;
for j=1:n
P(1:(n+1)-j,(n+1)-j)=(P(1:(n+1-j),(n+2-j))*q_u+P(2:(n+2-j),(n+2-j))*(q_d))/((1+r)^(T/n));

end
price=P(1,1);

11

MATLAB for Finance

u
d

European Binomial Call Option Pricing

C=f(S,t)

Right, but not the obligation to buy a share at the strike


price K.
European call option: stock price S=50; strike price K=55;
time t=0.5; steps n=2; volatility =0.20; interest rate return
r=0.05
Up move:
Down move:

ue

0.2 0.5

1
0.9048
u

Risk-neutral probability:

qu

1.1052

1 r n d

0.5363

ud

12

MATLAB for Finance

European Binomial Call Option Pricing II

C=f(S,t)

Stock price development:

Call payoff

Terminal prices
after 2 steps:

6.1=max[0;61.1-55]

61.1=50*u2
55.3

1.7
50=50*u0

50

3.2
0=max[0;50-55]
0

45.2

0=max[0;40.9-55]
40.9=50*u-2

6.1 * qu 0 * (1- qu)

1 r n
t

13

MATLAB for Finance

Black Scholes Continuous-Time Model

C=f(S,t)

call_bs S,K,T,r, =S d1 K erT d2


2. put_bs S,K,T,r, =K erT d2 S d1
with

2
log
+ r+
T

2
d1 =
T
1.

d2 =d1 T
and the Gaussian cumulative density function:

cdf('norm',di,0,1)

14

MATLAB for Finance

Exercises I

C=f(S,t)

a)

b)

c)

Code the two functions call_bs and put_bs from the slide
before.
Write a function that calculates the value of a European
call option with the binomial model(call_binomial).
Now use the function call_binomial. Write a piece of code
called Option_eval that returns a plot of call prices
depending on the number of steps n for n=1:200. Draw in
the value of the call option with the continuous-time
model call_bs as a constant function. Use the following
parameters: sigma=0.5, T=0.25, K=95, S=100 and r=0.1.

15

MATLAB for Finance

u
d

Solution Exercise I a) call_bs

C=f(S,t)

function call=call_bs(S, K, r, sigma, T)


%The function call_bs(S,K,r,sigma,T) calculates the value of a call option according
%to the Black Scholes model. S (scalar) is the underlying value of the asset,
%K (scalar) is the strike price, r (scalar) interest rate, sigma (scalar)
%the volatility and T (scalar) duration until maturity.
d_1=(log(S/K)+(r+sigma^2/2)*T)/(sigma*sqrt(T));
d_2=d_1-sigma*sqrt(T);
call=S*cdf('norm',d_1,0,1)-K*exp(-r*T)*cdf('norm',d_2,0,1);

16

MATLAB for Finance

u
d

Solution Exercise I a) put_bs

C=f(S,t)

function put=put_bs(S, K, r, sigma, T)


%The function put_bs(S,K,T,r,sigma) calculates the Black Scholes put option price,
%depending on the stock price S, strike price K, years until maturity T,
%interest rate r and volatility sigma.
d_1=(log(S/K)+(r+sigma^2/2)*T)/(sigma*sqrt(T));
d_2=d_1-sigma*sqrt(T);
put=K*exp(-r*T)*cdf('norm',-d_2,0,1)-S*cdf('norm',-d_1,0,1);

17

MATLAB for Finance

u
d

Solution Exercise I b) call_binomial

C=f(S,t)

function call=call_binomial(S, K, sigma , t , n, r)


%The function call_binomial(S, K, sigma , t , n, r) calculates the present value of an option with
%the Binomial Black Scholes model. S is the current value of the underlying asset, sigma its
%standard deviation, t the number of years until maturity and n the number of steps.
u=exp(sigma*sqrt(t/n));
q_u=((1+r)^(t/n)-1/u)/(u-1/u);
q_d=1-q_u;
P(:,n+1)=((u.^(n:-2:-n)*S)-K)';
P(:,n+1)=max(P(:,n+1),0)
for j=1:n
P(1:(n+1)-j,(n+1)-j)=(P(1:(n+1-j),(n+2-j))*q_u+P(2:(n+2-j),(n+2-j))*(q_d))/((1+r)^(t/n));
end
call=P(1,1);

18

MATLAB for Finance

u
d

Solution Exercise I c) Option_eval

C=f(S,t)

clc; clear all;


S=100; K=95; sigma=0.5; T=0.25; r=0.1;
M=200;
for n=1:M
call(n)=call_binomial(S,K,sigma,T,n,r);
end
plot(1:M,call);
hold on;
plot(3:M,call_bs(S,K,r,sigma,T),'k-')
title('Black Scholes: Binomial Model versus Continuous Model');
xlabel('Number of steps');
ylabel('Option price');
legend('Binomial','Continuous')

19

MATLAB for Finance

Solution Exercise I c)

C=f(S,t)
c)

Option_eval.m

20

MATLAB for Finance

Solution Exercise I c) Additional Material

C=f(S,t)

But: The binomial model does not converge to the value


of the Black Scholes model.

You might also like