Introduction
Motivation and content
Neoclassical growth model
Function approximation
Numerical integration
Summary
Monash Macroeconomics
Summer School
Intro and basic tools
Petr Sedláček
University of Bonn
February 2016
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model
Function approximation
Numerical integration
Summary
Goal
1 motivation and overview of entire course
what tools and how are they used in practice?
2 describe simple DSGE model
3 functional approximation
basics, polynomials, splines
4 numerical integration
monte-carlo, quadrature methods
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
Motivation and overview
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
Resources
much of this course is based on Wouter den Haan’s work
excellent lecture notes, slides on his webpage
other great resources include e.g.
DeJong, Dave (2011). “Structural Macroeconometrics”
Heer, Maussner (2009). “Dynamic General Equilibrium Modelling”
Judd (1998). “Numerical Methods in Economics”
lecture notes and slides by
Kopecky, Mukoyama, Nakajima etc.
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What tools are needed in modern macro?
1 theoretical tools
use models to look at data
2 computational tools
characterize model outcomes
solve models for particular parameter values
assign the “right” parameter values
3 empirical tools
analyze statistical properties of data and model
4 common sense
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
Why DSGE models?
prior to DSGE’s
long tradition of large macroeconometric models
these reduced-form systems have certain drawbacks
no “GE”
no forward-looking behavior
changes after Kydland and Prescott (1982)
other critical contributions by Hansen, Lucas, Sargent and Sims
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
Why DSGE models?
attempt to put discipline on reduced-form methods
discipline comes from “cross-equation” restrictions
stochastics of exogenous variables
together with forward-looking behavior of agents
result in implication for evolution of endogenous variables
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What will we cover?
1) Computational tools for “Rep-Agent models”
what do we need to solve for?
policy rules (functions)
why is this a tough problem?
forward looking behavior
dynamics today depend on expectations of future dynamics
focus on recursive problems
even then
analytical solutions are rare
“S” in DSGE necessitates computation of expectations
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What will we cover?
1) Computational tools for “Rep-Agent models”
characterize unknown functions and their integrals
function approximation
numerical integration
we’ll then be ready to solve models in several ways
projection
perturbation
other methods (which we won’t cover):
value (policy) function iteration
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What will we cover?
2) Tools for parametrizing models
discussion of alternative methods
calibration
estimation
matching moments
we’ll cover estimation in detail
Maximum Likelihood
Bayesian methods
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What will we cover?
3) Computational tools for “Hetero-Agent models”
solving for equilibrium prices and market clearing is tougher
Krusell-Smith algorithm
simulation methods
often compute “only” approximate equilibria:
need to check accuracy of solutions
if time permits, we’ll check out a few other topics:
practical issues regarding the Krusell-Smith algorithm
additional solution algorithm (Sedláček and Sterk; 2016)
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
What will we cover?
1 theoretical tools
use models to look at data
2 computational tools
characterize model outcomes
solve models for particular parameter values
assign the “right” parameter values
3 empirical tools
analyze statistical properties of data and model
4 common sense
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model Why DSGE’s?
Function approximation What will we cover?
Numerical integration
Summary
Main thing to remember
“The goal of computing is insight, not numbers”
Richard Hamming
Mathematician and
computer scientist
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
A simple DSGE model
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Neoclassical growth model
representative household maximizing expected lifetime utility
household owns production technology
capital is the only factor of production
resources spent on consumption and investment into capital
each period existing capital depreciates at certain rate
production subject to exogenous fluctuations in productivity
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Production
yt = Zt ktα
Zt = 1 − ρ + ρZt−1 + t
Et = 0
E2t = σz2
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Household decision
∞
X
max ∞ E0 β t u(ct )
{ct ,kt+1 }t=0
t=0
s.t. ct + kt+1 = yt + (1 − δ)kt
k0 given
Z0 given
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Solution
What is the solution?
a sequence {ct , kt+1 }∞
t=0
maximizing the expected discounted sum of per-period utilities
Sounds like a tough problem!
different k0 → optimal sequences different!
different realizations of Zt → optimal sequences different!
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Solution
Trick is to
replace sequential problem with 2-period decisions
recursiveness
must make sure that each 2-period decision is globally optimal
Principle of Optimality (Bellman)
decisions depend on state variables
agents facing the same state variables
make the same decisions
independent of in which period they are
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Policy rules
what are the state variables?
beginning-of-period capital and productivity
what are the policy rules?
ct = c(kt , Zt )
kt+1 = k(kt , Zt )
how are they determined?
α−1
uc (ct ) = βEt uc (ct+1 ) αZt+1 kt+1 +1−δ
ct + kt+1 = yt + (1 − δ)kt
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Where do we use our computational tools?
Function approximation?
analytical solutions rarely exist
→ need to approximate the policy functions
ct ≈ ce(kt , Zt ; ψc )
kt+1 ≈ k(k
e t , Zt ; ψk )
what are we solving for?
the coefficients of the approximations: ψc and ψk
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Where do we use our computational tools?
Numerical integration?
analytical solutions rarely exist
→ need to calculate expectations of (unknown) functions
α−1
uc (ct ) = βEt uc (ct+1 ) αZt+1 kt+1 +1−δ
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Where do we use our computational tools?
Numerical integration?
analytical solutions rarely exist
we need to calculate expectations of (unknown) functions
uc (e
c (kt , Zt ; ψc )) =
βEt uc (e e t , Zt ; ψk ), (1 − ρ + ρZt + t+1 ); ψc ))∗
c (k(k
h i
α(1 − ρ + ρZt + t+1 )k(k e t , Zt ; ψk )α−1 + 1 − δ
Sedláček Monash Macro
Introduction
Motivation and content
Production and household
Neoclassical growth model
Solution
Function approximation
Use of computational tools
Numerical integration
Summary
Special case of analytical solution
assume log utility (γ = 1)
and full depreciation (δ = 1)
this is the Brock-Mirman model
Turns out that this version has an analytical solution:
kt+1 = αβZt ktα
ct = (1 − αβ)Zt ktα
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Function approximation
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Why function approximation?
we are after policy rules
these are functions of state variables
moreover, closed form solutions rarely exist
→ work with approximations of true functions
let’s think about this problem more generally first
later we’ll talk about how to implement it with DSGE models
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Main idea of function approximation
Consider we want to approximate a function
y = f (x)
1. choose a family of functions to use as interpolants
popular choice is the family of polynomials
but others also exist
trigonometric functions (fourier approximation)
rational functions (pade approximation)
2. find coefficients of interpolant
such that interpolant and true function agree at certain points
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Main idea of function approximation
We’ve already made enormous progress at this point:
we have reduced the problem to a finite dimension!
y ≈ f (x) = a0 T0 (x) + a1 T1 (x) + ... + an Tn (x)
where aj are coefficients of the polynomial for j = 0, .., n
and Tj (x) are basis functions
aj ’s solve the above at each chosen node, i = 1, ..., n + 1
n
X
yi = f (xi ) = a0 + aj Tj (xi )
j=1
y = T (x)a
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Main idea of function approximation
the above (interpolation) method is a special case
regression is a method of interpolation!
when the number of grid points i
is generally larger than the number of basis functions
what if you run a regression of n points on n regressors?
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Why polynomial approximation?
Weierstrass’ theorem (a sloppy version)
if f (x) is a continuous function in [a, b]
then there exists a polynomial p for which
supa≤x≤b |f (x) − p(x)| ≤
with > 0
In other words
there exists a polynomial
that approximates any continuous function
arbitrarily well
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Problem with Weierstrass...
it is useless from a practical point of view
because it gives no guidance on how to find p
There are (at least) 2 important choices to be made
what type of polynomial to use
and where to evaluate it (grid points)
An example is a Taylor approximation at equidistant nodes
turns out to be a bad idea
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Why not monomials?
the choice of monomial basis functions implies
1 x1 · · · x1n−1
y1 a0
.. .. .. . . .. ..
. = . . . . .
yn 1 xn · · · xn n−1 an
the first matrix on the RHS is a Vandermonde matrix
even though it is non-singular, it is often ill-behaved
intuition from regression?
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Orthogonal polynomials
monomials often suffer from high correlation
orthogonal polynomials are constructed
to have orthogonal basis functions (w.r.t. some measure)
Z b
Ti (x)Tj (x)w (x) = 0 ∀i, j i 6= j
a
w (x) is some weighting function
Popular orthogonal polynomials are Chebyshev polynomials
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Chebyshev polynomials
defined on interval [−1, 1]
weighting function
1
w (x) =
(1 − x 2 )1/2
basis functions
T0 (x) = 1
T1 (x) = x
Tj+1 (x) = 2xTj (x) − Tj−1 (x) j > 1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Why not an equidistant grid?
suppose we have an equidistant grid
it turns out that the higher the order of polynomial
the larger the “swings” between grid points
these oscillations become more dramatic at the end points!
Weierstraas’ theorem
there exists a uniformly converging polynomial approximation
to find it, however, we have to be smart about the nodes
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Chebyshev nodes
Chebyshev nodes ensure uniform convergence
the roots (zj ) at which the basis functions are equal to 0
e.g. T2 (x) = 2x 2 − 1 → nodes of z1 = −1/2 and z2 = 1/2
i.e. get n Chebyshev nodes by solving the nth basis function
this is the reason for the popularity of Chebyshev polynomials
Chebyshev nodes can be computed according to
(2j − 1)π
zj = −cos
2n
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Interval conversion
to approximate on an interval [a, b]
we must rescale the Chebyshev nodes
find α and β for which
x = αz + β
β−α=a
β+α=b
then if z ∈ [−1, 1] and x ∈ [a, b] then
b−a a+b
x= z+
2 2
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Splines - main idea
polynomials approximate over entire domain
spectral method
splines split support into sections
finite element method
splines can be expressed as linear combinations of basis fces
but they are not polynomials
basis functions are zero for most of the domain
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Piece-wise linear splines
the easiest type is piece-wise linear
x − xi x − xi
f (x) ≈ 1 − fi + fi+1 x ∈ [xi , xi+1 ]
xi+1 − xi xi+1 − xi
in general not differentiable at nodes
could be problematic → use higher-order polynomials
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Cubic splines
fit a 3-rd order polynomial in each segment
f (x) ≈ ai + bi x + ci x 2 + di x 3 x ∈ [xi , xi+1 ]
( S (x) x ≤ x ≤ x
1 0 1
S(x) = Si (x) xi−1 ≤ x ≤ xi
Sn (x) xn−1 ≤ x ≤ xn
i.e. we have n separate cubic splines for n + 1 nodes
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Cubic splines
n splines give 4n coefficients to determine
what conditions pin down the 4n coefficients?
2 + 2(n − 1) function values at the nodes
2(n − 1) smoothness conditions (for 0 < i < n)
Si0 (xi ) = Si+1
0
(xi )
Si00 (xi ) = Si+1
00
(xi )
2 boundary conditions
“natural (simple)” S100 (x0 ) = 0 and Sn00 (xn ) = 0
or “clamped” S10 (x0 ) = 0 and Sn0 (xn ) = 0
Sedláček Monash Macro
Introduction Main idea
Motivation and content Why polynomials
Neoclassical growth model Choice of basis functions
Function approximation Choice of nodes
Numerical integration Interval conversion
Summary Splines
Before we move on...
sovling DSGE models means getting policy functions
so how does function approximation work in DSGE models?
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Numerical integration
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Why numerical integration?
in economics, there are plenty of integrals
expectations
evaluating integrals can be a tough problem
the functional form may be nasty
we may not even have the functional form
we may be able to evaluate it, but not draw from it
as in e.g. Bayesian estimation
therefore, we need a way around this...
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Intuitive integration method
Rb
Consider you want to compute the integral a h(x)dF (x)
where x is a random variable with CDF F (x)
Monte-Carlo integration uses the following approximation
Z b PT
h(xt )
h(x)dF (x) ≈ t=1
a T
{xt }T
t=1 is a series drawn from a random number generator
This procedure is very simple and intuitive but
it is not very accurate (fast)
more powerful procedures available → numerical integration
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Main idea of numerical integration
we want to calculate
Z b
I = f (x)dx
a
the basic idea is to approximate it with
n
X
I ≈ ωi f (xi )
i=1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Main idea of numerical integration
n
X
I ≈ ωi f (xi )
i=1
therefore, we face (at least) three choices
choice of quadrature weights, ωi ’s
choice of quadrature nodes, xi ’s
choice of number of evaluations, n
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Types of quadrature methods
Newton-Cotes quadrature methods
break interval into equidistant intervals
approximate f (x) with a low-order polynomial
use integrals of polynomials as the approximations
Gaussain quadrature methods
same idea as with Newton-Cotes
more clever in choosing quadrature nodes
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Newton-Cotes
Types of Newton-Cotes quadrature methods
mid-point rule
interpolant is a constant
trapezoid rule
interpolant is linear
Simpson’s rule
interpolant is quadratic
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Simpson’s quadrature
X
I ≈ ωi P2 (xi )
i
choose 3 equidistant nodes in (each) interval [a, b] :
x0 = a, x1 = a + h and x2 = a + 2h = b
choose polynomial type to approximate f (x)
Simpson’s quadrature uses Lagrange polynomials
the beauty is that Simpson’s rule can be standardized!
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Lagrange basis functions
Pn (x) = a0 L0 (x) + ... + an Ln (x)
(x − x0 )...(x − xj−1 )(x − xj+1 )...(x − xn )
Lj (x) =
(xj − x0 )...(xj − xj−1 )(xj − xj+1 )...(xj − xn )
Lj ’s are polynomials so the approximation is a polynomial
the approximation gives an exact fit at the n + 1 nodes
(
1 if x = xj
Lj (x) =
0 if x ∈ {x0 , ..., xn } \ xj
what are the coefficients of the polynomial?
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Simpson’s quadrature
Z b
I ≈ (f0 L0 (x) + f1 L1 (x) + f2 L2 (x)) dx
a
Z b Z b Z b
=f0 L0 (x)dx + f1 L1 (x)dx + f2 L2 (x)dx
a a a
doing the integration results in
Z b Z b Z b
L0 (x)dx = 1/3h L1 (x)dx = 4/3h L2 (x)dx = 1/3h
a a a
i.e. you can find quadrature weights
independent of the functional form of f!
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Simpson’s quadrature
The above can be easily extended to n + 1 equidistant nodes
total number of nodes must be odd
this gives us n/2 segments of lenght h
apply the above idea for each of the segments
Z b
1 4 2 4 2
f (x)dx ≈ f0 + f1 + f2 + f3 + f4 + · · ·
a 3 3 3 3 3
2 4 1
+ fn−2 + fn−1 + fn h
3 3 3
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Gaussian quadrature
Newton-Cotes formulas are simple due to equidistant nodes
moreover, one can show that with Newton-Cotes
we get the exact answer when the true function
is a polynomial of order n − 1
but we can get more accuracy by choosing nodes cleverly
we get the exact answer if the true function
is a polynomial of order 2n − 1!
i.e. 5 nodes give exact (accurate) answers for true functions
which are (approximated by) a 9th order polynomial!
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Procedure of Gaussian quadrature
R1
Using n nodes, we can approximate −1 f (x)dx as
Z 1 n
X
f (x)dx ≈ ωi f (ζi )
−1 i=1
i.e. we have 2n parameters
want correct answer for any polynomial of order 2n − 1
→ make sure we get correct answer for basis functions
1, x, x 2 , · · · , x 2n−1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Procedure of Gaussian quadrature
How to choose weights and nodes?
to get the basis functions
we must solve for ωi and ζi ∀i s.t.
Z 1 n
ωi ζij j = 0, 1, · · · , 2n − 1
X
x j dx =
−1 i=1
i.e. solve a system of 2n equations in 2n unknowns
note that the solution is independent of f !
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Gauss-Legendre quadrature
the above method (for interval between −1 and 1)
is called Gauss-Legendre quadrature
nodes (ζiGL ) and weights (ωiGL ) satisfy above 2n conditions
the approximation is then given by
Z 1 n
X
f (x)dx ≈ ωiGL f (ζiGL )
−1 i=1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Gauss-Hermite quadrature
when the true function is given by f (x) = g (x)W (x) where
g (x) can be approximated well by a polynomial
but f (x) cannot
then adjust the quadrature procedure depending on W (x)
Gauss-Hermite quadrature is used when W (x) = exp(−x 2 )
why is this an interesting case?
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Gauss-Hermite quadrature
nodes and weights chosen s.t.
Z ∞ n
ωi ζij j = 0, 1, · · · , 2n − 1
X
x j exp(−x 2 )dx =
−∞ i=1
the approximation is then given by
Z ∞ n
X
2
g (x) exp(−x )dx ≈ ωiGH f (ζiGH )
−∞ i=1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Chebyshev quadrature
1
case when W (x) = (1−x 2 )1/2
nodes and weights again choses such that
Z 1 n
1
ωi ζij
X
j
x 2 1/2
dx =
−1 (1 − x ) i=1
resulting nodes ζiGC = nodes in Chebyshev polynomials
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Change of variable
suppose we want to calculate
Z ∞
(y − µ)2
g (y )
√ exp − dy
−∞ σ 2π 2σ 2
how to use Gauss-Hermite quadrature?
y −µ
√
define x = √
σ 2
or y = xσ 2 + µ
this gives
∞
√
Z
g (xσ 2 + µ) √
√ exp(−x 2 )σ 2dx
−∞ σ 2π
then use Gauss-Hermite quadrature
Z ∞ n √
(y − µ)2 GH
g (y ) X
GH h(ζi σ 2 + µ)
√ exp − dy ≈ ωi √
−∞ σ 2π 2σ 2 π
i=1
Sedláček Monash Macro
Introduction Main idea
Motivation and content Newton-Cotes
Neoclassical growth model Gaussian quadrature
Function approximation Gauss-Hermite quadrature
Numerical integration Chebyshev quadrature
Summary Change of variable
Change of variable
could you instead simply do the following?
(y −µ)2
exp − 2
g (y ) 2σ
g (y ) = √
σ 2π exp(−y 2 )
R∞
and approximate −∞ g (y ) exp(−y 2 )?
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model
Function approximation
Numerical integration
Summary
What did we do?
1 motivation and overview of entire course
what tools and how are they used in practice?
2 a simple DSGE model
3 functional approximation
basics, polynomials, splines
4 numerical integration
quadrature methods
Sedláček Monash Macro
Introduction
Motivation and content
Neoclassical growth model
Function approximation
Numerical integration
Summary
What’s next?
we now know the basic tools
apply them in two solution methods for DSGE models
projection
perturbation
Sedláček Monash Macro