API Reference

Model Construction & Types

Dynspec.Types.AbstractModelBlock — Type
AbstractModelBlock

Abstract interface for a model block. Any AbstractModelBlock has an associated context and can evaluate residuals and derivatives.

source
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.

source
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.

source
Dynspec.Types.Context — Type
Context

Model context holding parameters, steady states, processes, time-dated values, and metadata as dictionaries.

source
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 :~).

source

Model Ingestion

Dynspec.parse_model — Function
parse_model(text::AbstractString; filename::AbstractString="<string>") -> ModelBlock

Parse a DynSpec model from a string, interpreting assignments and equations.

source
Dynspec.read_model — Function
read_model(filename::AbstractString) -> ModelBlock

Read and interpret a DynSpec model file (.dyno).

source

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 sorted Vector{Symbol} of variable names.
  • shifts=true: returns Dict{Symbol, Set{Int}} mapping variables to time shifts.
source
Dynspec.Analysis.list_constants — Function
list_constants(block::AbstractModelBlock) -> Vector{Symbol}

List all constant/parameter names defined in the block's context, sorted alphabetically.

source
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.1 or :z => 0.1) or constants (:α => 0.36).
source
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}.

source
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)) or TimedVars represent variables with time shifts.
  • If wrt is grouped (e.g. [ [(:z,0), (:x,0)], [(:z,1), (:x,1)] ]), returns (residuals, (J1, J2, ...)).
source
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 grouped wrt.
source
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).

source

Dyno Submodule (DSGE Perturbation)

Dynspec.Dyno — Module
Dyno

Submodule containing DSGE perturbation matrix extractors and model helpers.

source
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 symbols
    • exogenous: ordered list of exogenous shock symbols
    • constants: ordered list of constant / parameter symbols
  • residuals: residual vector evaluated at steady state (or at)
  • 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)
source
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.

source
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_t
  • C = ∂f / ∂y_{t-1}
  • D = ∂f / ∂e_t
source
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

source
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

source
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).

source
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.

source
Dynspec.Dyno.compile_dynamic — Function
compile_dynamic(block::ModelBlock; endogenous=nothing, exogenous=nothing) -> DynamicModel

Compile a model block into a DynamicModel with resolved endogenous and exogenous variable orderings.

source