13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

192

of our linear regression. The next step is to assume that tomorrow’s intercept and slope are equal

to today’s intercept and slope with the addition of some random system noise. This gives it the

nature of a random walk, the behaviour of which is discussed at length in the previous chapter

on white noise and random walk models.

β t+1 = Iβ t + w t (13.32)

Where the transition matrix is set to the two-dimensional indentify matrix, G t = I. This is

one half of the state space model. The next step is to actually use one of the ETFs in the pair

as the "observations".

13.3.2 Applying the Kalman Filter to a Pair of ETFs

To form the observation equation it is necessary to choose one of the ETF pricing series to be

the "observed" variables, y t , and the other to be given by x t , which provides the linear regression

formulation as above:

y t = F t x t + v t (13.33)

⎛ ⎞

1

= (β 0 , β 1 )

⎜ ⎟

⎝ ⎠ + v t (13.34)

x t

Thus we have the linear regression reformulated as a state space model, which allows us to

estimate the intercept and slope as new price points arrive via the Kalman Filter.

13.3.3 TLT and ETF

We are going to consider two fixed income ETFs, namely the iShares 20+ Year Treasury Bond

ETF (TLT) and the iShares 3-7 Year Treasury Bond ETF (IEI). Both of these ETFs track the

performance of varying duration US Treasury bonds and as such are both exposed to similar

market factors. We will analyse their regression behaviour over the last five years or so.

13.3.4 Scatterplot of ETF Prices

We are now going to use a variety of Python libraries, including NumPy, Matplotlib, Pandas

and PyKalman to to analyse the behaviour of a dynamic linear regression between these two

securities. As with all Python programs the first task is to import the necessary libraries:

from __future__ import print_function

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import pandas_datareader as pdr

from pykalman import KalmanFilter

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!