How to do it...

Execute the following steps to use the exponential smoothing methods to create forecasts of Google's stock prices.

  1. Import the libraries:
import pandas as pdimport numpy as npimport yfinance as yffrom datetime import datefrom statsmodels.tsa.holtwinters import (ExponentialSmoothing,                                          SimpleExpSmoothing,                                          Holt)
  1. Download the adjusted stock prices for Google:
df = yf.download('GOOG',                 start='2010-01-01',                 end='2018-12-31',                 adjusted=True,                 progress=False)
  1. Aggregate to monthly frequency:
goog = df.resample('M') \         .last() \         .rename(columns={'Adj Close': 'adj_close'}) \         .adj_close 
  1. Create the training/test split:
train_indices = goog.index.year < 2018goog_train = goog[train_indices]goog_test = goog[~train_indices]test_length ...

Get Python for Finance Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.