Building a fast, flexible and free DSGE model

A team at the New York Fed is part way through translating its DSGE model into Julia, a fast, open-source mathematical programming language
federal-reserve-bank-new-york
The New York Fed is translating its DSGE model into the Julia programming language

Dynamic stochastic general equilibrium (DSGE) models are a mainstay of economic modelling at central banks, but they are big beasts, consuming large quantities of computing power and time to run.

That is not about to change, but researchers at the Federal Reserve Bank of New York, in co-operation with Thomas Sargent and John Stachurski's QuantEcon project, have taken a big step towards streamlining the process.

Stachurski, a professor at the Australian National University, approached the New York Fed in 2015 about the possibility of translating a model for policy analysis into a new programming language.

The NY Fed had already published the code underlying its DSGE model, originally written in Matlab, and was pleased to take up Stachurski's suggestion.

The team chose to translate into Julia, a relatively new open source programming language designed to be easy to learn and focused on efficient mathematical programming.

Marco Del Negro and Marc Giannoni, both assistant vice-presidents in the NY Fed's research department, headed the project. "One of the arguments for going with Julia was it is fairly close to Matlab," says Giannoni. "People who are familiar with Matlab can at least read code written in Julia. There are a lot of subtleties to Julia you must get familiar with, but at least you can get started."

Lengthy translation

Research analysts Erica Moszkowski and Micah Smith, and summer intern Pearl Li, took on the bulk of the translation work, with QuantEcon economists acting as consultants.

The three had some coding experience, and Moszkowski had studied part of the QuantEcon course in computational economics, but it was still a steep learning curve.

The translation process for the estimation step took the summer and autumn to complete, and the team published the results in early December 2015. Work on translating the forecasting step and other features is ongoing.

By the time they had finished, the team had managed to cut the number of lines of code nearly in half – from 6,300 to 3,700 – and cut the time it takes to run some sections by as much as 90%. Overall, the model now runs around four times faster.

"The final product was much more expressive and elegant, I think, than the original Matlab code," says Smith.

The process was not as simple as recreating the Matlab code like-for-like. "A significant amount of the time was spent on design challenges, to make the code as clear and elegant and user-friendly as possible," explains Moszkowski.

Adaptation

All the code for the estimation step is now available on GitHub, an online repository for open-source code. Anyone can therefore download and run it with only a limited grasp of programming in Julia required (see box below). It comes pre-packed with sample dataset and configuration.

By making the model free, the hope is coders will take the model and suggest improvements, so it can evolve over time – indeed, it already draws on code originally written by economist Christopher Sims.

Other central banks and researchers can also take the model and adapt it to their needs, and many have already expressed an interest. "The whole point of putting our code on the web is for others to use it and adapt it to their needs," says Del Negro.

The model is designed as a flexible framework, allowing users to easily change it to match local conditions by adding their own equilibrium conditions, parameters and other settings. Applying it to other economies is "well within the scope" of the model, says Smith.

The NY Fed has been quick to recognise the potential in hiring economists who can code. Research analysts joining the NY Fed have typically studied some computer science at the undergraduate level, and many are studying the QuantEcon course to improve their skills.

During the development of the Matlab code, the NY Fed adopted a do-it-yourself approach rather than using a modelling package such as Dynare, which is in use at many central banks. Del Negro says this helped build the coding know-how to take on the Julia project.

Not all central banks can draw on this depth of expertise, but adapting and running the model requires much less coding knowledge than translating it.

Next steps

The focus for the team is now on building the parts of the model most useful for policy-making, such as forecasting. When that is done, the plan is to try and improve the code, possibly drawing on some of the higher-quality packages built by the coding community.

One key goal is to adapt the current linear model into a non-linear model, particularly useful when dealing with financial frictions. To do this, the team is planning to add a particle filter, or sequential Monte Carlo method, in the place of the current Kalman filter.

Translating other models into Julia is also "definitely" a possibility, says Del Negro, pointing to the NY Fed's nowcasting model as a likely candidate. The model incorporates various data releases into a more timely estimate of GDP growth than official statistics can manage.

There remains a debate over the value of DSGE models, as other models often perform better in specific areas, though DSGE methods have improved significantly in recent years.

Del Negro comes to their defence: "They are not the best athlete in all competitions, but they are up there. They do pretty well at a variety of things – forecasting, policy analysis, and a structural understanding of the economy. I guess we are pretty happy with it so far."

Running the model

One of the many advantages of the New York Fed's Julia translation is it can be run straightforwardly without state-of-the-art hardware, and with only a basic knowledge of coding. As such, I was able to test it on my own laptop.

To set up, I followed the initial steps of QuantEcon's excellent Julia tutorials, using the IJulia backend for a Jupyter notebook, with the addition of the Anaconda collection of mathematical packages. Jupyter is more user-friendly than the vanilla Julia program.

With IJulia installed, you can run Julia from your usual internet browser. To get the DSGE model up and running, simply create a new notebook and use the Pkg.add command to install the New York Fed's package straight from GitHub. From there, copying and pasting the code supplied in the Readme and hitting go sets the model off using the sample dataset.

julia-metropolis-hastings

Make sure you have time to spare. Optimisation can take a particularly long time – after 24 hours it was still running in my case, which I understand is common. Handily, the code saves its best guess of the mode of the posterior distribution as it goes, so I sent the ‘good enough' mode to the next estimation step – again, this is detailed in the Readme – and set the model running again.

Computing the Hessian matrix and completing the Metropolis-Hastings sampling algorithm took nearly another day in my case, somewhat longer than the New York Fed's typical 10–12 hours, but they have much more powerful processors.

When it finishes, the model spits out a large set of parameter estimates, which, when the translation work is completed, will feed into the forecasting step.

  • LinkedIn  
  • Save this article
  • Print this page  

Only users who have a paid subscription or are part of a corporate subscription are able to print or copy content.

To access these options, along with all other subscription benefits, please contact [email protected] or view our subscription options here: http://subscriptions.centralbanking.com/subscribe

You are currently unable to copy this content. Please contact [email protected] to find out more.

You need to sign in to use this feature. If you don’t have a Central Banking account, please register for a trial.

Sign in
You are currently on corporate access.

To use this feature you will need an individual account. If you have one already please sign in.

Sign in.

Alternatively you can request an individual account here: