Home>

I want to plot the autocorrelation and partial autocorrelation of the original series and its difference series for time series analysis.

import numpy as np
import statsmodels.api as sm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#Load data
marketcap = pd.read_csv ('stock_market_cap.csv', index_col = 0)
Check # a1 (original series).
a1 = marketcap ['Asset1']
plt.plot (a1)
fig = plt.figure (figsize = (12,8))
ax1 = fig.add_subplot (211)
fig = sm.graphics.tsa.plot_acf (a1, lags = 20, ax = ax1)
ax2 = fig.add_subplot (212)
fig = sm.graphics.tsa.plot_pacf (a1, lags = 20, ax = ax2)
Check # a2 (difference series).
a2 = a1-a1.shift ()
plt.plot (a2)
fig = plt.figure (figsize = (12,8))
ax1 = fig.add_subplot (211)
fig = sm.graphics.tsa.plot_acf (a2, lags = 20, ax = ax1)
ax2 = fig.add_subplot (212)
fig = sm.graphics.tsa.plot_pacf (a2, lags = 20, ax = ax2)


The original and difference series and their correlograms are as follows.

[Original Series]
]
[Difference series]

Trends