Module Documentation


class pydsge.parser.DSGE(*kargs, **kwargs)

Bases: pydsge.clsmethods.DSGE_RAW

Base class. Every model is an instance of the DSGE class and inherents its methods.

gen_sys(par=None, l_max=None, k_max=None, get_hx_only=False, parallel=False, verbose=True)
classmethod load(npzfile, force_parse=False, verbose=False)
classmethod parse(mtxt, ffile)
classmethod read(mfile, verbose=False)

Read and parse a given *.yaml file.

Parameters:mfile (str) – Path to the *.yaml file.
pydsge.parser.crawl_cached_models(mtxt, ftxt)


contains functions related to (re)compiling the model with different parameters

pydsge.mpile.box_check(self, par=None)

Check if parameterset lies outside the box constraints

Parameters:par (array or list, optional) – The parameter set to check
pydsge.mpile.get_cov(self, npar=None, **args)

get the covariance matrix

pydsge.mpile.get_par(self, dummy=None, npar=None, asdict=False, full=True, nsamples=1, verbose=False, roundto=5, debug=False, **args)

Get parameters. Tries to figure out what you want.

  • dummy (str, optional) –

    Can be None, a parameter name, a parameter set out of {‘calib’, ‘init’, ‘prior_mean’, ‘best’, ‘mode’, ‘mcmc_mode’, ‘post_mean’, ‘posterior_mean’} or one of {‘prior’, ‘post’, ‘posterior’}.

    If None, returns the current parameters (default). If there are no current parameters, this defaults to ‘best’. ‘calib’ will return the calibration in the main body of the *.yaml (parameters). ‘init’ are the initial values (first column) in the prior section of the *.yaml. ‘mode’ is the highest known mode from any sort of parameter estimation. ‘best’ will default to ‘mode’ if it exists and otherwise fall back to ‘init’. ‘posterior_mean’ and ‘post_mean’ are the same thing. ‘posterior_mode’, ‘post_mode’ and ‘mcmc_mode’ are the same thing. ‘prior’ or ‘post’/’posterior’ will draw random samples. Obviously, ‘posterior’, ‘mode’ etc are only available if a posterior/chain exists.

    NOTE: calling get_par with a set of parameters is the only way to recover the calibrated parameters that are not included in the prior (if you have changed them). All other options will work incrementially on (potential) previous edits of these parameters.

  • asdict (bool, optional) – Returns a dict of the values if True and an array otherwise (default is False).
  • full (bool, optional) – Whether to return all parameters or the estimated ones only. (default: True)
  • nsamples (int, optional) – Size of the sample. Defaults to 1
  • verbose (bool, optional) – Print additional output infmormation (default is False)
  • roundto (int, optional) – Rounding of additional output if verbose, defaults to 5
  • args (various, optional) – Auxilliary arguments passed to gen_sys calls

Numpy array of parameters or dict of parameters

Return type:

array or dict

pydsge.mpile.posterior_sampler(self, nsamples, seed=0, verbose=True)

Draw parameters from the posterior.

Parameters:nsamples (int) – Size of the sample
Returns:Numpy array of parameters
Return type:array
pydsge.mpile.prior_sampler(self, nsamples, seed=0, test_lprob=False, lks=None, verbose=True, debug=False, **args)

Draw parameters from prior. :param nsamples: Size of the prior sample :type nsamples: int :param seed: Set the random seed (0 by default) :type seed: int, optional :param test_lprob: Whether to ensure that drawn parameters have a finite likelihood (False by default) :type test_lprob: bool, optional :param verbose: :type verbose: bool, optional :param debug: :type debug: bool, optional

Returns:Numpy array of parameters
Return type:array
pydsge.mpile.sample_box(self, dim0, dim1=None, bounds=None, lp_rule=None, verbose=False)

Sample from a hypercube

pydsge.mpile.set_par(self, dummy=None, setpar=None, npar=None, verbose=False, return_vv=False, roundto=5, **args)

Set the current parameter values.

In essence, this is a wrapper around get_par which also compiles the transition function with the desired parameters.

  • dummy (str or array, optional) – If an array, sets all parameters. If a string and a parameter name,`setpar` must be provided to define the value of this parameter. Otherwise, dummy is forwarded to get_par and the returning value(s) are set as parameters.
  • setpar (float, optional) – Parametervalue to be set. Of course, only if dummy is a parameter name.
  • npar (array, optional) – Vector of parameters. If given, this vector will be altered and returnd without recompiling the model. THIS WILL ALTER THE PARAMTER WITHOUT MAKING A COPY!
  • verbose (bool) – Whether to output more or less informative messages (defaults to False)
  • roundto (int) – Define output precision if output is verbose. (default: 5)
  • args (keyword args) – Keyword arguments forwarded to the gen_sys call.


pydsge.engine.bruite_wrapper(bmat, bterm, x_bar, q)

iterate over (l,k) until (l_max, k_max) and check if RE equilibrium

pydsge.engine.check_cnst(bmat, bterm, s, l, k, q0)

constraint value in period s given CDR-state q0 under the assumptions (l,k)

pydsge.engine.find_lk(bmat, bterm, x_bar, q)

iteration loop to find (l,k) given state q

pydsge.engine.get_lam(omg, psi, S, T, V, W, h, l)
pydsge.engine.get_omg(omg, psi, lam, xi, S, T, V, W, h, l)
pydsge.engine.preprocess(self, PU, MU, PR, MR, gg, fq1, fp1, fq0, parallel=False, verbose=False)

dispatcher to jitted preprocessing

pydsge.engine.preprocess_jit(S, T, V, W, h, fq1, fp1, fq0, omg, lam, x_bar, l_max, k_max)

jitted preprocessing of system matrices until (l_max, k_max)

pydsge.engine.preprocess_jit_parallel(S, T, V, W, h, fq1, fp1, fq0, omg, lam, x_bar, l_max, k_max)

jitted preprocessing of system matrices until (l_max, k_max)

pydsge.engine.preprocess_jittable(S, T, V, W, h, fq1, fp1, fq0, omg, lam, x_bar, l_max, k_max)

jitted preprocessing of system matrices until (l_max, k_max)

pydsge.engine.preprocess_tmats(self, fq1, fp1, fq0, verbose)

dispatcher to jitted preprocessing

pydsge.engine.preprocess_tmats_jit(pmat, pterm, qmat, qterm, fq1, fp1, fq0, omg, l_max, k_max)

jitted preprocessing of system matrices until (l_max, k_max)

pydsge.engine.t_func_jit(pmat, pterm, qmat, qterm, bmat, bterm, x_bar, hxp, hxq, hxc, state, shocks, set_l, set_k, x_space)

jitted transitiona function


class pydsge.modesearch.PMDM(model, maxfev, tol, method, linear, update_freq, verbose)

Bases: object

A wrapper to have a progress par for the posterior mode maximization.

name = 'PMDM'
pydsge.modesearch.cmaes(self, p0=None, sigma=None, pop_size=None, restart_factor=2, seeds=3, seed=None, linear=None, lprob_seed=None, update_freq=1000, verbose=True, debug=False, **args)

Find mode using CMA-ES from grgrlib.

  • pop_size (int) – Size of each population. (Default: number of dimensions)
  • seeds (in, optional) – Number of different seeds tried. (Default: 3)
pydsge.modesearch.pmdm(self, linear=None, maxfev=None, linear_pre_pmdm=False, method=None, tol=0.01, update_freq=None, verbose=False)


pydsge.plots.fast_kde(x, bw=4.5)

A fft-based Gaussian kernel density estimate (KDE) The code was adapted from

  • x (Numpy array or list) –
  • bw (float) – Bandwidth scaling factor for the KDE. Should be larger than 0. The higher this number the smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott’s rule of thumb (the default rule used by SciPy).

  • density (A gridded 1D KDE of the input points (x))
  • xmin (minimum value of x)
  • xmax (maximum value of x)

pydsge.plots.get_axis(ax, default_rows, default_columns, **default_kwargs)

Verifies the provided axis is of the correct shape, and creates one if needed.

  • ax – matplotlib axis or None
  • default_rows – int, expected rows in axis
  • default_columns – int, expected columns in axis
  • **default_kwargs – keyword arguments to pass to plt.subplot

axis, or raises an error

pydsge.plots.kdeplot_op(ax, data, bw, prior=None, prior_alpha=1, prior_style='--')

Get a list of density and likelihood plots, if a prior is provided.

pydsge.plots.plot_posterior_op(trace_values, ax, bw, prior, kde_plot=False, point_estimate='mean', round_to=3, alpha_level=0.05, ref_val=None, rope=None, text_size=16, display_additinal_info=False, **kwargs)

Artist to draw posterior.

pydsge.plots.posteriorplot(trace, varnames=None, tune=0, figsize=None, plots_per_fig=4, text_size=None, ropep=None, ref_val=None, bw=4.5, ax=None, **kwargs)
pydsge.plots.scale_text(figsize, text_size)

Scale text to figsize.


Sort the normalized historical decomposition into negative and positive contributions

pydsge.plots.traceplot(trace, varnames, tune, figsize=None, combined=False, plots_per_fig=3, priors=None, draw_each_trace=True, bw=4.5, text_size=None, display_additinal_info=False, **kwargs)



class pydsge.symbols.Equation(*args, **kwargs)

Bases: sphinx.ext.autodoc.importer._MockObject

class pydsge.symbols.LaggedExpectation(name, date=0, exp_date=0)

Bases: pydsge.symbols.Variable

class pydsge.symbols.Parameter(name, exp_date=0)

Bases: sphinx.ext.autodoc.importer._MockObject

class pydsge.symbols.Shock(name, **args)

Bases: pydsge.symbols.TSymbol

class pydsge.symbols.TSymbol(name, **args)

Bases: sphinx.ext.autodoc.importer._MockObject

class pydsge.symbols.Variable(name, **args)

Bases: pydsge.symbols.TSymbol