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
ADAMwithmodel="NNN"and the AR vector hard-coded, so it inherits the full ADAM fit / predict / diagnostics surface (multi-step forecasts, prediction intervals, residual diagnostics). Iforderis 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 whenfast=True, sequential scan whenfast=False).ic (
Literal['AIC','AICc','BIC','BICc']) – Information criterion used for automatic order selection.h (
int) – Forecast horizon (used withholdout=Trueto reserve a test set).holdout (
bool) – Whether to hold out the lasthobservations 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
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
Svetunkov, I., & Petropoulos, F. (2017). Old dog, new tricks: a modelling view of simple moving averages. International Journal of Production Research. https://doi.org/10.1080/00207543.2017.1380326
Methods
|
Bootstrap the coefficient sampling distribution by refitting subsamples. |
|
Confidence intervals for the estimated parameters. |
|
Fit the SMA model to time series data. |
|
Covariance matrix of multi-step-ahead forecast errors. |
|
Detect outliers and return a matrix of indicator dummy variables. |
|
Diagnostic plots for the fitted ADAM model (R: |
|
Per-observation log-likelihood of the fitted model. |
|
Generate forecasts using the fitted ADAM model. |
|
Generate prediction intervals using the fitted ADAM model. |
|
Re-run the model on the in-sample data for |
|
Produce |
|
Return the (T-h) × h matrix of rolling in-sample multistep forecast errors. |
Return standardised residuals. |
|
|
Return studentised (leave-one-out) residuals. |
Select the best model based on information criteria and update model parameters. |
|
|
Re-simulate |
|
Generate a coefficient-table summary of the fitted model. |
|
Variance-covariance matrix of the estimated parameters. |
Attributes
Return original in-sample data. |
|
Return Akaike Information Criterion. |
|
Return corrected Akaike Information Criterion. |
|
$B). |
|
Return Bayesian Information Criterion. |
|
Return corrected Bayesian Information Criterion. |
|
Return estimated coefficients (parameter vector B). |
|
Parameter names aligned with |
|
$constant). |
|
$data). |
|
$distribution). |
|
'A' (additive) or 'M' (multiplicative). |
|
Observed Fisher Information matrix at the estimated parameters. |
|
Return in-sample fitted values. |
|
$holdout). |
|
$ICw). |
|
$initialType). |
|
$initial). |
|
Return True if model is a combination of multiple models. |
|
Return the vector of lags used in the model. |
|
Return log-likelihood of the fitted model. |
|
$loss). |
|
$lossValue). |
|
$measurement). |
|
modelName()). |
|
Return ETS model type code (e.g., 'AAN', 'AAA', 'MAdM'). |
|
$models). |
|
$nParam). |
|
Return number of observations used for fitting. |
|
Return number of estimated parameters. |
|
Fitted occurrence model (OM / OMG / AutoOM), or None. |
|
Return ARIMA orders as dict with 'ar', 'i', 'ma' keys. |
|
$persistence). |
|
$phi). |
|
$profile). |
|
Return model residuals (errors from fitting). |
|
Internal optimisation scale of the error distribution (R: |
|
|
|
$states). |
|
Time taken to fit the model in seconds. |
|
$transition). |