How it works...

We started by downloading Google's stock prices from the given years and resampling them to weekly frequency by taking the last (adjusted) close price in every week. In Step 3, we applied the first difference in order to make the series stationary.

If we want to difference a given series more than once, we should use the np.diff function as it implements recursive differencing. Using the diff method of a DataFrame/Series with periods > 1 results in taking the difference between the current observations and the one from that many periods before.

Step 4 is very important because, because we determined the order of the ARIMA model based on these results. We tested for stationarity using a custom function called test_autocorrelation. First, the series turned out to be stationary, so we knew that the order of integration was d=1. We determined the suggested lag order (p) by looking at the last lag after the PACF function crossed the confidence interval. In this case, it was p=2. Analogically, for the moving average order, we looked at the ACF plot to determine q=1. This way, we specified the model as ARIMA(2,1,1) in Step 5. We printed a summary using the summary method of the fitted model.

Hyndman and Athanasopoulos (2018) warned that if both p and q are positive, the ACF/PACF plots might not be helpful in determining the specification of the ARIMA model.

In Step 6 and Step 7, we investigated the goodness of fit by looking at the model's residuals. If the fit is good, the residuals should be similar to the white noise. That is why we used four different types of plots to investigate how closely the residuals resemble the white noise.

Finally, we employed the Ljung-Box test (the acorr_ljungbox function from statsmodels) for no significant correlation and plotted the results.

Different sources suggest a different number of lags to consider in the Ljung-Box test. The default value in statsmodels is min((nobs // 2 - 2), 40), while other commonly used variants include min(20,nobs − 1) and ln(nobs).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.124