Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Photo by Lucas Santos on Unsplash

A Step-by-Step Guide to Calculating Autocorrelation and Partial Autocorrelation

How to calculate the ACF and PACF values from scratch in Python

Eryk Lewinson
8 min readJan 30, 2022

--

If you have worked at any time series task, I am sure at one point you looked into the approaches to identifying the nature of relationships in time series — the measures of autocorrelation. For example, you might have used the ACF and PACF plots to determine the orders of an ARMA model.

However, have you actually wondered how those correlation coefficients are calculated? If not, this article is the right place for you. We will briefly describe what those two measures are and then show step-by-step how to calculate them in Python.

And to manage expectations — we will focus on the calculations behind the coefficients, not their interpretation and details on how to use them for time series modeling. That would be a topic for another article.

Setup

As always, we quickly import the required libraries. We will use the functions from statsmodels as a benchmark to make sure our calculations are correct.

--

--

Data Scientist, quantitative finance, gamer. My latest book - Python for Finance Cookbook 2nd ed: https://t.ly/WHHP