Get startedGet started for free

Compare AR Model with Random Walk

Sometimes it is difficult to distinguish between a time series that is slightly mean reverting and a time series that does not mean revert at all, like a random walk. You will compare the ACF for the slightly mean-reverting interest rate series of the last exercise with a simulated random walk with the same number of observations.

You should notice when plotting the autocorrelation of these two series side-by-side that they look very similar.

This exercise is part of the course

Time Series Analysis in Python

View Course

Exercise instructions

  • Import plot_acf function from the statsmodels module
  • Create two axes for the two subplots
  • Plot the autocorrelation function for 12 lags of the interest rate series interest_rate_data in the top plot
  • Plot the autocorrelation function for 12 lags of the interest rate series simulated_data in the bottom plot

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf

# Plot the interest rate series and the simulated random walk series side-by-side
fig, axes = plt.subplots(2,1)

# Plot the autocorrelation of the interest rate series in the top plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[0])

# Plot the autocorrelation of the simulated random walk series in the bottom plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[1])

# Label axes
axes[0].set_title("Interest Rate Data")
axes[1].set_title("Simulated Random Walk Data")
plt.show()
Edit and Run Code