StateSpaceEcon Reference
Public Interface
Steady state solver
StateSpaceEcon.SteadyStateSolver
— ModuleSteadyStateSolver
A module that is part of StateSpaceEcon package. Contains methods for finding a steady state solution of a model.
StateSpaceEcon.SteadyStateSolver.check_sstate
— Methodcheck_sstate(model; <options>)
Run a diagnostic test to determine if the steady state solution stored within the given model object is indeed a solution of the steady state system of equations.
Return the number of steady state equations that are violated by the current steady state solution. If verbose=true
, also display diagnostic information in the form of listing all bad equations and their residuals.
Options
Standard options (default values from model.options
)
verbose
tol
- an equation is considered satisfied if its residual, in absolute value, is smaller than this number.
StateSpaceEcon.SteadyStateSolver.clear_sstate!
— Methodclear_sstate!(model; lvl=0.1, slp=0.0, <options>)
Set the steady state values to the provided defaults and presolve.
Arguments
model
- the model instancelvl
,slp
- the initial guess for the level and the slope. Each could be a number or a vector of length equal to the number of variable in the model. Variables include regular and exogenous variables, but not shocks (shocks are assumed to be 0 in steady state).
Options
Standard options (default values are taken from model.options
)
verbose
StateSpaceEcon.SteadyStateSolver.diagnose_sstate
— Methoddiagnose_sstate([point,] model)
Run diagnostics on the steady state of the given model. If point
is not given, then we check the steady state solution stored inside the given model.
Return a tuple of "bad" equations and "bad" variables.
The set of "bad" equations is one that is inconsistent, i.e. there is no solution. This might happen if the system is overdetermined.
The set of "bad" variables contains variables that cannot be solved uniquely. This might happen if the system is underdetermined. In this case, try adding steady state constraints until you get a unique solution. See @steadystate
in ModelBaseEcon.
The output from this function may be difficult to read.<br> Call check_sstate
instead.
StateSpaceEcon.SteadyStateSolver.initial_sstate!
— Methodinitial_sstate!(model, init; <options>)
Set the steady state values from the given vector and presolve.
Call this function to specify initial guesses for the iterative steady state solver. If the value of a steady state variable is known, it is better to use @steadystate
to add that as a steady state constraint.
Arguments
model
- the model.init
- a vector of length equal to twice the number of variables in the model. The level and slope values are staggered, i.e., the level and slope of variable j are in init[2j-1] and init[2j].
Options
Standard options (default values are taken from model.options
)
verbose
StateSpaceEcon.SteadyStateSolver.sssolve!
— Methodsssolve!(model; <options>)
Solve the steady state problem for the given model.
Options
Standard options (default values are taken from model.options
)
verbose
tol
,maxiter
- control the stopping criteria of the solver
Specific options
presolve::Bool
- whether or not to use a presolve pass. Default istrue
.method::Symbol
- choose the solution algorithm. Valid options are:nr
for Newton-Raphson,:lm
for Levenberg-Marquardt, and:auto
. The:auto
method starts with the LM algorithm and automatically switches to NR when it starts to converge. Default is:nr
.
Stacked-Time Solver
StateSpaceEcon.StackedTimeSolver
— ModuleStackedTimeSolver
A module that is part of StateSpaceEcon package. Contains methods for solving the dynamic system of equations for the model and running simulations.
StateSpaceEcon.StackedTimeSolver.fcgiven
— Constantconst fcgiven = FCGiven()
Used when the final conditions are given in the exogenous data.
StateSpaceEcon.StackedTimeSolver.fclevel
— Constantconst fclevel = FCMatchSSLevel()
Used when the final condition is to match the level of the steady state solution.
StateSpaceEcon.StackedTimeSolver.fcnatural
— Constantconst fcnatural = FCConstRate()
Used when the final condition is a constant slope, but the slope value is unknown.
StateSpaceEcon.StackedTimeSolver.fcnone
— Constantconst fcnone = FCNone()
Used internally for variables without final conditions, such as shocks and exogenous.
StateSpaceEcon.StackedTimeSolver.fcrate
— Constantconst fcrate = FCMatchSSRate()
Used when the final condition is to match the slope of the steady state solution.
StateSpaceEcon.StackedTimeSolver.fcslope
— Constantconst fcslope = FCMatchSSRate()
Used when the final condition is to match the slope of the steady state solution.
StateSpaceEcon.StackedTimeSolver.FCConstRate
— Typestruct FCConstRate <: FinalCondition end
Final condition is such that the variable grows at a
StateSpaceEcon.StackedTimeSolver.FCGiven
— Typestruct FCGiven <: FinalCondition end
Final conditions are given in the exogenous data.
StateSpaceEcon.StackedTimeSolver.FCMatchSSLevel
— Typestruct FCMatchSSLevel <: FinalCondition end
Final conditions match the level of the steady state.
StateSpaceEcon.StackedTimeSolver.FCMatchSSRate
— Typestruct FCMatchSSRate <: FinalCondition end
Final conditions are such that the solution has the same slope (growth rate or rate of change) as the steady state solution.
StateSpaceEcon.StackedTimeSolver.FCNone
— Typestruct FCNone <: FinalCondition end
Variables that don't have lags in the model don't need final conditions.
StateSpaceEcon.StackedTimeSolver.FinalCondition
— Typeabstract type FinalCondition end
Abstract base type for all final conditions
StateSpaceEcon.StackedTimeSolver.dictoverlay
— Functiondictoverlay(d1, d2)
Merge two dictionaries. Common key where the values are TSeries
of the same frequency are overlayed. Otherwise, a common key takes the value of the last Dict containing it.
This function will be removed. Use TimeSeriesEcon.overlay
instead. An important difference is that TimeSeriesEcon.overlay
keeps the values from the first argument where the key appears, while dictoverlay
keeps it from the last.
StateSpaceEcon.StackedTimeSolver.seriesoverlay
— Functionseriesoverlay(ts1, ts2)
Return a new TSeries
over the full range of both arguments. The overlapping part contains values from the last argument.
This function will be removed in the future. Use TimeSeriesEcon.overlay
instead. Note the important difference that in TimeSeriesEcon.overlay
the values in the overlay come from the first series where the value exists, as opposed to seriesoverlay
where it was from the last one.
See also: dictoverlay
StateSpaceEcon.StackedTimeSolver.setfc
— Functionsetfc(model, fc)
Return a vector of final conditions for all variables in the model
. The final conditions of all variables are set to fc
, except shocks and exogenous, which are always fcnone
. Use setfc!
to update the final condition of individual variable.
StateSpaceEcon.StackedTimeSolver.setfc!
— Functionsetfc!(fc_vector, model, variable, new_fc)
Update the final condition for the given variable
in the given fc_vector
to new_fc
. The fc_vector
is the output of setfc
.
StateSpaceEcon.StackedTimeSolver.use_pardiso!
— Methoduse_pardiso!(model)
Instruct the stacked-time solver to use Pardiso with this model.
StateSpaceEcon.StackedTimeSolver.use_pardiso
— Methoduse_pardiso()
Set the default sparse factorization library to Pardiso. See also use_umfpack
.
StateSpaceEcon.StackedTimeSolver.use_umfpack!
— Methoduse_umfpack!(model)
Instruct the stacked-time solver to use Pardiso with this model. See also use_pardiso!
.
StateSpaceEcon.StackedTimeSolver.use_umfpack
— Methoduse_umfpack()
Set the default sparse factorization library to UMFPACK (the one used in Julia's standard library). See also use_pardiso
.
Plans
StateSpaceEcon.Plans
— ModulePlans
Module part of StateSpaceEcon. This module implements the Plan
data structure, which is used in simulations. The plan object contains information about the range of the simulation and which variables and shocks are exogenous or endogenous at each period of the range.
Constructors
Modify the plan
exogenize!
,endogenize!
- make variables exogenous or endogenousexog_endo!
,endo_exog!
- swap exogenous and endogenous variablesautoexogenize!
- exogenize and endogenize variables according to the list in the model
StateSpaceEcon.Plans.Plan
— TypePlan{T <: MIT}
A data structure representing the simulation plan. It holds information about the time range of the simulation and which variables/shocks are exogenous at each period.
StateSpaceEcon.Plans.Plan
— MethodPlan(model, range)
Create a default simulation plan for the given model over the given range. The range of the plan is augmented to include periods before and after the given range, over which initial and final conditions will be applied.
Instead of a range, one could also pass in a single moment in time (MIT
) instance, in which case it is interpreted as a range of length 1.
StateSpaceEcon.Plans.autoexogenize!
— Methodautoexogenize!(plan, model, date)
Modify the given plan according to the "autoexogenize" protocol defined in the given model. All variables in the autoexogenization list become endogenous and their corresponding shocks become exogenous over the given date or range. date
can be a moment in time (same frequency as the given plan), a range, an iterable, or a container.
StateSpaceEcon.Plans.compare_plans
— Functioncompare_plans(left, right; options)
compare_plans(file, left, right; options)
Display a comparison of two plans, or save it in a text file.
Options
alphabetical=false
- set totrue
to sort the variables. By default variables will be listed in the same order as in the left plan.exog_mark="X"
- a short string (ideally 1 character) to mark exogenous values.endo_mark="~"
- a short string (ideally 1 character) to mark endogenous values.missing_mark="."
- a short string (ideally 1 character) to display when a variable is missing from one of the plans.delim=" "
- delimiter. Use","
` to make it a CSV file.pagelines=0
- Set to a positive integer to enable pagination. Number is interpreted as the number of lines to repeat the header line (the one with the ranges).
StateSpaceEcon.Plans.count_endo_points
— Functioncount_endo_points(p::Plan, rng, vars)
Count the number of endogenous points for the given plan over the given range.
Example:
count_endo_points(p, :, m.shocks)
See also count_exog_points
StateSpaceEcon.Plans.count_exog_points
— Functioncount_exog_points(p::Plan, rng, vars)
Count the number of exogenous points for the given plan over the given range.
Example:
count_exog_points(p, :, m.exogenous)
See also count_endo_points
StateSpaceEcon.Plans.endo_exog!
— Methodendo_exog!(plan, endo_vars, exog_vars, date)
Modify the given plan so that the given variables listed in exog_vars
will be exogenous and the variables listed in endo_vars
will be endogenous on the given dates. exog_vars
and endo_vars
can each be a Symbol
or a String
or a Vector
of such. date
can be a moment in time (same type as the plan), or a range or an iterable or a container.
StateSpaceEcon.Plans.endogenize!
— Methodendogenize!(plan, vars, date)
Modify the given plan so that the given variables will be endogenous on the given dates. vars
can be a Symbol
or a String
or a Vector
of such. date
can be a moment in time (same type as the plan), or a range or an iterable or a container.
StateSpaceEcon.Plans.exog_endo!
— Methodexog_endo!(plan, exog_vars, endo_vars, date)
Modify the given plan so that the given variables listed in exog_vars
will be exogenous and the variables listed in endo_vars
will be endogenous on the given dates. exog_vars
and endo_vars
can each be a Symbol
or a String
or a Vector
of such. date
can be a moment in time (same type as the plan), or a range or an iterable or a container.
StateSpaceEcon.Plans.exogenize!
— Methodexogenize!(plan, vars, date)
Modify the given plan so that the given variables will be exogenous on the given dates. vars
can be a Symbol
or a String
or a Vector
of such. date
can be a moment in time (same type as the plan), or a range or an iterable or a container.
StateSpaceEcon.Plans.exportplan
— Functionexportplan(plan; options)
exportplan(file, plan; options)
Display the plan or save it in a text file.
Options
alphabetical=false
- set totrue
to sort the variables. By default variables will be listed in the same order as in the model.exog_mark="X"
- a short string (ideally 1 character) to mark exogenous values.endo_mark="-"
- a short string (ideally 1 character) to mark endogenous values.delim=" "
- delimiter. Use","
` to make it a CSV file.
See also importplan
StateSpaceEcon.Plans.importplan
— FunctionStateSpaceEcon.Plans.plansum
— Methodplansum(model, plan)
Return the total number of exogenous variables in the simulation plan. Periods over which initial and final conditions are imposed are not counted in this sum.
StateSpaceEcon.Plans.setexog!
— Methodsetexog!(plan, t, vinds)
Modify the plan at time t such that vinds
are exogenous and the rest are endogenous.
Various
StateSpaceEcon.StateSpaceEcon
— ModuleStateSpaceEcon
A package for Macroeconomic modelling.
StateSpaceEcon.SimData
— TypeSimData
Data structure containing the time series data for a simulation.
It is a collection of TSeries
of the same frequency and containing data for the same range. When used for simulation, the range must include the initial conditions, the simulation range and the final conditions, although it could extend beyond that. It must contain time series for all variables and shocks in the model, in the same order as in the model object.
StateSpaceEcon.array2data
— Functionarray2data(matrix, model, plan; copy=false)
array2data(matrix, vars, range; copy=false)
Convert a plain matrix with simulation data to a SimData
.
StateSpaceEcon.array2dict
— Functiondict2array, array2dict
dict2data, data2dict
Deprecated. Use the workspace instead of dict.
StateSpaceEcon.array2workspace
— Functionarray2workspace(matrix, model, plan; copy=false)
array2workspace(matrix, vars, range; copy=false)
Convert a plain matrix with simulation data to a Workspace
.
StateSpaceEcon.data2array
— Functiondata2array(data; copy=false)
data2array(data, model, plan; copy=false)
data2array(data, vars, range; copy=false)
Convert a SimData
to a matrix.
StateSpaceEcon.data2dict
— Functiondict2array, array2dict
dict2data, data2dict
Deprecated. Use the workspace instead of dict.
StateSpaceEcon.data2workspace
— FunctionStateSpaceEcon.dict2array
— Functiondict2array, array2dict
dict2data, data2dict
Deprecated. Use the workspace instead of dict.
StateSpaceEcon.dict2data
— Functiondict2array, array2dict
dict2data, data2dict
Deprecated. Use the workspace instead of dict.
StateSpaceEcon.printmatrix
— Methodprintmatrix(mat [, Val(F), colnames])
Display a matrix in full while controlling the formatting of each value and optionally showing the column names.
Val(F)
- display each number in the given formatF
. The format is in the form of a decimal point number where the whole part indicates the total width and the fractional part indicates the number of digits printed after the decimal point. Default isVal(12.7)
colnames
- a list of names to display in the first row. The names are displayed as given, possibly with padding to match the width given in theVal
argument. If any names are longer than that, they will not be truncated and so the display will not be aligned properly. Sorry about that!
StateSpaceEcon.shockdecomp
— Functionshockdecomp(model, plan, exog_data; control, solver, [options])
Compute the shock decomposition for the given model, plan, exogenous (shocks) data and control solution.
If the control
option is not specified we use the steady state solution stored in the model instance. The algorithm assumes that control
is a solution to the dynamic model for the given plan range and final condition. We verify the residual and issue a warning, but do not enforce this. See steadystatedata
.
As part of the algorithm we run a simulation with the given plan, data and solver. See simulate
for additional options that control the simulation.
Note that unlike simulate
, here we require exogdata
and control
to be MVTSeries
, i.e. plain Array
or Workspace
are not allowed.
The returned value is a Workspace
with three things in it: c
contains a copy of control
, s
contains the simulated solution for the given plan
and exogdata
and sd
contains the shock decomposition data. The data in sd
is organized as a Workspace
containing an MVTSeries
for each variable,
StateSpaceEcon.simulate
— Functionsimulate(model, plan, data; <options>)
Run a simulation for the given model, simulation plan and exogenous data.
Arguments
* `model` - the [`Model`](@ref ModelBaseEcon.Model) instance to simulate.
* `plan` - the [`Plan`](@ref) for the simulation.
* `data` - a 2D `Array` containing the exogenous data. This includes the
initial and final conditions.
Options as keyword arguments
* `fctype::`[`FinalCondition`](@ref) - set the desired final condition type
for the simulation. The default value is [`fcgiven`](@ref). Other possible
values include [`fclevel`](@ref), [`fcslope`](@ref) and
[`fcnatural`](@ref).
* `initial_guess::AbstractMatrix{Float64}` - a 2D `Array` containing the
initial guess for the solution. This is used to start the Newton-Raphson
algorithm. The default value is an empty array (`zeros(0,0)`), in which case
we use the exogenous data for the initial condition. You can use the steady
state solution using [`steadystatearray`](@ref).
* `deviation::Bool` - set to `true` if the `data` is given in deviations from
the steady state. In this case the simulation result is also returned as a
deviation from the steady state. Default value is `false`.
* `anticipate::Bool` - set to `false` to instruct the solver that all shocks
are unanticipated by the agents. Default value is `true`.
* `verbose::Bool` - control whether or not to print progress information.
Default value is taken from `model.options`.
* `tol::Float64` - set the desired accuracy. Default value is taken from
`model.options`.
* `maxiter::Int` - algorithm fails if the desired accuracy is not reached
within this maximum number of iterations. Default value is taken from
`model.options`.
* `linesearch::Bool` - When `true` the Newton-Raphson is modified to include a
search along the descent direction for a sufficient decrease in f. It will
do this at each iteration. Default is `false`.
StateSpaceEcon.solve!
— Functionsolve!(m::Model; [solver::Symbol])
Solve the given model and update its m.solverdata
according to the specified solver. The solver is specified as a Symbol
. The default is solve=:stackedtime
.
StateSpaceEcon.steadystatearray
— Functionsteadystatearray(model, plan; [ref=firstdate(plan) + m.maxlag])
Create a Matrix{Float64}
of the proper dimension for a simulation with the given model with the given plan. It is initialized to the steady state.
In the case of steady state solution that is not stationary (i.e., non-zero slope) use the ref
option to specify the period in which the steady state level is given. The default for ref
is the first simulation period.
This function returns a Matrix
. We recommend using zerodata
, which returns SimData
. See also zeroworkspace
zeroarray(model, range)
will be removed in future versions. Always create a simulation Plan
explicitly.
StateSpaceEcon.steadystatedata
— Functionsteadystatedata(model, plan; [ref=firstdate(plan) + m.maxlag))
Create a SimData
for a simulation with the given model
and plan
. Columns correspond to the model variables and shocks in the correct order. Data is initialized with the steady state.
In the case of steady state solution that is not stationary (i.e., non-zero slope) use the ref
option to specify the period in which the steady state level is given. The default for ref
is the first simulation period.
See also zeroarray
and zeroworkspace
StateSpaceEcon.steadystatedict
— Functionsteadystatedict(model, plan; [ref=firstdate(plan) + m.maxlag))
This function will be removed in a future version. Use steadystateworkspace
.
StateSpaceEcon.steadystateworkspace
— Methodsteadystateworkspace(model, plan; [ref=firstdate(plan) + m.maxlag))
Create a Workspace
containing a TSeries
for each variable/shock in the given model
. They are initialized to the steady state solution.
In the case of steady state solution that is not stationary (i.e., non-zero slope) use the ref
option to specify the period in which the steady state level is given. The default for ref
is the first simulation period.
We recommend using steadystatedata
. See also steadystatearray
.
StateSpaceEcon.stoch_simulate
— Functionstoch_simulate(model, plan, baseline, shocks; control, ...)
Run multiple simulations with the given shocks centered about the given control (steady state by default).
The baseline should span the plan range and must be given in levels ( i.e., option deviation=true is not implemented)
The shocks can be given as a collection of random realizations, where each realization could be an MVTSeries or a Workspace. Only the shocks should be provided.
All shock names must be exogenous in the given plan over the range of the given data. The data in control
is taken as anticipated and the stochastic realizations are taken as unanticipated and the same plan is used for both components.
Currently only the case of solver=stackedtime
is implemented.
StateSpaceEcon.workspace2array
— Functionworkspace2array(w, model, plan; copy=false)
workspace2array(w, vars, range; copy=false)
Convert a Workspace
to a matrix.
StateSpaceEcon.workspace2data
— FunctionStateSpaceEcon.zeroarray
— Functionzeroarray(model, plan)
Create a Matrix{Float64}
of the proper dimension for a simulation with the given model with the given plan. It is initialized to 0.
This function returns a Matrix
. We recommend using zerodata
, which returns SimData
. See also zeroworkspace
zeroarray(model, range)
will be removed in future versions. Always create a simulation Plan
explicitly.
StateSpaceEcon.zerodata
— Functionzerodata(model, plan)
Create a SimData
for a simulation with the given model
and plan
. Columns correspond to the model variables and shocks in the correct order. Data is initialized with 0.
See also zeroarray
and zeroworkspace
StateSpaceEcon.zerodict
— Functionzerodict(model, plan)
This function will be removed in a future version. Use zeroworkspace
.
StateSpaceEcon.zeroworkspace
— MethodInternals
Steady state solver
StateSpaceEcon.SteadyStateSolver.LMData
— TypeLMData
A data structure that holds the necessary buffers and internal data for performing a step of the Levenberg–Marquardt algorithm
Internal use. Do not call directly
StateSpaceEcon.SteadyStateSolver.LMData
— MethodLMData(model)
LMData(model, sd::SolverData)
Make an instance of the LMData for the given model. If solver data is not also given, then it is used, instead of creating a default SolverData for the model.
StateSpaceEcon.SteadyStateSolver.NRData
— TypeNRData
A data structure that holds the necessary buffers and internal data for performing a step of the Newton-Raphson algorithm
Internal use. Do not call directly.
StateSpaceEcon.SteadyStateSolver.SolverData
— TypeSolverData
A data structure used during the solution of the steady state problem. It contains some current state information and some buffers.
This is an internal data structure. Do not use directly.
Why is this necessary?
The solution of the steady state problem is done in steps:
- The user sets the initial guess. This can be done with either
initial_sstate!
orclear_sstate!
- Pre-solve step. In this step we look for equations that have only one unknown and attempt to solve it. If successful, the unknown is marked as "solved" and is not an unknown anymore, also the equation is marked as "solved" and is not considered anymore. The process repeats for as long as it keeps solving.
- Solve step. This is where we solve the non-linear system composed of the remaining equations for the remaining variables.
This data structure keeps track of which unknowns and equations are solved and which remain to be solved. It also holds an indexing map that translates the indexes of the variables and equations we solve for to their original indexes in the full steady state system.
Fields
point
- a buffer for the current solution values. Some of these may be presolved, which are kept fixed while solving the system, while the rest are updated during solver iterations. The length equals the total number of steady state variables.resid
- a buffer for the current residual vector. The entries corresponding to presolved equations would normally be all zeros, while the ones corresponding to "active" equations would be updated during solver iterations. Lentgh equals the total number of steady state equations.solve_var
- a Boolean vector, same size aspoint
. Value oftrue
means that the unknown is "active", whilefalse
indicates that it has been pre-solved.solve_eqn
- a Boolean vector, same size asresid
. Value oftrue
means that the equation is "active", whilefalse
indicates that it has been pre-solved.vars_index
- an Integer vector, same length aspoint
. Entries corresponding to pre-solved variables hold zeros. Entries for active vars are numbered sequentially from 1 tonvars
eqns_index
- an Integer vector, same length asresid
. Presolved equations have a zero here, while active equations are numbered sequentially from 1 toneqns
.
StateSpaceEcon.SteadyStateSolver.SolverData
— MethodSolverData(model, presolve=Val(false); <options>)
Construct a SolverData instance from all variables and equations in the model, ignoring anything pre-solved.
Options
verbose::Bool
- if not specified it's taken from the model options.tol::Float64
- desired tolerance when checking the residual of presolved equation.presolve::Bool
- iffalse
, any pre-solved information is ignored and the solver data is set up to solve all equations for all variables.
StateSpaceEcon.SteadyStateSolver.bisect!
— Methodbisect!(F, x, i, dF; <options>)
Solve the equation F(x) = 0
for x[i]
keeping the other values of x
fixed. The input value of x[i]
is used as the initial guess and it is updated in place. Other entries of x
are not accessed at all. Return true
upon success, or false
otherwise.
Arguments
F
- A function that must accept a single argumentx
, which is an array, and must return the value ofF
(numeric scalar).x
- An array.i
- The index identifying the dimension in which we're solving the problem.dF
- A numeric value. This must equal the partial derivative of F with respect tox[i]
at the input value ofx[i]
. This value is used to construct the initial interval in which the bisection method will be applied.
Options
maxiter = 500
- maximum number of iterations. The default is large (500) because this method sometimes converges slowly.tol = 1e-8
- desired tolerance of the solution.
This is an internal function used by the steady state solver. In the future it might be removed or modified.
StateSpaceEcon.SteadyStateSolver.first_step_lm!
— Methodfirst_step_nr!(x, dx, resid, J, lm::LMData; verbose=false)
Make the first step of a Levenberg–Marquardt algorithm. Involves determining the initial trust region. The lm
structure and the dx
vector would be updated. Vectors x
, resid
and the matrix J
are read-only inputs.
Internal function, do not call directly.
StateSpaceEcon.SteadyStateSolver.global_SS_R!
— Methodglobal_SS_R!(R, point, model::Model)
When a model is given, we compute the residual of the entire steady state system.
StateSpaceEcon.SteadyStateSolver.global_SS_R!
— MethodR, J = global_SS_RJ(point, sd::SolverData)
When a solver data is given, we compute the residual of the active equations only.
StateSpaceEcon.SteadyStateSolver.global_SS_R!
— Methodglobal_SS_R!(R, point, equations)
Compute the residual vector of the given set of equations at the given point. The equations
argument can be a container whose eltype
is SteadyStateEquations
. The residual R
is updated in place.
StateSpaceEcon.SteadyStateSolver.global_SS_RJ
— MethodR, J = global_SS_RJ(point, sd::SolverData)
When applied to a solver data, computes the residual and Jacobian of the active set of equations with respect to the active set of variables.
StateSpaceEcon.SteadyStateSolver.global_SS_RJ
— MethodR, J = global_SS_RJ(point, model::Model)
When a model is given, we compute the residual of the entire steady state system.
StateSpaceEcon.SteadyStateSolver.global_SS_RJ
— MethodR, J = global_SS_RJ(point, equations)
Compute the residual vector R
and the Jacobian matrix of the given set of equations at the given point. The equations
argument can be a container whose eltype
is SteadyStateEquations
.
StateSpaceEcon.SteadyStateSolver.newton1!
— Methodnewton1!(F, x, i; <options>)
Solve the equation F(x) = 0
for x[i]
keeping the other values of x
fixed. The input value of x[i]
is used as the initial guess and it is updated in place. Other entries of x
are not accessed at all. Return true
upon success, or false
otherwise.
Function F
The function F
must accept a single argument x
, which is an array, and must return a tuple of two things: the value of F
(numeric scalar) and the gradient of F
(an array of the same shape as x). Only the i-th index of the gradient array is used.
Options
maxiter = 5
- maximum number of iterations. The default is small (5) because the Newton method either converges very fast or doesn't converge at all.tol = 1e-8
- desired tolerance of the solution.
Notes
The tol
value is used for a stopping criterion and also for diagnosing problems.
This is an internal function used by the steady state solver. In the future it might be removed or modified.
StateSpaceEcon.SteadyStateSolver.presolve_sstate!
— Functionpresolve_sstate!(model; <options>)
presolve_sstate!(model, mask, values; <options>)
Solve for the steady state variables that are decoupled from the system, or can be solved by forward substitution.
This is called automatically by the steady state solver before running its main loop.
Arguments
model
- the Model instancemask
- a vector of Bool. Defaults tomodel.sstate.mask
values
- a vector of numbers. Defaults tomodel.sstate.values
Caller must specify either bothmask
andvalues
or neither of them.mask[i]
equalstrue
if and only if the i-th steady state value has alredy been solved for.
mask
and values
are both input and output data to the algorithm. Any values that are successfully pre-solved are updated in place, and their mask
entries are set to true
.
Options
verbose
-true
orfalse
, whether or not to print diagnostic messages.tol
- accuracy of the 1d solver.
StateSpaceEcon.SteadyStateSolver.step_lm!
— Methodstep_nr!(x, dx, resid, J, lm::LMData; verbose=false)
Attempt a Levenberg–Marquardt step. The lm
structure and the dx
vector would be updated. Vectors x
, resid
and the matrix J
are read-only inputs.
Internal function, do not call directly.
StateSpaceEcon.SteadyStateSolver.step_nr!
— Methodstep_nr!(x, dx, resid, J, nr::NRData; verbose=false)
Attempt a Newton-Raphson step. The nr
structure and the dx
vector would be updated accordingly. Vectors x
, resid
and the matrix J
are read-only inputs.
Internal function, do not call directly.
StateSpaceEcon.SteadyStateSolver.update_auxvars_ss
— Methodupdate_auxvars_ss(point, model)
This function is for internal use. Do not call directly.
Stacked-Time Solver
StateSpaceEcon.StackedTimeSolver.StackedTimeSolverData
— TypeStackedTimeSolverData
The data structure used in the stacked time algorithm.
StateSpaceEcon.StackedTimeSolver.assign_exog_data!
— Methodassign_exog_data!(x::Matrix, exog::Matrix, sd::StackedTimeSolverData)
Assign the exogenous points into x
according to the plan with which sd
was created using exogenous data from exog
. Also call assign_final_condition!
.
Internal function not part of the public interface.
StateSpaceEcon.StackedTimeSolver.assign_fc!
— Functionassign_fc!(x::Vector, exog::Vector, vind::Int, sd::StackedTimeSolverData, fc::FinalCondition)
Applying the final condition fc
for variable with index vind
. Exogenous data is provided in exog
and stacked time solver data in sd
. This function updates the solution vector x
in place and returns x
.
Internal function not part of the public interface.
StateSpaceEcon.StackedTimeSolver.assign_final_condition!
— Methodassign_final_condition!(x::Matrix, exog::Matrix, sd::StackedTimeSolver)
Assign the final conditions into x
. The final condition types for the different variables of the model are stored in the the solver data sd
. exog
is used for fcgiven
.
Internal function not part of the public interface.
StateSpaceEcon.StackedTimeSolver.assign_update_step!
— Methodassign_update_step!(x::Array, lambda, dx, sd::StackedTimeSolverData)
Perform something similar to x = x + lambda * dx
, but with the necessary corrections related to final conditions.
StateSpaceEcon.StackedTimeSolver.make_BI
— Methodmake_BI(J, II)
Prepares the BI
array for the solver data. Called from the constructor of StackedTimeSolverData
.
Internal function not part of the public interface.
StateSpaceEcon.StackedTimeSolver.shockdecomp
— Methodshockdecomp(model, plan, exog_data; control, fctype, [options])
Compute the shock decomposition for the given model, plan, exogenous (shocks) data and control solution.
If control
option is not specified we use the steady state solution stored in the model instance. The algorithm assumes that control
is a solution to the dynamic model for the given plan range and final condition. We verify the residual and issue a warning, but do not enforce this. See steadystatedata
.
As part of the algorithm we run a simulation with the given plan
, exog_data
and fctype
. See simulate
for other options.
For now only the case of anticipate=true
works. Shock decomp with unanticipated shocks is coming soon.
StateSpaceEcon.StackedTimeSolver.sim_nr!
— Functionsim_nr!(x, sd, maxiter, tol, verbose [, linesearch])
Solve the simulation problem.
x
- the array of data for the simulation. All initial, final and exogenous conditions are already in place.sd::AbstractSolverData
- the solver data constructed for the simulation problem.maxiter
- maximum number of iterations.tol
- desired accuracy.verbose
- whether or not to print progress information.linesearch::Bool
- Whentrue
the Newton-Raphson is modified to include a search along the descent direction for a sufficient decrease in f. It will do this at each iteration. Default isfalse
.
StateSpaceEcon.StackedTimeSolver.stackedtime_R!
— Methodstackedtime_R!(R::Vector, point::Array, exog::Array, sd::StackedTimeSolverData)
Compute the residual of the stacked time system at the given point
. R is updated in place and returned.
StateSpaceEcon.StackedTimeSolver.stackedtime_RJ
— MethodR, J = stackedtime_RJ(point::Array, exog::Array, sd::StackedTimeSolverData)
Compute the residual and Jacobian of the stacked time system at the given point
.
StateSpaceEcon.StackedTimeSolver.update_plan!
— Methodupdate_plan!(sd::StackedTimeSolverData, model, plan; changed=false)
Update the stacked time solver data to reflect the new plan. The new plan must have the same range as the original plan, otherwise the solver data cannot be updated in place.
By default the data structure is updated only if an actual change in the plan is detected. Setting the changed
flag to true
forces the update even if the plan seems unchanged. This is necessary only in rare circumstances.
Internal function not part of the public interface.
StateSpaceEcon.StackedTimeSolver.var_CiSc
— Functionvar_CiSc(sd::StackedTimeSolverData, var::ModelVariable, fc::FinalCondition)
Return data related to the correction of the Jacobian matrix needed for the given final condition for the given variable.
Internal function not part of the public interface.
Plans
StateSpaceEcon.Plans.setplanvalue!
— Methodsetplanvalue!(plan, value, vars, range)
setplanvalue!(plan, value, vars, date)
setplanvalue!(plan, value, vars, dates)
Modify the status of the given variable(s) on the given date(s). If value
is true
then variables become exogenous, otherwise they become endogenous.