GitHub

@@ -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

9292

x \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.

98989999

The 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).

112114113115

To see why {eq}`cpi_env` holds, write the Bellman equation in the equivalent

114116

form

@@ -278,7 +280,7 @@ As in {doc}`os_stochastic`, we assume that

278280

This allows us to compare our results to the analytical solutions we obtained in

279281

that lecture:

280282281-

```{code-cell} python3

283+

```{code-cell} ipython

282284

def v_star(x, α, β, μ):

283285

"""

284286

True value function

@@ -303,7 +305,7 @@ For this we need access to the functions $u'$ and $f, f'$.

303305304306

We use the same `Model` structure from {doc}`os_stochastic`.

305307306-

```{code-cell} python3

308+

```{code-cell} ipython

307309

class 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.

379381380382

Here's the operator $K$, that implements the root-finding step.

381383382-

```{code-cell} ipython3

384+

```{code-cell} ipython

383385

def 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:

402404403405

Let'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

408410

u = lambda c: np.log(c)

@@ -441,7 +443,7 @@ Here is a function called `solve_model_time_iter` that takes an instance of

441443

using time iteration.

442444443445444-

```{code-cell} python3

446+

```{code-cell} ipython

445447

def solve_model_time_iter(

446448

model: Model,

447449

σ_init: np.ndarray,

@@ -473,7 +475,7 @@ def solve_model_time_iter(

473475474476

Let's call it:

475477476-

```{code-cell} python3

478+

```{code-cell} ipython

477479

# Unpack

478480

grid = model.grid

479481

@@ -483,7 +485,7 @@ grid = model.grid

483485484486

Here is a plot of the resulting policy, compared with the true policy:

485487486-

```{code-cell} python3

488+

```{code-cell} ipython

487489

# Unpack

488490

grid, α, β = model.grid, model.α, model.β

489491

@@ -503,7 +505,7 @@ Again, the fit is excellent.

503505504506

The maximal absolute deviation between the two policies is

505507506-

```{code-cell} python3

508+

```{code-cell} ipython

507509

# Unpack

508510

grid, α, β = model.grid, model.α, model.β

509511

@@ -540,7 +542,7 @@ Compute and plot the optimal policy.

540542541543

We define the CRRA utility function and its derivative.

542544543-

```{code-cell} python3

545+

```{code-cell} ipython

544546

γ = 1.5

545547546548

def u_crra(c):

@@ -556,7 +558,7 @@ model_crra = create_model(u=u_crra, f=f, α=α,

556558557559

Now we solve and plot the policy:

558560559-

```{code-cell} python3

561+

```{code-cell} ipython

560562

%%time

561563

# Unpack

562564

grid = model_crra.grid

Read the original on github.com ↗