Sunteți pe pagina 1din 31

EC744 Lecture Notes: Projection Method

Jianjun Miao
Solve a functional equation problem
T) = 0,
or a xed point problem
T) = ).
References
Adda, J. and R. Cooper, 2003, Dynamic Economics, MIT Press.
Judd, K., 1992, Projection Methods for Solving Aggregate Growth Models,
Journal of Economic Theory 58, 410452.
Judd, K., 1998, Numerical Methods in Economics, Cambridge, MA: MIT
Press.
Miranda and Fackler, 2002, Applied Computational Economics and Fi-
nance, MIT Press. Chapters 5-9.
1 Function Approximation
1.1 Interpolation Principles
Approximate ) by
^
),
^
) (a) =
a

)=1
c
)

)
(a) ,
where a is called the degree of interpolation,
1
,
2
, ...,
a
are linearly inde-
pendent basis functions, and c
1
, c
2
, ..., c
a
are basis coecients. One needs to
determine (c
1
, c
2
, ..., c
a
) .
One way is to use the collocation method, which solves the interpolation
conditions
a

)=1
c
)

)
(a
i
) = ) (a
i
) , i = 1, 2, ..., a,
where (a
1
, ..., a
a
) is called the interpolation nodes or collocation nodes. We
can rewrite it as the matrix form:
c = j,
where
i)
=
)
(a
i
) and j
i
= ) (a
i
) . is called the interpolation matrix.
Other methods include the least-squares method and the Galerkin method.
They are all called the weighted residual method.
1.2 Spectral Method: Polynomial Interpolation
According to the Weierstrass Theorem, any continuous function dened on
a bounded interval can be approximated to any degree of accuracy using a
polynomial.
monomial basis. Use power functions 1, a, a
2
, a
3
... The interpolation matrix
is called Vandermonde matrix
=
_

_
1 a
1
... a
a1
1
1 a
2
... a
a1
2
...
1 a
a
... a
a1
a
_

_
.
This matrix is ill conditioned and cause rounding error.
Chebychev polynomials. Suppose a takes values in a bounded interval [o, b] .
Choose basis functions
)
(a) = T
)1
(a) , where
T
0
(:) = 1, T
1
(:) = :, T
2
(:) = 2:
2
1
T
)
(:) = 2:T
)1
(:) T
)2
(:) , ...
where : = 2 (a o) (b o) 1.
Choose the a roots of T
a
(:) as the interpolation nodes. Then the interpolation
matrix is well conditioned. In addition, it is orthogonal

T
= oioj a, a2, a2, ..., a2
1.3 Finite Element Method: Spline Interpolation
Linear spline and cubic spline method. An order I spline consists of a series of
Ith-order polynomial segments spliced together so as to preserve continuity of
derivatives of order I 1 or less. The points at which the polynomial pieces
are spliced together,
1
<
2
< ... <
j
, are called the breakpoints of the
spline.
Choose evenly or unevenly spaced interpolation nodes
1.4 Multidimensional Interpolation
Consider the problem of interpolating a o-variate function ) on a odimensional
interval
1 = (a
1
, a
2
, ..., a
o
) : o
i
a
i
b
i
, i = 1, 2, ..., o .
Let
_

i)
: ) = 1, 2, ..., a
i
_
be an a
i
degree univariate basis for real-valued
functions dened on [o
i
, b
i
] , and let
_
a
i)
: ) = 1, 2, ..., a
i
_
be a sequence of
a
i
interpolation nodes for the interval [o
i
, b
i
] . Then an a =
o
i=1
a
i
degree
function basis dened on 1 may be obtained by letting

)
1
)
2
...)
o
(a
1
, a
2
, ..., a
o
) =
1)
1
(a
1
)
2)
2
(a
2
) ...
o)
o
(a
o
) ,
for i = 1, ..., o and )
i
= 1, 2, ..., a
i
. An approximant for ) in the tensor product
basis takes the form
) (a
1
, a
2
, ..., a
o
) =
a
1

)
1
=1
a
2

)
2
=1
...
a
o

)
o
=1
c
)
1
...)
o

)
1
)
2
...)
o
(a
1
, a
2
, ..., a
o
) .
In tensor notation
) (a
1
, a
2
, ..., a
o
) =
_

o
(a
o
)
o1
_
a
o1
_
...
1
(a
1
)
_
c
where c is an a1 column vector and each
i
is the 1a
i
row vector of basis
functions over dimension i. In matrix form
c = j
where =
o

o1
...
1
is the a a interpolation matrix. Then we
have
c =
_

1
o

1
o1
...
1
1
_
j
Example:

1
(a
1
) =
_
1 a
1
a
2
1
_
,
2
(a
2
) = [1 a
2
]
Then
(a) = [1 a
2
]
_
1 a
1
a
2
1
_
=
_
1 a
1
a
2
1
a
2
a
1
a
2
a
2
1
a
2
_
Nodes a
1
= 0, 1, 2 and a
2
= 0, 1 . Then

1
=
_

_
1 0 0
1 1 1
1 2 4
_

_ ,
2
=
_
1 0
1 1
_
and
=
2

1
=
_

_
1 0 0 0 0 0
1 1 1 0 0 0
1 2 4 0 0 0
1 0 0 1 0 0
1 1 1 1 1 1
1 2 4 1 2 4
_

_
1.5 An Approximation Tool Kit
Routine 1: fspace=fundefn(bastype,n,a,b,order)
Input:
bastype is the string of basis function, which can take the value cheb for
Chebychev polynomial basis, spli for spline basis, or lin for a linear spline
basis
n us the vector containing the degree of approximation along each dimension
a is the vector of left endpoints of the interpolation intervals in each dimen-
sion;
b is the vector of right endpoints of the interpolation intervals in each dimen-
sion;
order is an optional input that species the order of the interpolation spline.
Cubic spline is the default.
Output:
fspace is a structured MATLAB variable containing numerous elds of informa-
tion necessary for forming approximations in the chosen function space.
Routine 2: c = funtf(fspace, f, additional parameters)
Input:
fspace is the approximation function space dened using fundef
f is the string name of the le that evaluates the function to be approximated
additional parameters are passed to f
Output:
c basis coecients
Routine 3: c = funtxy(fspace, x, y)
Input:
fspace is an approximation function space dened using fundef
x is a matrix of points at which the function has been evaluated
y is a matrix of function values at those points
Output:
c is the basis coecients
Routine 4: y = fun eval(c, fspace, x)
Input:
c is the basis coecients
fspace is the approximation function space dened using fundefn
x is the point at which the approximant is to be evaluated
Output:
y is the value of the approximant at x.
Routine 5: x = funnode(fspace)
Computes the standard nodes for interpolation
Routine 6: B = funbas(fspace, x)
Returns the matrix containing the values of the basis functions evaluated at
the points a. The matrix containing the value of the basis functions associated
with a derivative of given order at a can be obtained by
B = funbas(fspace, x, order)
Routine 7: y = gridmake(x) or y = gridmake(a
1
, a
2
, a
2
)
Form multidimensional grid points for matrix x
Example: X=gridmake([1;2;3],[4;5]) produces
1 4
2 4
3 4
1 5
2 5
3 5
Example 1: ) (a) = exp (ca) on [1, 1] .
Example 2: Miranda and Fackler p.144. Collocation Method Find a
function ) such that
j (a, ) (a)) = 0.
Approximate ) by
^
) (a) =
a

)=1
c
)

)
(a)
Now solve the a nonlinear equations
j
_
_
a
i
,
a

)=1
c
)

)
(a
i
)
_
_
= 0,
at the a collocation points (a
1
, ..., a
a
) .
Solve function S (j) such that
j S (j) j
j+1
j
_
c
_
S (j) + S (j)
2
_
= 0.
2 Numerical Integration
How to compute integral
_
) (a) &(a) oa?
Answer: Use summation
_
) (a) &(a) oa
a

i=0
&
i
) (a
i
)
where (a
i
) is quadrature node and (&
i
) is quadrature weights.
Newton-Cotes methods approximate the integrand ) between nodes using low-
order polynomials and sum the integrals of the polynomials to estimate the
integral of ).
Gaussian quadrature methods choose the nodes and weights to satisfy moment-
matching conditions.
Monte Carlo and quasi-Monte Carlo integration methods use equally weighted
random or equidistribted nodes.
2.1 Gaussian Quadrature Method
For a weight function & dened on an interval 1 1, and for a given order of
approximation a, the quadrature nodes a
1
, a
2
, ..., a
a
and quadrature weights
&
1
, &
2
, ..., &
a
are chosen so as to satisfy the 2a moment matching conditions:
_
1
a
I
&(a) oa =
a

i=1
&
i
a
I
i
,
for I = 0, 1, ..., 2a1. The integral approximation is then computed by forming
the prescribed weighted sum of function values at the prescribed nodes:
_
1
) (a) &(a) oa =
a

i=1
&
i
) (a
i
) .
When the weight function & is the density function, Gaussian quadrature has
a straightforward interpretation. It essentially discretizes a continuous random
variable as a discrete random variable with mass points a
i
and probabilities &
i
.
2.2 An Integration Tool Kit
Routine 1: [x, w] = qnwnorm(n, mu, var)
Input: a number of nodes and weights. mu and var are mean and variance of
a normal distribution.
Output: x and w and nodes and weights
Routine 2: [x, w] = qnwlog n(n, mu, var)
Input: a number of nodes and weights. mu and var are mean and variance of
a log-normal distribution.
Output: x and w and nodes and weights
3 Solving Dynamic Programming Problems
DP problem,
\ (c) = max
aA(c)
) (c, a) + c1
.
\ (j (c, a, .))
Step 1: Approximation \
\ (c) ~
a

)=1
c
)

)
(c) .
Step 2: Collocation method to determine c
1. Choose a collocation nodes c
1
, ..., c
a
.
a

)=1
c
)

)
(c
i
) = max
aA(c
i
)
) (c
i
, a) + c1
.
a

)=1
c
)

)
(j (c
i
, a, .)) .
2. Obtain the collocation equation
c = (c)
where is an aa collocation matrix with
i)
=
)
(c
i
) , is the collocation
function

i
(c) = max
aA(c
i
)
) (c
i
, a) + c1
.
a

)=1
c
)

)
(j (c
i
, a, .))
3. Newtons method to solve the collocation equation
c
_

t
(c)
_
1
[c (c)] .
Here
t
(c) is the a a Jacobina of the collocation function at c. One can
apply the envelope theorem to derive

t
i)
(c) =
0
i
(c)
0c
)
= c1
.

)
(j (c
i
, a
i
, .))
where a
i
is the optimal choice.
Remarks:
If the model is stochastic and shock is continuous, one has to use a quadra-
ture scheme. Say, . takes values .
1
, ..., .
1
with probabilities &
1
, ..., &
I
,
respectively. Then the collocation function takes the form

i
(c) = max
aA(c
i
)
) (c
i
, a) + c
1

I=1
a

)=1
&
I
c
)

)
(j (c
i
, a, .
I
))
and its Jacobian takes the form

t
i)
(c) =
0
i
(c)
0c
)
= c
1

I=1

)
(j (c
i
, a
i
, .
I
)) .
One has to choose a suitable basis functions and collocation nodes
One has to choose a suitable initial values. One way is to use the linear-
quadratic solution. The other way is to use a closed form solution under
special parameterization.
3.1 Example: Stochastic Growth Model
\ (I, :) = max
c
l (c) + o1
:
t
[:
\
_
I
t
, :
t
_
subject to
c + I
t
= :I(I) + I.
Suppose shock : is iid and normal. Choose state c = :I(I) + I. Then
\ (c) = max
0I
t
c
l
_
c I
t
_
+ 1
:
_
\
_
:I
_
I
t
_
+ I
t
__
3.2 A Tool Kit
Routine 1: [c, s, v, x, resid] = dp solve (mod el, fspace, s, vinit, xinit)
Let a denote the number of collocation nodes, let a
t
denote the number of
residual evaluation points and let o
c
and o
a
denote the dimensions of the state
and action spaces.
Input:
model is a structured variable that contains all information about the model
fsapce is a structured variable that contains all information about the basis
function
s contains a o
c
collocation nodes
vinit is an a 1 vector of initial guess for the value function
xinit is an a o
a
vector of initial guesses for the optimal policies
Output:
c is an a 1 vector of basis coecients
s is an a
t
o
c
matrix of nodes at which residuals are evaluated
v is an a
t
1 vector of optimal values at the evaluation nodes
x is an a
t
o
a
vector of optimal policies at the evaluation nodes
resid is the a
t
1 vector of residuals at the evaluation nodes.
User dened structured variable model Contain the elds:
func contains the name of the model function le, which evaluates the bound,
reward, and state transition functions
discount contains the discount factor
e and w contain the discretized random shocks only if the model is stochastic
action is specied only if the action space is discrete;
discretestates species the dimension index of the discrete state variables,
only if the state space contains discrete states variables
params contains the parameters to the passed to the model le
User dened model function le [out1,out2,out3]=func(ag,s,x,e,additional
parameters)
Input:
s arow matrix of state variables
x arow matrix of actions
e arow matrix of shock values
Output:
If ag = b, then out1 and out2 are the lower and upper bounds on the actions
If ag = f, then out1 is the value of the reward function, and out2 and out3
are the rst and second derivatives of the reward function w.r.t the action at
the states s and actions.
If ag = g, then out1 is the value of the state transition function, and out2
and out3 are the rst and second derivatives of the state transition function
w.r.t. the action at states s, actions x, and shocks e.
4 Rational Expectations Models
State is c
t
and evolves according to
c
t+1
= j (c
t
, a
t
, .
t+1
) .
Rational expectations condition for an interior solution
) (c
t
, a
t
, :
t
) = 0,
where
:
t
= 1
t
[I(c
t
, a
t
, .
t+1
, c
t+1
, a
t+1
)]
We try to solve policy function a = a(c) . It satises the functional equation
)
_
c, a(c) , 1
_
I
_
c, a, .
t
, j
_
c, a(c) , .
t
_
, a
_
j
_
c, a(c) , .
t
_____
= 0
The model may have constraints:
o (c) a b (c) .
Suppose
a
i
o
i
(c) ==)
i
(c, a, :) 0, a
i
< b
i
(c) ==)
i
(c, a, :) 0.
We may write the model as
min (max () (c, a, :) , o a) , b a) = 0.
We then solve this minmax nonlinear equation.
Direct approximation to the policy function is not good since it may not be
smooth. Instead, we approximate expectation : = (c) that solves
(c) = 1
_
I
_
c, a(c, (c)) , ., c
t
, a
_
c
t
, (c
t
___
for all c, with
c
t
= j (c, a(c, (c)) , .) .
Table: Notation Summary
c S R
o
state variable
a [o, b] R
n
response (choice or equilibrium) variable
: R
j
expectation variable
c R
q
shocks
j : R
o+n+q
R
o
state transition
I : R
o+n+q+o+n
R
o
expectation
) : R
o+n+j
R
n
equilibrium
a : R
o+j
R
n
closed functional form if exist
: R
o
R
n
response
: R
o
R
j
expectation
4.1 Example 1: Stochastic growth Model
\ (I, :) = max
c
c
1
1
+ o1
:
t
[:
\
_
I
t
, :
t
_
subject to
c + I
t
= exp (o) I
c
+ (1 c) I.
where
o
t
= jo + c
with c .
_
0, o
2
_
. Euler equation
c

o1
_
c
t
_
cc
o
t
_
I
t
_
c1
+ 1 c
__
= 0.
The deterministic steady state is
I
+
=
_
1o 1 + c
c
_
1(c1)
.
Now c = (I, o) is two dimensional and a = c.
j (c, a, c) = [c
c
2
c
c
1
+ (1 c) c
1
a jc
2
+ c] ,
I
_
c, a, c, c
t
, a
t
_
= a
t
_
cc
c
t
2
_
c
t
1
_
c1
+ 1 c
_
,
) (c, a, :) = a

o:,
and
a(c, :) = (o:)
1
.
4.2 Example 2. Asset Pricing Model
Dividends
o
t
= j + 0 (o j) + c
where c .
_
0, o
2
_
. The price function j (o) satises
o

j (o) = o1
_
_
o
t
_

_
j
_
o
t
_
+ o
t
_
_
.
Then c = o, a = j
j (c, a, c) = j + 0 (c j) + c
I
_
c, a, c, c
t
, a
t
_
= c
t
_
a
t
+ c
t
_
) (c, a, :) = c

a o:
with
a(c, :) = c

o:.
4.3 A Tool Kit
Main solver: [c,scoord,x,z,f,resid]=resolve(model, fspace, options, cinit)
Input:
model structure mod el
the basis function denition fspace
user specied options
the initial guess for c
Output:
the basis coecients c
states ccccvo
policy a
expectation function :
equilibrium function values )
collocation function residuals resid
The model variable has the following elds.
func user dened model function
params parameters to be passed to the model function le
e discretized shocks
w probabilities associated with the shocks
explicit 0/1 variable, 1 if a(c, :) has an explicit form
nxnext 0/1 variable, 1 if I is not a function of a
t
The options variable has the following elds
expapprox 1 if the expectation function is approximated, 0 otherwise (default
is 1)
usebroyden 1 if Broydens method is used (default is 0).
lowmemory 1 to use less memory (default is 0)
stepsize the c parameter in the xed-point coecient update
tol covergence criteria (default is 10^-8)
maxit maximum number of iterations allowed (default is 500)
showiters 1 to display summary information at each iteration (default is 0)
checks 1 to check whether next periods state is outside the approximation
bounds (default is 0)
nres ination factor used when computing residuals (default is 10)
xtol convergence criteria for computing a (default 10
8
)
xmaxit maximum iterations to compute a (default is 500)
lcpmethod method used to compute a (minmax or smooth) default is
minmax
Template of user dened model function
function [out1, out2]=func(ag,s,x,z,e,shat,xhat,additional parameters);
switch ag
case f
out1=f(z,x,z)
out2=df(s,x,z)/dx
case x
out1=x(s,z)
case g
out1=g(s,x,e)
case h
out1=h(s,x,e,shat,xhat)
case bounds
out1=a
out2=b
end
Procedure:
Step 1. Dene parameter values.
Step 2. Code model le.
Step 3. Discretizes the shock.
Step 4. Structure variable model.
Step 5. Compute linearized model.
Step 6. Initialize values.
Step 7. Launch solver resolve.
Examples:
demre01.m Stochastic Growth Model
demre02.m Asset Pricing Model

S-ar putea să vă placă și