## ARIMA :

ARIMA, short for Auto-Regressive Integrated Moving Average, is a commonly used time series forecasting method in statistics. It is used to model and predict future values based on historical data and trends.

The ARIMA model consists of three components: the autoregressive (AR) component, the differencing (I) component, and the moving average (MA) component.

The autoregressive component models the relationship between current values and past values. For example, if the current stock price is influenced by the previous three stock prices, the autoregressive component would be AR(3).

The differencing component is used to make the time series stationary, meaning that the mean, variance, and autocorrelation are constant over time. This is important because many statistical models assume stationary data. For example, if the time series has a trend, the differencing component would be used to remove the trend and make the data stationary.

The moving average component models the relationship between the current value and the error term. The error term is the difference between the actual value and the predicted value. For example, if the current stock price is influenced by the previous three error terms, the moving average component would be MA(3).

To illustrate the ARIMA model, let’s consider a simple example of monthly sales data for a retail store. The data is shown below:

Month: 1 2 3 4 5 6 7 8 9 10 11 12

Sales: 100 105 110 115 120 125 130 135 140 145 150 155

We can see that there is an upward trend in the data, meaning that the sales are increasing over time. To make the data stationary, we can take the first differences, which are calculated by subtracting the current value from the previous value. The first differences are shown below:

Month: 1 2 3 4 5 6 7 8 9 10 11 12

Sales: -5 5 5 5 5 5 5 5 5 5 5

Now the data is stationary, with a constant mean and variance. We can model the data using an ARIMA(1,1,0) model, which means that the autoregressive component is AR(1), the differencing component is I(1), and the moving average component is MA(0).

The AR(1) component means that the current value is influenced by the previous value. The I(1) component means that the first differences were taken to make the data stationary. The MA(0) component means that there is no moving average component, so the current value is not influenced by the error term.

To fit the ARIMA model, we can use the statsmodels library in Python. First, we import the necessary libraries and load the data into a pandas DataFrame:

import pandas as pd

import numpy as np

from statsmodels.tsa.arima_model import ARIMA

Load the data into a DataFrame

data = pd.DataFrame({“sales”: [100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155]})

Next, we can fit the ARIMA model and make predictions for the next 12 months:

Fit the ARIMA model

model = ARIMA(data, order=(1,1,0))

model_fit = model.fit(disp=False)

Make predictions for the next 12 months

predictions = model_fit.predict(start=13, end=24, dynamic=True)

The predictions are shown below:

Month: 1 2