Dsge model in python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Dynamic Stochastic Equilibrium Models (DSGE) in Python

License

escheffel/pymaclab

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.markdown

PyMacLab — The Python Macroeconomics Laboratory

PyMacLab is the Python Macroeconomics Laboratory which currently primarily serves the purpose of providing a convenience framework written in Python to solve non-linear DSGE models easily. At the time of this writing the library supports solving DSGE models using 1st and 2nd order perturbation methods which are computed around the steady state. In particular, the library provides wrapper functions for Paul Klein’s 1st-order accurate method based on the Schur Decomposition as well a more recently published method by the same author (co-authored with Paul Gomme, see here) which provides 2nd-order accurate solutions without using Tensor Algebra (using the Magnus and Neudecker 1999 definition of the Hessian matrix).

The library is extremely user-friendly in the sense of employing a model text file parser similar to that present in Dynare which requires users to only write down the original set of non-linear first-order conditions of optimality. In addition, users are offered a menu of options of how to provide information required for calculating the steady state of the model. Once the model is parsed and read in, several options of solving it exist and users are provided with further convenience methods suitable for simulating solved models and investigating dynamic statistical properties.

Читайте также:  Csharp загрузка из файла

It should also be mentioned that because PyMacLab is a convenience library of highly modular nature (using a object-oriented programming approach) it is very easy to loop over one model several thousand times each time changing the original set of primitive parameters, such as depreciation rates, impatience factors, etc. in order to compute solutions of the same model over a large set of conceivable parameterisations. Also, whenever solution methods require the calculation of the Jacobian or Hessian, this is always done analytically (symbolically) using the Python symbolic computation library SympyCore and not numerically as in other software packages. Sympycore is not supplanted by Sympy, but it works well at the moment so we will alter PyMacLab at a later stage to reflect this.

PyMacLab was authored by Eric M. Scheffel who is currently working as Assistant Professor in Economics at Nottingham University China and is distributed under the Apache License v2.0. When using this Python library please make sure to cite the project (using Latex) as:

@Misc, title = : Open source Macroeconomics Laboratory>, year = , url = "http://github.com/escheffel/pymaclab/" >
  • No “paper-and-pencil” linearization required, done automatically by 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 ordinary 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. Many options provided for solving for a model’s steady state.
  • 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.
  • If you have dynare++ installed on your computer, pymaclab provides a convenient wrapper/translation module to allow it to be used from inside pymaclab.
  • 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) [9].
  • Benefit from a large and growing set of convenience 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. You can easily programm extensions for pymaclab, you cannot do this easily for Dynare or Dynare++!
  • PyMacLab is free as in freedom and distributed under a Apache 2.0 license.
Читайте также:  Form input css template

numpy (required)
scipy (required)
sympycore (comes supplied with pymaclab)
mako (optional — but necessary for dynare++ translator)
wheezy.template (required)
pp (optional — but highly recommended for speed)
ipython (optional)
pandas (required)
dynare++ (optional — but necessary for dynare++ solution)

While numpy, scipy, and sympycore are absolutely necessary to run PyMacLab, Parallel Python (PP) can autodetect multi-core processors and can potentially speed up the computation of elements such as the analytical Hessian of a non-linear DSGE model, while mlabwrap have been marked as deprecated and are in the process of being pruned from the code. Scikits.timeseries is not used in any of the classes themselves, but is used in the example test file that ships with the library, so it is not essential. To explore the use of PyMacLab interactively a special IPython environment can be launched with pre-loaded convenience functions, but again, ipython is not a necessary dependency.

python setup.py build sudo python setup.py install

The below code snippet is indicative of how PyMacLab can be used in an environment such as IPython. Since the library is still undergoing change, it is always advisable to enter the subdirectory containing the test.py test-script and inspect/run this to better understand PyMacLab’s syntax. This could be outdated information. Please always consult PyMacLab’s Sphinx documentation for the latest explanation of how to use the library at www.pymaclab.com.

# Import the PyMacLab library import pymaclab as pm # Import a convenience handler to filepaths for supplied DSGE model files from pymaclab.modfiles import models # Model Instantiation, RBC1 steady state numerically solved/approximated rbc1 = pm.newMOD(models.stable.rbc1_num) # Model instantiation with closed-form steady state solution rbc2 = pm.newMOD(models.stable.rbc1_cf) # Solve the models using different methods rbc1.modsolvers.forkleind.solve() rbc2.modsolvers.pyklein2d.solve() # Simulate the models after they have been solved rbc1.modsolvers.forkleind.sim(400) rbc2.modsolvers.pyklein2d.sim(200) # If dynare++ is installed and in your PATH, then you can solve # the model alternatively using dynare++ in the background and all # relevant solution attributes get attached to the DSGE model instance # This feature is still experimental at the moment rbc1.modsolvers.dynarepp.solve(order=1,centralize=False) rbc1.modsolvers.dynarepp.P

About

Dynamic Stochastic Equilibrium Models (DSGE) in Python

Источник

dsgepy

This is a Python library to calibrate, estimate and analyze linearized DSGE models. The interface is inpired by the dynare interface which allows for symbolic declarations of the variables and equations. The implemented bayesian estimation method uses markov chain monte carlo (MCMC) to simulate the posterior distributions of the parameters. This library is an effort to bring the DSGE toolset into the open-source world in a full python implementation, which allows to embrace the advantages of this programming language when working with DSGEs.

Читайте также:  Php расширение файла по url

Installation

You can install this development version using:

Kalman Filter

Computing the likelihood of models involve using the kalman filter. pykalman is available for python, but some adjustments to the original library are needed to use with this library. So in order for dsgepy to work you need the corrected version of pykalman , available here. Make sure to clone this version and add it to the interpreter befor using dsgepy . The corrections here correct the way pykalman handles masked numpy arrays and deals with ill-estimated covariance matrices.

Example

A full example on how to use this library with a small New Keynesian model is available in this Jupyter notebook. The model used in the example is descibred briefly by the following equations:

Model Especification

For now, the model equations have to be linearized around its steady-state. Soon, there will be a functionality that allows for non-linearized declaration of the equilibrium conditions.

Model Solution

The solution method used is based on the implementation of Christopher A. Sims’ gensys function. You can find the author’s original matlab code here. The paper explaining the solution method is this one.

Model Estimation

The models are estimated using Bayesian methdos, specifically, by simulating the posterior distribution using MCMC sampling. Simulations are typically long, so there is a functionality that allows you to stop a simulation and continue it later from where it stoped.

Analysis

There are functionalities for computing Impulse-Response funcions for both state variables and observed variables. Historical decomposition is also available, but only when the number of exogenous shocks matches the number of observed variables.

Drawbacks

Since there is symbolic declaration of variables and equations, methdos involving them are slow, so the MCMC methods typically take a long time to run. Although there is room for improvement for the efficiency of these estimation algorithms.

Contributing

If you would like to contribute to this repository, plese check the contributing guidelines here. A list of feature suggestions is available on the projects page of this repository.

More Information and Help

If you need more information and help, specially about contributing, you can contact Gustavo Amarante on developer@dsgepy.com

Источник

Оцените статью