How to do it...

Execute the following steps to fit and evaluate an ARIMA model using Google's stock price.

  1. Import the libraries:
import yfinance as yfimport pandas as pdimport numpy as npfrom statsmodels.tsa.arima_model import ARIMAimport statsmodels.api as smfrom statsmodels.graphics.tsaplots import plot_acffrom statsmodels.stats.diagnostic import acorr_ljungboximport scipy.stats as scsfrom chapter_3_utils import test_autocorrelation
  1. Download Google's stock prices and resample them to weekly frequency:
df = yf.download('GOOG',                 start='2015-01-01',                 end='2018-12-31',                 adjusted=True,                 progress=False)goog = df.resample('W') \         .last() \         .rename(columns={'Adj Close': 'adj_close'}) \         .adj_close 
  1. Apply the first differences to the price series ...

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.