Skip to content

[ak2, ak_aiyagari, two_computation] Correct math and economics, add exercises - #1078

Merged
mmcky merged 3 commits into
mainfrom
tom_olg
Oct 9, 2026
Merged

mmcky merged 3 commits into
mainfrom
tom_olg

Conversation

@mmcky

@mmcky mmcky commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

ak2:

  • Fix marginal product of capital, the dating of debt in the capital transition law, and the old-age lump sum tax in the young person's problem (text disagreed with the code in each case)
  • Correct the claim about who bears the cost of government asset accumulation: the initial old are unaffected, while the cohorts young at t=0,1 lose; state G_0 = 0 in Experiment 3, as the code does
  • Present the closed-form steady state as the zero-debt case
  • Add Overview heading, notebook header, label, and style fixes; drop globals from the plotting methods

ak_aiyagari:

  • Widen the asset grid from 10 to 40: at 10, 30% of the population was pinned at the upper bound, understating K by ~30% and overstating r by ~190 basis points
  • Weight age-specific transfers by population share in the government budget constraint, and show the 1/J weights in the text
  • Add iteration caps to find_ss and path_iteration, which could loop forever
  • State the borrowing constraint, no depreciation, and the absence of retirement; rewrite both experiment narratives so that the debt path is the policy and the anticipation effect works through the after-tax rate

two_computation:

  • Replace the certainty-equivalence claim, which contradicted the risk-sensitive preferences, and explain what sigma < 0 does
  • Replace asserted welfare rankings with computed newborn welfare, and add a summary table of the four scenarios
  • Document the calibration consistency between the two price regimes and the funded debt target
  • Add market clearing to the equilibrium definition, the per-capita resource constraint, GDP, the labor-tax term in the compensation formula, a notation table, and concluding remarks
  • Remove dead and broken code; normalize figure labels

Each lecture gains three exercises with dropdown solutions.

thanks @thomassargent30

…xercises

ak2:
- Fix marginal product of capital, the dating of debt in the capital
  transition law, and the old-age lump sum tax in the young person's
  problem (text disagreed with the code in each case)
- Correct the claim about who bears the cost of government asset
  accumulation: the initial old are unaffected, while the cohorts young
  at t=0,1 lose; state G_0 = 0 in Experiment 3, as the code does
- Present the closed-form steady state as the zero-debt case
- Add Overview heading, notebook header, label, and style fixes; drop
  globals from the plotting methods

ak_aiyagari:
- Widen the asset grid from 10 to 40: at 10, 30% of the population was
  pinned at the upper bound, understating K by ~30% and overstating r by
  ~190 basis points
- Weight age-specific transfers by population share in the government
  budget constraint, and show the 1/J weights in the text
- Add iteration caps to find_ss and path_iteration, which could loop
  forever
- State the borrowing constraint, no depreciation, and the absence of
  retirement; rewrite both experiment narratives so that the debt path is
  the policy and the anticipation effect works through the after-tax rate

two_computation:
- Replace the certainty-equivalence claim, which contradicted the
  risk-sensitive preferences, and explain what sigma < 0 does
- Replace asserted welfare rankings with computed newborn welfare, and
  add a summary table of the four scenarios
- Document the calibration consistency between the two price regimes and
  the funded debt target
- Add market clearing to the equilibrium definition, the per-capita
  resource constraint, GDP, the labor-tax term in the compensation
  formula, a notation table, and concluding remarks
- Remove dead and broken code; normalize figure labels

Each lecture gains three exercises with dropdown solutions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The changes are extensive content/math revisions with substantial new executable exercise code whose numeric claims and successful notebook execution cannot be fully verified without running the full build, so final human review is warranted.

1 open finding
What changed in this PR

This PR revises three QuantEcon lecture files (ak2.md, ak_aiyagari.md, two_computation.md) to correct mathematical and economic inaccuracies, reconcile the prose with the executed code, and add three worked exercises (with dropdown solutions) to each lecture. These are MyST-markdown lectures whose code cells are executed during the Jupyter Book build, so correctness of the new code matters for CI.

I verified the key corrections against the surrounding code and confirmed they are consistent:

  • ak2.md: the firm FOC r_t = α K^{α-1} L^{1-α} matches K_to_r; the debt term in the capital law is correctly dated D_{t+1}; δ_{o,t+1} dating and the Lagrangian sign flip are consistent; the new exercises call closed.simulate/ak2.simulate with valid signatures and existing globals (τ_hat, Cy_hat, K_to_r, etc.).
  • ak_aiyagari.md: the 1/J weighting in the prose now matches find_τ and compute_aggregates; the a_max 10→40 change and the iteration caps are consistent; the extra i return value from find_ss is appended last, so all existing slices/indexing (ss1[:3], ss1[9], ss1[-1]) remain valid.
  • two_computation.md: operator renames (𝒯_t, 𝒟_t, 𝒮_t) are consistent and disambiguated from T_t(s) taxes; the σ=0 certainty-equivalence discussion is handled in solve_riccati_step; removed dead code (buyout_compensation_exp1_exo, age_mask/ε_masked) has no remaining references; the new GDP/resource-constraint equations match _compute_gdp.

Changes:

  • Corrected math/economics (marginal products, debt dating, lump-sum tax dating, cohort incidence) to agree with the code across all three lectures.
  • Widened the Aiyagari asset grid and added 1/J population weighting and iteration caps to avoid non-convergence.
  • Added notation/summary tables, computed welfare rankings, concluding remarks, and three exercises per lecture.
File Description
lectures/​ak2.md Fixes firm FOC, debt/δ dating, steady-state closed form; adds overview/header and three steady-state/transition exercises
lectures/​ak_aiyagari.md Adds 1/J weighting, widens asset grid to 40, adds iteration caps and new return value, rewrites experiment narratives, adds three exercises
lectures/​two_computation.md Replaces certainty-equivalence claim, adds notation/GDP/market-clearing content and computed welfare, removes dead code, normalizes labels, adds three exercises

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lectures/two_computation.md Outdated
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-1078--sunny-cactus-210e3e.netlify.app

Commit: b90a47b

📚 Changed Lectures


Build Info

@mmcky mmcky left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thomassargent30, this is a big improvement to all three lectures. I checked every number quoted in the new exercises and concluding remarks against the executed outputs in the preview build and they all agree, and the corrected formulas (marginal product of capital, the dating of debt and of the old-age lump sum tax, the 1/J weights, the compensation formula) now match what the code computes. The build is green.

I found a few small things in the text that I'd suggest fixing before we merge. I'm happy to push these to the branch myself if you'd like; just say the word.

1. Explanation of the newborn welfare ranking in two_computation. The welfare table is computed from the fixed-price terminal steady states (exp1_exo and exp2_exo), where the wage is held at $w = 5.0147$ by assumption. So the sentence "A newborn prefers either reform to the pay-as-you-go system that we started from, because both reforms raise the capital stock and hence wages" cannot be the reason, and the same wage argument appears in the Exercise 3 solution. Under fixed prices the newborn gains because the labor tax falls from $0.34$ to $0.08$ (buy-out) or $0.14$ (government funding). Government funding then wins despite its higher labor tax because the retained benefits are worth more to a newborn than the extra tax costs. I'd suggest rewording both passages along those lines, or alternatively computing the welfare table from the endogenous-price steady states, where the wage argument does hold.

2. Compensation formula in Step 4 of Experiment 1 (two_computation). The new formula writes the labor-tax term as $w,\varepsilon_{t+j}(\tau_{\ell,1} - \tau_{\ell,0})$ for every $j$. The code in _compute_compensation uses the dated tax path, so a cohort that is still alive after $s_2$ is compensated at $\tau_{\ell,2} - \tau_{\ell,0}$ in those later terms. Writing the term as $w,\varepsilon_{t+j}\left(\tau_\ell(s+j) - \tau_{\ell,0}\right)$ would match the code exactly.

3. Copilot's comment is right. The sentence "Passing compensation_data to find_transition_exo turns the buy-out on, since it sets comp_mult to one inside apply_compensation" misattributes where comp_mult is set. It is set to one inside find_transition_exo when compensation_data is passed, and apply_compensation only receives it as an argument.

4. Cross-references to the social security experiment. Exercise 3 in ak2 says it complements "the transition computed in {ref}exp-tax-cut", which is Experiment 1 (the tax cut). It complements Experiment 4, the unfunded social security system, which currently has no label. Exercise 3 in ak_aiyagari has the same problem: its link text says "Experiment 4 of the two-period model" but the target is the top of the ak2 lecture. Adding a label such as (exp-social-security)= above Experiment 4 in ak2 and pointing both references there would fix both.

One note for the record rather than a change request: widening the asset grid to $a_{\max} = 40$ shifts every downstream number in ak_aiyagari (steady-state capital goes from about $6.6$ to $9.5$), so the published lecture's figures will all change. That is the intended correction and the exercise makes a convincing case for it.

mmcky and others added 2 commits October 9, 2026 11:23
two_computation:
- Explain the newborn welfare ranking in terms of the labor tax rate
  and retained benefits, since the compared steady states hold the
  wage fixed
- Date the labor-tax term in the compensation formula as τ_ℓ(s+j) to
  match _compute_compensation
- Attribute the setting of comp_mult to find_transition_exo

ak2, ak_aiyagari:
- Add an exp-social-security label to Experiment 4 and point the
  exercise cross-references there instead of at the tax cut or the
  top of the lecture

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Lowercase the headings of Experiments 2 and 3 in ak2 to match
  Experiments 1 and 4
- Lowercase axis labels in two_computation (figure rule 6)
- Replace embedded titles on single-panel figures with mystnb captions
  in ak2 and ak_aiyagari, and drop the duplicate title on the already
  captioned population figure in two_computation (figure rule 1)
- Make the capital-stock zoom plot in ak_aiyagari data-driven: its
  y-limits and annotation were hardcoded around the old steady-state
  capital of 6.6, so after the asset-grid change the figure was empty
- Collapse runs of spaces in narrative text (writing rule 008)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mmcky

mmcky commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a style-guide pass in b90a47b: lowercase headings and axis labels, mystnb captions in place of embedded titles on single-panel figures, and collapsed double spaces in narrative text. One change goes beyond style: the capital-stock zoom plot in ak_aiyagari had its y-limits and the "tax cut" annotation hardcoded around the old steady-state capital of about 6.6, so after the asset-grid change the preview rendered an empty axis. The limits are now computed from the plotted path.

@mmcky

mmcky commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python.zh-cn
Translation PR: QuantEcon/lecture-python.zh-cn#290
Files synced (3):

  • lectures/ak2.md
  • lectures/ak_aiyagari.md
  • lectures/two_computation.md

mmcky added a commit that referenced this pull request Oct 9, 2026
…ources (#1083)

The publish-2026oct09 run deployed the 5 October build cache unchanged:
its HTML step logged "no targets are out of date" and wrote nothing,
and the release tarball's ak2.html lacks the content merged in #1078.
Sphinx's HTML builder rewrites a page only when its source is newer
than the existing output file, and the cache artifact is extracted
after the checkout, so every cached page looks newer than its source.

Remove _build/html and _build/.doctrees after the cache download, as
ci.yml already does for .doctrees. Notebook execution stays cached in
_build/.jupyter_cache, so this costs only the HTML render.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants