In this lab, You'll practice your knowledge on correlation, autocorrelation and the ACF and PACF.
You will be able to:
- Understand correlation in Time Series
- Plot and discuss the autocorrelation function (ACF) for a time-series
- Plot and discuss the partial autocorrelation function (PACF) for a time-series
- Interpret ACF and PACF and Identify use cases both functions
We'll be looking at the exchange rates dataset again. First, import the necessary libraries for time series and plotting. Then import the data (in exch_rates.csv
) and make sure it's set in the correct time series format with the datetime
as the index.
# your code here
# your code here
Plot the three exchange rates in one plot
# your code here
You can see that the EUR/USD and AUD/USD exchange rate are somewhere between rougly 0.5 and 2 between 2000 and 2018, where the Danish Krone is somewhere between roughly 4.5 and 9. Now let's look at the correlations between these time series.
# your code here
What is your conclusion here? You might want to use outside resources to understand what's going on.
Next, look at the plots of the differenced series. Use subplots to plot them rather than creating just one plot.
# your code here
# your code here
# your code here
Next, let's look at the "lag 1 autocorrelation" for the EUR/USD exchange rate. Create a "lag 1 autocorrelation" series, plot the result, and look at the correlation coefficient.
# your code here
# your code here
# your code here
Repeat this, but for a "lag 5 autocorrelation"
# your code here
# your code here
Knowing this, let's plot the ACF now.
# your code here
The series is heavily autocorrelated at first, and then there is a decay. This is a typical result for a series that is a random walk, generally you'll see heavy autocorrelations first, slowly tailing off until there is no autocorrelation anymore.
Next, let's look at the Partial Autocorrelation Function.
# your code here
This is interesting! Remember that Partial Autocorrelation Function gives the partial correlation of a time series with its own lagged values, controlling for the values of the time series at all shorter lags. When controlling for 1 period lags, the PACF is only very high for one-period lags, and basically 0 for shorter lags. This is again a typical result for Random Walk series!
Look at ACF and PACF for the airpassenger data and describe the result passengers.csv
. Do this both for the differenced and regular series.
# your code here
# your code here
# your code here
# your code here
# your code here
# your code here
# your code here
Look at correlation and autocorrelation functions for the NYSE data ("NYSE_monthly.csv")
# your code here
# your code here
# your code here
Great, you've now been introduced to correlation, the ACF and PACF. Let's move into more serious modeling with autoregressive and moving average models!