@@ -84,22 +84,23 @@ Recall the Bellman equation
8484```{math}
8585:label: cpi_fpb30
868687-v^*(x) = \max_{0 \leq c \leq x}
87+v(x) = \max_{0 \leq c \leq x}
8888 \left\{
89- u(c) + \beta \int v^*(f(x - c) z) \phi(dz)
89+ u(c) + \beta \int v(f(x - c) z) \phi(dz)
9090 \right\}
9191\quad \text{for all} \quad
9292x \in \mathbb R_+
9393```
949495-Let the optimal consumption policy be denoted by $\sigma^*$.
95+Let $v^*$ be the value function and let $\sigma^*$ be the optimal consumption policy.
969697-We know that $\sigma^*$ is a $v^*$-greedy policy so that $\sigma^*(x)$ is the maximizer in {eq}`cpi_fpb30`.
97+We know that $\sigma^*$ is a $v^*$-greedy policy.
98989999The conditions above imply that
100100101101* $\sigma^*$ is the unique optimal policy for the optimal savings problem
102-* the optimal policy is continuous, strictly increasing and also **interior**, in the sense that $0 < \sigma^*(x) < x$ for all strictly positive $x$, and
102+* the optimal policy is continuous, strictly increasing and also **interior**,
103+ in the sense that $0 < \sigma^*(x) < x$ for all strictly positive $x$, and
103104* the value function is strictly concave and continuously differentiable, with
104105105106```{math}
@@ -108,7 +109,8 @@ The conditions above imply that
108109(v^*)'(x) = u' (\sigma^*(x) ) := (u' \circ \sigma^*)(x)
109110```
110111111-The last result is called the **envelope condition** due to its relationship with the [envelope theorem](https://en.wikipedia.org/wiki/Envelope_theorem).
112+The last result is called the **envelope condition** due to its relationship
113+with the [envelope theorem](https://en.wikipedia.org/wiki/Envelope_theorem).
112114113115To see why {eq}`cpi_env` holds, write the Bellman equation in the equivalent
114116form
@@ -278,7 +280,7 @@ As in {doc}`os_stochastic`, we assume that
278280This allows us to compare our results to the analytical solutions we obtained in
279281that lecture:
280282281-```{code-cell} python3
283+```{code-cell} ipython
282284def v_star(x, α, β, μ):
283285 """
284286 True value function
@@ -303,7 +305,7 @@ For this we need access to the functions $u'$ and $f, f'$.
303305304306We use the same `Model` structure from {doc}`os_stochastic`.
305307306-```{code-cell} python3
308+```{code-cell} ipython
307309class Model(NamedTuple):
308310 u: Callable # utility function
309311 f: Callable # production function
@@ -379,7 +381,7 @@ state $x$ and $σ$, the current guess of the policy.
379381380382Here's the operator $K$, that implements the root-finding step.
381383382-```{code-cell} ipython3
384+```{code-cell} ipython
383385def K(σ: np.ndarray, model: Model) -> np.ndarray:
384386 """
385387 The Coleman-Reffett operator
@@ -402,7 +404,7 @@ def K(σ: np.ndarray, model: Model) -> np.ndarray:
402404403405Let's generate an instance and plot some iterates of $K$, starting from $σ(x) = x$.
404406405-```{code-cell} python3
407+```{code-cell} ipython
406408# Define utility and production functions with derivatives
407409α = 0.4
408410u = lambda c: np.log(c)
@@ -441,7 +443,7 @@ Here is a function called `solve_model_time_iter` that takes an instance of
441443using time iteration.
442444443445444-```{code-cell} python3
446+```{code-cell} ipython
445447def solve_model_time_iter(
446448 model: Model,
447449 σ_init: np.ndarray,
@@ -473,7 +475,7 @@ def solve_model_time_iter(
473475474476Let's call it:
475477476-```{code-cell} python3
478+```{code-cell} ipython
477479# Unpack
478480grid = model.grid
479481@@ -483,7 +485,7 @@ grid = model.grid
483485484486Here is a plot of the resulting policy, compared with the true policy:
485487486-```{code-cell} python3
488+```{code-cell} ipython
487489# Unpack
488490grid, α, β = model.grid, model.α, model.β
489491@@ -503,7 +505,7 @@ Again, the fit is excellent.
503505504506The maximal absolute deviation between the two policies is
505507506-```{code-cell} python3
508+```{code-cell} ipython
507509# Unpack
508510grid, α, β = model.grid, model.α, model.β
509511@@ -540,7 +542,7 @@ Compute and plot the optimal policy.
540542541543We define the CRRA utility function and its derivative.
542544543-```{code-cell} python3
545+```{code-cell} ipython
544546γ = 1.5
545547546548def u_crra(c):
@@ -556,7 +558,7 @@ model_crra = create_model(u=u_crra, f=f, α=α,
556558557559Now we solve and plot the policy:
558560559-```{code-cell} python3
561+```{code-cell} ipython
560562%%time
561563# Unpack
562564grid = model_crra.grid