5. Modern architecture

The modern branch of RISE is a ground-up redesign whose distinctives are architectural, not cosmetic. The chapter is in two parts:

  • Part A – what is the same for every model shape (one engine class, one state space, one set of engines, one validation style).

  • Part B – what each shape contributes on top: the inputs the factory needs and the behaviors that are intrinsic to that shape.

If you only have time for one part, read Part A – it is what makes the toolbox a toolbox rather than a collection of look-alike libraries. Part B is the per-shape contract you sign at construction time: the factory and the few methods that only one shape has.

5.1. Part A. Common across all shapes

5.1.1. One engine class

The legacy toolbox shipped multiple user-facing classes for the same underlying mathematics – @dsge, @rise, @rfvar, @svar, @prfvar, @proxy_svar, @bvar_dsge, plus shared backbones in @generic and @estimable. Each class carried its own methods, sometimes with subtle behavior drift between siblings.

The modern toolbox has one engine class, rise.engine.models.rise_model. Each shape’s factory – dsge_model, rfvar_model, svar_model, proxy_svar_model, prfvar_model, dsge_var_model – is a thin subclass of it, whose constructor turns the shape’s inputs into the common model data. A DSGE, a reduced-form VAR, a structural VAR with sign restrictions, a proxy SVAR, a DSGE-VAR and a panel VAR are therefore all rise_model objects with different shape data attached. Solving, estimating, filtering and forecasting are methods of rise_model, with a single body each for all shapes; what a shape needs beyond them enters through its data, including routines the factory registers at construction (the solve and the VAR-prior evaluator of a structural VAR, the solve and the likelihood of a DSGE-VAR). The subclasses add few methods of their own: dsge_model carries those that only make sense for a DSGE (optimal simple rules, perfect foresight, stoch_simul, accuracy checks, …), the structural VARs print_structural_form.

What this buys you:

  • A single, predictable API surface.

  • Cross-shape composition without translator code (a DSGE prior on a VAR is two field assignments, not a sibling class).

  • The same maintenance fix lands once and benefits every shape.

What this costs:

  • The model object is more polymorphic, so understanding its fields takes one more page of reading on day one.

5.1.2. Unified state-space

Every engine sees the model through a single state-space representation. Constant-parameter and regime-switching DSGEs, reduced-form and structural VARs and the other shapes are all solved into it, and the filters, simulators and forecasters work on it whatever the shape – the state space is the canonical description. Faster routes exist for special cases – the fast estimation kernel of a first-order DSGE, the closed-form mode of a conjugate VAR, the likelihood of fully observed data – and are chosen from properties of the model and the data; they agree with the general route.

5.1.3. Always regime-switching

A consequence of the unified state-space: every model is treated as Markov-switching from the start. h = 1 is the trivial non-switching case; h > 1 is a switching model. The solver, the filters and the estimator are written for h regimes, and a single regime goes through the same code; where one regime allows a shortcut (in some filter steps, for instance), the shortcut sits inside that code, not in a separate constant-parameter implementation. This eliminates a whole class of bugs where the constant-parameter and switching paths drifted apart.

5.1.4. No construction metadata after build

The legacy toolbox stashed user-supplied, class-specific metadata inside the model object after construction – flags, hints, and overrides that the engines later branched on.

The modern toolbox does not. Once a model is parsed and built, the canonical fields are all the engines look at; there is no “construction-time hint” carried through to runtime. Parsers populate canonical names; engines read canonical names. A model object is a value describing a state-space, not a record of the path the user took to reach it.

5.1.5. Estimate dispatches on properties, not class

In the legacy toolbox, estimate knew which class of model it was working with and branched accordingly.

In the modern toolbox, the estimator dispatches on properties of the data and the model, not on the class:

  • If the data has missing observations or unobserved states, the estimator runs a Kalman filter (or the regime-conditional Kalman filter, if h > 1).

  • If the data are complete and the model admits a closed-form posterior moment (notably a DSGE-VAR with a conjugate prior), the estimator short-circuits to the closed form.

  • For nonlinear models the estimator runs the appropriate nonlinear filter.

The estimator does not switch on the class name. The few steps that belong to one shape – the closed-form mode of a conjugate VAR, the complete-data requirement of a DSGE-VAR, the panel estimators – read the shape flags of the model data (is.rfvar, is.dsge_var, …) or the routines the factory registered. User code that constructs a model from a new shape gets the estimation behavior that follows from its properties, without touching estimator internals.

5.1.6. OOP only at the user boundary

Object-oriented MATLAB is used where it pays for itself: the user constructs a model with the appropriate factory, calls methods on it, and gets a typed return. Inside the engines, the code is plain MATLAB – structs, arrays, function handles. The boundary between OO and procedural is the user-facing method.

This means the engines are easy to read, easy to step through with the MATLAB debugger, and easy to vectorize. It also means the performance-sensitive code paths are not paying the OOP dispatch tax on every inner-loop call.

5.1.7. Arguments blocks at the user boundary

The factories and the user-facing methods declare an arguments ... end block, and their name-value options are the properties of the option classes in rise.options (rise_options and the per-shape classes), which carry default values, sizes, classes and validators in one place. Concretely, irf starts with:

function [myirfs,retcode]=irf(obj,nvp)

arguments

    obj rise.engine.models.rise_model

    nvp.?rise.options.rise_options

end

and rise.options.rise_options declares, among others:

irf_periods (1,1) double {mustBeInteger,mustBePositive} = 40

irf_regime_specific (1,1) logical = true

The block is the contract. An unknown option name or an invalid value is refused at the call, in MATLAB’s standard validator messages, not deep inside the implementation.

Behind that boundary, the numerical kernels – Lyapunov solvers, derivative and filtering steps, many package helpers – receive inputs that are already checked and do not all declare an arguments block; some older ones still set defaults from nargin. Extending the blocks to them is work in progress, not a property of the current code.

5.1.8. Stay close to plain MATLAB

Wherever a modern MATLAB built-in does the job, the modern branch uses the built-in. dictionary and configureDictionary replace containers.Map. datetime and calmonths replace custom date arithmetic. isMATLABReleaseOlderThan replaces verLessThan. Old custom utilities – fix_point_* option names, custom date types, hand-rolled validators – are being retired.

5.1.9. No internal switching syntax

In the legacy toolbox, certain solve-time choices were exposed via @-style markers in the model file – e.g. an @commitment parameter declared alongside the other parameters but meaning something special to the solver. In the modern toolbox these solve-time choices are options on the solve call, not parameters in the model file. The model file describes the model; the solve call describes how to solve it.

Concretely, commitment vs discretion is selected via:

m = solve(m, solve_policy_type = "discretion");

There is no @commitment parameter to declare, calibrate, or forget to set.

5.1.10. The common engine surface

Once the model is built, every shape sees the same surface of methods. The list below is exhaustive for the common engines – anything not on it is shape-specific (Part B).

Engine

Modern method(s)

Build

set, get, solve

Steady state / BGP

solve (with sstate_file), print_steady_state

Filtering

filter (Kalman / regime-conditional / nonlinear, picked by data + model properties)

Estimation

estimate, pull_objective, log_prior_density, log_posterior_kernel

Posterior simulation

the classes rwmh, imh, apt, slice and usrsmplr of rise.engine.estimation.rsamplers, + sample

Diagnostics

mcmc (constructed from draws), mdd

Forecast / IRF / decomposition

forecast, irf, variance_decomposition, historical_decomposition, simulate

Reporting / plotting

rnotes (and the rprt thin subclass), fanchart / plot_fanchart, quick_irfs, quick_plots, plot_probabilities, plot_decomp

5.2. Part B. What each shape contributes

Each shape is constructed by its own factory, a subclass of rise_model. The factory is where shape-specific knowledge enters the system; the entries in the table above work the same on every shape. The methods that only one shape has are listed with it below.

5.2.1. DSGE – dsge_model

Constructed from a model file (*.rs / *.rsa / *.dsge):

m = dsge_model('nk.rs');

Specific to this shape:

  • Model file language (Model file language) – @endogenous, @exogenous, @parameters, @model; Markov-switching parameters via @parameters(chain, N) name and the implicit chain_tp_i_j transition probabilities; @endogenous(log) for log-level variables.

  • Steady state / BGP (Zero-th order approximation: steady state and balanced-growth path) – the recommended pattern is a separate sstate_file (regime-agnostic, returns newp.<bare_name> for parameters implied by SS conditions). The @steady_state_model block inside the model file is also supported.

  • Optimal policy (Optimal policy) – declared in the model file via @optimization_problem (single or multi-player); commitment vs. discretion vs. loose commitment vs. stochastic replanning is selected at solve time, not in the model file.

  • Optimized simple rules (Optimal (optimized) simple rules) – the OSR objective is always a runtime argument to optimal_simple_rule; it is not declared in the model file.

  • Perturbation order – solve_order = 1..5; the engines share one code path across orders.

  • Occasionally-binding constraints, time-varying transition probabilities and deterministic / quasi-deterministic solutions all live here as well; see the matching chapters under the DSGE shape.

5.2.2. Reduced-form VAR – rfvar_model

mdl = rfvar_model(endog, ...
    lag_length         = 4, ...
    constant_term      = true, ...
    deterministic_vars = {});

Specific to this shape:

  • Lag length and deterministics – lag_length, constant_term, deterministic_vars.

  • Priors – VAR-coefficient priors are built by the functions of the package rise.engine.var.var_priors: minnesota, niw (normal-inverse-Wishart), inw (independent normal-Wishart), generate_sims_zha_prior (Sims-Zha dummy observations), each called as rise.engine.var.var_priors.minnesota(endog,constant_term,deterministic_vars,lag_length,data,...) and scaled by the data; user_defined, the same without the data; and, for a structural VAR, generate_structural_prior. The prior is passed through the option estim_var_prior.

  • Linear restrictions on the coefficients – estim_linear_restrictions accepts strings on the expanded names b<lag>(<row>, <col>) and c(<row>, <col>).

  • Closed-form mode – with constant parameters, complete data and a conjugate prior (minnesota, niw, inw, generate_sims_zha_prior), estimate finds the posterior mode in closed form, or by alternating two closed forms, instead of searching; without such a prior it searches numerically.

See Reduced-form VAR Modeling.

5.2.3. Structural VAR – svar_model

mdl = svar_model(endog, ...
    lag_length    = 4, ...
    constant_term = true);

Specific to this shape:

  • Identification at the model level – a structural VAR is identified at construction by zero / linear / sign / nonlinear restrictions on the structural-form coefficients (a0 / a1 / …), wired through the estim_* options.

  • Structural shocks – structural_shocks, print_structural_form.

  • The implication: there is no separate “identify a reduced-form VAR after the fact” step. Reduced-form VARs that need identification at IRF time still use the identification call from Reduced-form VAR Modeling; an SVAR has already paid that cost at the model level.

See Structural VAR Modeling.

5.2.4. Proxy SVAR – proxy_svar_model

prox=struct('proxy_var','mp_surprise','shock_var','R');

mdl=proxy_svar_model(prox,endog,...
    lag_length=4,...
    constant_term=true);

Specific to this shape:

  • Proxies struct – one element per instrument, with fields proxy_var (the instrument: an observed series, here mp_surprise, that is not in endog) and shock_var (the variable of endog, here R, whose structural shock the proxy instruments).

  • Relevance + noise parameters – each proxy adds the equation mp_surprise = beta_mp_surprise*epsilon<k> + sigma_mp_surprise*epsilon_mp_surprise, with epsilon<k> the structural shock of shock_var (k its position in endog). The relevance \(\beta_m\) (beta_<proxy_var>) and the noise scale \(\sigma_m\) (sigma_<proxy_var>) are estimated alongside the VAR coefficients and can be made regime-dependent.

See Proxy (instrumental) SVAR Modeling.

5.2.5. Panel VAR – prfvar_model

mdl = prfvar_model({'US','CA','MX','BR'}, endog, ...
    lag_length            = 4, ...
    constant_term         = true, ...
    estim_panel_estimator = 'dynamic_homogeneity');

Specific to this shape:

  • Units – the first argument lists the cross-sectional units (at least two).

  • Stacked names – the model is a reduced-form VAR on the variables <unit>_<var> (US_GROWTH, CA_GROWTH, …): the database, the parameters, the restrictions, the shocks and the outputs all use these names.

  • Panel estimator – estim_panel_estimator (‘unrestricted’, ‘independent’, ‘pooled’, ‘fixed_effects’, ‘dynamic_homogeneity’, ‘static_homogeneity’, ‘mean_group’) links the units’ coefficients through linear restrictions, imposed by the estimation, bootstrap and sample_posterior and in every regime.

See Panel VAR Modeling.

5.2.6. DSGE-VAR – dsge_var_model

mdl=dsge_var_model(dsge_model_obj,lag_length=4);

mdl=set(mdl,parameters={'dsge_prior_weight',1});

Specific to this shape:

  • DSGE backbone – the prior on the reduced-form VAR is the DSGE-implied prior; the DSGE-shaped rise_model is the first argument to the factory.

  • Weight of the DSGE prior – a parameter of the model, not a constructor option: set or estimate either dsge_prior_weight, \(\lambda\), the number of artificial DSGE observations per actual observation, or dsge_prior_share, \(\gamma = \lambda/(1+\lambda) \in [0,1]\), never both. \(\lambda = \infty\) (\(\gamma = 1\)) recovers the DSGE’s VAR approximation, \(\lambda = 0\) the unrestricted VAR.

  • No-holes assumption – the closed-form posterior moments require complete sample moments; dsge_var is the one shape for which the estimator requires no missing observations.

See DSGE-VAR Modeling.

5.3. Summary

Part A is the bargain: one engine class, one state space, one set of engines, one validation style at the user boundary, one set of solve-time options. Part B is where the shape of your model matters – the factory you call, the options it accepts and the few methods only that shape has.

Everything that used to require knowing which sibling class you were working with now requires knowing only which shape of model you are working with – and the engines handle the rest.