EEconomics, Built

Act X · The Graduate Core

Part 51 of 68

Computing Economies

Graduatestarts at this level44 min of film19 chaptersprerequisites: Part 22, Part 29, Part 30, Part 44

How is an economy that has no formula solved, and how do you know the answer is right?

The part opens on Richard Bellman's account of naming dynamic programming at RAND, a name 'not even a Congressman could object to', and on value iteration settling on the growth model of Part 29. The Bellman operator is a contraction (a cobweb, Banach's theorem, distances shrinking by beta, Blackwell's two conditions checked); Howard's policy iteration reaches the same policy in a handful of rounds by a sparse solve. The viewer chooses which of three grids reports the steady state to within 1%; interpolation, Runge's warning and Chebyshev's nodes; Carroll's endogenous grid method on Part 22's household, far faster and more accurate than value iteration; Judd's projection with its spectral convergence; perturbation to second order, and the precautionary saving that certainty equivalence cannot see. After an intermission of transistors per microprocessor since 1971, Euler-equation errors and eight methods compared; Tauchen against Rouwenhorst and quadrature against simulation; the HJB equation by Achdou et al.'s upwind scheme with its stationary distribution; the household's kink and the zero bound by guess and verify; Smolyak's sparse grids; the report, seeds and known answers of a reproducible computation; the EIS dial against method error; model teams, estimation loops, Moore's 1965 forecast as Called it?, and solvers that differentiate.

What you need. Part 22: the household's saving; Part 29: the growth model; Part 30: the zero bound; Part 44: the nested fixed point; Statistics, Built: optimization, Monte Carlo and reproducible computation.

Hook
Bellman names it "dynamic programming", 1950
Ideas, models and mathematics
the contraction mapping theorem, value and policy iteration, endogenous grids, projection and perturbation, continuous time and the HJB equation, accuracy and Euler errors, the curse of dimensionality
Agora gains
agora.solve: the solution harness
Play it
which grid is fine enough?

What you will be able to do

Principles and the major

  • Explain why repeating Bellman's equation converges, and why a coarse grid can bias an answer.
  • Read an Euler-equation error as a mistake in dollars.

Graduate

  • Solve a dynamic model by value and policy iteration, with interpolation, by the endogenous grid method, by collocation and by perturbation, and compare them by Euler errors.
  • Discretize a persistent process, compute expectations by quadrature, and solve an HJB equation by upwind finite differences.
  • Handle an occasionally binding constraint by guess and verify.

Research

  • Prove Blackwell's sufficient conditions, and derive the implicit derivative of a solution with respect to a parameter.
  • State the open problems of high-dimensional solution methods: certified accuracy, sequence-space methods, neural-network solvers.

Practice

  • Write a solution report and a replication package another team can run.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Principles and the major 13 min · Graduate 40 min · Research 44 min · Practice 18 min.

  1. 0A name nobody could object toPrinciples and the major3 min
  2. 1The Bellman operator as a contractionPrinciples and the major3 min
  3. 2Value and policy iteration, timedGraduate2 min
  4. 3Play it: which grid is fine enough?Principles and the major2 min
  5. 4Between the grid pointsGraduate3 min
  6. 5The endogenous grid methodGraduate3 min
  7. 6Projection: the rule as a polynomialGraduate2 min
  8. 7Perturbation, and when certainty equivalence misleadsGraduate2 min
  9. Intermission: transistors per microprocessor, 1971-2021Principles and the major
  10. 8Accuracy: Euler-equation errorsPrinciples and the major2 min
  11. 9Expectations: chains and quadratureGraduate2 min
  12. 10Continuous timeGraduate2 min
  13. 11Occasionally binding constraintsGraduate2 min
  14. 12The curse of dimensionalityResearch2 min
  15. 13ReproducibilityPractice3 min
  16. 14The Dials: parameters against method errorGraduate2 min
  17. 15In practice: model teams and estimationPractice2 min
  18. 16Frontier: solvers that differentiateResearch2 min
  19. Recap, problems, and the road aheadAll tracks3 min

Also on this page: Lecture · Key results · Try it · Lab · Problems · Notes and sources · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film.

A name nobody could object toPrinciples and the major3 min

In his autobiography, the mathematician Richard Bellman recalled the autumn of 1950, when he went to work at the RAND Corporation, which did research for the United States Air Force. His first task was to find a name for his mathematics of decisions made in stages. The Secretary of Defense, he wrote, had a pathological fear and hatred of the word research, and the Air Force answered to him. So Bellman chose programming, in the sense of planning, as in a military schedule, and dynamic, because the problems change over time and because, he said, it is impossible to use the word dynamic as an insult. It was, he wrote, something not even a Congressman could object to. His memory of the date has been questioned, since the Secretary he named took office only in 1953; the name stuck either way.

Seventy years on, dynamic programming is how economists solve economies that have no formula. Guess the value of being in each situation, apply Bellman's equation, and repeat. Each round the guess improves, and after 333 rounds the growth model of Part twenty-nine has settled, in a few hundredths of a second on a laptop. Inside an estimation, a model like this is solved again for every set of parameters the estimator tries, thousands of times. So speed matters; and so does a harder question.

The question: how is an economy that has no formula solved, and how do you know the answer is right? Why does repeating Bellman's equation converge at all? Which methods are fast, and which are accurate? How do you know a computed answer is right? And what breaks when the model grows?

Economics, Built. Part fifty-one: computing economies. This part opens Act ten, the graduate core: the tools that turn the models of the course into research. The Bellman operator, why it converges, and value and policy iteration. Grids, interpolation, and a method with no root finding at all. Projection and perturbation, and when certainty equivalence misleads. Accuracy, measured; expectations; and continuous time. Then constraints that bind, the curse of dimensionality, and how to make a computation that someone else can repeat.

What it does: Bellman at RAND; value iteration settling; the question; objectives

1The Bellman operator as a contractionPrinciples and the major3 min

Write the growth model as Bellman did. The value of starting a year with capital k is the best, over next year's capital, of this year's utility plus the discounted value of next year. Read the right-hand side as a machine. Put in a guess V, a value for every capital stock; the machine, the Bellman operator T, returns a new guess. The answer is the value function the machine leaves unchanged: a fixed point, V equals T of V. The model is the one of Part twenty-nine: utility with an elasticity of substitution of a half, a capital share of 0.36, eight percent depreciation, and a discount factor of 0.96.

Why should repeating the machine settle anywhere? Draw a machine on a line, a cartoon of T. The dashed diagonal is where the answer equals the guess. The purple line is the machine: it maps each guess to an answer, and it is flatter than the diagonal, so it brings any two guesses closer together. That is a contraction. Start anywhere, apply it, apply it again: the steps walk in to the one point where the line meets the diagonal. Stefan Banach proved in 1922 that a contraction on a complete space has exactly one fixed point, and that iterating from any start reaches it. The Bellman operator is such a machine, on the space of value functions.

On the real model, measure it. Each round, record how far the new value function is from the old, at the worst capital stock, on a log scale. After a few rounds the points fall on a straight line, and its slope is the discount factor: each round the change shrinks by a factor of 0.960, exactly the 0.96 the theory promises. That also says how long it will take: to shrink the change a million times needs about three hundred and thirty-eight rounds, and it took 333. Patience is expensive: with a discount factor of 0.99, as in quarterly models, it would take four times as many.

How do we know the Bellman operator is a contraction without proving it from scratch each time? David Blackwell gave two conditions in 1965 that are easy to check. Monotonicity: if one guess of the future is everywhere better than another, the operator's answers keep that order. A better future never makes today worse. Discounting: add the same amount to every future value, and today's value rises by only beta times that amount. Both are checked here on random guesses: the order is kept, and the discounting holds to the last digits a computer carries. Together they make T a contraction with modulus beta, so the value function exists, is unique, and iteration finds it. The rest of this part is about doing that fast, and accurately.

What it does: The operator; a cobweb; distances shrinking by beta; Blackwell's conditions

2Value and policy iteration, timedGraduate2 min

Value iteration has a weakness the last chapter exposed: it crawls. Each round the values improve by only the factor beta, so with a patient household they creep towards the answer, 333 rounds here. But look at the decisions instead of the values. After round 74, the best choice of next year's capital at every grid point never changes again. More than three quarters of the work only polishes numbers whose decisions are already right. That suggests a better plan.

Ronald Howard's policy iteration, from 1960, works on the decisions. Take a policy, and work out the value of following it forever, not one round at a time but exactly, in one step. Then improve the policy with a single Bellman step, and stop when no choice changes. The bars count the grid points whose choice changed in each round: all three hundred at first, then fewer and fewer, then none. 18 rounds instead of 333, and the same policy at every grid point. Even with each round doing more work, it is about 2 times as fast here, and the gain grows with patience, because value iteration slows as beta approaches one and policy iteration barely notices.

Why is it so much faster? Fix a policy sigma. Its value satisfies a linear equation: this year's utility under the policy, plus beta times the value wherever the policy sends you. The matrix P sigma records where that is, so each row has a single one in it, and the system has just two entries a row. A computer solves such a sparse system in one step, and that one step does the work of hundreds of rounds of value iteration. In fact policy iteration is Newton's method applied to the Bellman equation, which is why it converges in a handful of rounds where value iteration needs hundreds.

What it does: The policy settles first; Howard's method; why it is Newton's method

3Play it: which grid is fine enough?Principles and the major2 min

Your turn. Value iteration chooses next year's capital from a grid of points. On a grid of thirty points the policy is a staircase; on a hundred, a finer staircase; on a thousand, it is hard to tell from the accurate rule. You must report the economy's steady-state capital, where the policy crosses the diagonal, to within one percent. Which grid will do: thirty points, a hundred, a thousand, or none of them? Pause, and choose.

Here are the steady states each grid implies, as a share of the true one. Thirty points: 8.6 percent too low. A hundred: 2.5 percent too low, still outside the band. A thousand: 0.25 percent, inside it. Only the finest grid will do. Notice the direction: on a grid the household can only choose among a few capital stocks, and the rounding does not cancel out; it drags the steady state down.

A better yardstick than any one number is the Euler-equation error, which chapter eight builds properly. For now: at each capital stock, how far is the rule from satisfying the household's own first-order condition, as a fraction of consumption? With thirty points the worst mistake is about one dollar in 6 of consumption. With a hundred, one in 23. With a thousand, one in 246. Ten times the points buys about ten times the accuracy, and costs a hundred times the work, because each point must compare itself with every other. Fine enough depends on the question; the habit to learn is to measure the error rather than guess it.

What it does: Three grids; their steady states; Euler errors

4Between the grid pointsGraduate3 min

The staircase of the last chapter came from a restriction: next year's capital had to be one of the grid points. The best of seven points may be some way from the true best. Instead, keep the value function only at the grid points, fill in between them by interpolation, and search the filled-in curve for its peak, wherever it lies. A golden-section search does that without derivatives: each step keeps the better sixty-two percent of the interval, so sixty steps pin the peak down to far less than a billionth of the range.

How much does it buy? For reference, the thousand-point grid, faint. Forty points with straight lines between them nearly match it, at about one dollar in 122. The same forty points joined by a cubic spline: one in 1.1 million, thousands of times better, because the value function is smooth and a spline uses its curvature. And twelve points, placed where Chebyshev says and joined by one polynomial: one dollar in 4.7 million. Smooth problems reward smooth approximations.

Why Chebyshev's points? Carl Runge found the warning in 1901. Take this smooth, harmless-looking bump. Pass one polynomial through eleven evenly spaced points on it, and the polynomial swings wildly near the ends, missing by 1.9; adding more evenly spaced points makes the swings larger, not smaller. Put the eleven points where Chebyshev's nodes are, crowded towards the ends, and the error falls to 0.11, and keeps falling as points are added. Where you put the points matters as much as how many you use.

Three ways to place twenty-four points. Evenly, the natural first choice. Chebyshev's nodes, crowded at both ends, the right choice for a single polynomial across the whole range. And a grid that crowds its points near the borrowing limit, the one the household of chapter five uses, because that is where its consumption rule bends sharply. The rule is simple to state and easy to forget: put the points where the function bends.

What it does: Golden-section search; linear, spline and Chebyshev; Runge; where to put points

5The endogenous grid methodGraduate3 min

The household of Part twenty-two: it earns an income that moves persistently up and down, saves at a fixed return, and cannot borrow. Its assets next year are this year's, with interest, plus income, minus consumption, and must not fall below zero. Its rule is the Euler equation: the marginal utility of consuming today equals beta times R times the expected marginal utility tomorrow, unless the borrowing limit binds. The usual way to solve it: at every level of assets, search for the consumption that makes the equation hold, a root to find at every grid point, in every one of hundreds of rounds.

Christopher Carroll's trick, published in 2006, turns the problem around. Put the grid on next year's assets instead of this year's. Then the right-hand side of the Euler equation, which depends only on next year, is known from last round's consumption rule. Inverting marginal utility gives today's consumption directly: no search, just a power. The budget then says what assets today lead to that choice: a equals c plus a prime minus y, over R. Those assets fall wherever they fall, so the rule is interpolated back onto the grid; below the first of them the borrowing limit binds, and the household consumes everything it has. Today's grid is found, not chosen, which is where the name comes from.

Here are the rules it finds, for the lowest, middle and highest of five income levels. With the lowest income and little wealth, the household consumes everything it has: the rule lies on the dashed line, because the borrowing limit binds. With more wealth it starts to save, and the rule bends away. Higher income lifts the whole rule, by less than the income, because some of a good year is saved for bad ones.

How much faster is it? Plot each method by the time it takes and the worst error it leaves, both on log scales, so lower and further left is better. Value iteration on grids of a hundred to eight hundred points: each doubling of the grid costs four times the time and buys only a little accuracy. The endogenous grid method, with two hundred points, sits far below and to the left. Against value iteration with 800 points it is 85 times as fast and 43 times as accurate. Extending the blue line, value iteration would need a grid more than a hundred times finer to match it, and more memory than a laptop has.

What it does: The household; Carroll's trick; the rules; the race against value iteration

6Projection: the rule as a polynomialGraduate2 min

A different idea, from Kenneth Judd in 1992: stop storing the rule at grid points, and write it as a formula. Approximate consumption by a sum of Chebyshev polynomials with unknown coefficients theta. For any theta, the Euler equation leaves a residual: how far marginal utility today is from its discounted value tomorrow. Choose the n coefficients so that the residual is exactly zero at n points, Chebyshev's nodes: that is collocation, n equations in n unknowns, solved by Newton's method. Or make the residual zero on average against each polynomial: that is Galerkin's method. Either way, the whole policy becomes a handful of numbers.

Here is the residual of a polynomial of degree three, four coefficients, across the range of capital. It wiggles, as it must, because a cubic cannot be exactly the true rule. But it passes through zero at the four nodes where collocation forced it to, and between them it stays small. Chebyshev's nodes are spread so that those wiggles are about as even, and as small, as any placement can make them.

And as the degree rises? The worst Euler error falls steadily, from about one dollar in two hundred and fifty with a straight line, to one in 6 million at degree eight, each extra degree making the rule about 4 times more accurate. This is what mathematicians call spectral convergence, and it is the reward for a smooth problem. Galerkin's method, at degree four, lands in the same place as collocation. And the whole computation takes a few thousandths of a second. Projection's weakness is the other side of the same coin: a kink, such as a borrowing limit, ruins a single smooth polynomial, which is why the household used a grid.

What it does: Collocation and Galerkin; the residual; spectral convergence

7Perturbation, and when certainty equivalence misleadsGraduate2 min

The third family of methods works from a single point. Write next year's capital as a Taylor series around the steady state. The first coefficient comes from differentiating the Euler equation once at the steady state, which gives a quadratic; the stable root is 0.924, so the gap to the steady state closes by about 7.6 percent a year, the speed of convergence of Part twenty. The second coefficient comes from differentiating twice, and the equation for it is linear. This is perturbation, the workhorse of central banks' models: fast, and exact at the point it starts from.

How far can the series be trusted? Measure each approximation's mistake in next year's capital, against the accurate rule, across a wide range. At the steady state both are exact. The first-order rule, a straight line, drifts away as capital moves far from the steady state; the second-order rule bends with the truth and stays closer for longer. Within the range an economy usually visits, both are good; measured by Euler errors, first order is right to about one part in two hundred, second order to about one in eight hundred. Far from home, after a war or in a deep crisis, a local method can mislead.

Now the deeper trap. A first-order approximation of a model with uncertainty has a property called certainty equivalence: the rule depends on the average of future shocks, never on their size. Solve the household twice. Once with its income known for certain, at the same average; once with the income uncertain, as it is. The uncertain household consumes less at every level of wealth: at assets of two, 0.22 less, about a fifth of a year's income, saved against bad years. This is precautionary saving, the buffer stock of Part twenty-two. A first-order perturbation cannot see the gap at all; a second-order one sees part of it, as a constant shift. When risk itself drives behaviour, as with saving, asset prices or default, a method must see the risk.

What it does: g1 and g2; errors away from home; precautionary saving

Intermission: transistors per microprocessor, 1971-2021Principles and the major

This chapter has no narration to read.

8Accuracy: Euler-equation errorsPrinciples and the major2 min

Every chapter so far has quoted an Euler-equation error. Here is what it is. At any capital stock, take the computed rule, and ask what consumption today the household's own Euler equation would demand, given what the rule does tomorrow. The error is the gap, as a share of consumption. It is unit-free: minus three on the log scale means a mistake of one dollar in a thousand. And it needs no true answer to compare with, which is the whole point: in a real problem there is none. Kenneth Judd proposed it in 1992. For long simulated series, Wouter den Haan and Albert Marcet's test of 1994 asks whether the errors can be predicted from information the household had; if they can, the rule is wrong.

Now line the methods up on one problem, as Borağan Aruoba, Jesús Fernández-Villaverde and Juan Rubio-Ramírez did in 2006 for a family of growth models. Value iteration on a thousand grid points: the slowest, and among the least accurate. Searching between forty grid points with straight lines, slightly worse; with a cubic spline, or with twelve Chebyshev points, thousands of times better. Collocation reaches the same accuracy in a few milliseconds. Perturbation is the fastest of all and, on this wide range of capital, the least accurate of the smooth methods. The ranking is specific to this smooth model; with a borrowing limit, a kink or a big shock it can turn over. That is why the error must be shown for the problem at hand, every time.

One more lesson the errors teach. Stop value iteration earlier or later, with tolerances from one tenth down to a hundred millionth. Each tighter tolerance costs more rounds. But the error does not move at all. On a grid, the rule is decided by which grid point is best, and that settles long before the values do; after that, more rounds polish digits that do not matter. Two sources of error, the approximation and the stopping rule, and only measuring tells you which one binds.

What it does: The definition; eight methods compared; tolerance against accuracy

9Expectations: chains and quadratureGraduate2 min

Most economic models need an average over the future, and the future is usually a continuous random process, such as income following an autoregression. A computer must replace it with something finite. The common way is a Markov chain on a few states. George Tauchen's method of 1986 places the states evenly and assigns the transition probabilities from the normal distribution. With five states and persistence of 0.99, typical of yearly income, its chain never moves: the chance of staying put rounds to one, because the states are too far apart for a small shock to cross. K. Geert Rouwenhorst's construction of 1995 builds the chain differently, so that it moves by a small step now and then. Karen Kopecky and Richard Suen showed in 2010 that for persistent processes it is the one to use.

The numbers. With persistence 0.9, Tauchen's five-state chain is a little too persistent, and its spread is about a quarter too large. Rouwenhorst's matches both exactly. With persistence 0.99, Tauchen's chain is a random walk that never steps, and its spread is a third too large; Rouwenhorst's is still exact. A model fed the wrong chain gets the wrong amount of risk, and chapter seven showed how much behaviour depends on risk.

Inside each round, the average itself must be computed. Take the average of e to the half of a standard normal shock, whose true value is known. Simulate it with random draws, and the error falls like one over the square root of the number of draws: a hundred times the draws for ten times the accuracy. Gauss-Hermite quadrature instead places a few points and weights exactly where a normal distribution needs them. Seven of them beat a hundred thousand random draws by a factor of hundreds of millions; with ten, the error is at the limit of the machine. For smooth functions of normal shocks, quadrature is almost free accuracy; simulation earns its place when the shocks are many or strange.

What it does: Tauchen and Rouwenhorst; Gauss-Hermite against Monte Carlo

10Continuous timeGraduate2 min

Now let time run continuously. A household earns one of two incomes, switching between them at random, and saves or borrows at a fixed rate, down to a limit. Its Bellman equation becomes the Hamilton-Jacobi-Bellman equation: the return on being in a state equals the flow of utility, plus the value of the wealth it is accumulating, plus the expected gain from a switch of income. Because time is continuous, the best consumption satisfies a plain first-order condition, marginal utility equals the slope of the value function, with no search. Yves Achdou, Jiequn Han, Jean-Michel Lasry, Pierre-Louis Lions and Benjamin Moll showed in 2022 how fast this can be solved.

How is it solved? On a grid of wealth, the slope of the value function is a difference between neighbouring points. The trick is to take the difference in the direction the household is moving: forward where it saves, backward where it runs its wealth down. This upwind rule is what keeps the method stable. Then each step solves one linear system for the whole value function at once, an implicit step that can be as large as you like. The system has 1,000 unknowns, but each grid point talks only to its two neighbours and to the same wealth in the other income state, so of a million entries only about three thousand are not zero. 9 steps, a few hundredths of a second.

The results. Saving: with low income the household runs its wealth down, faster the more it has, until it reaches the borrowing limit and stops there; with high income it saves, less as it grows richer. And the distribution of wealth across many such households, which in discrete time needs a separate simulation. Here it comes from the same sparse matrix, transposed: the Kolmogorov forward equation. 3.6 percent of households sit exactly at the borrowing limit, low earners who have run out. That spike is a feature of the economics, and the method captures it exactly.

What it does: The HJB equation; upwind and implicit; saving and the distribution

11Occasionally binding constraintsGraduate2 min

Many economic constraints bind only sometimes. The household's borrowing limit is one: with little wealth and low income, it would like to borrow and cannot, so it spends everything. With a little more wealth it starts to save, and its rule follows the Euler equation. Where one regime gives way to the other, the rule has a kink. A single smooth polynomial cannot bend that sharply and smears the corner, which is why this household was solved on a grid. The endogenous grid method finds the kink exactly: it is the first point of the endogenous grid, below which the limit binds.

The zero bound on interest rates, from Part thirty, is the other famous case. Take the New Keynesian economy of that part, and let the natural rate of interest fall to minus two percent for a year. A linear solution that ignores the bound has the central bank cut its rate to about minus 3.6 percent, and the output gap falls to about minus 1.7 percent. But the rate cannot go below zero. Luca Guerrieri and Matteo Iacoviello's method guesses which quarters the bound binds in, solves the linear model for that sequence, checks whether the rule would ask for a negative rate anywhere else, and repeats. Here it settles after 2 guesses, with the rate at zero for 3 quarters. Respecting the bound, the output gap falls to minus 3.4 percent, twice as deep. The constraint that binds only sometimes is exactly the one that decides how bad the recession is.

What to take away. Kinks break the smooth methods: a polynomial or a Taylor series assumes the rule is smooth everywhere. Grids and regime methods cope: the endogenous grid finds the kink, and guess and verify finds the regime. The safest way solves the whole nonlinear model with the constraint inside it, at a higher cost. And whichever is used, the errors must be checked on both sides of the kink and at the corner itself, where approximations are worst.

What it does: The household's kink; the zero bound by guess and verify

12The curse of dimensionalityResearch2 min

Every method so far had a state with one or two parts: capital, or assets and income. Real models have more. With five grid points in one direction, a grid has five points. Add productivity, and it has twenty-five. Add two more parts and it has six hundred and twenty-five. With ten parts, nearly ten million, and that with only five points in each direction, far too coarse to be accurate. Bellman named the problem himself in 1957: the curse of dimensionality.

The way out begins with a Russian mathematician, Sergey Smolyak, in 1963. A full grid takes every combination of points in every direction, so its size multiplies with each new part: on a log scale, a straight line up. Smolyak's sparse grid keeps only the combinations that matter most for smooth functions: many points along each axis, few where several directions vary at once. Its size grows like the square of the number of parts, not exponentially. With twenty parts: 841 points, against about a hundred trillion. Dirk Krueger and Felix Kubler brought the method into economics in 2004.

Does the sparse grid give up accuracy? Test it on a smooth function of four variables, whose value is known everywhere. The full grid's error falls as points are added. Smolyak's falls too, and for a given accuracy it uses fewer points: in four dimensions, roughly a half or a third as many. In ten or twenty dimensions, where the full grid cannot even be stored, the saving is what makes the problem possible at all. The price is smoothness: a kink or a strong interaction between the variables erodes the advantage. Beyond a few dozen dimensions, even sparse grids give out, and the frontier uses neural networks as the approximation, the subject of Part sixty-four.

What it does: Grid sizes; Smolyak's sparse grid; accuracy per point

13ReproducibilityPractice3 min

A computed answer that nobody can check is an anecdote. The habit this part has been building is simple: every solution comes with its report. What model, with which parameters. Which method, on which grid or with which basis. Which solver and tolerance, and where it started. How long it took. And how accurate it is, measured. Agora's solvers return such a report with every answer, and the films quote them.

Randomness needs the same care. Average ten thousand random draws. With the random number generator started from seed zero, one answer; started from seed zero again, exactly the same answer, to the last digit; from seed one, a different answer, in the third decimal place. Neither is the truth. So fix the seed and record it, so that a result can be repeated exactly, and report how much the answer moves when the seed changes, so that nobody mistakes simulation noise for a finding.

And test the solver where the answer is known. With log utility and full depreciation, the growth model of Brock and Mirman, from Part twenty-nine, has a formula: consume a fixed share of output. Collocation reproduces it to within a few parts in ten million; value iteration on five hundred points, to about five parts in ten thousand, the grid's limit. Tests like these run every time the code changes, so a mistake introduced next year is caught the day it is made.

Put together, these make a replication package, which leading journals now require. Since 2019 the American Economic Association's data editor has checked that a paper's package runs before the paper is published. The raw data, with where each file came from, its licence and the date it was taken. The code, ideally one command from raw data to every table and figure. The environment: the versions of everything it ran on. The numbers that steer it: seeds, tolerances, grids, and their reports. Tests with known answers. And a README that says what to run and how long it takes. This series is built the same way: every number in these films comes from a compute script that anyone can rerun.

What it does: The report; seeds; a known answer; the replication package

14The Dials: parameters against method errorGraduate2 min

Every solver in this part was fed numbers: a discount factor, a capital share, and an elasticity of intertemporal substitution of a half. The last is one of the Dials, from Part seven. Robert Hall found it near zero in aggregate data; surveys of hypothetical choices, about 0.2; Annette Vissing-Jorgensen, about a third for stockholders and nearly one for bondholders; Jonathan Gruber, from tax variation, about two; Tomas Havranek's meta-analysis, near zero in macro data and about a third in micro data; and asset-pricing models assume one and a half. Contested, across a factor of ten or more.

Now set the two kinds of uncertainty side by side, on a log scale. Take consumption when capital is eighty percent of its steady state. Change the elasticity of substitution from the film's half to one, and consumption changes by 3 percent; to a quarter, by 2 percent the other way. A good method's error is about a hundred thousand times smaller: lost entirely in the uncertainty about the parameter. But a careless one, the thirty-point grid of chapter three, gets the steady state wrong by 9 percent, as large as the whole dispute about the parameter. So a method need not be perfect, only good enough that its error is small beside what we do not know about the economy; and only measuring shows which side of that line it is on.

What it does: The EIS dial; parameter uncertainty against method error

15In practice: model teams and estimationPractice2 min

Who uses these methods? Central banks keep model teams; the Federal Reserve's large model, FRB/US, has been in use since 1996. Many of their smaller models are solved by perturbation, often with Dynare, free software developed since the 1990s. Academic economists estimate models structurally, which means solving the model again inside every evaluation of the likelihood. Models with many different households, the subject of the next part, solve a household like chapter five's for every candidate interest rate. And firms use the same dynamic programming to price seats and rooms, manage inventories and replace equipment.

Why speed matters so much there. An estimation guesses the parameters, solves the model, computes what the model says about the data, compares, and guesses again, thousands of times over. John Rust's nested fixed point of Part forty-four works exactly so, solving the bus engine problem inside each step. A solver a thousand times too slow makes the estimation a thousand times too slow, and a solver that is not accurate makes the estimates wrong.

Called it? A forecast about the machines themselves. In April 1965 Gordon Moore, then director of research at Fairchild Semiconductor, plotted a handful of points and predicted in the magazine Electronics that by 1975 the cheapest chips would carry about sixty-five thousand components, the number doubling every year. In 1975 he reported that the projection had been met, and revised the pace to a doubling every two years. That pace held for half a century: the largest microprocessor grew from about two thousand three hundred transistors in 1971 to 58 billion in 2021, doubling about every 2.0 years. The verdict: right, with one revision, and the revision was made in the open. Every method in this part rides on that curve.

What it does: Who solves economies; estimation loops; Called it? (right)

16Frontier: solvers that differentiateResearch2 min

The frontier first. Estimation needs to know how the solution moves when a parameter moves. The collocation equations hold at the solution for every value of beta, so they can be differentiated: the derivative of the coefficients is one linear solve with the matrix Newton's method already built. Here, how consumption at the steady-state capital responds to the discount factor: minus 5.7558, the same, to six digits, as solving the model twice and differencing. Differentiable programming, the machinery of modern machine learning, does this automatically through any solver, so that estimation can follow gradients instead of guessing.

Second, the curse of dimensionality, attacked with machine learning. Draw states of the economy at random, with no grid at all. Let a neural network propose the policy at each. Compute the Euler residuals there, the yardstick of chapter eight, and adjust the network's weights to shrink them. Lilia Maliar, Serguei Maliar and Pablo Winant, and Marlon Azinovic, Luca Gaegauf and Simon Scheidegger, published such methods in 2021 and 2022. They solve economies with hundreds of state variables, such as many overlapping generations, and they must be checked the same way as any other method: by Euler errors on states the network never saw.

What remains open? Certifying accuracy: in a hundred dimensions the errors can only be sampled, and a bound on the worst one is hard to come by. Solving models with millions of different households quickly, for which the newest methods linearize around a solved household in sequence space, the subject of the next part. Knowing in advance when a local method is safe and when only a global one will do. And making computations that involve random training as reproducible as the ones in this film.

What it does: Implicit derivatives; neural-network solvers; open questions

Recap, problems, and the road aheadAll tracks3 min

So: how is an economy that has no formula solved, and how do you know the answer is right? By turning it into a fixed point and iterating towards it, which Blackwell's conditions guarantee will work; or into equations that must hold at well-chosen points; or into a series around the steady state. Each is fast when it fits the problem: grids and endogenous grids where there are kinks, polynomials where the rule is smooth, perturbation near home. And you know the answer is right only by measuring it: Euler-equation errors, known answers, fixed seeds, and a report with every result.

Part fifty-one in twelve lines. The Bellman operator is a contraction, so iterating it converges, at the rate beta. Policy iteration gets the same answer in a handful of rounds. Coarse grids bias the answer; measure the error, do not guess it. Interpolate between grid points, and put the points where the function bends. The endogenous grid method needs no root finding. Projection makes a policy a handful of numbers, more accurate with every degree. Perturbation is exact at home, and at first order blind to risk. Euler errors measure accuracy without knowing the answer. Discretize persistent shocks with Rouwenhorst, and integrate with quadrature. In continuous time the household is a sparse linear system. Constraints that bind sometimes need methods that find the regime. And many dimensions need sparse grids, or networks, and every answer needs its report.

The problems. How many rounds a contraction needs; Blackwell's conditions; evaluating a policy by one linear solve; the endogenous grid by hand; a collocation at two nodes; perturbation of Brock and Mirman's economy; what an Euler error means in money; and a starred problem counting the points of a Smolyak grid. Full solutions are in the part's notes.

The reading: Kenneth Judd's Numerical Methods in Economics; Stokey and Lucas, with Prescott, for the theory of recursive methods; Sargent and Stachurski's lectures, with code; and the handbook chapter by Fernández-Villaverde, Rubio-Ramírez and Schorfheide. Then the papers, from Bellman to the neural networks.

Next time, the methods of this part go to work on a whole population. In 1998 Per Krusell and Anthony Smith solved an economy with a distribution of households, and found, to general relief, that its average behaves almost as if there were one household. Part fifty-two asks what macroeconomics gets wrong by treating a country as one household: the household, the distribution, the interest rate that clears the market, and why later models with realistic inequality changed the account of how monetary policy works.

Where it goes next. Part 52 puts these methods to work on a whole population of households: what macroeconomics gets wrong by treating a country as one household.

Key results

The part's results in one place, for revision.

The Bellman operator\(\displaystyle (TV)(k) = \max_{k'}\, u(f(k) - k') + \beta V(k')\)
Contraction\(\displaystyle \lVert TV - TW \rVert \le \beta\, \lVert V - W \rVert\)
The endogenous grid\(\displaystyle c = \big(\beta R\, \mathbb{E}[u'(c')]\big)^{-1/\gamma},\ a = (c + a' - y)/R\)
Euler-equation error\(\displaystyle \log_{10}\Big|1 - \frac{u'^{-1}(\beta\,\mathbb{E}[u'(c')R'])}{c}\Big|\)
Smolyak, level 2\(\displaystyle 1 + 4d + 2d(d-1)\ \text{points}\)

Try it

Lab 51 · Computing economies

Solve the growth model and a household with a borrowing limit several ways, measure each answer with Euler-equation errors, and see which methods are fast, which are accurate, and why.

Figure produced by Lab 51: Computing economies
Produced by the lab below, seed 0, in 0.6 s.
python -m videos.economics.labs 51 needs numpy, scipy, matplotlib · download lab51.py · source on GitHub
value iteration: rounds, seconds                                              333, 0.015
policy iteration: rounds, seconds                                             18, 0.005
contraction ratio after 60 rounds (beta)                                      0.9599 (0.96)
grid of 30: steady state / true, worst Euler error                            0.9138, 10^-0.79
grid of 100: steady state / true, worst Euler error                           0.9747, 10^-1.37
grid of 1000: steady state / true, worst Euler error                          0.9975, 10^-2.39
household: endogenous grid (seconds, worst error)                             0.011, 10^-3.05
household: value iteration on the same grid                                   0.035, 10^-0.81
collocation: worst Euler error by degree 1..10                                -2.4, -3.0, -3.6, -4.3, -5.0, -5.6, -6.2, -6.8, -7.4, -8.1
perturbation: g1, g2 (seconds)                                                0.9242, -0.00422 (0.0004)
zero bound: quarters at zero, guesses; output gap with and without the bound  3, 2; -3.41%, -1.72%
Smolyak level 2 against 5^d points, d = 2, 5, 10, 20                          13 / 2e+01, 61 / 3e+03, 221 / 1e+07, 841 / 1e+14

Value iteration converges at the rate beta, and policy iteration in a handful of rounds; coarse grids bias the steady state; the endogenous grid method avoids root finding and beats value iteration on both time and accuracy; collocation's error falls geometrically with the degree; perturbation is exact at the steady state; the zero bound deepens the recession; sparse grids grow polynomially with the dimension.
The code (84 lines; it asserts its own result)
"""Lab 51: computing economies: value and policy iteration on the growth model, grids and their steady states, the
endogenous grid method against value iteration, collocation by degree, perturbation, the zero bound by guess and
verify, and Smolyak's sparse grids."""

import time

import numpy as np

from videos.coursekit import labs
from explainer.economics.agora import solve as S
from explainer.economics.island import truths

TITLE = "Computing economies"
GOAL = ("Solve the growth model and a household with a borrowing limit several ways, measure each answer with "
        "Euler-equation errors, and see which methods are fast, which are accurate, and why.")
TASKS = [
    "Raise beta to 0.99. How many more rounds does value iteration need, and how many does policy iteration?",
    "Give the household no income risk (sigma = 0.0001). How much more does it consume at assets of 2?",
    "Find the smallest collocation degree whose worst Euler error is below 10^-6.",
]


def run(seed=0):
    lab = labs.Lab()
    T = truths(51)
    m = S.growth(**T["growth"])

    g = S.kgrid(m, 300)
    v = S.vfi(m, g, tol=1e-6)
    h = S.howard(m, g)
    lab.row("value iteration: rounds, seconds", f"{v['iters']}, {v['seconds']:.3f}")
    lab.row("policy iteration: rounds, seconds", f"{h['iters']}, {h['seconds']:.3f}")
    assert np.array_equal(v["j"], h["j"])
    cp = S.contraction_path(m, g, 60)
    lab.row("contraction ratio after 60 rounds (beta)", f"{cp['ratio'][-1]:.4f} ({m['beta']})")

    for n in T["grids"]:
        gg = S.kgrid(m, n)
        r = S.vfi(m, gg, tol=1e-8)
        steady = gg[np.argmin(np.abs(r["kprime"] - gg))] / m["kss"]
        ee = S.euler_errors(m, lambda k, gg=gg, r=r: S.resources(k, m) - np.interp(k, gg, r["kprime"]))["max"]
        lab.row(f"grid of {n}: steady state / true, worst Euler error", f"{steady:.4f}, 10^{ee:.2f}")

    hh = S.household(**T["household"])
    e = S.egm(hh)
    vh = S.household_vfi(hh)
    lab.row("household: endogenous grid (seconds, worst error)",
            f"{e['seconds']:.3f}, 10^{S.household_euler_errors(hh, e['c'])['max']:.2f}")
    lab.row("household: value iteration on the same grid",
            f"{vh['seconds']:.3f}, 10^{S.household_euler_errors(hh, vh['c'])['max']:.2f}")

    degs, errs = [], []
    for n in range(2, 12):
        c = S.collocation(m, n)
        degs.append(n - 1)
        errs.append(S.euler_errors(m, c["c"])["max"])
    lab.row("collocation: worst Euler error by degree 1..10", ", ".join(f"{x:.1f}" for x in errs))
    assert errs[-1] < errs[0] - 4

    t0 = time.perf_counter()
    p1, p2 = S.perturbation(m, 1), S.perturbation(m, 2)
    lab.row("perturbation: g1, g2 (seconds)", f"{p1['g1']:.4f}, {p2['g2']:.5f} ({time.perf_counter() - t0:.4f})")

    z = S.zlb_occbin(**T["zlb"])
    lab.row("zero bound: quarters at zero, guesses; output gap with and without the bound",
            f"{z['bound_quarters']}, {z['iters']}; {z['x'][0]:.2f}%, {z['x_free'][0]:.2f}%")

    lab.row("Smolyak level 2 against 5^d points, d = 2, 5, 10, 20",
            ", ".join(f"{S.smolyak_count(d, 2)} / {S.tensor_count(d, 2):.0e}" for d in (2, 5, 10, 20)))

    lab.note = ("Value iteration converges at the rate beta, and policy iteration in a handful of rounds; coarse "
                "grids bias the steady state; the endogenous grid method avoids root finding and beats value "
                "iteration on both time and accuracy; collocation's error falls geometrically with the degree; "
                "perturbation is exact at the steady state; the zero bound deepens the recession; sparse grids grow "
                "polynomially with the dimension.")

    fig, ax = labs.figure(2, size=(11, 4.4))
    ax[0].semilogy(np.arange(1, len(v["dist"]) + 1), v["dist"], color=labs.BLUE, label="value iteration")
    ax[0].set(title="change from the round before", xlabel="round")
    ax[0].legend()
    ax[1].plot(degs, errs, marker="o", color=labs.ORANGE)
    ax[1].set(title="collocation: worst Euler error (log10)", xlabel="degree")
    lab.fig = fig
    return lab

Now change it

  1. Raise beta to 0.99. How many more rounds does value iteration need, and how many does policy iteration?
  2. Give the household no income risk (sigma = 0.0001). How much more does it consume at assets of 2?
  3. Find the smallest collocation degree whose worst Euler error is below 10^-6.

Problems, with solutions

Try each problem before opening its solution.

1. The contraction: with beta = 0.96 and a first change of 10, how many rounds of value iteration bring the change below 10^-6? With beta = 0.99?

Solution

The change after n rounds is about 10 x beta^n, so n must exceed log(10^-7)/log(beta). For beta = 0.96 that is 16.12/0.0408 = 395 rounds; for beta = 0.99, 16.12/0.01005 = 1,604 rounds. Patience is expensive for value iteration, which is why quarterly models use policy iteration or other methods.

2. Blackwell: show that the growth model's Bellman operator satisfies discounting, T(V + a) = TV + beta a, and monotonicity.

Solution

(T(V + a))(k) = max over k' of u(f(k) - k') + beta (V(k') + a). The constant beta a is the same for every choice, so it comes out of the max: (TV)(k) + beta a. For monotonicity, if V <= W everywhere then for every choice u + beta V(k') <= u + beta W(k') <= (TW)(k); taking the max over k' on the left gives (TV)(k) <= (TW)(k). By Blackwell's theorem, T is then a contraction with modulus beta.

3. Policy evaluation: a policy sends state 1 to state 2 and keeps state 2 where it is; utilities are 1 and 2, beta = 0.9. Solve V = u + beta P V.

Solution

State 2 stays put: V2 = 2 + 0.9 V2, so V2 = 20. State 1 moves to state 2: V1 = 1 + 0.9 x 20 = 19. One linear solve gives the value of following the policy forever, which is the evaluation step of Howard's method.

4. The endogenous grid by hand: u = log c, beta R = 1, R = 1.05, y = 1, and tomorrow's rule c(a') = 0.05 a' + 1. For a' = 2, find today's c and the assets a that choose it.

Solution

The Euler equation 1/c = beta R E[1/c'] = 1/c' gives c = c' = 0.05 x 2 + 1 = 1.1, with no search. The budget a' = R a + y - c gives a = (c + a' - y)/R = (1.1 + 2 - 1)/1.05 = 2.0. So the household with assets 2 consumes 1.1 and keeps its assets at 2.

5. Collocation: fit c0 + c1 x to e^x at the Chebyshev nodes +-1/sqrt(2). Find the coefficients and the error at x = 0.

Solution

At x = 0.7071, e^x = 2.0281; at -0.7071, 0.4931. So c1 = (2.0281 - 0.4931)/1.4142 = 1.0854 and c0 = (2.0281 + 0.4931)/2 = 1.2606. At x = 0 the fit gives 1.2606 against 1: an error of 0.26. More nodes, and a higher degree, shrink it quickly, as in the film's chapter on projection.

6. Perturbation: for Brock and Mirman's economy, k' = alpha beta k^alpha. Show that g1 = alpha, and find the speed of convergence for alpha = 0.36.

Solution

The derivative is alpha^2 beta k^(alpha - 1). At the steady state k* = alpha beta k*^alpha, so alpha beta k*^(alpha - 1) = 1 and g1 = alpha. With alpha = 0.36 the gap to the steady state shrinks to 36% of itself each year: a speed of convergence of 64% a year, far faster than with partial depreciation (7.6% in the film).

7. Euler errors: a rule's error is 10^-3 for a household that consumes 50,000 a year. What is the mistake in money, and is it worth a better method?

Solution

About 50 a year. That is small beside the uncertainty about the parameters (the film's dial chapter shows consumption moving by 2-3%, over 1,000, across the range of the EIS), so for many questions it is good enough; for welfare comparisons of small policies, whose effects may be a few dollars, it is not, and a method with errors near 10^-6 should be used.

8. Smolyak: show that the level-2 sparse grid in d dimensions has 1 + 4d + 2d(d - 1) points.

Solution

With nested Clenshaw-Curtis nodes, level 1 in a direction adds 1 point, level 2 adds 2 new points and level 3 adds 2 more. The level-2 grid takes multi-indices whose levels exceed one by at most 2 in total: all at level 1 (one point, the centre); one direction at level 2 (2 new points, d ways: 2d); one direction at level 3 (2 new points, d ways: 2d); two directions at level 2 (2 x 2 new points, d(d - 1)/2 ways: 2d(d - 1)). The total is 1 + 4d + 2d(d - 1): 13 in two dimensions, 221 in ten, 841 in twenty.

Notes and sources

Sources

The studies the film states are listed with what each shows in dials.SHOWN[51]; the EIS dial is in explainer/economics/dials.py; Moore's forecast is a Called it? entry (explainer/economics/calls.py); the microprocessor data are in the Data Room. Checked on 2026-11-21: Bellman's account of the name (his autobiography, as excerpted by Dreyfus in Operations Research, 2002; the conflict with Wilson's dates); Moore (1965: 65,000 components by 1975, doubling yearly; 1975: realized, revised to two years); Maliar, Maliar and Winant (JME 2021) and Azinovic, Gaegauf and Scheidegger (IER 2022). The methods are stated from the papers cited in the chapters (Howard 1960, Blackwell 1965, Tauchen 1986, Judd 1992, Den Haan and Marcet 1994, Rouwenhorst 1995, Krueger and Kubler 2004, Schmitt-Grohé and Uribe 2004, Carroll 2006, Aruoba et al. 2006, Kopecky and Suen 2010, Guerrieri and Iacoviello 2015, Achdou et al. 2022) and computed here. Not stated, because not checked: how many times a typical estimation solves its model; the AEA's exact procedures beyond its data editor's pre-publication checks.

About this partfrom its README

Part 51 of a sixty-eight-part course in economics (see the series plan and the syllabus), the first of Act X, The Graduate Core. It asks how an economy that has no formula is solved, and how you know the answer is right. Its answer: by turning the economy into a fixed point and iterating towards it, which Blackwell's conditions guarantee will work, or into equations that hold at well-chosen points, or into a series around the steady state; each is fast when it fits the problem (grids and endogenous grids where there are kinks, polynomials where the rule is smooth, perturbation near home). And you know the answer is right only by measuring it: Euler-equation errors, known answers, fixed seeds, and a report with every result.

It opens on Richard Bellman's own account, in his autobiography, of naming dynamic programming at RAND in 1950 to avoid the word research, which the Secretary of Defense was said to hate: "programming" for planning, "dynamic" because, he wrote, it cannot be used as an insult, a name "not even a Congressman could object to" (the date has been questioned, since the Secretary he named took office in 1953). From there it covers:

  • the Bellman operator as a contraction: a cobweb on a line, Banach's theorem, the distances between iterates shrinking by 0.96 a round on the growth model of Part 29 (333 rounds to a change below a millionth), and Blackwell's two conditions checked numerically;
  • value against policy iteration: the policy settles at round 74 of 333; Howard's method gets the same policy, at every grid point, in 18 rounds, by solving a sparse linear system for each policy's value;
  • Play it: which of three grids (30, 100, 1,000 points) reports the steady-state capital to within 1%? Only the finest; the coarse grids put it 8.6% and 2.5% too low, with worst Euler errors of about one dollar in 6, 23 and 245;
  • between the grid points: golden-section search on an interpolated value function (Euler errors of 10^-2.1 with straight lines on 40 points, 10^-6.1 with a cubic spline, 10^-6.7 with 12 Chebyshev points); Runge's example (an error of 1.9 with evenly spaced points, 0.11 with Chebyshev's); where to put the points;
  • the endogenous grid method on Part 22's household: no root finding; against value iteration on 800 points it is about 85 times as fast and 40 times as accurate;
  • projection: Chebyshev collocation, each extra degree about four times more accurate (10^-2.4 at degree 1 to 10^-8.1 at degree 10), with Galerkin's method agreeing;
  • perturbation to second order (g1 = 0.924, a convergence speed of 7.6% a year), its errors away from the steady state, and certainty equivalence: the household with income risk consumes 0.22 less at assets of 2 than one with the same income for certain, a precautionary gap a first-order perturbation cannot see;
  • an intermission film of transistors per microprocessor, 1971-2021 (2,300 to 58 billion, doubling every two years), as a line and a tune;
  • accuracy: Judd's Euler-equation errors and Den Haan and Marcet's test; eight methods compared on one model, after Aruoba, Fernández-Villaverde and Rubio-Ramírez; why a tighter stopping tolerance does not help a grid;
  • expectations: Tauchen's five-state chain at persistence 0.99 never moves and overstates the spread by a third; Rouwenhorst's is exact; seven Gauss-Hermite nodes beat 100,000 random draws by a factor of hundreds of millions;
  • continuous time: a two-income household's HJB equation by Achdou et al.'s implicit upwind scheme, 9 steps on a 1,000-unknown sparse system (2,996 non-zeros), and the stationary distribution from the same matrix transposed (3.6% at the borrowing limit);
  • occasionally binding constraints: the household's kink, and the zero bound solved by guess and verify after Guerrieri and Iacoviello (the rate at zero for 3 quarters; the output gap -3.4% against -1.7% if the bound is ignored);
  • the curse of dimensionality: 5^20 grid points against Smolyak's 841, and sparse-grid interpolation in four dimensions;
  • reproducibility: the report every solution carries, seeds, a known-answer test on Brock and Mirman's economy (collocation within 3 parts in 10 million), and what a replication package contains;
  • the Dials: the elasticity of intertemporal substitution (contested, 0 to 2) moves consumption by 2-3%, a hundred thousand times a good method's error, while a careless grid errs by as much as the whole dispute;
  • in practice (model teams, Dynare, structural estimation) and Called it? on Gordon Moore's 1965 forecast (right), and a frontier of solvers that return derivatives (the implicit function theorem against finite differences, to six digits) and neural-network solvers checked by the same Euler errors.
What is computed and built

Everything plotted is computed by compute.py with Agora's solver harness (explainer.economics.agora.solve) and the Island's Part 51 truths; the narration states the cached numbers.

  • The growth model. u = c^(1-gamma)/(1-gamma) with gamma = 2, output k^0.36, depreciation 8%, beta = 0.96; capital grids from half to one and a half times the steady state.
  • Value and policy iteration. The Bellman operator with next period's capital on the grid (a payoff matrix); Howard's evaluation step by a sparse solve of (I - beta P)V = u; Blackwell's conditions on random value functions.
  • Interpolation. Golden-section search (60 steps) on linear, cubic-spline or Chebyshev interpolants of the value function; Runge's function through 11 points.
  • The household. log income a five-state Rouwenhorst chain (persistence 0.9, innovation s.d. 0.2), normalized to mean one; R = 1.03, beta = 0.95, gamma = 2, no borrowing; 200 asset points crowded near the limit; the endogenous grid method to a change below 10^-9; value iteration with savings on grids of 100 to 800 points.
  • Projection. Chebyshev collocation on [0.5, 1.5] times the steady state, degree by degree, each started from the degree below, by Powell's hybrid method; Galerkin by Gauss-Chebyshev quadrature with 60 points.
  • Perturbation. g1 from the quadratic of the once-differentiated Euler equation; g2 from the second derivative of the Euler residual along the quadratic policy (a linear equation, solved numerically).
  • Euler errors. log10 |1 - u'^-1(beta u'(c') R')/c| on 241 points between 0.6 and 1.4 times the steady state.
  • Continuous time. Incomes 0.1 and 0.2 switching at rate 1.2, r = 0.03, rho = 0.05, borrowing to -0.15, 500 asset points; implicit steps of size 1,000 until the change is below 10^-8; the distribution from A' g = 0.
  • The zero bound. The three-equation model (beta = 0.99, sigma = 1, kappa = 0.1275, Taylor coefficients 1.5 and 0.5), the natural rate at -2% for four quarters, perfect foresight over 40 quarters, solved as a linear system for each guessed set of bound quarters.
  • Sparse grids. Smolyak's combination technique on nested Clenshaw-Curtis nodes with barycentric polynomial interpolation; the test function exp(-|x|^2/2) on [-1, 1]^4 at 300 random points.
Chapter notes
# Chapter What it does
0 A name nobody could object to Bellman at RAND; value iteration settling; the question; objectives
1 The Bellman operator as a contraction The operator; a cobweb; distances shrinking by beta; Blackwell's conditions
2 Value and policy iteration, timed The policy settles first; Howard's method; why it is Newton's method
3 Play it: which grid is fine enough? Three grids; their steady states; Euler errors
4 Between the grid points Golden-section search; linear, spline and Chebyshev; Runge; where to put points
5 The endogenous grid method The household; Carroll's trick; the rules; the race against value iteration
6 Projection: the rule as a polynomial Collocation and Galerkin; the residual; spectral convergence
7 Perturbation, and when certainty equivalence misleads g1 and g2; errors away from home; precautionary saving
— Intermission Transistors per microprocessor, 1971-2021, as a line and a tune; the story so far
8 Accuracy: Euler-equation errors The definition; eight methods compared; tolerance against accuracy
9 Expectations: chains and quadrature Tauchen and Rouwenhorst; Gauss-Hermite against Monte Carlo
10 Continuous time The HJB equation; upwind and implicit; saving and the distribution
11 Occasionally binding constraints The household's kink; the zero bound by guess and verify
12 The curse of dimensionality Grid sizes; Smolyak's sparse grid; accuracy per point
13 Reproducibility The report; seeds; a known answer; the replication package
14 The Dials: parameters against method error The EIS dial; parameter uncertainty against method error
15 In practice: model teams and estimation Who solves economies; estimation loops; Called it? (right)
16 Frontier: solvers that differentiate Implicit derivatives; neural-network solvers; open questions
— Outro The answer; twelve lines; problems; reading; next, Part 52, Many Agents
Notes
  • python -m videos.economics.labs 51: value iteration and Howard's method with their rounds; grids and their steady states; the endogenous grid method against value iteration; collocation by degree; perturbation; the zero bound by guess and verify; Smolyak's counts.
  • The interactive (course site): solver. The reader picks a grid size and a method for the growth model and watches the policy, the steady state and the Euler errors change.

Companion material in this repository

The syllabus's plan for this partfrom SYLLABUS.md, the plan of record
  1. Hook: the name; the question; objectives.
  2. The Bellman operator as a contraction: Blackwell's two conditions; the fixed-point theorem, drawn.
  3. Value function iteration, timed; Howard's policy iteration; why it is so much faster.
  4. Play it: three grids and their answers: which is fine enough?
  5. Interpolation and the grid: linear, splines, Chebyshev; where to put the points.
  6. The endogenous grid method (Carroll 2006): no root finding. The household of Part 22, a hundred times faster.
  7. Projection methods (Judd 1992): the policy function as a polynomial; collocation, Galerkin.
  8. Perturbation: first and second order around the steady state; when certainty equivalence misleads.
  9. Accuracy: Euler-equation errors (Den Haan and Marcet 1994); a method is not solved until this is shown.
  10. Expectations: quadrature, Tauchen and Rouwenhorst; simulation error.
  11. Continuous time: the Hamilton–Jacobi–Bellman equation by upwind finite differences (Achdou et al. 2022); why it is sparse and fast.
  12. Occasionally binding constraints: the zero bound and borrowing limits.
  13. The curse of dimensionality (Bellman 1957); sparse grids (Smolyak); a pointer to deep solvers (Part 64).
  14. Reproducibility: seeds, tolerances, tests; what a replication package must contain.
  15. Dials. 15. In practice: model teams at central banks; structural estimation. 16. Frontier: differentiable programming for economic models.

Agora: solve: one harness for value and policy iteration, endogenous grids, projection, perturbation and finite-difference HJB, each with an Euler-error report; every earlier dynamic module moves onto it. Reading: Bellman 1957; Stokey, Lucas & Prescott chs 3–4, 9; Judd, Numerical Methods in Economics; Carroll 2006; Den Haan & Marcet 1994; Aruoba, Fernández-Villaverde & Rubio-Ramírez 2006; Achdou et al. 2022; Sargent & Stachurski; Fernández-Villaverde, Rubio-Ramírez & Schorfheide 2016.

Build the film

python -m videos.economics.econ51.compute        # the part's numbers, into .cache/econ51
python tools/build.py econ51                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py econ51 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/economics/econ51. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it
python -m videos.economics.econ51.compute              # every number (about a minute), into .cache/econ51/
python tools/qa_scene.py econ51 Operator               # one chapter, silent, at 480p, with a contact sheet
EXPLAINER_TTS=silent python tools/build.py econ51 -q l   # the whole part, silent preview
python tools/build.py econ51                           # 1080p30 with narration and the series' computed score
python -m videos.economics.labs 51                     # the lab

Times quoted in the film are measured when the cache is built, so they differ from machine to machine; the ratios between methods are what the film relies on. The only data are Karl Rupp's microprocessor trend data via Our World in Data, registered in SOURCES.md.