Introduction

Pairs trading is a non-directional, market-neutral trading strategy which seeks to identify the price divergence from two highly correlated assets. Pairs trading assumes the co-movement and the mean reversion of two asset prices. It indicates that the price of selected assets tend to move together, and when they diverge, we can exploit the investment opportunity by taking a market neutral position as we assume their price will tend to move back to the average price over time. In this algorithm, we use a large family of international exchange-traded funds (ETFs) to examine the performance of the pairs trading strategy.

Method

The selection of pairs

The investment universe consists of 25 international ETFs. The pair selection is based on a rolling time period called the formation period. During each formation period, we save the history closing price of each ETF. Here we use a Python list-like container called deque to keep a fixed-length price series. From these prices, we compute normalized cumulative price indices which are comparable across the ETFs in the group. According to the paper Pairs Trading on International ETFs from Panagiotis, Dimitrios and Tao, here the formation period is 120 days.

Rtn=1t(1+rtn)   for   t=1,2,...,120 rtn=PtPt11

Where rtn is the simple return of the n-th ETF and Rtn is the index value.

For each formation period, we compute the average absolute distance among all pairs in the group and then rank the distances from the smallest to largest to identify the trading opportunities. The top 5 pairs with the smallest distance are used in the subsequent 20 day trading period. The definition of distance is

Dta,b=1120t+1t+120PtaPtb for all pairs a,b

  1. class Pair:
  2. def __init__(self, symbol_a, symbol_b, price_a, price_b):
  3. self.symbol_a = symbol_a
  4. self.symbol_b = symbol_b
  5. self.price_a = np.array(price_a)
  6. self.price_b = np.array(price_b)
  7. # compute normalized cumulative price indices
  8. self.index_a = np.cumprod(self.price_a[1:]/self.price_a[:-1])
  9. self.index_b = np.cumprod(self.price_b[1:]/self.price_b[:-1])
  10. def distance(self):
  11. return 1/120*sum(abs(self.index_a -self.index_b))

The Definition of Divergence

Now we consider the top 5 pairs. For each of the one month trading period, we compute the 120-day normalized cumulative price indices and compare them to a fraction of the distance value Dta,b for each pair (a,b). Assume the threshold is 0.5, if the index value of asset A is greater than asset B by 0.5 times the current distance Dta,b, then we sell asset A and buy asset B. The quantity of A and B is based on the dollar neutral. We invest the same amount of money in the long leg and the short leg, vice versa if the index value of asset B is greater than asset A by 0.5 times the distance. When the difference between index A and index B falls into the range (0.5Dta,b,0.5Dta,b), we liquidate the pair. The above procedure is repeated for all top 5 pairs. At the start of next month, the new pairs are selected and trade for next month.

  1. for i in self.sorted_pairs:
  2. pair = Pair(i[0], i[1], self.history_price[i[0].value], self.history_price[i[1].value])
  3. index_a = pair.index_a[-1]
  4. index_b = pair.index_b[-1]
  5. delta = pair.distance()
  6. if index_a - index_b > self.threshold*delta:
  7. if not self.portfolio[pair.symbol_a].invested and not self.portfolio[pair.symbol_b].invested:
  8. ratio = self.portfolio[pair.symbol_a].price / self.portfolio[pair.symbol_b].price
  9. quantity = int(self.calculate_order_quantity(pair.symbol_a, 0.2))
  10. self.sell(pair.symbol_a, quantity)
  11. self.buy(pair.symbol_b, floor(ratio*quantity))
  12. elif index_a - index_b < -self.threshold*delta:
  13. if not self.portfolio[pair.symbol_a].invested and not self.portfolio[pair.symbol_b].invested:
  14. ratio = self.portfolio[pair.symbol_b].price / self.portfolio[pair.symbol_a].price
  15. quantity = int(self.calculate_order_quantity(pair.symbol_b, 0.2))
  16. self.sell(pair.symbol_b, quantity)
  17. self.buy(pair.symbol_a, floor(ratio*quantity))
  18. # the position is closed when prices revert back
  19. elif self.portfolio[i[0]].invested and self.portfolio[i[1]].invested:
  20. self.liquidate(pair.symbol_a)
  21. self.liquidate(pair.symbol_b)
+ Expand


Reference

  1. Quantpedia - Pairs Trading with Country ETFs

Author

Jing Wu

August 2018