Skip to content

Commit 1c36e05

Browse files
AakashGfudemmcky
andauthored
update sources lecture-python (9ae923d) using tomyst (b06cacb) (#86)
* update sources lecture-python (9ae923d) using tomyst (b06cacb) * newline bug Co-authored-by: mmcky <[email protected]>
1 parent de18ce8 commit 1c36e05

17 files changed

+129
-125
lines changed

lectures/cass_koopmans_2.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ all other dates $t=1, 2, \ldots, T$.
195195
There are sequences of prices
196196
$\{w_t,\eta_t\}_{t=0}^T= \{\vec{w}, \vec{\eta} \}$
197197
where $w_t$ is a wage or rental rate for labor at time $t$ and
198-
$eta_t$ is a rental rate for capital at time $t$.
198+
$\eta_t$ is a rental rate for capital at time $t$.
199199

200200
In addition there is are intertemporal prices that work as follows.
201201

@@ -397,7 +397,7 @@ verify** approach.
397397
In this lecture {doc}`Cass-Koopmans Planning Model <cass_koopmans_1>`, we computed an allocation $\{\vec{C}, \vec{K}, \vec{N}\}$
398398
that solves the planning problem.
399399

400-
(This allocation will constitute the **Big** $K$ to be in the present instance of the *Big** $K$ **, little** $k$ trick
400+
(This allocation will constitute the **Big** $K$ to be in the present instance of the **Big** $K$ **, little** $k$ trick
401401
that we'll apply to a competitive equilibrium in the spirit of [this lecture](https://lectures.quantecon.org/py/rational_expectations.html#)
402402
and [this lecture](https://lectures.quantecon.org/py/dyn_stack.html#).)
403403

@@ -893,7 +893,7 @@ Vice-versa for lower $\gamma$.
893893

894894
We return to Hicks-Arrow prices and calculate how they are related to **yields** on loans of alternative maturities.
895895

896-
This will let us plot a **yield curve** that graphs yields on bonds of maturities $j=1, 2, \ldots$ against :math:j=1,2, ldots`.
896+
This will let us plot a **yield curve** that graphs yields on bonds of maturities $j=1, 2, \ldots$ against $j=1,2, \ldots$.
897897

898898
The formulas we want are:
899899

lectures/exchangeable.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ that are
5353
Understanding the distinction between these concepts is essential for appreciating how Bayesian updating
5454
works in our example.
5555

56-
You can read about exchangeability [here](https://en.wikipedia.org/wiki/Exchangeable_random_variables)
56+
You can read about exchangeability [here](https://en.wikipedia.org/wiki/Exchangeable_random_variables).
5757

5858
Below, we'll often use
5959

@@ -116,8 +116,10 @@ $$
116116
Using the laws of probability, we can always factor such a joint density into a product of conditional densities:
117117

118118
$$
119-
p(W_T, W_{T-1}, \ldots, W_1, W_0) = & p(W_T | W_{t-1}, \ldots, W_0) p(W_{T-1} | W_{T-2}, \ldots, W_0) \cdots \cr
120-
& p(W_1 | W_0) p(W_0)
119+
\begin{align}
120+
p(W_T, W_{T-1}, \ldots, W_1, W_0) = & p(W_T | W_{T-1}, \ldots, W_0) p(W_{T-1} | W_{T-2}, \ldots, W_0) \cdots \cr
121+
& \quad \quad \cdots p(W_1 | W_0) p(W_0)
122+
\end{align}
121123
$$
122124

123125
In general,
@@ -178,7 +180,7 @@ $G$ with probability $1 - \tilde \pi$.
178180
Thus, we assume that the decision maker
179181

180182
- **knows** both $F$ and $G$
181-
- **doesnt't know** which of these two distributions that nature has drawn
183+
- **doesn't know** which of these two distributions that nature has drawn
182184
- summarizing his ignorance by acting as if or **thinking** that nature chose distribution $F$ with probability $\tilde \pi \in (0,1)$ and distribution
183185
$G$ with probability $1 - \tilde \pi$
184186
- at date $t \geq 0$ has observed the partial history $w_t, w_{t-1}, \ldots, w_0$ of draws from the appropriate joint
@@ -480,9 +482,9 @@ learning_example()
480482
```
481483

482484
Please look at the three graphs above created for an instance in which $f$ is a uniform distribution on $[0,1]$
483-
(i.e., a Beta distribution with parameters $F_a=1, F_b=1$, while $g$ is a Beta distribution with the default parameter values $G_a=3, G_b=1.2$.
485+
(i.e., a Beta distribution with parameters $F_a=1, F_b=1$), while $g$ is a Beta distribution with the default parameter values $G_a=3, G_b=1.2$.
484486

485-
The graph on the left plots the likehood ratio $l(w)$ on the coordinate axis against $w$ on the ordinate axis.
487+
The graph on the left plots the likelihood ratio $l(w)$ on the coordinate axis against $w$ on the ordinate axis.
486488

487489
The middle graph plots both $f(w)$ and $g(w)$ against $w$, with the horizontal dotted lines showing values
488490
of $w$ at which the likelihood ratio equals $1$.
@@ -491,7 +493,7 @@ The graph on the right plots arrows to the right that show when Bayes' Law make
491493
to the left that show when Bayes' Law make $\pi$ decrease.
492494

493495
Notice how the length of the arrows, which show the magnitude of the force from Bayes' Law impelling $\pi$ to change,
494-
depend on both the prior probability $\pi$ on the ordinate axis and the evidence in the form of the current draw of
496+
depends on both the prior probability $\pi$ on the ordinate axis and the evidence in the form of the current draw of
495497
$w$ on the coordinate axis.
496498

497499
The fractions in the colored areas of the middle graphs are probabilities under $F$ and $G$, respectively,
@@ -528,7 +530,7 @@ assumptions about nature's choice of distribution:
528530
- that nature permanently draws from $G$
529531

530532
Outcomes depend on a peculiar property of likelihood ratio processes that are discussed in
531-
[this lecture](https://python-advanced.quantecon.org/additive_functionals.html)
533+
[this lecture](https://python-advanced.quantecon.org/additive_functionals.html).
532534

533535
To do this, we create some Python code.
534536

lectures/finite_markov.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,22 +1218,23 @@ Let $F$ be the cumulative distribution function of the normal distribution $N(0,
12181218
The values $P(x_i, x_j)$ are computed to approximate the AR(1) process --- omitting the derivation, the rules are as follows:
12191219

12201220
1. If $j = 0$, then set
1221-
1222-
$$
1223-
P(x_i, x_j) = P(x_i, x_0) = F(x_0-\rho x_i + s/2)
1224-
$$
1225-
1221+
1222+
$$
1223+
P(x_i, x_j) = P(x_i, x_0) = F(x_0-\rho x_i + s/2)
1224+
$$
1225+
12261226
1. If $j = n-1$, then set
1227-
1228-
$$
1229-
P(x_i, x_j) = P(x_i, x_{n-1}) = 1 - F(x_{n-1} - \rho x_i - s/2)
1230-
$$
1231-
1227+
1228+
$$
1229+
P(x_i, x_j) = P(x_i, x_{n-1}) = 1 - F(x_{n-1} - \rho x_i - s/2)
1230+
$$
1231+
12321232
1. Otherwise, set
1233-
1234-
$$
1235-
P(x_i, x_j) = F(x_j - \rho x_i + s/2) - F(x_j - \rho x_i - s/2)
1236-
$$
1233+
1234+
$$
1235+
P(x_i, x_j) = F(x_j - \rho x_i + s/2) - F(x_j - \rho x_i - s/2)
1236+
$$
1237+
12371238

12381239
The exercise is to write a function `approx_markov(rho, sigma_u, m=3, n=7)` that returns
12391240
$\{x_0, \ldots, x_{n-1}\} \subset \mathbb R$ and $n \times n$ matrix

lectures/harrison_kreps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Remember that state $1$ is the high dividend state.
175175
* In state $0$, a type $a$ agent is more optimistic about next period's dividend than a type $b$ agent.
176176
* In state $1$, a type $b$ agent is more optimistic about next period's dividend.
177177

178-
However, the stationary distributions $\pi_A = \begin{bmatrix} .57 & .43 \end{bmatrix}$ and $\pi_B = \begin{bmatrix} .43 & .57 \end{bmatrix}$ tell us that a type $B$ person is more optimistic about the dividend process in the long run than is a type A person.
178+
However, the stationary distributions $\pi_A = \begin{bmatrix} .57 & .43 \end{bmatrix}$ and $\pi_B = \begin{bmatrix} .43 & .57 \end{bmatrix}$ tell us that a type $B$ person is more optimistic about the dividend process in the long run than is a type $A$ person.
179179

180180
Transition matrices for the temporarily optimistic and pessimistic investors are constructed as follows.
181181

lectures/lake_model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ there exists an $\bar x$ such that
378378

379379
This equation tells us that a steady state level $\bar x$ is an eigenvector of $\hat A$ associated with a unit eigenvalue.
380380

381-
We also have $x_t \to \bar x$ as $t \to \infty$ provided that the remaining eigenvalue of $\hat A$ has modulus less that 1.
381+
We also have $x_t \to \bar x$ as $t \to \infty$ provided that the remaining eigenvalue of $\hat A$ has modulus less than 1.
382382

383383
This is the case for our default parameters:
384384

lectures/likelihood_bayes.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ We'll study how, at least in our setting, a Bayesian eventually learns the prob
5050
rests on the asymptotic behavior of likelihood ratio processes studied in {doc}`this lecture <likelihood_ratio_process>`.
5151

5252
This lecture provides technical results that underly outcomes to be studied in {doc}`this lecture <odu>`
53-
and {doc}`this lecture <wald_friedman>` and {doc}`this lecture <navy_captain>`
53+
and {doc}`this lecture <wald_friedman>` and {doc}`this lecture <navy_captain>`.
5454

5555
## The Setting
5656

@@ -262,7 +262,7 @@ and the initial prior $\pi_{0}$
262262
\pi_{t+1}=\frac{\pi_{0}L\left(w^{t+1}\right)}{\pi_{0}L\left(w^{t+1}\right)+1-\pi_{0}} .
263263
```
264264

265-
Formula {eq}`eq_Bayeslaw103` generalizes generalizes formula {eq}`eq_recur1`.
265+
Formula {eq}`eq_Bayeslaw103` generalizes formula {eq}`eq_recur1`.
266266

267267
Formula {eq}`eq_Bayeslaw103` can be regarded as a one step revision of prior probability $\pi_0$ after seeing
268268
the batch of data $\left\{ w_{i}\right\} _{i=1}^{t+1}$.
@@ -276,8 +276,7 @@ limiting behavior of $\pi_t$.
276276

277277
To illustrate this insight, below we will plot graphs showing **one** simulated
278278
path of the likelihood ratio process $L_t$ along with two paths of
279-
$\pi_t$ that are associated with the *same* realization of the likelihood ratio process but *different* initial prior probabilities
280-
probabilities $\pi_{0}$.
279+
$\pi_t$ that are associated with the *same* realization of the likelihood ratio process but *different* initial prior probabilities $\pi_{0}$.
281280

282281
First, we tell Python two values of $\pi_0$.
283282

@@ -374,5 +373,5 @@ $g$.
374373
This lecture has been devoted to building some useful infrastructure.
375374

376375
We'll build on results highlighted in this lectures to understand inferences that are the foundations of
377-
results described in {doc}`this lecture <odu>` and {doc}`this lecture <wald_friedman>` and {doc}`this lecture <navy_captain>`
376+
results described in {doc}`this lecture <odu>` and {doc}`this lecture <wald_friedman>` and {doc}`this lecture <navy_captain>`.
378377

lectures/lq_inventories.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ tags: [hide-output]
3535

3636
## Overview
3737

38-
This lecture can be viewed as an application of the {doc}`quantecon lecture <lqcontrol>`.
38+
This lecture can be viewed as an application of this {doc}`quantecon lecture <lqcontrol>` about linear quadratic control
39+
theory.
3940

4041
It formulates a discounted dynamic program for a firm that
4142
chooses a production schedule to balance
@@ -46,19 +47,19 @@ chooses a production schedule to balance
4647
In the tradition of a classic book by Holt, Modigliani, Muth, and
4748
Simon {cite}`Holt_Modigliani_Muth_Simon`, we simplify the
4849
firm’s problem by formulating it as a linear quadratic discounted
49-
dynamic programming problem of the type studied in this {doc}`quantecon <lqcontrol>`.
50+
dynamic programming problem of the type studied in this {doc}`quantecon lecture <lqcontrol>`.
5051

5152
Because its costs of production are increasing and quadratic in
52-
production, the firm wants to smooth production across time provided
53+
production, the firm holds inventories as a buffer stock in order to smooth production across time, provided
5354
that holding inventories is not too costly.
5455

55-
But the firm also prefers to sell out of existing inventories, a
56+
But the firm also wants to make its sales out of existing inventories, a
5657
preference that we represent by a cost that is quadratic in the
5758
difference between sales in a period and the firm’s beginning of period
5859
inventories.
5960

60-
We compute examples designed to indicate how the firm optimally chooses
61-
to smooth production and manage inventories while keeping inventories
61+
We compute examples designed to indicate how the firm optimally
62+
smooths production while keeping inventories
6263
close to sales.
6364

6465
To introduce components of the model, let
@@ -72,7 +73,7 @@ To introduce components of the model, let
7273
- $d(I_t, S_t) = d_1 I_t + d_2 (S_t - I_t)^2$, where
7374
$d_1>0, d_2 >0$, be a cost-of-holding-inventories function,
7475
consisting of two components:
75-
- a cost $d_1 t$ of carrying inventories, and
76+
- a cost $d_1 I_t$ of carrying inventories, and
7677
- a cost $d_2 (S_t - I_t)^2$ of having inventories deviate
7778
from sales
7879
- $p_t = a_0 - a_1 S_t + v_t$ be an inverse demand function for a
@@ -84,7 +85,7 @@ To introduce components of the model, let
8485
be the present value of the firm’s profits at
8586
time $0$
8687
- $I_{t+1} = I_t + Q_t - S_t$ be the law of motion of inventories
87-
- $z_{t+1} = A_{22} z_t + C_2 \epsilon_{t+1}$ be the law
88+
- $z_{t+1} = A_{22} z_t + C_2 \epsilon_{t+1}$ be a law
8889
of motion for an exogenous state vector $z_t$ that contains
8990
time $t$ information useful for predicting the demand shock
9091
$v_t$
@@ -133,17 +134,20 @@ appears in the firm’s one-period profit function)
133134
We can express the firm’s profit as a function of states and controls as
134135

135136
$$
136-
\pi_t = - (x_t' R x_t + u_t' Q u_t + 2 u_t' H x_t )
137+
\pi_t = - (x_t' R x_t + u_t' Q u_t + 2 u_t' N x_t )
137138
$$
138139

139-
To form the matrices $R, Q, H$, we note that the firm’s profits at
140+
To form the matrices $R, Q, N$ in an LQ dynamic programming problem, we note that the firm’s profits at
140141
time $t$ function can be expressed
141142

142143
$$
144+
\begin{equation}
145+
\begin{split}
143146
\pi_{t} =&p_{t}S_{t}-c\left(Q_{t}\right)-d\left(I_{t},S_{t}\right) \\
144147
=&\left(a_{0}-a_{1}S_{t}+v_{t}\right)S_{t}-c_{1}Q_{t}-c_{2}Q_{t}^{2}-d_{1}I_{t}-d_{2}\left(S_{t}-I_{t}\right)^{2} \\
145148
=&a_{0}S_{t}-a_{1}S_{t}^{2}+Gz_{t}S_{t}-c_{1}Q_{t}-c_{2}Q_{t}^{2}-d_{1}I_{t}-d_{2}S_{t}^{2}-d_{2}I_{t}^{2}+2d_{2}S_{t}I_{t} \\
146-
=&-\left(\underset{x_{t}^{\prime}Rx_{t}}{\underbrace{d_{1}I_{t}+d_{2}I_{t}^{2}}}\underset{u_{t}^{\prime}Qu_{t}}{\underbrace{+a_{1}S_{t}^{2}+d_{2}S_{t}^{2}+c_{2}Q_{t}^{2}}}\underset{2u_{t}^{\prime}Hx_{t}}{\underbrace{-a_{0}S_{t}-Gz_{t}S_{t}+c_{1}Q_{t}-2d_{2}S_{t}I_{t}}}\right) \\
149+
=&-\left(\underset{x_{t}^{\prime}Rx_{t}}{\underbrace{d_{1}I_{t}+d_{2}I_{t}^{2}}}\underset{u_{t}^{\prime}Qu_{t}}{\underbrace{+a_{1}S_{t}^{2}+d_{2}S_{t}^{2}+c_{2}Q_{t}^{2}}}
150+
\underset{2u_{t}^{\prime}N x_{t}}{\underbrace{-a_{0}S_{t}-Gz_{t}S_{t}+c_{1}Q_{t}-2d_{2}S_{t}I_{t}}}\right) \\
147151
=&-\left(\left[\begin{array}{cc}
148152
I_{t} & z_{t}^{\prime}\end{array}\right]\underset{\equiv R}{\underbrace{\left[\begin{array}{cc}
149153
d_{2} & \frac{d_{1}}{2}S_{c}\\
@@ -166,12 +170,14 @@ Q_{t} & S_{t}\end{array}\right]\underset{\equiv N}{\underbrace{\left[\begin{arra
166170
I_{t}\\
167171
z_{t}
168172
\end{array}\right]\right)
173+
\end{split}
174+
\end{equation}
169175
$$
170176

171177
where $S_{c}=\left[1,0\right]$.
172178

173179
**Remark on notation:** The notation for cross product term in the
174-
QuantEcon library is $N$ instead of $H$.
180+
QuantEcon library is $N$.
175181

176182
The firms’ optimum decision rule takes the form
177183

@@ -185,6 +191,16 @@ $$
185191
x_{t+1} = (A - BF ) x_t + C \epsilon_{t+1}
186192
$$
187193

194+
The firm chooses a decision rule for $u_t$ that maximizes
195+
196+
$$
197+
E_0 \sum_{t=0}^\infty \beta^t \pi_t
198+
$$
199+
200+
subject to a given $x_0$.
201+
202+
This is a stochastic discounted LQ dynamic program.
203+
188204
Here is code for computing an optimal decision rule and for analyzing
189205
its consequences.
190206

@@ -330,7 +346,7 @@ class SmoothingExample:
330346
Notice that the above code sets parameters at the following default
331347
values
332348

333-
- discount factor β=0.96,
349+
- discount factor $\beta=0.96$,
334350
- inverse demand function: $a0=10, a1=1$
335351
- cost of production $c1=1, c2=1$
336352
- costs of holding inventories $d1=1, d2=1$
@@ -465,7 +481,7 @@ We introduce this $I_t$ **is hardwired to zero** specification in
465481
order to shed light on the role that inventories play by comparing outcomes
466482
with those under our two other versions of the problem.
467483

468-
The bottom right panel displays an production path for the original
484+
The bottom right panel displays a production path for the original
469485
problem that we are interested in (the blue line) as well with an
470486
optimal production path for the model in which inventories are not
471487
useful (the green path) and also for the model in which, although

0 commit comments

Comments
 (0)