SlideShare a Scribd company logo
Options pricing using Lattice models • October 2019 • with C++ code snippets
Options pricing
using Lattice models in C++
QUASAR CHUNAWALA
quasar.chunawala@gmail.com
October 2019
Abstract
This is a short essay on using lattice methods to price European and American style
options.
1. BINOMIAL TREES
1.1. Introduction.
Binomial trees are useful for pricing a variety of European and American-style derivatives.
The primary practical use of the Binomial model was and still is for pricing American-style
options.
1.2. Pricing a European call option on a binomial tree.
Consider a stock with initial price S0, which follows a binomial process. During a time
period ∆t, the price per share of this stock will be one of two possible values, it can go up
to S0u or down to S0d. Consider a European call option that confers on its owner the right,
but not the obligation to buy one share of stock at time one for the strike price K. The
European call option pays (St − K)+
at time t.
We assume that the markets are complete. In a complete market, every derivative
security can be replicated by trading in the stock and money market asset.
Suppose we begin with an initial wealth X0 and buy ∆ shares of a stock at price S0 at
time zero, leaving us with a cash postion X0 − ∆S0. The value of our portfolio of stock and
the money market account at time one is :
X1 = ∆S1 + er∆t
(X0 − ∆S0) = X0er∆t
+ ∆(S1 − S0er∆t
)
We want to find X0 and ∆ so, that X1(u) = Cu and X1(d) = Cd. Note here, that Cu and
Cd are given quantities, the amounts that the derivative security will pay off depending
upon the outcome of the coin tosses. At time zero, we know what the two values Cu and
Cd are; we don’t know which of these two possibilities will be realized. Replication of the
derivative security thus requires that :
1
Options pricing using Lattice models • October 2019 • with C++ code snippets
Figure 1: A binomial tree with N=4 timesteps
e−r∆t
Cu = X0 + ∆(S0ue−r∆t
− S0)
e−r∆t
Cd = X0 + ∆(S0de−r∆t
− S0)
One way to solve these two equations in two unknowns is to multiply the first by a
number ˜p and the second by ˜q = 1 − ˜p and then add them to get
e−r∆t
(˜pCu + ˜qCd) = X0 + ∆((˜pS0u + ˜qS0d)e−r∆t
− S0)
If we choose ˜p so that the ∆ term in the above equation is zero, that is :
S0 = e−r∆t
(˜pS0u + ˜qS0d)
we obtain the simple formula for X0,
X0 = e−r∆t
(˜pCu + ˜qCd)
We can solve for ˜p and ˜q as follows:
S0 = e−r∆t
(˜pS0u + ˜qS0d)
er∆t
= (˜pu + (1 − ˜p)d)
er∆t
= ˜p(u − d) + d
˜p =
er∆t
− d
u − d
˜q =
u − er∆t
u − d
2
Options pricing using Lattice models • October 2019 • with C++ code snippets
We can solve for ∆ simply by subtracting the portfolio values at time one -
∆ =
Cu − Cd
S0u − S0d
Thus, we have replicated the option payoff.
The numbers ˜p and ˜q are both positive because of the no-arbitrage condition and they
sum to one. For this reason, we can regard them as up and down probabilities. They are
not the actual probabilities, which I shall p and q, but rather the risk-neutral probabilities.
Under the actual probabilities, the average rate of growth of a stock is typically strictly
greater than the rate of growth of an investment in the money market; otherwise no one
would want to incur the risk associated with investing in the stock. Thus, p and q = 1 − p
should satisfy
S0 < e−r∆t
(pS0u + qS0d)
whereas ˜p and ˜q satisfy
S0 = e−r∆t
(˜pS0u + ˜qS0d)
If the average rate of growth of the stock were exactly the same as the rate of growth
of the money market investment, then investors must be neutral about risk - they do
not require compensation for assuming it, nor are they willing to pay extra for it. This
is simply not the case, and hence ˜p and ˜q cannot be the actual probabilities. They are
only numbers which assist us in the solution of the two equations in the two unknowns
(∆, X0). They assist us by making the term multiplying the unknown ∆ drop out. If we
want to construct a portfolio whose value at time one is V1, then its value at time zero,
must be given by the formula above, so that its mean rate of growth under risk-neutral
probabilities is the rate of growth of the money market investment. The formula is called
the risk-neutral pricing formula.
1.3. Matching moments of the binomial and lognormal distributions.
Consider a time period ∆t in the continuous time Black Scholes world. Suppose the stock
price process governed by following SDE :
dS = mSdt + σSdz
where m and σ are known constants - the mean rate of growth of the stock and the
volatility of the stock price respectively. The simplest choice is a constant volatility.
From Ito’s formula, we know that, if S(t) is any stochastic process, then the process
f(S(t), t) is given by the expansion :
df =
∂f
∂t
+ mS
∂f
∂S
+
1
2
σ2
S2 ∂2
f
∂S2
dt + σS
∂f
∂S
dz
If we let f(S) = log S then we obtain the following Wiener process :
3
Options pricing using Lattice models • October 2019 • with C++ code snippets
∂f
∂t
= 0
∂f
∂S
=
1
S
∂2
f
∂S2
= −
1
S2
=⇒ d(ln S) = (m −
1
2
σ2
)dt + σdz
=⇒ ln(
ST
S0
) = (m −
1
2
σ2
)T + σZ(0, T)
=⇒ ST = S0 exp[(m − σ2
/2)T + σ
√
TZ(0, 1)]
Thus, log ST is normally distributed.
log ST ∼ N(log S0 + (m − σ2
/2)T, σT)
We can now calculate the moments of the lognormal distribution around 0. We need
to calculate the mean and variance. Since, log ST is normally distributed, we can use the
moment generating function of the normal distribution to help calculate expections.
The MGF of a normal random variable Z is given by,
E(etZ
) =
+∞
−∞
etz 1
√
2π
e−z2
/2
dz
= et2
/2 1
√
2π
+∞
−∞
e−(z−t)2
/2
dz
= et2
/2
The MGF of X = ν + σZ by completing the square as above is MX(t) = eνt+σ2
t2
/2
. Let
the random variable Y = eX
= eν+σZ
. Then E(Y n
) = E(enX
) = eνn+σ2
n2
/2
.
Therefore, in particular,
E[ST ] = S0e(ν+σ2
/2)∆t
= S0e(m−σ2
/2+σ2
/2)∆t
= S0em∆t
E[S2
T ] = S0e(2ν+2σ2
)∆t
= S0e(2m−σ2
+2σ2
)∆t
= S0e(2m+σ2
)∆t
For the underlying price at the end of the period to have the same mean and variance
in both the binomial model and the Black Scholes models, the following two identities
must hold where the first and second moments are matched.
4
Options pricing using Lattice models • October 2019 • with C++ code snippets
pu + (1 − p)d = er∆t
pu2
+ (1 − p)d2
= e(2r+σ2
)∆t
Solving the first equation for the probability p, we obtain :
p =
er∆t
− d
u − d
1.4. CRR Binomial Tree.
Cox, Ross, Rubinstein in their original model assume the identity ud = 1, so that u = 1/d.
Substituting u = 1/d and the value of the risk neutral probability p into the second
equation we get :
p(u2
− d2
) + d2
= e(2r+σ2
)∆t
(er∆t
− d)(u + d) + d2
= e(2r+σ2
)∆t
er∆t
(u + d) − du − d2
+ d2
= e(2r+σ2
)∆t
er∆t
(u + d) − du = e(2r+σ2
)∆t
er∆t
(d2
+ 1) − d = e(2r+σ2
)∆t
d
(d2
+ 1) − d(e−r∆t
+ e(r+σ2
)∆t
) = 0
d2
− 2Ad + 1 = 0
where A = 1
2 (e−r∆t
+ e(r+σ2
)∆t
).
The solutions of this quadratic equation are:
u = A + A2 − 1
d = A − A2 − 1
If we linearize the above solution using the series expansion ex
= 1 + x + x2
2! + . . ., we
obtain -
A =
1
2
[(1 − r∆t) + (1 + r∆t + σ2
∆t)]
= 1 +
1
2
σ2
∆t
A2
=
1
4
[(1 − 2r∆t) + (1 + 2r∆t + 2σ2
∆t) + 2(1 + σ2
∆t)]
= 1 + σ2
∆t
u = 1 + σ
√
∆t +
1
2
σ2
∆t
d = 1 − σ
√
∆t +
1
2
σ2
∆t
5
Options pricing using Lattice models • October 2019 • with C++ code snippets
Terms of higher orders can be added without violating the relations since they become
infinitesimally small as ∆t approached 0. Thus, the more common form is
u = eσ
√
∆t
d = e−σ
√
∆t
The CRR has traditionally been the most widely used version of the binomial model.
[1]
1.5. CRR Binomial Tree implementation.
The following is an implementation of the CRR model on a European option.
#include<iostream>
#include <iostream>
#include <array>
class CRRBinomialTree
{
private:
double p;
std::array<std::array<double, 200>, 200> S;
std::array<std::array<double, 200>, 200> C;
double u;
double d;
double T;
int N;
double sigma;
double dt;
double r;
double s_0;
double K;
char optionType;
double q;
public:
CRRBinomialTree(double vol, double expiry, int numOfTimeSteps,
double spot, double strike, double rate, double div, char optType);
double pv();
double payOff(double s_t);
};
// CRRBinomialTree.cpp : Computes the value of a European
// option using backwards induction in a CRR Binomial tree
#include<iostream>
#include "CRRBinomialTree.h"
#include<cmath>
CRRBinomialTree::CRRBinomialTree(double vol, double expiry, int numOfTimeSteps,
6
Options pricing using Lattice models • October 2019 • with C++ code snippets
double spot, double strike, double rate, double div, char optType)
{
N = numOfTimeSteps;
T = expiry;
dt = T / N;
r = rate;
q = div;
sigma = vol;
u = exp(sigma * sqrt(dt));
d = 1 / u;
double a = exp((r - q) * dt);
p = (a - d) / (u - d);
s_0 = spot;
K = strike;
optionType = optType;
S = {0.0};
C = {0.0};
//compute the stock prices at each node
//initialize call prices
for (int i = 0; i <= N; ++i)
{
for (int j = 0; j <= i; ++j)
{
S[i][j] = s_0 * pow(u, j) * pow(d, i - j);
C[i][j] = 0.0;
}
}
}
double CRRBinomialTree::payOff(double S_t)
{
if (optionType == 'C')
return std::max(S_t - K, 0.0);
if (optionType == 'P')
return std::max(K - S_t, 0.0);
}
double CRRBinomialTree::pv()
{
double df = 0.0;
//compute terminal payoffs
for (int j = N; j >= 0; --j)
{
C[N][j] = payOff(S[N][j]);
}
//work backwards
7
Options pricing using Lattice models • October 2019 • with C++ code snippets
for (int i = N - 1; i >= 0; --i)
{
for (int j = i; j >= 0; --j)
{
df = exp(-r * dt);
C[i][j] = df * (p * C[i + 1][j + 1] + (1 - p) * C[i + 1][j]);
}
}
return C[0][0];
}
#include<iostream>
#include "CRRBinomialTree.h"
int main()
{
CRRBinomialTree *europeanCall, *europeanPut;
europeanCall = new CRRBinomialTree(0.10, 1.0, 100, 100.0, 100.0, 0.05, 0.0, 'C');
europeanPut = new CRRBinomialTree(0.10, 1.0, 100, 100.0, 100.0, 0.05, 0.0, 'P');
double V_0=0.0;
V_0 = europeanCall->pv();
std::cout << "nCall value = " << V_0;
V_0 = europeanPut->pv();
std::cout << "nPut value = " << V_0;
return 0;
}
1.6. Early exercise of American options on non-dividend paying stocks.
Consider the following two portfolios at time t:
Portfolio A: One European Call option c, Ke−r(T −t)
cash.
Portfolio B: One share of stock worth St
In portfolio A, the cash will grow to K at time T. If ST > K, the option will be exercised
at maturity, and the portfolio A is worth ST . If ST < K, the call option expires worthless
and the portfolio is worth K. Hence, at time T, the portfolio is worth
max(ST , K)
Portfolio B is worth ST at time T. Hence, portfolio A is always worth as much as, and
can be worth more than the portfolio B at maturity.
max(ST , K) ≥ ST
In the absence of arbitrage opportunities, this must also be true today.
8
Options pricing using Lattice models • October 2019 • with C++ code snippets
c + Ke−r(T −t)
≥ St
c ≥ St − Ke−r(T −t)
≥ (St − K)
So, the European call c is always worth more than its intrinsic at expiry. Because
the owner of an American call has all the exercise opportunities open to the owner of a
corresponding European call, we must have C ≥ c. Given r > 0, C > St − K. This means
that C is always greater than the option’s intrinsic value prior to maturity.
Hence, it is never optimal to exercise American call options on non-dividend paying
stocks.
2. TRINOMIAL TREES
Trinomial trees are used more in practice then binomial trees, since they allow for 3
states: up, down and middle moves. We can price both European and American options
with trinomial trees.
2.1. CRR Trinomial tree.
The CRR has a symmetric tree structure where,
u = eλσ
√
∆t
(1)
d = e−λσ
√
∆t
(2)
ud = m2
= 1 (3)
The necessary and sufficient condition for the tree to recombine is ud = m2
.
We can compute the option value in a trinomial tree as the discounted expectation in
a risk-neutral world by computing:
Ci,j = e−r∆t
(puCi+1,j+1 + pmCi+1,j + pdCi+1,j−1) (4)
As before, we match the first two moments of the trinomial and lognormal distributions.
puu + (1 − pu − pd) + pdd = em∆t
(5)
puu2
+ (1 − pu − pd) + pdd2
= e(2m+σ2
)∆t
(6)
If we take the first order approximations of the power series of ex
, we can solve for
pu, pm, pd as follows. Let k = λσ
√
∆t. The first moment yields :
puek
+ (1 − pu − pd) + pde−k
= er∆t
pu(1 + k + k2
/2) + (1 − pu − pd) + pd(1 − k + k2
/2) = (1 + r∆t)
pu(k + k2
/2) + pd(−k + k2
/2) = r∆t
(7)
9
Options pricing using Lattice models • October 2019 • with C++ code snippets
The second moment yields:
pue2k
+ (1 − pu − pd) + pde−2k
= e(2r+σ2
)∆t
2λσ
√
∆t(pu − pd) = 2r∆t + σ2
∆t
pu(1 + 2k + 2k2
) + (1 − pu − pd) + pd(1 − 2k + 2k2
) = (1 + 2r∆t + σ2
∆t)
pu(2k + 2k2
) + pd(−2k + 2k2
) = 2r∆t + σ2
∆t
(8)
Plugging in the value of r∆t from equation 7 into 8, we obtain:
pu(2k + 2k2
) + pd(−2k + 2k2
) = 2r∆t + σ2
∆t
pu(2k + 2k2
) + pd(−2k + 2k2
) = pu(2k + k2
) + pd(−2k + k2
) + σ2
∆t
(pu + pd)k2
= σ2
∆t
(1 − pm)λ2
σ2
∆t = σ2
∆t
1 − pm =
1
λ2
pm = 1 −
1
λ2
(9)
Multiplying the left and right hand sides of the equation 9 by (−k + k2
/2),
pu + pd =
σ2
∆t
k2
pu(−k + k2
/2) + pd(−k + k2
/2) =
σ2
∆t
λ2σ2∆t
(−k + k2
/2)
pu(−k + k2
/2) + pd(−k + k2
/2) =
1
λ2
(−k + k2
/2)
(10)
I now solve equations 7 and 10 simultaneously.
pu(2k) = r∆t −
1
λ2
(−k + k2
/2)
pu(2λσ
√
∆t) = r∆t +
λσ
√
∆t
λ2
−
λ2
σ2
∆t
2λ2
pu(2λσ) ≈ r
√
∆t +
σ
λ
pu =
1
2λ2
+
1
2
r
λσ
√
∆t
(11)
Since pu and pd should add up to 1/λ2
,
pd =
1
2λ2
−
1
2
r
λσ
√
∆t (12)
It has been found that the value of λ that produces the best convergence rate is:
λ =
3
2
10
Options pricing using Lattice models • October 2019 • with C++ code snippets
2.2. CRR Trinomial Tree implementation.
The following code implements an American CRR trinomial tree with λ = 3/2. Suppose
we use a trinomial tree to price an at-the-money (ATM) American call option on a stock
priced at 50 dollars, strike price of 50, volatility of 20 percent, risk-free rate of 6 percent,
annual dividend yield of 3 percent and time to maturity = 1 year. Thus, S = 50, K = 50,
σ = 0.20, r = 0.06, q = 0.03 and T = 1.
//CRRTrinomialTree.h
#include <iostream>
#include <array>
class CRRTrinomialTree
{
private:
double p_u,p_d,p_m;
std::array<std::array<double, 250>, 250> S;
std::array<std::array<double, 250>, 250> C;
double u;
double d;
double T;
int N;
double sigma;
double dt;
double r;
double s_0;
double K;
char optionType;
double q;
double drift;
public:
CRRTrinomialTree(double vol, double expiry, int numOfTimeSteps,
double spot, double strike, double rate, double div, char optType);
double pv();
double payOff(double s_t);
void printTree();
int x(int i, int j);
int y(int i, int j);
};
// CRRTrinomialTree.cpp : Computes the value of a American option
// using backwards induction in a CRR Trinomial tree
#include<iostream>
#include "CRRTrinomialTree.h"
#include <cmath>
#include <iomanip>
CRRTrinomialTree::CRRTrinomialTree(double vol, double expiry, int numOfTimeSteps,
11
Options pricing using Lattice models • October 2019 • with C++ code snippets
double spot, double strike, double rate, double div, char optType)
{
N = numOfTimeSteps;
T = expiry;
dt = T / N;
r = rate;
q = div;
sigma = vol;
drift = (r - q - pow(sigma, 2.0) / 2.0);
const double lambda = sqrt(3.0 / 2.0);
u = exp(lambda * sigma * sqrt(dt));
d = 1 / u;
p_u = (1 / (2 * pow(lambda, 2))) +
(1 / 2) * (drift / (lambda * sigma)) * sqrt(dt);
p_d = (1 / (2 * pow(lambda, 2))) -
(1 / 2) * (drift / (lambda * sigma)) * sqrt(dt);
p_m = 1 - (1 / pow(lambda, 2));
s_0 = spot;
K = strike;
optionType = optType;
S = { 0.0 };
C = { 0.0 };
//compute the stock prices at each node
//initialize call prices
for (int i = 0; i <= N; ++i)
{
for (int j = -i; j <= i; ++j)
{
S[x(i,j)][y(i,j)] = s_0 * pow(u, j);
C[x(i,j)][y(i,j)] = 0.0;
}
}
}
int CRRTrinomialTree::x(int i, int j)
{
return (i + j);
}
int CRRTrinomialTree::y(int i, int j)
{
return i;
}
void CRRTrinomialTree::printTree()
{
std::cout << "nStock price tree";
std::cout << std::setprecision(5);
12
Options pricing using Lattice models • October 2019 • with C++ code snippets
for(int i = 2*N; i>=0;--i)
{
std::cout << "nn";
for (int j = 0; j <= N; ++j)
{
std::cout << "t" << S[i][j];
}
}
std::cout << "nnCall price tree";
for (int i = 2 * N; i >= 0; --i)
{
std::cout << "nn";
for (int j = 0; j <= N; ++j)
{
std::cout << "t" << C[i][j];
}
}
}
double CRRTrinomialTree::payOff(double S_t)
{
if (optionType == 'C')
return std::max(S_t - K, 0.0);
if (optionType == 'P')
return std::max(K - S_t, 0.0);
}
double CRRTrinomialTree::pv()
{
double df = 0.0;
int h = 0;
//compute terminal payoffs
for (int j = N; j >= -N; --j)
{
C[x(N,j)][y(N,j)] = payOff(S[x(N,j)][y(N,j)]);
}
//work backwards
for (int i = N - 1; i >= 0; --i)
{
for (int j = i; j >= -i; --j)
{
df = exp(-r * dt);
double v_u = C[x(i + 1, j + 1)][y(i + 1, j + 1)];
double v_m = C[x(i + 1, j)][y(i + 1, j)];
double v_d = C[x(i + 1, j - 1)][y(i + 1, j - 1)];
13
Options pricing using Lattice models • October 2019 • with C++ code snippets
double discountedExpectation = df * (p_u * v_u
+ p_m * v_m + p_d * v_d);
C[x(i,j)][y(i,j)] = std::max(discountedExpectation,
payOff(S[x(i,j)][y(i,j)]));
}
}
return C[0][0];
}
// testCRRTrinomialTree.cpp
#include<iostream>
#include "CRRTrinomialTree.h"
int main()
{
CRRTrinomialTree* americanCall;
americanCall = new CRRTrinomialTree(0.20, 1, 4, 50, 50, 0.06, 0.03, 'C');
double V_0 = americanCall->pv();
std::cout << "nPut value = " << V_0;
americanCall->printTree();
return 0;
}
The American call price and tree are printed as shown below:
Call value = 4.22538
Stock price tree
0 0 0 0 81.607
0 0 0 0 72.2
0 0 0 72.2 63.878
0 0 0 63.878 56.515
0 0 63.878 56.515 50
0 0 56.515 50 44.236
0 56.515 50 44.236 39.137
0 50 44.236 39.137 34.626
50 44.236 39.137 34.626 30.634
Call price tree
14
Options pricing using Lattice models • October 2019 • with C++ code snippets
0 0 0 0 31.607
0 0 0 0 22.2
0 0 0 22.226 13.878
0 0 0 13.986 6.5145
0 0 14.09 6.6962 0
0 0 7.494 2.1392 0
0 8.0402 2.9013 0 0
0 3.6442 0.70244 0 0
4.2254 1.1834 0 0 0
3. FINITE DIFFERENCE METHODS
Numerical methods known as finite difference methods are used for pricing derivatives
by approximating the diffusion process that the derivative must follow. Finite difference
methods schemes are used to numerically solve PDEs. They are particular useful for
valuation, when a closed-form analytical solution does not exist. By discretizing the
continuous time PDE, the derivative security must follow, it is possible approximate the
evolution of the derivative prices and therefore the PV of the contract.
3.1. The Black Scholes PDE.
Consider an underlying asset with price x. The underlying price evolves according to:
dx = µxdt + σxdz (13)
Consider a derivative contract whose value C depends on the asset price x at time t,
and can be thought of as a function C(t, x) of the random asset price x and time t. Using
Ito’s lemma, the function of a stochastic variable follows the process :
dC =
∂C
∂t
+ µx
∂C
∂x
+
1
2
σ2
x2 ∂2
C
∂x2
dt + σx
∂C
∂x
dz (14)
In the same way as for the asset-pricing model in equation 13, the process for C(t, x)
has two components - the drift component and a volatility component. The drift term is
deterministic, involving the drift and volatility parameters of the asset price process and
the partials of C with respect to x and t. Fundamentally, the source of randomness dz in
the asset-price process in equation 13 is the same as that in the derivative-price process
in equation 14.
It should therefore be possible to eliminate the source of randomness to create a
riskless portfolio Π akin to a money market asset. Construct a portfolio Π by shorting the
derivative C and buying ∂C
∂x units of the underlying.
15
Options pricing using Lattice models • October 2019 • with C++ code snippets
Π = −C +
∂C
∂x
x (15)
The change in the value of the portfolio over the time period dt is the differential,
dΠ = −dC +
∂C
∂x
dx (16)
Subsituting for dC and dx in equation 16 and using equations 13 and 14,
dΠ = −
∂C
∂t
+ µx
∂C
∂x
+
1
2
σ2
x2 ∂2
C
∂x2
dt − σx
∂C
∂x
dz +
∂C
∂x
(µxdt + σxdz) (17)
Simplifying we obtain,
dΠ =
∂C
∂t
+
1
2
σ2
x2 ∂2
C
∂x2
dt (18)
Finally, the rate of return on the riskless portfolio is:
dΠ
Π
=
∂C
∂t + 1
2 σ2
x2 ∂2
C
∂x2 dt
−C + ∂C
∂x x
= rdt (19)
The derivative C(t, x) price must therefore be the solution of the partial differential
equation,
∂C
∂t
(t, x) + rx
∂C
∂x
(t, x) +
1
2
σ2
x2 ∂2
C
∂x2
(t, x) = rC(t, x) (20)
3.2. Difference operators.
The principle of the finite difference method is to approximate the derivatives in partial
differential equations by a linear combination of the function values.
The derivative of a function at the point x can be approximated as:
Forward difference divided by h:
∆h[f](x)
h
=
f(x + h) − f(x)
h
(21)
Backward difference divided by h:
h[f](x)
h
=
f(x) − f(x − h)
h
(22)
Central difference divided by h:
δh[f](x)
h
=
f(x + h/2) − f(x − h/2)
h
(23)
In an analogous way, one can obtain finite difference approximations to higher order
derivatives and differential operators.
16
Options pricing using Lattice models • October 2019 • with C++ code snippets
The second order central difference:
f (x) ≈
δ2
h[f](x)
h
=
f (x + h/2) − f (x − h/2)
h
=
f(x+h)−f(x)
h − f(x)−f(x−h)
h
h
=
f(x + h) − 2f(x) + f(x − h)
h2
(24)
The second order forward difference:
f (x) ≈
∆2
h[f](x)
h
=
f (x + h) − f (x)
h
=
f(x+2h)−f(x+h)
h − f(x+h)−f(x)
h
h
=
f(x + 2h) − 2f(x + h) + f(x)
h2
(25)
The second order backward difference:
f (x) ≈
2
h[f](x)
h
=
f (x) − f (x − h)
h
=
f(x)−f(x−h)
h − f(x−h)−f(x−2h)
h
h
=
f(x) − 2f(x − h) + f(x − 2h)
h2
(26)
Mixed partial derivatives can be obtained as follows. Taking the central difference of
the x and y variables, we could obtain, for example:
∂2
u
∂x∂y i,j
=
∂
∂x
∂u
∂y
≈
(∂u
∂y )i+1,j − (∂u
∂y )i−1,j
2∆x
=
ui+1,j+1−ui+1j−1
2∆y −
ui−1,j+1−ui−1j−1
2∆y
2∆x
=
ui+1,j+1 − ui+1,j−1 − ui−1,j+1 + ui−1,j−1
4∆x∆y
(27)
3.3. Explicit finite difference scheme.
Consider the Black Scholes PDE:
∂C
∂t
+ rS
∂C
∂S
+
1
2
σ2
S2 ∂2
C
∂S2
= rC (28)
subject to the payoff condition C(t, ST ) = max(ST − K)+
.
We can simply this PDE by substituting it with finite differences. First, let’s substitute
x = log S, so that ∂C
∂S = ∂C
∂x · ∂x
∂S = 1
S
∂C
∂x and ∂2
C
∂S2 = − 1
S2
∂C
∂x + 1
S2
∂2
C
∂x2 .
∂C
∂t
+ ν
∂C
∂x
+
1
2
σ2 ∂2
C
∂x2
= rC (29)
We imagine time and space divided up into discrete intervals (∆t and ∆x), this is the
finite difference grid or lattice.
To obtain the explicit finite difference method we approximate the equation 29 using a
forward difference for ∂C/∂t and central differences for ∂C/∂x and ∂2
C/∂x2
. Denote by
Ci,j = C(ti, xj)
Therefore,
∂C
∂t t=ti
=
Ci+1,j − Ci,j
∆t
(30)
17
Options pricing using Lattice models • October 2019 • with C++ code snippets
∂C
∂x x=xj
=
Ci+1,j+1 − Ci+1,j−1
2∆x
(31)
∂2
C
∂x2
x=xj
=
Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1
∆x2
(32)
Figure 2: Stencils for grid points for explicit and implicit finite difference schemes in
solving a PDE that is first order in t and second order in x
Substituting these values in the equation 29 we obtain,
Ci+1,j − Ci,j
∆t
+r
Ci+1,j+1 − Ci+1,j−1
2∆x
+
1
2
σ2 Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1
∆x2
= rCi,j (33)
Multiplying throughout by 2∆x2
∆t,
2r(∆x)2
∆tCi,j = 2(∆x)2
(Ci+1,j − Ci,j) + r∆x∆t(Ci+1,j+1 − Ci+1,j−1)
+ σ2
∆t(Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1)
=⇒ Ci,j(2∆x2
)(1 + r∆t) = (r∆x∆t + σ2
∆t)Ci+1,j+1 + (2∆x2
− 2σ2
∆t)Ci+1,j
+ (σ2
∆t − r∆x∆t)Ci+1,j−1
=⇒ Ci,j =
1
1 + r∆t
∆t
r
2∆x
+
σ2
2∆x2
Ci+1,j+1 + 1 −
σ2
∆x2
∆t Ci+1,j
+
1
2
σ2
∆x2
−
r
∆x
∆t Ci+1,j−1
(34)
The coefficients of Ci+1,j+1, Ci+1,j and Ci+1,j−1 can be thought of as the trinomial
probabilities. (1 + r∆t) is the discounting factor.
Therefore the explicit finite difference method is equivalent of approximating the Black
Scholes diffusion process by a discrete trinomial process, where,
18
Options pricing using Lattice models • October 2019 • with C++ code snippets
Ci,j =
1
1 + r∆t
(puCi+1,j+1 + pmCi + 1, j + pdCi+1,j−1) (35)
pu = ∆t
r
2∆x
+
σ2
2∆x2
(36)
pm = 1 −
σ2
∆x2
∆t (37)
pd =
1
2
σ2
∆x2
−
r
∆x
∆t (38)
3.4. Explicit finite difference implementation.
We create a rectangular grid or lattice by adding extra nodes to a trinomial tree, so that
we have 2M + 1, M >= N at every time step i instead of just 2i + 1.
However, at time step i, given all option values at i + 1, we cannot compute the bottom
and top option values (Ci,−M and Ci,M ) using discounted expectations, since this would
require knowing option values Ci+1,−M−1 and Ci+1,M+1 which we do not have. With no
additional information we can only compute the region indicated by the dashed branches
using discounted expectations.
In order to be able to compute the remainder of the grid we must add the extra
boundary conditions which determine the behavior of the option price as a function asset
price for high and low values of the asset price xj.
For example, for a European call option we have the following Neumann boundary
conditions (the delta for deep ITM calls is 1, whereas for deep OTM calls is 0):
∂C
∂S
(t, S) = 1 for large S (39)
∂C
∂S
(t, S) = 0 for small S (40)
In terms of the grid, the conditions 39 and 40 become:
Ci,M − Ci,M−1
Si,M − Si,M−1
= 1 for large S (41)
Ci,−M+1 − Ci,−M
Si,−M+1 − Si,−M
= 0 for small S (42)
I price a one-year ATM European call option with S = 100, K = 100, T = 1 year, r = 0.06,
δ = 0.03, M = 3, N = 3, ∆x = 0.02.
// ExplicitFDMGrid.h
#include <iostream>
#include <array>
class ExplicitFDMGrid
{
19
Options pricing using Lattice models • October 2019 • with C++ code snippets
private:
double p_u, p_d, p_m;
std::array<std::array<double, 250>, 250> S;
std::array<std::array<double, 250>, 250> C;
double T;
long M;
long N;
double sigma;
double dt;
double r;
double s_0;
double K;
char optionType;
double q;
double drift;
double dx;
public:
ExplicitFDMGrid(double vol, double expiry, long N_, long M_,
double spot, double strike, double rate, double div, char optType, double dx);
double pv();
double payOff(double s_t);
void printTree();
int row(int i, int j);
int col(int i, int j);
};
// ExplicitFDMGrid.cpp : Computes the value of a European option
// the explicit finite difference method
#include<iostream>
#include "ExplicitFDMGrid.h"
#include <cmath>
#include <iomanip>
ExplicitFDMGrid::ExplicitFDMGrid(double vol, double expiry, long N_, long M_,
double spot, double strike, double rate, double div, char optType, double deltax)
{
N = N_; M = M_;
T = expiry;
dt = T / N;
r = rate;
q = div;
sigma = vol;
dx = deltax;
drift = (r - q - pow(sigma, 2.0) / 2.0);
p_u = 0.50 * dt * (pow((sigma/dx),2)+(drift/dx));
p_m = 1 - dt * (pow((sigma / dx), 2));
p_d = 0.50 * dt * (pow((sigma / dx), 2) - (drift / dx));
s_0 = spot;
K = strike;
20
Options pricing using Lattice models • October 2019 • with C++ code snippets
optionType = optType;
S = { 0.0 };
C = { 0.0 };
std::cout << "np_u = " << p_u;
std::cout << "np_m = " << p_m;
std::cout << "np_d = " << p_d;
//initialize the asset prices at maturity
//these apply to every time step
for (int j = -M; j <= M; ++j)
{
for (int i = 0; i <= N; ++i)
{
S[row(i, j)][col(i, j)] = s_0 * exp(j * dx);
}
}
//initialize the option values at maturity
for (int j = -M; j <= M; ++j)
{
C[row(N, j)][col(N, j)] = payOff(S[row(N, j)][col(N, j)]);
}
}
int ExplicitFDMGrid::row(int i, int j)
{
return (M+j);
}
int ExplicitFDMGrid::col(int i, int j)
{
return i;
}
void ExplicitFDMGrid::printTree()
{
std::cout << "nStock price tree";
std::cout << std::setprecision(8);
for (int j = 2 * M; j >= 0; --j)
{
std::cout << "nn";
for (int i = 0; i <= N; ++i)
{
std::cout << "t" << S[j][i];
}
}
21
Options pricing using Lattice models • October 2019 • with C++ code snippets
std::cout << "nnCall price tree";
for(int j = 2 * M; j >= 0; --j)
{
std::cout << "nn";
for (int i = 0; i <= N; ++i)
{
std::cout << "t" << C[j][i];
}
}
}
double ExplicitFDMGrid::payOff(double S_t)
{
if (optionType == 'C')
return std::max(S_t - K, 0.0);
if (optionType == 'P')
return std::max(K - S_t, 0.0);
}
double ExplicitFDMGrid::pv()
{
double df = 0.0;
//work backwards
for (int i = N - 1; i >= 0; --i)
{
for (int j = M - 1; j >= -M+1; --j)
{
df = exp(-r * dt);
double v_u = C[row(i + 1, j + 1)][col(i + 1, j + 1)];
double v_m = C[row(i + 1, j)][col(i + 1, j)];
double v_d = C[row(i + 1, j - 1)][col(i + 1, j - 1)];
C[row(i,j)][col(i,j)] = (p_u * v_u
+ p_m * v_m + p_d * v_d);
}
//Neumann boundary conditions
if (optionType == 'C')
{
C[row(i, M)][col(i, M)] = C[row(i, M - 1)][col(i, M - 1)] +
(S[row(i, M)][col(i, M)] - S[row(i, M - 1)][col(i, M - 1)]);
C[row(i, -M)][col(i, -M)] = C[row(i, -M + 1)][col(i, -M + 1)];
}
else if (optionType == 'P')
{
C[row(i, M)][col(i, M)] = C[row(i, M - 1)][col(i, M - 1)];
22
Options pricing using Lattice models • October 2019 • with C++ code snippets
C[row(i, -M)][col(i, -M)] = C[row(i, -M + 1)][col(i, -M + 1)] +
(S[row(i, -M)][col(i, -M)] - S[row(i, -M + 1)][col(i, -M + 1)]);
}
}
return C[row(0,0)][col(0,0)];
}
// test explicit FDM grid
#include<iostream>
#include "ExplicitFDMGrid.h"
int main()
{
ExplicitFDMGrid* g;
g = new ExplicitFDMGrid(0.20, 1, 3, 3, 100, 100, 0.06,0.03,'C',0.2);
double V_0 = g->pv();
std::cout << "nOption value = " << V_0;
g->printTree();
return 0;
}
REFERENCES
[1] Mark Rubinstein John Cox, Stephen Ross. Option pricing: A simplified approach.
Journal of Financial Economics, 1979.
23

More Related Content

What's hot

Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
BlueMax Capital
 
Forex trading strategies
Forex trading strategiesForex trading strategies
Forex trading strategies
IFC Markets Corp.
 
DS Lecture 2.ppt
DS Lecture 2.pptDS Lecture 2.ppt
DS Lecture 2.ppt
NomanMehboob4
 
Simple scalping secret strategy
Simple scalping secret strategySimple scalping secret strategy
Simple scalping secret strategy
Heri Valiant
 
SIP & TLS - Security in a peer to peer world
SIP & TLS - Security in a peer to peer worldSIP & TLS - Security in a peer to peer world
SIP & TLS - Security in a peer to peer world
Olle E Johansson
 
6lowpan 110828234426-phpapp01
6lowpan 110828234426-phpapp016lowpan 110828234426-phpapp01
6lowpan 110828234426-phpapp01
mrmr2010i
 
Guide to-fibonacci-trading
Guide to-fibonacci-tradingGuide to-fibonacci-trading
Guide to-fibonacci-trading
BoyEnvi BoyEnvi
 
BlackBull Markets - Forex White Label Program
BlackBull Markets - Forex White Label ProgramBlackBull Markets - Forex White Label Program
BlackBull Markets - Forex White Label Program
BlackBull Markets
 
OpenSplice DDS Tutorial -- Part II
OpenSplice DDS Tutorial -- Part IIOpenSplice DDS Tutorial -- Part II
OpenSplice DDS Tutorial -- Part II
Angelo Corsaro
 
Candlestick cheat-sheet-rgb-final
Candlestick cheat-sheet-rgb-finalCandlestick cheat-sheet-rgb-final
Candlestick cheat-sheet-rgb-final
subucud
 
DDS QoS Unleashed
DDS QoS UnleashedDDS QoS Unleashed
DDS QoS Unleashed
Angelo Corsaro
 
RTSP Analysis Wireshark
RTSP Analysis WiresharkRTSP Analysis Wireshark
RTSP Analysis Wireshark
Yoss Cohen
 
Introduction to Option Greeks
Introduction to Option GreeksIntroduction to Option Greeks
Introduction to Option Greeks
Marketcalls
 
7 Basic Rules for Trading in Intraday
7 Basic Rules for Trading in Intraday7 Basic Rules for Trading in Intraday
7 Basic Rules for Trading in Intraday
Platinum Trading Systems
 

What's hot (14)

Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
Forex Trading - How to Create a Trading Strategy | Different Candle Stick Pat...
 
Forex trading strategies
Forex trading strategiesForex trading strategies
Forex trading strategies
 
DS Lecture 2.ppt
DS Lecture 2.pptDS Lecture 2.ppt
DS Lecture 2.ppt
 
Simple scalping secret strategy
Simple scalping secret strategySimple scalping secret strategy
Simple scalping secret strategy
 
SIP & TLS - Security in a peer to peer world
SIP & TLS - Security in a peer to peer worldSIP & TLS - Security in a peer to peer world
SIP & TLS - Security in a peer to peer world
 
6lowpan 110828234426-phpapp01
6lowpan 110828234426-phpapp016lowpan 110828234426-phpapp01
6lowpan 110828234426-phpapp01
 
Guide to-fibonacci-trading
Guide to-fibonacci-tradingGuide to-fibonacci-trading
Guide to-fibonacci-trading
 
BlackBull Markets - Forex White Label Program
BlackBull Markets - Forex White Label ProgramBlackBull Markets - Forex White Label Program
BlackBull Markets - Forex White Label Program
 
OpenSplice DDS Tutorial -- Part II
OpenSplice DDS Tutorial -- Part IIOpenSplice DDS Tutorial -- Part II
OpenSplice DDS Tutorial -- Part II
 
Candlestick cheat-sheet-rgb-final
Candlestick cheat-sheet-rgb-finalCandlestick cheat-sheet-rgb-final
Candlestick cheat-sheet-rgb-final
 
DDS QoS Unleashed
DDS QoS UnleashedDDS QoS Unleashed
DDS QoS Unleashed
 
RTSP Analysis Wireshark
RTSP Analysis WiresharkRTSP Analysis Wireshark
RTSP Analysis Wireshark
 
Introduction to Option Greeks
Introduction to Option GreeksIntroduction to Option Greeks
Introduction to Option Greeks
 
7 Basic Rules for Trading in Intraday
7 Basic Rules for Trading in Intraday7 Basic Rules for Trading in Intraday
7 Basic Rules for Trading in Intraday
 

Similar to Options pricing using Lattice models

presentation
presentationpresentation
presentation
Gábor Bakos
 
DP_M4_L2.pdf
DP_M4_L2.pdfDP_M4_L2.pdf
DP_M4_L2.pdf
ssusercf3299
 
BB_11_Futures & Options_Hull_Chap_12.pptx
BB_11_Futures & Options_Hull_Chap_12.pptxBB_11_Futures & Options_Hull_Chap_12.pptx
BB_11_Futures & Options_Hull_Chap_12.pptx
IbrahimKhatatbeh5
 
Remark on variance swaps pricing
Remark on variance swaps pricingRemark on variance swaps pricing
Remark on variance swaps pricing
Ilya Gikhman
 
Remark on variance swaps pricing new
Remark on variance swaps pricing newRemark on variance swaps pricing new
Remark on variance swaps pricing new
Ilya Gikhman
 
BB_12_Futures & Options_Hull_Chap_13.pptx
BB_12_Futures & Options_Hull_Chap_13.pptxBB_12_Futures & Options_Hull_Chap_13.pptx
BB_12_Futures & Options_Hull_Chap_13.pptx
IbrahimKhatatbeh5
 
The comparative study of finite difference method and monte carlo method for ...
The comparative study of finite difference method and monte carlo method for ...The comparative study of finite difference method and monte carlo method for ...
The comparative study of finite difference method and monte carlo method for ...
Alexander Decker
 
11.the comparative study of finite difference method and monte carlo method f...
11.the comparative study of finite difference method and monte carlo method f...11.the comparative study of finite difference method and monte carlo method f...
11.the comparative study of finite difference method and monte carlo method f...
Alexander Decker
 
Options pricing and hedging
Options pricing and hedgingOptions pricing and hedging
Options pricing and hedging
Ilya Gikhman
 
Derivatives pricing and Malliavin Calculus
Derivatives pricing and Malliavin CalculusDerivatives pricing and Malliavin Calculus
Derivatives pricing and Malliavin Calculus
Hugo Delatte
 
Black-Scholes overview
Black-Scholes overviewBlack-Scholes overview
Black-Scholes overview
Inon Sharony
 
Option pricing model
Option pricing modelOption pricing model
Option pricing model
Vishal Jain
 
Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)
Ameya Ranadive
 
Black-Schole Model.pptx
Black-Schole Model.pptxBlack-Schole Model.pptx
Black-Schole Model.pptx
YashRajSingh731869
 
The convenience yield implied by quadratic volatility smiles presentation [...
The convenience yield implied by quadratic volatility smiles   presentation [...The convenience yield implied by quadratic volatility smiles   presentation [...
The convenience yield implied by quadratic volatility smiles presentation [...
yigalbt
 
Value of options presentation
Value of options presentationValue of options presentation
Value of options presentation
Trevor Ruwa
 
Modeling an Asset Price
Modeling an Asset PriceModeling an Asset Price
Modeling an Asset Price
Adnan Kuhait
 
портфель English
портфель Englishпортфель English
портфель English
Ilya Gikhman
 
Black scholes pricing consept
Black scholes pricing conseptBlack scholes pricing consept
Black scholes pricing consept
Ilya Gikhman
 
Black Scholes pricing consept
Black Scholes pricing conseptBlack Scholes pricing consept
Black Scholes pricing consept
Ilya Gikhman
 

Similar to Options pricing using Lattice models (20)

presentation
presentationpresentation
presentation
 
DP_M4_L2.pdf
DP_M4_L2.pdfDP_M4_L2.pdf
DP_M4_L2.pdf
 
BB_11_Futures & Options_Hull_Chap_12.pptx
BB_11_Futures & Options_Hull_Chap_12.pptxBB_11_Futures & Options_Hull_Chap_12.pptx
BB_11_Futures & Options_Hull_Chap_12.pptx
 
Remark on variance swaps pricing
Remark on variance swaps pricingRemark on variance swaps pricing
Remark on variance swaps pricing
 
Remark on variance swaps pricing new
Remark on variance swaps pricing newRemark on variance swaps pricing new
Remark on variance swaps pricing new
 
BB_12_Futures & Options_Hull_Chap_13.pptx
BB_12_Futures & Options_Hull_Chap_13.pptxBB_12_Futures & Options_Hull_Chap_13.pptx
BB_12_Futures & Options_Hull_Chap_13.pptx
 
The comparative study of finite difference method and monte carlo method for ...
The comparative study of finite difference method and monte carlo method for ...The comparative study of finite difference method and monte carlo method for ...
The comparative study of finite difference method and monte carlo method for ...
 
11.the comparative study of finite difference method and monte carlo method f...
11.the comparative study of finite difference method and monte carlo method f...11.the comparative study of finite difference method and monte carlo method f...
11.the comparative study of finite difference method and monte carlo method f...
 
Options pricing and hedging
Options pricing and hedgingOptions pricing and hedging
Options pricing and hedging
 
Derivatives pricing and Malliavin Calculus
Derivatives pricing and Malliavin CalculusDerivatives pricing and Malliavin Calculus
Derivatives pricing and Malliavin Calculus
 
Black-Scholes overview
Black-Scholes overviewBlack-Scholes overview
Black-Scholes overview
 
Option pricing model
Option pricing modelOption pricing model
Option pricing model
 
Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)Options pricing ( calculation of option premium)
Options pricing ( calculation of option premium)
 
Black-Schole Model.pptx
Black-Schole Model.pptxBlack-Schole Model.pptx
Black-Schole Model.pptx
 
The convenience yield implied by quadratic volatility smiles presentation [...
The convenience yield implied by quadratic volatility smiles   presentation [...The convenience yield implied by quadratic volatility smiles   presentation [...
The convenience yield implied by quadratic volatility smiles presentation [...
 
Value of options presentation
Value of options presentationValue of options presentation
Value of options presentation
 
Modeling an Asset Price
Modeling an Asset PriceModeling an Asset Price
Modeling an Asset Price
 
портфель English
портфель Englishпортфель English
портфель English
 
Black scholes pricing consept
Black scholes pricing conseptBlack scholes pricing consept
Black scholes pricing consept
 
Black Scholes pricing consept
Black Scholes pricing conseptBlack Scholes pricing consept
Black Scholes pricing consept
 

More from Quasar Chunawala

Resume
ResumeResume
Systems of linear algebraic equations i
Systems of linear algebraic equations iSystems of linear algebraic equations i
Systems of linear algebraic equations i
Quasar Chunawala
 
Vector Addition
Vector AdditionVector Addition
Vector Addition
Quasar Chunawala
 
Recursive squaring
Recursive squaringRecursive squaring
Recursive squaring
Quasar Chunawala
 
Investigation of functions
Investigation of functionsInvestigation of functions
Investigation of functions
Quasar Chunawala
 
Vector spaces
Vector spacesVector spaces
Vector spaces
Quasar Chunawala
 
Interpolation techniques - Background and implementation
Interpolation techniques - Background and implementationInterpolation techniques - Background and implementation
Interpolation techniques - Background and implementation
Quasar Chunawala
 

More from Quasar Chunawala (7)

Resume
ResumeResume
Resume
 
Systems of linear algebraic equations i
Systems of linear algebraic equations iSystems of linear algebraic equations i
Systems of linear algebraic equations i
 
Vector Addition
Vector AdditionVector Addition
Vector Addition
 
Recursive squaring
Recursive squaringRecursive squaring
Recursive squaring
 
Investigation of functions
Investigation of functionsInvestigation of functions
Investigation of functions
 
Vector spaces
Vector spacesVector spaces
Vector spaces
 
Interpolation techniques - Background and implementation
Interpolation techniques - Background and implementationInterpolation techniques - Background and implementation
Interpolation techniques - Background and implementation
 

Recently uploaded

waterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
waterlessdyeingtechnolgyusing carbon dioxide chemicalspdfwaterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
waterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
LengamoLAppostilic
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
Daniel Tubbenhauer
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
KrushnaDarade1
 
Thornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdfThornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdf
European Sustainable Phosphorus Platform
 
Eukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptxEukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptx
RitabrataSarkar3
 
Oedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptxOedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptx
muralinath2
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
hozt8xgk
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
MAGOTI ERNEST
 
The binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defectsThe binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defects
Sérgio Sacani
 
Direct Seeded Rice - Climate Smart Agriculture
Direct Seeded Rice - Climate Smart AgricultureDirect Seeded Rice - Climate Smart Agriculture
Direct Seeded Rice - Climate Smart Agriculture
International Food Policy Research Institute- South Asia Office
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
AbdullaAlAsif1
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
Gokturk Mehmet Dilci
 
Basics of crystallography, crystal systems, classes and different forms
Basics of crystallography, crystal systems, classes and different formsBasics of crystallography, crystal systems, classes and different forms
Basics of crystallography, crystal systems, classes and different forms
MaheshaNanjegowda
 
The cost of acquiring information by natural selection
The cost of acquiring information by natural selectionThe cost of acquiring information by natural selection
The cost of acquiring information by natural selection
Carl Bergstrom
 
aziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobelaziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobel
İsa Badur
 
Immersive Learning That Works: Research Grounding and Paths Forward
Immersive Learning That Works: Research Grounding and Paths ForwardImmersive Learning That Works: Research Grounding and Paths Forward
Immersive Learning That Works: Research Grounding and Paths Forward
Leonel Morgado
 
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of ProteinsGBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
Areesha Ahmad
 
ESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptxESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptx
PRIYANKA PATEL
 
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
Advanced-Concepts-Team
 
Randomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNERandomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNE
University of Maribor
 

Recently uploaded (20)

waterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
waterlessdyeingtechnolgyusing carbon dioxide chemicalspdfwaterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
waterlessdyeingtechnolgyusing carbon dioxide chemicalspdf
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
 
SAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdfSAR of Medicinal Chemistry 1st by dk.pdf
SAR of Medicinal Chemistry 1st by dk.pdf
 
Thornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdfThornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdf
 
Eukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptxEukaryotic Transcription Presentation.pptx
Eukaryotic Transcription Presentation.pptx
 
Oedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptxOedema_types_causes_pathophysiology.pptx
Oedema_types_causes_pathophysiology.pptx
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
 
The binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defectsThe binding of cosmological structures by massless topological defects
The binding of cosmological structures by massless topological defects
 
Direct Seeded Rice - Climate Smart Agriculture
Direct Seeded Rice - Climate Smart AgricultureDirect Seeded Rice - Climate Smart Agriculture
Direct Seeded Rice - Climate Smart Agriculture
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
 
Basics of crystallography, crystal systems, classes and different forms
Basics of crystallography, crystal systems, classes and different formsBasics of crystallography, crystal systems, classes and different forms
Basics of crystallography, crystal systems, classes and different forms
 
The cost of acquiring information by natural selection
The cost of acquiring information by natural selectionThe cost of acquiring information by natural selection
The cost of acquiring information by natural selection
 
aziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobelaziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobel
 
Immersive Learning That Works: Research Grounding and Paths Forward
Immersive Learning That Works: Research Grounding and Paths ForwardImmersive Learning That Works: Research Grounding and Paths Forward
Immersive Learning That Works: Research Grounding and Paths Forward
 
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of ProteinsGBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
 
ESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptxESR spectroscopy in liquid food and beverages.pptx
ESR spectroscopy in liquid food and beverages.pptx
 
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
 
Randomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNERandomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNE
 

Options pricing using Lattice models

  • 1. Options pricing using Lattice models • October 2019 • with C++ code snippets Options pricing using Lattice models in C++ QUASAR CHUNAWALA quasar.chunawala@gmail.com October 2019 Abstract This is a short essay on using lattice methods to price European and American style options. 1. BINOMIAL TREES 1.1. Introduction. Binomial trees are useful for pricing a variety of European and American-style derivatives. The primary practical use of the Binomial model was and still is for pricing American-style options. 1.2. Pricing a European call option on a binomial tree. Consider a stock with initial price S0, which follows a binomial process. During a time period ∆t, the price per share of this stock will be one of two possible values, it can go up to S0u or down to S0d. Consider a European call option that confers on its owner the right, but not the obligation to buy one share of stock at time one for the strike price K. The European call option pays (St − K)+ at time t. We assume that the markets are complete. In a complete market, every derivative security can be replicated by trading in the stock and money market asset. Suppose we begin with an initial wealth X0 and buy ∆ shares of a stock at price S0 at time zero, leaving us with a cash postion X0 − ∆S0. The value of our portfolio of stock and the money market account at time one is : X1 = ∆S1 + er∆t (X0 − ∆S0) = X0er∆t + ∆(S1 − S0er∆t ) We want to find X0 and ∆ so, that X1(u) = Cu and X1(d) = Cd. Note here, that Cu and Cd are given quantities, the amounts that the derivative security will pay off depending upon the outcome of the coin tosses. At time zero, we know what the two values Cu and Cd are; we don’t know which of these two possibilities will be realized. Replication of the derivative security thus requires that : 1
  • 2. Options pricing using Lattice models • October 2019 • with C++ code snippets Figure 1: A binomial tree with N=4 timesteps e−r∆t Cu = X0 + ∆(S0ue−r∆t − S0) e−r∆t Cd = X0 + ∆(S0de−r∆t − S0) One way to solve these two equations in two unknowns is to multiply the first by a number ˜p and the second by ˜q = 1 − ˜p and then add them to get e−r∆t (˜pCu + ˜qCd) = X0 + ∆((˜pS0u + ˜qS0d)e−r∆t − S0) If we choose ˜p so that the ∆ term in the above equation is zero, that is : S0 = e−r∆t (˜pS0u + ˜qS0d) we obtain the simple formula for X0, X0 = e−r∆t (˜pCu + ˜qCd) We can solve for ˜p and ˜q as follows: S0 = e−r∆t (˜pS0u + ˜qS0d) er∆t = (˜pu + (1 − ˜p)d) er∆t = ˜p(u − d) + d ˜p = er∆t − d u − d ˜q = u − er∆t u − d 2
  • 3. Options pricing using Lattice models • October 2019 • with C++ code snippets We can solve for ∆ simply by subtracting the portfolio values at time one - ∆ = Cu − Cd S0u − S0d Thus, we have replicated the option payoff. The numbers ˜p and ˜q are both positive because of the no-arbitrage condition and they sum to one. For this reason, we can regard them as up and down probabilities. They are not the actual probabilities, which I shall p and q, but rather the risk-neutral probabilities. Under the actual probabilities, the average rate of growth of a stock is typically strictly greater than the rate of growth of an investment in the money market; otherwise no one would want to incur the risk associated with investing in the stock. Thus, p and q = 1 − p should satisfy S0 < e−r∆t (pS0u + qS0d) whereas ˜p and ˜q satisfy S0 = e−r∆t (˜pS0u + ˜qS0d) If the average rate of growth of the stock were exactly the same as the rate of growth of the money market investment, then investors must be neutral about risk - they do not require compensation for assuming it, nor are they willing to pay extra for it. This is simply not the case, and hence ˜p and ˜q cannot be the actual probabilities. They are only numbers which assist us in the solution of the two equations in the two unknowns (∆, X0). They assist us by making the term multiplying the unknown ∆ drop out. If we want to construct a portfolio whose value at time one is V1, then its value at time zero, must be given by the formula above, so that its mean rate of growth under risk-neutral probabilities is the rate of growth of the money market investment. The formula is called the risk-neutral pricing formula. 1.3. Matching moments of the binomial and lognormal distributions. Consider a time period ∆t in the continuous time Black Scholes world. Suppose the stock price process governed by following SDE : dS = mSdt + σSdz where m and σ are known constants - the mean rate of growth of the stock and the volatility of the stock price respectively. The simplest choice is a constant volatility. From Ito’s formula, we know that, if S(t) is any stochastic process, then the process f(S(t), t) is given by the expansion : df = ∂f ∂t + mS ∂f ∂S + 1 2 σ2 S2 ∂2 f ∂S2 dt + σS ∂f ∂S dz If we let f(S) = log S then we obtain the following Wiener process : 3
  • 4. Options pricing using Lattice models • October 2019 • with C++ code snippets ∂f ∂t = 0 ∂f ∂S = 1 S ∂2 f ∂S2 = − 1 S2 =⇒ d(ln S) = (m − 1 2 σ2 )dt + σdz =⇒ ln( ST S0 ) = (m − 1 2 σ2 )T + σZ(0, T) =⇒ ST = S0 exp[(m − σ2 /2)T + σ √ TZ(0, 1)] Thus, log ST is normally distributed. log ST ∼ N(log S0 + (m − σ2 /2)T, σT) We can now calculate the moments of the lognormal distribution around 0. We need to calculate the mean and variance. Since, log ST is normally distributed, we can use the moment generating function of the normal distribution to help calculate expections. The MGF of a normal random variable Z is given by, E(etZ ) = +∞ −∞ etz 1 √ 2π e−z2 /2 dz = et2 /2 1 √ 2π +∞ −∞ e−(z−t)2 /2 dz = et2 /2 The MGF of X = ν + σZ by completing the square as above is MX(t) = eνt+σ2 t2 /2 . Let the random variable Y = eX = eν+σZ . Then E(Y n ) = E(enX ) = eνn+σ2 n2 /2 . Therefore, in particular, E[ST ] = S0e(ν+σ2 /2)∆t = S0e(m−σ2 /2+σ2 /2)∆t = S0em∆t E[S2 T ] = S0e(2ν+2σ2 )∆t = S0e(2m−σ2 +2σ2 )∆t = S0e(2m+σ2 )∆t For the underlying price at the end of the period to have the same mean and variance in both the binomial model and the Black Scholes models, the following two identities must hold where the first and second moments are matched. 4
  • 5. Options pricing using Lattice models • October 2019 • with C++ code snippets pu + (1 − p)d = er∆t pu2 + (1 − p)d2 = e(2r+σ2 )∆t Solving the first equation for the probability p, we obtain : p = er∆t − d u − d 1.4. CRR Binomial Tree. Cox, Ross, Rubinstein in their original model assume the identity ud = 1, so that u = 1/d. Substituting u = 1/d and the value of the risk neutral probability p into the second equation we get : p(u2 − d2 ) + d2 = e(2r+σ2 )∆t (er∆t − d)(u + d) + d2 = e(2r+σ2 )∆t er∆t (u + d) − du − d2 + d2 = e(2r+σ2 )∆t er∆t (u + d) − du = e(2r+σ2 )∆t er∆t (d2 + 1) − d = e(2r+σ2 )∆t d (d2 + 1) − d(e−r∆t + e(r+σ2 )∆t ) = 0 d2 − 2Ad + 1 = 0 where A = 1 2 (e−r∆t + e(r+σ2 )∆t ). The solutions of this quadratic equation are: u = A + A2 − 1 d = A − A2 − 1 If we linearize the above solution using the series expansion ex = 1 + x + x2 2! + . . ., we obtain - A = 1 2 [(1 − r∆t) + (1 + r∆t + σ2 ∆t)] = 1 + 1 2 σ2 ∆t A2 = 1 4 [(1 − 2r∆t) + (1 + 2r∆t + 2σ2 ∆t) + 2(1 + σ2 ∆t)] = 1 + σ2 ∆t u = 1 + σ √ ∆t + 1 2 σ2 ∆t d = 1 − σ √ ∆t + 1 2 σ2 ∆t 5
  • 6. Options pricing using Lattice models • October 2019 • with C++ code snippets Terms of higher orders can be added without violating the relations since they become infinitesimally small as ∆t approached 0. Thus, the more common form is u = eσ √ ∆t d = e−σ √ ∆t The CRR has traditionally been the most widely used version of the binomial model. [1] 1.5. CRR Binomial Tree implementation. The following is an implementation of the CRR model on a European option. #include<iostream> #include <iostream> #include <array> class CRRBinomialTree { private: double p; std::array<std::array<double, 200>, 200> S; std::array<std::array<double, 200>, 200> C; double u; double d; double T; int N; double sigma; double dt; double r; double s_0; double K; char optionType; double q; public: CRRBinomialTree(double vol, double expiry, int numOfTimeSteps, double spot, double strike, double rate, double div, char optType); double pv(); double payOff(double s_t); }; // CRRBinomialTree.cpp : Computes the value of a European // option using backwards induction in a CRR Binomial tree #include<iostream> #include "CRRBinomialTree.h" #include<cmath> CRRBinomialTree::CRRBinomialTree(double vol, double expiry, int numOfTimeSteps, 6
  • 7. Options pricing using Lattice models • October 2019 • with C++ code snippets double spot, double strike, double rate, double div, char optType) { N = numOfTimeSteps; T = expiry; dt = T / N; r = rate; q = div; sigma = vol; u = exp(sigma * sqrt(dt)); d = 1 / u; double a = exp((r - q) * dt); p = (a - d) / (u - d); s_0 = spot; K = strike; optionType = optType; S = {0.0}; C = {0.0}; //compute the stock prices at each node //initialize call prices for (int i = 0; i <= N; ++i) { for (int j = 0; j <= i; ++j) { S[i][j] = s_0 * pow(u, j) * pow(d, i - j); C[i][j] = 0.0; } } } double CRRBinomialTree::payOff(double S_t) { if (optionType == 'C') return std::max(S_t - K, 0.0); if (optionType == 'P') return std::max(K - S_t, 0.0); } double CRRBinomialTree::pv() { double df = 0.0; //compute terminal payoffs for (int j = N; j >= 0; --j) { C[N][j] = payOff(S[N][j]); } //work backwards 7
  • 8. Options pricing using Lattice models • October 2019 • with C++ code snippets for (int i = N - 1; i >= 0; --i) { for (int j = i; j >= 0; --j) { df = exp(-r * dt); C[i][j] = df * (p * C[i + 1][j + 1] + (1 - p) * C[i + 1][j]); } } return C[0][0]; } #include<iostream> #include "CRRBinomialTree.h" int main() { CRRBinomialTree *europeanCall, *europeanPut; europeanCall = new CRRBinomialTree(0.10, 1.0, 100, 100.0, 100.0, 0.05, 0.0, 'C'); europeanPut = new CRRBinomialTree(0.10, 1.0, 100, 100.0, 100.0, 0.05, 0.0, 'P'); double V_0=0.0; V_0 = europeanCall->pv(); std::cout << "nCall value = " << V_0; V_0 = europeanPut->pv(); std::cout << "nPut value = " << V_0; return 0; } 1.6. Early exercise of American options on non-dividend paying stocks. Consider the following two portfolios at time t: Portfolio A: One European Call option c, Ke−r(T −t) cash. Portfolio B: One share of stock worth St In portfolio A, the cash will grow to K at time T. If ST > K, the option will be exercised at maturity, and the portfolio A is worth ST . If ST < K, the call option expires worthless and the portfolio is worth K. Hence, at time T, the portfolio is worth max(ST , K) Portfolio B is worth ST at time T. Hence, portfolio A is always worth as much as, and can be worth more than the portfolio B at maturity. max(ST , K) ≥ ST In the absence of arbitrage opportunities, this must also be true today. 8
  • 9. Options pricing using Lattice models • October 2019 • with C++ code snippets c + Ke−r(T −t) ≥ St c ≥ St − Ke−r(T −t) ≥ (St − K) So, the European call c is always worth more than its intrinsic at expiry. Because the owner of an American call has all the exercise opportunities open to the owner of a corresponding European call, we must have C ≥ c. Given r > 0, C > St − K. This means that C is always greater than the option’s intrinsic value prior to maturity. Hence, it is never optimal to exercise American call options on non-dividend paying stocks. 2. TRINOMIAL TREES Trinomial trees are used more in practice then binomial trees, since they allow for 3 states: up, down and middle moves. We can price both European and American options with trinomial trees. 2.1. CRR Trinomial tree. The CRR has a symmetric tree structure where, u = eλσ √ ∆t (1) d = e−λσ √ ∆t (2) ud = m2 = 1 (3) The necessary and sufficient condition for the tree to recombine is ud = m2 . We can compute the option value in a trinomial tree as the discounted expectation in a risk-neutral world by computing: Ci,j = e−r∆t (puCi+1,j+1 + pmCi+1,j + pdCi+1,j−1) (4) As before, we match the first two moments of the trinomial and lognormal distributions. puu + (1 − pu − pd) + pdd = em∆t (5) puu2 + (1 − pu − pd) + pdd2 = e(2m+σ2 )∆t (6) If we take the first order approximations of the power series of ex , we can solve for pu, pm, pd as follows. Let k = λσ √ ∆t. The first moment yields : puek + (1 − pu − pd) + pde−k = er∆t pu(1 + k + k2 /2) + (1 − pu − pd) + pd(1 − k + k2 /2) = (1 + r∆t) pu(k + k2 /2) + pd(−k + k2 /2) = r∆t (7) 9
  • 10. Options pricing using Lattice models • October 2019 • with C++ code snippets The second moment yields: pue2k + (1 − pu − pd) + pde−2k = e(2r+σ2 )∆t 2λσ √ ∆t(pu − pd) = 2r∆t + σ2 ∆t pu(1 + 2k + 2k2 ) + (1 − pu − pd) + pd(1 − 2k + 2k2 ) = (1 + 2r∆t + σ2 ∆t) pu(2k + 2k2 ) + pd(−2k + 2k2 ) = 2r∆t + σ2 ∆t (8) Plugging in the value of r∆t from equation 7 into 8, we obtain: pu(2k + 2k2 ) + pd(−2k + 2k2 ) = 2r∆t + σ2 ∆t pu(2k + 2k2 ) + pd(−2k + 2k2 ) = pu(2k + k2 ) + pd(−2k + k2 ) + σ2 ∆t (pu + pd)k2 = σ2 ∆t (1 − pm)λ2 σ2 ∆t = σ2 ∆t 1 − pm = 1 λ2 pm = 1 − 1 λ2 (9) Multiplying the left and right hand sides of the equation 9 by (−k + k2 /2), pu + pd = σ2 ∆t k2 pu(−k + k2 /2) + pd(−k + k2 /2) = σ2 ∆t λ2σ2∆t (−k + k2 /2) pu(−k + k2 /2) + pd(−k + k2 /2) = 1 λ2 (−k + k2 /2) (10) I now solve equations 7 and 10 simultaneously. pu(2k) = r∆t − 1 λ2 (−k + k2 /2) pu(2λσ √ ∆t) = r∆t + λσ √ ∆t λ2 − λ2 σ2 ∆t 2λ2 pu(2λσ) ≈ r √ ∆t + σ λ pu = 1 2λ2 + 1 2 r λσ √ ∆t (11) Since pu and pd should add up to 1/λ2 , pd = 1 2λ2 − 1 2 r λσ √ ∆t (12) It has been found that the value of λ that produces the best convergence rate is: λ = 3 2 10
  • 11. Options pricing using Lattice models • October 2019 • with C++ code snippets 2.2. CRR Trinomial Tree implementation. The following code implements an American CRR trinomial tree with λ = 3/2. Suppose we use a trinomial tree to price an at-the-money (ATM) American call option on a stock priced at 50 dollars, strike price of 50, volatility of 20 percent, risk-free rate of 6 percent, annual dividend yield of 3 percent and time to maturity = 1 year. Thus, S = 50, K = 50, σ = 0.20, r = 0.06, q = 0.03 and T = 1. //CRRTrinomialTree.h #include <iostream> #include <array> class CRRTrinomialTree { private: double p_u,p_d,p_m; std::array<std::array<double, 250>, 250> S; std::array<std::array<double, 250>, 250> C; double u; double d; double T; int N; double sigma; double dt; double r; double s_0; double K; char optionType; double q; double drift; public: CRRTrinomialTree(double vol, double expiry, int numOfTimeSteps, double spot, double strike, double rate, double div, char optType); double pv(); double payOff(double s_t); void printTree(); int x(int i, int j); int y(int i, int j); }; // CRRTrinomialTree.cpp : Computes the value of a American option // using backwards induction in a CRR Trinomial tree #include<iostream> #include "CRRTrinomialTree.h" #include <cmath> #include <iomanip> CRRTrinomialTree::CRRTrinomialTree(double vol, double expiry, int numOfTimeSteps, 11
  • 12. Options pricing using Lattice models • October 2019 • with C++ code snippets double spot, double strike, double rate, double div, char optType) { N = numOfTimeSteps; T = expiry; dt = T / N; r = rate; q = div; sigma = vol; drift = (r - q - pow(sigma, 2.0) / 2.0); const double lambda = sqrt(3.0 / 2.0); u = exp(lambda * sigma * sqrt(dt)); d = 1 / u; p_u = (1 / (2 * pow(lambda, 2))) + (1 / 2) * (drift / (lambda * sigma)) * sqrt(dt); p_d = (1 / (2 * pow(lambda, 2))) - (1 / 2) * (drift / (lambda * sigma)) * sqrt(dt); p_m = 1 - (1 / pow(lambda, 2)); s_0 = spot; K = strike; optionType = optType; S = { 0.0 }; C = { 0.0 }; //compute the stock prices at each node //initialize call prices for (int i = 0; i <= N; ++i) { for (int j = -i; j <= i; ++j) { S[x(i,j)][y(i,j)] = s_0 * pow(u, j); C[x(i,j)][y(i,j)] = 0.0; } } } int CRRTrinomialTree::x(int i, int j) { return (i + j); } int CRRTrinomialTree::y(int i, int j) { return i; } void CRRTrinomialTree::printTree() { std::cout << "nStock price tree"; std::cout << std::setprecision(5); 12
  • 13. Options pricing using Lattice models • October 2019 • with C++ code snippets for(int i = 2*N; i>=0;--i) { std::cout << "nn"; for (int j = 0; j <= N; ++j) { std::cout << "t" << S[i][j]; } } std::cout << "nnCall price tree"; for (int i = 2 * N; i >= 0; --i) { std::cout << "nn"; for (int j = 0; j <= N; ++j) { std::cout << "t" << C[i][j]; } } } double CRRTrinomialTree::payOff(double S_t) { if (optionType == 'C') return std::max(S_t - K, 0.0); if (optionType == 'P') return std::max(K - S_t, 0.0); } double CRRTrinomialTree::pv() { double df = 0.0; int h = 0; //compute terminal payoffs for (int j = N; j >= -N; --j) { C[x(N,j)][y(N,j)] = payOff(S[x(N,j)][y(N,j)]); } //work backwards for (int i = N - 1; i >= 0; --i) { for (int j = i; j >= -i; --j) { df = exp(-r * dt); double v_u = C[x(i + 1, j + 1)][y(i + 1, j + 1)]; double v_m = C[x(i + 1, j)][y(i + 1, j)]; double v_d = C[x(i + 1, j - 1)][y(i + 1, j - 1)]; 13
  • 14. Options pricing using Lattice models • October 2019 • with C++ code snippets double discountedExpectation = df * (p_u * v_u + p_m * v_m + p_d * v_d); C[x(i,j)][y(i,j)] = std::max(discountedExpectation, payOff(S[x(i,j)][y(i,j)])); } } return C[0][0]; } // testCRRTrinomialTree.cpp #include<iostream> #include "CRRTrinomialTree.h" int main() { CRRTrinomialTree* americanCall; americanCall = new CRRTrinomialTree(0.20, 1, 4, 50, 50, 0.06, 0.03, 'C'); double V_0 = americanCall->pv(); std::cout << "nPut value = " << V_0; americanCall->printTree(); return 0; } The American call price and tree are printed as shown below: Call value = 4.22538 Stock price tree 0 0 0 0 81.607 0 0 0 0 72.2 0 0 0 72.2 63.878 0 0 0 63.878 56.515 0 0 63.878 56.515 50 0 0 56.515 50 44.236 0 56.515 50 44.236 39.137 0 50 44.236 39.137 34.626 50 44.236 39.137 34.626 30.634 Call price tree 14
  • 15. Options pricing using Lattice models • October 2019 • with C++ code snippets 0 0 0 0 31.607 0 0 0 0 22.2 0 0 0 22.226 13.878 0 0 0 13.986 6.5145 0 0 14.09 6.6962 0 0 0 7.494 2.1392 0 0 8.0402 2.9013 0 0 0 3.6442 0.70244 0 0 4.2254 1.1834 0 0 0 3. FINITE DIFFERENCE METHODS Numerical methods known as finite difference methods are used for pricing derivatives by approximating the diffusion process that the derivative must follow. Finite difference methods schemes are used to numerically solve PDEs. They are particular useful for valuation, when a closed-form analytical solution does not exist. By discretizing the continuous time PDE, the derivative security must follow, it is possible approximate the evolution of the derivative prices and therefore the PV of the contract. 3.1. The Black Scholes PDE. Consider an underlying asset with price x. The underlying price evolves according to: dx = µxdt + σxdz (13) Consider a derivative contract whose value C depends on the asset price x at time t, and can be thought of as a function C(t, x) of the random asset price x and time t. Using Ito’s lemma, the function of a stochastic variable follows the process : dC = ∂C ∂t + µx ∂C ∂x + 1 2 σ2 x2 ∂2 C ∂x2 dt + σx ∂C ∂x dz (14) In the same way as for the asset-pricing model in equation 13, the process for C(t, x) has two components - the drift component and a volatility component. The drift term is deterministic, involving the drift and volatility parameters of the asset price process and the partials of C with respect to x and t. Fundamentally, the source of randomness dz in the asset-price process in equation 13 is the same as that in the derivative-price process in equation 14. It should therefore be possible to eliminate the source of randomness to create a riskless portfolio Π akin to a money market asset. Construct a portfolio Π by shorting the derivative C and buying ∂C ∂x units of the underlying. 15
  • 16. Options pricing using Lattice models • October 2019 • with C++ code snippets Π = −C + ∂C ∂x x (15) The change in the value of the portfolio over the time period dt is the differential, dΠ = −dC + ∂C ∂x dx (16) Subsituting for dC and dx in equation 16 and using equations 13 and 14, dΠ = − ∂C ∂t + µx ∂C ∂x + 1 2 σ2 x2 ∂2 C ∂x2 dt − σx ∂C ∂x dz + ∂C ∂x (µxdt + σxdz) (17) Simplifying we obtain, dΠ = ∂C ∂t + 1 2 σ2 x2 ∂2 C ∂x2 dt (18) Finally, the rate of return on the riskless portfolio is: dΠ Π = ∂C ∂t + 1 2 σ2 x2 ∂2 C ∂x2 dt −C + ∂C ∂x x = rdt (19) The derivative C(t, x) price must therefore be the solution of the partial differential equation, ∂C ∂t (t, x) + rx ∂C ∂x (t, x) + 1 2 σ2 x2 ∂2 C ∂x2 (t, x) = rC(t, x) (20) 3.2. Difference operators. The principle of the finite difference method is to approximate the derivatives in partial differential equations by a linear combination of the function values. The derivative of a function at the point x can be approximated as: Forward difference divided by h: ∆h[f](x) h = f(x + h) − f(x) h (21) Backward difference divided by h: h[f](x) h = f(x) − f(x − h) h (22) Central difference divided by h: δh[f](x) h = f(x + h/2) − f(x − h/2) h (23) In an analogous way, one can obtain finite difference approximations to higher order derivatives and differential operators. 16
  • 17. Options pricing using Lattice models • October 2019 • with C++ code snippets The second order central difference: f (x) ≈ δ2 h[f](x) h = f (x + h/2) − f (x − h/2) h = f(x+h)−f(x) h − f(x)−f(x−h) h h = f(x + h) − 2f(x) + f(x − h) h2 (24) The second order forward difference: f (x) ≈ ∆2 h[f](x) h = f (x + h) − f (x) h = f(x+2h)−f(x+h) h − f(x+h)−f(x) h h = f(x + 2h) − 2f(x + h) + f(x) h2 (25) The second order backward difference: f (x) ≈ 2 h[f](x) h = f (x) − f (x − h) h = f(x)−f(x−h) h − f(x−h)−f(x−2h) h h = f(x) − 2f(x − h) + f(x − 2h) h2 (26) Mixed partial derivatives can be obtained as follows. Taking the central difference of the x and y variables, we could obtain, for example: ∂2 u ∂x∂y i,j = ∂ ∂x ∂u ∂y ≈ (∂u ∂y )i+1,j − (∂u ∂y )i−1,j 2∆x = ui+1,j+1−ui+1j−1 2∆y − ui−1,j+1−ui−1j−1 2∆y 2∆x = ui+1,j+1 − ui+1,j−1 − ui−1,j+1 + ui−1,j−1 4∆x∆y (27) 3.3. Explicit finite difference scheme. Consider the Black Scholes PDE: ∂C ∂t + rS ∂C ∂S + 1 2 σ2 S2 ∂2 C ∂S2 = rC (28) subject to the payoff condition C(t, ST ) = max(ST − K)+ . We can simply this PDE by substituting it with finite differences. First, let’s substitute x = log S, so that ∂C ∂S = ∂C ∂x · ∂x ∂S = 1 S ∂C ∂x and ∂2 C ∂S2 = − 1 S2 ∂C ∂x + 1 S2 ∂2 C ∂x2 . ∂C ∂t + ν ∂C ∂x + 1 2 σ2 ∂2 C ∂x2 = rC (29) We imagine time and space divided up into discrete intervals (∆t and ∆x), this is the finite difference grid or lattice. To obtain the explicit finite difference method we approximate the equation 29 using a forward difference for ∂C/∂t and central differences for ∂C/∂x and ∂2 C/∂x2 . Denote by Ci,j = C(ti, xj) Therefore, ∂C ∂t t=ti = Ci+1,j − Ci,j ∆t (30) 17
  • 18. Options pricing using Lattice models • October 2019 • with C++ code snippets ∂C ∂x x=xj = Ci+1,j+1 − Ci+1,j−1 2∆x (31) ∂2 C ∂x2 x=xj = Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1 ∆x2 (32) Figure 2: Stencils for grid points for explicit and implicit finite difference schemes in solving a PDE that is first order in t and second order in x Substituting these values in the equation 29 we obtain, Ci+1,j − Ci,j ∆t +r Ci+1,j+1 − Ci+1,j−1 2∆x + 1 2 σ2 Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1 ∆x2 = rCi,j (33) Multiplying throughout by 2∆x2 ∆t, 2r(∆x)2 ∆tCi,j = 2(∆x)2 (Ci+1,j − Ci,j) + r∆x∆t(Ci+1,j+1 − Ci+1,j−1) + σ2 ∆t(Ci+1,j+1 − 2Ci+1,j + Ci+1,j−1) =⇒ Ci,j(2∆x2 )(1 + r∆t) = (r∆x∆t + σ2 ∆t)Ci+1,j+1 + (2∆x2 − 2σ2 ∆t)Ci+1,j + (σ2 ∆t − r∆x∆t)Ci+1,j−1 =⇒ Ci,j = 1 1 + r∆t ∆t r 2∆x + σ2 2∆x2 Ci+1,j+1 + 1 − σ2 ∆x2 ∆t Ci+1,j + 1 2 σ2 ∆x2 − r ∆x ∆t Ci+1,j−1 (34) The coefficients of Ci+1,j+1, Ci+1,j and Ci+1,j−1 can be thought of as the trinomial probabilities. (1 + r∆t) is the discounting factor. Therefore the explicit finite difference method is equivalent of approximating the Black Scholes diffusion process by a discrete trinomial process, where, 18
  • 19. Options pricing using Lattice models • October 2019 • with C++ code snippets Ci,j = 1 1 + r∆t (puCi+1,j+1 + pmCi + 1, j + pdCi+1,j−1) (35) pu = ∆t r 2∆x + σ2 2∆x2 (36) pm = 1 − σ2 ∆x2 ∆t (37) pd = 1 2 σ2 ∆x2 − r ∆x ∆t (38) 3.4. Explicit finite difference implementation. We create a rectangular grid or lattice by adding extra nodes to a trinomial tree, so that we have 2M + 1, M >= N at every time step i instead of just 2i + 1. However, at time step i, given all option values at i + 1, we cannot compute the bottom and top option values (Ci,−M and Ci,M ) using discounted expectations, since this would require knowing option values Ci+1,−M−1 and Ci+1,M+1 which we do not have. With no additional information we can only compute the region indicated by the dashed branches using discounted expectations. In order to be able to compute the remainder of the grid we must add the extra boundary conditions which determine the behavior of the option price as a function asset price for high and low values of the asset price xj. For example, for a European call option we have the following Neumann boundary conditions (the delta for deep ITM calls is 1, whereas for deep OTM calls is 0): ∂C ∂S (t, S) = 1 for large S (39) ∂C ∂S (t, S) = 0 for small S (40) In terms of the grid, the conditions 39 and 40 become: Ci,M − Ci,M−1 Si,M − Si,M−1 = 1 for large S (41) Ci,−M+1 − Ci,−M Si,−M+1 − Si,−M = 0 for small S (42) I price a one-year ATM European call option with S = 100, K = 100, T = 1 year, r = 0.06, δ = 0.03, M = 3, N = 3, ∆x = 0.02. // ExplicitFDMGrid.h #include <iostream> #include <array> class ExplicitFDMGrid { 19
  • 20. Options pricing using Lattice models • October 2019 • with C++ code snippets private: double p_u, p_d, p_m; std::array<std::array<double, 250>, 250> S; std::array<std::array<double, 250>, 250> C; double T; long M; long N; double sigma; double dt; double r; double s_0; double K; char optionType; double q; double drift; double dx; public: ExplicitFDMGrid(double vol, double expiry, long N_, long M_, double spot, double strike, double rate, double div, char optType, double dx); double pv(); double payOff(double s_t); void printTree(); int row(int i, int j); int col(int i, int j); }; // ExplicitFDMGrid.cpp : Computes the value of a European option // the explicit finite difference method #include<iostream> #include "ExplicitFDMGrid.h" #include <cmath> #include <iomanip> ExplicitFDMGrid::ExplicitFDMGrid(double vol, double expiry, long N_, long M_, double spot, double strike, double rate, double div, char optType, double deltax) { N = N_; M = M_; T = expiry; dt = T / N; r = rate; q = div; sigma = vol; dx = deltax; drift = (r - q - pow(sigma, 2.0) / 2.0); p_u = 0.50 * dt * (pow((sigma/dx),2)+(drift/dx)); p_m = 1 - dt * (pow((sigma / dx), 2)); p_d = 0.50 * dt * (pow((sigma / dx), 2) - (drift / dx)); s_0 = spot; K = strike; 20
  • 21. Options pricing using Lattice models • October 2019 • with C++ code snippets optionType = optType; S = { 0.0 }; C = { 0.0 }; std::cout << "np_u = " << p_u; std::cout << "np_m = " << p_m; std::cout << "np_d = " << p_d; //initialize the asset prices at maturity //these apply to every time step for (int j = -M; j <= M; ++j) { for (int i = 0; i <= N; ++i) { S[row(i, j)][col(i, j)] = s_0 * exp(j * dx); } } //initialize the option values at maturity for (int j = -M; j <= M; ++j) { C[row(N, j)][col(N, j)] = payOff(S[row(N, j)][col(N, j)]); } } int ExplicitFDMGrid::row(int i, int j) { return (M+j); } int ExplicitFDMGrid::col(int i, int j) { return i; } void ExplicitFDMGrid::printTree() { std::cout << "nStock price tree"; std::cout << std::setprecision(8); for (int j = 2 * M; j >= 0; --j) { std::cout << "nn"; for (int i = 0; i <= N; ++i) { std::cout << "t" << S[j][i]; } } 21
  • 22. Options pricing using Lattice models • October 2019 • with C++ code snippets std::cout << "nnCall price tree"; for(int j = 2 * M; j >= 0; --j) { std::cout << "nn"; for (int i = 0; i <= N; ++i) { std::cout << "t" << C[j][i]; } } } double ExplicitFDMGrid::payOff(double S_t) { if (optionType == 'C') return std::max(S_t - K, 0.0); if (optionType == 'P') return std::max(K - S_t, 0.0); } double ExplicitFDMGrid::pv() { double df = 0.0; //work backwards for (int i = N - 1; i >= 0; --i) { for (int j = M - 1; j >= -M+1; --j) { df = exp(-r * dt); double v_u = C[row(i + 1, j + 1)][col(i + 1, j + 1)]; double v_m = C[row(i + 1, j)][col(i + 1, j)]; double v_d = C[row(i + 1, j - 1)][col(i + 1, j - 1)]; C[row(i,j)][col(i,j)] = (p_u * v_u + p_m * v_m + p_d * v_d); } //Neumann boundary conditions if (optionType == 'C') { C[row(i, M)][col(i, M)] = C[row(i, M - 1)][col(i, M - 1)] + (S[row(i, M)][col(i, M)] - S[row(i, M - 1)][col(i, M - 1)]); C[row(i, -M)][col(i, -M)] = C[row(i, -M + 1)][col(i, -M + 1)]; } else if (optionType == 'P') { C[row(i, M)][col(i, M)] = C[row(i, M - 1)][col(i, M - 1)]; 22
  • 23. Options pricing using Lattice models • October 2019 • with C++ code snippets C[row(i, -M)][col(i, -M)] = C[row(i, -M + 1)][col(i, -M + 1)] + (S[row(i, -M)][col(i, -M)] - S[row(i, -M + 1)][col(i, -M + 1)]); } } return C[row(0,0)][col(0,0)]; } // test explicit FDM grid #include<iostream> #include "ExplicitFDMGrid.h" int main() { ExplicitFDMGrid* g; g = new ExplicitFDMGrid(0.20, 1, 3, 3, 100, 100, 0.06,0.03,'C',0.2); double V_0 = g->pv(); std::cout << "nOption value = " << V_0; g->printTree(); return 0; } REFERENCES [1] Mark Rubinstein John Cox, Stephen Ross. Option pricing: A simplified approach. Journal of Financial Economics, 1979. 23