ML for trading – strategies and use cases
In practice, we apply ML to trading in the context of a specific strategy to meet a certain business goal. In this section, we briefly describe how trading strategies have evolved and persified, and outline real-world examples of ML applications, highlighting how they relate to the content covered in this book.
The evolution of algorithmic strategies
Quantitative strategies have evolved and become more sophisticated in three waves:
- In the 1980s and 1990s, signals often emerged from academic research and used a single or very few inputs derived from market and fundamental data. AQR, one of the largest quantitative hedge funds today, was founded in 1998 to implement such strategies at scale. These signals are now largely commoditized and available as ETF, such as basic mean-reversion strategies.
- In the 2000s, factor-based investing proliferated based on the pioneering work by Eugene Fama and Kenneth French and others. Funds used algorithms to identify assets exposed to risk factors like value or momentum to seek arbitrage opportunities. Redemptions during the early days of the financial crisis triggered the quant quake of August 2007, which cascaded through the factor-based fund industry. These strategies are now also available as long-only smart beta funds that tilt portfolios according to a given set of risk factors.
- The third era is driven by investments in ML capabilities and alternative data to generate profitable signals for repeatable trading strategies. Factor decay is a major challenge: the excess returns from new anomalies have been shown to drop by a quarter from discovery to publication, and by over 50 percent after publication due to competition and crowding.
Today, traders pursue a range of different objectives when using algorithms to execute rules:
- Trade execution algorithms that aim to achieve favorable pricing
- Short-term trades that aim to profit from small price movements, for example, due to arbitrage
- Behavioral strategies that aim to anticipate the behavior of other market participants
- Trading strategies based on absolute and relative price and return predictions
Trade-execution programs aim to limit the market impact of trades and range from the simple slicing of trades to match time-weighted or volume-weighted average pricing. Simple algorithms leverage historical patterns, whereas more sophisticated versions take into account transaction costs, implementation shortfall, or predicted price movements.
HFT funds most prominently rely on very short holding periods to benefit from minor price movements based on bid-ask or statistical arbitrage. Behavioral algorithms usually operate in lower-liquidity environments and aim to anticipate moves by a larger player with significant price impact, based, for example, on sniffing algorithms that generate insights into other market participants' strategies.
In this book, we will focus on strategies that trade based on expectations of relative price changes over various time horizons beyond the very short term, dominated by latency advantages, because they are both widely used and very suitable for the application of ML.
Use cases of ML for trading
ML is capable of extracting tradable signals from a wide range of market, fundamental, and alternative data and is thus applicable to strategies targeting a range of asset classes and investment horizons. More generally, however, it is a flexible tool to support or automate decisions with quantifiable goals and digital data relevant to achieving these goals. Therefore, it can be applied at several steps of the trading process. There are numerous use cases in different categories, including:
- Data mining to identify patterns, extract features, and generate insights
- Supervised learning to generate risk factors or alphas and create trade ideas
- The aggregation of inpidual signals into a strategy
- The allocation of assets according to risk profiles learned by an algorithm
- The testing and evaluation of strategies, including through the use of synthetic data
- The interactive, automated refinement of a strategy using reinforcement learning
We briefly highlight some of these applications and identify where we will demonstrate their use in later chapters.
Data mining for feature extraction and insights
The cost-effective evaluation of large, complex datasets requires the detection of signals at scale. There are several examples throughout the book:
- Information theory helps estimate a signal content of candidate features and is thus useful for extracting the most valuable inputs for an ML model. In Chapter 4, Financial Feature Engineering – How to Research Alpha Factors, we use mutual information to compare the potential values of inpidual features for a supervised learning algorithm to predict asset returns. Chapter 18 in De Prado (2018) estimates the information content of a price series as a basis for deciding between alternative trading strategies.
- Unsupervised learning provides a broad range of methods to identify structure in data to gain insights or help solve a downstream task. We provide several examples:
- In Chapter 13, Data-Driven Risk Factors and Asset Allocation with Unsupervised Learning, we introduce clustering and dimensionality reduction to generate features from high-dimensional datasets.
- In Chapter 15, Topic Modeling – Summarizing Financial News, we apply Bayesian probability models to summarize financial text data.
- In Chapter 20, Autoencoders for Conditional Risk Factors and Asset Pricing, we use deep learning to extract nonlinear risk factors conditioned on asset characteristics and predict stock returns based on Kelly et al. (2020).
- Model transparency emphasizes model-specific ways to gain insights into the predictive power of inpidual variables and introduce a novel game-theoretic approach called SHapley Additive exPlanations (SHAP). We apply it to gradient boosting machines with a large number of input variables in Chapter 12, Boosting Your Trading Strategy, and the Appendix, Alpha Factor Library.
Supervised learning for alpha factor creation
The most familiar rationale for applying ML to trading is to obtain predictions of asset fundamentals, price movements, or market conditions. A strategy can leverage multiple ML algorithms that build on each other:
- Downstream models can generate signals at the portfolio level by integrating predictions about the prospects of inpidual assets, capital market expectations, and the correlation among securities.
- Alternatively, ML predictions can inform discretionary trades as in the quantamental approach outlined previously.
ML predictions can also target specific risk factors, such as value or volatility, or implement technical approaches, such as trend-following or mean reversion:
- In Chapter 3, Alternative Data for Finance – Categories and Use Cases, we illustrate how to work with fundamental data to create inputs to ML-driven valuation models.
- In Chapter 14, Text Data for Trading – Sentiment Analysis, Chapter 15, Topic Modeling – Summarizing Financial News, and Chapter 16, Word Embeddings for Earnings Calls and SEC Filings, we use alternative data on business reviews that can be used to project revenues for a company as an input for a valuation exercise.
- In Chapter 9, Time-Series Models for Volatility Forecasts and Statistical Arbitrage, we demonstrate how to forecast macro variables as inputs to market expectations and how to forecast risk factors such as volatility.
- In Chapter 19, RNNs for Multivariate Time Series and Sentiment Analysis, we introduce recurrent neural networks that achieve superior performance with nonlinear time series data.
Asset allocation
ML has been used to allocate portfolios based on decision-tree models that compute a hierarchical form of risk parity. As a result, risk characteristics are driven by patterns in asset prices rather than by asset classes and achieve superior risk-return characteristics.
In Chapter 5, Portfolio Optimization and Performance Evaluation, and Chapter 13, Data-Driven Risk Factors and Asset Allocation with Unsupervised Learning, we illustrate how hierarchical clustering extracts data-driven risk classes that better reflect correlation patterns than conventional asset class definition (see Chapter 16 in De Prado 2018).
Testing trade ideas
Backtesting is a critical step to select successful algorithmic trading strategies. Cross-validation using synthetic data is a key ML technique to generate reliable out-of-sample results when combined with appropriate methods to correct for multiple testing. The time-series nature of financial data requires modifications to the standard approach to avoid look-ahead bias or otherwise contaminating the data used for training, validation, and testing. In addition, the limited availability of historical data has given rise to alternative approaches that use synthetic data.
We will demonstrate various methods to test ML models using market, fundamental, and alternative data sources that obtain sound estimates of out-of-sample errors.
In Chapter 21, Generative Adversarial Networks for Synthetic Time-Series Data, we present generative adversarial networks (GANs), which are capable of producing high-quality synthetic data.
Reinforcement learning
Trading takes place in a competitive, interactive marketplace. Reinforcement learning aims to train agents to learn a policy function based on rewards; it is often considered as one of the most promising areas in financial ML. See, for example, Hendricks and Wilcox (2014) and Nevmyvaka, Feng, and Kearns (2006) for applications to trade execution.
In Chapter 22, Deep Reinforcement Learning – Building a Trading Agent, we present key reinforcement algorithms like Q-learning to demonstrate the training of reinforcement learning algorithms for trading using OpenAI's Gym environment.