using Plots
using LinearAlgebra
using Statistics
using Distributions
using Random
using Optim
using Interpolations
using DataFramesKydland & Prescott (1982): Real Business Cycles
1 Introduction
1.1 From Micro to Macro
In the McCall search model, an unemployed worker receives random wage offers and decides each period whether to accept or keep searching. In Rust (1987), a bus superintendent observes accumulated mileage and decides whether to replace the engine or keep running it. Both are single-agent models set in a micro environment: one decision-maker, one state variable, one choice.
Kydland & Prescott (1982) scale this up dramatically. The agent is a representative household in a macroeconomy: it owns capital, supplies labor, and makes consumption and savings decisions. Firms produce using capital and labor, and productivity fluctuates randomly over time. The question is whether a perfectly competitive economy hit by productivity shocks can replicate the business cycles we observe in the data.
“Time to Build and Aggregate Fluctuations” was published in Econometrica in 1982 (now with over 10,000 citations) and earned Finn Kydland and Edward Prescott the 2004 Nobel Prize in Economics.
Before KP (1982), business cycles were thought to require market failures: sticky prices, coordination failures, or demand shortfalls. KP showed that a perfectly competitive economy hit by productivity shocks could generate realistic fluctuations without any friction. This launched the Real Business Cycle (RBC) research program.
The core model is a stochastic neoclassical growth model: households save and consume optimally, firms produce using capital and labor, and productivity fluctuates randomly. The model combines dynamic programming (as in McCall and Rust), Markov chains (for the productivity process), and linear algebra (for computing expectations).
A key computational challenge distinguishes the RBC model from everything we have done so far. In McCall and Rust, the state space was discrete: we stored the value function as a vector and looked up values directly. In the RBC model, capital \(k\) is continuous. We cannot simply index into a vector to evaluate the value function at an arbitrary capital level. This lecture introduces linear interpolation, the tool that lets us handle continuous state spaces.
1.2 Roadmap
We build the model in two stages. First we study the economy without productivity shocks: where it is heading in the long run (the steady state) and how it gets there from any starting point (the transition). Business cycles are then what happens when productivity shocks keep knocking the economy off that path, so in the second stage we add shocks and reuse the same solution code. These notes cover seven main topics:
- The Growth Model — households, firms, competitive equilibrium, and the steady state, first without shocks
- The Planner’s Problem — the First Welfare Theorem and the Bellman equation
- Linear Interpolation — a new tool for continuous state spaces
- Solving the Deterministic Model — value function iteration and the transition to the steady state
- Adding Productivity Shocks — the stochastic growth model, reusing the same solver
- Calibration and Simulation — matching long-run moments and generating artificial business cycles with
DataFrames - Linearized Solution — differentiating the Euler equation for a fast, analytical policy rule
2 The Neoclassical Growth Model
We start with the deterministic version of the model: productivity is constant, so households know every future price with certainty. This lets us focus on how households and firms interact through markets before we add any randomness.
2.1 The Household
A representative household lives forever and maximizes discounted lifetime utility:
\[ \max_{\{c_t, k_{t+1}\}} \; \sum_{t=0}^{\infty} \beta^t \log(c_t) \]
where \(c_t\) is consumption in period \(t\) and \(\beta \in (0,1)\) is the discount factor. Since there are no shocks (yet), there is no expectation operator: the household can perfectly foresee the future.
Why log utility? The function \(\log(c_t)\) has two important properties. First, it is increasing: more consumption is always better. Second, it is concave: the marginal utility of an extra dollar of consumption \(1/c_t\) falls as \(c_t\) rises. A household consuming $100 values an extra dollar much more than a household already consuming $10,000. This concavity is what drives consumption smoothing: the household prefers a steady consumption path to one that swings between feasts and famines.
The household owns the capital stock \(k_t\) and supplies one unit of labor inelastically each period. Capital is the household’s savings vehicle: each unit of capital it holds earns the real interest rate \(r_t\). It earns two types of income:
- Interest income: \(r_t k_t\) — the household rents its capital stock to firms and receives the interest rate \(r_t\) on each unit
- Wage income: \(w_t\) — the household supplies one unit of labor at the competitive wage
The household takes both prices \((r_t, w_t)\) as given. It is a price taker in competitive markets. Each period, it faces the budget constraint:
\[ c_t + k_{t+1} = (1 + r_t) \, k_t + w_t \]
The left side describes uses of funds: the household allocates its resources between consumption today (\(c_t\)) and capital carried forward to tomorrow (\(k_{t+1}\)). The right side describes sources of funds: the capital it owns plus the interest it earns on that capital, \((1 + r_t) k_t\), and wage income \(w_t\). From the household’s point of view, capital works exactly like a bank account: deposit \(k_{t+1}\) today, withdraw \((1 + r_{t+1}) k_{t+1}\) tomorrow.
Notice that depreciation does not appear in the household’s budget constraint. Machines do wear out, but that happens inside the firm, and the firm is responsible for it. We will see below how the firm’s cost of capital accounts for depreciation, so the return the household earns, \(r_t\), is already net of depreciation.
The household’s problem is to choose sequences of consumption \(\{c_t\}\) and capital \(\{k_{t+1}\}\) to maximize lifetime utility subject to this budget constraint in every period. This is a dynamic optimization problem: today’s savings decision affects the capital available tomorrow, which affects future income and future choices.
We fix labor supply at \(\ell_t = 1\) (inelastic). The full KP (1982) model includes labor-leisure choice and time-to-build for investment, which generate additional dynamics. The core insights carry through without these features, and the simplified model is considerably easier to solve.
2.1.1 The Household’s Euler Equation
To characterize the household’s optimal saving, substitute consumption from the budget constraint, \(c_t = (1 + r_t) k_t + w_t - k_{t+1}\), into the objective:
\[ \sum_{t=0}^{\infty} \beta^t \log\bigl((1 + r_t) k_t + w_t - k_{t+1}\bigr) \]
The choice \(k_{t+1}\) shows up in exactly two terms of this sum. It lowers consumption in period \(t\) one-for-one, and it raises resources in period \(t+1\) by \(1 + r_{t+1}\). Setting the derivative with respect to \(k_{t+1}\) to zero:
\[ -\beta^t \frac{1}{c_t} + \beta^{t+1} \frac{1 + r_{t+1}}{c_{t+1}} = 0 \]
Dividing by \(\beta^t\) gives the household’s Euler equation:
\[ \boxed{\frac{1}{c_t} = \beta \, \frac{1 + r_{t+1}}{c_{t+1}}} \]
The same condition follows from a perturbation argument. Suppose the household saves one extra unit at \(t\). The cost is one less unit of consumption today, which lowers utility by \(1/c_t\). The benefit is \(1 + r_{t+1}\) extra units of consumption tomorrow, each worth \(1/c_{t+1}\) in utility and discounted by \(\beta\). At the optimum, the household cannot gain by saving a little more or a little less, so cost equals benefit.
Rearranging the Euler equation as \(c_{t+1}/c_t = \beta(1 + r_{t+1})\) shows how the interest rate shapes the consumption path. If \(1 + r_{t+1} > 1/\beta\), the reward for waiting more than compensates for impatience, so the household saves and its consumption grows. If \(1 + r_{t+1} < 1/\beta\), consumption falls over time.
2.2 The Firm
A representative firm produces output using capital and labor according to a Cobb–Douglas production function:
\[ y_t = z_t \, k_t^\alpha \, \ell_t^{1-\alpha} \]
This specification has three components. The variable \(z_t\) is total factor productivity (TFP). For now we hold it constant at \(z_t = 1\); later it becomes the random shock that drives business cycles. When \(z_t\) is high, the same inputs produce more output; when \(z_t\) is low, the economy is less productive. The parameter \(\alpha \in (0,1)\) is capital’s share of output, typically about \(1/3\) based on U.S. national accounts data. The remaining share \((1-\alpha) \approx 2/3\) goes to labor.
The production function exhibits constant returns to scale (CRS): if you double both capital and labor, output exactly doubles. Mathematically, \(f(\lambda k, \lambda \ell) = \lambda f(k, \ell)\) for any \(\lambda > 0\). This ends up being a natural assumption for an aggregate economy. If the U.S. had twice as many workers and twice as many machines, we would expect roughly twice the output.
2.2.1 The Cost of Capital
The firm does not own capital; it rents it from households. Using a unit of capital for one period costs the firm two things:
- Interest: the firm pays the household the interest rate \(r_t\) on each unit it rents.
- Depreciation: production wears out a fraction \(\delta \in (0,1)\) of each machine. The firm must return the capital intact, so it pays to replace the worn-out fraction \(\delta\).
The total cost of using one unit of capital for one period, the rental rate or user cost of capital, is therefore \(r_t + \delta\). The parameter \(\delta\) is the depreciation rate: if \(\delta = 0.10\), then 10% of the machines break down each year and must be replaced just to keep the capital stock constant.
Households earn the interest rate \(r_t\) on their capital; firms pay the rental rate \(r_t + \delta\). The gap \(\delta\) covers the wear and tear that happens inside the firm.
You will often see an equivalent way of writing the model in which the household is paid a rental rate \(R_t\) and bears depreciation itself: \(c_t + k_{t+1} = R_t k_t + (1-\delta) k_t + w_t\). Setting \(R_t = r_t + \delta\) turns this into our budget constraint \(c_t + k_{t+1} = (1 + r_t) k_t + w_t\), so the two descriptions are the same economy. We put depreciation in the firm’s problem so that the household’s return on saving is exactly the real interest rate \(r_t\), the price we can compare to interest rates in the data.
2.2.2 Profit Maximization
The firm rents capital at rate \(r_t + \delta\) and hires labor at wage \(w_t\), taking both prices as given. It chooses inputs to maximize profits:
\[ \pi_t = z_t \, k_t^\alpha \, \ell_t^{1-\alpha} - (r_t + \delta) \, k_t - w_t \, \ell_t \]
The firm’s first-order conditions set the marginal product of each factor equal to its cost. Taking the derivative of profits with respect to \(k_t\) and \(\ell_t\):
\[ \underbrace{\alpha \, z_t \, k_t^{\alpha - 1} \, \ell_t^{1-\alpha}}_{\text{MPK}} = r_t + \delta \qquad\qquad \underbrace{(1-\alpha) \, z_t \, k_t^{\alpha} \, \ell_t^{-\alpha}}_{\text{MPL}} = w_t \]
The rental rate equals the marginal product of capital (MPK) and the wage equals the marginal product of labor (MPL). Each factor is paid exactly what it contributes at the margin. Equivalently, the interest rate equals the marginal product of capital net of depreciation: \(r_t = \text{MPK} - \delta\).
With constant returns to scale, paying each factor its marginal product exactly exhausts output: \((r_t + \delta) k_t + w_t \ell_t = y_t\). The firm earns zero profits in equilibrium. This is Euler’s theorem applied to homogeneous functions. You can verify this directly: \(\alpha z_t k_t^{\alpha} \ell_t^{1-\alpha} + (1-\alpha) z_t k_t^{\alpha} \ell_t^{1-\alpha} = z_t k_t^{\alpha} \ell_t^{1-\alpha} = y_t\).
Since the household supplies \(\ell_t = 1\) unit of labor, the factor prices simplify to:
\[ r_t = \alpha \, z_t \, k_t^{\alpha - 1} - \delta \qquad\qquad w_t = (1-\alpha) \, z_t \, k_t^{\alpha} \]
These expressions reveal two important economic forces. First, the interest rate falls with capital: the exponent \(\alpha - 1 < 0\) means that as the economy accumulates more capital, each additional unit is less productive. This is diminishing returns to capital, and it is what prevents the economy from accumulating capital without bound. Second, the wage rises with capital: more capital per worker means each worker is more productive (they have more machines to work with). Both factor prices move with \(z_t\): once productivity varies, a high \(z_t\) makes every factor of production more valuable.
2.3 Competitive Equilibrium
We now have all the pieces of the model: a household that saves and consumes, and a firm that produces using capital and labor. The next step is to define what it means for these pieces to fit together consistently.
In a competitive equilibrium, every agent optimizes, every market clears, and no one has an incentive to deviate. Formally:
A competitive equilibrium is a sequence of prices \(\{r_t, w_t\}_{t=0}^{\infty}\) and allocations \(\{c_t, k_{t+1}\}_{t=0}^{\infty}\) such that:
- Household optimizes: given prices, the household maximizes lifetime utility subject to its budget constraint \(c_t + k_{t+1} = (1 + r_t) k_t + w_t\)
- Firm optimizes: given prices, the firm’s factor demands satisfy \(r_t + \delta = \text{MPK}\) and \(w_t = \text{MPL}\)
- Markets clear: the labor market clears (\(\ell_t = 1\)), the capital market clears (the firm rents exactly the \(k_t\) households own), and the goods market clears (\(c_t + k_{t+1} - (1-\delta)k_t = y_t\))
The goods market clearing condition says every unit of output is either consumed or invested. Investment is \(i_t = k_{t+1} - (1-\delta)k_t\), which is the new capital created beyond what survives depreciation. There is no government, no foreign trade, and no inventory accumulation, so \(y_t = c_t + i_t\) must hold in every period.
Now here is the key simplification. Substitute the firm’s factor prices into the household’s budget constraint:
\[ c_t + k_{t+1} = \Big(1 + \underbrace{\alpha \, z_t \, k_t^{\alpha-1} - \delta}_{r_t}\Big) \, k_t + \underbrace{(1-\alpha) \, z_t \, k_t^\alpha}_{w_t} \]
Multiplying out the first term gives \(k_t + \alpha z_t k_t^\alpha - \delta k_t\), and adding the wage gives \(k_t - \delta k_t + z_t k_t^\alpha\). The budget constraint collapses to the aggregate resource constraint:
\[ c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t \]
Notice what happened: prices \((r_t, w_t)\) have disappeared entirely. Rental payments plus wages exactly equal total output (zero profits), and the \(\delta k_t\) the firm pays out covers exactly the capital that wore out in production. The household’s budget constraint, once we substitute in the competitive factor prices, is identical to the economy-wide resource constraint (which is also the goods market clearing condition).
The same substitution in the household’s Euler equation gives the equilibrium Euler equation:
\[ \frac{1}{c_t} = \beta \, \frac{1 + \alpha \, z_{t+1} \, k_{t+1}^{\alpha-1} - \delta}{c_{t+1}} \]
Together, the resource constraint and the equilibrium Euler equation are two equations in the two sequences \(\{c_t\}\) and \(\{k_{t+1}\}\): the household’s saving decision meets the firm’s demand for capital. Given initial capital \(k_0\), they pin down the entire equilibrium path. Solving them directly is hard, however, because they link every period to the next and we would need to find an infinite sequence. We start with the easiest case, the steady state, and then use the planner’s problem to compute the full path.
2.4 The Steady State
With productivity constant at \(z = 1\), the economy settles in the long run at a steady state \(k_{ss}\) where \(k_{t+1} = k_t = k_{ss}\). Consumption, the interest rate, and the wage are all constant too. At the steady state, investment exactly replaces worn-out capital (\(i_{ss} = \delta k_{ss}\)) and consumption equals output net of depreciation (\(c_{ss} = k_{ss}^\alpha - \delta k_{ss}\)).
Understanding the steady state helps in three ways:
- It tells us where capital should be on average
- It guides grid construction (we center the capital grid around \(k_{ss}\))
- It provides a starting point for simulation
2.4.1 Deriving the Steady State
The decentralized model splits the steady-state calculation neatly into two steps: the household pins down the interest rate, and the firm pins down the capital stock.
Step 1: the household. In steady state \(c_t = c_{t+1} = c_{ss}\), so the Euler equation becomes
\[ \frac{1}{c_{ss}} = \beta \cdot \frac{1 + r_{ss}}{c_{ss}} \quad\Longrightarrow\quad 1 = \beta(1 + r_{ss}) \quad\Longrightarrow\quad \boxed{r_{ss} = \frac{1}{\beta} - 1} \]
The household is willing to keep its consumption flat only if the interest rate exactly compensates it for its impatience. If \(r > r_{ss}\), it would save more and let consumption grow; if \(r < r_{ss}\), it would save less and let consumption fall. The more patient the household (\(\beta\) closer to 1), the lower the steady-state interest rate. With \(\beta = 0.96\), \(r_{ss} = 1/0.96 - 1 \approx 4.2\%\) per year.
Step 2: the firm. Given \(r_{ss}\), the firm demands capital until its marginal product equals the rental rate:
\[ \alpha \, k_{ss}^{\alpha - 1} = r_{ss} + \delta \quad\Longrightarrow\quad k_{ss} = \left(\frac{\alpha}{r_{ss} + \delta}\right)^{\frac{1}{1-\alpha}} \]
Substituting \(r_{ss} = 1/\beta - 1\), the rental rate is \(r_{ss} + \delta = \bigl(1 - \beta(1-\delta)\bigr)/\beta\), so
\[ \boxed{k_{ss} = \left(\frac{\alpha \beta}{1 - \beta(1-\delta)}\right)^{\frac{1}{1-\alpha}}} \]
A higher rental rate means the firm demands less capital. Anything that raises the rental rate, whether more impatience (a higher \(r_{ss}\)) or faster depreciation (a higher \(\delta\)), lowers the steady-state capital stock.
The household’s budget constraint gives one more useful way to read the steady state. Setting \(k_{t+1} = k_t = k_{ss}\) in \(c_t + k_{t+1} = (1 + r_t) k_t + w_t\) gives
\[ c_{ss} = r_{ss} \, k_{ss} + w_{ss} \]
In steady state the household consumes its income (interest plus wages) and leaves its capital untouched. Meanwhile the firm spends \(\delta k_{ss}\) replacing worn-out machines, which is exactly steady-state investment.
Households keep accumulating capital until the interest rate it earns, \(r_{ss} = \alpha k_{ss}^{\alpha-1} - \delta\) (the marginal product of capital net of depreciation), falls to the household’s rate of impatience \(1/\beta - 1\). At that point, saving one more unit costs exactly as much as it benefits.
4 Linear Interpolation
4.1 Why We Need Interpolation
Before we can solve the planner’s Bellman equation, we need a new computational tool. In the McCall and Rust models, the state space was discrete: we stored the value function as a vector and looked up values by index. If the state was wage offer \(j\), we simply read \(V[j]\) from the vector. No approximation was needed.
In the growth model, capital \(k\) is continuous. We can store \(V\) on a finite grid of \(N_k\) points: \(V(k_1), V(k_2), \ldots, V(k_N)\). But when we optimize the Bellman equation, the optimizer will try many candidate values of \(k'\), and the optimal \(k'\) will almost certainly not land exactly on a grid point. We need to evaluate \(V(k')\) for any \(k'\) in the range, not just the grid values.
Interpolation is the solution: use the known grid values to approximate \(V\) at off-grid points. The idea is simple—if we know the value function at \(k = 3.0\) and \(k = 3.5\), we can make a reasonable guess about its value at \(k = 3.27\) by drawing a straight line between the two known points.
We know \(V\) at the blue dots—but optimization may require \(V(2.7)\), which lies between grid points.
4.2 How Linear Interpolation Works
Given two adjacent grid points \(k_i\) and \(k_{i+1}\) with known values \(V_i\) and \(V_{i+1}\), linear interpolation draws a straight line between them and reads off the value at \(k'\):
\[ V(k') \approx V_i + \frac{k' - k_i}{k_{i+1} - k_i} \cdot (V_{i+1} - V_i) \]
Using the interpolation weight \(w = \frac{k' - k_i}{k_{i+1} - k_i} \in [0,1]\), this becomes a weighted average:
\[ V(k') \approx (1 - w) \cdot V_i + w \cdot V_{i+1} \]
The algorithm has three steps:
- Find the interval: locate \(i\) such that \(k_i \leq k' \leq k_{i+1}\)
- Compute the weight: \(w = \frac{k' - k_i}{k_{i+1} - k_i} \in [0, 1]\)
- Interpolate: \(\hat{V} = (1-w) V_i + w V_{i+1}\)
When \(w = 0\), \(k'\) is exactly at \(k_i\) and \(\hat{V} = V_i\). When \(w = 1\), \(k'\) is at \(k_{i+1}\) and \(\hat{V} = V_{i+1}\). When \(w = 0.5\), \(k'\) is at the midpoint and \(\hat{V}\) is the average.
4.3 Interpolations.jl
We could implement linear interpolation by hand—find the interval, compute the weight, take the weighted average. But Julia’s Interpolations.jl package does all of this automatically and returns an object with clean call syntax that behaves like a function:
# Known grid points
k_demo = [1.0, 2.0, 3.0, 4.0, 5.0]
V_demo = [0.0, 0.7, 1.2, 1.5, 1.6]
V_itp = linear_interpolation(k_demo, V_demo)5-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.0
0.7
1.2
1.5
1.6
The object V_itp behaves like a function: call it with any \(k'\) to get an interpolated value.
V_itp(2.0) # exact grid point → 0.70.7
V_itp(2.5) # midpoint → (0.7 + 1.2)/2 = 0.950.95
V_itp(2.7) # arbitrary point → 0.3×0.7 + 0.7×1.2 = 1.051.05
linear_interpolation(xs, ys) returns a callable object. Writing V_itp(k') is just like calling a function: clean, readable, and exactly what we need inside an optimizer that tries many candidate \(k'\) values.
We can visualize the interpolation object over a fine grid using broadcasting:
k_fine = LinRange(1.0, 5.0, 200)
plot(k_fine, V_itp.(k_fine), linewidth=2, color=:steelblue,
label="V_itp(k)", legend=:bottomright, size=(700, 400))
scatter!(k_demo, V_demo, markersize=8, color=:red, label="Grid points")
xlabel!("k")
ylabel!("V(k)")
title!("Linear Interpolation in Action")The interpolation connects the dots with straight line segments. With more grid points, the piecewise-linear approximation better captures curvature. For smooth economic functions, 100–500 grid points typically give excellent accuracy.
5 Solving the Deterministic Model
The Bellman equation
\[ V(k) = \max_{k'} \left\{ \log(c) + \beta \, V(k') \right\}, \qquad c = k^\alpha + (1-\delta) k - k' \]
is an infinite-horizon, recursive problem, and it can look intimidating. But at its heart is a simple one-period trade-off: consume now or save for later. Our strategy is to boil the Bellman equation down to a problem we can solve in a few lines of Julia, and then iterate that problem to recover \(V\). The same strategy, with the same code at its core, will solve the stochastic model later.
5.1 A Simple Problem
Strip away the complexity. A planner has resources \(R\) to split between consumption \(c\) and savings \(k'\), so \(c + k' = R\). It values consumption today, \(\log(c)\), and capital carried into the future, \(\beta \, v^f(k')\):
\[ \max_{k'} \;\; \log(R - k') \;+\; \beta\, v^f(k') \]
Here \(v^f(k')\) is the value of having capital \(k'\) in the future. Eventually we will have to find this function, but for now we take it as known. We also require the planner to choose \(k'\) inside the range of the capital grid. This simple problem is all we need: once we can solve it, we can solve the entire infinite-horizon Bellman equation.
5.1.1 Solving It in Julia
The problem rarely has a closed form, so we solve it numerically with Optim.jl. Since Optim minimizes by convention, we minimize the negative of the payoff. For a one-dimensional problem with known bounds, optimize(obj, k_min, k_max) uses Brent’s method, a reliable bracketed search that combines the safety of bisection with the speed of inverse quadratic interpolation.
As a first example, suppose the planner places no value on the future, \(v^f(k') = 0\), and has resources \(R = 5\):
#inputs
resources = 5.
vf_zero(kp) = 0.0
#solve for max
obj(kp) = -(log(resources - kp) + m_det.β * vf_zero(kp))
k_max = min(m_det.k_grid[end], resources - 1e-8)
k_min = m_det.k_grid[1]
res = optimize(obj, k_min, k_max, Brent())
(kp = Optim.minimizer(res), c = resources - Optim.minimizer(res), k_min = k_min)(kp = 0.7065758021941072, c = 4.2934241978058925, k_min = 0.7065757834312838)
With no future value, there is no reason to save: the optimizer drives \(k'\) all the way to the lower bound of the grid and the planner consumes nearly everything. The upper bound resources - 1e-8 keeps consumption strictly positive, so log is always defined.
Now give capital a future value of \(\log(k')\):
#inputs
vf_log(kp) = log(kp)
resources = 5.
#solve for max
obj(kp) = -(log(resources - kp) + m_det.β * vf_log(kp)) # same code, new future value
k_max = min(m_det.k_grid[end], resources - 1e-8)
k_min = m_det.k_grid[1]
res = optimize(obj, k_min, k_max)
(kp = Optim.minimizer(res), c = resources - Optim.minimizer(res))(kp = 2.4489795689617475, c = 2.5510204310382525)
The planner now saves, because the future value rewards capital, and the optimum is interior (away from the bounds). With \(\log\) on both sides, the planner splits resources so that \(1/c = \beta/k'\), i.e. \(k' = \beta R/(1+\beta)\).
5.2 The optimal_policy Function
Both examples ran the same code with a different future value, so we wrap that code in a function that takes resources \(R\) and the future value vf as inputs:
function optimal_policy(m, R, vf)
(; β, k_grid) = m
obj(kp) = -(log(R - kp) + β * vf(kp))
k_max = min(k_grid[end], R - 1e-8) #avoid negative consumption
k_min = k_grid[1]
res = optimize(obj, k_min, k_max)
return (V = -Optim.minimum(res),
kp = Optim.minimizer(res),
c = R - Optim.minimizer(res))
endoptimal_policy (generic function with 1 method)
The function returns a named tuple (V, kp, c) with the optimal value, the optimal capital choice, and the implied consumption. Nothing in optimal_policy is specific to the deterministic model: it only needs resources and a callable future value. We will reuse it unchanged once we add shocks.
5.3 Iterating the Bellman Equation
The Bellman equation at capital \(k\) is exactly our simple problem with two substitutions:
\[ R = \underbrace{k^\alpha + (1-\delta)k}_{\text{resources at }k}, \qquad v^f(k') = \underbrace{V(k')}_{\text{continuation value}} \]
So optimal_policy already solves the Bellman equation at a single \(k\), if we can supply \(v^f\). The catch is that \(v^f\) is \(V\) itself, which is what we are trying to find. We need a fixed point: a function \(V\) such that the \(V\) we put into the right-hand side of the Bellman equation is the \(V\) we get out.
There is one more practical issue. optimal_policy needs \(v^f(\cdot)\) as a callable function of \(k'\), but we store \(V\) on a grid: \(V[i] = V(k_i)\). Linear interpolation bridges the gap: linear_interpolation(k_grid, V) turns the grid values into a function we can evaluate at any \(k'\). In the deterministic model, the future value is just the interpolated \(V\).
5.3.1 The Bellman Operator
The bellman_operator function applies one step of value function iteration. It builds \(v^f\) from the current guess \(V\), then calls optimal_policy at every grid point:
function bellman_operator(m::GrowthModel, V)
(; N_k, α, δ, k_grid) = m
V_new = similar(V)
kp_policy = similar(V)
c_policy = similar(V)
vf = linear_interpolation(k_grid, V) # V(k') as a function
for ik in 1:N_k
k = k_grid[ik]
R = k^α + (1 - δ) * k # resources at k
result = optimal_policy(m, R, vf)
V_new[ik] = result.V
kp_policy[ik] = result.kp
c_policy[ik] = result.c
end
return V_new, kp_policy, c_policy
endbellman_operator (generic function with 1 method)
An important efficiency detail: the interpolation object vf is built once per Bellman iteration (before the loop), not once per grid point. The loop itself is straightforward—all the economic and computational heavy lifting happens inside optimal_policy. We also collect the consumption policy directly, since optimal_policy already returns it.
5.3.2 Value Function Iteration
We solve the Bellman equation by value function iteration (VFI), the same approach we used for the McCall and Rust models:
- Start with an initial guess \(V^0(k) = 0\) for all \(k\)
- Apply
bellman_operatorto get \(V^{n+1}\) and the associated policies - Repeat until \(\|V^{n+1} - V^n\|_\infty < \text{tol}\)
The Bellman operator is a contraction mapping with modulus \(\beta\). By the Banach fixed-point theorem, iterating converges to the unique fixed point \(V^*\) at a geometric rate, from any starting guess.
Convergence is measured by the sup norm: the largest change in the value function across all grid points. Once converged, solveGrowth builds interpolation objects for the policy functions so they can be evaluated at any capital level when we simulate:
function solveGrowth(m::GrowthModel;
tol=1e-6, maxiter=1000, verbose=true)
(; k_grid, N_k) = m
V = zeros(N_k) # initial guess: V = 0
V_new, kp_policy, c_policy = bellman_operator(m, V)
#Iterate the Bellman operator until convergence
dist = 1.0
iter = 0
while dist > tol && iter < maxiter
V_new, kp_policy, c_policy = bellman_operator(m, V)
dist = maximum(abs.(V_new - V))
V = V_new
iter += 1
end
if dist < tol && verbose
println("Converged in $iter iterations "*
"(dist = $(round(dist, digits=8)))")
end
#Interpolate the policy functions
kp_itp = linear_interpolation(k_grid, kp_policy)
c_itp = linear_interpolation(k_grid, c_policy)
#Return the solution
return (V=V, kp=kp_policy, c=c_policy,
kp_itp=kp_itp, c_itp=c_itp)
endsolveGrowth (generic function with 1 method)
sol_det = solveGrowth(m_det);Converged in 274 iterations (dist = 9.6e-7)
The deterministic model solves quickly: each iteration requires only one optimization per grid point.
5.4 Results
5.4.1 The Value Function
plot(m_det.k_grid, sol_det.V, linewidth=2, label="V(k)",
legend=:bottomright, size=(700, 400))
vline!([ss.k], color=:gray, linestyle=:dash, label="k_ss")
xlabel!("Capital k")
ylabel!("V(k)")
title!("Value Function (No Shocks)")The value function is increasing in \(k\): more capital means more output, and therefore more consumption both now and in the future. It is also concave, reflecting diminishing returns to capital: the first units of capital are extremely valuable, but additional units contribute less and less.
5.4.2 The Savings Policy \(k'(k)\)
plot(m_det.k_grid, sol_det.kp, linewidth=2, label="k'(k)",
legend=:topleft, size=(700, 400))
plot!(m_det.k_grid, m_det.k_grid, color=:gray, linestyle=:dash, label="45° line")
vline!([ss.k], color=:gray, linestyle=:dot, label="k_ss")
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")
title!("Savings Policy Function (No Shocks)")The 45-degree line (\(k' = k\)) is the reference line where capital stays constant. When the policy function lies above the 45° line, the planner saves more than enough to replace depreciation and capital is growing (\(k' > k\)). When it lies below, capital is shrinking (\(k' < k\)). The policy crosses the 45° line exactly at the analytical steady state \(k_{ss}\): the numerical solution of the Bellman equation agrees with the pencil-and-paper steady state we derived from the household and firm conditions. Since the policy is above the 45° line to the left of \(k_{ss}\) and below it to the right, the economy converges to \(k_{ss}\) from any starting point.
5.4.3 The Consumption Policy \(c(k)\)
plot(m_det.k_grid, sol_det.c, linewidth=2, label="c(k)",
legend=:topleft, size=(700, 400))
vline!([ss.k], color=:gray, linestyle=:dash, label="k_ss")
hline!([ss.c], color=:gray, linestyle=:dot, label="c_ss")
xlabel!("Capital k")
ylabel!("Consumption c(k)")
title!("Consumption Policy Function (No Shocks)")Consumption is increasing in \(k\): richer economies consume more. At \(k_{ss}\), the planner consumes exactly \(c_{ss}\).
5.5 Transition to the Steady State
The policy function tells us what happens in a single period. To see how the economy evolves over time, we start it away from the steady state and repeatedly apply the policy, \(k_{t+1} = k'(k_t)\). Along the way we compute output, consumption, and investment, and we use the firm’s first-order conditions to back out the prices that would support this allocation in a competitive equilibrium: \(r_t = \alpha k_t^{\alpha-1} - \delta\) and \(w_t = (1-\alpha) k_t^\alpha\).
function simulateGrowth(m::GrowthModel, sol, k_0, T)
(; α, δ) = m
k_sim = zeros(T); y_sim = zeros(T); c_sim = zeros(T); i_sim = zeros(T)
r_sim = zeros(T); w_sim = zeros(T)
k_sim[1] = k_0 # initial capital
for t in 1:T
kp = sol.kp_itp(k_sim[t]) # interpolated policy
y_sim[t] = k_sim[t]^α
c_sim[t] = y_sim[t] + (1-δ)*k_sim[t] - kp
i_sim[t] = kp - (1-δ)*k_sim[t]
r_sim[t] = α * k_sim[t]^(α-1) - δ # firm: r = MPK - δ
w_sim[t] = (1-α) * k_sim[t]^α # firm: w = MPL
if t < T
k_sim[t+1] = kp
end
end
return DataFrame(t=0:T-1, k=k_sim, y=y_sim, c=c_sim,
i=i_sim, r=r_sim, w=w_sim)
endsimulateGrowth (generic function with 1 method)
Since kp_itp is an interpolation object, sol.kp_itp(k_sim[t]) evaluates the policy at the current capital level even when it is not on the grid. We store the results in a DataFrame (from DataFrames.jl): a table with one row per period and one column per variable, which makes the path easy to inspect, plot, and analyze.
Suppose the economy starts with half its steady-state capital stock, as it might after a war destroyed much of its capital:
sim_det = simulateGrowth(m_det, sol_det, 0.5 * ss.k, 60)
first(sim_det, 6)| Row | t | k | y | c | i | r | w |
|---|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 0 | 1.76644 | 1.20654 | 0.803842 | 0.4027 | 0.125402 | 0.808383 |
| 2 | 1 | 1.9925 | 1.25545 | 0.855771 | 0.399684 | 0.10793 | 0.841155 |
| 3 | 2 | 2.19293 | 1.2958 | 0.899823 | 0.395978 | 0.0949967 | 0.868186 |
| 4 | 3 | 2.36962 | 1.32936 | 0.937026 | 0.392338 | 0.0851313 | 0.890673 |
| 5 | 4 | 2.52499 | 1.35752 | 0.969221 | 0.388297 | 0.0774189 | 0.909537 |
| 6 | 5 | 2.66079 | 1.38119 | 0.996414 | 0.384776 | 0.0712998 | 0.925397 |
5.5.1 Quantities
p1 = plot(sim_det.t, sim_det.k, linewidth=2, label="", title="Capital")
hline!(p1, [ss.k], color=:gray, linestyle=:dash, label="")
p2 = plot(sim_det.t, sim_det.y, linewidth=2, label="", title="Output")
hline!(p2, [ss.y], color=:gray, linestyle=:dash, label="")
p3 = plot(sim_det.t, sim_det.c, linewidth=2, label="", title="Consumption")
hline!(p3, [ss.c], color=:gray, linestyle=:dash, label="")
p4 = plot(sim_det.t, sim_det.i, linewidth=2, label="", title="Investment")
hline!(p4, [ss.i], color=:gray, linestyle=:dash, label="")
plot(p1, p2, p3, p4, layout=(2, 2), size=(800, 500), xlabel="Period")Capital climbs gradually toward \(k_{ss}\) (dashed lines), growing fastest when it is scarce and slowing as it approaches the steady state. Because capital is a stock, it takes many periods of investment to rebuild it. Output follows capital. Consumption rises smoothly: the household would like to consume more right away, but it is willing to postpone consumption while capital is productive. Investment starts above its steady-state level, because the return to building capital is high when capital is scarce, and falls back toward \(\delta k_{ss}\) as the capital stock is rebuilt.
5.5.2 Prices
p1 = plot(sim_det.t, 100 .* sim_det.r, linewidth=2, label="",
title="Interest rate r (%)")
hline!(p1, [100 * ss.r], color=:gray, linestyle=:dash, label="")
p2 = plot(sim_det.t, sim_det.w, linewidth=2, label="", title="Wage w")
hline!(p2, [ss.w], color=:gray, linestyle=:dash, label="")
plot(p1, p2, layout=(1, 2), size=(800, 350), xlabel="Period", bottom_margin=5Plots.mm)The prices tell the same story from the market’s point of view. When capital is scarce, its marginal product is high, so the firm is willing to pay a high interest rate. As capital accumulates, diminishing returns push \(r_t\) down toward \(r_{ss} = 1/\beta - 1\), while the wage rises toward \(w_{ss}\) because each worker has more machines to work with. The high interest rate early in the transition is exactly what makes the household willing to save and postpone consumption.
5.5.3 Checking the Household’s Euler Equation
The planner never saw a price. If the First Welfare Theorem holds, its allocation should nonetheless satisfy the household’s Euler equation at the interest rate the firm would pay:
\[ \frac{c_{t+1}}{c_t} = \beta \, (1 + r_{t+1}) \]
We can check this along the simulated transition by comparing consumption growth from the planner’s solution to the right-hand side computed from the firm’s interest rate:
growth_c = sim_det.c[2:end] ./ sim_det.c[1:end-1] # c_{t+1}/c_t from the planner
growth_euler = m_det.β .* (1 .+ sim_det.r[2:end]) # β(1 + r_{t+1}) from the firm
println("Largest gap: ", round(maximum(abs.(growth_c .- growth_euler)), sigdigits=2))
plot(sim_det.t[1:end-1], growth_c, linewidth=2, label="c'/c (planner)",
size=(700, 350), legend=:topright)
plot!(sim_det.t[1:end-1], growth_euler, linewidth=2, linestyle=:dash,
label="β(1 + r') (household Euler)")
xlabel!("Period")
title!("Consumption Growth Along the Transition")Largest gap: 0.00099
The two lines coincide, up to a small approximation error that comes from solving the Bellman equation on a grid. The planner’s allocation is the competitive equilibrium: at the prices implied by the firm’s first-order conditions, the household would choose exactly the consumption path the planner chose. Consumption grows while \(r_{t+1} > r_{ss}\) and stops growing as the interest rate falls to \(r_{ss}\).
6 Adding Productivity Shocks
Without shocks, the economy glides smoothly to its steady state and stays there: there are no business cycles. To generate fluctuations, we now let productivity \(z_t\) vary randomly over time. Most of the model, and most of our code, carries over unchanged.
6.1 Technology Shocks
What drives business cycles in this model? The answer is total factor productivity (TFP), \(z_t\). Some periods the economy is highly productive: new technologies diffuse, weather is favorable, supply chains run smoothly. Other periods it is less so. The RBC model takes the position that these productivity fluctuations are the primary source of aggregate fluctuations.
Productivity follows an AR(1) process in logs:
\[ \log z_{t+1} = \rho \, \log z_t + \sigma_\varepsilon \, \varepsilon_{t+1}, \qquad \varepsilon_{t+1} \sim N(0, 1) \]
The parameter \(\rho \in (0,1)\) governs the persistence of technology shocks. With \(\rho = 0.90\), a 1% productivity innovation today still predicts a \(0.90^4 \approx 0.66\%\) deviation four periods later. This persistence is critical: if shocks were purely temporary (\(\rho = 0\)), they would cause one-period blips in output, not the sustained expansions and contractions we observe in the data. It is the persistence of productivity shocks that turns one-period disturbances into multi-period business cycles.
The parameter \(\sigma_\varepsilon\) controls the volatility of innovations: how large the surprises are in each period. The typical estimate of \(\sigma_\varepsilon \approx 0.02\) means that a one-standard-deviation shock moves productivity by about 2%. This may sound small, but because the shocks are persistent and the economy amplifies them through savings and investment responses, the resulting output fluctuations end up being comparable to what we see in the data.
Why model TFP as an AR(1)? First, it is empirically grounded: regressing the Solow residual on its own lag yields a tight fit with high \(R^2\). Second, the AR(1) is parsimonious: it captures both the volatility and persistence of productivity with just two parameters. Third, the process is stationary when \(|\rho| < 1\), so the model has a well-defined long-run distribution around which business cycles fluctuate.
The AR(1) process for \(\log z_t\) is continuous: \(z_t\) can take any positive value. To solve the model on a computer, we discretize this process into a finite-state Markov chain with \(S\) states and a transition matrix \(P\), just like we studied in the Markov chain lectures. This lets us compute the conditional expectation \(\mathbb{E}[V(k', s') \mid s]\) as a finite sum \(\sum_{s'=1}^{S} P_{s,s'} V(k', s')\) using the Markov chain tools we’ve developed.
6.1.1 Discretizing the AR(1): Rouwenhorst Method
The AR(1) process for \(\log z_t\) is continuous, but our Bellman equation requires computing expectations as finite sums over a Markov chain. We need to approximate the continuous process with an \(N\)-state Markov chain that captures its persistence and volatility.
The Rouwenhorst (1995) method does this in two steps:
- Grid construction: create an evenly spaced grid for \(\log z\) spanning \(\pm\sqrt{N-1} \cdot \sigma_z\), where \(\sigma_z = \sigma_\varepsilon / \sqrt{1 - \rho^2}\) is the unconditional standard deviation of the process. This ensures the grid covers the same range as the true stationary distribution.
- Transition matrix: build \(P\) recursively, starting from a \(2 \times 2\) base case with parameter \(p = (1+\rho)/2\). Each recursion step adds one state by combining four shifted copies of the previous matrix. The resulting transition matrix captures the AR(1) persistence exactly for any \(N\).
Why Rouwenhorst over the more common Tauchen (1986) method? Rouwenhorst performs much better for highly persistent processes (\(\rho\) close to 1), which is exactly the empirically relevant case for RBC models. Tauchen’s method can severely understate the persistence of the discretized process when \(\rho > 0.9\), leading to business cycles that are too short-lived.
function rouwenhorst(N, ρ, σ_ε)
σ_z = σ_ε / sqrt(1 - ρ^2) # unconditional std dev
p = (1 + ρ) / 2 # persistence parameter
P = [p 1-p; 1-p p] # base case: N = 2
for n in 3:N # recursively expand
z = zeros(n - 1)
P = p * [P z; z' 0] +
(1-p) * [z P; 0 z'] +
(1-p) * [z' 0; P z] +
p * [0 z'; z P]
P[2:end-1, :] ./= 2 # normalize interior rows
end
z_grid = collect(LinRange(
-sqrt(N-1) * σ_z,
sqrt(N-1) * σ_z, N))
return z_grid, P
endrouwenhorst (generic function with 1 method)
Let’s test the function with a 7-state approximation using the calibrated parameter values (\(\rho = 0.90\), \(\sigma_\varepsilon = 0.02\)). The function returns the grid in log levels, so we exponentiate to get the productivity levels \(\bar z_s\):
log_z_grid, P_z = rouwenhorst(7, 0.90, 0.02)
z_grid = exp.(log_z_grid) # convert to levels
round.(z_grid, digits=4)7-element Vector{Float64}:
0.8937
0.9278
0.9632
1.0
1.0382
1.0778
1.1189
The seven productivity states range from about 0.89 (a deep recession) to about 1.12 (a strong boom), centered at 1.0 (average productivity). These fluctuations of roughly \(\pm 10\%\) around the mean are consistent with the range of Solow residual variation in U.S. data.
The transition matrix shows how likely the economy is to move between productivity states:
round.(P_z, digits=3)7×7 Matrix{Float64}:
0.735 0.232 0.031 0.002 0.0 0.0 0.0
0.039 0.745 0.195 0.02 0.001 0.0 0.0
0.002 0.078 0.751 0.156 0.012 0.0 0.0
0.0 0.006 0.117 0.753 0.117 0.006 0.0
0.0 0.0 0.012 0.156 0.751 0.078 0.002
0.0 0.0 0.001 0.02 0.195 0.745 0.039
0.0 0.0 0.0 0.002 0.031 0.232 0.735
The high diagonal values (the probability of staying in the same state next period) confirm that the economy tends to remain near its current productivity level. This persistence is exactly what we need: a good shock today predicts good productivity tomorrow, generating the sustained expansions and contractions we observe in the data.
heatmap(P_z,
xlabel="Next State", ylabel="Current State",
title="Transition Matrix for Productivity",
color=:viridis, yflip=true)6.2 The Stochastic Growth Model
6.2.1 What Changes with Shocks?
Remarkably little. The household now maximizes expected lifetime utility,
\[ \max_{\{c_t, k_{t+1}\}} \; \mathbb{E}_0 \sum_{t=0}^{\infty} \beta^t \log(c_t) \]
where \(\mathbb{E}_0\) denotes the expectation conditional on information available at time 0: the household does not know future productivity but makes the best plan given what it does know. The budget constraint and the firm’s first-order conditions are unchanged, because they hold period by period:
\[ c_t + k_{t+1} = (1 + r_t) k_t + w_t, \qquad r_t = \alpha z_t k_t^{\alpha-1} - \delta, \qquad w_t = (1-\alpha) z_t k_t^\alpha \]
What is new is that when the household saves at \(t\), it does not know the interest rate it will earn, because \(r_{t+1}\) depends on next period’s productivity \(z_{t+1}\). The same perturbation argument as before now compares the certain cost \(1/c_t\) to the expected discounted benefit:
\[ \frac{1}{c_t} = \beta \, \mathbb{E}_t\left[ \frac{1 + r_{t+1}}{c_{t+1}} \right] \]
Substituting the factor prices into the budget constraint still yields the aggregate resource constraint \(c_t + k_{t+1} = z_t k_t^\alpha + (1-\delta) k_t\), now with random \(z_t\). The First Welfare Theorem still applies (markets are complete because there is a single representative household), so we can again compute the competitive equilibrium by solving the planner’s problem.
6.2.2 The Planner’s Bellman Equation
Given initial conditions \((k_0, z_0)\), the planner now maximizes expected lifetime utility:
\[ \max_{\{c_t,\, k_{t+1}\}_{t=0}^{\infty}} \; \mathbb{E}_0 \sum_{t=0}^{\infty} \beta^t \log(c_t) \quad \text{subject to} \quad c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t \]
Productivity follows the finite-state Markov chain from Rouwenhorst. Let \(\bar z_1, \ldots, \bar z_S\) denote the \(S\) possible productivity values and let \(s_t \in \{1, \ldots, S\}\) be the index of the current state, so \(z_t = \bar z_{s_t}\). The transition matrix is \(P_{s, s'} = \Pr(s_{t+1} = s' \mid s_t = s)\).
The same splitting argument as in the deterministic case applies: today’s choice plus a continuation problem that starts from \((k_1, s_1)\). The Markov property is key here: the distribution of future productivity depends only on \(s_1\), not on the whole history of shocks, so the continuation problem has the same form as the original. The state of the economy is now the pair \((k, s)\): current capital and the current productivity index. The Bellman equation is:
\[ V(k, s) = \max_{k'} \left\{ \log\left(\bar z_s k^\alpha + (1-\delta) k - k'\right) + \beta \, \mathbb{E}\left[V(k', s') \mid s\right] \right\} \]
subject to \(0 < k' < \bar z_s k^\alpha + (1-\delta) k\). The conditional expectation is a sum over the Markov chain:
\[ \mathbb{E}\left[V(k', s') \mid s\right] = \sum_{s'=1}^{S} P_{s, s'} \, V(k', s') \]
The following table compares the RBC planner’s problem to the models we have solved previously:
| McCall | Rust | RBC | |
|---|---|---|---|
| State | Wage offer (discrete) | Mileage (discrete) | Capital \(\times\) Productivity |
| Choice | Accept/Reject | Replace/Keep | How much to save |
| State space | Finite | Finite | Continuous \(\times\) Finite |
| Continuation | \(\sum_j P_{ij} V_j\) | \(\sum_j F_{ij} V_j\) | \(\sum_{s'} P_{s,s'} V(k', s')\) |
The key difference is in the last row. In McCall and Rust, the continuation value was a simple weighted sum over a finite vector. In the RBC model, the continuation value involves \(V(k', s')\) where \(k'\) is a continuous variable that will generally not fall on a grid point, which is why we still need interpolation.
6.3 Solving the Stochastic Model
6.3.1 Reusing the Deterministic Solver
The stochastic Bellman equation is still our simple problem. At state \((k, s)\) the planner splits resources \(R\) between consumption and capital, valuing capital at \(v^f(k')\), where now
\[ R = \underbrace{\bar z_s \, k^\alpha + (1-\delta)k}_{\text{resources at }(k,\,s)}, \qquad v^f(k') = \underbrace{\mathbb{E}\big[V(k', s') \mid s\big]}_{\text{expected continuation value}} \]
This means optimal_policy(m, R, vf) works unchanged: only its inputs change. Three things are new:
- The state is \((k, s)\), so the value function becomes a matrix: \(V[i, s] = V(k_i, s)\).
- The future value \(v^f\) is an expectation over next period’s productivity, not just the interpolated \(V\).
- The model must store the productivity grid and the transition matrix.
6.3.2 The RBCModel Struct
The stochastic model needs the parameters of the productivity process and the Markov chain that approximates it, so we define a new struct:
@kwdef mutable struct RBCModel
β::Float64 = 0.96 # discount factor
α::Float64 = 0.33 # capital share
δ::Float64 = 0.10 # depreciation rate
ρ::Float64 = 0.90 # TFP persistence
σ_ε::Float64 = 0.02 # TFP innovation std dev
N_z::Int = 7 # productivity states
N_k::Int = 200 # capital grid points
z_grid::Vector{Float64} = Float64[] # filled by setup!
P_z::Matrix{Float64} = zeros(0,0) # filled by setup!
k_grid::Vector{Float64} = Float64[] # filled by setup!
endRBCModel
Compared to GrowthModel, RBCModel adds the shock parameters (\(\rho\), \(\sigma_\varepsilon\), \(N_z\)) and two computed objects: the productivity grid z_grid and transition matrix P_z. We also use a coarser capital grid (\(N_k = 200\)): with 7 productivity states, each Bellman iteration solves 7 times as many optimization problems, so computational cost becomes a real concern.
The setup! function for the stochastic model discretizes productivity and builds the capital grid:
function setup!(m::RBCModel)
(; ρ, σ_ε, N_z, N_k) = m
# Discretize productivity
log_z, P = rouwenhorst(N_z, ρ, σ_ε)
m.z_grid = exp.(log_z)
m.P_z = P
# Capital grid centered on (deterministic) steady state
k_ss = steady_state(m).k
m.k_grid = collect(LinRange(0.2k_ss, 1.8k_ss, N_k))
return m
endsetup! (generic function with 2 methods)
We now have two functions named setup!: one whose argument is a GrowthModel and one whose argument is an RBCModel. Julia keeps both as separate methods of the same function and, every time setup! is called, picks the method that matches the type of its argument. This is called multiple dispatch, and it lets us use the same natural name for the same task across different models. We will do the same with bellman_operator. Notice also that steady_state is reused as-is: the deterministic steady state (with \(z = 1\)) is still the natural center for the capital grid.
m = setup!(RBCModel()) # create with defaults and set upRBCModel(0.96, 0.33, 0.1, 0.9, 0.02, 7, 200, [0.8936953824472262, 0.927811339397771, 0.9632296400120643, 1.0, 1.0381740329206182, 1.0778053226306605, 1.118949498498781], [0.7350918906249998 0.23213428125000016 … 1.781250000000008e-6 1.5625000000000085e-8; 0.03868904687500002 0.74527321875 … 2.82187500000001e-5 2.968750000000013e-7; … ; 2.968750000000013e-7 2.8218750000000093e-5 … 0.74527321875 0.03868904687500002; 1.5625000000000085e-8 1.781250000000008e-6 … 0.23213428125000016 0.7350918906249998], [0.7065757834312838, 0.7349808400516369, 0.7633858966719901, 0.7917909532923432, 0.8201960099126963, 0.8486010665330495, 0.8770061231534025, 0.9054111797737555, 0.9338162363941087, 0.9622212930144619 … 6.103536541298375, 6.131941597918729, 6.160346654539082, 6.188751711159434, 6.217156767779788, 6.245561824400141, 6.2739668810204945, 6.302371937640848, 6.3307769942612, 6.359182050881554])
Let’s inspect what setup! produced:
println("z_grid: ", round.(m.z_grid, digits=4))
k1 = round(m.k_grid[1], digits=3)
kN = round(m.k_grid[end], digits=3)
println("k_grid: [$k1, ..., $kN]")
println("N_k = $(m.N_k) grid points")z_grid: [0.8937, 0.9278, 0.9632, 1.0, 1.0382, 1.0778, 1.1189]
k_grid: [0.707, ..., 6.359]
N_k = 200 grid points
The productivity grid matches what we computed above, and the capital grid runs from well below to well above the steady state.
6.3.3 The Expected Continuation Value
optimal_policy needs \(v^f(\cdot)\) as a callable function of \(k'\), but now \(V\) is stored as a matrix with \(V[i, s'] = V(k_i, s')\). We build \(v^f\) for a given current state \(s\) in two steps. First, compute the expected continuation value at every capital grid point:
\[ \mathbb{E}V[i', s] \;=\; \sum_{s'=1}^{S} P_{s, s'} \, V[i', s'] \]
Second, interpolate these values over the capital grid to get a function we can evaluate at any \(k'\). The function compute_vf does both:
function compute_vf(m, V, s)
(; k_grid, P_z) = m
Nk = length(k_grid)
S = length(P_z[s, :])
EV_s = zeros(Nk) # E[V(k', s') | s] on the grid
for i′ in 1:Nk
EV_s[i′] = sum(P_z[s, s′] * V[i′, s′] for s′ in 1:S)
end
#construct the interpolated callable function
return linear_interpolation(k_grid, EV_s)
endcompute_vf (generic function with 1 method)
In the deterministic model, \(v^f\) was simply linear_interpolation(k_grid, V). Now we take the expectation over \(s'\) first and then interpolate. Taking the expectation on the grid and interpolating the result is the same as interpolating each column of \(V\) and then taking the expectation, because linear interpolation is itself a weighted average, but it is cheaper: we interpolate one vector instead of \(S\) of them.
6.3.4 The Bellman Operator
The stochastic bellman_operator has the same structure as the deterministic one, with one extra loop over the current productivity state:
function bellman_operator(m::RBCModel, V)
(; N_k, N_z, α, δ, z_grid, k_grid) = m
V_new = similar(V)
kp_policy = similar(V)
c_policy = similar(V)
for s in 1:N_z
vf = compute_vf(m, V, s) # E[V(k', s')|s] as a function
z = z_grid[s]
for ik in 1:N_k
k = k_grid[ik]
R = z * k^α + (1 - δ) * k # resources at (k, s)
result = optimal_policy(m, R, vf)
V_new[ik, s] = result.V
kp_policy[ik, s] = result.kp
c_policy[ik, s] = result.c
end
end
return V_new, kp_policy, c_policy
endbellman_operator (generic function with 2 methods)
For each productivity state \(s\), compute_vf builds the expected continuation value once, and we reuse it for all \(N_k\) capital levels. For each capital level we form resources and hand \((R, v^f)\) to the same optimal_policy we used in the deterministic model. Multiple dispatch ensures that bellman_operator(m, V) calls this method when m is an RBCModel and the deterministic method when m is a GrowthModel.
6.3.5 Solving the Model
solveRBC is the same iteration loop as solveGrowth. The only differences are that the initial guess \(V = 0\) is now an \(N_k \times N_z\) matrix and that we build one interpolated policy function for each productivity state:
function solveRBC(m::RBCModel;
tol=1e-6, maxiter=1000, verbose=true)
(; k_grid, N_k, N_z) = m
V = zeros(N_k, N_z) # initial guess: V = 0
V_new, kp_policy, c_policy = bellman_operator(m, V)
#Iterate the Bellman operator until convergence
dist = 1.0
iter = 0
while dist > tol && iter < maxiter
V_new, kp_policy, c_policy = bellman_operator(m, V)
dist = maximum(abs.(V_new - V))
V = V_new
iter += 1
end
if dist < tol && verbose
println("Converged in $iter iterations "*
"(dist = $(round(dist, digits=8)))")
end
#Interpolate the policy functions
kp_itp = [linear_interpolation(k_grid, kp_policy[:, s])
for s in 1:N_z]
c_itp = [linear_interpolation(k_grid, c_policy[:, s])
for s in 1:N_z]
#Return the solution
return (V=V, kp=kp_policy, c=c_policy,
kp_itp=kp_itp, c_itp=c_itp)
endsolveRBC (generic function with 1 method)
m = setup!(RBCModel())
sol = solveRBC(m);Converged in 274 iterations (dist = 9.7e-7)
VFI takes a moment because each Bellman iteration solves \(N_k \times N_z\) optimization problems. More efficient methods exist (policy iteration, endogenous grid method), but VFI with interpolation is the clearest to understand.
7 Calibration
7.1 Why Calibrate?
The model has five parameters: \((\alpha, \beta, \delta, \rho, \sigma_\varepsilon)\). How do we choose their values? In many areas of economics, we would estimate parameters econometrically: maximizing a likelihood function or minimizing a distance metric. The RBC literature instead calibrates: it picks parameter values so that the model’s steady state matches long-run averages in the data.
The key principle behind calibration is separation of evidence. We use well-established long-run facts (growth accounting, interest rates, investment rates) to pin down the parameters, and then ask whether the model (without any further tuning) can reproduce business cycle fluctuations it was not calibrated to match. If the model generates realistic output volatility, consumption smoothing, and investment volatility using only parameters that match long-run averages, that is strong evidence that the model captures something real about how the economy works.
Calibration is not estimation. We are not maximizing a likelihood or minimizing a distance from the data. We are using economic theory to set each parameter at a value consistent with a specific, well-established long-run fact, and then evaluating the model on its ability to reproduce short-run dynamics. This makes the exercise a genuine test of the model: can a few structural parameters, pinned down by slow-moving averages, explain fast-moving business cycle fluctuations?
7.2 Matching Long-Run Moments
Each parameter is pinned down by a different data moment, as summarized in the table:
| Parameter | Target | Data Source | Value |
|---|---|---|---|
| \(\alpha\) | Capital’s share of income | National accounts: \((r + \delta)K/Y \approx 1/3\) | 0.33 |
| \(\beta\) | Real interest rate | \(r = 1/\beta - 1 \approx 4\%\)/yr | 0.96 |
| \(\delta\) | Investment–capital ratio | \(I/K \approx 10\%\)/yr | 0.10 |
- \(\alpha = 0.33\): The National Income and Product Accounts (NIPA) decompose national income into compensation of employees and returns to capital. Labor’s share of income has historically averaged approximately \(2/3\) in the United States, so capital’s share, the rental payments \((r + \delta)K\) as a fraction of output, is approximately \(1/3\). In the Cobb–Douglas production function, capital’s share is exactly \(\alpha\), so we set \(\alpha = 0.33\).
- \(\beta = 0.96\): The household’s steady-state Euler equation gives \(r_{ss} = 1/\beta - 1\). The average annual real return on capital in the U.S. is about 4%, so \(\beta = 1/(1 + r_{ss}) = 1/1.04 \approx 0.96\). A discount factor of 0.96 means the household values a dollar next year at 96 cents today.
- \(\delta = 0.10\): The Bureau of Economic Analysis estimates that the aggregate capital stock depreciates at roughly 10% per year. This means that about 10% of all machines, buildings, and equipment must be replaced each year just to keep the capital stock constant.
7.3 The Productivity Process
The remaining two parameters, \(\rho\) and \(\sigma_\varepsilon\), govern the stochastic productivity process. Unlike \(\alpha\), \(\beta\), and \(\delta\), which come from long-run averages, these are estimated directly from time-series data.
The procedure starts by constructing the Solow residual: the part of output that cannot be explained by measured inputs. Given the production function \(Y_t = z_t K_t^\alpha L_t^{1-\alpha}\), we can back out productivity as:
\[ \log z_t = \log Y_t - \alpha \log K_t - (1-\alpha) \log L_t \]
With data on output (\(Y_t\)), the capital stock (\(K_t\)), and hours worked (\(L_t\)), and using our calibrated \(\alpha = 0.33\), we compute the Solow residual series. Regressing \(\log z_t\) on \(\log z_{t-1}\) by OLS gives:
- \(\hat{\rho} \approx 0.90\): productivity shocks are very persistent: a 1% shock today still predicts a 0.81% deviation two periods later (\(0.9^2 \approx 0.81\))
- \(\hat{\sigma}_\varepsilon \approx 0.02\): innovations are small (about 2% of output per period)
r_impl = round(1/m.β - 1, digits=3)
println("Calibrated Parameters:")
println(" α = $(m.α) (capital share)")
println(" β = $(m.β) (discount factor → r ≈ $r_impl)")
println(" δ = $(m.δ) (depreciation rate)")
println(" ρ = $(m.ρ) (TFP persistence)")
println(" σ_ε = $(m.σ_ε) (TFP innovation std dev)")Calibrated Parameters:
α = 0.33 (capital share)
β = 0.96 (discount factor → r ≈ 0.042)
δ = 0.1 (depreciation rate)
ρ = 0.9 (TFP persistence)
σ_ε = 0.02 (TFP innovation std dev)
KY = round(ss.k / ss.y, digits=2)
IY = round(ss.i / ss.y, digits=2)
CY = round(ss.c / ss.y, digits=2)
println("Implied Steady State:")
println(" K/Y = $KY (data: ≈ 3.0)")
println(" I/Y = $IY (data: ≈ 0.25-0.30)")
println(" C/Y = $CY (data: ≈ 0.65-0.70)")Implied Steady State:
K/Y = 2.33 (data: ≈ 3.0)
I/Y = 0.23 (data: ≈ 0.25-0.30)
C/Y = 0.77 (data: ≈ 0.65-0.70)
- Match \(\alpha\) from factor shares in national income accounts
- Match \(\beta\) and \(\delta\) from long-run interest rates and investment rates
- Match \(\rho\) and \(\sigma_\varepsilon\) from the estimated Solow residual process
- Then ask: does the model reproduce business cycle statistics it was not calibrated to match?
7.4 Results
With the stochastic model solved, we can inspect the value and policy functions to understand how the planner responds to productivity. We plot each function for three productivity levels: low (\(s = 1\), the worst state), median (\(s = 4\), where \(z = 1\)), and high (\(s = 7\), the best state).
7.4.1 The Value Function
plot(legend=:bottomright, size=(700, 400))
for s in [1, 4, 7]
plot!(m.k_grid, sol.V[:, s], linewidth=2,
label="z = $(round(m.z_grid[s], digits=3))")
end
xlabel!("Capital k")
ylabel!("V(k, s)")
title!("Value Function")
vline!([ss.k], color=:gray, linestyle=:dash, label="k_ss")Several features stand out. First, higher productivity \(z\) shifts the value function upward: more output at every capital level means the planner can achieve higher lifetime utility. Second, the value function is concave in \(k\), just as in the deterministic model. Third, the curves are relatively close together, which makes sense because productivity shocks are moderate (\(\pm 10\%\)) and temporary.
7.4.2 The Savings Policy \(k'(k, s)\)
plot(legend=:topleft, size=(700, 400))
for s in [1, 4, 7]
plot!(m.k_grid, sol.kp[:, s], linewidth=2,
label="z = $(round(m.z_grid[s], digits=3))")
end
plot!(m.k_grid, m.k_grid, color=:gray, linestyle=:dash, label="45° line")
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")
title!("Savings Policy Function")
vline!([ss.k], color=:gray, linestyle=:dot, label="")Notice how the policy functions shift with productivity. Higher \(z\) means more output, which means the planner has more resources and saves more at every capital level. The high-\(z\) policy function crosses the 45° line at a higher capital level than the low-\(z\) function. This captures an important intuition: during a boom (high \(z\)), the economy accumulates capital; during a recession (low \(z\)), it runs down its capital stock. Because productivity keeps changing, capital never settles down; it keeps chasing a moving target.
7.4.3 Shocks vs. No Shocks
How does uncertainty itself change behavior? We can compare the stochastic savings policy at average productivity (\(z = 1\)) to the deterministic policy, in which \(z = 1\) forever:
plot(m.k_grid, sol.kp[:, 4], linewidth=2,
label="With shocks, z = $(round(m.z_grid[4], digits=3))",
legend=:topleft, size=(700, 400))
plot!(m.k_grid, sol_det.kp_itp.(m.k_grid), linewidth=2, linestyle=:dash,
label="No shocks (z = 1 forever)")
plot!(m.k_grid, m.k_grid, color=:gray, linestyle=:dot, label="45° line")
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")
title!("Savings Policy: With and Without Shocks")The two policies are nearly identical. With log utility and shocks of a few percent, the mere possibility of future shocks barely changes how much the planner saves (there is very little precautionary saving). What drives fluctuations is the realized productivity, which shifts the policy up in booms and down in recessions.
7.4.4 The Consumption Policy \(c(k, s)\)
plot(legend=:topleft, size=(700, 400))
for s in [1, 4, 7]
plot!(m.k_grid, sol.c[:, s], linewidth=2,
label="z = $(round(m.z_grid[s], digits=3))")
end
xlabel!("Capital k")
ylabel!("Consumption c(k, s)")
title!("Consumption Policy Function")
vline!([ss.k], color=:gray, linestyle=:dash, label="k_ss")Consumption is increasing in both \(k\) and \(z\). Richer economies (higher \(k\)) and more productive economies (higher \(z\)) consume more. Importantly, when productivity is high, the planner can afford to both consume more and save more simultaneously: the extra output is split between current consumption and future capital. The consumption function is relatively smooth and nearly linear, reflecting the household’s desire to smooth consumption over time rather than responding dramatically to each productivity realization.
7.4.5 The Investment Policy
i_policy = sol.kp .- (1 - m.δ) .* m.k_grid # i = k' - (1-δ)k
plot(legend=:topleft, size=(700, 400))
for s in [1, 4, 7]
plot!(m.k_grid, i_policy[:, s], linewidth=2,
label="z = $(round(m.z_grid[s], digits=3))")
end
xlabel!("Capital k")
ylabel!("Investment i(k, s)")
title!("Investment Policy Function")
hline!([m.δ * ss.k], color=:gray, linestyle=:dash, label="Steady state i")Investment responds much more strongly to productivity than consumption does. The gap between the high-\(z\) and low-\(z\) investment curves is large relative to the corresponding gap for consumption. Why? Because consumption smoothing means the household absorbs productivity shocks mainly through the investment margin. When \(z\) is high, the household consumes a bit more but channels most of the extra output into investment. When \(z\) is low, the household cuts investment sharply to protect its consumption. This asymmetry between consumption and investment responses foreshadows a key business cycle fact: investment is the most volatile component of GDP.
8 Simulation
8.1 Simulating the Economy
Solving the model gives us policy functions: for any \((k, s)\), we know the optimal \(k'\), \(c\), and \(i\). But to understand what the model implies for business cycles, we need to see these policies in action. Simulation generates artificial time series—period-by-period paths of output, consumption, investment, and capital—that we can compare to actual macroeconomic data.
The simulation procedure extends the deterministic transition. We start the economy at the deterministic steady state \(k_{ss}\) with median productivity. Each period, we:
- Compute output, consumption, and investment using the policy function at the current state \((k_t, s_t)\)
- Set \(k_{t+1}\) to the optimal savings from the policy function
- Draw next period’s productivity state \(s_{t+1}\) from the Markov chain (using the transition probabilities from the current state)
- Repeat
function simulateRBC(m::RBCModel, sol, T; seed=42)
Random.seed!(seed)
(; α, δ, z_grid, P_z, N_z) = m
k_sim = zeros(T); z_sim = zeros(T); s_sim = zeros(Int, T)
y_sim = zeros(T); c_sim = zeros(T); i_sim = zeros(T)
k_sim[1] = steady_state(m).k # start at steady state
s_sim[1] = (N_z + 1) ÷ 2 # start at median z
for t in 1:T
s = s_sim[t]
z = z_grid[s]
kp = sol.kp_itp[s](k_sim[t]) # interpolated policy!
z_sim[t] = z
y_sim[t] = z * k_sim[t]^α
c_sim[t] = y_sim[t] + (1-δ)*k_sim[t] - kp
i_sim[t] = kp - (1-δ)*k_sim[t]
if t < T
k_sim[t+1] = kp
s_sim[t+1] = rand(Categorical(P_z[s, :]))
end
end
return DataFrame(t=1:T, k=k_sim, z=z_sim,
y=y_sim, c=c_sim, i=i_sim)
endsimulateRBC (generic function with 1 method)
Several implementation details are worth noting. First, sol.kp_itp[s](k_sim[t]) calls the interpolated policy function for state \(s\) at the current capital level, which may not be on our grid. Interpolation is thus used in two places: inside VFI to evaluate the continuation value, and here in simulation to evaluate the policy function at off-grid capital levels.
Second, rand(Categorical(P_z[s, :])) draws the next productivity state from the appropriate row of the transition matrix. The Categorical distribution (from Distributions.jl) takes a probability vector and returns a random integer according to those probabilities—this is how we simulate the Markov chain.
Third, as in the deterministic transition, we store all results in a DataFrame, which supports filtering, transformation, and statistical operations.
sim = simulateRBC(m, sol, 200)
first(sim, 6)| Row | t | k | z | y | c | i |
|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 1 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
| 2 | 2 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
| 3 | 3 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
| 4 | 4 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
| 5 | 5 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
| 6 | 6 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 |
Each row is one period, and columns contain all the macro aggregates. The first(sim, 6) command displays the first six rows, letting us verify that the simulation starts at the steady state and begins responding to productivity shocks.
8.1.1 Output, Consumption, and Investment
p1 = plot(sim.y, linewidth=2, label="", title="Output", size=(800, 150))
p2 = plot(sim.c, linewidth=2, label="", title="Consumption", size=(800, 150))
p3 = plot(sim.i, linewidth=2, label="", title="Investment", size=(800, 150))
plot(p1, p2, p3, layout=(3, 1), size=(800, 500), xlabel="Period")The simulation reveals the signature patterns of business cycles. Consumption is visibly smoother than output—it fluctuates but with smaller amplitude. This is consumption smoothing in action: the household spreads income over time using savings as a buffer rather than consuming all of a good shock immediately. Investment is much more volatile than output—it swings widely above and below its mean. When output rises, most of the extra income goes to investment; when output falls, investment bears the brunt of the cut. Plotting the three series on separate panels (rather than overlaid) makes these amplitude differences easy to read off directly. This is exactly what we see in U.S. macro data: consumption moves gently while investment swings dramatically.
8.1.2 Productivity and Capital
p1 = plot(sim.z, linewidth=2, color=:steelblue, label="Productivity z",
title="Technology Shock", size=(800, 200))
p2 = plot(sim.k, linewidth=2, color=:darkgreen, label="Capital k",
title="Capital Stock", size=(800, 200))
hline!(p2, [ss.k], color=:gray, linestyle=:dash, label="k_ss")
plot(p1, p2, layout=(2,1), size=(800, 450))Capital responds sluggishly to productivity shocks: it rises gradually during expansions and falls slowly during contractions. This is the same force we saw in the deterministic transition: capital is a stock variable, so it takes many periods of high investment to significantly increase the capital stock, and many periods of low investment for it to depreciate away. This sluggishness is the model’s propagation mechanism: even if a productivity shock lasts only one period, the capital stock takes many periods to adjust back to steady state, generating the persistent dynamics that characterize business cycles. The title of the original paper, “Time to Build and Aggregate Fluctuations,” refers precisely to this insight: the time it takes to build and deplete capital is what turns transitory productivity shocks into sustained macroeconomic fluctuations.
8.2 Business Cycle Statistics
The visual impression from the plots is informative, but the real test of the model is quantitative: can it reproduce the specific statistical patterns observed in U.S. data? The standard approach is to compute business cycle statistics: the standard deviations and correlations of log deviations from trend for each macro aggregate. We simulate a long series (10,000 periods to minimize sampling noise) and compute these moments.
The transform! function from DataFrames.jl adds new columns computed from existing ones. Here we compute log deviations from mean: \(\hat{x}_t = \log x_t - \overline{\log x}\). These are percentage deviations from trend (since \(\log(1 + x) \approx x\) for small \(x\)), which is the standard way to measure business cycle fluctuations:
sim_long = simulateRBC(m, sol, 10_000)
transform!(sim_long,
:y => (x -> log.(x) .- mean(log.(x))) => :y_dev,
:c => (x -> log.(x) .- mean(log.(x))) => :c_dev,
:i => (x -> log.(x) .- mean(log.(x))) => :i_dev,
:k => (x -> log.(x) .- mean(log.(x))) => :k_dev)| Row | t | k | z | y | c | i | y_dev | c_dev | i_dev | k_dev |
|---|---|---|---|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 1 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353789 | -0.00357166 | -0.00165563 | -0.00479484 |
| 2 | 2 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353789 | -0.00357166 | -0.00165563 | -0.00479483 |
| 3 | 3 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165562 | -0.00479483 |
| 4 | 4 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165562 | -0.00479483 |
| 5 | 5 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165561 | -0.00479482 |
| 6 | 6 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165561 | -0.00479482 |
| 7 | 7 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165561 | -0.00479481 |
| 8 | 8 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.0016556 | -0.00479481 |
| 9 | 9 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.0016556 | -0.0047948 |
| 10 | 10 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353788 | -0.00357166 | -0.00165559 | -0.0047948 |
| 11 | 11 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353787 | -0.00357166 | -0.00165559 | -0.0047948 |
| 12 | 12 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353787 | -0.00357166 | -0.00165558 | -0.00479479 |
| 13 | 13 | 3.53288 | 1.0 | 1.51664 | 1.16335 | 0.353288 | -0.00353787 | -0.00357166 | -0.00165558 | -0.00479479 |
| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
| 9989 | 9989 | 3.56075 | 1.03817 | 1.57862 | 1.19233 | 0.386299 | 0.0365189 | 0.0210287 | 0.0876725 | 0.00306369 |
| 9990 | 9990 | 3.59098 | 1.0 | 1.52483 | 1.17318 | 0.351649 | 0.00184465 | 0.00483755 | -0.00630495 | 0.0115159 |
| 9991 | 9991 | 3.58353 | 1.0 | 1.52378 | 1.17163 | 0.352151 | 0.00115946 | 0.00351831 | -0.00487775 | 0.00943955 |
| 9992 | 9992 | 3.57733 | 0.96323 | 1.46691 | 1.14967 | 0.317239 | -0.0368755 | -0.015399 | -0.109285 | 0.00770755 |
| 9993 | 9993 | 3.53683 | 0.96323 | 1.46141 | 1.14071 | 0.320704 | -0.0406323 | -0.0232284 | -0.0984199 | -0.00367664 |
| 9994 | 9994 | 3.50385 | 0.96323 | 1.4569 | 1.13552 | 0.321384 | -0.0437238 | -0.0277893 | -0.0963025 | -0.0130448 |
| 9995 | 9995 | 3.47485 | 0.96323 | 1.45291 | 1.13251 | 0.320403 | -0.0464666 | -0.030443 | -0.0993602 | -0.0213563 |
| 9996 | 9996 | 3.44777 | 0.96323 | 1.44916 | 1.12806 | 0.321107 | -0.0490486 | -0.0343806 | -0.0971655 | -0.0291806 |
| 9997 | 9997 | 3.4241 | 0.96323 | 1.44587 | 1.12328 | 0.322597 | -0.051322 | -0.0386278 | -0.0925355 | -0.0360697 |
| 9998 | 9998 | 3.40429 | 0.96323 | 1.44311 | 1.11926 | 0.323843 | -0.0532371 | -0.0422059 | -0.0886813 | -0.0418728 |
| 9999 | 9999 | 3.3877 | 0.96323 | 1.44078 | 1.11588 | 0.324902 | -0.0548488 | -0.0452337 | -0.085414 | -0.0467568 |
| 10000 | 10000 | 3.37383 | 0.96323 | 1.43883 | 1.11304 | 0.325798 | -0.0562024 | -0.0477864 | -0.0826603 | -0.0508587 |
σ_y = std(sim_long.y_dev)
σ_c = std(sim_long.c_dev)
σ_i = std(sim_long.i_dev)
σ_k = std(sim_long.k_dev)
stats = DataFrame(
Variable = ["Output", "Consumption",
"Investment", "Capital"],
σ_pct = 100 .* [σ_y, σ_c, σ_i, σ_k],
σ_relative = [1.0, σ_c/σ_y, σ_i/σ_y, σ_k/σ_y],
corr_y = [1.0,
cor(sim_long.y_dev, sim_long.c_dev),
cor(sim_long.y_dev, sim_long.i_dev),
cor(sim_long.y_dev, sim_long.k_dev)]
)
stats| Row | Variable | σ_pct | σ_relative | corr_y |
|---|---|---|---|---|
| String | Float64 | Float64 | Float64 | |
| 1 | Output | 6.20502 | 1.0 | 1.0 |
| 2 | Consumption | 5.42276 | 0.873931 | 0.97211 |
| 3 | Investment | 10.2088 | 1.64525 | 0.910738 |
| 4 | Capital | 6.47982 | 1.04429 | 0.86667 |
The model reproduces two central stylized facts:
- Consumption is less volatile than output (\(\sigma_c / \sigma_y < 1\)) — consumption smoothing
- Investment is more volatile than output — investment absorbs the shocks
- All variables are procyclical (positively correlated with output)
With just one source of randomness (technology shocks), the model generates realistic comovement among macro aggregates. This was revolutionary in the early 1980s.
8.3 Comparative Statics
Comparative statics, changing one parameter while holding the others fixed, helps us understand what drives the model’s predictions. We examine three parameters: the persistence of productivity shocks \(\rho\), capital’s share \(\alpha\), and the discount factor \(\beta\). For each experiment, we re-solve and re-simulate the model with a smaller grid (\(N_k = 100\)) for speed.
8.3.1 Effect of Persistence (\(\rho\))
The persistence parameter \(\rho\) controls how long productivity shocks last. How does this affect the character of business cycles?
plot(legend=:topright, size=(700, 400),
title="Output: Effect of Shock Persistence")
for ρ_val in [0.5, 0.75, 0.95]
m_trial = setup!(RBCModel(ρ=ρ_val, N_k=100))
sol_trial = solveRBC(m_trial, tol=1e-5, verbose=false)
sim_trial = simulateRBC(m_trial, sol_trial, 150)
plot!(sim_trial.y, linewidth=2, label="ρ = $ρ_val")
end
xlabel!("Period")
ylabel!("Output")Higher persistence produces longer, more pronounced business cycles. With \(\rho = 0.50\), output fluctuates rapidly but reverts to trend quickly: the economy forgets shocks fast, so booms and busts are short-lived. With \(\rho = 0.95\), a single positive shock sustains an expansion for many periods because the economy expects high productivity to continue. This comparison underscores why the calibrated value of \(\rho\) matters so much: the model needs \(\rho \approx 0.90\) to generate the persistent cycles we observe in the data.
8.3.3 Effect of Discount Factor (\(\beta\))
The discount factor \(\beta\) measures how much the household values the future relative to the present. A patient household (\(\beta\) close to 1) is willing to defer consumption in exchange for higher future income from capital accumulation.
plot(legend=:topleft, size=(700, 400),
title="Savings Policy: Effect of β")
for β_val in [0.90, 0.96, 0.99]
m_trial = setup!(RBCModel(β=β_val, N_k=100))
sol_trial = solveRBC(m_trial, tol=1e-5, verbose=false)
s_mid = (m_trial.N_z + 1) ÷ 2
plot!(m_trial.k_grid, sol_trial.kp[:, s_mid],
linewidth=2, label="β = $β_val")
end
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")More patient agents (\(\beta\) closer to 1) save more at every capital level and accumulate more capital in the long run. In terms of the decentralized economy, a more patient household accepts a lower interest rate \(r_{ss} = 1/\beta - 1\); the lower rental rate \(r_{ss} + \delta\) leads firms to use more capital. The policy function for \(\beta = 0.99\) lies well above the one for \(\beta = 0.90\), and the steady state shifts dramatically rightward. Impatient agents (\(\beta = 0.90\)) consume heavily today, save little, and arrive at a much lower steady state. The difference is quantitatively large: the steady-state capital stock roughly doubles between \(\beta = 0.90\) and \(\beta = 0.99\).
9 Linearized Solution
9.1 The Euler Equation
Value function iteration gives an accurate global solution (it works at any \((k, s)\) in the state space), but it is computationally expensive. Each Bellman iteration solves \(N_k \times N_z = 200 \times 7 = 1{,}400\) optimization problems, and convergence takes many iterations. For a model with one continuous state variable this is manageable, but as models grow larger (multiple capital stocks, heterogeneous agents, many shocks), VFI becomes prohibitively slow.
A linearized solution provides a fast, analytical alternative. Instead of solving the Bellman equation globally, we take a first-order Taylor expansion of the model’s equilibrium conditions around the deterministic steady state. This gives a linear policy rule that maps today’s state into tomorrow’s capital—no iteration, no optimization, no interpolation. The cost is accuracy: the linearized solution is exact at the steady state and increasingly approximate as we move away from it. But since business cycle fluctuations are small (a few percent of GDP), the linearized solution is typically excellent.
The approach is to linearize the equilibrium conditions around the steady state. Define deviations from steady state:
\[ \hat{k}_t \equiv k_t - k_{ss}, \qquad \hat{c}_t \equiv c_t - c_{ss}, \qquad \hat{z}_t \equiv z_t - 1, \qquad \hat{r}_t \equiv r_t - r_{ss} \]
We take first-order Taylor expansions around the steady state, dropping products of deviations like \(\hat{k}_t \cdot \hat{z}_t\) as second-order small.
VFI is accurate but slow (\(N_k \times N_z\) optimization problems per iteration). Linearization gives a policy rule that is nearly exact near the steady state—and almost instant to compute. Most of the macro literature uses linearization or higher-order perturbation.
The linearized system is built from two equations: the household’s Euler equation (with the interest rate from the firm’s problem) and the resource constraint. The Euler equation says that the marginal cost of saving one more unit today equals the expected discounted marginal benefit of the extra capital tomorrow:
\[ \frac{1}{c_t} = \beta \, \mathbb{E}_t \left[ \frac{1 + r_{t+1}}{c_{t+1}} \right], \qquad r_{t+1} = \alpha z_{t+1} k_{t+1}^{\alpha-1} - \delta \]
The left side, \(1/c_t\), is the marginal utility of consumption today—the cost of forgoing one unit of consumption. The right side is the discounted expected marginal utility of the return from saving that unit: each unit saved yields \(1 + r_{t+1}\) units next period, valued at \(1/c_{t+1}\). At the optimum, the household is indifferent between consuming one more unit today and saving it to consume the return tomorrow. This is the same intertemporal tradeoff that generates the steady-state condition \(1 = \beta(1 + r_{ss})\), but now applied to every period and every state of the world. By the First Welfare Theorem, it is also the planner’s first-order condition.
9.2 Linearizing the Resource Constraint
We now linearize the two equations around the steady state, starting with the simpler one: the aggregate resource constraint.
\[ c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t \]
We write each variable as its steady-state value plus a deviation: \(k_t = k_{ss} + \hat{k}_t\), \(c_t = c_{ss} + \hat{c}_t\), \(z_t = 1 + \hat{z}_t\). The nonlinear term \(z_t k_t^\alpha\) is linearized using a first-order Taylor expansion: \((1 + \hat{z}_t)(k_{ss} + \hat{k}_t)^\alpha \approx k_{ss}^\alpha + \alpha k_{ss}^{\alpha-1} \hat{k}_t + k_{ss}^\alpha \hat{z}_t\), dropping products of deviations as second-order small. The coefficient \(\alpha k_{ss}^{\alpha-1}\) is the steady-state marginal product of capital, which the firm’s first-order condition tells us equals the rental rate \(r_{ss} + \delta\). Substituting into the resource constraint and subtracting the steady-state equation (\(c_{ss} + k_{ss} = y_{ss} + (1-\delta)k_{ss}\)) to cancel the constants:
\[ \hat{c}_t + \hat{k}_{t+1} = \underbrace{(r_{ss} + \delta + 1 - \delta)}_{= 1 + r_{ss} \,=\, 1/\beta} \hat{k}_t + y_{ss} \, \hat{z}_t \]
Rearranging:
\[ \boxed{\hat{c}_t = \frac{1}{\beta} \, \hat{k}_t - \hat{k}_{t+1} + y_{ss} \, \hat{z}_t} \]
This expresses \(\hat{c}_t\) as a linear function of \(\hat{k}_t\), \(\hat{k}_{t+1}\), and \(\hat{z}_t\), using the household’s steady-state Euler equation \(1 + r_{ss} = 1/\beta\).
9.3 Linearizing the Euler Equation
Linearizing the left side of the Euler equation gives \(1/(c_{ss} + \hat{c}_t) \approx 1/c_{ss} - \hat{c}_t/c_{ss}^2\). On the right side, a first-order expansion of the ratio gives
\[ \frac{1 + r_{ss} + \hat{r}_{t+1}}{c_{ss} + \hat{c}_{t+1}} \approx \frac{1 + r_{ss}}{c_{ss}} + \frac{\hat{r}_{t+1}}{c_{ss}} - \frac{(1 + r_{ss}) \, \hat{c}_{t+1}}{c_{ss}^2} \]
Multiplying by \(\beta\), using \(\beta(1 + r_{ss}) = 1\) to cancel the constant terms on both sides, and multiplying through by \(-c_{ss}^2\):
\[ \boxed{\hat{c}_t = \mathbb{E}_t[\hat{c}_{t+1}] - \beta \, c_{ss} \, \mathbb{E}_t[\hat{r}_{t+1}]} \]
This is an intertemporal substitution equation: when the household expects high interest rates (\(\hat{r}_{t+1} > 0\)), it saves more today, so consumption today is low relative to expected consumption tomorrow.
To use this equation we need the deviation of the interest rate. Differentiating the firm’s condition \(r_{t+1} = \alpha z_{t+1} k_{t+1}^{\alpha-1} - \delta\) around the steady state, \(\partial r/\partial k = \alpha(\alpha-1)k_{ss}^{\alpha-2} = (\alpha-1)(r_{ss}+\delta)/k_{ss}\) and \(\partial r/\partial z = \alpha k_{ss}^{\alpha-1} = r_{ss} + \delta\), so
\[ \hat{r}_{t+1} = \underbrace{\frac{(\alpha - 1) \, (r_{ss} + \delta)}{k_{ss}}}_{\gamma} \hat{k}_{t+1} + (r_{ss} + \delta) \, \hat{z}_{t+1} \]
More capital lowers the interest rate (diminishing returns, \(\alpha - 1 < 0\)), while higher productivity raises it. Depreciation is a constant cost, so it drops out of the deviation.
9.4 Solving the Linearized System
We now have two linearized equations (resource constraint and Euler equation) in three unknowns (\(\hat{c}_t\), \(\hat{k}_{t+1}\), and exogenous \(\hat{z}_t\)). The method of undetermined coefficients gives us the solution.
9.4.1 Guessing a Linear Policy Rule
Since both equations and the exogenous process for productivity are (approximately) linear, we guess that the optimal policy rule is also linear:
\[ \hat{k}_{t+1} = \phi_k \, \hat{k}_t + \phi_z \, \hat{z}_t \]
Substituting into the linearized resource constraint:
\[ \hat{c}_t = \underbrace{\left(\tfrac{1}{\beta} - \phi_k\right)}_{\psi_k} \hat{k}_t + \underbrace{(y_{ss} - \phi_z)}_{\psi_z} \hat{z}_t \]
Once we know \((\phi_k, \phi_z)\), consumption is pinned down by the resource constraint.
9.4.2 Finding \(\phi_k\)
The crucial step is to substitute our guess into the linearized Euler equation and require that the equation holds for all values of \((\hat{k}_t, \hat{z}_t)\). Using \(\mathbb{E}_t[\hat{z}_{t+1}] = \rho \hat{z}_t\) and \(\hat{k}_{t+1} = \phi_k \hat{k}_t + \phi_z \hat{z}_t\), both expectations are linear in \((\hat{k}_t, \hat{z}_t)\):
\[ \mathbb{E}_t[\hat{c}_{t+1}] = \psi_k (\phi_k \hat{k}_t + \phi_z \hat{z}_t) + \psi_z \rho \, \hat{z}_t, \qquad \mathbb{E}_t[\hat{r}_{t+1}] = \gamma (\phi_k \hat{k}_t + \phi_z \hat{z}_t) + (r_{ss} + \delta) \rho \, \hat{z}_t \]
Since both sides of the Euler equation are linear in \(\hat{k}_t\) and \(\hat{z}_t\), the coefficients on \(\hat{k}_t\) must match on both sides, and separately the coefficients on \(\hat{z}_t\) must match. Matching coefficients on \(\hat{k}_t\):
\[ \psi_k = \phi_k\bigl(\psi_k - \beta\, c_{ss}\, \gamma\bigr) \]
Since \(\psi_k = 1/\beta - \phi_k\), this is one equation in one unknown:
\[ \boxed{\frac{1}{\beta} - \phi_k = \phi_k\!\left(\frac{1}{\beta} - \phi_k - \beta \, c_{ss}\, \gamma\right)} \]
This is a quadratic equation in \(\phi_k\), so it has two roots. We pick the stable root (\(|\phi_k| < 1\)), which ensures that capital mean-reverts toward the steady state after a shock. The unstable root (\(|\phi_k| > 1\)) would imply that deviations from steady state grow without bound, which is economically nonsensical for a stationary model.
9.4.3 Finding \(\phi_z\)
Matching coefficients on \(\hat{z}_t\) gives
\[ \psi_z = \psi_k \phi_z + \psi_z \rho - \beta\, c_{ss}\bigl(\gamma \phi_z + (r_{ss} + \delta)\,\rho\bigr) \]
Substituting \(\psi_z = y_{ss} - \phi_z\) and collecting the \(\phi_z\) terms gives a linear equation for \(\phi_z\):
\[ \boxed{\phi_z = \frac{y_{ss}(1 - \rho) + \beta\, c_{ss}\, (r_{ss} + \delta)\, \rho}{\psi_k - \beta\, c_{ss}\, \gamma + (1 - \rho)}} \]
This is arithmetic once \(\phi_k\) (and hence \(\psi_k\)) is known.
- Guess \(\hat{k}_{t+1} = \phi_k \hat{k}_t + \phi_z \hat{z}_t\) → consumption \(\hat{c}_t = \psi_k \hat{k}_t + \psi_z \hat{z}_t\) follows from the resource constraint
- Compute \(\mathbb{E}_t[\hat{c}_{t+1}]\) and \(\mathbb{E}_t[\hat{r}_{t+1}]\) as linear functions of \((\hat{k}_t, \hat{z}_t)\)
- Match \(\hat{k}_t\) coefficients in the Euler equation → quadratic for \(\phi_k\)
- Match \(\hat{z}_t\) coefficients → linear equation for \(\phi_z\)
9.5 Julia Implementation
The implementation is short because linearization reduces the problem to solving one nonlinear equation (the quadratic for \(\phi_k\)) and one linear equation (for \(\phi_z\)). We solve the quadratic with solve1D from the course package EC410. The call solve1D(f, a, b) finds a root of f between a and b, provided f(a) and f(b) have opposite signs. That is exactly what we need to pick out the stable root: the residual equals \(1/\beta > 0\) at \(\phi_k = 0\) and \(\beta c_{ss} \gamma < 0\) at \(\phi_k = 1\), so the bracket \([0, 1]\) contains exactly one root, the stable one. (The other root is larger than \(1/\beta\).)
using EC410function linearize_rbc(m)
(; α, β, δ, ρ) = m
ss_vals = steady_state(m)
k_ss = ss_vals.k; y_ss = ss_vals.y; c_ss = ss_vals.c; r_ss = ss_vals.r
γ = (α - 1) * (r_ss + δ) / k_ss # slope of r in k
# Step 1: solve for ϕ_k (the stable root lies in (0, 1))
ϕk_residual(ϕ_k) = (1/β - ϕ_k) - ϕ_k * (1/β - ϕ_k - β * c_ss * γ)
ϕ_k = solve1D(ϕk_residual, 0.0, 1.0)
# Step 2: compute ϕ_z directly
ψ_k = 1/β - ϕ_k
num = y_ss*(1 - ρ) + β*c_ss*(r_ss + δ)*ρ
den = ψ_k - β*c_ss*γ + (1 - ρ)
ϕ_z = num / den
return (ϕ_k=ϕ_k, ϕ_z=ϕ_z)
endlinearize_rbc (generic function with 1 method)
lin = linearize_rbc(m)
println("ϕ_k = $(round(lin.ϕ_k, digits=4))")
println("ϕ_z = $(round(lin.ϕ_z, digits=4))")ϕ_k = 0.8589
ϕ_z = 0.9403
The linearized capital policy rule is:
\[ k_{t+1} \approx k_{ss} + \phi_k \, (k_t - k_{ss}) + \phi_z \, (z_t - 1) \]
The coefficient \(\phi_k\) tells us how persistent capital deviations are: if capital is one unit above steady state today, it will be roughly \(\phi_k\) units above steady state tomorrow (holding productivity constant). Since \(|\phi_k| < 1\), capital mean-reverts: deviations shrink over time as the economy returns to steady state. This is the linearized version of the deterministic transition we computed earlier. The coefficient \(\phi_z\) tells us how much capital responds to a productivity shock: since \(\phi_z > 0\), higher productivity leads to more saving. A productivity level 0.01 above its mean raises next period’s capital by roughly \(0.01 \, \phi_z\).
9.6 Comparing to VFI
How good is the linearized approximation? We compare the linearized policy functions and simulated time series directly against the VFI solution. If the two are close, linearization gives us the same economic insights at a fraction of the computational cost.
9.6.1 Policy Functions
s_mid = (m.N_z + 1) ÷ 2
kp_linear = ss.k .+ lin.ϕ_k .* (m.k_grid .- ss.k) .+
lin.ϕ_z .* (m.z_grid[s_mid] - 1.0)
plot(m.k_grid, sol.kp[:, s_mid],
linewidth=2, label="VFI",
legend=:topleft, size=(700, 400))
plot!(m.k_grid, kp_linear,
linewidth=2, linestyle=:dash, label="Linearized")
plot!(m.k_grid, m.k_grid,
color=:gray, linestyle=:dot, label="45° line")
vline!([ss.k], color=:gray,
linestyle=:dashdot, label="k_ss", alpha=0.5)
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")
title!("Savings Policy: VFI vs. Linearized (median z)")Near \(k_{ss}\), the two solutions nearly coincide: the linearized policy function is almost indistinguishable from the VFI solution. Far from the steady state, the linearized solution diverges because it is a straight line that cannot capture the curvature of the true policy function. The VFI solution curves gently (reflecting diminishing returns), while the linearized solution continues in a straight line. For typical business cycle fluctuations, which stay within \(\pm 10\%\) of the steady state, this divergence is negligible.
plot(legend=:topleft, size=(700, 400),
title="VFI (solid) vs. Linearized (dashed)")
for s in [1, 4, 7]
z = m.z_grid[s]
kp_lin = ss.k .+ lin.ϕ_k .* (m.k_grid .- ss.k) .+
lin.ϕ_z .* (z - 1.0)
col = palette(:default)[s ÷ 3 + 1]
plot!(m.k_grid, sol.kp[:, s], linewidth=2,
label="z = $(round(z, digits=3))", color=col)
plot!(m.k_grid, kp_lin, linewidth=2,
linestyle=:dash, label="", color=col)
end
plot!(m.k_grid, m.k_grid,
color=:gray, linestyle=:dot, label="45°")
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")9.6.2 Simulating the Linearized Model
The linearized simulation function is nearly identical to the VFI simulation, except the policy function is the simple linear rule \(k_{t+1} = k_{ss} + \phi_k(k_t - k_{ss}) + \phi_z(z_t - 1)\) instead of an interpolated object. We use the same random seed so both simulations face identical productivity shocks, making the comparison apples-to-apples:
function simulateRBC_linear(m, lin, T; seed=42)
Random.seed!(seed)
(; α, δ, z_grid, P_z, N_z) = m
k_ss = steady_state(m).k
k_sim = zeros(T); s_sim = zeros(Int, T)
y_sim = zeros(T); c_sim = zeros(T); i_sim = zeros(T)
k_sim[1] = k_ss
s_sim[1] = (N_z + 1) ÷ 2
for t in 1:T
z = z_grid[s_sim[t]]
kp = k_ss + lin.ϕ_k * (k_sim[t] - k_ss) + lin.ϕ_z * (z - 1.0)
y_sim[t] = z * k_sim[t]^α
c_sim[t] = y_sim[t] + (1-δ)*k_sim[t] - kp
i_sim[t] = kp - (1-δ)*k_sim[t]
if t < T
k_sim[t+1] = kp
s_sim[t+1] = rand(Categorical(P_z[s_sim[t], :]))
end
end
return DataFrame(t=1:T, k=k_sim,
z=z_grid[s_sim], y=y_sim, c=c_sim, i=i_sim)
endsimulateRBC_linear (generic function with 1 method)
sim_vfi = simulateRBC(m, sol, 200)
sim_lin = simulateRBC_linear(m, lin, 200)
plot(sim_vfi.y, linewidth=2, label="VFI",
legend=:topright, size=(700, 400))
plot!(sim_lin.y, linewidth=2,
linestyle=:dash, label="Linearized")
xlabel!("Period")
ylabel!("Output")
title!("Simulated Output: VFI vs. Linearized")p1 = plot(sim_vfi.c, linewidth=2, label="VFI",
title="Consumption", size=(700, 200))
plot!(p1, sim_lin.c, linewidth=2,
linestyle=:dash, label="Linearized")
p2 = plot(sim_vfi.i, linewidth=2, label="VFI",
title="Investment", size=(700, 200))
plot!(p2, sim_lin.i, linewidth=2,
linestyle=:dash, label="Linearized")
plot(p1, p2, layout=(2,1), size=(700, 450))The two simulations track each other very closely—the solid and dashed lines are nearly superimposed throughout the 200-period simulation. This confirms that for the moderate fluctuations generated by the calibrated productivity process, linearization is an excellent approximation to the full VFI solution. The small differences that do appear tend to emerge during the most extreme episodes, where the economy moves furthest from the steady state and the linear approximation becomes less accurate.
Pros: Almost instant to compute, gives closed-form policy rules, easy to analyze theoretically.
Cons: Only accurate near the steady state, misses nonlinearities (e.g., precautionary savings, occasionally binding constraints).
Most of the macro literature uses linearization (or higher-order perturbation). VFI is the gold standard for accuracy but is computationally demanding.
10 Summary
These notes developed the Kydland & Prescott (1982) Real Business Cycle model from first principles. We first studied the deterministic growth model, then added productivity shocks, and solved the model using two complementary methods: value function iteration with linear interpolation, and linearization of the equilibrium conditions.
Economic Concepts:
- The RBC model shows that a competitive economy with technology shocks can generate realistic business cycle fluctuations without any market failures.
- In the competitive equilibrium, households own capital and earn the real interest rate \(r_t\), while firms rent capital at the rental rate \(r_t + \delta\); depreciation is part of the firm’s cost of capital.
- In the steady state, the household’s Euler equation pins down \(r_{ss} = 1/\beta - 1\) and the firm’s first-order condition \(\alpha k_{ss}^{\alpha-1} = r_{ss} + \delta\) pins down \(k_{ss}\).
- The First Welfare Theorem lets us replace the competitive equilibrium with the simpler social planner’s problem; prices are backed out from the firm’s first-order conditions.
- Without shocks, the economy converges gradually to its steady state, with a high interest rate while capital is scarce.
- With shocks, the planner’s problem is a stochastic Bellman equation with state variables \((k, s)\) and control \(k'\).
- Calibration sets parameters to match long-run data moments (\(\alpha\), \(\beta\), \(\delta\)) and the estimated Solow residual process (\(\rho\), \(\sigma_\varepsilon\)).
- The model reproduces key stylized facts: consumption smoothing (\(\sigma_c / \sigma_y < 1\)), volatile investment (\(\sigma_i / \sigma_y > 1\)), and procyclical comovement.
- The linearized solution approximates the Euler equation around the steady state and delivers a closed-form policy rule \(\hat{k}_{t+1} = \phi_k \hat{k}_t + \phi_z \hat{z}_t\) that is highly accurate near the steady state.
Julia Tools:
| Tool | Purpose |
|---|---|
Interpolations.jl: linear_interpolation |
Evaluate \(V(k')\) and policies at off-grid \(k\) |
Optim.jl: Brent() |
1D optimization of the Bellman equation |
EC410: solve1D(f, a, b) |
Bracketed root finding for the linearized coefficient \(\phi_k\) |
DataFrames.jl: DataFrame, transform! |
Tabular simulation output and in-place column operations |
@kwdef mutable struct + setup! |
Bundle parameters; rebuild grids consistently |
| Multiple dispatch | One function name (setup!, bellman_operator) with a method per model type |
(; ...) = m destructuring |
Extract struct fields cleanly |
Categorical |
Draw next state from Markov transition probabilities |
Broadcasting . |
Element-wise operations on policy arrays |