From attention to profit: quantitative trading strategy based on transformer

Zhaofeng Zhang, Banghao Chen, Shengxin Zhu, Nicolas LangrenéarXiv 2024 · arXiv · OpenReview

Abstract

In traditional quantitative trading practice, navigating the complicated and dynamic financial market presents a persistent challenge. Fully capturing various market variables, including long-term information, as well as essential signals that may lead to profit remains a difficult task for learning algorithms. In order to tackle this challenge, this paper introduces Quantformer, an enhanced neural network architecture based on transformers, to build investment factors. By transfer learning from sentiment analysis, Quantformer not only exploits its original inherent advantages in capturing long-range dependencies and modeling complex data relationships, but is also able to solve tasks with numerical inputs and accurately forecast future returns over a given period. This work collects more than 5,000,000 rolling data of 4,601 stocks in the Chinese capital market from 2010 to 2019. The results of this study demonstrated the model's superior performance in predicting stock trends compared with other 100 factor-based quantitative strategies. Notably, the model's innovative use of transformer-like model to establish factors, in conjunction with market sentiment information, has been shown to enhance the accuracy of trading signals significantly, thereby offering promising implications for the future of quantitative trading strategies.

Introduction

While Transformer models have revolutionized Natural Language Processing (NLP), they do not "plug and play" into financial markets due to two primary hurdles: data type mismatch and architecture overkill. Financial data consists of numerical time series (price, volume, turnover) rather than categorical tokens, and the standard sequence-to-sequence decoder is often unnecessary for the single-point prediction tasks required in trading.

The core challenge of quantitative trading: forecasting future trends from historical price and volume data.

Quantformer addresses these issues by treating stock market trends similarly to sentiment analysis, allowing the model to "read" market mood through volatility and liquidity. By modifying the standard Transformer architecture, the model achieves significant outperformance over traditional price-volume factors.

The Quantformer Architecture

The authors introduce a streamlined, encoder-only Transformer architecture with several key innovations:

  • Linear Embedding: Instead of a word-embedding layer, a standard linear layer transforms numerical inputs (daily profit rates and turnover) into a high-dimensional feature space.
  • Temporal Order Preservation: Unlike sentences where word order is flexible, time series data has a rigid temporal order. The authors found that explicit positional encoding was unnecessary, simplifying the model.
  • Simplified Output and Quantile Labeling: The model removes the autoregressive decoder and masking operations. Instead, it ranks stocks into quantiles based on their empirical cumulative distribution function (CDF). Predicting that a stock will be in the "top 20%" of the market is a more stable and learnable signal than predicting exact price changes.
Workflow of factor-based trading strategies, illustrating how stock selection and signal generation lead to portfolio decisions.

Experimental Setup and Datasets

The study utilizes a massive dataset covering 4,601 stocks listed on the Shanghai (SHSE) and Shenzhen (SZSE) exchanges from January 2010 to May 2023. This includes over 5,000,000 rolling data points. The model was benchmarked against the CSI 300 index and 100 traditional price-volume factors sourced from the JoinQuant platform. Features primarily included price fluctuations and turnover rates, adjusted for dividends and stock splits.

Key Results

Quantformer-based strategies demonstrated dominant performance across daily, weekly, and monthly frequencies:

  • Superior Returns: The "Month_1" strategy achieved an Annual Return (AR) of 17.35% and an Annual Excess Return (AER) of 19.43% over the benchmark.
  • Risk-Adjusted Performance: The model recorded a Sharpe Ratio of 0.915, significantly higher than the best traditional factor tested (0.243).
  • Risk Mitigation: The model demonstrated a lower Value-at-Risk (VaR) of 2.81%, indicating superior downside protection.
  • Robustness: When focusing only on the top 1% of predicted performers, the model reached an annual return of 24.71%.

Conclusion and Future Work

Quantformer proves that stripped-down Transformer architectures can effectively capture long-range dependencies in financial time series. While the results in the Chinese market are promising, future work should explore global markets like the NYSE or NASDAQ. Additionally, integrating multi-modal data—such as financial news and macroeconomic indicators—could further enhance the model's ability to interpret market sentiment and improve signal accuracy.

Summary updated

Abstract

In traditional quantitative trading practice, navigating the complicated and dynamic financial market presents a persistent challenge. Fully capturing various market variables, including long-term information, as well as essential signals that may lead to profit remains a difficult task for learning algorithms. In order to tackle this challenge, this paper introduces quantformer, an enhanced neural network architecture based on transformers, to build investment factors. By transfer learning from sentiment analysis, quantformer not only exploits its original inherent advantages in capturing long-range dependencies and modeling complex data relationships, but is also able to solve tasks with numerical inputs and accurately forecast future returns over a given period. This work collects more than 5,000,000 rolling data of 4,601 stocks in the Chinese capital market from 2010 to 2019. The results of this study demonstrated the model's superior performance in predicting stock trends compared with other 100 factor-based quantitative strategies. Notably, the model's innovative use of transformer-liked model to establish factors, in conjunction with market sentiment information, has been shown to enhance the accuracy of trading signals significantly, thereby offering promising implications for the future of quantitative trading strategies.
BibTeX
@misc{zhang2024from,
  author = {Zhaofeng Zhang and Banghao Chen and Shengxin Zhu and Nicolas Langrené},
  title = {{From attention to profit: quantitative trading strategy based on transformer}},
  year = {2024},
  eprint = {2404.00424},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.00424},
}
Figure