Here are some very simple working examples of very standard DSGE Models. In the following codes, I employ two methods to solve rational expectations models. The resolution is performed via the dynare package (requires Matlab or octave) initially developed by Michel Juillard. The second way is through matlab codes written by Paul Klein, Bennett McCallum and Edward Nelson. All theses codes are based on the generalized Schur form to solve a systems of linear expectational difference equations.

In this section, I share very standard business cycle models very close to the canonical neo-classical growth model. I extend the set-up with several real rigidities taken from Christiano et al. (2005) and Smets and Wouters (2003, 2007) which aim at enhancing the empirical relevance of macro-models.

The basic RBC Model

Our economy is populated by a large number of households $j\in[0;1]$, the utility function of the representative household $j$ is defined by: $\mathcal{U}(C_t(j),H_t(j))=\frac{C_{t}(j)^{1-\sigma^C}}{1-\sigma^C}-\frac{H_{t}(j)^{1+1/\sigma^L}}{1+1/\sigma^L}$
where $\sigma^C$ is the risk aversion and $\sigma^L$ is the frischian elasticity of labor. $\mathcal{U}(.)$ is increasing in consumption $C_t(j)$ and decreasing with hours worked $H_t(j)$.

The welfare index is determined by the sum of the current and expected utilities: $\mathcal{W}_t(j)=\sum^{+\infty}_{\tau=0}\beta^\tau \mathcal{U}(C_{t+\tau}(j),H_{t+\tau}(j))$

Additionally, the production function follows a Cobb-Douglas technology: $Y_t(j)= e^{\varepsilon^A_t} H_t(j)^{1-\alpha}$
where $\varepsilon^A_t\sim\mathcal{N}\left(0,\sigma_{A,t}^2\right)$ is an IID exogenous disturbance associated with a productivity shock.
The resources constraint is given by the demand from households and authorities: $Y_t=C_t + g^y\bar{Y}e^{\varepsilon^G_t},$
where $\varepsilon^G_t$ is a IDD normal shock, $\bar{Y}$ is the steady state level of the GDP and $g^y$ is the spending to GDP ratio.
The basic RBC Model with Physical Capital

Capital law of motion reads as in Solow’s model and is determined by: $I_t(j) = K_{t+1}(j) - (1-\delta)K_t(j).$

The Cobb-Douglas production function now combines labor, physical capital and technology to produce goods: $Y_t(j)= e^{\varepsilon^A_t} K_t(j)^\alpha H_t(j)^{1-\alpha},$
where $\varepsilon^A_t\sim\mathcal{N}\left(0,\sigma_{A,t}^2\right)$ is an IID exogenous disturbance associated with a productivity shock.
The resources constraint now includes investment: $Y_t=C_t + I_t + g^y\bar{Y}e^{\varepsilon^G_t},$
where $\varepsilon^G_t$ is a IDD normal shock, $\bar{Y}$ is the steady state level of the GDP and $g^y$ is the share of public spending to the GDP.

RBC Model with external habits

In this setting, we consider that each household has external consumption habits. This feature captures the autocorrelation of consumption observed in the data. Thus the utility function subject to external habits reads as follows: $\mathcal{U}(C_t(j),H_t(j))=\frac{ \left(C_t(j)-C_{t-1}\right)^{1-\sigma^C}}{1-\sigma^C}-\frac{H(j)^{1+1/\sigma^L}}{1+1/\sigma^L}.$
RBC Model with investment adjustment costs

To introduce asset price fluctuations, households supplying investment goods face an investment adjustement costs given by: $AC^I(I_t(j),I_{t-1}(j))=\left( \frac{I_t(j)}{I_{t-1}(j)} -1 \right)^2.$
The law of motion of capital with investment adjustment costs is defined by: $(1-AC^I_t)I_t(j) = K_{t+1}(j) - (1-\delta)K_t(j).$
These costs drive a wedge between the price of assets and goods and offer a tradeoff beetwen capital goods and riskless bonds.
RBC Model with variable capital utilization

Standard RBC model suppose that capital is homogenous and its utilization is constant. CEE (2005) introduce variable capital utilization in order to match the data. The amount of capital utilized in the production is: $K^u_{t+1}(j) = K_{t}(j) u_t(j).$
This equation shows that capital requires one period to be installed (i.e; « time to build »).
The Cobb-Douglas production function now combines technology, labor and utilized capital: $Y_t(j)= e^{\varepsilon^A_t} K^u_t(j)^\alpha H_t(j)^{1-\alpha}.$
The variable utilization of capital incurs a variable cost, denoted $a(u_t)$. Its functional forms is defined by:
$altex a(u_t) = \bar{Z}(u_t-1) + \frac{\bar{Z}}{2}\frac{\psi}{1-\psi}(u_t-1)^2.$
Given this cost, the resources constraint also includes capital utilization costs: $Y_t=C_t + I_t + g^y\bar{Y}e^{\varepsilon^G_t} + a(u_t)K_{t}.$
In equilibrium, the optimal capital utilization is defined by: $Z_t = a'(u_t) = \bar{Z} + \bar{Z}\frac{\psi}{1-\psi}(u_t-1).$
New Keynesian Model codes (NK)
In this section, the previous basic RBC model is extended to account for nominal rigidities implied by price stickiness.

The New Keynesian Model

The standard New Keynesian model assumes that monopolistic competitive firms are price makers on the good market, but they cannot adjust prices as prices are sticky. There are two ways of introducing nominal rigidities: the Rotemberg way, see Rotemberg (1982) and the Calvo price setting, see Calvo (1983). I present here the Calvo price setting. There is a continuum of monopolitic firms $i\in[0;1]$ that chooses their price $P^* _t(i)$. Among these firms, a fraction $\theta^p$ is not allowed to set price, then the price remains the same such that $P^*_{t}(i)=P_{t-1}(j)$. For the share $1-\theta^p$ of firms allowed to reset their price, each firm maximizes the expected sum of profits: $\max_{P^*_{t}(j)}\sum_{\tau=0}^{+\infty} \left(\beta\theta^p\right)^\tau \left( P^*_{t}(j) - MC_{t+\tau}(j) \right) Y_{t+\tau}(j),$
under the demand constraint from final goods packers.
The FOC from the previous problem, combined with the aggregate price equation and taken in logs gives rise to the New Keynesian Phillips Curve (NKPC): $\widehat{\pi}_t = \beta E_t\widehat{\pi}_{t+1} + \frac{(1-\theta^p)(1-\beta\theta^p)}{\theta^p}(\widehat{mc}_t-\widehat{p}_t).$
Finally, to close the model, we suppose that monetary authority controls the nominal interest rates and is concerned by both price and GDP growths. The monetary policy rule à la Taylor in logs reads: $\widehat{r}_t = \rho^R\widehat{r}_{t-1} + (1-\rho^R)( \phi^\pi\widehat{\pi}_t + \phi_Y( \widehat{y}_t - \widehat{y}_{t-1} )$
New Keynesian Model with price indexation

Galì and Gertler (1999) observe backward looking dynamics in firms’ price setting. They include in New Keynesian setup an indexation mechanism when firms are setting their price. In particular in our model, for the fraction $\theta^p$ of firms not allowed to reset price, their selling price remains the same such that $P^*_{t}(i)=P_{t-1}(j)\pi_{t-1}^{\gamma^p}$ and indexed on past inflation in a proportion $\gamma^p$. Concerning the share $1-\theta^p$ of firms allowed to reset their price, each firm maximizes the expected sum of profits: $\max_{P^*_{t}(j)}\sum_{\tau=0}^{+\infty} \left(\beta\theta^p\right)^\tau \left( P^*_{t}(j) \left( \frac{P_{t-1+\tau}}{P_{t-1}} \right)^{\gamma^p} - MC_{t+\tau}(j) \right) Y_{t+\tau}(j),$
under the demand constraint from final goods packers.
The FOC from the previous problem, combined with the aggregate price equation and taken in logs give rise to the New Keynesian Phillips Curve (NKPC):
\$late
\widehat{\pi}_t = \gamma^p\widehat{\pi}_{t-1} + \beta E_t\widehat{\pi}_{t+1} + \frac{(1-\theta^p)(1-\beta\theta^p)}{\theta^p}(\widehat{mc}_t-\widehat{p}_t).
Published codes
Here are my own codes for models published in peer-review journals.

Global banking and the conduct of macroprudential policy in a monetary union

This paper questions the role of cross-border lending in the definition of national macroprudential policies in the European Monetary Union. We build and estimate a two-country DSGE model with corporate and interbank cross-border loans, Core-Periphery diverging financial cycles and a national implementation of coordinated macroprudential measures based on Countercyclical Capital Buffers. I provide here the estimated model (at the mode), not the optimization exercise.
A Welfare Analysis of Macroprudential Policy Rules in the Euro Area

In this paper published in Revue d’Economie Politique in 2017, we estimate DSGE model of the European Monetary Union that accounts for financial differences between core and peripheral countries. We find that country-adjusted macroprudential measures lead to significant welfare gains with respect to a uniform macroprudential policy rule that reacts to union-wide financial developments. However, peripheral countries are the winners from the implementation of macroprudential measures while core countries incur welfare losses, thus questioning the interest of adopting coordinated macroprudential measures with peripheral countries.
Financial Frictions and the Extensive Margin of Activity

In this paper published in Research in Economics in 2015, we evaluate the role of financial frictions on the decision to create new goods/startups using an estimated DSGE model. We extend the initial framework of Bilbiie, Ghironi and Melitz (2012) and augment it with real, nominal and financial frictions to get a data friendly model. The model is estimated using Bayesian techniques for the US economy. I share the model which is calibrated on the posterior estimated mean value of deep parameters and shocks, I also share the data involved in the estimation exercise.
Cross-border lending (interbank and corporate) in an Estimated DSGE model

This model is the first estimated DSGE model with cross-border lending and has been published in the Journal of Economic Dynamics and Control (2015). I cannot give the data, these are internal to ECB and cannot be shared. The given mod file is calibrated on the estimated parameters and shocks in our paper (at the posterior mean).
A Simple dynamic 3-equation New Keynesian Model

This code was published in the Economics and Business Review hosted by the University of Poznan. This paper aims at introducing New Keynesian Macroeconomics for graduate students. This paper is currently taught in the Master Program of the University Paris-Dauphine, University of Rennes and the University of Poznan.

### Bibliography

Melitz, M., Bilbiie, F. O., & Ghironi, F. (2012). Endogenous Entry, Product Variety, and Business Cycles. Journal of Political Economy, 120(2).
Calvo, G. A. (1983). Staggered prices in a utility-maximizing framework. Journal of monetary Economics, 12(3), 383-398.
Christiano, L. J., Eichenbaum, M., & Evans, C. L. (2005). Nominal rigidities and the dynamic effects of a shock to monetary policy. Journal of political Economy, 113(1), 1-45.
Poutineau, J. C., & Vermandel, G. (2015). Cross-border banking flows spillovers in the Eurozone: Evidence from an estimated DSGE model. Journal of Economic Dynamics and Control, 51, 378-403.
Poutineau, J. C., & Vermandel, G. (2015). Financial frictions and the extensive margin of activity. Research in Economics, 69(4), 525-554.
Poutineau, J. C., & Vermandel, G. (2017). A Welfare Analysis of Macroprudential Policy Rules in the Euro Area. Revue d Economie Politique.
Poutineau, J. C., & Vermandel, G. (2017). Global banking and the conduct of macroprudential policy in a monetary union. Journal of Macroeconomics, 54, 306-331.
Rotemberg, J. J. (1982). A monetary equilibrium model with transactions costs.
Smets, F., & Wouters, R. (2003). An estimated dynamic stochastic general equilibrium model of the euro area. Journal of the European economic association, 1(5), 1123-1175.
Smets, F., & Wouters, R. (2007). Shocks and frictions in US business cycles: A Bayesian DSGE approach. National bank of belgium working paper, (109).