I want to create a DSGE model in Python. I want to build it myself to help me understand it (not just use a library)

Can someone direct me to a very simple model which would be straightforward to understand, and quick to implement?

(I hear there are some 3- or 4-equation models, but I'm wondering if there's a quick summary of the actual equations so I can get straight to coding)



2 Answers 2


As mentioned by Michael quantecon has good resources. Here is an example of very simple DSGE model from quantecon.

I am not sure if you can get to as low as 3 equations but here is very simple example of real business cycle DSGE by Chad Fulton. I won't copy all the code from the site, you can just follow the link which has full code, but it is based on the following set of equations and it is quite simple

$$ \psi c_t = (1−α)z_t(k_t/n_t)^α \text{ static FOC}$$

$$ 1/c_t = \beta E_t\left(\frac{1}{c_{t+1}} \left[αz_{t+1}(k_{t+1}n_{t+1})^{α−1}+(1−δ)\right]\right) \text{Euler Equation}$$

$$ y_t = z_tk^α_tn^{1−α}_t \text{ Production Function}$$

$$ y_t = c_t + i_t \text{ Resource Constraint} $$ $$k_t =(1−δ)k_t+i_t \text{ Capital Evolution}$$ $$1 =l_t+n_t \text{ Labor-leisure Tradeoff}$$ $$\ln z_t=ρ \ln z_{t−1}+ε_t\text{ Technology Shocks}$$

Where; $y_t$ is output, $c_t$ consumption, $i_t$ investment, $n_t$ labor, $l_t$ leisure, $k_t$ capital stock, $z_t$ technology and rest are parameters. $β$ is discount rate, $ψ$ marginal disutility of labor, $δ$ depreciation, $α$ capital share of output, $ρ$ technology shock.

You could probably simplify it a bit further but not much more.


Jordi Galís book "Monetary Policy, Inflation, and the Business Cycle" features the 3-equation "Simple New Keynesian" Model:

\begin{align*} \pi_t &= \beta E_t[\pi_{t+1}] + \kappa\tilde{y_t}\\ \tilde{y}_t &= -\frac{1}{\sigma}\left(i_t-E_t[\pi_{t+1}]-r_t^n\right)+E_t[\tilde{y}_{t+1}]\\ i_t &= \rho + \phi_\pi\pi_t + \phi_y\tilde{y}_t+v_t. \end{align*}

This is 3 equations in 3 variables ($\tilde{y}_t,\pi_t,i_t$) (you also have to specify the shock, $v_t$, so in some sense it is 4 equations). This is really a work horse model in modern business cycle analysis. You should probably read more about the variables and in particular the parameters in Galí's book to ensure that the model has a unique and stable equilibrium under your calibration.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.