Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f...

29
Lecture VIII Global Approximation Methods: I Gianluca Violante New York University Quantitative Macroeconomics G. Violante, ”Global Methods” p. 1 /29

Transcript of Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f...

Page 1: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Lecture VIII

Global Approximation Methods: I

Gianluca Violante

New York University

Quantitative Macroeconomics

G. Violante, ”Global Methods” p. 1 /29

Page 2: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Global function approximation

• Global methods: function interpolation over the entire domain

• First choice: type of approximation

1. Interpolation I: finite element methods

◮ Splines (e.g., B-splines, cubic splines, Schumaker splines)

2. Interpolation II: spectral methods

◮ Orthogonal polynomials (e.g., Chebyshev, Lagrange, etc...)

• Second choice: how to minimize residuals between true functionand interpolant

1. Collocation

2. Least squares

3. Galerkin method

G. Violante, ”Global Methods” p. 2 /29

Page 3: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Interpolation

• Today, one dimension.

• We want to represent a real-valued function f on [a, b] with acomputationally tractable function

• Interpolation is a form of function approximation in which theapproximating (interpolant) and the true function must agree , i.e.they must have same value, at a finite number of points.

• In some cases additional restrictions are imposed on theinterpolant. E.g., f ′ evaluated at a finite number of points mayhave to agree with that of the underlying function. Other examplesinclude additional constraints imposed on the interpolant such asmonotonicity, convexity, or smoothness requirements.

• In general, interpolation is any method that takes information at afinite set of points, X , and finds a function which satisfies thatinformation at X .

G. Violante, ”Global Methods” p. 3 /29

Page 4: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Interpolation

• We want to approximate a known function f (x) . The interpolant fis chosen to be a linear combination of a collection of basisfunctions {φj (x)}

n

j=0where n is the order/degree of interpolation

• Basis functions: linearly independent functions that span thefamily of functions chosen for the interpolation (the function space)

◮ any function in the space can be obtained as a linearcombination of basis functions, just as every vector in a vectorspace can be obtained as a linear combination of basisvectors.

• In general we are interested in the space of continuous orcontinuously differentiable functions.

G. Violante, ”Global Methods” p. 4 /29

Page 5: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Interpolation

• Thus, for a given family of basis function {φj}n

j=0we have:

f(x) ≃ f(x) ≡n∑

j=0

wjφj (x)

• We have reduced the problem of characterizing aninfinite-dimensional object, f , to the problem of determining the n

weights (or coefficients) {wj}

• There is arbitrariness in interpolation: there are arbitrarily manyfunctions passing through a finite number of points. Which basis?

• Choices: spectral or finite element methods depending whetherthe basis functions are nonzero over the entire domain of the truefunction (except possibly at a finite number of points) or nonzeroonly on a subinterval of the domain.

G. Violante, ”Global Methods” p. 5 /29

Page 6: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Finite element methods

• Use local basis

• These are called splines

• An order n spline consists of a series of nth order polynomialsegments spliced together so as to preserve continuity ofderivatives of order n− 1 or less.

• The points at which the pieces are spliced together are calledknots or breakpoints.

• By convention the first and last knots are the two extremes of thefunction domain.

G. Violante, ”Global Methods” p. 6 /29

Page 7: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Splines

• An order n spline with K + 1 knots has K (n+ 1) parameters.

• The simplest way to proceed (Judd calls it the “kindergartenprocedure of connecting the dots”) is to use linear B-splines,where B stands for basic.

• Suppose we have a grid with knots x0 < ...xk < ... < xK and wewant to approximate a function f (x) .

• B0 splines are defined as right-continuous step functions

B0k (x) =

{

1 if xk ≤ x < xk+1

0 otherwise

• So interpolant is:

f (x) =K−1∑

k=0

[

f (xk) + f (xk+1)

2

]

B0k (x)

G. Violante, ”Global Methods” p. 7 /29

Page 8: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Linear B-splines

• B1 splines implement piece-wise linear interpolation

B1k (x) =

x−xk−1

xk−xk−1if xk−1 ≤ x < xk

xk+1−x

xk+1−xkif xk ≤ x < xk+1

0 elsewhere

and each one looks like a “tent-function” with peak at xk equal toone, thus the weight of the interpolant must be f (xk)

• The interpolant is therefore defined as:

f (x) =K∑

k=0

f (xk)B1k (x)

• You can also obtain the same weights from 2K conditions: f atknots equal to f(x) (K + 1 conditions), and interpolant continuousat interior knots (K − 1 conditions)

G. Violante, ”Global Methods” p. 8 /29

Page 9: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Linear spline Basis Functions on [0, 1].

0

1

0

1

0 10

1

0 1 0 1

G. Violante, ”Global Methods” p. 9 /29

Page 10: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Linear B-splines

• It is easy to see that for any given point x on an interval [xk, xk+1]there are only two nonzero basis at x, Bk (x) and Bk+1 (x) .

• To locate the knots (k, k + 1) that bracket x you use a bracketingalgorithm that essentially proceeds by bisection.

• Thus

f (x) = f (xk)xk+1 − x

xk+1 − xk

+ f (xk+1)x− xk

xk+1 − xk

= f (xk)xk+1 − x− xk + xk

xk+1 − xk

+ f (xk+1)x− xk

xk+1 − xk

= f (xk) + [f (xk+1)− f (xk)]x− xk

xk+1 − xk

that is a familiar formula for linear interpolation of decision rules(see later...)

G. Violante, ”Global Methods” p. 10 /29

Page 11: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Linear Spline approximation (7 knots)

x0=a x

1 x

2 x

3 x

4 x

5 x

6=b

G. Violante, ”Global Methods” p. 11 /29

Page 12: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Pros and cons of linear splines

• Pros:

◮ Preserves monotonicity and concavity of f .

◮ We can exploit information about f clustering points moreclosely together in areas of high curvature or areas where weknow a kink exists in order to increase our accuracy.

◮ We can capture binding inequality constraints very well.

• Cons:

◮ The approximated function is not differentiable at the knots(they become kinks).

◮ f ′′ = 0 where it exists (it does not exist at the knots). Functionnot smooth.

G. Violante, ”Global Methods” p. 12 /29

Page 13: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Cubic splines

• Cubic spline (n = 3), has 4K coefficients to be determined

◮ f (xk) = f (xk) (K + 1 conditions)

◮ Continuity of f at interior points (K − 1 conditions)

◮ Continuity of f ′ at interior points (K − 1 conditions)

◮ Continuity of f ′′ at interior points (K − 1 conditions)

◮ f ′′ (x0) = f ′′ (xK) = 0 (2 conditions)

• These last two can be modified to something else depending onwhat is suitable in the particular case at hand, they are ad-hocand they can be more than 2.

G. Violante, ”Global Methods” p. 13 /29

Page 14: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Cubic spline Basis Functions on [0,1].

0

1

0

1

0 10

1

0 1 0 1

G. Violante, ”Global Methods” p. 14 /29

Page 15: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Cubic spline Basis Functions on [0,1].

0

10

20

30

40

50

60

0 5 10 15 20 25

Spline 1: Piecewise Linear Interpolation

Spline 2: Piecewise Cubic Interpolation

Data

G. Violante, ”Global Methods” p. 15 /29

Page 16: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Pros and cons of cubic splines

• Pros:

◮ Easy to compute: interpolant matrix very sparse, easy toinvert.

◮ Smooth approximation

• Cons:

◮ It may not be able to handle constraints well

◮ It does not preserve monotonicity and concavity of f

G. Violante, ”Global Methods” p. 16 /29

Page 17: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Schumaker splines

• So far: linear interpolation preserves shape (monotonicity andconcavity), but not differentiability. Cubic splines preservesdifferentiability, but not shape.

• Schumaker quadratic splines preserve both (Schumaker, 1983,SIAM Journal on Numerical Analysis).

• By shape we mean that in those intervals where the data ismonotonically increasing or decreasing, the spline has the sameproperty. Similarly for convexity or concavity.

• Idea: add knots to a subinterval by means of an algorithm

G. Violante, ”Global Methods” p. 17 /29

Page 18: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Solving the income fluctuation problem

V (a, yj) = max{c,a′}

u (c) + β∑

yi∈Y

π (yi|yj)V (a′, yi)

s.t.

c+ a′ ≤ Ra+ yj

a′ ≥ a

The Euler equation, once we substitute in the budget constraint, reads:

uc (Ra+ yj − a′)− βR∑

yi∈Y

π (yi|yj)uc (Ra′ + yi − a′′) ≥ 0.

where the strict inequality holds when the constraint binds.

G. Violante, ”Global Methods” p. 18 /29

Page 19: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Policy function iteration with linear interpolation

1. Construct a grid on the asset space {a0, a2, ..., am} witha0 = a = 0.

2. Guess an initial vector of decision rules for a′′ on the grid points,call it a0 (ai, yj), where the subscript 0 denotes the initial iteration

3. For each point (ai, yj) on the grid, check whether the borrowingconstraint binds. I.e. check whether:

uc (Rai + yj − a0)−βR∑

y′∈Y

π (y′|yj)uc (Ra0 + y′ − a0 (a0, y′)) > 0.

4. If this inequality holds, the borrowing constraint binds. Then, seta′0 (ai, yj) = a0 and repeat this check for the next grid point. If theequation instead holds with the < inequality, we have an interiorsolution (it is optimal to save for the household) and we proceedto the next step.

G. Violante, ”Global Methods” p. 19 /29

Page 20: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Policy function iteration with linear interpolation

5. For each point (ai, yj) on the grid, use a nonlinear equation solverto find the solution a∗ of the nonlinear equation

uc (Rai + yj − a∗)− βR∑

y′∈Y

π (y′|yj)uc (Ra∗ + y′ − a0 (a∗, y′)) = 0

(a) Need to evaluate the function a0 (a, y′) outside grid points:

assume it is piecewise linear.

(b) Every time the solver calls an a∗ which lies between gridpoints, do as follows. First, find the pair of adjacent grid points{ai, ai+1} such that ai < a∗ < ai+1, and then compute

a0 (a∗, y′) = a0 (ai, y

′)+(a∗ − ai)

(

a0 (ai+1, y′)− a0 (ai, y

′)

ai+1 − ai

)

(c) If the solution of the nonlinear equation is a∗, then seta′0 (ai, yj) = a∗ and iterate on the next grid point.

G. Violante, ”Global Methods” p. 20 /29

Page 21: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Policy function iteration with linear interpolation

6. Check convergence by comparing a′0 (ai, yj)− a0 (ai, yj) throughsome pre-specified norm. For example, declare convergence atiteration n when

maxi,j

{|a′n (ai, yj)− an (ai, yj) |} < ε

for some small number ε which determines the degree oftolerance in the solution algorithm.

7. If convergence is achieved, stop. Otherwise, go back to point 3with the new guess a1 (ai, yj) = a′0 (ai, yj).

Note that the most time-consuming step in this procedure is 5, theroot-finding problem. We now discuss how to avoid it.

G. Violante, ”Global Methods” p. 21 /29

Page 22: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Endogenous grid method (EGM)

• EGM is much faster than the traditional method because it doesnot require the use of a nonlinear equation solver

• The essential idea of the method is to construct a grid on a′, nextperiod’s asset holdings, rather than on a, as is done in thestandard algorithm.

• The method also requires the policy function to be at least weaklymonotonic in the state

• Recall the Euler equation:

uc (c (a, y)) ≥ βR∑

y′∈Y

π (y′|y)uc (c (a′, y′)) .

• As usual, we start from a guess c0 (a, y) and iterate on the EulerEquation until the decision rule for consumption that we solve foris essentially identical to the one in the previous iteration.

G. Violante, ”Global Methods” p. 22 /29

Page 23: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

EGM: Algorithm

1. Construct a grid for (a′, y)

2. Guess a policy function c0 (ai, yj). If y is persistent, a good initialguess is to set c0 (ai, yj) = rai + yj which is the solution underquadratic utility if income follows a random walk.

3. Fix yj . Instead of iterating over {ai} , we iterate over {a′i}. For anypair {a′i, yj} on the mesh construct the RHS of the Euler equation[call it B (a′i, yj)]

B (a′i, yj) ≡ βR∑

y′∈Y

π (y′|yj)uc (c0 (a′i, y

′))

where the RHS of this equation uses the guess c0 on the grid

G. Violante, ”Global Methods” p. 23 /29

Page 24: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

EGM: Algorithm

4. Use the Euler equation to solve for the value c (a′i, yj) that satisfies

uc (c (a′i, yj)) = B (a′i, yj)

and note that it can be done analytically, e.g. for uc (c) = c−γ we

have c (a′i, yj) = [B (a′i, yj)]− 1

γ . Here algorithm becomes muchmore efficient because it does not require a nonlinear solver.

5. From the budget constraint:

c (a′i, yj) + a′i = Ra∗i + yj

solve for a∗ (a′i, yj) the value of assets today that would lead theconsumer to have a′i assets tomorrow if her income shock was yjtoday. This yields c (a∗i , yj) = c (a′i, yj), a function not defined onthe grid points. This is the endogenous grid and it changes oneach iteration.

G. Violante, ”Global Methods” p. 24 /29

Page 25: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

EGM: Algorithm

6. Let a∗0 be the value of asset holdings that induces the borrowingconstraint to bind next period, i.e., the value for a∗ that solves thatequation at the point a′0, the lower bound of the grid.

7. Now we need to update our guess defined on the original grid.

• To get new guess c1 (ai, yj) on grid points ai > a∗0 we can usesimple linear interpolation methods using values for{

c (a∗n, yj) , c(

a∗n+1, yj)}

on the two most adjacent values{

a∗n, a∗n+1

}

that bracket ai.

• If some points ai are beyond a∗m, the upper bound of theendogenous grid, just extend linearly the function

G. Violante, ”Global Methods” p. 25 /29

Page 26: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

EGM: Algorithm

• To update the consumption policy function on grid valuesai < a∗0, we use the budget constraint:

c1 (ai, yj) = Rai + yj − a′0

since we cannot use the Euler equation as the borrowingconstraint is binding for sure next period: the reason is that wefound it was binding at a∗0, therefore a fortiori it will be bindingfor ai < a∗0.

8. Check convergence as before.

G. Violante, ”Global Methods” p. 26 /29

Page 27: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Envelope condition method (ECM)

It is an alternative method that, in some cases, like the EGM, avoidsthe use of nonlinear solvers

1. Construct a grid on a with K + 1 points: call it A.

2. Guess a value function V0 (a, yj) =∑K

k=0w0

kjBk (a) where Bk arecubic splines.

3. Compute the derivative of the value function on the nodes of A:

V ′0 (ai, yj) =

K∑

k=0

w0kjB

′k (ai)

Note: if you wish to use B1 splines instead, you need to use adifferent grid in the above step because V0 is not differentiable onthe nodes of the original grid A

G. Violante, ”Global Methods” p. 27 /29

Page 28: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Envelope Condition Method (ECM)

5. For any pair {ai, yj} on A× Y construct the envelope condition:

V ′0 (ai, yj) = uc (Rai + yj − a0 (ai, yj))R

from which we can obtain:

a0 (ai, yj) = Rai + yj − u−1

c

(

V ′0 (ai, yj)

R

)

On each point of the grid we must verify if the borrowing constraintbinds and if it does, we set a0 (ai, yj) = 0.

6. Update the value function from the Bellman equation. For eachpoint of the grid A compute:

V1 (ai, yj) = u (Rai + yj − a0 (ai, yj))+β∑

yj′∈Y

π (yj′ |yj) V0 (a0 (ai, yj) , yj′)

G. Violante, ”Global Methods” p. 28 /29

Page 29: Lecture VIII Global Approximation Methods: I · 2015-10-08 · We can exploit information about f clustering points more closely together in areas of high curvature or areas where

Envelope Condition Method (ECM)

• In practice, need to solve (K + 1)J equations in (K + 1)J

coefficients{

w1kj

}

of the type:

K∑

k=0

w1kjBk (ai) = u (Rai + yj − a0 (ai, yj))

+β∑

yj′∈Y

π (yj′ |yj)K∑

k=0

w0kj′Bk (a0 (ai, yj))

for all gridpoints, i = 0, 1, ...K and j = 1, 2, ..., J

• It is a linear system of equations

G. Violante, ”Global Methods” p. 29 /29