How to apply machine learning for cross-sectional momentum trading?
Have you ever wondered if we can use machine learning to select stocks to create a cross-sectional momentum portfolio? The cross-sectional momentum has become a subject of considerable research and application in both academia and traders in recent decades.
In this post, we will explore how machine learning can be implemented for cross-sectional momentum trading.
All the concepts covered in this post are taken from the Quantra course Advanced Momentum Trading: Machine Learning Strategies. You can preview the concepts taught in this post by clicking on the free preview button and going to Section 26 and Unit 3 of the course.
Note: The links in this tutorial will be accessible only after logging into quantra.quantinsti.com.
Note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice.
Complexity level: Advanced
In this post, we will cover the following topics:
- An example of a cross-sectional momentum strategy
- Need for a more refined approach
- How to apply machine learning for cross-sectional momentum trading?
- What is hierarchical clustering?
- How to use hierarchical clustering for cross-sectional momentum trading?
If you are new to machine learning, Python for Machine Learning in Finance course would be helpful.
An Example of a Cross-Sectional Momentum Strategy
A cross-sectional momentum strategy is a trading strategy that involves ranking assets within a particular universe (e.g., stocks, currencies, commodities) based on their recent performance and investing in the top performers while shorting the bottom performers.
It exploits the tendency of assets that have performed well in the recent past to continue performing well in the near future, and vice versa. You can learn more about the cross-sectional momentum strategy and its modification by watching the video in the course Advanced Momentum Trading: Machine Learning Strategies.
Need for a More Refined Approach
Traditional momentum strategies focus on short-term performance for stock selection, typically over a month, but overlook momentum's evolution over time. An alternative approach involves analysing momentum's month-over-month changes, providing a deeper understanding of its dynamics and enabling a better understanding of the stock’s momentum to create a cross-sectional momentum portfolio.
This is where machine learning can help us!
How to Apply ML for Cross-Sectional Momentum Trading?
Machine learning algorithms such as clustering algorithms can be used to consider multiple factors to group the stocks according to their similarities. For example, monthly returns of stocks in the last 12 months can be used as features for a machine learning model to group the stocks with similar momentum.
Once the groups of stocks are formed, long positions can be taken in the group of stocks with the highest recent performance and short positions can be taken in the group of stocks with the lowest recent performance to create a cross-sectional momentum portfolio.
Hierarchical clustering is one such machine learning algorithm that can be used to group stocks based on similarities in their momentum.
What is Hierarchical Clustering?
Hierarchical clustering is a popular machine-learning algorithm for grouping elements. It creates groups so that elements within a group are similar to each other and different from elements in other groups. You can gain an intuition of hierarchical clustering by watching the video in the course Advanced Momentum Trading: Machine Learning Strategies.Clusters are visually represented in a hierarchical tree called a dendrogram.
How To Use Hierarchical Clustering for Cross-Sectional Momentum Trading?
For cross-sectional momentum trading, the hierarchical clustering algorithm can be used to cluster or group the stocks with similar momentum.
For this, features such as monthly returns of stocks in the last 12 months for every single month can be passed as features to the clustering algorithm. This would result in multiple clusters of stocks grouped based on the similarity in momentum.
However, we can stop this clustering process at a specific number of clusters, say 5 clusters.
The above dendrogram has five clusters with 20, 46, 20, 3, and 11 stocks each where each of the clusters has stocks of similar momentum. You can check this unit for more ways to customise the clustering process for creating a cross-sectional momentum portfolio.
Once the clusters are formed, perform the following steps to create a cross-sectional momentum portfolio.
- Find the performance of each cluster in the last 12 months.
- Go long in stocks of cluster with the highest performance.
- Go short in stocks of cluster with the worst performance.
- Hold the positions for a holding period of one month
Steps 2 and 3 will result in a cross-sectional momentum portfolio. Repeat steps 1 to 4 after every holding period to repeat the process of clustering and rebalancing the portfolio.
The following is the performance of the cross-sectional momentum portfolio created using the top 100 high average daily turnover stocks of the S&P 500 index. The portfolio was rebalanced every single month from 2015 to 2023. This ML-based cross-sectional momentum strategy increased the capital by 3.5 times in the span of 8 years with a limited maximum drawdown of 29%.
Note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice.
The detailed performance analysis is depicted in the following plots.
The Python code to create a cross-sectional momentum portfolio and study its performance is covered in the course Advanced Momentum Trading: Machine Learning Strategies.
What to do next?
- Go to this course
- Click on
- Go through 10-15% of course content
- Drop us your comments and queries on the community
IMPORTANT DISCLAIMER: This post is for educational purposes only and is not a solicitation or recommendation to buy or sell any securities. Investing in financial markets involves risks and you should seek the advice of a licensed financial advisor before making any investment decisions. Your investment decisions are solely your responsibility. The information provided is based on publicly available data and our own analysis, and we do not guarantee its accuracy or completeness. By no means is this communication sent as the licensed equity analysts or financial advisors and it should not be construed as professional advice or a recommendation to buy or sell any securities or any other kind of asset.