Lesson 1 of 15

Autocorrelation Function (ACF)

Autocorrelation Function (ACF)

The Autocorrelation Function (ACF) measures how correlated a time series is with a lagged version of itself. It is the foundation of time series analysis.

For a time series xs of length n with mean μ, the ACF at lag k is:

acf(xs, k) = Σ(xs[i] - μ)(xs[i+k] - μ) / Σ(xs[i] - μ)²

where the sums run over valid indices. By definition, acf(xs, 0) = 1.0.

High ACF at lag 1 means each value is strongly correlated with the previous one. ACF decaying slowly indicates a non-stationary or AR process.

Task

Implement acf(xs, lag) which returns the autocorrelation of the series at the given lag.

  • For lag == 0, return 1.0
  • Otherwise use the formula above
Python runtime loading...
Loading...
Click "Run" to execute your code.