Pairs Trading – Introduction & Kalman Filter

Pairs trading strategy is based on the principle of long-short equities (such as stocks) which are highly correlated. The stocks are highly correlated which means that most of the time the prices move together in the same direction however opportunity arises when they momentarily move in the opposite direction. Pairs trading involves using two stocks that belong to the same sector and the reason being, as they belong to the same sector they are exposed to the same market factor. Occasionally their relative stock prices will diverge due to certain events but will revert to the long-running mean. The trade is executed on the belief that any deviation in the relationship will be rectified in the long run. This strategy was pioneered by Garry Bamberger and Nunzio Tartaglia at Morgan Stanley around the 1980s. Most hedge funds rely on this strategy today as well.

So far we have stated that the stocks in the pairs trading strategy should be correlated which can be checked easily by the Spearman rho (which ranges between +/- 1, both inclusive) however that is not the only criteria. We will find numerous stocks which are correlated due to macroeconomic factors but we can not execute the strategy on them. The stocks in question should also be cointegrated. “Cointegration tests identify scenarios where two or more non-stationary time series are integrated together in a way that they cannot deviate from equilibrium in the long term. The tests are used to identify the degree of sensitivity of two variables to the same average price over a specified period of time.” We can use various tests like the Engle-Granger Two-Step Method, Phillips-Perron etc. to check for cointegration.

However, finding the cointegrated pairs of stock is the first hurdle, and modeling them is the second one. The relationship keeps on changing and there is a dynamic hidden factor that affects them and is not easy to model. As stated earlier the strategy involves going long (buying) on one stock and shorting (selling) the other one. However, we need to know the quantity / the number of stock we need to sell if we buy x number of stock. The relationship is not 1:1. The ratio keeps on changing with time and we need to model them to arrive at the correct hedge ratio (akin to delta hedging). This is where the Kalman filter comes in.

The idea of the Kalman filter is derived from the field of Modern Control Systems. The model is basically a state-space used to estimate an unknown “hidden” variable by observing the related variables and by modeling those relationships. Imagine there is a flight that we want to track. We use a radar that sends a beam every 3 seconds in the direction of the flight (track cycle of 3 secs). The radar uses the beam to estimate the current position and the velocity of the flight so that it can send the beam to the right coordinates after a gap of 3 secs. Theoretically, if we know the location, the direction, and the speed then we can easily predict the location of the flight. However that is not the case, “The error magnitude depends on many parameters, such as radar calibration, the beam width, the magnitude of the return echo, etc. The error included in the measurement is called Measurement Noise. Furthermore, the target motion is not strictly aligned to motion equations due to external factors such as wind, air turbulence, pilot maneuvers, etc. The dynamic model error (or uncertainty) is called Process Noise”. Due to this, the estimation can be far off from the actual location. In this particular scenario, the radar can end up sending the beam to a completely different location. In order to increase the accuracy, a prediction algorithm is needed that considers all the uncertainty and that is where the Kalman filter comes in.

The Kalman filter is underpinned by Bayesian probability theory and enables an estimate of the hidden variable in the presence of noise. This overcomes the linear regression where only one slope (or beta) is used for the investment time horizon. Linear regression does not capture both uncertainty and dynamism in the real market. On the other hand, the Kalman filtering framework provides a dynamic estimate of the hedge ratio (beta or slope) in a pairs trading strategy.

In Kalman filtering, we estimate the hidden state (beta in this case) and use the estimated hidden state to estimate the observed variable (stock price in this case).

Stock 1=𝛽∗Stock 2 + 𝜖 

The above equation is used to estimate stock price where 𝜖 is a white noise with ~𝑁(0,𝑉𝑒). 𝛽 is a hidden state and is also known as a hedge ratio. While

𝛽𝑡=𝛽𝑡−1+𝜔 

The above-hidden state equation is used to estimate the next state of the hedge ratio. 𝜔 is a white noise with ~𝑁(0,𝑉c).

Where

𝑉𝑒 is the variance of the residual

𝑉c is the covariance of the transition state

Then we have to iterate, for each iteration. For every time step:

  1. Form the current state and the state transition model predict the upcoming state of the hidden variable
  2. Which is then updated in the state covariance prediction matrix
  3. Predict the upcoming value of the observed variable using the above prediction
  4. Which is then updated in the measured covariance prediction
  5. Compute the residual
  6. Calculate the Kalman gain
  7. Update the estimate of the hidden variable
  8. Update the state covariance prediction

Computing the quantity is one aspect but executing the trade is altogether a different ball game. Firstly we have to factor in the transaction costs and each time we rebalance we will incur some costs. Secondly, there has to be a deep enough market to execute high-volume trades. Thirdly the bid-ask spread will widen as we keep on executing large trades direction. As both the stock belongs to the same industry we will be exposed to the sector-specific risks. At the end of the day, all strategies seem easy to execute on paper but things turn ugly when one tries to execute them in real-world scenarios!!

Leave a comment

search previous next tag category expand menu location phone mail time cart zoom edit close