PyMacLab - Python Macroeconomics Laboratory



PyMacLab is the Python Macroeconomics Laboratory which currently primarily serves the purpose of providing a convenience framework written in form of a Python library with the ability to solve non-linear DSGE models using a DSGE model class from which to instantiate instances. At the time of writing these words, the library supports solving DSGE models using 1st and 2nd order perturbation methods which are computed around the steady state. Apart from that, the library also contains two advanced macroeconometric classes, the VAR class and the FAVAR class which can be employed for empirical work or in combination with DSGE models in order to estimate instead of calibrate deep parameters. If you want to learn about PyMacLab as quickly as possible, skip reading this and instead start reading through the tutorial series available in the Documentation section to this site.

The DSGE model class provides wrapper functions for Paul Klein’s 1st-order accurate method based on the Schur Decomposition [6] as well a more recently published method by the same author (co-authored with Paul Gomme) which computes 2nd-order accurate solutions without using Tensor Algebra [2] (using the Magnus & Neudecker 1999 definition of the Hessian matrix). PyMacLab possesses the added advantage of being equipped with an advanced model file parser module, similar to the one available in Dynare, which automates cumbersome and error-prone (log-)linearization by hand. PyMacLab is also written entirely in Python, is free and incredibly flexible to use and extend.

First things first

Features at a Glance

  • No “paper-and-pencil” linearization required, done automatically py parsing a DSGE model file.
  • Solutions based on analytical computation of Jacobian and Hessian of models using Sympycore.
  • DSGE models are Python DSGE class instances, treat them as if they were data structures, pass them around, copy them, stack them into arrays, and work with many of them simultaneously!
  • Loop over a DSGE model instance thousands of times to alter the parameter space, each time re-computing the solution.
  • Choose from closed form or non-linear steady state solvers or a combination of both.
  • Choose from a number of tried and tested perturbation methods, such as Klein’s 1st order accurate and Klein & Gomme’s 2nd order accurate methods.
  • Solving models is as fast as using optimized compiled C or Fortran code, expensive computation of analytical Jacobian and Hessian employs parallelized multi-core CPU approach.
  • DSGE example models are provided, including very complex ones such as the one based on Christiano, Eichenbaum and Evans (2001) [8].
  • Benefit from a large and growing set of convience methods to simulate models and plot filtered simulated series as well as impulse-response functions.
  • Carry out advanced empirical macroeconometric analyses using the VAR and FAVAR classes which come provided.
  • Use PyMacLab as a free Python library within a rich and rapidly evolving Python software ecosystem for scientists.
  • Enjoy the power, flexibility and extensibility of the Python programming language and the open-source transparency of PyMacLab.
  • PyMacLab is free as in freedom and distributed under a Apache 2.0 license.


PyMacLab is currently known to work well but continues to mature. This documentation site is well under way but still work-in-progress. If you have used PyMacLab already and spotted some bugs or felt that some other important features are missing, you can head over to the library’s Github repository to submit an Issue item. We are currently in the process of adding more example DSGE model files (and eliminating mistakes in already existing ones). If you have used PyMacLab yourself and want to contribute your own DSGE model files we are happy to include them! Finally, to better understand PyMacLab’s inner workings, take a look at the API documentation.



What is PyMacLab?
This is a succinct introduction to PyMacLab including an explanation of its current features.
Philosophy behind PyMacLab
Here I discuss the basic Philosophy behind PyMacLand and what it sets out to do now and in the near future.
Why Macroeconomics in Python?
In this section I touch upon the the pros and cons of doing Macroeconomics or scientific computing using Python in general.

Series of Brief Tutorials

  1. Basic DSGE tutorial

    Brief tutorial on how to use PyMacLab to work with DSGE models.

  2. PyMacLab DSGE instance tutorial

    Succinct tutorial facilitating the understanding of the DSGE OOP data structure in PyMacLab.

  3. PyMacLab DSGE instance updater tutorial

    Tutorial on how to use DSGE model instance’s intelligent runtime update features.

  4. PyMacLab DSGE steady state solver tutorial

    This section illustrates various options available to solve DSGE models’ steady state.

  5. PyMacLab DSGE dynamic solver tutorial

    This section finally shows how dynamic solution to the PyMacLab DSGE models are obtained.

  6. PyMacLab DSGE simulation and plotting tutorial

    Short tutorial on using convenience functions for simulations, IRFs and plotting.

  7. Description of all template DSGE models

    Detailed description of all of the template DSGE models which come supplied with PyMacLab.

API Documentation

PyMacLab - API Documentation
The auto-generated documentation of pymaclab’s main modules and classes


Building a Linux Scientific Environment
Building a Linux scientific environment from scratch.
Reference list of academic articles and books related to the solution of DSGE models or Python programming.
Release History
History of current and past releases

Download & Installation

PyMacLab is known to work with any of Python version greater than or equal to 2.4 and smaller than 3.0. In the future we will consider implementing a compatibility branch for versions of Python greater than or equal to 3.0, once all core dependencies are known to have been migrated as well.


Proper functioning of PyMacLab depends on a number of additional Python libraries already being installed on your system, such as:

Sympycore and Parallel Python come distributed with PyMacLab and will be installed along with the main library; the other required Python libraries need to be installed separately before and installation of PyMacLab is attempted. All of the mentioned scientific packages are great libraries by themselves and should be checked out by any serious scientist interested in doing work in Python.

The Pandas data library is not needed by the DSGE-modelling features of PyMacLab itself, but is instead required in the experimentally made available modules used to estimated and work with VAR and FAVAR models. These modules are in the pymaclab.stats. branch and some test files are included in the test/stats directory.

If you want to enjoy a Matlab-style interactive environment in which to execute and inspect DSGE and other data structures, you’d be hard-pressed to pass over the brilliant and now extra features-ladden IPython. When downloading and installing pymaclab using pip all of these dependencies should be installed automatically for you, if they are not already present on your system. Following right below is a list of options users have to install PyMacLab on their Python-ready computers.

If you already have a working Python programming environment with some of the above libraries installed, you may want to consider installing PyMacLab in its own isolated execution environment using virtualenv which would ensure that your existing system Python installation would remain untouched by PyMacLab’s setup routine and its dependency resolution.

Option 1

You can download the source code of PyMacLab right here. Alternatively, PyMacLab is also hosted at PyPI and can be installed in the usual way by executing the command inside a Linux shell using pip:

sudo pip install pymaclab

Option 2

Otherwise get the latest source code compressed as a tarball here:

And install it in the usual way by running in a Linux shell the command:

sudo python install

Option 3

Alternatively, for the brave-hearted and bleeding-edge aficionados, they can also navigate over to our open Github repository where PyMacLab is currently being maintained, and clone the most up-to-date version and/or nightly build, by having git installed on your system and calling:

git clone git://

This will create a new folder called pymaclab containing the latest version of the source code as well as the installation script which you can then use in the usual way to install the module on your system.

Credit & Thanks

Thanks must go to all members of the Python scientific community without whose efforts projects like PyMacLab would be much harder to implement. We are all standing on the shoulders of giants! Special thanks go to Eric Jones, Travis Oliphant and Pearu Peterson, the founding coders of the Numpy/Scipy Suite which PyMacLab heavily makes use of.

I would also like to give a special mention to Skipper Seabold, lead coder of another unique and outstanding Python library, Statsmodels, who has kindly helped me clean up some of the rough edges of my code. I would also like to thank colleagues at Nottingham University Business School China, especially Gus Hooke and Carl Fey for their kind support.

Last but most certainly not least, my expression of thanks go to my former PhD supervisor Max Gillman who has introduced me to the world of general equilibrium macroeconomics and to monetary macroeconomics more deeply. Also, many of the lectures once delivered by Martin Ellison formerly at the Economics Department at Warwick now at Oxford made a lasting impression on me.

Online Resources