#### [PLUS] How to Calculate Bitcoin Autocorrelation (ACF) with live code

###### What is Autocorrelation?
We will quickly define what is autocorrelation so that we can move farther along in the analysis. It is likely that you already know what autocorrelation is and why you would want to look for it in a timeseries. But nonetheless, autocorrelation is defined as the correlation between one time period and a corresponding period that is a few lengths behind the other (these are called lags). So as an example, autocorrelation with lag period equal to two (2) means that it is a measure of correlation between the current period in the window and the period 2 equal lengths before it. Most autocorrelation (ACF) functions will calculate for up to 1000 lags (or more). Generally, when looking at timeseries data, the most important lags will be those regarded as statistically significant. And the final question: Why? Why do we care if the timeseries points are correlated? Well, most models make a few assumptions about the underlying distribution of the data (That it is "i.i.d.") -> Independent and Identically Distributed. So the presence of autocorrelation (ACF) could cause problems in the forecasts of a model.

###### Interpreting Autocorrelation
Positive autocorrelation means that a change in one period is positively associated with another period. Ie. An increase in one period, on average, leads to an increase in the next. For timeseries, this usually means there is some sort of trend in the data. Negative autocorrelation is the opposite; it means that on average, an increase in one period is associated with a decrease in the next. Negative acf indicates a mean reverting tendency in the timeseries.

###### Autocorrelation and Bitcoin
Our live code (also fully documented/commented!) uses data from FTX exchange and a statistical library to calculate the autocorrelation of daily Bitcoin returns. The results are rather interesting at the time of writing (July 2022) ... At a lag equal to one, ACF shows a value of almost -0.08. This indicates a mean reverting tendency in Bitcoin price from day to day. Also statistically significant is a lag of 4 with a positive value of .082. So the ACF implies that there is a tendency for moves to reverse initially, but continue on day 4. The graph below removes lag equal to 0; as a point is always correlated with itself. The ACF lag(s) can be used as inputs into other time series (ARMA) models as the lag value. The working code below can be switched to do the same analysis for any other cryptocurrency pair using the data that we offer on our site.

This is a premium post. Create Plus+ Account to view the live, working codebase for this article.

Notice: Information contained herein is not and should not be construed as an offer, solicitation, or recommendation to buy or sell securities. The information has been obtained from sources we believe to be reliable; however no guarantee is made or implied with respect to its accuracy, timeliness, or completeness. Author does not own the any crypto currency discussed. The information and content are subject to change without notice. CryptoDataDownload and its affiliates do not provide investment, tax, legal or accounting advice.