Skip to content

Commit 2c89670

Browse files
jstacclaude
andcommitted
Improve cake eating lecture with exercises and fixes
- Add new exercise (cep_ex2) asking readers to verify that the optimal policy satisfies the Euler equation, with complete solution - Fix grammatical errors: missing "as" in comparison, subject-verb agreement ("Here are" vs "Here's"), and missing article "a" - Add note clarifying differentiability assumption of value function in Derivation II with reference to EDTC theorem 10.1.13 - Improve readability and consistency throughout the lecture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c6cc43c commit 2c89670

File tree

1 file changed

+104
-38
lines changed

1 file changed

+104
-38
lines changed

lectures/cake_eating.md

Lines changed: 104 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ progressively more challenging---and useful---problems.
3030

3131
The main tool we will use to solve the cake eating problem is dynamic programming.
3232

33-
Readers might find it helpful to review the following lectures before reading this one:
33+
The following lectures contain background on dynamic programming and might be
34+
worth reviewing:
3435

3536
* The {doc}`shortest paths lecture <intro:short_path>`
3637
* The {doc}`basic McCall model <mccall_model>`
3738
* The {doc}`McCall model with separation <mccall_model_with_separation>`
3839
* The {doc}`McCall model with separation and a continuous wage distribution <mccall_fitted_vfi>`
3940

40-
In what follows, we require the following imports:
41+
We require the following imports:
4142

4243
```{code-cell} ipython
4344
import matplotlib.pyplot as plt
@@ -46,7 +47,7 @@ import numpy as np
4647

4748
## The model
4849

49-
We consider an infinite time horizon $t=0, 1, 2, 3..$
50+
We consider a discrete time model with an infinite time horizon.
5051

5152
At $t=0$ the agent is given a complete cake with size $\bar x$.
5253

@@ -55,13 +56,12 @@ so that, in particular, $x_0=\bar x$.
5556

5657
We choose how much of the cake to eat in any given period $t$.
5758

58-
After choosing to consume $c_t$ of the cake in period $t$ there is
59+
After choosing to consume $c_t$ of the cake in period $t$, the amount left in period $t+1$ is
5960

6061
$$
61-
x_{t+1} = x_t - c_t
62+
x_{t+1} = x_t - c_t
6263
$$
6364

64-
left in period $t+1$.
6565

6666
Consuming quantity $c$ of the cake gives current utility $u(c)$.
6767

@@ -98,15 +98,14 @@ subject to
9898
```{math}
9999
:label: cake_feasible
100100
101-
x_{t+1} = x_t - c_t
102-
\quad \text{and} \quad
103-
0\leq c_t\leq x_t
101+
x_{t+1} = x_t - c_t
102+
\quad \text{and} \quad
103+
0\leq c_t\leq x_t
104104
```
105105

106106
for all $t$.
107107

108-
A consumption path $\{c_t\}$ satisfying {eq}`cake_feasible` where
109-
$x_0 = \bar x$ is called **feasible**.
108+
A consumption path $\{c_t\}$ satisfying {eq}`cake_feasible` where $x_0 = \bar x$ is called **feasible**.
110109

111110
In this problem, the following terminology is standard:
112111

@@ -122,7 +121,7 @@ The key trade-off in the cake-eating problem is this:
122121
* But delaying some consumption is also attractive because $u$ is concave.
123122

124123
The concavity of $u$ implies that the consumer gains value from
125-
*consumption smoothing*, which means spreading consumption out over time.
124+
**consumption smoothing**, which means spreading consumption out over time.
126125

127126
This is because concavity implies diminishing marginal utility---a progressively smaller gain in utility for each additional spoonful of cake consumed within one period.
128127

@@ -132,18 +131,16 @@ The reasoning given above suggests that the discount factor $\beta$ and the curv
132131

133132
Here's an educated guess as to what impact these parameters will have.
134133

135-
First, higher $\beta$ implies less discounting, and hence the agent is more patient, which should reduce the rate of consumption.
136-
137-
Second, higher $\gamma$ implies that marginal utility $u'(c) =
138-
c^{-\gamma}$ falls faster with $c$.
134+
1. Higher $\beta$ implies less discounting, and hence the agent is more patient, which should reduce the rate of consumption.
135+
2. Higher $\gamma$ implies that marginal utility $u'(c) = c^{-\gamma}$ falls faster with $c$.
139136

140137
This suggests more smoothing, and hence a lower rate of consumption.
141138

142-
In summary, we expect the rate of consumption to be *decreasing in both
143-
parameters*.
139+
In summary, we expect the rate of consumption to be decreasing in both parameters.
144140

145141
Let's see if this is true.
146142

143+
147144
## The value function
148145

149146
The first step of our dynamic programming treatment is to obtain the Bellman
@@ -182,7 +179,7 @@ v(x) = \max_{0\leq c \leq x} \{u(c) + \beta v(x-c)\}
182179
\quad \text{for any given } x \geq 0.
183180
```
184181

185-
The intuition here is essentially the same it was for the McCall model.
182+
The intuition here is essentially the same as it was for the McCall model.
186183

187184
Choosing $c$ optimally means trading off current vs future rewards.
188185

@@ -198,31 +195,34 @@ If $c$ is chosen optimally using this trade off strategy, then we obtain maximal
198195

199196
Hence, $v(x)$ equals the right hand side of {eq}`bellman-cep`, as claimed.
200197

198+
199+
201200
### An analytical solution
202201

203-
It has been shown that, with $u$ as the CRRA utility function in
204-
{eq}`crra_utility`, the function
202+
It has been shown that, with $u$ as the CRRA utility function in {eq}`crra_utility`, the function
203+
$v^*$ given by
205204

206205
```{math}
207206
:label: crra_vstar
208207
209-
v^*(x_t) = \left( 1-\beta^{1/\gamma} \right)^{-\gamma}u(x_t)
208+
v^*(x) = \left( 1-\beta^{1/\gamma} \right)^{-\gamma}u(x)
210209
```
211210

212211
solves the Bellman equation and hence is equal to the value function.
213212

214213
You are asked to confirm that this is true in the exercises below.
215214

215+
```{note}
216216
The solution {eq}`crra_vstar` depends heavily on the CRRA utility function.
217217
218-
In fact, if we move away from CRRA utility, usually there is no analytical
219-
solution at all.
218+
In fact, if we move away from CRRA utility, usually there is no analytical solution at all.
220219
221220
In other words, beyond CRRA utility, we know that the value function still
222221
satisfies the Bellman equation, but we do not have a way of writing it
223222
explicitly, as a function of the state variable and the parameters.
224223
225-
We will deal with that situation numerically when the time comes.
224+
We will deal with that situation numerically in the following lectures.
225+
```
226226

227227
Here is a Python representation of the value function:
228228

@@ -248,26 +248,24 @@ ax.legend(fontsize=12)
248248
plt.show()
249249
```
250250

251+
251252
## The optimal policy
252253

253-
Now that we have the value function, it is straightforward to calculate the
254-
optimal action at each state.
254+
Now that we have the value function, it is straightforward to calculate the optimal action at each state.
255255

256-
We should choose consumption to maximize the
257-
right hand side of the Bellman equation {eq}`bellman-cep`.
256+
We should choose consumption to maximize the right hand side of the Bellman equation {eq}`bellman-cep`.
258257

259258
$$
260-
c^* = \arg \max_{c} \{u(c) + \beta v(x - c)\}
259+
c^* = \arg \max_{c} \{u(c) + \beta v(x - c)\}
261260
$$
262261

263-
We can think of this optimal choice as a function of the state $x$, in
264-
which case we call it the **optimal policy**.
262+
We can think of this optimal choice as a function of the state $x$, in which case we call it the **optimal policy**.
265263

266264
We denote the optimal policy by $\sigma^*$, so that
267265

268266
$$
269-
\sigma^*(x) := \arg \max_{c} \{u(c) + \beta v(x - c)\}
270-
\quad \text{for all } x
267+
\sigma^*(x) := \arg \max_{c} \{u(c) + \beta v(x - c)\}
268+
\quad \text{for all } x
271269
$$
272270

273271
If we plug the analytical expression {eq}`crra_vstar` for the value function
@@ -276,16 +274,16 @@ into the right hand side and compute the optimum, we find that
276274
```{math}
277275
:label: crra_opt_pol
278276
279-
\sigma^*(x) = \left( 1-\beta^{1/\gamma} \right) x
277+
\sigma^*(x) = \left( 1-\beta^{1/\gamma} \right) x
280278
```
281279

282280
Now let's recall our intuition on the impact of parameters.
283281

284-
We guessed that the consumption rate would be decreasing in both parameters.
282+
We guessed that consumption would be decreasing in both parameters.
285283

286284
This is in fact the case, as can be seen from {eq}`crra_opt_pol`.
287285

288-
Here's some plots that illustrate.
286+
Here are some plots that illustrate.
289287

290288
```{code-cell} python3
291289
def c_star(x, β, γ):
@@ -332,7 +330,7 @@ The Euler equation for the present problem can be stated as
332330
u^{\prime} (c^*_{t})=\beta u^{\prime}(c^*_{t+1})
333331
```
334332

335-
This is necessary condition for the optimal path.
333+
This is a necessary condition for the optimal path.
336334

337335
It says that, along the optimal path, marginal rewards are equalized across time, after appropriate discounting.
338336

@@ -447,6 +445,11 @@ This is just the Euler equation.
447445

448446
Another way to derive the Euler equation is to use the Bellman equation {eq}`bellman-cep`.
449447

448+
```{note}
449+
The argument that follows assumes that the value function is differentiable.
450+
A proof of differentiability of the value function can be found in [EDTC](https://johnstachurski.net/edtc.html), theorem 10.1.13.
451+
```
452+
450453
Taking the derivative on the right hand side of the Bellman equation with
451454
respect to $c$ and setting it to zero, we get
452455

@@ -611,3 +614,66 @@ $$
611614
612615
Our claims are now verified.
613616
```
617+
618+
```{exercise}
619+
:label: cep_ex2
620+
621+
Verify that the optimal policy {eq}`crra_opt_pol` satisfies the Euler equation {eq}`euler_pol`.
622+
```
623+
624+
```{solution} cep_ex2
625+
:class: dropdown
626+
627+
Recall that the optimal policy is
628+
629+
$$
630+
\sigma^*(x) = (1 - \beta^{1/\gamma})x
631+
$$
632+
633+
and the Euler equation in policy form is
634+
635+
$$
636+
u'(\sigma(x)) = \beta u'(\sigma(x - \sigma(x)))
637+
$$
638+
639+
With CRRA utility $u(c) = \frac{c^{1-\gamma}}{1-\gamma}$, the marginal utility is
640+
641+
$$
642+
u'(c) = c^{-\gamma}
643+
$$
644+
645+
Now let's verify the Euler equation. The left-hand side is
646+
647+
$$
648+
u'(\sigma^*(x))
649+
= [\sigma^*(x)]^{-\gamma}
650+
= [(1 - \beta^{1/\gamma})x]^{-\gamma}
651+
= (1 - \beta^{1/\gamma})^{-\gamma} x^{-\gamma}
652+
$$
653+
654+
For the right-hand side, we first compute the state in the next period:
655+
656+
$$
657+
x - \sigma^*(x) = x - (1 - \beta^{1/\gamma})x = x\beta^{1/\gamma}
658+
$$
659+
660+
Next period's consumption under the optimal policy is
661+
662+
$$
663+
\sigma^*(x - \sigma^*(x)) = \sigma^*(x\beta^{1/\gamma}) = (1 - \beta^{1/\gamma}) \cdot x\beta^{1/\gamma}
664+
$$
665+
666+
Therefore, the right-hand side of the Euler equation is
667+
668+
$$
669+
\begin{aligned}
670+
\beta u'(\sigma^*(x - \sigma^*(x)))
671+
&= \beta [(1 - \beta^{1/\gamma}) \cdot x\beta^{1/\gamma}]^{-\gamma} \\
672+
&= \beta (1 - \beta^{1/\gamma})^{-\gamma} x^{-\gamma} (\beta^{1/\gamma})^{-\gamma} \\
673+
&= \beta (1 - \beta^{1/\gamma})^{-\gamma} x^{-\gamma} \beta^{-1} \\
674+
&= (1 - \beta^{1/\gamma})^{-\gamma} x^{-\gamma}
675+
\end{aligned}
676+
$$
677+
678+
Since the left-hand side equals the right-hand side, the optimal policy $\sigma^*$ satisfies the Euler equation.
679+
```

0 commit comments

Comments
 (0)