Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10....

25
Numerical Methods-Lecture IV: Bellman Equations: Solutions Trevor Gallen Fall, 2015 1 / 25

Transcript of Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10....

Page 1: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Numerical Methods-Lecture IV:Bellman Equations: Solutions

Trevor Gallen

Fall, 2015

1 / 25

Page 2: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Preliminaries

I We’ve seen the abstract concept of Bellman Equations

I Now we’ll talk about a way to solve the Bellman Equation:Value Function Iteration

I This is as simple as it gets!

2 / 25

Page 3: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Value Function Iteration

I Bellman equation:

V (x) = maxy∈Γ(x)

{F (x , y) + βV (y)}

I A solution to this equation is a function V for which thisequation holds ∀ x

I What we’ll do instead is to assume an initial V0 and define V1

as:V1(x) = max

y∈Γ(x){F (x , y) + βV0(y)}

I Then redefine V0 = V1 and repeatI Eventually, V1 ≈ V0

I But V is typically continuous: we’ll discretize itI Make function continuous by connecting the dots

3 / 25

Page 4: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

4 / 25

Page 5: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

5 / 25

Page 6: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

6 / 25

Page 7: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

7 / 25

Page 8: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

8 / 25

Page 9: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

9 / 25

Page 10: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

10 / 25

Page 11: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

11 / 25

Page 12: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

12 / 25

Page 13: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

13 / 25

Page 14: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

14 / 25

Page 15: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

15 / 25

Page 16: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

16 / 25

Page 17: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

17 / 25

Page 18: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Approximating f(x)

18 / 25

Page 19: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Basic Steps

1. Choose grid of states X and a stopping threshold ε

2. Assume an initial V0 for each x ∈ X

3. For each x ∈ X , solve the problem:

maxy∈Γ(x)

{F (x , y) + βV0(y)}

4. Store the solution as V1(x)

5. Redefine V0 = V1

6. Repeat steps 3-5 until abs(V1 − V0) < ε.

7. Now, for all your relevant points, the Bellman equation holds

8. Solve the system one last time, storing the policy function

19 / 25

Page 20: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

How do I solve the problem?

I Step 3 requires you to solve:

maxy∈Γ(x)

{F (x , y) + βV0(y)}

I How do we do it?

I How do we maximize?

I We’ll learn good ways

I For now, discretize all your choices like you discretized yourstates

I Pick best choice, store utility

I If you allow for choices to imply states that aren’t defined,interpolate linearly

20 / 25

Page 21: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Intuition for VFI

I In the iteration period, all future states are the same: wedon’t care what happens.

I In a “cake-eating” example, this means eat everything.

I In such a scenario, we eat all the cake: we’re happier withmore cake.

I When we iterate once more, now tomorrow is the last day onearth: we now prefer saving a little cake.

I When we iterate again, tomorrow’s tomorrow is the last day...

I Because we discount, as we iterate more, whatever we do onthe last day matters less and less

I Eventually, we’re all but immortal: limt→∞

βt = 0

(really,

limt→∞

βtu2(xt , xt+1)xt+1 = 0)

21 / 25

Page 22: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Aside: Intuition for VFI

I In the iteration period, all future states are the same: wedon’t care what happens.

I In a “cake-eating” example, this means eat everything.

I In such a scenario, we eat all the cake: we’re happier withmore cake.

I When we iterate once more, now tomorrow is the last day onearth: we now prefer saving a little cake.

I When we iterate again, tomorrow’s tomorrow is the last day...

I Because we discount, as we iterate more, whatever we do onthe last day matters less and less

I Eventually, we’re all but immortal: limt→∞

βt = 0 (really,

limt→∞

βtu2(xt , xt+1)xt+1 = 0)

22 / 25

Page 23: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Let’s do a concrete example

U(ct) = log(ct)

ct + it = k0t .7

kt+1 = 0.93kt + it

I Discretize statesI Minimum: k = 0I Maximum: k̄ = 0.93k̄ + k̄0.7 ⇒ k̄ = 7075I Choose 10 possible steps

I Allow choice of feasible discrete k

I Choose best, store it.

I Repeat

23 / 25

Page 24: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Solving in Matlab

alpha = 0.7;

delta = 0.07;

k min = 0;

k max = 7075;

k num = 10;

k space = linspace(k min,k max,k num);

V 1 = 0.*k space;

V 0 = V 1;

error = Inf;

while error > 1e-10

for k index = 1:k num

k = k space(k index);

kchoice index = find(k space < 0.93k+k.^0.7);

k choices = k space(kchoice index);

c choices = 0.93*k+k.^0.7-k choices;

utility = log(c choices) + beta V 0(find(kchoice index));

[V,ind] = max(utility);

V 1(k index) = V;

k best(k index) = k choices(ind);

end

error = max(abs(V 1-V 0))

end

24 / 25

Page 25: Numerical Methods-Lecture IV: Bellman Equations: Solutionstgallen/Teaching/Econ_690... · 2015. 10. 8. · Aside: Intuition for VFI I In the iteration period, all future states are

Simulating in Matlab

num i = k num

num t = 50;

k sim = NaN(num i,num t);

k sim(:,1) = NaN(num i,num t);

for i = 1:num i

for t = 1:num t

k sim(i,t+1) = k best(find(k space)==k sim(i,t))

end end

25 / 25