2026-11-13
The RBC Revolution
Before KP (1982), business cycles were thought to require market failures (sticky prices, coordination failures). KP showed that a perfectly competitive economy hit by productivity shocks could generate realistic fluctuations.
Connection to Previous Lectures
The RBC model combines: dynamic programming (McCall, Rust), Markov chains (productivity shocks), and linear algebra (matrix operations for expectations).
DataFramesDeterministic First
We first understand the economy without shocks: where it is heading (the steady state) and how it gets there (the transition). Business cycles are then what happens when productivity shocks keep knocking it off that path.
\[ \max_{\{c_t, k_{t+1}\}} \; \sum_{t=0}^{\infty} \beta^t \log(c_t) \]
No Uncertainty (Yet)
For now there are no shocks: the household knows all future prices. We add random productivity once we understand the deterministic model.
Simplification
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.
\[ c_t + k_{t+1} = (1 + r_t) \, k_t + w_t \]
\[ \boxed{\frac{1}{c_t} = \beta \, \frac{1 + r_{t+1}}{c_{t+1}}} \]
\[ y_t = z_t \, k_t^\alpha \, \ell_t^{1-\alpha} \]
Depreciation Lives in the Firm’s Problem
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.
\[ \pi_t = z_t \, k_t^\alpha \, \ell_t^{1-\alpha} - (r_t + \delta) \, k_t - w_t \, \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 \]
Zero Profits
With CRS, 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
\[ r_t = \alpha \, z_t \, k_t^{\alpha - 1} - \delta \qquad\qquad w_t = (1-\alpha) \, z_t \, k_t^{\alpha} \]
Competitive Equilibrium
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:
\[ 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} \]
\[ c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t \]
\[ \frac{1}{c_t} = \beta \, \frac{1 + \alpha \, z_{t+1} \, k_{t+1}^{\alpha-1} - \delta}{c_{t+1}} \]
\[ \frac{1}{c_{ss}} = \beta \cdot \frac{1 + r_{ss}}{c_{ss}} \quad\Longrightarrow\quad 1 = \beta \, (1 + r_{ss}) \]
\[ \boxed{r_{ss} = \frac{1}{\beta} - 1} \]
\[ \alpha \, k_{ss}^{\alpha - 1} = r_{ss} + \delta \]
\[ k_{ss} = \left(\frac{\alpha}{r_{ss} + \delta}\right)^{\frac{1}{1-\alpha}} \quad\Longrightarrow\quad \boxed{k_{ss} = \left(\frac{\alpha \beta}{1 - \beta(1-\delta)}\right)^{\frac{1}{1-\alpha}}} \]
\[ c_{ss} + k_{ss} = (1 + r_{ss}) \, k_{ss} + w_{ss} \quad\Longrightarrow\quad c_{ss} = r_{ss} \, k_{ss} + w_{ss} \]
The Logic of the Steady State
Households keep accumulating capital until the interest rate it earns, \(r_{ss} = \alpha k_{ss}^{\alpha-1} - \delta\) (the marginal product 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
Yes! The First Welfare Theorem!
The Shortcut
The CE allocation = the planner’s solution. So instead of tracking prices and market clearing, we can solve the much simpler planner’s problem and recover the competitive equilibrium allocations directly.
\[ \frac{1}{c_t} = \beta \, \frac{\alpha \, z_{t+1} \, k_{t+1}^{\alpha-1} + 1 - \delta}{c_{t+1}} \]
\[ \max_{\{c_t,\, k_{t+1}\}_{t=0}^{\infty}} \; \sum_{t=0}^{\infty} \beta^t \log(c_t) \]
subject to, for every \(t \geq 0\) (with \(z_t = 1\)), \[ c_t + k_{t+1} = k_t^\alpha + (1-\delta) \, k_t, \qquad c_t \geq 0, \quad k_{t+1} \geq 0 \]
\[ \sum_{t=0}^{\infty} \beta^t \log(c_t) = \log(c_0) + \beta \sum_{t=1}^{\infty} \beta^{t-1} \log(c_t) \]
\[ \max_{c_0,\, k_1} \left\{ \log(c_0) + \beta \left[\; \max_{\{c_t,\, k_{t+1}\}_{t=1}^\infty} \sum_{t=1}^\infty \beta^{t-1} \log(c_t) \;\right] \right\} \]
\[ V(k) = \max_{k'} \left\{ \log(c) + \beta \, V(k') \right\} \]
where \(c = k^\alpha + (1-\delta) k - k' > 0\)
GrowthModel Structmutable struct holds the model parameters and the objects we’ll compute from them:GrowthModel
setup! functionfunction steady_state(m)
(; α, β, δ) = m
r_ss = 1/β - 1 # household: β(1 + r) = 1
k_ss = (α / (r_ss + δ))^(1/(1-α)) # firm: α k^(α-1) = r + δ
y_ss = k_ss^α
w_ss = (1-α) * k_ss^α # firm: w = MPL
i_ss = δ * k_ss # replace worn-out capital
c_ss = y_ss - i_ss
return (k=k_ss, y=y_ss, c=c_ss, i=i_ss, r=r_ss, w=w_ss)
endsteady_state (generic function with 1 method)
m: it works for any model with fields α, β, δ
setup! Functionsetup! (generic function with 1 method)
setup! mutates the struct (note the ! convention)
k_gridsetup! again after changing a parameter rebuilds the grid consistentlyk_ss = 4.434, r_ss = 0.0417
w_ss = 1.095, c_ss = 1.28
\[ V(k') \approx V_i + \frac{k' - k_i}{k_{i+1} - k_i} \cdot (V_{i+1} - V_i) \]
\[ V(k') \approx (1 - w) \cdot V_i + w \cdot V_{i+1} \]
Intuition
Linear interpolation draws a straight line between adjacent known points and reads off the value at \(k'\). The weight \(w\) measures how far \(k'\) is from \(k_i\) toward \(k_{i+1}\).
Interpolations.jlInterpolations.jl package does all of this for us with clean call syntax: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
V_itp behaves like a function — just call it with any \(k'\):Call Syntax
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.
V_itp.(k_fine) evaluates the interpolant at every point in the vectorRule of Thumb
For smooth economic functions, 100–500 grid points typically give excellent accuracy with linear interpolation.
\[ V(k) = \max_{k'} \left\{ \log(c) + \beta \, V(k') \right\}, \qquad c = k^\alpha + (1-\delta) k - k' \]
The plan
Boil this down to a problem you can solve in a few lines of Julia, then iterate it to recover \(V\).
\[ c + k' = R \]
\[ \max_{k'} \;\; \log(\underbrace{R - k'}_{=\,c}) \;+\; \beta\, v^f(k') \]
This is ALL you need
Learn to solve this two-variable problem we can solve the entire infinite-horizon Bellman equation.
Optim.jlOptim.jl:resources is \(R\); vf is the future value \(v^f\)Optim minimizes by convention)(kp = 0.8867671586152306, c = 4.11323284138477)
#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.4489795934593364, c = 2.5510204065406636)
optimal_policyvf as inputsoptimal_policy (generic function with 1 method)
vf directly(V, kp, c)
\[ 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 one \(k\) if we can supply \(v^f\)
But \(v^f\) is \(V\), which is what we’re solving for!
We need to find the fixed point: \(V\) that we put into the bellman equation is the V we get out.
The iteration loop
Guess \(V\) \(\rightarrow\) interpolate it to get \(v^f\) \(\rightarrow\) run optimal_policy at every \(k\) \(\rightarrow\) get \(V_{\text{new}}\) \(\rightarrow\) repeat until convergence.
optimal_policy needs \(v^f(\cdot)\) as a callable function of \(k'\)bellman_operator: Pseudocodebellman_operator: Full Functionfunction 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)
optimal_policybellman_operator to get \(V^{n+1}\) and policiesConvergence
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.
solveGrowth: PseudocodesolveGrowth: Full Functionfunction 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)
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
kp_itp = linear_interpolation(k_grid, kp_policy) # k'(k) at any k
c_itp = linear_interpolation(k_grid, c_policy) # c(k) at any k
return (V=V, kp=kp_policy, c=c_policy, kp_itp=kp_itp, c_itp=c_itp)
endsolveGrowth (generic function with 1 method)
Converged in 293 iterations (dist = 1.0e-6)
(V = [1.7644644786633954, 1.7806230227257094, 1.7966983524539102, 1.8126914692020115, 1.8286034134759044, 1.8444351494130145, 1.86018776242375, 1.8758624428397455, 1.8914604921888594, 1.9069830571931121 … 8.492197698384393, 8.496161882399209, 8.50012371402122, 8.504083202019583, 8.50804042794461, 8.511995355017795, 8.51594781028582, 8.519897892590805, 8.523845746500088, 8.527791355826585], kp = [1.2168720890963585, 1.223840428893597, 1.2307883964616213, 1.237730429314422, 1.2446550429276024, 1.251572206964698, 1.258485091789756, 1.265406909983036, 1.2723324962090006, 1.279252053282327 … 7.467952613392386, 7.473984301767737, 7.479897416403173, 7.485912349777228, 7.491896670422614, 7.498020107706739, 7.505023864160718, 7.511049506161238, 7.5170709978344, 7.523075912791381], c = [0.56007268867594, 0.5621705987426344, 0.5642754335791873, 0.5663729322117435, 0.5684747520282569, 0.570571092656603, 0.5726589495526839, 0.5747252725818295, 0.576775386244476, 0.5788192437005444 … 1.7950415263091521, 1.7961286866509178, 1.7973340691631243, 1.798437281892765, 1.799570756831395, 1.8005647651346264, 1.800678104793116, 1.8017692099507086, 1.802864117000592, 1.8039752528496464], kp_itp = 1000-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.2168720890963585
1.223840428893597
1.2307883964616213
1.237730429314422
1.2446550429276024
1.251572206964698
1.258485091789756
1.265406909983036
1.2723324962090006
1.279252053282327
⋮
7.473984301767737
7.479897416403173
7.485912349777228
7.491896670422614
7.498020107706739
7.505023864160718
7.511049506161238
7.5170709978344
7.523075912791381, c_itp = 1000-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.56007268867594
0.5621705987426344
0.5642754335791873
0.5663729322117435
0.5684747520282569
0.570571092656603
0.5726589495526839
0.5747252725818295
0.576775386244476
0.5788192437005444
⋮
1.7961286866509178
1.7973340691631243
1.798437281892765
1.799570756831395
1.8005647651346264
1.800678104793116
1.8017692099507086
1.802864117000592
1.8039752528496464)
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)")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)")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)
| Row | t | k | y | c | i | r | w |
|---|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 0 | 2.21692 | 1.30046 | 0.878326 | 0.422136 | 0.113581 | 0.871309 |
| 2 | 1 | 2.4617 | 1.34619 | 0.928461 | 0.417733 | 0.100462 | 0.90195 |
| 3 | 2 | 2.6825 | 1.3849 | 0.971419 | 0.413479 | 0.0903698 | 0.927882 |
| 4 | 3 | 2.88138 | 1.41797 | 1.00975 | 0.40822 | 0.0823985 | 0.950042 |
DataFrame stores the path as a table: one row per period, one column per variablep1 = 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")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)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
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")\[ \log z_{t+1} = \rho \, \log z_t + \sigma_\varepsilon \, \varepsilon_{t+1}, \qquad \varepsilon_{t+1} \sim N(0, 1) \]
Connecting to Markov Chains
We’ll discretize this continuous AR(1) process into a finite-state Markov chain. This lets us use our Markov chain tools!
Why Rouwenhorst?
Rouwenhorst is simpler to implement than Tauchen (1986) (an alternative method) and performs better for highly persistent processes (\(\rho\) close to 1): exactly the case in RBC models.
rouwenhorst Functionfunction 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, # evenly spaced grid
sqrt(N-1) * σ_z, N))
return z_grid, P
endrouwenhorst (generic function with 1 method)
7-element Vector{Float64}:
0.8937
0.9278
0.9632
1.0
1.0382
1.0778
1.1189
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
\[ 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 \]
\[ \frac{1}{c_t} = \beta \, \mathbb{E}_t\left[ \frac{1 + r_{t+1}}{c_{t+1}} \right] \]
\[ \max_{\{c_t,\, k_{t+1}\}_{t=0}^{\infty}} \; \mathbb{E}_0 \sum_{t=0}^{\infty} \beta^t \log(c_t) \]
subject to, for every \(t \geq 0\), \[ c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t, \qquad c_t \geq 0, \quad k_{t+1} \geq 0 \]
\[ V(k, s) = \max_{k'} \left\{ \log(c) + \beta \, \mathbb{E}\left[V(k', s') \mid s\right] \right\} \]
where \(c = \bar z_s \, k^\alpha + (1-\delta) k - k' > 0\)
\[ 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}} \]
optimal_policy(m, R, vf) works unchanged — only its inputs changeWhat’s New
RBCModel Struct@kwdef mutable struct RBCModel
β::Float64 = 0.96 # discount factor
α::Float64 = 0.33 # capital share
δ::Float64 = 0.08 # depreciation rate
ρ::Float64 = 0.90 # persistence of TFP
σ_ε::Float64 = 0.02 # std dev of TFP innovation
N_z::Int = 7 # number of productivity states
N_k::Int = 200 # number of 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
z_grid, P_z)setup! Functionsetup! (generic function with 2 methods)
Multiple Dispatch
We now have two setup! functions: one for GrowthModel, one for RBCModel. Julia picks the right method based on the type of m. We’ll use the same trick for bellman_operator.
RBCModel(0.96, 0.33, 0.08, 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.8867671427443421, 0.9224160731059237, 0.9580650034675052, 0.9937139338290869, 1.0293628641906685, 1.06501179455225, 1.1006607249138316, 1.1363096552754133, 1.171958585636995, 1.2076075159985764 … 7.660063911444845, 7.695712841806427, 7.7313617721680075, 7.767010702529589, 7.802659632891172, 7.838308563252753, 7.873957493614335, 7.909606423975916, 7.9452553543374975, 7.980904284699079])
optimal_policy needs \(v^f(\cdot)\) as a callable function of \(k'\)
But \(V\) is stored on a grid: \(V[i, s'] = V(k_i, s')\)
Compute the expected continuation value on the grid (rows = \(k\), columns = current state \(s\)):
\[ \mathbb{E}V[i', s] \;=\; \sum_{s'=1}^{S} P_{s, s'} \, V[i', s'] \]
compute_vf: The Future Value for State \(s\)compute_vf(m, V, s) builds the future value \(v^f(\cdot)\) for a single current state \(s\):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)
optimal_policy expects as inputlinear_interpolation(k_grid, V): now we take the expectation firstbellman_operator: Pseudocodebellman_operator: Full Functionfunction 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)
compute_vf in place of a plain interpolationcompute_vf builds \(v^f\) once, then we reuse it across all \(k\)solveRBC: PseudocodesolveRBC: Full Functionfunction 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)
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
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 (V=V, kp=kp_policy, c=c_policy, kp_itp=kp_itp, c_itp=c_itp)
endsolveRBC (generic function with 1 method)
solveGrowth; \(V\) is now an \(N_k \times N_z\) matrix with one interpolated policy per stateConverged in 294 iterations (dist = 9.6e-7)
(V = [0.5450767096793305 0.9524145298018536 … 2.601594644353457 3.019041640967936; 0.6288520459017412 1.0350077981944352 … 2.6796968957245433 3.096067287082055; … ; 7.561499679633554 7.877213571940094 … 9.168728441903228 9.498811277963835; 7.582033994564341 7.897513180113204 … 9.188095953883254 9.51794445504028], kp = [1.1539249754881118 1.171958597827226 … 1.2641278395321915 1.285496326920585; 1.1875771745562833 1.207607520388135 … 1.2998968026283584 1.3217391807554197; … ; 7.358439432225009 7.4025190720995875 … 7.589068507764866 7.644303444974232; 7.388480155618007 7.432574853941241 … 7.624414964838906 7.674711618118873], c = [0.5208484138810829 0.5356042861902821 … 0.5875971126232149 0.6057730746662906; 0.5312381980186944 0.544426612586032 … 0.5981867053510661 0.6164064753257412; … ; 1.7222221898789316 1.745749781405082 … 1.8564418373926106 1.8827418787488632; 1.7275968224578087 1.7512093081341567 … 1.8570501398025003 1.8884090088944356], kp_itp = Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Vector{Float64}, Gridded{Linear{Throw{OnGrid}}}, Tuple{Vector{Float64}}}, Gridded{Linear{Throw{OnGrid}}}, Throw{Nothing}}[200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.1539249754881118
1.1875771745562833
1.2210546041465316
1.2543945213699295
1.287713293658379
1.3209209760976173
1.3539903647904865
1.3868741681135464
1.4215010942520252
1.457150038630307
⋮
7.143981576474527
7.174024628032842
7.20407646728552
7.234128943252147
7.267925589788542
7.299585122385198
7.3287528759142955
7.358439432225009
7.388480155618007, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.171958597827226
1.207607520388135
1.2432564423330124
1.2789053815738283
1.3145542933403247
1.348521466418067
1.3818308248797162
1.4149994120075626
1.448032698896076
1.480972181865112
⋮
7.186995183208912
7.217099560710612
7.24719658924116
7.277251928412222
7.307196745836364
7.339223551166018
7.372599333027445
7.4025190720995875
7.432574853941241, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.1966980793818214
1.2312146963253168
1.2655161078288129
1.299639330628922
1.3335755409510233
1.3673011902760543
1.40086652668322
1.4342978264440338
1.4677102872011518
1.501013499384367
⋮
7.2322766380156285
7.262706359280602
7.292906507588421
7.323010212435755
7.353145228032412
7.38327185412017
7.412869917007583
7.446170343383855
7.4784013148646, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.2144385078394053
1.2493292015429769
1.2840607932755177
1.3186173420072411
1.352994831912756
1.3871738144178913
1.42150109950597
1.457150044612743
1.4927989689595331
1.5284478884385235
⋮
7.274833539306181
7.30486847092527
7.339223508783326
7.3706292919389735
7.400670341721313
7.430708476519994
7.460874916228915
7.490774091216102
7.5209988134254475, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.2432564391086491
1.2789053611810879
1.3143265239659931
1.3491681309866461
1.383838030864317
1.4183457482390183
1.452683227669331
1.4868561943866843
1.5208988390565692
1.554823375608721
⋮
7.324537106562674
7.354351546822783
7.384474358283663
7.414727775095247
7.446170415037176
7.4810122031648545
7.511367300478341
7.5418029616896725
7.572105934326614, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.2641278395321915
1.2998968026283584
1.335421971810719
1.3707277829529638
1.4058370965832898
1.4407628925214153
1.4755110369389828
1.5100448785017473
1.5444171124395547
1.5786451316680594
⋮
7.374872425666881
7.4072126654909525
7.436888151129454
7.467277755782855
7.497793653349554
7.528293981099016
7.558739445007627
7.589068507764866
7.624414964838906, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
1.285496326920585
1.3217391807554197
1.357708838767241
1.3934440944546151
1.428964150298179
1.4642853158242062
1.4994149733622462
1.5344172923582304
1.5692669011027773
1.6039408124374275
⋮
7.425834087661302
7.456311363009074
7.486785276867606
7.517468307686493
7.5529895190132414
7.583250019978197
7.613775476672608
7.644303444974232
7.674711618118873], c_itp = Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Vector{Float64}, Gridded{Linear{Throw{OnGrid}}}, Tuple{Vector{Float64}}}, Gridded{Linear{Throw{OnGrid}}}, Throw{Nothing}}[200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5208484138810829
0.5312381980186944
0.5415152207019758
0.5516598791718297
0.5615717885134295
0.5713554145121036
0.5810511979626509
0.5907185344812849
0.5984398161220563
0.6049463549252709
⋮
1.6885484495921617
1.6939772088779348
1.699388929838011
1.7047918265967503
1.7064424276731698
1.7102220791953284
1.7164855071658565
1.7222221898789316
1.7275968224578087, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5356042861902821
0.544426612586032
0.5529504324502863
0.5611940561608642
0.5691741211222321
0.5785874137401004
0.5884237521452151
0.5981786591062779
0.6078581875089979
0.6174314381583021
⋮
1.7124338511041115
1.7179033921555051
1.7233717165868434
1.7288732303408674
1.7344768305609461
1.7379900715654273
1.7401460279266967
1.745749781405082
1.7512093081341567, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5449060065321552
0.5553062911011002
0.5656118787408402
0.5758047806692903
0.5859110467030448
0.595969876033289
0.6059452873795508
0.6158240502181533
0.6255029308034168
0.6350833403653231
⋮
1.736605209486882
1.7418554123470527
1.7473262955900086
1.7528847977759652
1.7584032319230438
1.7639213647022691
1.7699594354162826
1.7722865821987046
1.7756746874813434, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5625062699328931
0.5729951426528785
0.5833213847514467
0.5935206915866738
0.6036149626134171
0.6136398945272445
0.6232634887648099
0.6313259316470055
0.6391613245596841
0.6467810732481571
⋮
1.7661524153629422
1.771907460101244
1.7733331665607848
1.7776989663378266
1.7834204078975615
1.789135741798388
1.794713816262247
1.800550268218486
1.8060523522155796, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5703781272564081
0.5805890983041915
0.5906938142164844
0.6010645799006737
0.6113121130552159
0.6214437574178158
0.6314829452615034
0.6414380121313046
0.6512876621135704
0.6610315389260266
⋮
1.791305459833752
1.7973952493008172
1.8031670831031263
1.8087988004428164
1.8132318559988674
1.8142563962959466
1.8197583310500907
1.8251704754156517
1.8307061508955096, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.5875971126232149
0.5981867053510661
0.6086733268921196
0.6190538326928596
0.6293246372961168
0.6394902731938963
0.649560838041843
0.6595875807072
0.6695311929566445
0.6793865921762086
⋮
1.8186843312172503
1.8223669360020374
1.828704344630765
1.8343177600551774
1.8397950836015369
1.8452782523129505
1.8508066336286442
1.8564418373926106
1.8570501398025003, 200-element extrapolate(interpolate((::Vector{Float64},), ::Vector{Float64}, Gridded(Linear())), Throw()) with element type Float64:
0.6057730746662906
0.6164064753257412
0.626953069285235
0.6373961671419377
0.6477365772934363
0.6579761710407448
0.6681241392852688
0.6781314673607808
0.6880374250088324
0.6978777796234297
⋮
1.8484035237766125
1.8540722359277817
1.8597339793818906
1.8651763547485976
1.8657703765766858
1.871615012885191
1.8771846738010485
1.8827418787488632
1.8884090088944356])
Patience
This 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.
Calibration vs. Estimation
Calibration uses different data moments than the ones we’re trying to explain. We match long-run averages (growth accounting, interest rates) and then ask: can the model reproduce business cycle fluctuations?
| 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 8\%\)/yr | 0.08 |
\[ \log z_t = \rho \, \log z_{t-1} + \varepsilon_t, \qquad \varepsilon_t \sim N(0, \sigma_\varepsilon^2) \]
\[ \log z_t = \log Y_t - \alpha \log K_t - (1-\alpha) \log L_t \]
Calibrated Parameters:
α = 0.33 (capital share)
β = 0.96 (discount factor → r ≈ 0.042)
δ = 0.08 (depreciation rate)
ρ = 0.9 (TFP persistence)
σ_ε = 0.02 (TFP innovation std dev)
Implied Steady State:
K/Y = 2.71 (data: ≈ 2.8)
I/Y = 0.22 (data: ≈ 0.25-0.30)
C/Y = 0.78 (data: ≈ 0.65-0.70)
The Calibration Strategy
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="")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")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")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)
simulateGrowth, simulation just calls the interpolated policy, now one per state:Interpolation Everywhere
Linear interpolation is used in two places: (1) inside VFI to evaluate the continuation value, and (2) in simulation to evaluate the policy function. Both are essential for handling the continuous state space.
| Row | t | k | z | y | c | i |
|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 1 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
| 2 | 2 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
| 3 | 3 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
| 4 | 4 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
| 5 | 5 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
| 6 | 6 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 |
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))sim_long = simulateRBC(m, sol, 10_000)
sim_long.y_dev = log.(sim_long.y) .- mean(log.(sim_long.y))
sim_long.c_dev = log.(sim_long.c) .- mean(log.(sim_long.c))
sim_long.i_dev = log.(sim_long.i) .- mean(log.(sim_long.i))
sim_long.k_dev = log.(sim_long.k) .- mean(log.(sim_long.k))
first(sim_long, 6) #report the first 6 rows| 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 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.000783354 | -0.00496687 |
| 2 | 2 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.000783355 | -0.00496687 |
| 3 | 3 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.000783356 | -0.00496688 |
| 4 | 4 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.000783357 | -0.00496688 |
| 5 | 5 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.000783359 | -0.00496688 |
| 6 | 6 | 4.43384 | 1.0 | 1.6347 | 1.27999 | 0.354707 | -0.00359466 | -0.00367429 | -0.00078336 | -0.00496688 |
stats = DataFrame(
Variable = ["Output", "Consumption", "Investment", "Capital"],
σ_pct = [100*std(sim_long.y_dev), 100*std(sim_long.c_dev), 100*std(sim_long.i_dev), 100*std(sim_long.k_dev)],
σ_relative = [1.0, std(sim_long.c_dev)/std(sim_long.y_dev), std(sim_long.i_dev)/std(sim_long.y_dev), std(sim_long.k_dev)/std(sim_long.y_dev)],
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.15173 | 1.0 | 1.0 |
| 2 | Consumption | 5.29062 | 0.860021 | 0.965192 |
| 3 | Investment | 11.1569 | 1.81362 | 0.892204 |
| 4 | Capital | 6.4229 | 1.04408 | 0.853609 |
Key Business Cycle Facts
The model reproduces two central stylized facts:
The RBC Achievement
With just one source of randomness (technology shocks), the model generates realistic comovement among macro aggregates. This was revolutionary in the early 1980s.
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")plot(legend=:topleft, size=(700, 400), title="Savings Policy: Effect of α")
for α_val in [0.25, 0.33, 0.40]
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'")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'")\[ \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} \]
Why Linearize?
VFI is accurate but slow (\(N_k \times N_z\) optimization problems per iteration). Linearization gives a policy rule that’s nearly exact near the steady state — and almost instant to compute.
\[ c_t + k_{t+1} = z_t \, k_t^\alpha + (1-\delta) \, k_t \]
\[ (c_{ss} + \hat{c}_t) + (k_{ss} + \hat{k}_{t+1}) = (1 + \hat{z}_t)(k_{ss} + \hat{k}_t)^\alpha + (1-\delta)(k_{ss} + \hat{k}_t) \]
\[ (k_{ss} + \hat{k}_t)^\alpha \approx k_{ss}^\alpha + \alpha \, k_{ss}^{\alpha-1} \, \hat{k}_t \]
\[ \text{RHS} \approx k_{ss}^\alpha + \underbrace{\alpha k_{ss}^{\alpha-1}}_{r_{ss} + \delta} \hat{k}_t + \underbrace{k_{ss}^\alpha}_{y_{ss}} \hat{z}_t + (1-\delta) k_{ss} + (1-\delta) \hat{k}_t \]
\[ \hat{c}_t + \hat{k}_{t+1} = \underbrace{(1 + r_{ss})}_{= 1/\beta} \hat{k}_t + y_{ss} \, \hat{z}_t \]
\[ \boxed{\hat{c}_t = \frac{1}{\beta} \, \hat{k}_t - \hat{k}_{t+1} + y_{ss} \, \hat{z}_t} \]
\[ \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 Euler Equation
At the optimum, the household is indifferent between consuming one more unit today vs. saving it and consuming the return tomorrow.
\[ \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} \]
\[ \hat{r}_{t+1} = \underbrace{\frac{(\alpha - 1) \, (r_{ss} + \delta)}{k_{ss}}}_{\text{diminishing MPK}} \hat{k}_{t+1} + \underbrace{(r_{ss} + \delta)}_{\text{productivity effect}} \hat{z}_{t+1} \]
\[ -\frac{\hat{c}_t}{c_{ss}^2} = \frac{\beta}{c_{ss}} \mathbb{E}_t[\hat{r}_{t+1}] - \frac{1}{c_{ss}^2} \mathbb{E}_t[\hat{c}_{t+1}] \]
\[ \boxed{\hat{c}_t = \mathbb{E}_t[\hat{c}_{t+1}] - \beta \, c_{ss} \, \mathbb{E}_t[\hat{r}_{t+1}]} \]
\[ \hat{c}_t = \underbrace{\left(\tfrac{1}{\beta} - \phi_k\right)}_{\equiv\; \psi_k} \hat{k}_t + \underbrace{(y_{ss} - \phi_z)}_{\equiv\; \psi_z} \hat{z}_t \]
\[ \boxed{\hat{c}_t = \psi_k \, \hat{k}_t + \psi_z \, \hat{z}_t} \]
\[ \mathbb{E}_t[\hat{c}_{t+1}] = \psi_k \underbrace{(\phi_k \hat{k}_t + \phi_z \hat{z}_t)}_{\hat{k}_{t+1}} + \psi_z \underbrace{\rho \, \hat{z}_t}_{\mathbb{E}_t[\hat{z}_{t+1}]} \]
\[ \mathbb{E}_t[\hat{r}_{t+1}] = \gamma \underbrace{(\phi_k \hat{k}_t + \phi_z \hat{z}_t)}_{\hat{k}_{t+1}} + (r_{ss} + \delta) \underbrace{\rho \, \hat{z}_t}_{\mathbb{E}_t[\hat{z}_{t+1}]} \]
\[ \psi_k = \phi_k\bigl(\psi_k - \beta\, c_{ss}\, \gamma\bigr) \]
\[ \boxed{\frac{1}{\beta} - \phi_k = \phi_k\!\left(\frac{1}{\beta} - \phi_k - \beta \, c_{ss}\, \gamma\right)} \]
\[ \psi_z = \psi_k \phi_z + \psi_z \rho - \beta\, c_{ss}\bigl(\gamma \phi_z + (r_{ss} + \delta)\,\rho\bigr) \]
\[ \boxed{\phi_z = \frac{y_{ss}(1 - \rho) + \beta\, c_{ss}\, (r_{ss} + \delta)\, \rho}{\psi_k - \beta\, c_{ss}\, \gamma + (1 - \rho)}} \]
Summary of the Approach
solve1D from the course package EC410 to solve the \(\phi_k\) equation, then compute \(\phi_z\) directly:function 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 (ψ_k = ϕ_k·(ψ_k − β·c_ss·γ) with ψ_k = 1/β − ϕ_k)
ϕk_residual(ϕ_k) = (1/β - ϕ_k) - ϕ_k * (1/β - ϕ_k - β * c_ss * γ)
ϕ_k = solve1D(ϕk_residual, 0.0, 1.0) # stable root lies in (0, 1)
# Step 2: compute ϕ_z directly
ψ_k = 1/β - ϕ_k
ϕ_z = (y_ss*(1 - ρ) + β*c_ss*(r_ss + δ)*ρ) / (ψ_k - β*c_ss*γ + (1 - ρ))
return (ϕ_k=ϕ_k, ϕ_z=ϕ_z)
endlinearize_rbc (generic function with 1 method)
solve1D(f, a, b) finds the root of f between a and b
ϕ_k = 0.8784
ϕ_z = 1.0427
\[ k_{t+1} \approx k_{ss} + \phi_k \, (k_t - k_{ss}) + \phi_z \, (z_t - 1) \]
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)")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)
plot!(m.k_grid, sol.kp[:, s], linewidth=2,
label="z = $(round(z, digits=3))", color=palette(:default)[s ÷ 3 + 1])
plot!(m.k_grid, kp_lin, linewidth=2, linestyle=:dash,
label="", color=palette(:default)[s ÷ 3 + 1])
end
plot!(m.k_grid, m.k_grid, color=:gray, linestyle=:dot, label="45°")
xlabel!("Current Capital k")
ylabel!("Next Period Capital k'")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))Linearization: Pros and Cons
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.
Concepts
Julia Tools
Interpolations.jl: linear_interpolation with call syntaxOptim.jl: Brent() for 1D optimizationEC410: solve1D(f, a, b) for bracketed root findingDataFrames.jl: tabular simulation outputsetup! and (; ...) = m destructuringCategorical for Markov simulationEC 410 | University of Oregon