rational_expectations#
Series: lecture-python.myst
File:
lectures/rational_expectations.mdAudit date: 2026-08-26
Corpus snapshot:
e25fdf2345Categories audited: writing, math, code, figures, references, links, admonitions (JAX out of scope)
Overall score: 7.9 / 10
Priority: HIGH
Score breakdown#
Category |
Score |
One-line note |
|---|---|---|
Writing |
3.5/10 |
|
Math |
5/10 |
|
Code |
7.5/10 |
|
JAX |
out of scope |
JAX rules target |
Figures |
10/10 |
no mechanical violations detected. |
References |
9/10 |
|
Links |
10/10 |
no mechanical violations detected. |
Admonitions |
10/10 |
no mechanical violations detected. |
Issues#
Critical#
None found.
High severity#
[qe-code-001] (reviewer) — Follow PEP8 unless closer to mathematical notation. Count: 5. Lines: 795, 684, 686, 685, 693. Example: flake8 finds one thing (E226 at 685,
a1/2anda0/2tight inside a list literal, where the same matrix at 879 is writtena1 / 2,-a0 / 2), and the rest is what a linter cannot see. 795 is a bug:print('f(h0, h1, h2) = {h0}, {h1}, {h2}')puts thefinside the quotes, so the line prints the literal textf(h0, h1, h2) = {h0}, {h1}, {h2}- and it sits directly under 794, which is a correct f-string. 684 sets a shape by assignment,B.shape = 3, 1, where the two later cells build the same object properly (B = np.array([[1], [0]])at 878 and 940). 686, 880 and 942 write the same quantity three ways -Q = 0.5 * γ,Q = γ / 2,Q = γ / 2- against \(Q = \gamma/2\) in the algebra at 640 and 855. And 693-698 routes two f-strings throughout1andout2before printing them, where 794 prints directly. Separately, the cell language isipythonin the three setup cells (33, 69, 76) andpython3in the four solution cells (667, 776, 874, 938).[qe-math-002] — Use \top for transpose notation. Count: 14. Lines: 502, 503, 511, 517, 645, 860. Example: apostrophe transpose
Y'.[qe-writing-002] (reviewer) — Keep writing clear, concise, and valuable. Count: 5. Lines: 49, 973, 800, 258, 233. Example: five sentences are broken as written. 49 loses its parenthesis and its number agreement at once: “a setting that is readily “Bellmanized” (i.e., susceptible to being formulated as a dynamic programming problems.” - the opening bracket is never closed and “a … problems” does not agree. The footnote at 973-981 is three sentences in one paragraph (the file’s only qe-writing-001 hit) and its last sentence has no main verb: “conditions under which collections of adaptive agents who use least squares learning to converge to a rational expectations equilibrium”. 800 says “the answer is pair (iii)” where the candidates at 741-743 are an unnumbered bullet list, so there is no pair (iii) to point at. 258 (“While it faces no uncertainty, it does face adjustment costs”) has no full stop. And “equilibrium” is misspelled twice - “Competitive Equilbrium” in the
{index}entry at 233 and “in equilbrium” at 395.[qe-writing-006] — Capitalize lecture titles properly. Count: 1. Lines: 202. Example: H3 Title Case: ‘Further Reading’ (Reading).
[qe-writing-008] — Remove excessive whitespace between words. Count: 30. Lines: 44, 49, 53, 86, 103, 104, 108, 112, 180, 215, …. Example: 2 spaces.
Medium severity#
[qe-math-009] (reviewer) — Choose simplicity in mathematical notation. Count: 4. Lines: 503, 343, 976, 90. Example: four small notational inconsistencies, each a choice between two forms where the file already uses both. (1) 503 writes the quadratic term as
{a_1 \over 2} Y^2- plain-TeX\over- while every other fraction in the lecture is\frac, including the one three characters later in the same display (\frac{\gamma (Y' - Y)^2}{2}) and at 273, 327, 344, 479 and 906. (2) 343 hand-sets\textrm{argmax}where the series provides an\argmaxmacro (lectures/_config.yml:110), so the operator is upright but not spaced as an operator. (3) \(\gamma\) is the adjustment-cost parameter throughout (273, 280, 327, 376, 479) and then, in the footnote at 976-977, the relaxation parameter of the modified mapping \(\gamma\Phi + (1-\gamma)I\) - two meanings, one of them introduced with the words “\(\gamma \in (0,1)\) is a relaxation parameter” directly under a lecture in which \(\gamma = 10\). (4) The differential is spelled three ways:d \, \omega(90, 92),d \omega(127, 251, 296) andd\omega(720-721). Related: \(s\) is the integration variable in \(\int_0^Y (a_0 - a_1 s)\,ds\) (183) and the surplus function \(s(Y_t, Y_{t+1})\) at 478, and \(x\) is the integration variable at 479 and the LQ state vector at 616.[qe-writing-001] — Use one sentence per paragraph. Count: 1. Lines: 973. Example: 3 sentences in one paragraph.
[qe-writing-003] (reviewer) — Maintain logical flow. Count: 4. Lines: 236, 183, 202, 314. Example: (1) The lecture cannot decide whether there are \(n\) firms or a unit measure of them, and the two conventions are interleaved. 86 and 127 set a unit measure, \(\Omega = [0,1]\) and \(Y = \int_0^1 y(\omega)d\omega\); 152 then warns the reader “not to set \(Y = n y\)” with \(n\) undefined; 236 opens the dynamic model with “a collection of \(n\) firms” and 251 immediately writes \(Y_t = \int_0^1 y_t(\omega)d\omega = y_t\); the exercise-1 solution works “the case \(n > 1\)” at 707-714 and “the case of a unit measure” at 716-725, giving two different answers; and 761-765 writes the aggregate law as \(Y_{t+1} = n h(Y_t/n, Y_t)\) before saying “we can use \(Y_t = n y_t = y_t\)”, which quietly sets \(n = 1\). (2) 183 mistypes the consumer-surplus formula as \(a_o Y - \frac{a_1}{2}Y^2\) - a letter
owhere the subscript zero belongs - in the display that{eq}`staticY`is derived from three lines later. (3) §“Further Reading” (202-208) is an H3 sitting inside the Overview, between the static example and the model, so the reader meets the reading list before meeting the problem; it belongs at the end. (4) 314 introduces \(Y^e_{t+1}\) for perceived output and never uses it again.[qe-writing-005] (reviewer) — Use bold for definitions, italic for emphasis. Count: 4. Lines: 42, 56, 82, 977. Example: the file bolds most of its definitions - representative firm (82), consumer surplus (180), belief function (312), Euler equation (371), transversality condition (384), actual law of motion (395), rational expectations equilibrium and recursive competitive equilibrium (409), planning problem (484) - but three of its central terms are marked twice, differently. rational expectations equilibrium is italic where it is first named (42, “This lecture introduces the concept of a rational expectations equilibrium”) and bold where it is defined (409). perceived law of motion and actual law of motion are italic at 56 and the second is bold at 395. And representative firm is bold at 82 in a sentence that puts the companion term in quotation marks (
is a "price taker"), which 148 then sets in italic (we want the firm to be a *price taker*) - three markings, no bold. 977 introduces the relaxation parameter in italic, which is a definition.[qe-writing-007] (reviewer) — Use visual elements to enhance understanding. Count: 4. Lines: 70, 418, 741, 952. Example: a 981-line lecture built around a fixed point, with
import matplotlib.pyplot as pltat 70 and not oneplt.call anywhere in the file - the Figures category scores 10/10 because there is nothing to check. Four places pay for it. (1) The mapping \(\Phi\) from a perceived law of motion to an actual one (418-424) is the concept the lecture exists to teach, and §“Failure of contractivity” (433-447) argues that \(\Phi\) reverses the ordering of beliefs - “suppose there are two beliefs with \(H_a(Y) > H_b(Y)\) for every \(Y\) … \(\Phi\) reverses the ordering” - which is one 45-degree diagram of \(\kappa_1 \mapsto \Phi(\kappa)_1\) with two iterates marked, and is left entirely to prose. (2) Exercise 2 tests three candidate \((\kappa_0, \kappa_1)\) pairs (741-743) and the solution reports only which one passesnp.allclose(793-800); the residual \(h_0 + h_1 + h_2 - \kappa_1\) plotted over a \(\kappa_1\) grid would show that the equilibrium is a crossing and would connect directly to the order reversal of 445. (3) Exercise 4’s conclusion is handed to the reader as arithmetic homework - “If you crunch the numbers, you will see that the monopolist adopts a lower long-run quantity” (964-966) - when the two laws of motion it just computed, \(Y_{t+1} = 73.4729 + 0.9265 Y_t\) and \(Y_{t+1} = 95.0818 + 0.9525 Y_t\), drawn against the 45-degree line, would put both fixed points on one axes. (4) The static example of 110-176, where the whole Big-\(Y\)-little-\(y\) trick is introduced, has an inverse demand curve, a cost curve, consumer surplus as “the area under the inverse demand curve” (180) and a planning problem (190-198) - four objects that live naturally in a single supply-and-demand picture that is never drawn.
Low severity#
[qe-ref-001] — Use correct citation style. Count: 1. Lines: 978. Example:
{cite}in narrative flow: ‘and{cite}’.
Strengths#
The Big \(Y\), little \(y\) trick is taught twice, once in a static model where the whole argument fits in twenty lines (110-176) and then in the dynamic one, and both times the lecture says exactly where the substitution must not happen: “The essence of the Big \(Y\), little \(y\) trick is not to set \(Y = n y\) before taking the first-order condition” (152-153), then “At this point, but not before, we substitute \(Y = y\)” (165).
The equivalence at the heart of the lecture is verified rather than asserted, and in two independent ways: 529-543 shows by hand that the planner’s Euler equation
{eq}`comp16`and the firm’s{eq}`ree_comp7`are the same difference equation once \(y_t = Y_t\) and \(H(Y_t) = Y_{t+1}\) are imposed, and then exercise 3 computes \((\kappa_0, \kappa_1)\) from the planner’s LQ problem (874-891) and gets the pair that exercise 2 identified as the equilibrium from the firm’s problem (777-797).The failure of contractivity is explained by a mechanism rather than waved at: 443-447 supposes two ordered beliefs, notes that by the Euler equation the actual law decreases as \(H\) increases, and concludes that \(\Phi\) reverses the ordering so Blackwell’s monotonicity fails - three sentences that say why the obvious algorithm is not available.
Nearly every displayed equation is labelled and the labels are genuinely used:
ree_comp3d_staticat 140 and 176,max_problem_staticat 148, 153 and 157,BigYsimpleFONCat 165,staticYat 174, 196 and 198,ree_comp3dat 292 and 903,ree_hlomat 318, 379, 403 and 600,comp4at 363, 388, 422 and 566,ree_opbeat 388 and 422,ree_comp7at 379, 386, 389, 445 and 531,comp10at 494,comp12at 545,comp14at 520,comp16at 535,ree_hlom2at 579 and 588,ree_ex5at 575, 598, 600 and 605.The
{prf:definition}at 408-414 is short, numbered and states both halves of the fixed point (“Given belief \(H\), the map \(h\) is the firm’s optimal policy function” / “\(H(Y) = h(Y,Y)\) for all \(Y\)”), and 416 immediately translates it back into the language of perceived versus actual laws of motion.The four exercises build one on another rather than sitting side by side: ree_ex1 sets up the firm’s LQ problem, ree_ex2 extends that program to test candidate equilibria, ree_ex3 solves the planner’s problem and compares with ree_ex2, and ree_ex4 changes one matrix entry (\(a_1/2 \to a_1\), 930-934) to turn the planner into a monopolist - so the last exercise’s economics comes out of a one-character difference in \(R\).
Each solution states the mapping between the LQ output and the model’s parameters explicitly before computing anything - \(h_0 = -F_2\), \(h_1 = 1 - F_0\), \(h_2 = -F_1\) (662), \(\kappa_0 = -F_1\), \(\kappa_1 = 1 - F_0\) (870) - and 643-646 and 858-861 both invite the reader to multiply out \(x_t' R x_t + u_t' Q u_t\) and check it equals the negative of the period return.
The envelope step is attributed and used consistently: 361-363 names Benveniste-Scheinkman
{cite}`BenvenisteScheinkman1979`for differentiating the right side of{eq}`comp4`naively, and 514 then says “Applying the same Benveniste-Scheinkman formula” for the planner’s problem rather than re-deriving it.The footnote at 973-981 is well placed: it hangs off the sentence that says direct iteration on \(\Phi\) may diverge (439) and points to the relaxation-parameter literature (
{cite}`MarcetSargent1989`,{cite}`EvansHonkapohja2001`) that studies when adaptive agents converge, which is exactly the reader’s next question.
Recommended actions#
Write the two genuine transposes with
^\top:$x_t' R x_t + u_t' Q u_t$at 645 and 860 becomes$x_t^\top R x_t + u_t^\top Q u_t$. This is the whole qe-math-002 finding - I verified that after these two editscheck_math_002reports zero hits for the file, down from 14, because the sixY'hits at 502-517 are false positives that only count while the file supplies transpose evidence elsewhere (see scanner_doubts). Math should be 10/10 once this is done.Settle \(n\) against the unit measure. 86, 127 and 251 set a unit measure; 152 warns against \(Y = ny\); 236 says “\(n\) firms”; 707-714 and 761-765 carry an \(n\) that 764 then sets to 1. Either restore \(n\) firms throughout or delete the \(n\) passages - as it stands the exercise-1 solution answers the question twice with two different laws of motion (713 and 723).
Fix
a_oat 183 (letterofor subscript zero) in the consumer-surplus formula that{eq}`staticY`is derived from, and the two misspellings of “equilibrium” at 233 (inside the{index}entry) and 395.Fix the print at 795: the
fis inside the quotes, so the line emitsf(h0, h1, h2) = {h0}, {h1}, {h2}literally instead of the values. The correct form is on the line above it.Repair the two broken sentences: 49 (“susceptible to being formulated as a dynamic programming problems.” - unclosed parenthesis, plural after “a”) and the footnote’s final sentence at 978-981, which has no main verb. Add the full stop at 258 and renumber or re-letter the candidate pairs at 741-743 so 800’s “pair (iii)” refers to something.
Draw something. The lecture imports matplotlib at 70 and never uses it, and the three figures it most needs are cheap: \(\Phi\) on a 45-degree diagram for §“Failure of contractivity” (433-447), the equilibrium residual over a \(\kappa_1\) grid for exercise 2 (741-743), and the monopolist’s and competitive laws of motion with their fixed points for exercise 4 (952-966). If none is added, drop the unused import.
Move §“Further Reading” (202-208) to the end of the lecture; it currently interrupts the Overview between the static example and the model.
Pick one marking per term: rational expectations equilibrium is italic at 42 and bold at 409, the two laws of motion are italic at 56 and bold at 395, and “price taker” is quoted at 82 and italic at 148. Bold the relaxation parameter definition at 977.
Clear the 30 double spaces (qe-writing-008 x30 - 44, 49, 53, 86, 103-112, 180, 215 and on), and sentence-case the H3 at 202,
### Further Reading->### Further reading(the single qe-writing-006 hit, genuine).The single qe-ref-001 hit is at 978 and is genuine: “See
{cite}`MarcetSargent1989`and{cite}`EvansHonkapohja2001`for statements and applications” reads the citations as sentence constituents, so both want{cite:t}. Two more that the checker cannot see should be cited the same way: “a model due to Lucas and Prescott{cite}`Lucas_Prescott_1971`” (44-45) and “Lucas and Prescott{cite}`Lucas_Prescott_1971`used this method” (454) both name the authors in prose and cite them parenthetically, printing the surnames twice.Code tidying: build
Bwith a literal rather thanB.shape = 3, 1(684), write \(Q = \gamma/2\) the same way in all three cells (686, 880, 942), spacea1 / 2and-a0 / 2at 685 to match 879, print directly at 693-698 instead of viaout1/out2, and settle the cell language, which isipythonat 33, 69 and 76 andpython3at 667, 776, 874 and 938.Replace
\textrm{argmax}at 343 with the\argmaxmacro,{a_1 \over 2}at 503 with\frac{a_1}{2}, rename the footnote’s relaxation parameter so it is not \(\gamma\) (976-977), and settled\omegaon one spelling (90, 92, 127, 251, 296, 720-721).