snowdrop.src.numeric.solver package

Subpackages

Submodules

snowdrop.src.numeric.solver.ABLR module

Created on Fri Nov 1, 2019

@author: agoumilevski

snowdrop.src.numeric.solver.ABLR.ABLRsolver(model, T, n, y, params=None, shocks=None)[source]

Solve nonlinear model by direct method.

Solver uses Newton’s method to update the numerical solution. It employs ABLR stacked matrices method to solve equations. If number of equations greater is large, it uses sparse matrices spsolver algorithm.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

array of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

array of parameters.

type params:

numpy.ndarray.

param shocks:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.ABLR.dense_Fstack(model, T, y, n, params=None, shocks=None)[source]

Compute values of functions and partial derivatives of model equations.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param y:

array of endogenous variables.

type y:

numpy.ndarray.

param n:

Number of endogenous variables.

type n:

int.

param params:

array of parameters.

type params:

numpy.ndarray.

param n_shocks:

Number of shock variables.

type n_shocks:

int.

returns:

Stacked matrices of functions and jacobian values.

snowdrop.src.numeric.solver.ABLR.parallel_sparse_Fstack(model, T, y, n, params=None, shocks=None, use_thread_pool=True)[source]

Compute values of functions and partial derivatives of model equations.

Asynchronous run.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param y:

array of endogenous variables.

type y:

numpy.ndarray.

param n:

Number of endogenous variables.

type n:

int.

param params:

array of parameters.

type params:

numpy.ndarray.

param n_shocks:

Number of shock variables.

type n_shocks:

int.

returns:

Stacked matrices of functions and jacobian.

snowdrop.src.numeric.solver.ABLR.sparse_Fstack(model, T, y, n, params=None, shocks=None)[source]

Compute values of functions and partial derivatives of model equations.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param y:

array of endogenous variables.

type y:

numpy.ndarray.

param n:

Number of endogenous variables.

type n:

int.

param params:

array of parameters.

type params:

numpy.ndarray.

param n_shocks:

Number of shock variables.

type n_shocks:

int.

returns:

Stacked matrices of functions and jacobian.

snowdrop.src.numeric.solver.AndersonMoore module

Created on Fri Nov 1, 2019

@author: agoumilevski

snowdrop.src.numeric.solver.AndersonMoore.solve_am(model, steady_state, p=None, suppress_warnings=False)[source]

Find first-order accuracy approximation solution.

It implements an algoritm of Anderson and Moore.

Please see “Anderson-Moore Algorithm (AMA)”, https://www.federalreserve.gov/econres/ama-index.htm

Parameters:
param model:

The Model object.

type model:

instance of class Model.

param steady_state:

Steady state.

type steady_state:

list.

param p:

List of parameters.

type p:

list.

param suppress_warnings:

Do not show warnings if True

type suppress_warnings:

bool.

snowdrop.src.numeric.solver.Benes module

snowdrop.src.numeric.solver.BinderPesaran module

Created on Fri Nov 1, 2019

@author: agoumilevski

snowdrop.src.numeric.solver.BinderPesaran.getMatrices(model, n, y, t=None)[source]

Return state-space model representation matrices.

snowdrop.src.numeric.solver.BinderPesaran.printResults(A, C, R, Z, W)[source]

Display results.

snowdrop.src.numeric.solver.BinderPesaran.solve_quadratic_determinantal_equation(model, steady_state, p=None, suppress_warnings=False)[source]

Find first-order accuracy approximation.

It applies substitution algorithm similar to Binder and Pesaran (1995).

For general system of the form

\[F * x_{t+1} + C * x_{t} + L * x_{t-1} + C = G * w_{t+1}, w = Normal(0, Q) \]

We seek solution of the form

\[x_{t+1} = A * x_{t} + B + E * w_{t+1}\]

For details please see https://callumjones.github.io/files/dynare_str.pdf

Parameters:
param model:

The Model object.

type model:

instance of class Model.

param steady_state:

Steady state.

type steady_state:

list.

param p:

Parameters values.

type p:

list.

param suppress_warnings:

Do not show warnings if True

type suppress_warnings:

bool.

snowdrop.src.numeric.solver.BinderPesaran.solve_quadratic_equation(F, C, L, c, psi, N=1000, TOLERANCE=1e-12, suppress_warnings=False)[source]

Find first-order accuracy approximation solution. It applies substitution algorithm similar to Binder and Pesaran (1995). For general system of equations with leads and lags

\[F*x_{t+1} + C*x_{t} + L*x_{t-1} + c + psi*w_{t+1} = 0, w = Normal(0, Q)\]

Rewriting equations

\[x_{t} = -C^{-1}*[L*x_{t-1} + F*x_{t+1} + c + psi*w_{t+1}]\]

Representing

\[x_{t} = A*x_{t} + z_{t}\]

and substituting, we can decouple x and z by finding matrix A satisfying quadratic equation

\[C^{-1} * L + A + C^{-1} * F * A^{2} = 0\]

Forward eqution for z is

\[z_{t} = [I+C^{-1}*F*A]*C^{-1} * [F*z_{t+1} + c + psi*w_{t+1}]^{-1}\]

By induction we get

\[z_{t} = [I+C^{-1}*F*A] * C^{-1} * \sum_{k} [F^{k}*(c+psi*w_{t+k})]^{-1}\]
Parameters:
param F:

The Jacobian matrix of lead variables.

type F:

numpy.ndarray.

param C:

The Jacobian matrix of current variables.

type C:

numpy.ndarray.

param L:

The Jacobian matrix of lag variables.

type L:

numpy.ndarray.

param jacob:

Jacobian matrix.

type jacob:

numpy.ndarray.

param c:

Array of constants.

type c:

numpy.ndarray.

param Psi:

Matrix of coefficients of shocks.

type Psi:

numpy.ndarray.

Note

Please see paper ‘Multivariate Linear Rational Expectations Models:Characterization of the Nature of the Solutions and their Fully Recursive Computation’ describing the theory underlying this approach.

Matlab program is available at: http://www.inform.umd.edu/econ/mbinder

snowdrop.src.numeric.solver.BinderPesaran.solve_recursive(F, C, L, c, psi, N=300, TOLERANCE=1e-08, suppress_warnings=False)[source]

Find first-order accuracy approximation solution.

It applies recursive algorithm of Binder and Pesaran (1995). Please see paper ‘Multivariate Linear Rational Expectations Models: Characterization of the Nature of the Solutions and their Fully Recursive Computation’

For general system of equations with leads and lags

\[F * x_{t+1} + C * x_{t} + L * x_{t-1} + c + psi * w_{t+1} = 0, w = Normal(0, Q)\]

We seek solution of the form

\[x_{t+1} = A * x_{t} + B + R * w_{t+1}\]

Matlab program can be downloaded from: http://www.inform.umd.edu/econ/mbinder

Parameters:
param F:

The Jacobian matrix of lead variables.

type F:

numpy.ndarray.

param C:

The Jacobian matrix of current variables.

type C:

numpy.ndarray.

param L:

The Jacobian matrix of lag variables.

type L:

numpy.ndarray.

param jacob:

Jacobian matrix.

type jacob:

numpy.ndarray.

param c:

Array of constants.

type c:

numpy.ndarray.

param Psi:

Matrix of coefficients of shocks.

type Psi:

numpy.ndarray.

param N:

Initial Forecasting Horizon (See Binder and Pesaran, 1995)

type N:

int.

snowdrop.src.numeric.solver.LBJ module

Created on Fri Nov 1, 2019

@author: A.Goumilevski

ALGORITHM

Laffargue, Boucekkine, Juillard (LBJ)

see Juillard (1996) Dynare: A program for the resolution and simulation of dynamic models with forward variables through the use of a relaxation algorithm. CEPREMAP. Couverture Orange. 9602.

snowdrop.src.numeric.solver.LBJ.LBJsolver(model, T, n, y, params, shocks)[source]

Solve nonlinear model by LBJ method.

Solver uses Newton’s method and LBJ solver to update the solution. It applies backward substitution method. It differs from LBJsolver method by direction of endogenous variables substitution.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

array of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

Values of parameters.

type params:

numpy.ndarray.

param shocks:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.LBJ.dense_system_solver(model: Model, T: int, n: int, y: array, params: list = None, shocks: list = None) array[source]

Solve nonlinear model by LBJ method for dense matrices.

Solver employs Newton’s method and LBJ solver to update the solution. It uses backward substitution method.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

Array of values of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

Array of parameters.

type params:

numpy.ndarray.

param shock:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.LBJ.solver_with_tunes(model: Model, start: int, T: int, n: int, y: array, params: list = None, shocks: list = None) array[source]

Nonlinear solver with tunes.

Solver employs Newton’s method and LBJ solver to update the solution. It uses backward substitution method.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

Array of values of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

Array of parameters.

type params:

numpy.ndarray.

param shock:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.LBJ.sparse_system_solver(model: Model, T: int, n: int, y: array, params: list = None, shocks: list = []) array[source]

Solve nonlinear model by LBJ method for sparse matrices.

Solver employs Newton’s method and LBJ solver to update the solution. It uses backward substitution method.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

Array of values of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

Array of parameters.

type params:

numpy.ndarray.

param shock:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.Villemot module

Created on Fri Nov 1, 2019

@author: agoumilevski

snowdrop.src.numeric.solver.Villemot.solution(model, Jacob, Psi, K=None, qz_factor=1.000001, debug=False, suppress_warnings=False)[source]

Find first-order accuracy approximation solution.

It implements an algoritm described by Sebastien Villemot in the paper: “Solving rational expectations model at first order: what Dynare does.” For references please see https://www.dynare.org/wp-repo/dynarewp002.pdf

Parameters:
param model:

The Model object.

type model:

instance of class Model.

param jacob:

Jacobian matrix.

type jacob:

numpy.ndarray.

param Psi:

Matrix of coefficients of shocks.

type Psi:

numpy.ndarray.

param C:

Array of constants.

type C:

numpy.ndarray.

snowdrop.src.numeric.solver.Villemot.solve_villemot(model, steady_state, p=None, suppress_warnings=False)[source]

Finds first-order accuracy approximation solution.

It implements an algoritm described by Sebastien Villemot in his paper: “Solving rational expectations model at first order: what Dynare does.” For references please see https://www.dynare.org/wp-repo/dynarewp002.pdf

Parameters:
param model:

The Model object.

type model:

Instance of a class Model.

param steady_state:

Steady state.

type steady_state:

list.

param p:

Model parameters.

type p:

list.

param suppress_warnings:

Do not show warnings if True

type suppress_warnings:

bool.

snowdrop.src.numeric.solver.linear_solver module

The linear solver. It uses direct and iterative solvers that are applicable to equations with maximum of one lead and one lag variables.

Note

This solver was designed to solve system of linear equations with shocks. To include exogenous processes in addition, please use Villemot solver.

snowdrop.src.numeric.solver.linear_solver.find_steady_state(model, method='iterative', debug=False)[source]

Find steady state solution.

Parameters:
param model:

Model object.

type model:

`Model’.

param method:

Find steady state solution by iterations, by minimizing square of equations error, etc…

type model:

str.

returns:

Array of endogenous variables steady states and their growth.

snowdrop.src.numeric.solver.linear_solver.simulate(model, T, periods, y0, steady_state, parameters=None, Npaths=1)[source]

Find first-order accuracy approximation solution.

For details on an algorithm to select anticipated and un-anticipated shocks to bring the level of endogenous variables to the desired path please see: https://michalandrle.weebly.com/uploads/1/3/9/2/13921270/iris_simulate.pdf

Parameters:
param model:

Model object.

type model:

`Model’.

param T:

Time span.

type T:

int.

param periods:

Simulation periods.

type periods:

numpy.ndarray.

param y0:

Starting values of endogenous variables.

type y0:

numpy.ndarray

param steady_state:

Steady state values of endogenous variables.

type steady_state:

numpy.ndarray

param parameters:

Values of parameters.

type parameters:

list.

param Npaths:

Number of simulation paths. This is the number of paths of stochastic shocks.

type Npaths:

int.

returns:

Numerical solution.

snowdrop.src.numeric.solver.linear_solver.solve(model, p=None, steady_state=None, suppress_warnings=False)[source]

Select solver.

This is a convenience method to choose model equations solver.

snowdrop.src.numeric.solver.nonlinear_solver module

The non-linear solver. It is either the ABLR solver that uses stacked matrices algotithm or the LBJ solver that solves equations with maximum of one lead and one lag variables.

snowdrop.src.numeric.solver.nonlinear_solver.TOLERANCE = 1e-08

Maximum number of iterations

snowdrop.src.numeric.solver.nonlinear_solver.find_steady_state(model)[source]

Find the steady state.

Parameters:
param model:

Model object.

type model:

`Model’.

returns:

Array of endogenous variables steady states and their growth.

snowdrop.src.numeric.solver.nonlinear_solver.first_order_solution(model, T, periods, y0, steady_state=None, params=None, Npaths=1, MULT=1)[source]

Find solution by iterations. This is agent’s perfect foresight forecast.

This algorithm iterates until either the change in subsequent iterations of this solution is less than TOLEARANCE level or the number of iterations exceeds NITERATIONS.

Parameters:
param model:

Model object.

type model:

`Model’.

param T:

Time span.

type T:

int.

param periods:

Array of endogenous variables.

type periods:

numpy.ndarray.

param y0:

Starting values or guessed values of endogenous variables.

type y0:

numpy.ndarray

param steady_state:

Steady state solution.

type steady_state:

numpy.ndarray

param params:

Values of parameters.

type params:

numpy.ndarray.

param Npaths:

Number of simulation paths. This is the number of paths of stochastic shocks.

type Npaths:

int.

param MULT:

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

type MULT:

int.

returns:

First order approximation numerical solution.

snowdrop.src.numeric.solver.nonlinear_solver.get_steady_state(model, x0, ss_variables=None, p=None, e=None)[source]

Find the steady state solution. Uses Euler iterative algorithm.

Parameters:
param model:

Model object.

type model:

`Model’.

param model:

Initial guess.

type x0:

numpy.ndarray.

param nss:

Number of model equations.

type nss:

int.

param p:

Parameters.

type p:

numpy.ndarray.

param e:

Shocks.

type e:

numpy.ndarray.

returns:

Array of endogenous variables steady states and this solution relative error.

snowdrop.src.numeric.solver.nonlinear_solver.homotopy_solver(model, y0, par_name, par_steps, periods, T=101, tol=0.0001, debug=False, MULT=1.0)[source]

Solve model by adjusting parameters step-by-step.

Solves this model iteratively since it could blow up for final parameters.

Parameters:
param model:

Model object.

type model:

`Model’.

param y0:

Starting values of endogenous variables.

type y0:

numpy ndarray.

param par_name:

Parameter name.

type par_name:

str.

param start:

Starting value of parameter.

type start:

float.

param stop:

Final value of parameter.

type stop:

float.

param par_steps:

Steps values.

type par_steps:

numpy ndarray.

param tol:

Tolerance of solution convergence.

type tol:

float, optional. The default is 1.e-4.

param periods:

Periods.

type periods:

list.

param T:

Time span of simulations.

type T:

int, optional. The default is 101.

param debug:

Debug flag.

type debug:

bool, optional. The default is False.

param MULT:

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

type MULT:

float, optional. The default is 1.

returns:

The solution.

snowdrop.src.numeric.solver.nonlinear_solver.predict(model: Model, T: int, y: array, params: list = None, shocks: list = None, debug=False) array[source]

Solve backward looking nonlinear model equations.

Note

This code was developed to solve IMFE aplication. It doesn’t have lead variables nor shocks.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Time span.

type T:

int.

param n:

Number of endogenous variables.

type n:

int.

param y:

Array of values of endogenous variables for current iteration.

type y:

numpy.ndarray.

param params:

Array of parameters.

type params:

numpy.ndarray.

param shock:

Array of shock values.

type shocks:

numpy.ndarray.

returns:

Numerical solution.

snowdrop.src.numeric.solver.nonlinear_solver.second_order_approximation(model, jacobian, hessian, ghy, ghu, Sigma=None)[source]

Compute the second order reduced form solution of the DSGE model.

It implements an algoritm described by Michel Juillard in: “Computing first and second order approximation of DSGE models with DYNARE”, CEPREMAP

Note

It is assumed that model is linear to shock variables…

Parameters:
param model:

The Model object.

type model:

instance of class `Model’.

param jacobia:

Matrix containing the Jacobian of the model.

type jacobian:

numpy.ndarray.

param hessian:

Hessian matrix (second order derivative with respect to endogenous and shock variables).

type hessian:

numpy.ndarray.

param ghy:

Transition matrix.

type ghy:

numpy.ndarray.

param ghu:

Matrix of shocks.

type ghu:

numpy.ndarray.

param Sigma:

Matrix of error covariances.

type Sigma:

numpy.ndarray.

snowdrop.src.numeric.solver.nonlinear_solver.second_order_solution(model, T, periods, y0, steady_state=None, params=None, order=2, Npaths=1, MULT=1)[source]

Find the second order approximation solution.

This algorithm uses the Jacobian (first order derivatives) and the Hessian (second oredr derivatives).

Parameters:
param model:

Model object.

type model:

`Model’.

param T:

Time span.

type T:

int.

param y0:

Starting values or guessed values of endogenous variables.

type y0:

numpy.ndarray

param steady_state:

Steady state solution.

type steady_state:

numpy.ndarray.

param periods:

Array of endogenous variables.

type periods:

numpy.ndarray.

param params:

Values of parameters.

type params:

numpy.ndarray.

param order:

Order of partial derivatives of Jacobian.

type order:

int.

param Npaths:

Number of simulation paths. This is the number of paths of stochastic shocks.

type Npaths:

int.

param MULT:

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

type MULT:

int.

returns:

Second order approximation to numerical solution.

snowdrop.src.numeric.solver.nonlinear_solver.simulate(model, T, periods, y0, steady_state=None, params=None, order=1, Npaths=1, MULT=1)[source]

Find solution by iterations by applying Newton method.

It iterates until either the change in subsequent iterations of this solution is less than TOLEARANCE level or the number of iterations exceeds NITERATIONS.

Parameters:
param model:

Model object.

type model:

`Model’.

param T:

Time span.

type T:

int.

param y0:

Starting values or guessed values of endogenous variables.

type y0:

numpy.array

param steady_state:

Steady state solution.

type steady_state:

numpy.ndarray

param periods:

Array of endogenous variables.

type periods:

numpy.ndarray.

param params:

Values of parameters.

type params:

numpy.ndarray.

param order:

Order of partial derivatives of Jacobian.

type order:

int.

param Npaths:

Number of simulation paths. This is the number of paths of stochastic shocks.

type Npaths:

int.

param MULT:

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

type MULT:

int.

returns:

Numerical solution.

snowdrop.src.numeric.solver.solver module

snowdrop.src.numeric.solver.solver.SerialDifferentiableFunction(f, epsilon=1e-08)[source]

Finite difference of function.

snowdrop.src.numeric.solver.solver.my_solve(m, sol)[source]

Solve system of algebraic equations by elimination method.

snowdrop.src.numeric.solver.solver.newton(f, x, verbose=False, tol=1e-06, maxit=5, jactype='serial')[source]

Solve nonlinear system using safeguarded Newton iterations

snowdrop.src.numeric.solver.solver.serial_solve(A, B, diagnose=True)[source]

Solve matrix equation.

snowdrop.src.numeric.solver.solver.test_serial_solve()[source]

Test serial solve metod.

snowdrop.src.numeric.solver.solvers module

snowdrop.src.numeric.solver.solvers.SerialDifferentiableFunction(f, epsilon=1e-08)[source]
snowdrop.src.numeric.solver.solvers.Sylvester_iterative_solver(x0, A, B, C, D)[source]

Iterative solution of Sylvester equation.

\[A*x + B*x*C = D\]
snowdrop.src.numeric.solver.solvers.Sylvester_solver(A, B, C, D)[source]

” Solves Silvester equation.

\[A*x + B*x*C = D\]

where D is n*m*p matrix

snowdrop.src.numeric.solver.solvers.disclyap_fast(G, V, tol=1e-16, check_flag=None)[source]
Args:

G: [double] first input matrix V: [double] second input matrix tol: [scalar] tolerance criterion check_flag: if non-empty - check positive-definiteness

Returns:

X: [double] solution matrix exitflag: [scalar] 0 if solution is found, 1 otherwise

Solve the discrete Lyapunov equation by using the Doubling Algorithm

\[X = G * X * G' + V\]

If check_flag is defined then the code will check if the resulting X is positive definite and generate an error message if it is not

Joe Pearlman and Alejandro Justiniano 3/5/2005

snowdrop.src.numeric.solver.solvers.lyapunov_solver(T, R, Q, N, n_shocks, method=1, options=None)[source]

Solve the Lyapunov equation: P = T*P*T’ + R*Q*R’.

This equation arising in a state-space system, where P is the variance of the states.

Args:
T: double

n*n matrix

R: double

n*n matrix

Q: double

nsh*nsh matrix

method: int

method number

N: int

shocks maximum lead number minus minimum lag number

n_shocks: int

number of shocks

options: dictionary

options

Returns:
P: double

nsh*nsh matrix.

Algorithms:
options:

steady: The transition matrix is decomposed into stable and unstable parts. For the stable part we solve the Lyapinov equation with the help of the scipy package Lyapunov solver.

fp: True iteration-based fixed point algorithm is used.

db: Then doubling algorithm is used.

If none of these algorithms is selected then the reordered Schur decomposition, a.k.a. Bartels-Stewart algorithm is used.

snowdrop.src.numeric.solver.solvers.lyapunov_symm(a, b, method=0, X=None, lyapunov_fixed_point_tol=1e-10, qz_criterium=1.000001, lyapunov_complex_threshold=1e-15, debug=False)[source]

Solves the Lyapunov equation x-a*x*a’ = b, for b and x symmetric matrices. If a has some unit roots, the function computes only the solution of the stable subsystem.

Args:

a: [double] n*n matrix.

b: [double] n*n matrix.

qz_criterium: [double] unit root threshold for eigenvalues

lyapunov_fixed_point_tol: [double] convergence criteria for fixed_point algorithm.

lyapunov_complex_threshold: [double] scalar, complex block threshold for the upper triangular matrix T.

method: [integer] Scalar, if method=0 [default] then U, T, n and k are not persistent; method=1 then U, T, n and k are declared as persistent; method=3 fixed point method

Returns:

x: [double] m*m solution matrix of the lyapunov equation, where m is the dimension of the stable subsystem. u: [double] Schur vectors associated with unit roots

Algorithm:

Uses reordered Schur decomposition (Bartels-Stewart algorithm) [method<3] or a fixed point algorithm (method==3)

snowdrop.src.numeric.solver.solvers.newton(f, x, verbose=False, tol=1e-06, maxit=5, jactype='serial')[source]

Solve nonlinear system using safeguarded Newton iterations Args: Returns:

snowdrop.src.numeric.solver.solvers.serial_solve(A, B, diagnose=True)[source]

Generalized universal functions solve.

snowdrop.src.numeric.solver.solvers.solve(m, sol)[source]

Seems to segfault on windows.

Args:
mTYPE

DESCRIPTION.

solTYPE

DESCRIPTION.

Returns:

None.

snowdrop.src.numeric.solver.solvers.sylvester_solver(A, C, D, B=None)[source]

Solves Silvester equation:

\[A*x + B*x*C = D\]
snowdrop.src.numeric.solver.solvers.test1()[source]

Test Lypunov equations solvers.

snowdrop.src.numeric.solver.solvers.test2()[source]

Test Lypunov equation solver.

snowdrop.src.numeric.solver.solvers.test_serial_solve()[source]

snowdrop.src.numeric.solver.tunes module

Implements judgemental adjustments to endogenous variables paths.

Created on Fri Oct 23, 2020 Part of the code translated from Matlab Iris to Python.

@author: A.Goumlevski

snowdrop.src.numeric.solver.tunes.anticipated(mapSwap, y, shocks, T, Re, C, Nperiods, rng, total_nmbr_shocks, n_shocks)[source]

Forecast of linear model with a fixed path of some of the endogenous variables.

This is a solution when all shocks are anticipated.

Parameters:
mapSwapdict.

Map of indices and values of exogenized variables and endogenized shocks.

ynumpy.ndarray.

The solution with no tunes.

shockslist.

Shocks at different time periods.

Tnumpy.ndarray.

Transition matrix.

Renumpy.ndarray.

Forward matrix of coefficiets of shocks.

Cnumpy.ndarray.

Matrix of constants.

Nperiodsint.

Number of time periods.

rnglist.

Time range of the tunes.

Returns:
ynumpy.ndarray.

Numerical solution with judgemental adjustments.

shocksnumpy.ndarray.

Shocks that bring path of endogenous variables to the desired level.

snowdrop.src.numeric.solver.tunes.calcPrhs(stdUnAntShk, stdAntShk, indEndog, indExog, nx, ne, nt, last) array[source]

Compute MSE/Cov matrix of the RHS in the swapped system.

Parameters:
stdUnAntShknumpy .ndarray.

Covariance matrix of un-anticipated shocks.

stdAntShknumpy .ndarray.

Covariance matrix of anticipated shocks.

indEndoglist.

Indices of endogenized variables.

indExoglist.

Indices of exogenized variables.

nxint.

Number of endogenous variables.

neint.

Number of shocks.

ntint.

Size of covariance matrix.

lastint.

Last period of adjustments.

Returns:
PrhsNumpy array.

Covariance matrix of shocks.

snowdrop.src.numeric.solver.tunes.computeMatrices(model, T, Re, C, indExog, indEndog, nx, ne, last)[source]

Compute system solution matrices with swapped exogenized variables and endogenized shocks.

Parameters:
modelModel

Model object.

Tnumpy.ndarray.

Transition matrix of endogenous variables.

Renumpy.ndarray.

Forward matrix of coefficients of shocks for the entire range of adjustments.

Cnumpy.ndarray.

Array of constants.

indExoglist.

Indices of exogenized variables.

indEndoglist.

Indices of endogenized variables.

nxint

Number of endogenous variables.

neint

Number of shocks.

lastint

Last period of adjustments.

Returns:
MNumpy array.

Swapped matrix of shocks.

snowdrop.src.numeric.solver.tunes.forecast_with_tunes(model, Nperiods=0, y=None, T=None, Re=None, C=None, shocks=None, has_imaginary_shocks=False, has_imaginary_values=False, scale=1 + 0j)[source]

Forecast with judgmental adjustments (conditional forecasts). This is a solution for a ‘fixed path’ of endogenous variables.

For references please see Michal Andrle’s algorithm described in an unpubished paper: https://michalandrle.weebly.com/uploads/1/3/9/2/13921270/iris_simulate.pdf

Parameters:
modelModel.

Model object.

Nperiodsnumpy.ndarray.

Number of time periods.

ynumpy.ndarray.

The solution with no tunes.

Tnumpy.ndarray.

Transition matrix.

Renumpy.ndarray.

Matrix of coefficiets of forward shocks.

Cnumpy.ndarray.

Matrix of constants.

shockslist.

Shocks at different time periods.

has_imaginary_shocksbool.

Flag set to True if ay of the shocks is a complex number, and to False other otherwise.

has_imaginary_valuesbool.

Flag set to True if any of the endogenous variables path is a complex number, and to False other otherwise.

scalenumpy.complex.

Scaling factor for standard deviations of expected and un-expected shocks. If model.anticipate flag is set to True , then real part of scale is a multiplier for standard devitions of expected shocks and the imaginary part is a multiplier for standard devitions of un-expected shocks. If model.anticipate flag is set to False, then it is wise versa.

Returns:
modelModel.

Model object.

ynumpy array.

Numerical solution with tunes.

snowdrop.src.numeric.solver.tunes.getData(m1, n, m2=None)[source]

Get list of indices or 2d array or values.

Parameters:
m1dict

Map with key as time period and index as value.

nint, optional

The number of variables.

m2dict, optional

Map with time periods and values of variables. The default is None.

Returns:
arrlist or numpy array

Indices of exogenized variables and endogenized shocks.

snowdrop.src.numeric.solver.tunes.getIndices(mapSwap, condShocks, anticipate, nx, ne, last, debug=False)[source]

Return indices of exogenized variables and endogenized shocks and judgemental adjustments.

Parameters:
mapSwapdict.

Map of indices and values of exogenized variables and endogenized shocks.

condShocksdict.

Map of conditinal shocks.

anticipatebool.

True if shocks are anticipated.

nxint

The number of endogenous variables.

neint

The number of shocks.

lastint

The last time period of adjustments.

Returns:

Indices of exogenized variables and endogenized shocks and values of judgemental adjustments.

snowdrop.src.numeric.solver.tunes.hasImaginaryShocks(shocks) bool[source]

Check if any shock at any time is a complex number.

Parameters:
shocksNumpy array

List of shocks.

Returns:
imaginary_shocksbool

Returns True if any shock is a complex.

snowdrop.src.numeric.solver.tunes.hasImaginaryValues(m) bool[source]

Check if any shock at any time is a complex number.

Parameters:
mdict.

Map of indices and values of exogenized variables and endogenized shocks.

Returns:
imaginary_valuesbool

Returns True if any path has imaginary value.

snowdrop.src.numeric.solver.tunes.mixed(model, x, T, Re, C, shocks, Nperiods, scale=1 + 0j)[source]

Forecast with judgmental adjustments (conditional forecasts).

This is a generic case with a mixture of anticipated and un-anticipated shocks. This soltion also can handle conditional shocks.

If model anticipate flag is set to True, then real numbers describe anticipated shocks and imaginary numbers describe un-anticipated shocks. If model anticipate flag is set to False, then real numbers describe un-anticipated shocks and imaginary numbers describe anticipated shocks.

Parameters:
modelModel.

`Model’ object.

xnumpy.ndarray.

Unadjusted values of endogenous variables.

Tnumpy array.

Transition matrix.

Renumpy.ndarray.

Matrix of coefficiets of shocks.

Cnumpy.ndarray.

Matrix of constants.

shockslist.

Shocks at different time periods.

Nperiodsint.

Simulation time range.

scalenumpy.complex.

Scaling factor for standard deviations of expected and un-expected shocks. If model.anticipate flag is set to True , then real part of scale is a multiplier for standard devitions of expected shocks and the imaginary part is a multiplier for standard devitions of un-expected shocks. If model.anticipate flag is set to False, then it is wise versa.

Returns:
xnumpy array.

Solution of the system.

eanumpy array.

Anticipated shocks.

eunumpy array.

Un-anticipated shocks.

snowdrop.src.numeric.solver.tunes.non_linear_anticipated(model, shocks, Nperiods, minimizeObjFunc=False, debug=True)[source]

Forecast of non-linear model with a fixed path of some of the endogenous variables and anticipated shocks.

Parameters:
param model:

Model object.

type model:

`Model’.

param shocks:

Shocks at different time periods..

type shocks:

list.

param Nperiods:

Number of time periods.

type Nperiods:

int.

param minimizeObjFunc:

If True applies minimization algorithm to find desired path.

type minimizeObjFunc:

bool.

returns:

Array of steady states of endogenous variables and their growth.

snowdrop.src.numeric.solver.tunes.non_linear_mixed(model, shocks, Nperiods)[source]

Forecast of non-linear model with a fixed path of some of the endogenous variables.

Parameters:
param model:

Model object.

type model:

`Model’.

param shocks:

Shocks at different time periods..

type shocks:

list.

param Nperiods:

Number of time periods.

type Nperiods:

int.

returns:

Array of endogenous variables steady states and their growth.

snowdrop.src.numeric.solver.tunes.non_linear_not_anticipated(model, shocks, Nperiods, minimizeObjFunc=False, debug=True)[source]

Forecast of non-linear model with a fixed path of some of the endogenous variables and all un-anticipated shocks.

Parameters:
param model:

Model object.

type model:

`Model’.

param shocks:

Shocks at different time periods..

type shocks:

list.

param Nperiods:

Number of time periods.

type Nperiods:

int.

param minimizeObjFunc:

If True applies minimization algorithm to find desired path.

type minimizeObjFunc:

bool.

returns:

Array of endogenous variables steady states and their growth.

snowdrop.src.numeric.solver.tunes.not_anticipated(mapSwap, y, shocks, T, R, C, Nperiods, rng)[source]

Forecast of linear model with a fixed path of some of the endogenous variables with all un-anticipated shocks.

Parameters:
mapSwapdict.

Map of indices and values of exogenized variables and endogenized shocks.

ynumpy.ndarray.

The solution with no tunes.

shockslist.

Shocks at different time periods.

Tnumpy.ndarray.

Transition matrix.

Rnumpy.ndarray.

Matrix of coefficiets of shocks.

Cnumpy.ndarray.

Matrix of constants.

Nperiodsnumpy array.

Number of time periods.

rnglist.

Time range of the tunes.

Returns:
ynumpy.ndarray.

Numerical solution with tunes.

shocksnumpy.ndarray.

Shocks that bring path of endogenous variables to the desired level.

snowdrop.src.numeric.solver.tunes.stdcorr2cov(stdDev, ne, T) array[source]

Create covariance matrix given standard deviations.

Parameters:
stdDevnumpy.ndarray

Standard deviations.

neint

Number of shocks.

Tint

Number of time periods.

Returns:
covNumpy array

Diagonal covariance matrix.

snowdrop.src.numeric.solver.util module

Utility module functions.

class snowdrop.src.numeric.solver.util.UnionFind(numOfElements)[source]

Bases: object

find_set(node)[source]
union_set(node1, node2)[source]
snowdrop.src.numeric.solver.util.arnoldi_iteration(A, b, n: int)[source]

Computes a basis of the (n + 1)-Krylov subspace of A: the space spanned by {b, Ab, …, A^n b}.

Arguments:

A: m × m array

b: initial vector (length m)

n: dimension of Krylov subspace, must be >= 1

Returns:

Q: m x (n + 1) array, the columns are an orthonormal basis of the Krylov subspace.

h: (n + 1) x n array, A on basis Q. It is upper Hessenberg.

Please see:

snowdrop.src.numeric.solver.util.cartesian(arrays, out=None)[source]

Generate a cartesian product of input arrays.

Args:
arrays: list of array-like

1-D arrays to form the cartesian product of.

out: ndarray

Array to place the cartesian product in.

Returns:
outndarray

2-D array of shape (M, len(arrays)) containing cartesian products formed of input arrays.

Examples:

>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))
>>> array([[1, 4, 6],
           [1, 4, 7],
           [1, 5, 6],
           [1, 5, 7],
           [2, 4, 6],
           [2, 4, 7],
           [2, 5, 6],
           [2, 5, 7],
           [3, 4, 6],
           [3, 4, 7],
           [3, 5, 6],
           [3, 5, 7]])
snowdrop.src.numeric.solver.util.check()[source]
snowdrop.src.numeric.solver.util.checkBK(model, x, qz_factor=1.000001, debug=False)[source]

Check Blachard-Kahn Condition.

snowdrop.src.numeric.solver.util.checkSolution(model, periods, y)[source]

Return errors of equations given solution.

Parameters:
param model:

Model object.

type model:

Model.

param periods:

Array of periods.

type periods:

numpy.array.

param y:

Array of endogenous variables values.

type y:

np.array.

returns:

Array of equations residuals.

snowdrop.src.numeric.solver.util.checkSteadyState(model, endog)[source]

Find values of equations residuals for a given steady state.

Parameters:
param model:

Model object.

type model:

Model.

param endog:

List of endogenous variables values.

type endog:

list.

returns:

Array of equations residuals.

snowdrop.src.numeric.solver.util.clustered_sorter(a, b, div)[source]

Sort eigen values.

The sorting algorithm of General Schur decomposition function.

Args:
aDiagonal element of Schur decomposition.

complex or real array.

bDiagonal element of Schur decomposition.

complex or real array.

Returns:
clustersnp.array

Clusters of eigen values.

snowdrop.src.numeric.solver.util.decompose(model, y, endog, n, T, periods, isKF)[source]

Decomposes the right-hand-side of equations into components that are caused by contributions of endogenous variables one at a time.

Parameters:
param model:

Model object.

type model:

Model.

param y:

Values of endogenous variables.

type y:

numpy.array

param endog:

Valiables names.

type endog:

List.

param n:

Endogenous variable name.

type n:

str.

param T:

Time span.

type T:

int.

param periods:

Vector of periods that define shocks timing.

type periods:

numpy.array.

param isKF:

True if shocks are obtained by Kalman Filter.

type isKF:

bool.

returns:

Array of decompositions.

snowdrop.src.numeric.solver.util.find_eigen_values(model, steady_state=None)[source]

Find eigen values of Jacobian.

Parameters:
param model:

Model object.

type model:

Model.

param steady_state:

Endogenous variables steady states.

type steady_state:

list.

returns:

Eigen values.

snowdrop.src.numeric.solver.util.find_residuals(model, y)[source]

Find values of shocks that minimize errors of equations.

Parameters:
param model:

Model object.

type model:

Model.

param y:

Array of endogenous varuables values.

type y:

np.array.

returns:

Array of endogenous variables residuals.

snowdrop.src.numeric.solver.util.find_starting_lag_values(model)[source]

Find starting values of lead/lag variables.

These are starting values of variables with lead or lag greater than one.

Parameters:
param model:

Model object.

type model:

Model.

returns:

Array of starting values.

snowdrop.src.numeric.solver.util.gauss_hermite_nodes(orders, sigma, mu=None)[source]

Compute the weights and nodes for Gauss Hermite quadrature.

Args:
ordersint, list, array

The order of integration used in the quadrature routine

sigmaarray-like

If one dimensional, the variance of the normal distribution being approximated. If multidimensional, the variance-covariance matrix of the multivariate normal process being approximated.

Returns:
xarray

Quadrature nodes

warray

Quadrature weights

snowdrop.src.numeric.solver.util.getAllShocks(model, periods, n_shocks, Npaths, T)[source]

Return list of shocks for all paths.

Args:
modelModel.

Model object.

periods

Simulation periods.

n_shocksint

Number of shocks.

Npathsint

Number of paths.

Tint

Time range.

Returns:
all_shocksList

List of shocks for all paths.

snowdrop.src.numeric.solver.util.getCombinedShocks(shocks, n_shocks, T, min_lag_shock, max_lead_shock)[source]

Combine lagged and lead shocks.

Parameters:
param shocks:

Array of shocks.

type shocks:

np.array.

param n_shocks:

Number of shock variables.

type n_shocks:

int.

param T:

Maximum time.

type t:

int.

param min_lag_shock:

Minimum lag of shocks

type min_lag_shock:

int

param max_lead_shock:

Maximum lead of shocks

type max_lead_shock:

int

returns:

Arrays of shocks arranged from laged shocks to lead shocks.

snowdrop.src.numeric.solver.util.getCovarianceMatricies(measurement_variables, measurement_shocks, measurement_equations, shocks, model)[source]

Build covariance matrices of errors of endogenous and measurement variables.

It is assumed that standard deviations of variables are prefixed with ‘std_RES_*’ or ‘std_SHK_*’ name.

Parameters:
param measurement_variables:

List of measurement variables.

type measurement_variables:

list.

param measurement_shocks:

Measurement shock variables.

type measurement_shocks:

list.

param shocks:

List of shock variables.

type shocks:

list.

param model:

Model object.

type model:

Model.

returns:

Covariance matrices of endogenous `Q’ and measurement `H’ variables. These covariance matrices are diagonal.

snowdrop.src.numeric.solver.util.getCovarianceMatrix(Q, H, calib, shocks, meas_shocks)[source]

Build covariance matrices of errors of endogenous and measurement variables.

It is assumed that standard deviations of variables are prefixed with ‘std_RES_*’ or ‘std_SHK_*’ name.

Parameters:
param Q:

Covariance matrix of shocks errors.

type Q:

numpy array.

param calib:

Map of estimated shock names and values of standard deviations.

type calib:

dict.

param shocks:

List of shock variables.

type shocks:

list.

param meas_shocks:

List of shock of measurement variables.

type meas_shocks:

list.

returns:

Diagonal covariance matrices of endogenous variables.

snowdrop.src.numeric.solver.util.getExogenousData(model, t=0)[source]

Return combined lag and lead time series.

Args:
modelModel.

Model object.

tTime period.

int.

Returns:
exogList

Exogenous data at time t.

snowdrop.src.numeric.solver.util.getForwardLookingVariables(model, T=None, K=None, debug=False)[source]

Get indices of forward/backward looking endogenous variables.

Args:
modelModel

Instance of model object.

T: 2-D ndarray.

State transition matrix.

K: 1-D ndarray

Vector of constants.

debugbool, optional

If True prints names of backward and forward variables.

Returns:

List of backward and forward variables and their column and row numbers.

snowdrop.src.numeric.solver.util.getIndicesAndData(n, row_ind, col_ind, jacob)[source]

Build row and column indices and partition jacobian matrix into lead, current, and lag parts.

Parameters

nint

Number of rows.

row_indlist

Row indices.

col_indlist

Column indices.

jacob2d numpy.array

Jacobian matrix.

Returns

lead_row_indlist

Row indices of lead variables.

lead_col_indlist

Column indices of lead variables.

lead_datalist

Jacobian matrix of lead variables.

current_row_indlist

Row indices of current variables

current_col_indlist

Column indices of current variables.

current_datalist

Jacobian matrix of current variables.

lag_row_indlist

Row indices of lag variables

lag_col_indlist

Column indices of lag variables.

lag_datalist

Jacobian matrix of lag variables.

snowdrop.src.numeric.solver.util.getMatlabMatrices(n_meas_shocks)[source]

Read Matlab matrices.

snowdrop.src.numeric.solver.util.getMatrices(model, n, y, t=None)[source]
snowdrop.src.numeric.solver.util.getMatrix(n, row_ind, col_ind, jacob)[source]

Build matrix given row, column and data indices.

Parameters

nint

Number of rows.

row_indlist

Row indices.

col_indlist

Column indices.

jacob2d numpy.array

Jacobian matrix.

Returns

lead_row_indlist

Row indices of lead variables.

lead_col_indlist

Column indices of lead variables.

lead_datalist

Jacobian matrix of lead variables.

current_row_indlist

Row indices of current variables

current_col_indlist

Column indices of current variables.

current_datalist

Jacobian matrix of current variables.

lag_row_indlist

Row indices of lag variables

lag_col_indlist

Column indices of lag variables.

lag_datalist

Jacobian matrix of lag variables.

snowdrop.src.numeric.solver.util.getOneVarEqsSolution(lvars, lfunc, largs, leqs, mv, mp, exog_data, T)[source]

Solve one variable equations.

Parameters:
param lvars:

List of equations variables.

type lvars:

list.

param lfunc:

Compiled functions.

type lfunc:

list.

param largs:

Functions arguments.

type largs:

list.

param leqs:

Equations.

type leqs:

list.

param mv:

Values of variables.

type mv:

dictionary.

param mp:

Parameters.

type mp:

dictionary.

param exog_data:

Exogenous data.

type exog_data:

dictionary.

param T:

Time span.

type T:

int.

returns:

Dictionary of time series.

snowdrop.src.numeric.solver.util.getParameters(parameters=None, model=None, t=0)[source]

Return model parameters.

Parameters:
param parameters:

Values of parameters.

type parameters:

numpy.array.

param model:

Model object.

type model:

model.

param t:

Current period.

type t:

int.

snowdrop.src.numeric.solver.util.getShocks(i=0, t=0, periods=None, shock_values=None, model=None, n_shk=0, bStochastic=False, permanent_shocks=False)[source]

Return shock values. It combines lead, lag and current values of shocks.

Parameters:
param i:

Current period.

type i:

int.

param t:

Time.

type t:

int.

param periods:

list of periods at which shocks are applied.

type periods:

List.

param shock_values:

Array of shock values.

type shock_values:

List.

param n_shk:

Number of shocks

type n_shk:

int.

param bStochastic:

True means that shocks are stochastic and are described by an exogenous process.

type bStochastic:

bool.

returns:

Shocks values.

snowdrop.src.numeric.solver.util.getStableUnstableRowsColumns(model, T=None, K=None, debug=True)[source]

Return row and column numbers of stable and unstable endogenous variables.

Parameters:
param model:

Model object.

type model:

Model.

param T:

State transition matrix.

type T:

2-D ndarray.

param K:

Vector of constants.

type K:

1-D ndarray.

returns:

Array of starting values

snowdrop.src.numeric.solver.util.getStableUnstableVariables(model, T=None, K=None, debug=False)[source]

Get indices of stable and unstable endogenous variables.

Args:
modelModel

Instance of model object.

T: 2-D ndarray.

State transition matrix.

K: 1-D ndarray

Vector of constants.

debugbool, optional

If True prints names of stable and unstable variables..

Returns:

Indices of stable and unstable endogenous variables.

snowdrop.src.numeric.solver.util.getStationaryVariables(model, T=None, K=None, debug=False)[source]

Return stationary and non-stationary endogenous variables.

Parameters:
param model:

Model object.

type model:

Model.

param T:

Transition matrix.

type T:

2-D ndarray.

param K:

Vector of constants.

type K:

1-D ndarray.

snowdrop.src.numeric.solver.util.getTrend(data, N, deg=1)[source]

Get trend component.

Parameters:
param data:

Observation data.

type data:

pandas DataFrame.

param deg:

Fitted polynomial degree.

type deg:

int.

snowdrop.src.numeric.solver.util.getTrendCofficients(model, T)[source]

Create an array with steady state paths for all variables.

Parameters:
param model:

The Model object.

type model:

instance of class Model.

param T:

Time range.

type T:

int.

snowdrop.src.numeric.solver.util.get_adjusted_shocks(model, x, shocks, N, debug=False)[source]

Get shocks that satisfy model equations.

Parameters:
param model:

Model object.

type model:

`Model’.

param x:

Solution.

type x:

numpy 2D array.

param shocks:

Shocks at different time periods..

type shocks:

list.

param N:

Number of time periods.

type N:

int.

returns:

List of shocks that satisfy original equations.

snowdrop.src.numeric.solver.util.hermgauss(n)[source]

Compute weights and nodes of Gauss-Hermite quadrature.

Credits : both routines below are ported from the Compecon Toolbox by Paul L Fackler and Mario J. Miranda. Original code is available at http://www4.ncsu.edu/~pfackler/compecon/toolbox.html

Translated from Matlab code to Python by A.G.

snowdrop.src.numeric.solver.util.is_pd(B)[source]

Returns true when input is positive-definite, via Cholesky

snowdrop.src.numeric.solver.util.nearest_pd(A)[source]

Find the nearest positive-definite matrix to input A.

snowdrop.src.numeric.solver.util.orthogonalize_shocks(model)[source]

Uses Cholesky decomposition to orthogonalize shocks.

Parameters:
param model:

Model object

type model:

`Model’.

snowdrop.src.numeric.solver.util.qzdiv(A, B, Q, Z, cluster=None, v=None)[source]

Reorder QZ decomposition matrices.

Takes U.T. matrices A, B, orthogonal matrices Q,Z, rearranges them according to the order of matrix roots: abs(B(i,i)/A(i,i)) so that lower values are in lower right corner, while preserving U.T. and orthonormal properties and Q’AZ’ and Q’BZ’. The columns of v are sorted correspondingly.

snowdrop.src.numeric.solver.util.qzdiv2(stake, A, B, Q, Z, v=None)[source]

Reorder QZ decomposition matrices.

Takes U.T. matrices A, B, orthonormal matrices Q,Z, rearranges them so that all cases of abs(B(i,i)/A(i,i))>stake are in lower right corner, while preserving U.T. and orthonormal properties and Q’AZ’ and Q’BZ’. The columns of v are sorted correspondingly.

by Christopher A. Sims modified (to add v to input and output) 7/27/2000

snowdrop.src.numeric.solver.util.qzswitch(i, A, B, Q, Z)[source]

Swap QZ decomposition matrices. This is a simplified version of Sims’ code.

Takes U.T. matrices A, B, orthonormal matrices Q,Z, interchanges diagonal elements i and i+1 of both A and B, while maintaining Q’AZ’ and Q’BZ’ unchanged. If diagonal elements of A and B are zero at matching positions, the returned A will have zeros at both positions on the diagonal. This is natural behavior if this routine is used to drive all zeros on the diagonal of A to the lower right, but in this case the qz transformation is not unique and it is not possible simply to switch the positions of the diagonal elements of both A and B.

snowdrop.src.numeric.solver.util.qzswitch2(i, A, B, Q, Z)[source]

Swap QZ decomposition matrices. This is an original version of Sims’ code.

Takes U.T. matrices A, B, orthonormal matrices Q,Z, interchanges diagonal elements i and i+1 of both A and B, while maintaining Q’AZ’ and Q’BZ’ unchanged. If diagonal elements of A and B are zero at matching positions, the returned A will have zeros at both positions on the diagonal. This is natural behavior if this routine is used to drive all zeros on the diagonal of A to the lower right, but in this case the qz transformation is not unique and it is not possible simply to switch the positions of the diagonal elements of both A and B.

Translated from the original Sims’ Matlab code.

snowdrop.src.numeric.solver.util.sorter(a, b)[source]

Sort eigen values.

The sorting algorithm of ordered Schur decomposition function.

Args:
aDiagonal element of Schur decomposition.

complex or real array.

bDiagonal element of Schur decomposition.

complex or real array.

Returns:
clustersnp.array

Clusters of eigen values.

snowdrop.src.numeric.solver.util.test_hermite()[source]

Test hermgauss.

Module contents