Skip to content

SIMPLE TOOLKIT for COMPUTATIONAL ANALYSIS: An abbreviated translation into Python of Harald Uhlig's "Analyzing Nonlinear Dynamic Stochastic Models Easily." Solved examples and simulations of macroeconomic models.

Notifications You must be signed in to change notification settings

Mac-Tj-NY/Uhlig_Toolkit_in_Python

Repository files navigation

Uhlig_Toolkit_in_Python

A Simple Toolkit for Computational Analysis: Solving linear approximations of dynamic stochastic general equilibrium (DSGE) models in Python

An abbreviated translation from MATLAB into Python of Harald Uhlig's solution method, as described in:

Uhlig, like others, made good use of the neoclassical growth model as an example. Before him, Robert King, Charles Plosser and Sergio Rebelo used the neoclassical growth model to develop methods for the analysis of business cycles:

  • Production, growth and business cycles: I. The basic neoclassical model. Journal of Monetary Economics (1988) 21:196-232.
  • Production, growth and business cycles: II. New directions. Journal of Monetary Economics. (1988) 21:309-41.
  • Production, growth and business cycles: Technical Appendix. Computational Economics (2002) 20: 87–116. For related code see: https://ideas.repec.org/c/dge/qmrbcd/104.html

CONTENTS OF THIS REPOSITORY:

  • 'uhlig_solver_abreviated.ipynb' Uhlig's solver algorithm using the generalized eigenvalue eigenvector method

  • 'uhlig_solver_QZ.ipynb' Uhlig's solver algorithm modified to use a QZ decomposition, based on:

    • Chris Sims in "Solving Linear Rational Expectations Models," Computational Economics, October 2002, Vol 20, Issue 1-2, pp 1-20, and in his MATLAB code qzdiv.m and qzswitch.m. For more of Sim's work see http://www.princeton.edu/~sims/

    • Paul Klein "Using the Generalized Schur Form to Solve a Multivariate Linear Rational Expectations Model," Journal of Economic Dynamics and Control, 24 (2000) 405-1423. For more of Klein's work see http://paulklein.ca/newsite/codes/codes.php

    • The functions qzdiv() and qzswitch() are adaptations from Sims' MATLAB code into Python made by Kerk Phillips (https://github.com/kerkphil) and Yulong Li (https://github.com/yulong-git).

  • Other programs: Calc_Moments.ipynb, Detrend_Filters.ipynb, uhlig_impulse_resp_all.ipynb, uhlig_plot_impresp_all.ipynb, uhlig_simul_rand.ipynb, uhlig_plot_simul_all.ipynb

  • Unsolved examples: uhlig_example_xx.ipynb

  • Solved examples with impulse responses: za_impresp_example_xx.ipynb

  • Solved examples with simulations, given randomly generated innovations: zb_simul_example_xx.ipynb

  • Solved examples filtered into trend and cyclical components with calculated moments for cyclical components. Log first differences provided for comparison: zc_detmom_example_xx.ipynb

  • Solved examples using a QZ decomposition: zd_qzsoln_example_xx.ipynb

COPYRIGHT:

(c) Harald Uhlig "Feel free to copy, modify and use at your own risk. However, you are not allowed to sell this software or otherwise impinge on its free distribution."

NOTES:

Generalized Eigenvalue Eigenvector Method:

  • As a check, I ran the examples using both my Python code and Uhlig's MATLAB code. I then compared the output matrices, i.e. PP, QQ, RR, SS, Resp_mat, and verified that these are identical for all models.
  • I also compared intermediate matrices, including Psi_mat, Gamma_mat, Theta_mat, Xi_mat, Delta_mat, Lambda_mat, Omega_mat, which are nearly identical for all models.
  • Exceptions occur in the intermediate matrices eVecs (Xi_eigvec) and eVals (Xi_eigval) because eigenvalues and eigenvectors computed in Python (numpy.linalg.eig() function) do not always coincide with MATLAB (eig() function). However, the results of both Python and MATLAB eigenvalue and eigenvector computations appear to be true and differences are not due to discrepancies in precision.
  • These differences have no impact on the solution output of example models, with one exception.
  • They do result in different intermediate and output matrices for 'Model 3 with Sunspots' of example 05. Separately, for instructional purposes, Uhlig set-up 'Model 3' of example 04 incorrectly and finds that the model hangs when solved. He showed the correction in example 05_03.

QZ Decomposition:

  • When using MATLAB, all examples have identical solution results for the generalized method and the QZ decomposition.
  • For the most part, the QZ decomposition in Python yields identical results to the QZ decomposition in MATLAB.
  • However, the functions numpy.linalg.qz() in Python and qz() in MATLAB return small discrepancies for intermediate matrices in examples 03, 04_01, 05_02 and 07. But these are small enough so that the final output matrices are the same.
  • In example 05_03, however, both intermediate matrices and final output matrices are noticeably different between the Python and MATLAB QZ decomposition solvers.

Moment Calculations were spot checked using EViews.

About

SIMPLE TOOLKIT for COMPUTATIONAL ANALYSIS: An abbreviated translation into Python of Harald Uhlig's "Analyzing Nonlinear Dynamic Stochastic Models Easily." Solved examples and simulations of macroeconomic models.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published