---
title: "Partial autocorrelation"
output: html_document
---

## Partial autocorrelation for exchange rate between GBP and NZD

Read in the quarterly GBP to NZD exchange rate, and save it as a vector called `exchange_data`:
```{r}
www <- "http://asta.math.aau.dk/eng/static/datasets?file=pounds_nz.dat"
exchange_data <- read.table(www, header = TRUE)
```

Now convert it to a time series object (`ts`) with the correct starting date (First quarter 1991)
and frequency and call it `exchange`:
```{r}
# Put your commands here
```

- Plot the series and its autocorrelation function.

- Make a scatterplot of the series and its lag 1 values.

- Plot the partial autocorrelation function.

Consider the series of first order differences $y_t = x_{t+1} - x_{t}$ for $t = 1,\dots,38$:
```{r}
dexchange <- diff(exchange)
```

- Plot the series of differences and its autocorrelation function and comment on it.

## Random walk

The method of removing trend by differencing can be really effective as seen in
the following where we redo the exercise above for an artificial dataset `x`:
```{r}
x <- cumsum(rnorm(1000))
```

This is called a random walk and we will discuss it more in the next lecture.

- Plot the series and its autocorrelation function.

- Make a scatterplot of the series and its lag 1 values.

- Plot the partial autocorrelation function.

Consider the series of first order differences $y_t = x_{t+1} - x_{t}$ for $t = 1,\dots,999$:
```{r}
dx <- diff(x)
```

- Plot the series and its autocorrelation function.
