Machine Learning Meets Pair Trading: Predicting and Trading China AH Premiums

Warren Kwan
Warren Kwan
Published in
12 min readJul 11, 2024

Author: David Hou, Zhiyuan Fan

Supervisor: Warren Kwan, Advisory Board Member at Columbia Business School for Financial Studies

A detailed stock market graph overlaying a background of financial district skyscrapers from both Hong Kong and Shanghai. The graph highlights fluctuations in A-shares and H-shares prices, with lines and data points showcasing trading patterns. Additionally, algorithmic symbols and data points interconnect to emphasize the use of machine learning in trading strategies.
Generated by DALL-E

Introduction

In the ever-evolving landscape of financial markets, leveraging our strong Columbia heritage, we explore the application of advanced trading strategies to China AH shares. This research, conducted by David Hou and Zhiyuan Fan from Columbia’s MSFE program, under my supervision as a member of the Advisory Board at CBS for Financial Studies , highlights significant arbitrage opportunities between A-shares and H-shares of Chinese companies. Our work reflects the innovative spirit and commitment to excellence fostered at Columbia, contributing valuable insights to the field of finance.

Before we start!🤵‍♂️

  1. Clap my article 50 times, that will really really help me out.👏
  2. Contact information for the authors: yhou24@gsb.columbia.edu (David Hou), zfan24@gsb.columbia.edu (Zhiyuan Fan), wkwan93@gsb.columbia.edu (Warren Kwan)
  3. Follow me at LinkedIn

Pay Tribute to the following Medium articles:

  1. Advanced Machine Learning and Deep Learning Techniques for Stock Market Analysis
  2. How to Forecast Time Series Data using any Supervised Learning Model

The above articles already covered our techniques and have the corresponding coding. In here, we do not want to repeat what was written.

Background on China AH Shares Class

China AH shares refer to the dual-listing of Chinese companies on both the Shanghai or Shenzhen Stock Exchanges (A-shares) and the Hong Kong Stock Exchange (H-shares). These two classes of shares, despite representing the same company, often exhibit significant differences in valuation due to various factors such as market structure, investor base, and regulatory environment. A-shares are primarily traded by domestic retail investors, while H-shares are predominantly held by foreign institutional investors. This lack of fungibility between A-shares and H-shares creates unique trading opportunities, particularly in the context of the A/H premium, which is the price differential between the two share classes.

Market Dynamics and A/H Premium

The A/H premium has fluctuated over the years, influenced by market cycles and investor behavior. It tends to widen during the final leg of a market drawdown and narrows during the early stages of a risk rally. Fundamental long-short managers often use A/H premium trading as a strategy, while long-only managers can enhance returns by selecting between A- and H-shares based on these trading patterns. Quant fund managers can also identify alpha factors with low market correlation using the A/H premium.

In the context of this article, the focus is on pair trading strategies that exploit the A/H price premium. This involves taking long positions in one class of shares (e.g., A-shares) and short positions in the other (e.g., H-shares) to capitalize on the price differential. The aim is to explore the application of machine learning algorithms, particularly random forests, in China AH pair trading, and evaluate their performance over time.

Our main findings are as follows:

  1. Random forest works extremely well for certain stocks, and short-term momentum factors generally have higher importance than the long-term ones. Among the individual stocks, China Merchants Bank performs the best in terms of return and sharpe ratio. BYD has moderate performance, while Zijin Mining performs the worst. Long-short portfolio generally performs better than a long-only portfolio in terms of return, but can be subject to a higher volatility and thus a lower sharpe ratio.
  2. Transaction fees significantly reduce the strategy’s performance due to high churning, especially for the long-short portfolio. We assumed a transaction fee of 10 bps for both long and short trades and an annualized borrowing cost of 2% for both A-shares and H-shares. In reality, these costs can be higher, particularly for the short trades and A-share borrowing.
  3. Pair Trading in AH shares

This strategy offers several advantages. Firstly, by taking simultaneous long and short positions in China AH shares of the same company, one can hedge out the beta and fundamental risk associated with the company. This allows technical factors, such as momentum, to have a more significant impact on predicting the premium’s movement. Secondly, initiatives like Stock Connect, QFII, and B2B cross-border securities borrowing and lending have increased foreign investors’ access to A-shares for both long and short positions, enhancing the liquidity of China AH pair trading. Thirdly, AH stocks trade in the same time zone, unlike markets such as China-US pair trading, which operate in different time zones. Finally, since these two classes of shares represent the same company, we can ignore fundamental data when applying machine learning to this strategy. In other words, only technical indicators and data are used as input features for the machine learning models. This gives China AH pair trading a natural advantage for execution.

2. Data

Firstly, we manually calculated an index by taking the daily ratio of the A-share closing price to the H-share closing price for four securities over the past 10 years: BYD, China Merchants Bank, Zijin Mining, and CSI/HSI. We adjust all prices to HKD and remove all missing values. The appendix displays the index plot for the four securities, revealing that the China AH premium has fluctuated but gradually declined over the past 10 years, particularly for BYD and Zijin Mining. This decline can be attributed to the Chinese market becoming more efficient and institutionalized, with foreign investors’ access increasing the liquidity of China AH pair trading. We prefer to identify stocks whose index returns can be positively predicted by technical factors over various periods, as this enhances the potential for stable long-term performance.

We then computed the daily percentage change of our index. We define a new variable based on the cumulative return from t+1 to t+n: it is set to 1 if the cumulative return is greater than a positive threshold (e.g., 0.8%), -1 if the return is less than a negative threshold (e.g., -0.8%), and 0 otherwise. This signal serves as our response variable, making it a 3-class classification problem. We use cumulative return over the next n days because it can reduce trading frequency and transaction cost. If the predicted response variable is 1, we will take a long position in the index. In practice, this can be approximately replicated by going long on the A-share and short on the H-share. The features we use to forecast the response variable is a set of technical factors such as moving averages and price momentum, calculated over various time lengths. We exclude fundamental factors, as fundamental risks are hedged out in our pair trading strategy.

3. Random Forest

Machine learning provides significant predictive power for our trading strategy. Unlike traditional methods, ML can capture complex, nonlinear relationships within the data, which are crucial for making accurate predictions in pair trading. In particular, ML models such as random forest can identify intricate patterns that are often missed by simpler models such as logistic regression. This ability to uncover and leverage nonlinear interactions makes ML a valuable tool in enhancing the effectiveness of our trading strategy.

For our classification task, random forest is an ideal choice due to several reasons. Random forest is highly effective for classification problems, which aligns well with our goal of predicting the future movement of the China AH premium. While deep learning models can also capture nonlinearities, they are prone to overfitting, especially with the smaller dataset in our case. Random forest, on the other hand, offers a better balance between fitting the data well and generalizing to new, unseen data. This is particularly important since we train our model separately for different stocks, and the number of factors and samples is relatively small.

Below is an example of the factor importance indicated by random forest trained on one security’s AH ratio index. For each security, we split our dataset into 60% for training and 40% for testing. While the average accuracy of the model is volatile across different stocks, the precision remains around 30% for long-only strategy, which indicates a consistent ability to identify profitable trading opportunities. Precision is the number of true buy signals divided by the total number of buy signal predictions, which is critical for the strategy’s profit capabilities.

From our analysis, we found that the index return on t is the most important factor. Most technical factors, excluding the signal, have similar significance. However, short-term momentum indicators exhibit slightly higher importance compared to long-term ones. This suggests that short-term momentum might be a critical predictor in our pair trading strategy, possibly because short-term price movements are more responsive to immediate AH premium conditions and sentiment difference, which are crucial for arbitrage opportunities in the China AH market.

4. Trading Strategy and Backtest Result

We use our trained random forest model to forecast the signal (response variable) at the end of each trading day. We then adjust our positions accordingly. If the predicted signal is 1, indicating that the index is expected to rise by more than the threshold the next trading day, we will take a long position in A-shares and a short position in H-shares to capture the expected increase. If the signal is 0, we will unwind all positions. If the signal is -1, we will short A-shares and long H-shares instead. When calculating actual cumulative returns during the backtest, we use the daily cumulative return of A-shares minus that of H-shares instead of the index cumulative return, as the latter is not directly replicable in practice. This means we are employing a self-financing strategy: selling H-shares and using the entire proceeds to buy A-shares, or vice versa, without requiring any additional capital. We also factor in a transaction fee of 10 bps for both long and short positions in A-shares and H-shares, and an annualized borrowing cost of 2%, during the backtest. For each stock, we will implement two trading strategies and compare their performance: a long/short strategy and a long-only strategy. This comparison is important because, in practice, shorting the index is more challenging due to the limited access to A-shares for short-selling and the potentially higher borrowing cost. Next, we test our strategy using various sets of tuning parameters. We select cumulative return days (n) from 1, 2, 5, and 10, and adjust the threshold from 0.6% to 0.9% in 0.1% increments. The optimal combination of parameters is determined based on the highest long-only after-fee return for China Merchants Bank. The results indicate that n = 1 (daily trading frequency) and a threshold of 0.6% yield the best outcome, and we apply this set of parameters to all securities.

For all of the securities, we present backtest results and summary statistics for long-only and long-short portfolios over the past 4 years, both with and without all the relevant costs.

4.1 Portfolio Backtest (BYD, CM, Zijin)

Long-only portfolio: excluding cost (top) and including cost (bottom)

Long-short portfolio: excluding cost (top) and including cost (bottom)

4.2 CSI / HSI

Long-only portfolio: excluding cost (bottom) and including cost (top)

Long-short portfolio: excluding cost (bottom) and including cost (top)

5. Discussion

In general, BYD and China Merchants Bank exhibit better performance compared to Zijin Mining and the CSI / HSI Index. Zijin Mining is the worst performing stock, displaying a significant volatility, maximum drawdown and negative sharpe ratio. This performance disparity may imply that larger-cap stocks or more renowned AH names like China Merchants Bank and BYD tend to have more stable performance over time due to their higher liquidity and more stable shareholder structure. However, this hypothesis can only be confirmed by generalizing the model’s results to more China AH stocks.

Although CSI / HSI is not exactly a China AH pair trading strategy due to the different underlying components, the correlation between CSI and HSI has gradually increased over the past decade due to stronger economic ties and market integration. This suggests that CSI / HSI could become a more suitable candidate for delta one pair trading. However, the historical data used to train the model may not fully capture the current or future patterns.

When comparing the long-only and long-short strategies, BYD and China Merchants Bank show a clear advantage for the long-short strategy, even after accounting for transaction costs. Conversely, for Zijin Mining and the CSI / HSI Index, the results are less certain. We evaluate our strategy using different sets of tuning parameters, such as trading frequency and thresholds. Although the optimal parameters identified in part 4 indicate that transaction costs significantly reduce the strategy’s returns, the highest return is achieved with daily trading. While more frequent trading can lead to increasing transaction costs, higher potential gross return tends to counterbalance these costs. For example, daily trading frequency reveals that the long-only trading strategy averages 36 trades per 252 trading days, whereas the long-short strategy averages 75.5 trades per 252 trading days across different stocks.

There are a few limitations in our analysis. Firstly, a more rigorous method for selecting the optimal set of tuning parameters can be achieved through the use of a genetic algorithm. Secondly, our factor values were calculated using the closing price of the ratio index to determine the position at the end of each trading period. However, this approach is challenging to implement in practice because AH shares close at different times. Additionally, it is difficult to open or close positions exactly at the closing price due to time constraints. A better approach might be to use data from 10 minutes before the market closes, allowing sufficient time for trading.

6. Conclusion

In conclusion, our study highlights the significant potential of machine learning algorithms, particularly random forests, in predicting and pair trading China AH premiums. The analysis revealed that short-term momentum indicators are slightly more critical than long-term ones for predicting trading signals. This insight is crucial for developing more effective trading strategies.

Our findings indicate that larger-cap stocks like China Merchants Bank and BYD tend to deliver better and more stable performance, while smaller-cap stocks such as Zijin Mining exhibit higher volatility. The long-short strategy generally outperforms the long-only strategy in terms of return, despite higher volatility and increased transaction costs. This demonstrates the efficacy of pair trading in hedging against market risks and capturing arbitrage opportunities.

However, transaction fees significantly impact the performance of our strategies, particularly the long-short portfolio. This emphasizes the need to consider trading costs when implementing these strategies in real-world scenarios.

Future research should focus on refining model parameters and expanding the dataset to include a broader range of AH stocks. This will help generalize our findings and improve the robustness of our trading strategies. Additionally, exploring advanced optimization techniques, such as genetic algorithms, could further enhance the selection of optimal tuning parameters.

Overall, our study underscores the value of integrating machine learning into financial trading strategies, providing a pathway for more informed and profitable trading decisions in the China AH market.

Before you go🤵‍♂️

  1. Clap my article 50 times, that will really really help me out.👏
  2. Follow me at LinkedIn

Appendix

--

--