Converts state-space equations (image, PDF, LaTeX, or text) into a MATLAB Econometrics Toolbox ssm object. Use NaN-form scripts or parameter-mapping functions for linear Gaussian models.
Ships in computational-finance. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Convert structural state-space equations into a MATLAB Econometrics Toolbox ssm object. Use the ssm class only; do not use other state-space classes. "Diffuse" always means ssm StateType 2.
ssm object.ss models.idss, ssest, n4sid) from input-output or measurement data — use matlab-identify-linear-system.hmmtrain, hmmviterbi).Images and PDFs may be typeset or handwritten; text may be LaTeX, semi-formal or plain math.
Use a NaN-form script whenever it can express the model (it can be pasted into the Command Window; a parameter-mapping function must first be saved in a file). Otherwise use a parameter-mapping function (ParamMap), which can express any model.
NaN-form applies when every unknown scalar parameter appears in exactly one entry of A, B, C, D, Mean0, Cov0 and equals that entry (a NaN means "estimate this entry"). A variance or a covariance matrix still qualifies through Rule 1 or Rule 7.
| Model feature | Form |
|---|---|
| Variance $\sigma^2$ of a disturbance that no other entry uses | NaN-form; the NaN estimates $\sigma$ (Rule 1) |
| Intercept | NaN-form; NaN on the constant-1 state (Rule 8) |
Regression term $Z_t\beta$, and the cell array A{t} or C{t} has no unknown entry | NaN-form; $\beta$ as diffuse states (Rule 8) |
| Matrix of known time-varying data, e.g. TVP regression | NaN-form with a cell array (Rule 4) |
Confounded initial state fixed at 0 (Rule 9), or a request that estimate fit all unknowns | Neither forces ParamMap |
| A parameter in two or more entries (sharing), whatever kind of parameter it is: an intercept shared across equations; one AR coefficient for several series; $\sigma$ in an ARMA MA term, where $B = [\sigma;\ \theta_1\sigma]$ puts $\sigma$ in two rows of B | ParamMap |
| An entry that is a function of parameters or a product of two parameters, e.g. a signal-to-noise ratio $q = \sigma_\xi^2/\sigma_\varepsilon^2$ used as a parameter, or $\theta_1\sigma$ | ParamMap |
An unknown entry inside a cell array A{t} or C{t}: ssm counts each NaN in each cell as a separate parameter (T periods give T parameters) | ParamMap (Rule 8) |
Reparameterize only noise scales: a variance to a standard deviation (Rule 1), and a covariance matrix to its lower Cholesky factor (Rule 7). Writing a standard deviation as exp(params(i)) is offered only in the exp() tip; do not use it in the code unless the user asks. Do not reparameterize any other parameter. In particular, never merge two user parameters into one free entry (e.g., estimating $\theta_1\sigma$ instead of $\theta_1$ in an MA term). When a parameter enters a matrix entry multiplied by another parameter, or through a function, use a parameter-mapping function so that every user parameter is estimated directly. Carrying regression coefficients as states (Rule 8) is not a reparameterization.
When you use ParamMap, tell the user why in one sentence.
Identify the observation equations ($y_t = C x_t + D e_t$), the state equations ($x_t = A x_{t-1} + B u_t$, or $x_{t+1} = A x_t + B u_t$), and which noise variances and covariances are known or unknown.
ssm uses $x_t = A x_{t-1} + B u_t$. A model written as $x_{t+1} = A x_t + B u_t$ gives the same filter, likelihood and estimates; only smoothed disturbances shift by one period, so add the timing tip (Step 7) when the user will smooth disturbances.Display the parsed equations in LaTeX so the user can check the interpretation, then continue without waiting for confirmation.
Observed vs. state variables unclear (e.g. the model uses $x$, $f$, $z$, $p$, $c$ rather than $y$). First apply the lag test, then these conventions; ask only if both leave it ambiguous:
Question: "Which variables are observed in your data? (e.g., p, c or y1, y2)"
Vector or matrix form with unknown dimensions (bold symbols, matrix coefficients such as $\Lambda$, $\Phi$, $\Sigma$, $y_{i,t}$ for $i = 1,\ldots,n$ with $n$ unspecified, or $\in \mathbb{R}^n$ with symbolic $n$). If the code can take its dimensions from the data (n = size(Y, 2), p = size(Z, 2)), do so without asking. Ask only when the matrices cannot be built at all (e.g. the number of factors is unspecified): "The equations are in vector/matrix form. What are the concrete dimensions? (e.g., n = 5 observed series, r = 2 factors)"
ssm requires linear Gaussian equations. If an equation is nonlinear in the states, check whether an exact transformation of the data (log, log-squared, ...) makes it linear in the states. If one exists, always use it: transform the data, rewrite the observation equation, and build the ssm from the result. A transformed disturbance that is not Gaussian is approximated by a Gaussian with the same mean and variance, so estimate gives quasi-ML estimates. For stochastic volatility, or any other log-squared transformation, read references/linearization.md for the transformed model and its matrices.
No exact linearizing transformation (e.g. the model can be linearized only by a Taylor expansion around the states): do not generate ssm code. Reply in 2-3 sentences: name the nonlinear term; say that ssm requires linear Gaussian equations, so this model cannot be written as an ssm object; and note that the Econometrics Toolbox's nonlinear state-space class (bnlssm, R2023b or later) handles such models. This is the only place another class may be named.
For standard models (local level, local linear trend, basic structural, ARMA, factor model), references/standard-models.md lists the state vector and matrices.
List the states in a fixed order, $x_t = [x_{1,t}; \ldots; x_{m,t}]$, and document the order as a code comment. Add one shared constant-1 state (StateType 1) where Rule 8 requires it.
$$x_{t} = A , x_{t-1} + B , u_{t}, \quad u_t \sim N(0, I) \qquad y_{t} = C , x_{t} + D , e_{t}, \quad e_t \sim N(0, I)$$
A is m×m, B is m×k, C is n×m, D is n×h (m states, n observed series, k state disturbances, h observation disturbances).
B and D contain standard deviations, not variances. For a std dev $\sigma$, put NaN in the B or D entry. For a variance that no other entry uses (e.g. $\varepsilon_t \sim N(0, \sigma_\varepsilon^2)$), still use NaN: it estimates the std dev, and by MLE invariance its square is the MLE of $\sigma^2$. Add a comment such as % sigma_eps^2 = D(1,1)^2.
sqrt(pi^2/2)).B(i,j) = params(k). Use exp(params(k)) only if the user asks for it; otherwise mention it in the exp() tip. Never sqrt(params(k)): it is complex when the optimizer tries a negative value.Parameter order: ssm maps the parameter vector to NaN entries column by column (column-major). Document this order.
Known coefficients are finite numbers (e.g. a loading fixed at 1). A, B, C, D must not contain Inf. Do not use Inf in Cov0 either; Step 4 says what Cov0 holds. Put missing observations in Y as NaN; never use zero placeholders with D{t} = Inf (a textbook device that ssm rejects: "must be a finite numeric array").
Time-varying matrices: pass a matrix that changes over time as a cell array {C_1, ..., C_T}, one matrix per period. Cell arrays and numeric matrices can be mixed in one call, e.g. ssm(A, B, C_cells, D). Cells keep the same size unless the state or observation dimension changes over time; then A need not be square at a change, so prefer fixed dimensions. Whether to use NaN-form: Choose the Output Form.
No noise → empty matrix, never a zero column: with no observation noise set D = []; with no state noise set B = []. ssm expands these to zeros(n, 0) / zeros(m, 0), so the disturbance does not exist; D = 0 or B = zeros(m, 1) creates a zero-impact disturbance that slows filtering, smoothing and simulation. Never include an all-zero column in B or D.
Multiple observed series: C and D have one row per observed series.
Correlated noise: for a noise covariance $\Omega$ (e.g. a VAR $x_t = A x_{t-1} + v_t$, $v_t \sim N(0, \Omega)$), set B to the lower-triangular Cholesky factor, so $\Omega = BB'$, and estimate its $m(m+1)/2$ free entries. This keeps $\Omega$ positive semidefinite; use chol(Omega, 'lower'), never chol(Omega) (upper-triangular, so $BB' \neq \Omega$). Add the comment % Omega = B * B'. The same applies to D for correlated observation noise.
Intercepts and regression coefficients: if ParamMap is required for another reason, use the fewest states. All intercepts share one constant-1 state (StateType 1), except an observation intercept in ParamMap form, which goes into DeflateY. An intercept multiplies the constant 1, so it is one NaN entry; $Z_t\beta$ multiplies time-varying data, so in NaN-form $\beta$ must become states.
| State equation | Observation equation | |
|---|---|---|
| Intercept c, NaN-form | c = NaN in A on the constant-1 state: $x_t = c + \phi x_{t-1} + u_t$ → states $[x;,1]$, A = [NaN NaN; 0 1], B = [NaN; 0], StateType [0; 1]. The default initialization then starts x at $c/(1-\phi)$ exactly | c = NaN in C, e.g. C = [1 NaN]. A mean $\mu$ in $y_t = \mu + \phi(y_{t-1} - \mu) + \varepsilon_t$ is $y_t = \mu + x_t$, $x_t = \phi x_{t-1} + \varepsilon_t$ |
| Intercept c, ParamMap | same as NaN-form | DeflateY = y - c (with regressors, a column of ones in Z); no extra state |
| Regression $\beta$, NaN-form | $\beta$ as diffuse static states (StateType 2), cell A{t} = [A Z_t; 0 I], zero rows in B; x is StateType 2 too (its initial mean depends on the unknown past Z path) | $\beta$ as diffuse static states, cell C{t} = [C Z_t] |
| Regression $\beta$, ParamMap | one constant-1 state, A{t} = [A Z_t*beta; 0 1] (Z passed as in the DeflateY template), B = [B; 0] (one extra state however many regressors) | DeflateY = y - Z*beta (8th output, Step 5); no extra state |
estimate fits the other parameters, and the filtered or smoothed states at the last period give the $\beta$ estimates (GLS given the fitted variances). So a request that estimate fit all unknowns, $\beta$ included, keeps NaN-form. Use DeflateY only when ParamMap is required for another reason.estimate name-value arguments ('Predictors', 'Beta0'): it works, but it leaves the regression outside the ssm object.Identification:
'Mean0', [0; 0; 1], 'Cov0', zeros(3), 'StateType', [2; 2; 1]; explain why in one sentence. In NaN-form pass Mean0 and Cov0 as ssm name-value arguments; in ParamMap form return them as outputs.Classify every state:
When uncertain, use 2: diffuse initialization is always safe (it costs a few initial observations) except for a confounded state (Rule 9).
Always write StateType explicitly: in NaN-form as 'StateType' in the ssm call, in ParamMap form as the StateType output. Without it, ssm assigns state types by default rules that can misclassify states.
With StateType 2, leave Cov0 empty: when Cov0 is given, ssm ignores StateType and uses Cov0 as given. The only exception is fixing a confounded initial state at 0 (Rule 9); then give each state that stays diffuse 1e7 on the diagonal of Cov0, the value StateType 2 uses.
% TEMPLATE — not executable
% State-Space Model: [Model Name]
% State vector: x_t = [state1_t; state2_t; ...] (m = ?)
% Observation: y_t = [obs1_t; obs2_t; ...] (n = ?)
A = [...];
B = [...];
C = [...];
D = [...];
StateType = [...]; % 0=stationary, 1=constant, 2=diffuse
mdl = ssm(A, B, C, D, 'StateType', StateType);
% Parameter order (column-major NaN scan):
% params(1) -> B(row, col) = sigma_...
% Estimation:
% params0 = [...];
% estMdl = estimate(mdl, y, params0);
Always a named function with 7 outputs (8 with DeflateY). Never ssm(@(p) deal(...)).
% TEMPLATE — not executable
function [A, B, C, D, Mean0, Cov0, StateType] = ssmParamsMap(params)
% State-Space Model: [Model Name]
% State vector: x_t = [state1_t; state2_t; ...] (m = ?)
% params(1) = sigma_...
A = [...];
B = zeros(m, k);
B(...) = params(1);
C = [...];
D = zeros(n, h);
D(...) = params(...);
Mean0 = [];
Cov0 = [];
StateType = [...]; % 0=stationary, 1=constant, 2=diffuse
end
Companion script:
mdl = ssm(@ssmParamsMap);
% params0 = [...];
% estMdl = estimate(mdl, y, params0);
For regression or an intercept through DeflateY, pass the data through an anonymous function that calls the named function; y and Z are captured when mdl is created. DeflateY must be the 8th output; in any other position ssm misreads it and errors with a misleading "Length of the initial mean vector" message:
% TEMPLATE — not executable
function [A, B, C, D, Mean0, Cov0, StateType, DeflateY] = ssmParamsMap(params, y, Z)
% ... A, B, C, D, Mean0, Cov0, StateType as above ...
p = size(Z, 2);
beta = params(end-p+1:end);
DeflateY = y - Z * beta(:);
end
mdl = ssm(@(params) ssmParamsMap(params, y, Z));
Before finalizing, check:
After the commented % estMdl = estimate(...) line, add as MATLAB comments each tip that applies; the text of each tip is in references/tips.md:
D = []). Omit it when DD' is not diagonal.estimate use fmincon instead of fminunc.End the output with this markdown table:
| Property | Value |
|---|---|
| Model | [name] |
| States (m) | [number] |
| Observations (n) | [number] |
| Free parameters | [number] |
| StateType | [e.g., all diffuse / mixed / all stationary] |
| Output form | NaN-form script / parameter-mapping function |
estimate call as a commented line → tips → summary table. Write nothing after the table.ssmParamsMap.m on your MATLAB path"), or as a local function at the end of the companion script, since ssm(@fcn) needs the function defined in a file.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/computational-finance:matlab-specify-ssmfrom computational-finance
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin computational-finance5 skills in this plugin
/matlab-access-datafeedConnect to Bloomberg, FRED, Haver Analytics, LSEG Datastream, NOAA Climate Data Online, or US government agencies (BEA, BLS, Census, EIA) from MATLAB and retrieve data. Covers market data (bloomberg/blp/bloombergHypermedia), economic data (fredrs, haver/haverdirect/haverview), historical financial data (datastreamws), weather/climate data (@noaa from GitHub), and government data (usbea/usbls/uscensus/useia from GitHub).
/matlab-optimize-portfolioFormulate and solve portfolio optimization problems in MATLAB. Routes to the Financial Toolbox Portfolio object for mean-variance (Markowitz), minimum- variance, target-return, maximum Sharpe ratio, and efficient frontier problems with bounds, budget, group, turnover, tracking-error, or cardinality constraints; or to the problem-based framework (optimproblem/optimvar/solve) when constraints exceed what Portfolio can express: integer round lots, whole shares, per-lot or fixed commissions, minimum trade sizes, semi-integer positions, wash-sale rules, realized capital-gains caps, tax-loss harvesting, asymmetric or bucketed transaction- cost caps, or a custom efficient frontier over such constraints. Use when users ask about portfolio optimization, when they attempt quadprog, fmincon, intlinprog, or ga for a portfolio problem, or when code rounds Portfolio weights to whole shares or lots.
/matlab-price-instrumentPrice financial instruments in MATLAB using the Financial Instruments Toolbox. Route to the appropriate numerical method reference based on the user's request: Monte Carlo simulation (AssetMonteCarlo, IRMonteCarlo, RoughVolMonteCarlo), FFT / Numerical Integration (Vanilla European options), or Interest-Rate Trees (option-embedded bonds with IRTree). Use when the user asks to price financial instruments or compute Greeks using any of these methods. Use one of the following models depending on the pricing method and instrument: Black-Scholes, Bachelier, Heston, Bates, Merton, Hull-White, Black-Karasinski, Black-Derman-Toy, Cox-Ingersoll-Ross, Linear Gaussian 2 Factor (G2PP), Brace-Gatarek-Musiela (BGM), SABR-BGM, RoughBergomi, RoughHeston.
/matlab-use-spreadsheet-linkExchange data between Excel and MATLAB using Spreadsheet Link VBA macros and worksheet functions. Use when writing Excel VBA macros that call MLPutMatrix, MLGetMatrix, MLPutVar, MLGetVar, MLPutRanges, MLEvalString, MLGetFigure, or MatlabRequest.Other plugins' skills for the same job