snowdrop.src package

Subpackages

Submodules

snowdrop.src.driver module

Created on Tue Mar 13, 2018 Driver program of Python framework.

@author: A.Goumilevski

snowdrop.src.driver.estimate(fname=None, model=None, y0=None, output_variables=None, fout=None, Plot=False, Output=False, output_dir=None, meas=None, Prior=None, estimate_Posterior=False, estimateOnly=False, algorithm='SLSQP', burn=50, Ndraws=300, Niter=100, sample=False, resetParameters=False, Parallel=False, method=None, fit_data_only=False, estimate_ML=False, runKalmanFilter=True)[source]

Estimates model parameters.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param y0:

Starting (or guessed) values of the solution.

type y0:

numpy array.

param fout:

Path to output excel file.

type fout:

str.

param Plot:

Boolean variable.If this flag is raised then plots graphs.

type Plot:

bool.

param decomp_variables:

List of decomposition variables.

param Output:

If set outputs simulation results to excel file and Python sqlite database.

type Output:

bool.

param output_dir:

Path to output directory.

type output_dir:

str.

param meas:

Path to a file with measurement data.

type meas:

str.

type Prior:

str.

param estimate_Posterior:

If this flag is raised, then calibrate model parameters and apply Kalman Filter with the new calibrated parameters.

type estimate_Posterior:

bool.

param estimateOnly:

If this flag is raised, then only estimate model parameters.

type estimateOnly:

bool.

param algorithm:

Algorithm applied to minimiza likelihood function.

type algorith:

str.

param burn:

Number of samples to discard.

type burn:

int.

param Ndraws:

The number of draws of Markov Chain Monte Carlo parameters sampling.

type Ndraws:

int.

param Niter:

The number of iterations. It is used in Markov Chain Monte Carlo sampling of parameters.

type Niter:

int.

param sample:

Boolean variable. If this flag is raised then run Markov Chain Monte Carlo parameters sampling.

type sample:

bool.

param resetParameters:

If True resets parameters to the samples mean values.

type resetParameters:

bool

param method:

Algorithm of Markov Chain Monte Carlo sampling.

type method:

str.

param fit_data_only:

If True calibrate model parameters by minimizing sum of standard deviations of errors of model fit to data. Otherwise, calibrate model by maximizing sum of the prior likelihood of model parameters and the likelihood of model fit to data.

type fit_data_only:

bool

param estimate_ML:

If True estimate maimum likelihood only.

type estimate_ML:

bool.

param runKalmanFilter:

If True runs Kalman filter after estimation, otherwise - runs forecast,

type runKalmanFilter:

bool.

returns:

Model estimation.

snowdrop.src.driver.findEigenValues(fname=None, model=None, steady_state=None)[source]

Find eigen values of system of equations at steady state.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param Output:

Boolean variable. If set saves steady state solution to excel file and sqlite database.

type Output:

bool.

returns:

Steady state solution.

snowdrop.src.driver.findSteadyStateSolution(fname=None, model=None, Output=False, excel_dir=None, debug=False)[source]

Find steady state solution.

This function uses variables starting values as initial condition for an iterative algorithm.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param Output:

Boolean variable. If set saves steady state solution to excel file and sqlite database.

type Output:

bool.

param excel_dir:

Pth to directory where excel steady state file will be saved.

type excel_dir:

str.

returns:

Steady state solution.

snowdrop.src.driver.findSteadyStateSolutions(fname=None, model=None, number_of_steps=10, par_range={}, Plot=False, Output=False)[source]

Find steady state solution for a range of parameters.

The parameters range is defined in the “options” sections of YAML model file.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param number_of_steps:

Number of steps of parameter range.

type number_of_steps:

int.

param par_range:

Parameters range.

type par_range:

dictionary.

param Plot:

Boolean variable. If set to True shows graphs.

type Plot:

bool.

param Output:

Boolean variable. If set to True saves graphs.

type Output:

bool.

returns:

List of steady state arrays for given parameter range.

snowdrop.src.driver.getImpulseResponseFunctions(fname, Plot=False, Output=False)[source]

Get impulse response functions (IRF).

Parameters:
param fname:

Path to model file.

type fname:

str.

type Plot:

bool.

param Output:

Boolean variable. If set then saves graphs.

type Output:

bool.

returns:

IRF for given parameters.

snowdrop.src.driver.importModel(fname, order=1, hist=None, boundary_conditions_path=None, exogenous=None, InitCondition=None, Prior=None, estimate=False, Solver=None, Filter=None, Smoother=None, shocks_file_path=None, steady_state_file_path=None, measurement_file_path=None, calibration_file_path=None, use_cache=False, SamplingMethod=None, anticipate=None, model_info=False, graph_info=False, bSparse=False)[source]

Import model.

Parameters:
param fname:

The path to yaml file name.

type fname:

str.

param order:

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

type order:

int.

param hist:

Path to the history excel 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:

List of exogenous variables.

type exogenous:

list.

param InitCondition:

Endogenous variables initial condition method.

type InitCondition:

str.

param Prior:

Error covariance matrix estimation method.

type Prior:

str.

param estimate:

If True estimate model parameters.

type estimate:

bool.

param Solver:

Solver algorithm.

type Solver:

str.

param Filter:

KF filter algorithm.

type Filter:

str.

param Smoother:

KF smoother algorithm.

type Smoother:

str.

param shocks_file_path:

Path to shock file.

type shocks_file_path:

str.

param steady_state_file_path:

Path to 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 or a file.

type calibration_file_path:

list or str.

param use_cache:

If True reads previously saved model from a file of model dump.

type use_cache:

bool.

param anticipate:

If True future shocks are anticipated.

type anticipate:

bool.

param model_info:

If True creates a pdf/latex model file.

type model_info:

bool.

param graph_info:

If True displays graph of model equations. The default is False.

type graph_info:

bool, optional

param bSparse:

Use sparse matrix algebra.

type bSparse:

bool.

returns:

Instance of Model class.

snowdrop.src.driver.kalman_filter(fname=None, model=None, y0=None, T=-1, output_variables=None, fout=None, Plot=False, decomp_variables=None, anticipate=None, Output=False, output_dir=None, hist=None, meas=None, InitCondition=None, Prior=None, calibration_file_path=None, Solver=None, Filter=None, Smoother=None)[source]

Runs Kalman filtering.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param y0:

Starting (or guessed) values of the solution.

type y0:

numpy array.

param T:

Number of time periods.

type T:

int.

param output_variables:

output variables.

type output_variables:

list.

param Plot:

Boolean variable.If this flag is raised then plots graphs.

type Plot:

bool.

param decomp_variables:

List of decomposition variables.

type decomp_variables:

list.

param anticipate:

It True then future shocks are anticipated.

type anticipate:

bool.

param Output:

If set outputs simulation results to excel file and Python sqlite database.

type Output:

bool.

param output_dir:

Path to output directory.

type output_dir:

str.

param hist:

Path to history excel file. It contains starting and terminal values of endogenous variables.

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 meas:

Path to a file with measurement data.

type meas:

str.

param InitCondition:

(StartingValues,SteadyState) If StartingValues then use starting values If SteadyState then use steady state as starting values

type InitialCondition:

str.

param Prior:

(StartingValues,DiffusePrior,Equilibrium) If Rosenberg then applies algorithm to find initial values of state variables. If StartingValues then use starting values for covariance matrices If SteadyState then use steady state for covariance matrices If Equilibrium then solve Lyapunov equation to find steady state covariance matrices.

type Prior:

str.

param estimate_Posterior:

If this flag is raised, then calibrate model parameters and apply Kalman Filter with the new calibrated parameters.

type estimate_Posterior:

bool.

param fout:

Path to output excel file.

type fout:

str.

param calibration_file_path:

Path to a calibration file or files.

type calibration_file_path:

str or list.

param Solver:

Name of numerical method to solve the system of equations.

type Solver:

str.

param Filter:

Name of Kalman filter algorithm.

type Filter:

str.

param Smoother:

Name of Kalman filter smoother algorithm.

type Smoother:

str.

param calibration_file_path:

If True the transition equations, variables, shocks are combined with the measurement ones.

type calibration_file_path:

bool.

returns:

Kalman filter results.

snowdrop.src.driver.optimize(fpath=None, fout=None, Output=False, plot_variables=None, model_info=False)[source]

Call main driver program.

Runs model optimization.

Parameters:
param fpath:

Path to model file.

type fpath:

str.

param fout:

Path to output excel file.

type fout:

str.

param Output:

If set outputs simulation results to excel file and Python sqlite database.

type Output:

bool.

param output_dir:

Path to output directory.

type output_dir:

str.

param plot_variables:

Names of variables to plot.

type plot_variables:

list.

param model_info:

If True creates a pdf/latex model file.

type model_info:

bool.

returns:

Optimization results.

snowdrop.src.driver.run(fname=None, model=None, y0=None, order=1, T=-1, Tmax=1000000.0, irf=False, prefix=None, output_variables=None, Plot=False, decomp_variables=None, anticipate=None, PlotSurface=False, Plot3D=False, Output=False, output_dir=None, hist=None, boundary_conditions_path=None, exogenous=None, meas=None, InitCondition=None, Prior=None, estimate_Posterior=False, estimateOnly=False, algorithm='SLSQP', burn=50, Ndraws=300, Niter=100, sample=False, resetParameters=False, Parallel=False, method=None, fout=None, MULT=1, shocks_file_path=None, steady_state_file_path=None, calibration_file_path=None, Solver=None, Filter=None, Smoother=None, fit_data_only=False, estimate_ML=False, header=None, opt_ss_continue=True, graph_info=False, use_cache=False, model_info=False, Sparse=False, runKalmanFilter=False, orth_shocks=None)[source]

Main driver program.

It runs simulations, finds steady state solution, plots graphs, and saves results to excel files and Python sqlite databases.

Parameters:
param fname:

Path to model file.

type fname:

str.

param model:

Model object.

type model:

Model.

param y0:

Starting (or guessed) values of the solution.

type y0:

numpy array.

param order:

Approximation order of non-linear system of equations.

type order:

int.

param T:

Number of time periods.

type T:

int.

param Tmax:

Maximum number of periods to display in graphs.

type Tmax:

int.

param irf:

IRF variable.

type irf:

int.

param prefix:

Prefix name. It is used to plot and output variables which name starts with prefix.

type prefix:

str.

param output_variables:

output variables.

type output_variables:

list.

param Plot:

Boolean variable.If this flag is raised then plots graphs.

type Plot:

bool.

param decomp_variables:

List of decomposition variables.

type decomp_variables:

list.

param anticipate:

It True then future shocks are anticipated.

type anticipate:

bool.

param PlotSurface:

Boolean variable. If this flag is raised then plots 2D graphs.

type PlotSurface:

bool.

param Plot3D:

Boolean variable. If this flag is raised then plots 3D graphs.

type Plot3D:

bool.

param Output:

If set outputs simulation results to excel file and Python sqlite database.

type Output:

bool.

param output_dir:

Path to output directory.

type output_dir:

str.

param hist:

Path to history excel file. It contains starting and terminal values of endogenous variables.

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:

List of exogenous variables.

type exogenous:

list.

param meas:

Path to a file with measurement data.

type meas:

str.

param InitCondition:

(StartingValues,SteadyState) If StartingValues is set, then use starting values If SteadyState is set, then use steady state as starting values

param Prior:

(StartingValues,DiffusePrior,Equilibrium) If Rosenberg then applies algorithm to find initial values of state variables. If StartingValues then use starting values for covariance matrices If SteadyState then use steady state for covariance matrices If Equilibrium then solve Lyapunov equation to find steady state covariance matrices.

type Prior:

str.

param estimate_Posterior:

If this flag is raised, then calibrate model parameters and apply Kalman Filter with the new calibrated parameters.

type estimate_Posterior:

bool.

param estimateOnly:

If this flag is raised, then only estimate model parameters.

type estimateOnly:

bool.

param algorithm:

Algorithm applied to minimiza likelihood function.

type algorith:

str.

param burn:

Number of samples to discard.

type burn:

int.

param Ndraws:

The number of draws of Markov Chain Monte Carlo parameters sampling.

type Ndraws:

int.

param Niter:

The number of iterations. It is used in Markov Chain Monte Carlo sampling of parameters.

type Niter:

int.

param sample:

Boolean variable. If this flag is raised then run Markov Chain Monte Carlo parameters sampling.

type sample:

bool.

param resetParameters:

If True resets parameters to the samples mean values.

type resetParameters:

bool

param method:

Algorithm of Markov Chain Monte Carlo sampling.

type method:

str.

param fout:

Path to output excel file.

type fout:

str.

param MULT:

Multiplier defining terminal time. If set greater than one than solution will be computed for this extended time range interval.

type MULT:

float.

param shocks_file_path:

Path to shock file.

type shocks_file_path:

str.

param steady_state_file_path:

Path to steady-state file.

type steady_state_file_path:

str.

param calibration_file_path:

Path to a calibration file or files.

type calibration_file_path:

str or list.

param Solver:

Name of numerical method to solve the system of equations.

type Solver:

str.

param Filter:

Name of Kalman filter algorithm.

type Filter:

str.

param Smoother:

Name of Kalman filter smoother algorithm.

type Smoother:

str.

param fit_data_only:

If True calibrate model parameters by minimizing sum of standard deviations of errors of model fit to data. Otherwise, calibrate model by maximizing sum of the prior likelihood of model parameters and the likelihood of model fit to data.

type fit_data_only:

bool

param estimate_ML:

If True estimate maimum likelihood only.

type estimate_ML:

bool.

param header:

Graph header.

type header:

str.

param opt_ss_continue:

If set and steady state solution is invalid, then find steady state and continue simulations.

type opt_ss_continue:

bool.

param graph_info:

If True shows model equations graph.

type graph_info:

bool.

param calibration_file_path:

If True the transition equations, variables, shocks are combined with the measurement ones.

type calibration_file_path:

bool.

param use_cache:

If True reads previously saved model from a file of model dump.

type use_cache:

bool.

param model_info:

If True creates a pdf/latex model file.

type model_info:

bool.

param Sparse:

If True use sparse matrices algebra.

type Sparse:

bool.

param runKalmanFilter:

If True runs Kalman Filter.

type runKalmanFilter:

bool.

param orth_shocks:

If True shocks are orthogonalized (applied only for linear models).

type orth_shocks:

bool.

returns:

Simulation results.

snowdrop.src.driver.setParameters(model, order, Solver, Filter, Smoother, Prior, InitCondition, SamplingMethod=None)[source]

Set model parameters.

Parameters:
param model:

Model object.

type fname:

Model.

param order:

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

type order:

int.

param Solver:

Solver algorithm.

type Solver:

str.

param Filter:

KF filter algorithm.

type Filter:

str.

param Smoother:

KF smoother algorithm.

type Smoother:

str.

param Prior:

Error covariance matrix estimation method.

type Prior:

str.

param InitCondition:

Endogenous variables initial condition method.

type InitCondition:

str.

param SamplingMethod:

Markov Chain Monte Carlo sampling algorithm.

type SamplingMethod:

str.

returns:

Instance of Model class.

snowdrop.src.info module

snowdrop.src.version module

Module contents