[00:00] Can yesterday's market behaviour tell us anything about tomorrow? Today we'll explore autocorrelation, one of the most important tools in time series analysis, and using Python with Y-Finance to see what stock returns and trading volume can actually predict. [00:19] So let's get right into it. Autocorrelation is a measure of how a variable it relations to its past values. So this is done with lagged values. It is the correlation between [00:32] for example the return and then the return from five rows ago. So what does this value mean? A positive autocorrelation means that a higher value on one value tends to follow a high value [00:47] and low values tend to follow low values. Negative means a higher variable will tend to follow lower values, and then a zero means there's not really a correlation detected. [01:00] Let's work this out in Python code now. We will first take our data frame of the Apple stocks from the start of 2022 to 2025 Now from last time we make the return instead of close as relative values are generally better to [01:17] use. Now let's get our autocorrelation. We get this with one simple line. df return the value we want the autocorrelation for, .autocall and then give [01:31] the lag in brackets. Let's say lag equals 1. So this will see if there is a correlation between a current return value and the one before it. Let's also take another auto correlation [01:45] of 5 too and print them out to have a look. Lag 1 has a 0.015 autocorrelation and a 0.026 five. So therefore, there appears to be a more correlation between current rows and [02:02] five rows than just the row before it. However, overall, these values are pretty close to zero So they weak And therefore we can get too much information from it Generally returns show a weak autocorrelation in finance So this doesn show that a very predictive nature Compared to if we had a high autocorrelation it would mean that when the [02:25] return is quite high, it tends to stay quite high, making it easier to predict. But generally, just how life goes, this shows that finance isn't very predictable in this regard. [02:37] What about a difference matrix? Take the absolute return with simple df.return.abs. Let's take our lag1 and lag5 once again. These values are quite a lot bigger than previously, around [02:54] 0.14, about 8 times the size, so slightly more positive correlation. This means that often larger movements in return seem to cluster together. Now this metric says a lot more [03:08] about volatility or risk rather than the predictive nature we are looking for. This means that return autocorrelation may not be used in models, however the absolute return we can [03:20] for sure find useful when it comes to volatility modelling which are just as important What is another important metric to test The relative volume We can get this with the current volume divided by the rolling volume mean [03:35] let's say 30 days. So to this write in Python, df relative volume equals df volume divided by df volume dot rolling 30 dot mean. Let's print this autocorrelation for lags one and five. [03:50] And as we can see, we get 0.36 for lag 1, which is pretty strong for finance, and this means that the volume increase or decrease tends to stay the same for the next day. [04:02] However, lag 5 gave a low 0.014. This is quickly reduced, so we could make some decent predictions on volume that the next day's volume will tend to be the same, but completely irrelevant in about 5 days time. [04:20] We could use this details to detect news driven activity or detecting unusual activity. And then that is everything we are going through for today's video. If you found this video helpful, please like the video and subscribe to support the channel. [04:35] And I hope to see you in another video.