\( \newcommand{\bm}[1]{\boldsymbol{#1}} \newcommand{\textm}[1]{\textsf{#1}} \def\T{{\mkern-2mu\raise-1mu\mathsf{T}}} \newcommand{\R}{\mathbb{R}} % real numbers \newcommand{\E}{{\rm I\kern-.2em E}} \newcommand{\w}{\bm{w}} % bold w \newcommand{\bmu}{\bm{\mu}} % bold mu \newcommand{\bSigma}{\bm{\Sigma}} % bold mu \newcommand{\bigO}{O} %\mathcal{O} \renewcommand{\d}[1]{\operatorname{d}\!{#1}} \)

Exercises

Exercise 15.1 (Mean-reversion)

  1. Generate a random walk and plot it. Is is stationary? Does it revert to the mean?
  2. Generate an AR(1) sequence with autoregressive coefficient less than 1 and plot it. Is is stationary? Does it revert to the mean?
  3. Change the autoregressive coefficient of the AR(1) model and observe how the strength of the mean-reversion changes.

Exercise 15.2 (Cointegration versus correlation) Consider the cointegration model of two time series with a common trend: \[ \begin{aligned} y_{1t} &= x_{t} + w_{1t}\\ y_{2t} &= x_{t} + w_{2t}, \end{aligned} \] where \(x_t\) is a stochastic common trend defined as a random walk, \[ x_{t} = x_{t-1} + w_{t}, \] and the terms \(w_{1t}\), \(w_{2t}\), \(w_{t}\) are i.i.d. residual terms mutually independent, with variances \(\sigma_1^2\), \(\sigma_2^2\), and \(\sigma^2\), respectively.

Generate realizations of such time series with different values for the residual variances and plot the sequences as well as the scatter plot of the series differences (\(\Delta y_{1t}\) versus \(\Delta y_{2t}\)). Choose the appropriate values of the variances to obtain cointegrated time series with low correlation as well as non-cointegrated time series with high correlation.

Exercise 15.3 (Simple pairs trading on AR(1) spread) Generate a synthetic mean-reverting spread with an AR(1) model for the log-prices, implement a simple pairs trading strategy based on thresholds, and plot the cumulative return (ignoring transaction costs).

Note: with a buy position, the portfolio return is the same as that of the spread; with a short position, it is the opposite; and with no position, it is just zero.

Exercise 15.4 (Discovering cointegrated pairs)

  1. Download market data corresponding to several assets (e.g., stocks, commodities, ETFs, or cryptocurrencies).
  2. Implement a pre-screening approach on different pairs based on normalized prices.
  3. Then consider running cointegration tests on the successful pairs from the pre-screening phase. In particular, try some of the following tests:
    • Dickey–Fuller (DF)
    • Augmented Dickey–Fuller (ADF)
    • Phillips–Perron (PP)
    • Pantula, Gonzales-Farias and Fuller (PGFF)
    • Elliott, Rothenberg and Stock DF-GLS (ERSD)
    • Johansen’s Trace Test (JOT)
    • Schmidt and Phillips Rho (SPR)
  4. Plot the spreads of the successful cointegrated pairs as well as some of the unsuccessful ones for comparison.

Exercise 15.5 (Pairs trading with least squares)

  1. Download market data corresponding to a pair of cointegrated assets (e.g., stocks, commodities, ETFs, or cryptocurrencies).
  2. Using an initial window as training data, estimate the hedge ratio \(\gamma\) via least squares.
  3. Using that hedge ratio, compute the normalized spread (with leverage 1) in the remaining window as test data, i.e., a spread obtained using the normalized portfolio \[ \w = \frac{1}{1+\gamma}\begin{bmatrix} \;\;\;1\\ -\gamma \end{bmatrix}. \]
  4. Trade the normalized spread via the thresholded strategy.
  5. Plot the cumulative return ignoring transaction costs.
  6. Plot the cumulative return including transaction costs (e.g., as 30-90 bps of the portfolio turnover).

Exercise 15.6 (Pairs trading with rolling least squares) Repeat Exercise 15.5 but using a rolling least squares to track the hedge ratio over time \(\gamma_t\).

Exercise 15.7 (Pairs trading with Kalman) Repeat Exercise 15.5 but using the Kalman filter to better track the hedge ratio over time \(\gamma_t\).

Exercise 15.8 (Statistical arbitrage with more than two assets)

  1. Download market data corresponding to \(N>2\) cointegrated assets (e.g., stocks, commodities, ETFs, or cryptocurrencies).
  2. Choose a pair of assets and implement pairs trading via least squares.
  3. With all the \(N\) assets, use VECM to obtain \(K>2\) cointegration relationships and then:
    • implement pairs trading with the strongest direction;
    • implement \(K\) parallel pairs trading and combine the result into a final cumulative return plot.
  4. Compare and discuss the three implementations: pairs trading on just two assets, pairs trading on the strongest of the \(K\) directions, and \(K\) parallel pairs trading schemes.