Get startedGet started for free

Plotting pairs of data

Time series data is often presented in a time series plot. For example, the index values from the eu_stocks dataset are shown in the adjoining figure. Recall, eu_stocks contains daily closing prices from 1991-1998 for the major stock indices in Germany (DAX), Switzerland (SMI), France (CAC), and the UK (FTSE).

It is also useful to examine the bivariate relationship between pairs of time series. In this exercise we will consider the contemporaneous relationship, that is matching observations that occur at the same time, between pairs of index values as well as their log returns. The plot(a, b) function will produce a scatterplot when two time series names a and b are given as input.

To simultaneously make scatterplots for all pairs of several assets the pairs() function can be applied to produce a scatterplot matrix. When shared time trends are present in prices or index values it is common to instead compare their returns or log returns.

In this exercise, you'll practice these skills on the eu_stocks data. Because the DAX and FTSE returns have similar time coverage, you can easily make a scatterplot of these indices. Note that the normal distribution has elliptical contours of equal probability, and pairs of data drawn from the multivariate normal distribution form a roughly elliptically shaped point cloud. Do any of the pairs in the scatterplot matrices exhibit this pattern, before or after log transformation?

This exercise is part of the course

Time Series Analysis in R

View Course

Exercise instructions

  • Use plot() to make a scatterplot of DAX and FTSE.
  • Use pairs() to make a scatterplot matrix of the four indices in eu_stocks.
  • Generate logreturns from eu_stocks using diff(log(___)).
  • Use another call to plot() to generate a simple time series plot of logreturns.
  • Use another call to pairs() to generate a scatterplot matrix for logreturns.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Make a scatterplot of DAX and FTSE
plot(___, ___)

# Make a scatterplot matrix of eu_stocks
pairs(___)

# Convert eu_stocks to log returns
logreturns <- 

# Plot logreturns


# Make a scatterplot matrix of logreturns

Edit and Run Code