snowdrop.src.model package

Submodules

snowdrop.src.model.factory module

snowdrop.src.model.factory.getModel(name, eqs, variables, parameters, shocks, exogenous=[], exog_data={}, shocks_file_path=None, Solver=None, ss=None, meas_eqs=[], meas_variables=[], var_labels={}, meas_shocks=[], meas_parameters=[], options={}, eqs_labels=[], calibration={}, return_interface=False, infos={}, definitions={}, check=True, bCompileAll=True)[source]

Instantiate a model object based on passed parameters and calibration dictionary.

Parameters:
param name:

Model name.

type name:

str.

param eqs:

Transition equations.

type eqs:

list.

param variables:

Endogenous variables.

type variables:

list.

param parameters:

Model parameters.

type parameters:

list.

param shocks:

Shock names.

type shocks:

list.

param exogenous:

Exogenous variables.

type exogenous:

list.

param exog_data:

Exogenous data.

type exog_data:

dict.

param shocks_file_path:

Path to shock file.

type shocks_file_path:

str.

param Sover:

Solver name.

type Silver:

str.

param ss:

Map with variables names as a key and steady states as values.

type ss:

dict.

param meas_eqs:

Measurement equations.

type meas_eqs:

list.

param meas_variables:

Measurement variables. The default is an empty list.

type meas_variables:

list.

param var_labels:

Labels of endogenous variables. The default is an empty dict.

type var_labels:

dict.

param meas_shocks:

Measurement shocks. The default is an empty list.

type meas_shocks:

list.

param meas_parameters:

Measurement parameters. The default is an empty list.

type meas_parameters:

list.

param options:

Model options.

type options:

dict.

param eqs_labels:

Equation labels. The default is an empty list.

type eqs_labels:

list.

param calibration:

Calibration values. The default is an empty dictionary.

type calibration:

dict, optional.

param return_interface:

if True returns `Interface’ object.

type return_interface:

bool.

param infos:

Brief information on model. The default is an empty dictionary.

type infos:

dict, optional.

param definitions:

Variables definitions. The default is an empty dictionary.

type definitions:

dict, optional.

param check:

If True checks for errors of passed parameters. The default is False.

type check:

bool, optional.

param bCompileAll:

If True compiles all functions source code.

type bCompileAll:

bool, optional.

Returns:

Interface object.

snowdrop.src.model.factory.import_model(fname, order=1, return_interface=True, check=True, hist=None, boundary_conditions_path=None, exogenous=None, shocks_file_path=None, steady_state_file_path=None, measurement_file_path=None, calibration_file_path=None, calibration={}, tag_variables=None, tag_shocks=None, tag_parameters=None, tag_equations=None, tag_measurement_variables=None, tag_measurement_equations=None, options={}, conditions={}, debug=False)[source]

Parse a model file and create a model object.

Parameters:
param fname:

Path to model file.

type fname:

str.

param order:

Approximation order of solution of the non-linear system of equations.

type order:

int.

param return_interface:

if True returns Interface object.

type return_interface:

bool.

param check:

If True checks syntax of model file.

type check:

bool.

param hist:

Path to history file.

type hist:

str.

param boundary_conditions_path:

Path to the boundary conditions excel file. This file contains initial and terminal conditions.

type boundary_conditions_path:

str.

param exogenous:

Exogenous variables list.

type exogenous:

list.

param shocks_file_path:

Path to a file containing shock values.

type shocks_file_path:

str.

param steady_state_file_path:

Path to a file containing steady-state values.

type steady_state_file_path:

str.

param measurement_file_path:

Path to a file with measurement data.

type measurement_file_path:

str.

param calibration_file_path:

Path to calibration files or a file.

type calibration_file_path:

list or str.

param calibration:

Map with values of calibrated parameters and starting values of endogenous variables.

type calibration:

dict.

param variables:

Tag for endogenous variables section.

type variables:

list, optional.

param tag_shocks:

Tag for shock variables section.

type tag_shocks:

str, optional.

param tag_parameters:

Tag for parameters section.

type tag_parameters:

str, optional.

param tag_equations:

Tag for equations section.

type tag_equations:

str, optional.

param tag_measurement_variables:

Tag for measurement variables section.

type tag_measurement_variables:

str, optional.

param tag_measurement_equations:

Tag for measurement equations section.

type tag_measurement_equations:

str, optional.

param options:

Dictionary of options.

type options:

dict, optional.

param conditions:

Dictionary of preprocessing directives.

type conditions:

dict, optional.

param debug:

If set to True prints information on Iris model file sections. The default is False.

type debug:

bool, optional.

Returns:
modelInterface.

`Interface’ object.

snowdrop.src.model.factory.instantiate_model(txt='', order=1, data=None, exog_data={}, return_interface=False, filename='', hist=None, boundary_conditions_path=None, exogenous=None, calibration={}, shocks_file_path=None, exog_file_path=None, steady_state_file_path=None, calibration_file_path=None, labels={}, measurement_file_path=None, infos={})[source]

Parse a model file and create an instance of a model.

Parameters:
param txt:

Content of model file.

type txt:

str.

param order:

Approximation order of solution of the non-linear system of equations.

type order:

int.

param data:

Dictionary of model file.

type data:

dict.

param exog_data:

Exogenous time series.

type exog_data:

dict.

param return_interface:

If True returns `Interface’ object.

type return_interface:

bool.

param filename:

Model file name.

type filename:

str.

param hist:

Path to history file.

type hist:

str.

param boundary_conditions_path:

Path to the boundary conditions excel file. This file contains initial and terminal conditions.

type boundary_conditions_path:

str.

param exogenous:

Exogenous variables list.

type exogenous:

list.

param shocks_file_path:

Path to shock file.

type shocks_file_path:

str.

param exog_file_path:

Path to exogenous series data file.

type exog_file_path:

str.

param steady_state_file_path:

Path to a steady-state file.

type steady_state_file_path:

str.

param measurement_file_path:

Path to a file with measurement data.

type measurement_file_path:

str.

param calibration_file_path:

Path to calibration files.

type calibration_file_path:

list.

Returns:
modelModel.

Model object.

snowdrop.src.model.interface module

class snowdrop.src.model.interface.Interface(model_name, symbols, equations, ss_equations, calibration, exog_data=None, ss=None, order=1, constraints=None, objective_function=None, eq_vars=[], steady_state=None, measurement_equations=None, bellman=None, terminal_values=None, domain=None, exogenous=None, options=None, data_sources=None, measurement_file_path=None, definitions=None, priors=None, bSparse=False)[source]

Bases: object

get_cov(**opts)[source]

Return covariance of distribution.

Parameters:
param self:

Model object.

type self:

‘SymbolicModel’

param opts:

Keyword arguments .

type opts:

dict.

returns:

Covariance matrix.

get_distribution(**opts)[source]

Return random process distribution.

Parameters:
param self:

Model object.

type self:

‘SymbolicModel’

param opts:

Keyword arguments.

type opts:

Dictionary.

returns:

Exogenous process object.

get_domain()[source]

Return domain of endogenous variables.

Parameters:
param self:

Model object.

type self:

‘SymbolicModel’

returns:

Domain of endogenous variables.

get_exogenous()[source]

Exogenous process assumption.

get_grid(**dis_opts)[source]

Return model grid object.

Parameters:
param self:

Model object.

type self:

‘SymbolicModel’

param dis_opts:

Distribution options.

type dis_opts:

dict

returns:

Domain of endogenous variables.

snowdrop.src.model.interface.get_address(data, address, default=None)[source]

Type of a grid.

snowdrop.src.model.interface.get_type(d)[source]

Type of a tag.

snowdrop.src.model.model module

Model class.

class snowdrop.src.model.model.Model(interface, anticipate=None, options=None, infos=None, bCompileAll=True)[source]

Bases: object

condition(mapCond, reset=False)[source]

Set conditional shocks.

Parameters:
param self:

Parameter.

type self:

`Model’.

param mapCond:

Dictionary of conditional shocks.

type mapCond:

dict.

param reset:

Flag to reset model swap dictionary.

type reset:

bool.

flip(endogVariables, exogVariables, bParams=True)[source]

Flip endogenous variables with their exogenous counterparts.

Note

This method is in DEVELOPMENT stage and needs testing.

Parameters:
param self:

instance of Model.

type self:

`Model’.

param endogVariables:

Endogenous variables to be flipped.

type endogVariables:

list.

param exogVariables:

Exogenous (shock) variables or parameters to be flipped.

type exogVariables:

list.

get_calibration(pname, *args)[source]

Return calibration value.

Parameters:
param self:

Model object.

type self:

`Model’.

param pname:

name of the variable.

type pname:

str

param args:

Variable number of arguments.

type args:

Tuple

returns:

Calibration value.

residuals()[source]

Compute residuals of model equations.

Parameters:
param self:

Model object.

type self:

`Model’.

setCalibration(param_name, param_value)[source]

Set calibration dictionary values given the time of their appearance.

Args:
selfModel

self object.

param_namestr

Parameter name.

param_valuenumeric.

Parameter value.

Returns:

None.

setParameters(d, start=None)[source]

Set parameters values given the time of their appearance.

Args:
selfModel

self object.

ddict

Map of parameters name and parameters values.

startdatetime.

Start date of simulations. Default is None.

Returns:

None.

setShocks(d, start=None, reset=False)[source]

Set shocks values given the time of their appearance.

Args:
modelself

self object.

ddict

Map of shock name and shock values.

startdatetime.

Start date of simulations. Default is None.

Returns:

None.

setStartingValues(hist, skip_rows=0, bTreatMissingObs=True, debug=False)[source]

Set starting values for current and lagged endogenous variables.

Parameters:
param self:

Model object.

type self:

`Model’.

param hist:

Path to historical data file or dictionary.

type hist:

str or dict.

param skip_rows:

The number of rows to skip.

type skip_rows:

int.

param bTreatMissingObs:

If True find missing variables values by minimizing residuals of steady state equations given the observations.

type bTreatMissingObs:

bool.

param debug:

If True print missing variables information.

type debug:

bool.

set_calibration(*args, **kwargs)[source]

Set the calibration value.

Note

PLEASE USE THIS FUNCTION ONLY WHEN VALUE IS A SCALAR!!! IN OTHER WORDS THIS VALUE SHOULD NOT BE TIME DEPENDENT.

Parameters:
param self:

Model object.

type self:

`Model’

param args:

Variable number of arguments.

type args:

Tuple

param kwargs:

Arbitrary number of keyword arguments

type kwargs:

dict

swap(var1, var2, val1=None, val2=None, delta1=None, delta2=None, rng=None, reset=False)[source]

Swap variables, i.e. exogenize variable var1 and endogenize variable var2.

Parameters:
param self:

Parameter.

type self:

`Model’.

param var1:

Endogenous variable.

type var1:

str or list of str or dict.

param var2:

Exogenous variable.

type var2:

str or list of str.

param val1:

New value of exogenized variable.

type val1:

float or pandas.Series.

param val2:

New value of endogenized variable.

type val2:

float.

param delta1:

New value of exogenized variable is the value of edogenized variable plus delta1.

type delta1:

float.

param delta2:

New value of endogenized variable is the value of exogenized variable plus delta2.

type delta2:

float.

param rng:

Simulation range or a date.

type rng:

list of datetime.

param reset:

Flag to reset model swap dictionary.

type reset:

bool.

snowdrop.src.model.settings module

Created on Thu Dec 5 11:35:18 2019

@author: A.Goumilevski

class snowdrop.src.model.settings.BoundaryCondition[source]

Bases: object

Condition = 2
class snowdrop.src.model.settings.BoundaryConditions(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Boundary Conditions.

FixedBoundaryCondition = 1
ZeroDerivativeBoundaryCondition = 2
class snowdrop.src.model.settings.FilterAlgorithm(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Kalman filter algorithms.

Diffuse = 1
Durbin_Koopman = 2
Non_Diffuse_Filter = 3
Particle = 4
Unscented = 5
class snowdrop.src.model.settings.InitialCondition(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Endogenous variables starting values algorithms.

History = 3
StartingValues = 1
SteadyState = 2
class snowdrop.src.model.settings.PriorAssumption(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Assumptions about starting value of error covariance matrix.

Asymptotic = 4
Diffuse = 1
Equilibrium = 3
StartingValues = 2
class snowdrop.src.model.settings.SamplingAlgorithm(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Assumptions about sampling methods.

Emcee = 1
Particle_gibbs = 43
Particle_pmmh = 41
Particle_smc = 42
Pymc3 = 3
Pymcmcstat = 2
Pymcmcstat_am = 22
Pymcmcstat_dr = 23
Pymcmcstat_dram = 24
Pymcmcstat_mh = 21
class snowdrop.src.model.settings.SmootherAlgorithm(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Kalman smoother algorithms.

BrysonFrazier = 1
Diffuse = 2
Durbin_Koopman = 3
class snowdrop.src.model.settings.SolverMethod(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Solver algorithms.

ABLR = 2
AndersonMoore = 6
BinderPesaran = 5
Klein = 4
LBJ = 1
Villemot = 3

snowdrop.src.model.util module

Utility module.

@author: A.Goumilevski

class snowdrop.src.model.util.Data(success: bool, x: float, fun: float, nfev: int = 0)[source]

Bases: object

fun: float
nfev: int = 0
success: bool
x: float
snowdrop.src.model.util.expand(sets, indices, expr, objFunc=False, loop=False)[source]

Expands expression.

Parameters:
param sets:

Dictionary of categories.

type sets:

dict.

param indices:

List of indeces.

type indices:

list.

param expr:

Object.

type expr:

list or dict.

returns:

objFunc: True if expanding expression for objective function.

type objFunc:

bool.

returns:

Expanded expression.

snowdrop.src.model.util.expand_list(sets, indices, arr, objFunc=False, loop=False)[source]

Iterates thru a list of indices and categories, substitutes an index of a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param sets:

Dictionary of categories.

type sets:

dict.

param indices:

List of indeces.

type indices:

list.

param arr:

List of indeces.

type arr:

list.

param:

objFunc: True if expanding expression for objective function.

type objFunc:

bool.

param loop:

True if expanding expression for objective function.

type loop:

bool.

returns:

list object.

snowdrop.src.model.util.expand_loop(categories, sub, expr)[source]

Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param categories:

Categories.

type categories:

list.

param sub:

Sub-string to replace.

type sub:

str.

param expr:

Text.

type expr:

str.

returns:

Text representation of sum operation.

snowdrop.src.model.util.expand_map(sets, indices, m)[source]

Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param sets:

Dictionary of categories.

type sets:

dict.

param indices:

List of indeces.

type indices:

list.

param m:

Map.

type m:

dict.

returns:

Dictionary object.

snowdrop.src.model.util.expand_minmax(b, sets, indices, txt)[source]

Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param b:

True if minimum and False if maximum.

type b:

bool.

param sets:

Dictionary of categories.

type sets:

dict.

param indices:

List of indeces.

type indices:

list.

param txt:

Text.

type txt:

str.

returns:

Text representation of min/max operation.

snowdrop.src.model.util.expand_obj_func_sum(categories, sub, expr)[source]

Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param categories:

Categories.

type categories:

list.

param sub:

Sub-string to replace.

type sub:

str.

param expr:

Text.

type expr:

str.

returns:

Text representation of sum operation.

snowdrop.src.model.util.expand_prod(sets, indices, txt)[source]
snowdrop.src.model.util.expand_sum(sets, indices, txt)[source]
snowdrop.src.model.util.expand_sum_or_prod(sets, indices, txt, symb)[source]

Iterates thru a list of indices and categories, substitutes an index in a variable name with a corresponding category, and builds a list of new variables.

Parameters:
param sets:

Dictionary of categories.

type sets:

dict.

param indices:

List of indeces.

type indices:

list.

param txt:

Text.

type txt:

str.

param symb:

Symbol “+” or “*”.

type txt:

str.

returns:

Text representation of summation or product operation.

snowdrop.src.model.util.firstNonZero(vals)[source]

Return first non-zero value.

Args:
valslist

List of values.

Returns:

First non nan occurence of an element in a list.

snowdrop.src.model.util.fix(eqs, model_eqs)[source]

Get equations, labels of equations and complementarity conditions.

Parameters:
param eqs:

Equations.

type eqs:

list.

param model_eqs:

Model equations to solve.

type model_eqs:

list.

returns:

List of equations and complementarity conditions.

snowdrop.src.model.util.getConstraints(n, constraints, cal, eqLabels, jacobian)[source]

Build linear constraints.

snowdrop.src.model.util.getEquationsLables(model)[source]

Build partite graph relating equations numbers to endogenous variables.

In other words, match equation numbers to endogenous variables.

Parameters:
param model:

The Model object.

type model:

Instance of class Model.

snowdrop.src.model.util.getIndex(e, ind)[source]

Find the first matching occurance of open bracket.

Parameters:
param e:

Expression.

type e:

str.

param ind:

Starting index.

type ind:

int.

returns:

Index of the matching open bracket.

snowdrop.src.model.util.getLabels(keys, m)[source]
snowdrop.src.model.util.getLimits(var_names, constraints, cal)[source]

Find variables upper and lower limits.

snowdrop.src.model.util.getStartingValues(hist, var_names, orig_var_values, options, skip_rows=0, debug=False)[source]

Get starting values for current and lagged endogenous variables.

Parameters:
param hist:

Path to historical data file.

type hist:

str.

param orig_var_values:

Values of endogenous variables.

type orig_var_values:

list.

param var_names:

Names of endogenous variables.

type var_names:

list

param options:

Model options.

type options:

dict.

param skip_rows:

NUmber of rows to skip.

type skip_rows:

int.

snowdrop.src.model.util.importModel(fpath)[source]

Parse a model file and create a model object.

Parameters:
param fpath:

Path to model file.

type fpath:

str.

snowdrop.src.model.util.lastNonZero(vals)[source]

Return last nonzero value.

Args:
valslist

List of values.

Returns:

Last non nan occurence of an element in a list.

snowdrop.src.model.util.loadLibrary(lib='libpath')[source]

Simple example of loading and using the system C library from Python.

snowdrop.src.model.util.print_path_solution_status(status)[source]
snowdrop.src.model.util.replace_all(old, new, expr)[source]
snowdrop.src.model.util.setValues(model, d, names, values, start=None, isShock=True)[source]

Set shocks values given the time of their appearance.

Args:
modelModel

model object.

ddict

Map of variables name and variable values.

startdatetime.

Start date of simulations. Default is None.

isShock: bool

True if shocks and False if parameters.

Returns:

New calibration dictionary.

Module contents