API Reference
Model Construction & Types
Dynspec.Types.AbstractModelBlock — Type
AbstractModelBlockAbstract interface for a model block. Any AbstractModelBlock has an associated context and can evaluate residuals and derivatives.
Dynspec.Types.ModelBlock — Type
ModelBlock(context, equations; metadata=Dict{Symbol, Any}(), filename="", source="", tree=nothing)A block of equations associated with a model evaluation context and preserving the parsed AST tree.
Dynspec.Types.Equation — Type
Equation(residual, raw, metadata, complementarity, tree=nothing)A model equation with its residual expression, source string, metadata, optional complementarity, and optional parsed AST node.
Dynspec.Types.Context — Type
ContextModel context holding parameters, steady states, processes, time-dated values, and metadata as dictionaries.
Dynspec.Types.Normal — Type
NormalGaussian distribution with mean vector Μ and covariance matrix Σ.
Dynspec.Types.TimedVar — Type
TimedVar(name, shift)A variable with a time shift, e.g. x[t] (shift 0), x[t-1] (shift -1), or x[~] (shift :~).
Dynspec.Types.Complementarity — Type
Complementarity(variable, lb, ub)Complementarity condition residual ⟂ lb <= variable <= ub.
Dynspec.Types.equations — Function
equations(b::AbstractModelBlock) -> Vector{Equation}Return the list of equations in b.
Model Ingestion
Dynspec.parse_model — Function
parse_model(text::AbstractString; filename::AbstractString="<string>") -> ModelBlockParse a DynSpec model from a string, interpreting assignments and equations.
Dynspec.read_model — Function
read_model(filename::AbstractString) -> ModelBlockRead and interpret a DynSpec model file (.dyno).
Analysis & Evaluation
Dynspec.Analysis.list_variables — Function
list_variables(block::AbstractModelBlock; shifts::Bool=false) -> Vector{Symbol} or Dict{Symbol, Set{Int}}
list_variables(eq::Equation; shifts::Bool=false)List all variables occurring in equations.
shifts=false(default): returns a sortedVector{Symbol}of variable names.shifts=true: returnsDict{Symbol, Set{Int}}mapping variables to time shifts.
Dynspec.Analysis.list_constants — Function
list_constants(block::AbstractModelBlock) -> Vector{Symbol}List all constant/parameter names defined in the block's context, sorted alphabetically.
Dynspec.Analysis.residuals — Function
residuals(block::AbstractModelBlock; filter_by=nothing, at=nothing) -> Vector{Float64}Compute equation residuals directly on the parsed AST equations.
filter_by: filter equations by tag (:transition), tags ([:transition, :arbitrage]), or predicate.at: overrides for variables (e.g.(:z, 0) => 0.1or:z => 0.1) or constants (:α => 0.36).
Dynspec.Analysis.jacobian — Function
jacobian(block::AbstractModelBlock; wrt, filter_by=nothing, at=nothing)Compute analytical Jacobian(s) with respect to wrt. If wrt is a flat vector of targets, returns a single Matrix{Float64}. If wrt is grouped (vector of vectors), returns a Tuple of Matrix{Float64}.
Dynspec.Analysis.residuals_and_jacobian — Function
residuals_and_jacobian(block::AbstractModelBlock; wrt, filter_by=nothing, at=nothing)Simultaneously evaluate equation residuals (order 0) and analytical Jacobian(s) (order 1) with respect to wrt.
- Bare symbols (
:α,:β) represent constants/parameters. - Tuples (
(:z, 0),(:k, -1)) orTimedVars represent variables with time shifts. - If
wrtis grouped (e.g.[ [(:z,0), (:x,0)], [(:z,1), (:x,1)] ]), returns(residuals, (J1, J2, ...)).
Dynspec.Analysis.taylor — Function
taylor(block::AbstractModelBlock; wrt, filter_by=nothing, at=nothing, order::Int=1)Compute local Taylor expansion terms of the model equations around the steady state (or at).
order=1(default): returns(residuals, J)or(residuals, (J1, J2, ...))for groupedwrt.
Dynspec.Analysis.filter_equations — Function
filter_equations(block::AbstractModelBlock, tag::Union{Symbol, String}) -> Vector{Equation}Filter equations belonging to a specific tag (e.g. :transition, :arbitrage).
Dyno Submodule (DSGE Perturbation)
Dynspec.Dyno — Module
DynoSubmodule containing DSGE perturbation matrix extractors and model helpers.
Dynspec.Dyno.first_order_model — Function
first_order_model(block::AbstractModelBlock; filter_by=nothing, endogenous=nothing, exogenous=nothing, at=nothing)Construct a first-order DSGE model representation as a NamedTuple:
symbols: NamedTuple of variable and parameter groups:endogenous: ordered list of endogenous variable symbolsexogenous: ordered list of exogenous shock symbolsconstants: ordered list of constant / parameter symbols
residuals: residual vector evaluated at steady state (orat)jacobians: NamedTuple of first-order Jacobians:A: ∂f / ∂y_{t+1} (lead)B: ∂f / ∂y_t (current)C: ∂f / ∂y_{t-1} (lag)D: ∂f / ∂e_t (shocks)
Dynspec.Dyno.endogenous_exogenous — Function
endogenous_exogenous(block::AbstractModelBlock; endogenous=nothing, exogenous=nothing)
-> (endogenous = Vector{Symbol}, exogenous = Vector{Symbol})Extract the ordered lists of endogenous and exogenous variables from block. If not explicitly provided, exogenous variables are inferred from declared processes and endogenous variables from steady states and equation variable occurrences.
Dynspec.Dyno.compute_dsge_jacobians — Function
compute_dsge_jacobians(block::AbstractModelBlock; filter_by=nothing, endogenous=nothing, exogenous=nothing, at=nothing)
-> (residuals, A, B, C, D)[TEMPORARY / CONVENIENCE HELPER] Evaluate residuals and compute standard first-order perturbation matrices for DSGE solvers:
A= ∂f / ∂y_{t+1}B= ∂f / ∂y_tC= ∂f / ∂y_{t-1}D= ∂f / ∂e_t
Dynspec.Dyno.solve_dsge — Function
solve_dsge(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix, D::AbstractMatrix; max_iter::Int=50, tol::Float64=1e-11) -> (P, Q)Solve the first-order linear DSGE system: A * Et[y{t+1}] + B * yt + C * y{t-1} + D * et = 0 using cyclic reduction to find the stable recursive law of motion matrices P and Q: yt = P * y{t-1} + Q * et
solve_dsge(model::NamedTuple; max_iter::Int=50, tol::Float64=1e-11)Solve a first-order DSGE model (as returned by first_order_model(block)) for the recursive decision rules: yt = P * y{t-1} + Q * e_t
solve_dsge(block::AbstractModelBlock; filter_by=nothing, endogenous=nothing, exogenous=nothing, at=nothing, max_iter::Int=50, tol::Float64=1e-11)Compute first-order perturbation matrices and solve for the recursive decision rules P and Q (y_t = P * y_{t-1} + Q * e_t).
Dynspec.Dyno.simulate_linear — Function
simulate_linear(P, Q; T=40, shocks=nothing, shock_idx=1, shock_size=1.0) -> Matrix{Float64}Simulate the linear system y_t = P * y_{t-1} + Q * e_t for T periods. If shocks is omitted, computes the Impulse Response Function (IRF) to a one-time shock of shock_size on shock shock_idx at t=1. If shocks is an n_shocks × T matrix, simulates under that shock sequence.
Dynspec.Dyno.compile_dynamic — Function
compile_dynamic(block::ModelBlock; endogenous=nothing, exogenous=nothing) -> DynamicModelCompile a model block into a DynamicModel with resolved endogenous and exogenous variable orderings.