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.

191

13.3 Dynamic Hedge Ratio Between ETF Pairs Using the

Kalman Filter

A common quant trading technique involves taking two assets that form a cointegrating relationship

and utilising a mean-reverting approach to construct a trading strategy. This can be

carried out by performing a linear regression between the two assets (such as a pair of ETFs)

and using this to determine how much of each asset to long and short at particular thresholds.

One of the major concerns with such a strategy is that any parameters introduced via this

structural relationship such as the hedging ratio between the two assets are likely to be timevarying.

They will not be fixed throughout the period of the strategy. In order to improve

profitability it would be useful if we could determine a mechanism for adjusting the hedging

ratio over time.

One approach to this problem is to utilise a rolling linear regression with a lookback window.

This involves updating the linear regression on every bar so that the slope and intercept terms

"follow" the latest behaviour of the cointegration relationship. However it also introduces another

free parameter into the strategy–the lookback window length. This must be optimised often via

cross-validation.

A more sophisticated approach is to utilise a state space model that treats the "true" hedge

ratio as an unobserved hidden variable and attempts to estimate it with "noisy" observations.

In our case this means the pricing data of each asset.

The Kalman Filter performs exactly this task. In the previous section we took an in-depth

look at the Kalman Filter and how it could be viewed as a Bayesian updating process.

In this section we are going to make use of the Kalman Filter via the PyKalman Python library

to help us dynamically estimate the slope and intercept (and hence hedging ratio) between a pair

of ETFs.

This technique will ultimately be backtested with QSTrader in a later chapter. It will enable

us to see how performance of such a strategy has changed in the last few years.

The plots in this chapter were largely inspired by and extended from a post[74] written by

Aidan O’Mahoney who runs The Algo Engineer blog. Head over to his blog to check out more

great posts on algo trading.

13.3.1 Linear Regression via the Kalman Filter

How do we utilise this state space model approach to incorporate the information in a linear

regression?

In a subsequent chapter we define the multiple linear regression as a model which possesses

a response value y that is a linear function of its feature inputs x:

y(x) = β T x + ɛ (13.31)

Where β T = (β 0 , β 1 , . . . , β p ) represents the transpose vector of the intercept β 0 and slopes

β i , with ɛ ∼ N (µ, σ 2 ) represents the error term.

Since we are in a one-dimensional setting we can simply write β T = (β 0 , β 1 ) and x = (x, 1) T .

We set the (hidden) states of our system to be given by the vector β T –the intercept and slope

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

Saved successfully!

Ooh no, something went wrong!