Autocorrelation Function

Time Series Analysis in Python

Rob Reider

Adjunct Professor, NYU-Courant Consultant, Quantopian

Autocorrelation Function

  • Autocorrelation Function (ACF): The autocorrelation as a function of the lag
  • Equals one at lag-zero
  • Interesting information beyond lag-one
Time Series Analysis in Python

ACF Example 1: Simple Autocorrelation Function

  • Can use last two values in series for forecasting
Time Series Analysis in Python

ACF Example 2: Seasonal Earnings

  • Earnings for H&R Block
  • ACF for H&R Block
Time Series Analysis in Python

ACF Example 3: Useful for Model Selection

  • Model selection

Time Series Analysis in Python

Plot ACF in Python

  • Import module:
    from statsmodels.graphics.tsaplots import plot_acf
    
  • Plot the ACF:
    plot_acf(x, lags= 20, alpha=0.05)
    
Time Series Analysis in Python

Confidence Interval of ACF

Time Series Analysis in Python

Confidence Interval of ACF

  • Argument alpha sets the width of confidence interval
  • Example: alpha=0.05
    • 5% chance that if true autocorrelation is zero, it will fall outside blue band
  • Confidence bands are wider if:
    • Alpha lower
    • Fewer observations
  • Under some simplifying assumptions, 95% confidence bands are $\pm 2/\sqrt{N}$
  • If you want no bands on plot, set alpha=1
Time Series Analysis in Python

ACF Values Instead of Plot

from statsmodels.tsa.stattools import acf
print(acf(x))
[ 1.         -0.6765505   0.34989905 -0.01629415 -0.02507013  0.01930354
 -0.03186545  0.01399904 -0.03518128  0.02063168 -0.02620646 -0.00509828
...
  0.07191516 -0.12211912  0.14514481 -0.09644228  0.05215882]
Time Series Analysis in Python

Let's practice!

Time Series Analysis in Python

Preparing Video For Download...