I'm trying to see the influence of autocorrelation in my processes and to do so I have to compute it, however it seems to be hard to find a coherent formula over the web. I found pretty much two different ones which are those :

First Formula

Second Formula

Even tough those two formulas are very close between each others, they seem to disagree on the way of computing the means used at various places within the formulas.

I struggle to figure out which one is the correct one even if I might feel like the first one is correct, compared to the second one, but it is just pure intuition and not mathematically justified.

Can anyone help me figure out which one is the correct one and why ? Thanks everyone for your help.

  • 1
    $\begingroup$ So, eg. if the process $\{X_{i+1}\}_{i=1}^{N-1} = \{X_2,\ldots,X_N\}$ has a different mean than the lagged process $\{X_{i}\}_{i=1}^{N-1} = \{X_1,\ldots,X_{N-1}\}$ then you would use the first formula. For processes that satisfy covariance stationarity, you have time-independent mean and covariances, leaving you with the simplified formulation as seen in the third formula of the first picture (and/or the first formula in the second picture). $\endgroup$
    – Pleb
    Commented Apr 8, 2022 at 14:21
  • $\begingroup$ Ok thanks for your complete explanation ! So when looking at stocks, we can't do such an assumption over the means I believe ? so I should use the first formula of the first picture (I'm pretty confident with that but just to be sure) $\endgroup$ Commented Apr 8, 2022 at 14:39
  • $\begingroup$ And for the case of lag k with the first formula, I should be looking at those 3 means : 1) mean between obs 1 and N-K 2) mean between obs 1+K and N 3) mean between 1 and N Am I right ? $\endgroup$ Commented Apr 8, 2022 at 14:40
  • $\begingroup$ Also when you look at the bottom term of the first formula of the first picture, you would thought it would turn into the sum from 1 to N-k as k change from 1 to k but the second picture seems to tell us that no matter the value of k you always take the sum from 1 to N so it is not very clear how you extend the formula without approximation to the lag k one $\endgroup$ Commented Apr 8, 2022 at 15:00
  • $\begingroup$ Stocks are non-stationary processes and (usually) whenever we want to infer some statistical analysis on stocks, we transform them into (log-)returns which satisfy covariance stationarity. Be wary, doing statistical analysis on non-stationary processes can lead to spurious results. -There are only two means that needs to be calculated: For $X_{i+k}$ and its lagged process $X_i$. -The denominator is just the standard deviation of each process. In the second formula we assume that the first and second moment is time-independent therefore $X_{i+k}$ and its lagged counterpart will have same std. $\endgroup$
    – Pleb
    Commented Apr 8, 2022 at 15:54

1 Answer 1


the autocorrelation is the correlation of a process $X$ and its lagged version, hence you have to consider it from a probabilistic viewpoint. Use the $\sigma_\ell$ notation for the operator that shifts a process: $${\cal A}(X;\ell):=\frac{\mathbb{E}\big((X - \mathbb{E}X) \cdot (\sigma_\ell\circ X - \mathbb{E}\sigma_\ell\circ X)\big)}{\sqrt{\mathbb{E}(X - \mathbb{E}X)^2 \cdot \mathbb{E}(\sigma_\ell\circ X - \mathbb{E}\sigma_\ell\circ X)^2}}.$$

This is the true definition. Now you need to use empirical estimators for all these quantities.

Usually we take $\frac{1}{N}\sum_{n=1}^N X_n$ as an estimator for $\mathbb{E}X$ over a sample of size $N$.

I let you replace and you will get the first formula you snapshotted in your question.

Now think about the set of information you have: you know $X_t$ from $t=1$ to $t=N+\ell$. When it is about estimating quantities that are not a function of the dependencies between $X$ and $\sigma_\ell\circ X$, isn't it better to use all the available information?

i.e. $\frac{1}{N+\ell}\sum_{n=1}^{N+\ell} X_n$ may be a better estimator of $\mathbb{E}X$, no? simply because you use more observations (of course it is submitted to some stationarity assumptions, like it has been underlined in one remark).

Here we talk about $\mathbb{E}X$, $\mathbb{E}\sigma_\ell\circ X$, $\mathbb{E}(X - \mathbb{E}X)^2$ and $\mathbb{E}(\sigma_\ell\circ X - \mathbb{E}\sigma_\ell\circ X)^2$ that are all concerning $X$ only. You can estimate them using as many observation as possible. Of course if you care about outliers, you can also use a bootstrap method (especially for the variance terms, since bootstrap is designed that for), or any method you like.

If you do so, then you recover the last formula of your question:

  1. at the numerator you use $\bar X=1/N\sum_n X_n$ for $\mathbb{E}X$ and for $\mathbb{E}\sigma_l\circ X$: $$\mathbb{E}\big((X - \mathbb{E}X) \cdot (\sigma_\ell\circ X - \mathbb{E}\sigma_\ell\circ X)\big)\simeq \mathbb{E}\big((X - \bar X) \cdot (\sigma_\ell\circ X - \bar X)\big).$$
  2. the denominator boils down to $$\sqrt{\mathbb{E}(X - \mathbb{E}X)^2 \cdot \mathbb{E}(\sigma_\ell\circ X - \mathbb{E}\sigma_\ell\circ X)^2}\simeq \mathbb{E}(X - \bar X)^2.$$
  3. When you put them together $${\cal A}(X;\ell)\simeq \frac{\sum_n (X_n - \bar X) (X_{n+\ell}-\bar X)}{\sum_n (X_n - \bar X)^2}.$$

What is important to understand is that: both formula are ok since they are estimators of the same statistic ${\cal A}(X;\ell)$, that is the true formula. It depends how you want to build the estimators. Which one is the best? it depends on the true (not known) distribution of the $X_t$.

I would say that

  • if $X$ is stationary, the second one is the best,
  • whereas if $X$ is not stationary, the first one may be better.
  • $\begingroup$ Thanks for your answer which gives a great theoretical explanation. However, my main struggle was not to understand this theoretically but to move from the theory to a practical formula. I don't doubt that your help will be useful for people enchanting a difficulty to understand what autocorrelation is about $\endgroup$ Commented Apr 13, 2022 at 12:56
  • $\begingroup$ I answered to your question @Strauss : let me edit and add some details at the end. $\endgroup$
    – lehalle
    Commented Apr 13, 2022 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.