# gustavohm/dsgelab architecture

> Architecture diagram of the GitHub repository gustavohm/dsgelab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gustavohm/dsgelab
- Repository: https://github.com/gustavohm/dsgelab

## Overview

dsgelab is a Python toolkit for declaring DSGE models once and solving, simulating, estimating, and analyzing them. The main workflow is model declaration → steady state → first-order solution → simulation, impulse responses, and moments; the same model also supports higher-order perturbation and deterministic transitions. Separate branches provide global and heterogeneous-agent methods, regime switching, policy optimization, and statistical estimation. The graph includes README-documented capabilities whose implementation was not sampled; edges are limited to documented workflows or references visible in the source index, so unsampled internals are not asserted.

Main entry points: [`src/dsgelab/model.py`](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/model.py) (Model declaration), [`src/dsgelab/solve.py`](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solve.py) (First-order solve), [`src/dsgelab/solution.py`](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solution.py) (Solution analysis), [`src/dsgelab/estimation.py`](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/estimation.py) (Bayesian estimation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_modeling["Model and solutions"]
  node_model["Model declaration<br/>[model.py]"]
  node_steady["Steady state<br/>[steady.py]"]
  node_linearize["Linearization<br/>[linearize.py]"]
  node_klein["Klein solver<br/>[klein.py]"]
  node_solve["First-order solve<br/>[solve.py]"]
  node_solution["Solution analysis<br/>[solution.py]"]
  node_second["Second-order<br/>[secondorder.py]"]
  node_third["Third-order<br/>[thirdorder.py]"]
  node_tensors["Derivative tensors<br/>[tensors.py]"]
  node_symbolic["Text equations<br/>[symbolic.py]"]
end

subgraph group_global["Global and transitions"]
  node_projection["Global projection<br/>[projection.py]"]
  node_timeiter["Time iteration<br/>[time_iteration.py]"]
  node_valueiter["Value iteration<br/>[value_iteration.py]"]
  node_egm["Endogenous grid<br/>[egm.py]"]
  node_foresight["Perfect foresight<br/>[foresight.py]"]
  node_extended["Extended path<br/>[extended_path.py]"]
end

subgraph group_agents["Agents and regimes"]
  node_heterogeneous["Heterogeneous agents<br/>[heterogeneous.py]"]
  node_switching["Regime switching<br/>[switching.py]"]
end

subgraph group_inference["Inference and analysis"]
  node_bvar["BVAR and DSGE-VAR<br/>[bvar.py]"]
  node_kalman["State-space filters<br/>[kalman.py]"]
  node_estimation["Bayesian estimation<br/>[estimation.py]"]
  node_moments["Moment estimation"]
  node_identification["Identification<br/>[identification.py]"]
  node_particle["Particle filters<br/>[particle.py]"]
  node_kim["Kim filter<br/>[kim.py]"]
  node_plots["Plots<br/>[plots.py]"]
end

subgraph group_policy["Policy and interoperability"]
  node_policy["Optimal policy<br/>[optimal.py]"]
  node_dynare["Dynare import<br/>[dynare.py]"]
end

node_user(("Modeler"))
node_user_result(("Results consumer"))

node_user -->|"declares"| node_model
node_model -->|"solves steady state"| node_steady
node_model -->|"solves model"| node_solve
node_steady -->|"anchors solution"| node_solve
node_solve -.->|"uses solver"| node_klein
node_solve -->|"returns solution"| node_solution
node_model -->|"linearizes equations"| node_linearize
node_linearize -->|"computes derivatives"| node_tensors
node_solution -->|"provides responses"| node_user_result
node_model -->|"solves second order"| node_second
node_model -->|"solves third order"| node_third
node_user -->|"declares equations"| node_symbolic
node_model -->|"solves globally"| node_projection
node_model -->|"iterates policies"| node_timeiter
node_model -->|"optimizes value"| node_valueiter
node_model -->|"solves by EGM"| node_egm
node_model -->|"computes transitions"| node_foresight
node_model -->|"computes expectations paths"| node_extended
node_foresight -->|"uses model"| node_model
node_extended -->|"uses transitions"| node_foresight
node_model -->|"solves agent blocks"| node_heterogeneous
node_model -->|"solves switching model"| node_switching
node_model -->|"builds state space"| node_kalman
node_kalman -->|"supplies likelihood"| node_estimation
node_estimation -->|"uses DSGE-VAR"| node_bvar
node_estimation -->|"uses particle filter"| node_particle
node_model -->|"fits moments"| node_moments
node_model -->|"checks identification"| node_identification
node_switching -->|"filters regimes"| node_kim
node_solution -.->|"plots results"| node_plots
node_model -->|"optimizes policy"| node_policy
node_user -->|"imports model"| node_dynare
node_dynare -->|"creates declaration"| node_model

click node_model "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/model.py"
click node_steady "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/steady.py"
click node_linearize "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/linearize.py"
click node_klein "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/klein.py"
click node_solve "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solve.py"
click node_solution "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solution.py"
click node_second "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/secondorder.py"
click node_third "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/thirdorder.py"
click node_tensors "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/tensors.py"
click node_symbolic "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/symbolic.py"
click node_projection "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/projection.py"
click node_timeiter "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/time_iteration.py"
click node_valueiter "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/value_iteration.py"
click node_egm "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/egm.py"
click node_foresight "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/foresight.py"
click node_extended "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/extended_path.py"
click node_heterogeneous "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/heterogeneous.py"
click node_switching "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/switching.py"
click node_bvar "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/bvar.py"
click node_kalman "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/kalman.py"
click node_estimation "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/estimation.py"
click node_moments "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/moment_estimation.py"
click node_identification "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/identification.py"
click node_particle "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/particle.py"
click node_kim "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/kim.py"
click node_plots "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/plots.py"
click node_policy "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/optimal.py"
click node_dynare "https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/dynare.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_model,node_steady,node_linearize,node_klein,node_solve,node_solution,node_second,node_third,node_tensors,node_symbolic toneBlue
class node_projection,node_timeiter,node_valueiter,node_egm,node_foresight,node_extended toneAmber
class node_heterogeneous,node_switching toneMint
class node_bvar,node_kalman,node_estimation,node_moments,node_identification,node_particle,node_kim,node_plots toneRose
class node_policy,node_dynare,node_user,node_user_result toneIndigo
```

## Components

### Model and solutions

- [Model declaration](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/model.py): `src/dsgelab/model.py`
- [Steady state](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/steady.py): `src/dsgelab/steady.py`
- [Linearization](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/linearize.py): `src/dsgelab/linearize.py`
- [Klein solver](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/klein.py): `src/dsgelab/klein.py`
- [First-order solve](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solve.py): `src/dsgelab/solve.py`
- [Solution analysis](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/solution.py): `src/dsgelab/solution.py`
- [Second-order](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/secondorder.py): `src/dsgelab/secondorder.py`
- [Third-order](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/thirdorder.py): `src/dsgelab/thirdorder.py`
- [Derivative tensors](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/tensors.py): `src/dsgelab/tensors.py`
- [Text equations](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/symbolic.py): `src/dsgelab/symbolic.py`

### Global and transitions

- [Global projection](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/projection.py): `src/dsgelab/projection.py`
- [Time iteration](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/time_iteration.py): `src/dsgelab/time_iteration.py`
- [Value iteration](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/value_iteration.py): `src/dsgelab/value_iteration.py`
- [Endogenous grid](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/egm.py): `src/dsgelab/egm.py`
- [Perfect foresight](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/foresight.py): `src/dsgelab/foresight.py`
- [Extended path](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/extended_path.py): `src/dsgelab/extended_path.py`

### Agents and regimes

- [Heterogeneous agents](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/heterogeneous.py): `src/dsgelab/heterogeneous.py`
- [Regime switching](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/switching.py): `src/dsgelab/switching.py`

### Inference and analysis

- [BVAR and DSGE-VAR](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/bvar.py): `src/dsgelab/bvar.py`
- [State-space filters](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/kalman.py): `src/dsgelab/kalman.py`
- [Bayesian estimation](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/estimation.py): `src/dsgelab/estimation.py`
- [Moment estimation](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/moment_estimation.py): `src/dsgelab/moment_estimation.py`
- [Identification](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/identification.py): `src/dsgelab/identification.py`
- [Particle filters](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/particle.py): `src/dsgelab/particle.py`
- [Kim filter](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/kim.py): `src/dsgelab/kim.py`
- [Plots](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/plots.py): `src/dsgelab/plots.py`

### Policy and interoperability

- [Optimal policy](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/optimal.py): `src/dsgelab/optimal.py`
- [Dynare import](https://github.com/gustavohm/dsgelab/blob/main/src/dsgelab/dynare.py): `src/dsgelab/dynare.py`

### Other components

- **Modeler**
- **Results consumer**

## Connections

- Modeler → Model declaration: declares (evidence: `README.md`)
- Model declaration → Steady state: solves steady state (evidence: `README.md`)
- Model declaration → First-order solve: solves model (evidence: `README.md`)
- Steady state → First-order solve: anchors solution (evidence: `README.md`)
- First-order solve → Klein solver: uses solver
- First-order solve → Solution analysis: returns solution (evidence: `README.md`)
- Model declaration → Linearization: linearizes equations (evidence: `src/dsgelab/linearize.py`)
- Linearization → Derivative tensors: computes derivatives (evidence: `src/dsgelab/linearize.py`)
- Solution analysis → Results consumer: provides responses (evidence: `README.md`)
- Model declaration → Second-order: solves second order (evidence: `README.md`)
- Model declaration → Third-order: solves third order (evidence: `README.md`)
- Modeler → Text equations: declares equations (evidence: `README.md`)
- Model declaration → Global projection: solves globally (evidence: `README.md`)
- Model declaration → Time iteration: iterates policies (evidence: `README.md`)
- Model declaration → Value iteration: optimizes value (evidence: `README.md`)
- Model declaration → Endogenous grid: solves by EGM (evidence: `README.md`)
- Model declaration → Perfect foresight: computes transitions (evidence: `README.md`)
- Model declaration → Extended path: computes expectations paths (evidence: `README.md`)
- Perfect foresight → Model declaration: uses model (evidence: `src/dsgelab/foresight.py`)
- Extended path → Perfect foresight: uses transitions (evidence: `src/dsgelab/extended_path.py`)
- Model declaration → Heterogeneous agents: solves agent blocks (evidence: `README.md`)
- Model declaration → Regime switching: solves switching model (evidence: `README.md`)
- Model declaration → State-space filters: builds state space (evidence: `src/dsgelab/kalman.py`)
- State-space filters → Bayesian estimation: supplies likelihood (evidence: `src/dsgelab/estimation.py`)
- Bayesian estimation → BVAR and DSGE-VAR: uses DSGE-VAR (evidence: `src/dsgelab/estimation.py`)
- Bayesian estimation → Particle filters: uses particle filter (evidence: `src/dsgelab/estimation.py`)
- Model declaration → Moment estimation: fits moments (evidence: `README.md`)
- Model declaration → Identification: checks identification (evidence: `README.md`)
- Regime switching → Kim filter: filters regimes (evidence: `README.md`)
- Solution analysis → Plots: plots results
- Model declaration → Optimal policy: optimizes policy (evidence: `README.md`)
- Modeler → Dynare import: imports model (evidence: `README.md`)
- Dynare import → Model declaration: creates declaration (evidence: `src/dsgelab/dynare.py`)
