smooth.SMA

class smooth.SMA(order=None, ic='AICc', h=10, holdout=False, fast=True, verbose=0, **kwargs)

Simple Moving Average in Single Source of Error state space form.

SMA(m) is an AR(m) state-space model where every AR coefficient is fixed at 1/m. It is implemented as a thin wrapper over ADAM with model="NNN" and the AR vector hard-coded, so it inherits the full ADAM fit / predict / diagnostics surface (multi-step forecasts, prediction intervals, residual diagnostics). If order is left unspecified, the order is selected automatically by information criterion.

Parameters:
  • order (Optional[int]) – Order of the moving average. If None, selected automatically using the information criterion (ternary search when fast=True, sequential scan when fast=False).

  • ic (Literal['AIC', 'AICc', 'BIC', 'BICc']) – Information criterion used for automatic order selection.

  • h (int) – Forecast horizon (used with holdout=True to reserve a test set).

  • holdout (bool) – Whether to hold out the last h observations for validation.

  • fast (bool) – If True, use ternary search for order selection (fast, finds a local minimum). If False, evaluate all orders 1 … min(200, T) sequentially. When a pandas Series with a DatetimeIndex is passed, the inferred seasonal period is always evaluated as a candidate regardless of this flag.

  • verbose (int) – Verbosity level. 0 = silent.

  • **kwargs – Additional arguments passed to ADAM (e.g. n_iterations).

model

Model name, e.g. "SMA(3)".

Type:

str

ICs_

IC values for each evaluated order (only present after auto-selection). Keys are order integers, values are IC floats.

Type:

dict

See also

ADAM

Parent class; all ADAM attributes are available after fit().

MSARIMA

General multiple-seasonal ARIMA wrapper.

Examples

Fixed order:

>>> import numpy as np
>>> from smooth import SMA
>>> y = np.cumsum(np.random.randn(60)) + 100
>>> model = SMA(order=4, h=5)
>>> model.fit(y)
>>> fc = model.predict(h=5)
>>> fc.mean

Auto-selected order:

>>> model = SMA(h=5)
>>> model.fit(y)
>>> print(model.model)   # e.g. "SMA(3)"
>>> print(model.ICs_)

References

Methods

coefbootstrap([nsim, size, replace, prob, ...])

Bootstrap the coefficient sampling distribution by refitting subsamples.

confint([parm, level, type, bootstrap, ...])

Confidence intervals for the estimated parameters.

fit(y[, X])

Fit the SMA model to time series data.

multicov([type, h, nsim])

Covariance matrix of multi-step-ahead forecast errors.

outlierdummy([level, type])

Detect outliers and return a matrix of indicator dummy variables.

plot([which, level, legend, lowess])

Diagnostic plots for the fitted ADAM model (R: plot.adam).

point_lik([log])

Per-observation log-likelihood of the fitted model.

predict(h[, X, interval, level, side, ...])

Generate forecasts using the fitted ADAM model.

predict_intervals(h[, X, levels, side, nsim])

Generate prediction intervals using the fitted ADAM model.

reapply([nsim, type, bootstrap, heuristics, ...])

Re-run the model on the in-sample data for nsim parameter draws.

reforecast([h, X, occurrence, interval, ...])

Produce h-step-ahead forecasts via Monte-Carlo reforecasting.

rmultistep([h])

Return the (T-h) × h matrix of rolling in-sample multistep forecast errors.

rstandard()

Return standardised residuals.

rstudent()

Return studentised (leave-one-out) residuals.

select_best_model()

Select the best model based on information criteria and update model parameters.

simulate([nsim, seed, obs, randomizer])

Re-simulate obs observations from the fitted model.

summary([level, digits, type])

Generate a coefficient-table summary of the fitted model.

vcov([type, bootstrap, heuristics, step_size])

Variance-covariance matrix of the estimated parameters.

Attributes

actuals

Return original in-sample data.

aic

Return Akaike Information Criterion.

aicc

Return corrected Akaike Information Criterion.

b_value

$B).

bic

Return Bayesian Information Criterion.

bicc

Return corrected Bayesian Information Criterion.

coef

Return estimated coefficients (parameter vector B).

coef_names

Parameter names aligned with coef (the B vector).

constant_value

$constant).

data

$data).

distribution_

$distribution).

error_type

'A' (additive) or 'M' (multiplicative).

fisher_information_

Observed Fisher Information matrix at the estimated parameters.

fitted

Return in-sample fitted values.

holdout_data

$holdout).

ic_weights

$ICw).

initial_type

$initialType).

initial_value

$initial).

is_combined

Return True if model is a combination of multiple models.

lags_used

Return the vector of lags used in the model.

loglik

Return log-likelihood of the fitted model.

loss_

$loss).

loss_value

$lossValue).

measurement

$measurement).

model_name

modelName()).

model_type

Return ETS model type code (e.g., 'AAN', 'AAA', 'MAdM').

models

$models).

n_param

$nParam).

nobs

Return number of observations used for fitting.

nparam

Return number of estimated parameters.

om_model

Fitted occurrence model (OM / OMG / AutoOM), or None.

orders

Return ARIMA orders as dict with 'ar', 'i', 'ma' keys.

persistence_vector

$persistence).

phi_

$phi).

profile

$profile).

residuals

Return model residuals (errors from fitting).

scale

Internal optimisation scale of the error distribution (R: adam_obj$scale).

sigma

sigma(adam_obj)).

states

$states).

time_elapsed

Time taken to fit the model in seconds.

transition

$transition).