doke93 / Modeling-Time-Series-using-ARIMA-model

Exploiting different standard temporal structures seen in time series processes
1 stars 0 forks source link

Modeling-Time-Series-using-ARIMA-model

Key Features

1. Auto Regressive (AR):

2. Integrated (I):

Checking for stationarity

There are three ways of checking for stationarity in a time series.

3. Moving Average (MA):

Special case - Random Walk

Limitation

Roadmap

When we use the ARIMA class to model a time series process, each of the above components are specified in the model as parameters (with the notations p, d, and q respectively).

That is, the classification ARIMA(p, d, q) process can be thought of as AR(p)I(d)MA(q)

Here,

  1. p: The number of past observations (we usually call them lagged terms) of the process included in the model.

  2. d: The number of times we difference the original process to make it stationary.

  3. q: The number of past error terms (we usually call them lagged error terms or lagged residuals) of the process included in the model.

Applying ARIMA model on Netflix weekly adjusted close prices

App Screenshot

First we will checks the stationarity of a pandas Series

App Screenshot

App Screenshot

Points to note:

We will again check stationarity on log_returns App Screenshot App Screenshot

Points to note:

We now fit an ARIMA model to the weekly stock prices (from mid-2010 to mid-2019) of Netflix and learn to evaluate it.

While creating the ARIMA model class, we select the order arbitrarily (p and q) and we inferred d from the result of above stationarity check

App Screenshot

Points to note:

Diagnosing the residual

App Screenshot

Points to note:

Additional Statistical tests

  1. To check for autocorrelations in residuals: The Ljung-Box test
  1. To check for normality in residuals: The Jarque-Bera test

App Screenshot

Points to note:

The Jarque-Bera test

App Screenshot

Automatically finding the best ARIMA fit (using the pmdarima library)

Calling auto arima function and pass seasonal equals to false

  model = pm.auto_arima(train,
                     error_action='ignore', trace=True,
                     suppress_warnings=True, maxiter=10,
                     seasonal=False)

Model summary

App Screenshot

Points to note:

Next we will create a function to plot the data itself, the fitted value for the in-sample data, forecast for the out-of-sample data and the confidence bound

App Screenshot

Points to note:

Therefore we write a function to plot only the test period, to see closely how well our model actually performs.

App Screenshot

Points to note:

So finally we will check, do this model perform better than the naive forecast, by using RMSE function.

    def rmse(y, t):
    return np.sqrt(np.mean((t - y)**2))

App Screenshot

Points to note:

Conclusion