The full academy launches January 2027. Join the waitlist for the $179 founding price.
Waldbauer Academy of Economics

Courses › Graduate Macroeconomic Theory

Graduate · Module 2 of 15

Dynamic programming

Turning a plan over many periods into a recursion: state and control variables, the Bellman equation, contraction mappings, guess-and-verify, value function iteration, and the cake-eating problem.

By Maximus S. Waldbauer · About 5 to 6 hours, including the problem set and quiz.

The crash course introduced the Bellman equation through cake eating. This module turns that sketch into a working method. Dynamic programming replaces a choice of an entire infinite plan with a much smaller problem: choose today’s action, knowing that tomorrow you will again behave optimally from wherever you land.

You will see how to set up a problem in terms of states and controls, why the Bellman operator is a contraction, how to solve problems exactly by guessing the form of the value function, how to derive the Euler equation from the Bellman equation, and how computers solve the problems we cannot solve by hand. The method is the backbone of Modules 3 to 11.

By the end of this module you will be able to

What this module covers

  1. From plans to recursion
  2. The Bellman equation
  3. Contraction mappings and value function iteration
  4. Guess and verify
  5. Uncertainty and numerical methods
  6. Problem set with step-by-step solutions
  7. Module quiz

Lesson 2.1 Free lesson

From plans to recursion

Many economic decisions are plans: how much of a paycheque to spend this month and how much to keep, how to draw down savings in retirement, when to accept a job offer. The direct approach chooses the whole sequence at once. For a cake (or savings account) of size W0 eaten over periods 0, 1, …, T, the sequence problem is

max over c0, …, cT of Σt=0T βt u(ct) subject to Wt+1 = Wt − ct, WT+1 ≥ 0

Here β between 0 and 1 is the discount factor: a util next period is worth β utils today. With few periods we can solve this by working backward, which is the heart of dynamic programming.

Worked example: Three periods of cake, solved backward

Take u(c) = ln c, β = 0.9 and W0 = $100 to spend over periods 0, 1 and 2.

Period 2 (last): nothing is left to save for, so eat whatever remains: c2 = W2.

Period 1: choose c1 to maximize ln c1 + 0.9 ln(W1 − c1). The first-order condition 1/c1 = 0.9/(W1 − c1) gives c1 = W1/1.9.

Period 0: the same logic with two periods to go gives c0 = W0/(1 + 0.9 + 0.81) = 100/2.71 = $36.90. Then W1 = $63.10, c1 = 63.10/1.9 = $33.21 and c2 = $29.89.

Each period’s consumption is 0.9 times the previous one, and with T periods left the share eaten is 1/(1 + β + … + βT). As the horizon grows without limit, that share tends to 1 − β = 10%: the infinite-horizon rule from the crash course.

Backward induction works because of Bellman’s principle of optimality: an optimal plan has the property that, whatever the first decision, the remaining decisions are optimal for the situation that first decision creates. So we never need to reconsider the past; we only need the best continuation from each possible situation.

Why recursion matters

With an infinite horizon there is no last period to start from. But the problem looks the same every period: facing a cake of size W, you want to do the best you can from here on. The only thing that differs between dates is the size of the cake. That observation turns an infinite sequence of choices into one equation in one unknown function, the Bellman equation of Lesson 2.

Common mistake

Treating discounting as irrational. β < 1 only says a util today counts more than a util tomorrow. It may reflect impatience, a chance of not being around to enjoy the future, or simply a convenient way to keep infinite sums finite.

Key ideas

  • A sequence problem chooses an entire plan; dynamic programming chooses one decision at a time.
  • Backward induction solves finite problems from the last period to the first.
  • The principle of optimality: the rest of an optimal plan is optimal from wherever it starts.
  • With log utility, the share of wealth eaten tends to 1 − β as the horizon grows.

Practice questions: Dynamic programming

Try these, then open each answer to check your work.

  1. 1.In a dynamic program, the state variable is
    1. the choice made today that maximizes the reward
    2. everything inherited from the past that matters for the future
    3. the discount factor applied to future rewards
    4. the reward earned in the current period
    Show answer

    Answer: B. The state summarizes what is inherited and relevant for future payoffs; the control is chosen.

  2. 2.With log utility and β = 0.9, an infinite-horizon cake eater with $200 eats this period
    1. $10
    2. $20
    3. $90
    4. $180
    Show answer

    Answer: B. c = (1 − β)W = 0.1 × 200 = $20.

  3. 3.Which pair of conditions combines into the Euler equation u′(c) = β(1 + r)u′(c′)?
    1. The first-order condition and the envelope condition
    2. Monotonicity and discounting
    3. The transversality condition and the budget
    4. Completeness and transitivity
    Show answer

    Answer: A. The FOC gives u′(c) = βV′(a′) and the envelope condition gives V′(a′) = (1 + r)u′(c′).

Problems with step-by-step solutions

  1. 4.With u = ln c, β = 0.8 and a cake of $100 to be eaten over two periods (0 and 1), find c0 and c1.
    Show step-by-step solution
    1. In period 1 eat everything left: c1 = 100 − c0.
    2. Maximize ln c0 + 0.8 ln(100 − c0): 1/c0 = 0.8/(100 − c0), so c0 = 100/1.8 ≈ $55.56.
    3. c1 ≈ $44.44, and c1/c0 = 0.8 = β.
  2. 5.With log utility and β = 0.95, what share of the cake is eaten in period 0 when there are 3 periods in total, and in the infinite-horizon limit?
    Show step-by-step solution
    1. With 3 periods the share is 1/(1 + β + β2) = 1/(1 + 0.95 + 0.9025) = 1/2.8525 ≈ 35.1%.
    2. Infinite horizon: 1 − β = 5%.

Get the full module

The complete module adds every lesson, interactive graphs, a full problem set with step-by-step solutions, and a quiz. The academy opens in January 2027: join the waitlist for the founding price (lifetime access for $179).

Join the waitlist Try a full module free

More practice: free practice questions for this course.