Git Product home page Git Product logo

dsgepy's Introduction

dsgepy

This is a Python library to specify, calibrate, solve, simulate, estimate and analyze linearized DSGE models. The specification interface is inpired by dynare, which allows for symbolic declarations of parameters, variables and equations. Once a model is calbrated or estimated, it is solved using Sims (2002) methodology. Simulated trajectories can be generated from a calibrated model. Estimation uses bayesian methods, specifically markov chain monte carlo (MCMC), to simulate the posterior distributions of the parameters. Analysis tools include impulse-response functions, historical decompostion and extraction of latent variables.

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.


Installation

You can install this development version using:

pip install dsgepy

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 declaration with non-linearized 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. This process is slow, 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. Also, MCMC methods for macroeconomic models require many iterations to achieve convergence. Clearly, there is room for improvement on the efficiency of these estimation algorithms. Contributions are welcome. Speaking of contributions...


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 [email protected]

dsgepy's People

Contributors

gusamarante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dsgepy's Issues

Error using dsge.estimate() in: example_snkm.ipynb

Hi everyone!
I'm trying to reproduce the output in the Jupiter Notebook file "example_snkm.ipynb". I'm currently stuck in the following error when I'm running the dsge.estimate() function. I have not made any changes to the code. Thank you in advance:

dsge.estimate(file_path='example_snkm.h5', nsim=2000, ck=0.2)
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:347: RuntimeWarning: invalid value encountered in scalar subtract
shrinkSignal = ((not badg) and (f0 - f < max(- theta * dfhat * lambda_, 0))) or (badg and (f0 - f < 0))
f at the beginning of iteration 1 is inf
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:438: RuntimeWarning: invalid value encountered in scalar subtract
g0 = (fcn(x + tvecv) - f0) / delta
C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py:347: RuntimeWarning: invalid value encountered in scalar subtract
shrinkSignal = ((not badg) and (f0 - f < max(- theta * dfhat * lambda_, 0))) or (badg and (f0 - f < 0))
Traceback (most recent call last):

File "C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\lineardsge.py", line 171, in estimate
df_chains = pd.read_hdf(file_path, key='chains')

File "C:\Users\nicol\anaconda3\lib\site-packages\pandas\io\pytables.py", line 414, in read_hdf
raise FileNotFoundError(f"File {path_or_buf} does not exist")

FileNotFoundError: File example_snkm.h5 does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\nicol\AppData\Local\Temp\ipykernel_10112\3113586507.py", line 1, in
dsge.estimate(file_path='example_snkm.h5', nsim=2000, ck=0.2)

File "C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\lineardsge.py", line 187, in estimate
_, theta_mode_irr, _, h, _, _, retcodeh = csminwel(fcn=obj_func, x0=theta_irr0, crit=1e-14, nit=100,

File "C:\Users\nicol\anaconda3\lib\site-packages\dsgepy\pycsminwel.py", line 231, in csminwel
nogh = gh.size == 0

AttributeError: 'NoneType' object has no attribute 'size'

Forcasting usign DSGE model

Hi everyone!
I'm trying to forecast the observable variable using an estimated and calibrated standard DSGE using the Dsgepy library. Using some real data from FRED I calibrated the model but now i have some difficulty to forecast GDP, interest rates, exc. There are some examples or functions already in Python?

Package name

Hi Gustavo,

It seems we have an issue with the package name. I am have been working on a similar, although a bit more complex project with the same name since 2018:

https://github.com/gboehl/pydsge

I think this is a bit unfortunate.. Could you maybe get in touch to see if we can resolve this?

Best,
Gregor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.