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

Contributor:
QuantInsti
Visit: 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:

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:

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:

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:

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:

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:

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 Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight 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 permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR 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 sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. 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.

In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.

Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.