# SARIMA

SARIMA is the abbreviation for Seasonal Autoregressive Integrated Moving Average, a time series analysis in the fields of statistics and econometrics.

Without accounting for seasonality, we utilize three parameters:

- **p**: Number of historical points considered for auto-regression (AR)
- **q**: Number of historical points considered for moving averages (MA).
- **d**: Number of times to apply differencing. Specifies that calculations should be made on the differences between consecutive points, rather than the raw points.

To make predictions, we maximize **p** and **q** historical points. This means that we use **$max(p,q)+d$** historical points to make a prediction.

When considering seasonality, we add these additional parameters:

- **sp**: Seasonally-adjusted number of historical points considered for auto-regression (AR)
- **sq**: Seasonally-adjusted number of historical points considered for moving averages (MA).
- **sd**: Seasonally-adjusted number of times to apply differencing.
- **sm**: Number of discrete timestamps in a period.

In Kloudfuse, we implement the SARIMA algorithm as the **agile** option for anomaly detection.

## In Dashboards

To use the `sarima` operator in a dashboard, apply the following function:

```code
sarima( \
  ${promql}, \ (1)
  2, 1, 2, 0, 0, 0, 0, \
  ${bound}, \ (2)
  ${band} \ (3)
)
```

|     |     |
| --- | --- |
| **1** | `${promql}`: PromQL query to evaluate |
| **2** | `${band}`: 4 = lower band, 5 = upper band, 6 = both upper and lower bands |
| **3** | `${bound}`: Number of standard deviations (stdv): 1, 2, or 3 |

## Limitations

If the evaluated metrics do not exhibit true seasonality, SARIMA may create incorrect (invalid) alerts, or mask valid alerting conditions.

## Next steps

For an in-depth discussion of the SARIMA functions, see these external resources:

- [Seasonal AutoRegressive Integrated Moving Average with eXogenous regressors model](https://www.statsmodels.org/0.9.0/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html) in StatsModels
- [Autoregressive integrated moving average](https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average.html) in Wikipedia
