Is pairs trading still profitable? Pairs trading has been a popular short-term speculation strategy in quantitative methods of speculation. The theory behind this strategy is fairly straightforward. Under the premise of high positive correlation between two stocks, practitioners match a long position with a short position in two stocks that are proven to be economically linked. As a result, if the prices converge as history tells us, the practitioners would profit [1].
In order to better demonstrate our strategy, we selected pairs of stocks from the NASDAQ 100 index given their “linkage” to each other.
On top of that, we conducted cointegration tests on all stocks chosen given that a positive high correlation between the stocks we wish to perform the strategy on is crucial to the success of the performance. Once data selection was applied, we picked the pair of stocks that showed the highest cointegration between them. In addition, we would then use this chosen pair for the future simulation. However, in order to avoid data mining, we conducted a train test split later in our strategy simulation.
Moreover, with the pair we chose, we then operated our pairs trading strategy on it in hope to retrieve some profits. The fundamental rules in our strategy is that we long one share of the underpriced stock and short one share of the overpriced stock if the ratio of the stocks’ prices reaches beyond or below the cutoff, under the assumption that we had one share of each to start. We then choose to liquidate once the spread narrows to a specified level.
From there on, we looked at multiple pairs selected and developed an optimal portfolio based on our risk aversion assumption to further examine the strategy. Which eventually shows us the return from our strategy.
Methodology
I. Data
We first obtained our data from Bloomberg terminal, using the built in excel to get the stock prices of 100 stocks in the NASDAQ 100 index from 5/24 – 12/3 in 30-minute increments for a total of 3250 data points. We then cleaned the data by checking for NA values and created an 80/20 training test split . In order to select the “relevant” pairs, we
measured the cointegration p-values of each pair of stocks using the coint() function in the statsmodels.tsa.stattools package, and looked at the ones that are most cointegrated.
To select the pairs satisfying our requirement, we set the cutoff as 0.001 instead of 0.05 in our project. Our reasoning is that since the stocks are in the same index, if we only look at the 0.05 cutoff, we end up with close to half of the stocks being significantly cointegrated. Thus, 0.001 will serve better for the purpose of this project, and we will be able to find better cointegrated pairs. Finally, we incorporate all pairs with p-value lower than the cutoff into our portfolio.
II. Trading
For our algorithm, we made the following assumptions:
1. Firstly, we start with one share of each stock, and when we buy and sell, we “all in” -either buying or selling one share, or an amount equivalent to the ratio between two stocks.
2. Secondly, there is no transaction cost [3], instead we assume a 0.05% slippage estimate [2] and other factors that we might need to subtract from our returns.
3. Thirdly, when we apply our strategy to a portfolio of pairs, we assume that the investor is risk averse.
Moreover, for the first assumption, we try to keep our trading simple by not trading partial amounts of stocks.
Is pairs trading still profitable?
For the second assumption, we note that recent developments in trading have seen a dramatic decrease in transaction costs due to the rise of Robinhood in the past few years, especially during the COVID-19 pandemic. Thus while in the past papers such as [1] Gatev, E., Goetzmann, W., & Rouwenhorst, K. (1999, March) have considered proportional transaction costs of less than 100 bp, we have reason to believe their assumptions are outdated.
For the sake of demonstration, we will first use the best pair we have found, which is the one with the lowest p-value for cointegration, to illustrate our trading process. Our algorithm involves first calculating the hedge ratio as stock1/stock2 (Figure1), the 30 day rolling mean, and the n day rolling mean and standard deviation (Figure2), where n < 30 and needs to be optimized for each pair (Table 1). As a result, we make transactions off the z-score (Figure3), which also needs to be optimized for each stock in our portfolio and has a default value of 1 (Table1).
We trade in the following way: if the z-score of our ratios is greater than our z-score threshold, we buy 1 share of stock 1 and sell an amount of stock 2 equal to the ratio of stock1/stock2. In addition, if the z-score falls below our threshold, we sell 1 share of stock 2 and buy an amount of stock 1 equal to the ratio of stock1/stock2. So whenever the z-score of our ratios is greater than the absolute value of our z-score threshold, our profit does not change, but the amounts we hold in the stocks change. Furthermore, when the absolute value of the z-score of our ratios falls below 0.75, we liquidate our shares and add the profit to our returns. Finally, we subtract the transaction costs from our returns.
Firstly, (Figure 1: Ratios(stock1/stock2) )
Secondly, (Figure 2: Ratios with rolling MAs)
Thirdly, (Figure 3 Rolling ratio Z-score)
Fourthly, (Figure 4)
III. Optimization
For each pair we chose, we performed an optimization of total returns before using them in our portfolio. The parameters we need to optimize for our algorithm include window and z-score. For window values we tested 24 values from 2 to 25, and for z-score values we tested 10 values from 1 to 5.5 in increments of 0.5. Our optimization results are included in Table1.
As for the optimization of the portfolio with ten pairs of stocks, we chose to reduce the volatility based on our risk aversion assumption. Recalling that an unconstrained optimal portfolio problem can be expressed with the formula below, we solve for the weight of each pair with the np.linal package in python.
With the given weight and the profit gained after a series of transactions of pairs, we can calculate the final profit of our portfolio. Furthermore, we use our previously optimized window and z-score values and create a vector of returns at each data point. In addition, we also created a covariance matrix of these returns for the ten pairs of stocks. Moreover, we then solved the maximization problem to obtain a series of weights.
Weight of initial portfolio
Weight of optimized portfolio
Results and Discussion
Here are the optimized values from the training set
| Pairs | 26/72 | 49/50 49/57 49/65 | 49/77 |
| z-score | 1 | 1 1 1 | 1 |
| window | 3 | 2 2 14 | 2 |
| profit | 1857.18 | 116.10 158.27 10.2 | 292.69 |
| Pairs | 56/67 | 93/94 93/96 93/99 | 93/101 |
| z-score | 1 | 1 1 1 | 1 |
| window | 3 | 2 10 4 | 2 |
| profit | 4009.77 | 1322.20 270.81 768.54 | 1317.63 |
Here are the results of our optimization and the weights we obtained. From the results above, we can gain the trading consequence, so that optimized weight of pairs in the portfolio can also be led to.
In the following charts, we compare the profit 1056 earned from optimized portfolio and 256 from the initial portfolio, the result of optimized portfolio is obviously better than that of the initial portfolio.
Profits of each pair in initial portfolio
Profits of each pair in optimized portfolio
Here are the optimized values obtained from the test set
| Pairs | 26/72 | 49/50 49/57 49/65 | 49/77 |
| z-score | 1 | 1 1 1 | 1 |
| window | 3 | 2 2 14 | 2 |
| profit | 373.46 | 156.80 86.65 61.35 | 90.32 |
| Pairs | 56/67 | 93/94 93/96 93/99 | 93/101 |
| z-score | 1 | 1 1 1 | 1 |
| window | 3 | 2 10 4 | 2 |
| profit | 496.62 | 73.21 203.18 204.63 | 398.80 |
We utilize the same pairs trading strategy and optimization on the test data, in addition compare the trading consequence of training data and test data. Furthermore, it is obvious that the optimized trading strategy on test data can gain better profit than the initial trading strategy. Also, the profit produced by training data is higher than that produced by test data, which is the rational result.
Optimized Portfolio Return of Training data vs. Test data: 1056 vs. 257 Initial Portfolio Return of Training data vs. Test data.: 116 vs. 45
Is pairs trading still profitable? Limitations
1. Time constraint
In conclusion, our project, the period of time in which we chose the data is around 6 months, and it can be too short to capture all the fluctuations in the stock market. As a result, the project may not be a fair representation of the whole market and its result may not apply to all either. However, the data is enough for the sake of this project to illustrate the fundamental process of this strategy. Lastly, for any future studies, it may be informative to look at a longer period of time.
Is pairs trading still profitable?
2. Gradient Overweight and Underweight
For any rational investors in the market, one will not go all in during every transaction. Given that, gradient overweighting and underweighting would be a more reasonable behavior in transactions. However, it is beyond the scope of our project, and “all-in” is able to suffice the purpose of demonstrating pairs trading strategy.
3. Take risk-free rate into consideration
Risk-free rate is commonly incorporated in past research to calculate an excess return. However, we did not include it as part of our project. As a result, the return we got is a gross return, instead of excess return.
4. Stoploss and Takeprofit
We didn’t set a target profit or loss for our transactions, so that we often faced more risks of profit retracement if target profit was not preinstalled, and more risk to suffer a margin closeout or to blow-up if the loss continued spreading.
5. Intraday Data Shortfalls
Data might not be IID anymore, so there might be more autocorrelation between. But we are making a buy/sell decision based on the past and executed at the present.
Is pairs trading still profitable? References
Firstly, [1] Gatev, E., Goetzmann, W., & Rouwenhorst, K. (1999, March). Pairs Trading: Performance of A Relative Value Arbitrage Rule. Retrieved from https://www.nber.org/system/files/working_papers/w7032/w7032.pdf
Secondly, [2] Kakushadze, Z. and Serur, J.A. 151 Trading Strategies. Cham, Switzerland: Palgrave Macmillan, an imprint of Springer Nature, 1st Edition (2018), XX, 480 pp; ISBN 978-3-030-02791-9https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3247865
Thirdly, [3] Schuler Capital Management LLC. Transaction Costs. Retrieved from https://www.schulercapital.com/transaction-cost-assumptions.html [4] Xing, H. (2019, Nov 24). A Singular Stochastic Control Approach for Optimal Pairs Trading with Proportional Transaction Costs. Retrieved from https://arxiv.org/abs/1911.10450v1



