Dissecting a HANK Model
Introduction
This is an attempt (basically, this are notes) to breakdown the Heterogeneous Agent New Keynesian (HANK) model into its mathematical components. I like this type of model because it allows for a focus on inequality as one of the central mechanisms one can pay attention to.
These types of models are based on Aiyagari (1994), which is the simplest and most famous example of a Heterogeneous Agent (HA) model. However, Aiyagari (1994) is not a New Keynesian model because it features flexible prices (no inflation, no nominal rigidities).
The simplest HANK model is effectively Aiyagari + Sticky Prices, which is what I will try to dissect below.
Mathematical Structure of HANK
A HANK model merges two worlds:
- Idiosyncratic Risk (The Aiyagari Block): Households face uninsurable income shocks and must self-insure by saving in a single asset, creating a wealth distribution.
- Nominal Rigidities (The New Keynesian Block): Firms face costs to adjust prices, allowing monetary policy to affect real output.
1. The Household Problem
There is a continuum of households indexed by \(i \in [0,1]\). They maximize expected discounted utility.
State Variables:
- \(a_{it}\): Real asset holdings (savings).
- \(z_{it}\): Idiosyncratic labor productivity shock (e.g., employed/unemployed or high/low skill). This follows a Markov process with transition matrix \(\Pi(z'|z)\).
The Bellman Equation:
\[V_t(a, z) = \max_{c, a', n} \left\{ u(c, n) + \beta \mathbb{E}_t [V_{t+1}(a', z')] \right\}\]
Subject to the Budget Constraint:
\[c + a' = (1 + r_t) a + w_t z n + T_t\]
And the Borrowing Constraint:
\[a' \ge \underline{a}\]
Where:
- \(r_t\) is the real interest rate.
- \(w_t\) is the real wage.
- \(n\) is the labor supply.
- \(T_t\) represents government transfers (or redistributed firm profits).
- \(\underline{a}\) is the borrowing limit (often set to 0).
The Euler Equation (First Order Condition):
\[u'(c_t) \ge \beta (1+r_{t+1}) \mathbb{E}_t [u'(c_{t+1})]\]
(The inequality holds strictly if the borrowing constraint binds).
2. The Distribution of Agents
Unlike a Representative Agent model, the “state” of the economy includes the entire distribution of wealth and income, denoted by the measure \(\mu_t(a, z)\).
The law of motion for the distribution is defined by the household’s optimal policy function \(a'_{t}(a, z)\): \[\mu_{t+1}(\mathcal{A}, \mathcal{Z}) = \int \mathbb{1}_{\{a'_t(a,z) \in \mathcal{A}\}} \Pi(z, \mathcal{Z}) d\mu_t(a,z)\]
In words: the mass of people with assets in set \(\mathcal{A}\) tomorrow is the sum of people today who chose to save that amount.
- \(\mu_{t+1}(\mathcal{A}, \mathcal{Z})\): This is the target tomorrow. We want to know: “How many people will have assets inside range \(\mathcal{A}\) and productivity inside range \(\mathcal{Z}\) tomorrow?”
- \(\int ... d\mu_t(a,z)\): This represents scanning every grid square today. We look at every person currently in the economy to see where they are going.
- \(\mathbb{1}_{\{a'_t(a,z) \in \mathcal{A}\}}\): This is the the decision.
- It asks the person: “Based on your current situation (\(a,z\)), did you decide to save an amount that lands you in the target range \(\mathcal{A}\)?”
- If no: The value is 0. This person is ignored.
- If yes: The value is 1. We count them.
- \(\Pi(z, \mathcal{Z})\): This is the probability.
- It asks: “Given your current job \(z\), what is the chance you land in the target job status \(\mathcal{Z}\)?”
3. The Firm Side
To introduce sticky prices, we typically use the standard New Keynesian setup:
- Final Good Firm: Aggregates intermediate goods \(Y_t = (\int y_{jt}^{\frac{\epsilon-1}{\epsilon}} dj)^{\frac{\epsilon}{\epsilon-1}}\).
- Intermediate Good Firms: Produce using labor \(y_{jt} = N_{jt}\). They face a Rotemberg pricing cost (quadratic cost to adjust prices) or Calvo friction.
This leads to the New Keynesian Phillips Curve (NKPC). In a HANK model, the linearized NKPC looks similar to the standard model:
\[\pi_t = \kappa (\hat{w}_t - \hat{A}_t) + \beta \mathbb{E}_t \pi_{t+1}\]
Where \(\pi_t\) is inflation and \(\hat{w}_t\) is the deviation of real marginal cost (wages).1
Here is the step-by-step derivation of where those equations come from. To understand this, we must separate the Final Good Firm (the buyer) from the Intermediate Good Firms (the sellers).
3.1 The Final Good Firm (The Aggregator)
Origin of the Integral Equation
Imagine a retailer that bundles many specific products (apples, t-shirts, milk, towels) into one “aggregate consumption basket” \(Y_t\).
The retailer buys intermediate goods \(y_{jt}\) from a continuum of producers \(j \in [0,1]\) at price \(P_{jt}\). It sells the final basket at price \(P_t\).
The retailer maximizes profit: \[ \max_{y_{jt}} \left( P_t Y_t - \int_0^1 P_{jt} y_{jt} \, dj \right) \]
The Technology Constraint: The retailer uses a Dixit-Stiglitz Aggregator (Constant Elasticity of Substitution - CES). This is where the first equation comes from: \[ Y_t = \left( \int_0^1 y_{jt}^{\frac{\epsilon-1}{\epsilon}} \, dj \right)^{\frac{\epsilon}{\epsilon-1}} \]
- \(\epsilon > 1\) is the elasticity of substitution. If \(\epsilon\) is high, goods are very similar (substitutes).
Solving the Retailer’s Problem: If you solve the Lagrangian for this maximization, you get the Demand Curve that each intermediate firm faces. \[ y_{jt} = \left( \frac{P_{jt}}{P_t} \right)^{-\epsilon} Y_t \] Intuition: If firm \(j\) charges a price \(P_{jt}\) higher than the average \(P_t\), demand for its product crashes.
3.2 The Intermediate Firm (The Monopolist)
Origin of the Linear Production Function
Each intermediate firm \(j\) produces a specific good. The Production Function is: \[ y_{jt} = A_t N_{jt} \]
Where:
- \(A_t\): Aggregate technology (productivity).
- \(N_{jt}\): Labor hired by firm \(j\).
Real Marginal Cost (\(mc_t\)): To produce 1 extra unit of goods, the firm needs \(1/A_t\) units of labor. Labor costs \(W_t\) (nominal wage). So the nominal marginal cost is \(W_t / A_t\). To see this, just rewrite the production function. We know that output depends on labor: \[ y_{jt} = A_t N_{jt} \]
We need to know how much labor is required to produce a specific amount of output. Solve for \(N_{jt}\): \[ N_{jt} = \frac{y_{jt}}{A_t} \]
The firm’s total nominal cost (\(TC_t\)) is the Nominal Wage (\(W_t\)) multiplied by the amount of labor used (\(N_{jt}\)). \[ TC_t(y_{jt}) = W_t \cdot N_{jt} \]
Substitute the expression for \(N_{jt}\) from Step A: \[ TC_t(y_{jt}) = W_t \left( \frac{y_{jt}}{A_t} \right) = \left( \frac{W_t}{A_t} \right) y_{jt} \]
Nominal Marginal Cost (\(MC^{nom}_t\)) is the derivative of Total Cost with respect to output \(y_{jt}\): \[ MC^{nom}_t = \frac{\partial TC_t}{\partial y_{jt}} \]
Since the cost function is linear (\(\text{Constant} \times y\)), the derivative is just the constant: \[ MC^{nom}_t = \frac{W_t}{A_t} \]
The real marginal cost (divided by price level \(P_t\)) is:2 \[ mc_t = \frac{W_t}{P_t A_t} = \frac{w_t}{A_t} \]
3.3 The Pricing Friction (Rotemberg)
Origin of the Quadratic Cost
In a flexible world, a monopolist sets price as a markup over marginal cost: \(P_{jt} = \frac{\epsilon}{\epsilon-1} MC_t\).
But in New Keynesian models, we add a friction. Rotemberg (1982) assumes that changing prices is effectively costly (e.g., printing new menus, meetings, customer anger).
The Cost Function is such that the firm pays a cost measured in units of the final good:
\[ \text{Cost}_t = \frac{\psi}{2} \left( \frac{P_{jt}}{P_{jt-1}} - 1 \right)^2 Y_t \]
Where:
- \(\psi\): Slope of the cost. If \(\psi=0\), prices are flexible. If \(\psi \to \infty\), prices are fixed.
- \(\pi_{jt} = \frac{P_{jt}}{P_{jt-1}} - 1\) is the firm’s inflation rate.
The Firm’s Maximization Problem: The firm chooses a sequence of prices \(P_{jt}\) to maximize the discounted stream of real profits: \[ \max_{P_{jt}} \mathbb{E}_0 \sum_{t=0}^\infty \beta^t \left[ \underbrace{\frac{P_{jt}}{P_t} y_{jt}}_{\text{Revenue}} - \underbrace{mc_t y_{jt}}_{\text{Labor Cost}} - \underbrace{\frac{\psi}{2} \pi_{jt}^2 Y_t}_{\text{Adjustment Cost}} \right] \] Subject to the demand curve from Step 1: \(y_{jt} = (\frac{P_{jt}}{P_t})^{-\epsilon} Y_t\).
3.4 Deriving the NKPC
The above is a dynamic optimization problem. We take the First Order Condition (FOC) with respect to \(P_{jt}\).3
After taking the derivative and cleaning up the algebra (which involves some heavy rearrangement), we get the Non-Linear Phillips Curve: \[ \pi_t (1+\pi_t) = \frac{\epsilon-1}{\psi} \left( mc_t - \frac{\epsilon-1}{\epsilon} \right) + \beta \mathbb{E}_t \left[ \frac{Y_{t+1}}{Y_t} \pi_{t+1} (1+\pi_{t+1}) \right] \]
Linearization (Approximation): We approximate this equation around a “Zero Inflation Steady State” (where \(\pi=0\) and inflation terms squared are \(\approx 0\)).
- \(\pi_t(1+\pi_t) \approx \pi_t\).
- The ratio \(Y_{t+1}/Y_t \approx 1\).
- Let \(\kappa = \frac{\epsilon-1}{\psi}\) (This is the slope of the Phillips curve).
- The term \((mc_t - \frac{\epsilon-1}{\epsilon})\) becomes the log-deviation \(\hat{mc}_t\).
This yields the New Keynesian Philips Curve equation:
\[ \pi_t = \beta \mathbb{E}_t \pi_{t+1} + \kappa \widehat{mc}_t \] Substituting \(\widehat{mc}_t = \hat{w}_t - \hat{A}_t\): \[ \pi_t = \kappa (\hat{w}_t - \hat{A}_t) + \beta \mathbb{E}_t \pi_{t+1} \]
5. Market Clearing Conditions
There are three markets which must clear in equilibrium:
- Labor Market: \(\int z \ell(a,z) d\mu_t(a,z) = N_t\) (Aggregate effective labor supply = Demand).
- Asset Market: \(\int a d\mu_t(a,z) = K_t + B_t\) (Household savings = Capital + Gov Bonds).
- Goods Market: \(Y_t = C_t + I_t + \text{AdjCosts}\).
If these equations do not hold, the economy is not in equilibrium, and prices (\(w_t, r_t\)) must change until they do.
To understand the structure, we must distinguish between what is given (Exogenous) and what the model solves for (Endogenous).
A. Exogenous Parameters (Inputs - Fixed):
- \(A_t\): Aggregate Technology (Productivity).
- \(\beta\): Household patience (discount factor).
- \(B_t\) (or \(\bar{B}\)): The supply of Government Bonds (how much debt the govt issues).
- \(G_t\): Government spending on goods.
- \(\psi\): The cost of adjusting prices (Rotemberg parameter).
- \(\epsilon\): Elasticity of substitution (competition level).
B. Endogenous Variables (Outputs - Solved by the Model):
- Prices: \(w_t\) (Real Wage), \(r_t\) (Real Interest Rate), \(\pi_t\) (Inflation).
- Aggregate Quantities: \(Y_t\) (GDP), \(C_t\) (Total Consumption), \(N_t\) (Total Labor Hours), \(K_t\) (Total Capital).
- The Distribution: \(\mu_t(a,z)\) (Who has how much money).
- Individual Choices: \(\ell(a,z)\) (Hours worked by person type \(a,z\)), \(c(a,z)\) (Consumption), \(a'(a,z)\) (Savings).
Focusing on these three markets:
The Labor Market
Equation: \[ \underbrace{\int z \cdot \ell(a,z) \, d\mu_t(a,z)}_{\text{Aggregate Labor Supply}} = \underbrace{N_t}_{\text{Labor Demand}} \]
Definitions:
- \(\ell(a,z)\): This is the Labor Supply Policy Function. It is the optimal number of hours a specific household chooses to work.
- Note: In simple Aiyagari models, labor is fixed (inelastic). In HANK, households usually choose labor by equating Marginal Rate of Substitution to the wage.
- \(z\): The idiosyncratic productivity (skill). If \(z=2\), one hour of your work counts as two “effective” hours.
- \(N_t\): Aggregate Labor Demand. This comes from the firms. In the simple model where \(Y_t = A_t N_t\), demand is simply \(N_t = Y_t / A_t\).
How it is determined:
- If Firms want more workers (\(N_t\)) than households want to supply, there is a shortage.
- The wage \(w_t\) rises.
- Higher wages encourage households to work more (\(\ell\) goes up) and firms to hire less.
- This continues until Supply = Demand.
The Asset Market (Savings)
Equation: \[ \underbrace{\int a \, d\mu_t(a,z)}_{\text{Aggregate Household Savings}} = \underbrace{K_t + B_t}_{\text{Aggregate Asset Demand}} \]
Definitions:
- Left Side (The Supply of Funds): Sum of all bank account balances of all households.
- Right Side (The Demand for Funds):
- \(B_t\) (Government Bonds): The government needs to borrow money to cover its debt. This is usually set by fiscal policy (Exogenous).
- \(K_t\) (Physical Capital): Firms borrow money to build factories/machines. In the simplest model, we often assume \(K_t = 0\) (an endowment economy) to make the math easier. In that case, households can only save in Government Bonds (\(B_t\)).
How it is determined:
- If households want to save more than the government and firms want to borrow (Supply > Demand), there is a “savings glut.”
- The interest rate \(r_t\) falls.
- Lower rates make saving less attractive (lowers Supply) and borrowing cheaper (raises Demand via \(K_t\)).
- This continues until Supply = Demand.
The Goods Market (Resource Constraint)
Equation: \[ \underbrace{Y_t}_{\text{Total Supply}} = \underbrace{C_t + I_t + G_t + \text{AdjCosts}_t}_{\text{Total Demand}} \]
Definitions:
- \(C_t\): Aggregate Consumption. \(\int c(a,z) d\mu_t\).
- \(I_t\): Investment. If there is capital, \(I_t = K_{t+1} - (1-\delta)K_t\). If no capital, \(I_t=0\).
- \(G_t\): Government purchases.
- \(\text{AdjCosts}_t\): Price Adjustment Costs.
- Recall the Rotemberg friction: \(\frac{\psi}{2} \pi_t^2 Y_t\).
- This represents resources that are “burned” or wasted in the process of changing prices (menu costs). It creates a wedge between what is produced and what can actually be consumed.
How it is determined:
- Walras’ Law: If \(N-1\) markets clear, the \(N^{th}\) market must clear automatically.
- If the Labor Market clears (Wage is correct) and the Asset Market clears (Interest rate is correct), the Goods Market will mathematically balance on its own. In HANK, the New Keynesian Phillips Curve effectively governs this market by linking Output (\(Y_t\)) to Inflation (\(\pi_t\)).
Solving a HANK Model
Solving a full HANK model with aggregate shocks (like a recession) is computationally heavy because the distribution \(\mu_t\) is a state variable that changes over time.
However, the foundation is solving the steady state. Because we have established in the Market Clearing section that wages are determined by the intersection of Labor Supply and Labor Demand, we cannot simply guess the interest rate and find the wage mechanically. We must find the specific pair of \((r, w)\) that clears both the Asset Market and the Labor Market simultaneously.
We use numerical methods to discretize the state space and an iterative algorithm.
1. Discretize the State Space
- Create a grid for assets \(a\): e.g., \(a \in \{a_1, a_2, ..., a_{100}\}\).
- The productivity shock \(z\) is discrete (e.g., following a Markov chain).
2. Solve the Household Problem (Inner Loop)
We need to find two policy functions: Savings \(a'(a,z)\) and Labor Supply \(n(a,z)\).
Guess value function \(V_0(a,z)\).
Iterate the Bellman equation. Notice the maximization is over consumption, labor, and savings: \[V_{j+1}(a, z) = \max_{c, n, a'} \left\{ u(c, n) + \beta \mathbb{E}[V_j(a', z')|z] \right\}\] Subject to: \(c + a' = (1+r)a + wzn + T\)
Implementation Detail: We typically do not grid-search \(n\). Instead, for every choice of \(a'\), we solve for the optimal \(n\) using the Intratemporal First Order Condition (Marginal Rate of Substitution = Real Wage): \[ \frac{-u_n(c, n)}{u_c(c, n)} = w \cdot z \]
Stop when \(V_{j+1} \approx V_j\).
Store optimal policies \(a^*(a,z)\) and \(n^*(a,z)\).
3. Solve for the Stationary Distribution
- Define the transition matrix \(\Lambda\) based on the savings policy \(a^*\).
- Solve for the invariant distribution \(\mu\) such that \(\mu = \Lambda \mu\).
4. Market Clearing (Outer Loop)
Since the labor supply depends on the wage, and the wage depends on capital (which depends on savings), we use a multivariate solver.
Guess Aggregate Quantities: It is often numerically more stable to guess Aggregate Capital (\(K\)) and Aggregate Labor (\(N\)) rather than guessing prices directly.
- Guess vector \(\vec{X} = [K_{guess}, N_{guess}]\).
Get Prices from Firms: Using the guessed quantities and the firm’s production function (assuming Cobb-Douglas \(Y = K^\alpha N^{1-\alpha}\)), calculate the prices that firms would pay: \[ r = \alpha (K_{guess}/N_{guess})^{\alpha-1} - \delta \] \[ w = (1-\alpha) (K_{guess}/N_{guess})^{\alpha} \]
Solve Household Side: Feed this \(r\) and \(w\) into Step 2 and Step 3.
Get Aggregate Supplies: Calculate the actual aggregate behavior of the households by integrating over the distribution: \[ A^{supply} = \sum_{a,z} a \cdot \mu(a,z) \] \[ N^{supply} = \sum_{a,z} z \cdot n^*(a,z) \cdot \mu(a,z) \]
Compute Errors (Residuals): Compare the Household Supply to your original Guess (Demand). \[ \text{Error}_K = A^{supply} - K_{guess} \] \[ \text{Error}_N = N^{supply} - N_{guess} \]
Update Guesses: We need both errors to be zero. Since we have 2 unknowns and 2 errors, we cannot use a simple “High/Low” bisection.
- Use a numerical solver (like Newton-Raphson or Broyden’s Method) to update \([K_{guess}, N_{guess}]\) simultaneously.
Iterate until \(\text{Error}_K \approx 0\) and \(\text{Error}_N \approx 0\).
Solving for Dynamics
The algorithm above gives you the long-run average (Steady State). HANK models are used to study business cycles (fluctuations around the steady state).
There are two main approaches to solve the dynamics:
- Reiter’s Method (2009): Discretize the distribution into a histogram, linearize the massive system of equations, and solve the linear system.
- Sequence Space Jacobian (Auclert et al., 2021): The modern standard. It looks at the “Impulse Response Function” directly by computing the Jacobian of the household block and combining it with the linearized firm equations.
Summary
In this post, I summarized the inner workings of a HANK model. We looked at the Bellman Equation and the Kolmogorov Forward Equation that determine the problem of the agents, and derived the New Keynesian Phillips Curve for Firms.
We outlined an algorithm to find the steady state that accounts for the mutual dependence of wages and interest rates. We guess Aggregate Capital and Labor \(\to\) derive implied prices \(\to\) Solve Bellman \(\to\) Simulate the steady-state distribution \(\to\) Calculate Aggregate Supplies. We then check if the supplied Capital and Labor match our initial guesses, iterating until all markets clear simultaneously.
Footnotes
In Representative Agent models, the wage \(\hat{w}_t\) is determined by a simple labor supply condition (\(u'_L / u'_c\)). In HANK, there is no single marginal rate of substitution; the wage is determined by market clearing where aggregate labor supply comes from the aggregation of heterogeneous agents.↩︎
In logs, \(\hat{mc}_t = \hat{w}_t - \hat{A}_t\). This matches the term in the NKPC equation).↩︎
In HANK with Rotemberg, all firms are identical, so they all choose the same price \(P_{jt} = P_t\). This simplifies the math hugely because \(P_{jt}/P_t = 1\).↩︎