Close Navigation
Learn more about IBKR accounts
Autocorrelation and Autocovariance: Calculation, Examples, and More – Part II

Autocorrelation and Autocovariance: Calculation, Examples, and More – Part II

Posted November 21, 2022
José Carlos Gonzáles Tanaka via QuantInsti Blog
QuantInsti

See Part I for an overview of autocovariance.

Calculation of the autocovariance with an example

You might have been thinking up to now:
Why are the autocovariance and autocorrelation defined with an “s” subscript?
Great question!

Let us explain: Actually, the autocovariance formula defined above is a function which allows the calculation of the autocovariance for different lags. The same for the autocorrelation function.

Confused? Don’t worry! We got you covered!

Let’s see an example to make the concept clear to your thoughts! We are going to make an example of how to calculate the autocovariance of the Microsoft price returns at lag 1. We are going to use the autocovariance function shown above.

Imagine we have the following returns for Microsoft prices:

Day 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10
5%1%-2%3%-4%6%2%-1%-3%4%

Let’s suppose we want to compute the autocovariance at lag 1. You will need the returns up to day 10, and the 1-period lagged returns up to day 9.

Thus, you have the following data structure for returns on days 10 and 9:

VariableDay 1Day 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10
rt5%1%-2%3%-4%6%2%-1%-3%4%
rt−15%1%-2%3%-4%6%2%-1%-3%

Do you get to see the difference between the 2 variables?
The second one is the first lag of Xt.

Now, since the 2 variables have different dimensions (the first one has 10 observations, while the second one has 9), we are going to use data from day 2 onwards.

Consequently, our data is as follows:

VariableDay 2Day 3Day 4Day 5Day 6Day 7Day 8Day 9Day 10
rt1%-2%3%-4%6%2%-1%-3%4%
rt−15%1%-2%3%-4%6%2%-1%-3%

The covariance between these 2 variables will be the autocovariance of the returns at lag 1.

You can do this, right?
Check an example we give in our previous article.

Before you get ready to use a pencil and a piece of paper, let us tell you something important.

Remember the autocovariance formula:

 class=

If you paid attention to details, you could see that the average return is the same for both returns, in our case, for returns up to day 10 and up to day 9. As we explained before, autocovariance and autocorrelation functions are applied only to stationary time series.

Consequently, not only the variance but also the mean is a unique value for the whole span. That’s why the mean is the same for any lag of the price returns.

The mean of the Microsoft price returns is 1.1%. Let’s follow the procedure to compute the autocovariance:

Variablertrt−1(rtr)(rt−1r)(rtr)(rt−1r)
Day 21%5%-0.100%3.900%-0.004%
Day 3-2%1%-3.100%-0.100%0.003%
Day 43%-2%1.900%-3.100%-0.059%
Day 5-4%3%-5.100%1.900%-0.097%
Day 66%-4%4.900%-5.100%-0.250%
Day 72%6%0.900%4.900%0.044%
Day 8-1%2%-2.100%0.900%-0.019%
Day 9-3%-1%-4.100%-2.100%0.086%
Day 104%-3%2.900%-4.100%-0.119%

The autocovariance is just the sum of the last column values divided by (N-1, equal to 8), which results in -0.046%.


Calculation of the autocorrelation with an example

Let’s follow the same exercise and compute the autocorrelation of the Microsoft price returns up to day 10 at lag 1. The autocorrelation is the autocovariance divided by the variance. We give you the exact hint you need: The variance of Microsoft price returns up to day 10 is 0.121%.

Let’s follow the algebraic formulas and use the numbers to compute the autocorrelation:

 class=

Stay tuned for the next installment in this series to learn about computation of autocovariance and autocorrelation in Python

Visit QuantInsti for additional insight on this topic: https://blog.quantinsti.com/autocorrelation-autocovariance/.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.