Exercise

# Are We Confident This Stock is Mean Reverting?

In the last chapter, you saw that the autocorrelation of MSFT's weekly stock returns was -0.16. That autocorrelation seems large, but is it statistically significant? In other words, can you say that there is less than a 5% chance that we would observe such a large negative autocorrelation if the true autocorrelation were really zero? And are there any autocorrelations at other lags that are significantly different from zero?

Even if the true autocorrelations were zero at all lags, in a finite sample of returns you won't see the estimate of the autocorrelations exactly zero. In fact, the standard deviation of the sample autocorrelation is \(\small 1/\sqrt{N}\) where \(\small N\) is the number of observations, so if \(\small N=100\), for example, the standard deviation of the ACF is 0.1, and since 95% of a normal curve is between +1.96 and -1.96 standard deviations from the mean, the 95% confidence interval is \(\small \pm 1.96/\sqrt{N}\). This approximation only holds when the true autocorrelations are *all* zero.

You will compute the actual and approximate confidence interval for the ACF, and compare it to the lag-one autocorrelation of -0.16 from the last chapter. The weekly returns of Microsoft is pre-loaded in a DataFrame called `returns`

.

Instructions

**100 XP**

- Recompute the autocorrelation of weekly returns in the Series
`'Adj Close'`

in the`returns`

DataFrame. - Find the number of observations in the returns DataFrame using the
`len()`

function. - Approximate the 95% confidence interval of the estimated autocorrelation. The math function
`sqrt()`

has been imported and can be used. - Plot the autocorrelation function of
`returns`

using`plot_acf`

that was imported from statsmodels. Set`alpha=0.05`

for the confidence intervals (that's the default) and`lags=20`

.