How it works...

In Steps 2 to 5, we downloaded Google's stock prices from 2010-2018, resampled the values to a monthly frequency, split the data into training (2010-2017) and test (2018) sets, and plotted the series. 

In Step 6, we fitted three different SES models using the SimpleExpSmoothing class and its fit method. For fitting, we only used the training data. We could have manually selected the value of the smoothing parameter (smoothing_level), however, the best practice is to let statsmodels optimize it for the best fit. This optimization is done by minimizing the sum of squared residuals (errors). We created the forecasts using the forecast method, which requires the number of periods we want to forecast for (which is equal to the length of the test set). In Step 7, we visualized the results and compared them to the actual stock prices. We extracted the fitted values of the model by using the fittedvalues method of the fitted model.

In Step 8, we used the Holt class (which is a wrapper around the more general ExponentialSmoothing class) to fit Holt's linear trend model. By default, the trend in the model is linear, but we can make it exponential by specifying exponential=True and add dampening with damped=True. As in the case of SES, using the fit method with no arguments results in running the optimization routine to determine the optimal value of the parameter. We can access it by running fitted_model.params. In our example, we manually specified the value of the dampening parameter to be 0.99, as the optimizer selected 1 to be the optimal value, and this would be indistinguishable on the plot. In Step 9, we visualized the results.

..................Content has been hidden....................

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