Execute the following steps to transform the series from non-stationary to stationary.
- Import the libraries and update the inflation data:
import cpiimport pandas as pdfrom datetime import datefrom statsmodels.graphics.tsaplots import plot_acf, plot_pacffrom statsmodels.tsa.stattools import adfuller, kpssfrom chapter_3_utils import test_autocorrelation# update the CPI data (if needed)# cpi.update()
- Deflate the gold prices (to 2011-12-31 USD values) and plot the results:
DEFL_DATE = date(2011, 12, 31)df['dt_index'] = df.index.map(lambda x: x.to_pydatetime().date())df['price_deflated'] = df.apply(lambda x: cpi.inflate(x.price, x.dt_index, DEFL_DATE), axis=1)df[['price', 'price_deflated']].plot(title='Gold Price (deflated)'); ...