Macroeconomics I
Simulating the neoclassical growth model
Luiz Brotherhood
Universitat de Barcelona
Fall 2020
1 / 14
The Euler method
• Used for simulating differential equations
• Let’s say x is a function of time, x (t) (time is continuous, t ≥ 0)
• We don’t know the function x (t)
• Therefore, we will simulate it in the computer
• This means we will compute the value of x for a finite number of time
periods
• For example: x (0), x (0.1), x (0.2), x (0.3), ..., x (99.9), x (100)
• Let’s say we know x (0) (for example, x (0) = 1)
• And we know how x changes over time for each point in time
∂x (t)
∂t
2 / 14
The Euler method: an example
∂x (0)/∂t says how x changes in time zero from an infinitesi-
maly small change in t. If we assume that t going from t = 0
to t = 1 is small enough, we can approximate the value of x
at t = 1
x (t)
The real function we are trying to
approximate is the blue curve. In
practical applications, we don’t
know this function (that’s why
we want to approximate it in the
computer)
Let’s say we know x
x (0) at time zero, x (0)
t
0
3 / 14
The Euler method: an example
∂x (0)/∂t says how x changes in time zero from an infinitesi-
maly small change in t. If we assume that t going from t = 0
to t = 1 is small enough, we can approximate the value of x
at t = 1
x (t)
The real function we are trying to
approximate is the blue curve. In
practical applications, we don’t
know this function (that’s why
we want to approximate it in the
computer)
Let’s say we know x
x (0) at time zero, x (0)
t
0
3 / 14
The Euler method: an example
∂x (0)/∂t
x (1) ≈ x (0)says
+ how x changes
approx. changeinoftime
x fromzerot from an tinfinitesi-
= 0 to =1
maly small change | in t. If we assume {z that t going from t} = 0
∂x (0)/∂t
to t = 1 is small enough, we can approximate the value of x
= x̂ (1)
at t = 1
x̂ (1)
x (t)
x (1)
x (0)
t
0 1
3 / 14
The Euler method: an example
∂x (0)/∂t says how x changes in time zero from an infinitesi-
maly small
Keep doingchange
this to in
gett. the
If we assume
value of x that t going
in time from1,t 2,=3,
periods 0
to 5,
4, t =and
1 issosmall
on...enough, we can approximate the value of x
at t = 1
x̂ (1)
x (t)
x (1)
x (0)
t
0 1 2 3 4 5
3 / 14
The Euler method: an example
∂x precision
The (0)/∂t saysof how x changes in time
the approximation zero from
increases an infinitesi-
as we choose
maly small
smaller gaps change
betweenintime
t. If periods
we assume that
(e.g., t tgoing
goingfrom
from0t to
=0
to t = 1 is small enough,
0.0001, then to 0.0002, ...) we can approximate the value of x
at t = 1
x̂ (1)
x (t)
x (1)
x (0)
t
0 1 2 3 4 5
3 / 14
The Euler method
• Let’s see this more formally
• x is a function of time, x (t)
• We know x at time 0, x (0)
• x moves over time according to the differential equation
∂x (t)
≡ ẋ (t) = f (x (t), t)
∂t
• Using the definition of a derivative,
x (t + ∆) − x (t)
ẋ (t) = lim
∆→0 ∆
4 / 14
The Euler method
• We can approximate ẋ (t) using a very small ∆, let’s say ∆ = 0.0001
x (t + ∆) − x (t)
ẋ (t) ≈
∆
which implies that
x (t + ∆) ≈ x (t) + ∆ẋ (t)
• That is, if we know x (t) and ẋ (t), we can approximate the value of x
after a small period of time, ∆, using the equation above
• For example,
x (0.0001) ≈ x (0) + 0.0001 × ẋ (0)
x (0.0002) ≈ x (0.0001) + 0.0001 × ẋ (0.0001)
...
• We can do this many times to simulate the path of x (t) over time
5 / 14
The Euler method
• Here’s an example using
L̇(t)
= n,
L(t)
with L(0) = 1
• We know that the analytical solution to this differential equation is
L(t) = e nt
• But let’s use the Euler method to simulate L(t) from t = 0 to
t = 1000
6 / 14
The Euler method
10 4 10 4
2.5 2.4
2.2
2
2
1.8
1.5
1.6
1.4
1
1.2
1
0.5
0.8
0 0.6
0 200 400 600 800 1000 900 920 940 960 980 1000
• The smaller ∆ is, the better is the approximation
• However, higher precision means higher computational cost because
we need to compute L(t) for a larger number of time periods between
0 and 1000
7 / 14
Neoclassical growth model
• The neoclassical growth model is described by the following system of
differential equations
˙
ĉ(t) 1h 0 i
= f (k̂(t)) − δ − ρ − θx
ĉ(t) θ
˙
k̂(t) = f (k̂(t)) − ĉ(t) − (x + n + δ)k̂(t)
• Let’s say k̂(0) < k̂ ∗
• For a given ĉ(0), we can use the Euler method and the differential
equations above to simulate paths for ĉ(t) and k̂(t)
• But how do we find the ĉ(0)?
8 / 14
Neoclassical growth model
• We must find a path of (k̂(t), ĉ(t)) such that k̂(t) % k̂ ∗ and
ĉ(t) % ĉ ∗ (strictly increasing over time)
• There is only one ĉ(0) that makes this possible
• This ĉ(0) is between zero and the consumption that corresponds to the
˙
k̂(t) = 0 locus with k̂(t) = k̂(0) (that is, f (k̂(0)) − (x + n + δ)k̂(0))
• Due to numerical precision issues, we never find the exact value of
ĉ(0) in the computer
• Either because a computer can’t store all digits of ĉ(0) (the real ĉ(0)
may have an infinite number of digits!)...
• ... or because the Euler method provides an approximation to the true
path of the variables
9 / 14
Neoclassical growth model
• Therefore, for a given guess of ĉ(0), we will either have k̂(t) → 0 or
k̂(t) → k̂ ∗∗ , where k̂ ∗∗ > k̂ ∗
• In the first case, there will be a time period t such that
k̂(t + ∆) < k̂(t) (remember we must have k̂(t) % k̂ ∗ )
• The guess of ĉ(0) was too high
• Try a lower guess of ĉ(0)
• In the second case, there will be a time period t such that
ĉ(t + ∆) < ĉ(t) (remember we must have ĉ(t) % ĉ ∗ )
• The guess of ĉ(0) was too low
• Try a higher guess of ĉ(0)
• How to update the guesses of ĉ(0)? Bisection idea
10 / 14
ĉ(t)
˙
ĉ(t) =0
We know that the true true path of k̂(t)
ĉ(0) is between ĉ(0)lb and and ĉ(t)
ĉ(0)ub (“lb” means “lower ˙
k̂(t) =0
bound” and “ub” means “up-
per bound”). But where ex-
actly is ĉ(0)? We don’t
know. Let’s guess it is in
the middle of the interval
[ĉ(0)lb , ĉ(0)ub ]
ĉ(0)ub
true ĉ(0) we
want to find
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
˙
ĉ(t) =0
We know that the true true path of k̂(t)
ĉ(0) is between ĉ(0)lb and and ĉ(t)
ĉ(0)ub (“lb” means “lower ˙
k̂(t) =0
bound” and “ub” means “up-
per bound”). But where ex-
actly is ĉ(0)? We don’t
know. Let’s guess it is in
the middle of the interval
[ĉ(0)lb , ĉ(0)ub ]
ĉ(0)ub
true ĉ(0) we
want to find
ĉ(0)new
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
˙
ĉ(t) =0
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Use the Euler method to sim-
ulate the path of the variables
starting from ĉ(0)new
ĉ(0)ub
true ĉ(0) we
want to find
ĉ(0)new
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Use the Euler method to sim-
ulate the path of the variables
starting from ĉ(0)new
ĉ(0)ub
true ĉ(0) we
want to find
ĉ(0)new
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Since the guess for consump-
tion is too high, it becomes
the new upper bound of the
interval
ĉ(0)ub
true ĉ(0) we
want to find
ĉ(0)new
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Since the guess for consump-
tion is too high, it becomes
the new upper bound of the
interval
true ĉ(0) we
want to find
ĉ(0)ub
ĉ(0)
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Compute another ĉ(0)new as
the middle point of the new
interval [ĉ(0)lb , ĉ(0)ub ]
true ĉ(0) we
want to find
ĉ(0)ub
ĉ(0)
ĉ(0)new
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Simulate the path starting
from this new initial con-
sumption
if ĉ(t) starts to decrease at
some point, we know that the
guess of ĉ(0) was too low
true ĉ(0) we
want to find
ĉ(0)ub
ĉ(0)
ĉ(0)new
ĉ(0)lb k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
Since the guess for initial
consumption is too low, it be-
comes the new lower bound
of the interval
if ĉ(t) starts to decrease at
some point, we know that the
guess of ĉ(0) was too low
true ĉ(0) we
want to find
ĉ(0)ub
ĉ(0)
ĉ(0)lb
k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
ĉ(t)
if k̂(t) starts to decrease at some
˙ Keep doing this until
point, we know that the guess of ĉ(t) = 0
ĉ(0) was too high we get very close to
the true ĉ(0)!
true path of k̂(t)
and ĉ(t)
˙
k̂(t) =0
if ĉ(t) starts to decrease at
some point, we know that the
guess of ĉ(0) was too low
true ĉ(0) we
want to find
ĉ(0)ub
ĉ(0)
ĉ(0)lb
k̂(t)
k̂(0) k̂ ∗ k̂ ∗∗
11 / 14
Notes
• This procedure belongs to a class of computational routines called
“shooting algorithms”
• Starting from an initial condition, we simulate the paths of the variables
(“shoot”), and check if these paths satisfy properties we want them to
satisfy
• This algorithm is simple
• It works well as a first step towards understanding the usage of these
types of tools to simulate growth models
• However, it may not work so well for some parameters values (the
interval of ĉ(0) may collapse before we find paths of the variables that
get sufficiently close to the steady state)
• This simple algorithm can be improved to avoid some of its drawbacks
12 / 14
...
...
13 / 14
...
• ...
14 / 14