Skip to content
All library documents

Using Time2Vec and Transformer Attention to Rank Stocks

Article BigQuant

Summary

This tutorial explains attention and Transformer components before outlining a time-series stock ranking model. It adds Time2Vec features to factor sequences so the model can represent both periodic and linear time patterns, then applies self-attention, feed-forward layers, residual connections, and normalization to predict future stock returns. The discussion also describes preprocessing and rolling input windows.

The example uses Chinese A-share data, trains on an earlier period, and evaluates a daily portfolio that buys highly ranked stocks and removes weaker-ranked holdings. It reports a backtest setup and model configuration, but the supplied text does not give numerical performance results or compare the strategy with benchmarks. Its choices, including a short input window, selected factors, and a single attention head in the example, are implementation details rather than evidence that the approach will generalize to other markets or periods.

Key ideas

  • Time2Vec combines periodic and nonperiodic representations to encode time in factor sequences.
  • Self-attention weights historical observations when forming a return prediction.
  • The described model uses feed-forward layers, residual connections, and normalization within Transformer encoders.
  • The example ranks Chinese stocks using predicted returns and a daily portfolio process.
  • The text describes a backtest design but provides no numerical performance evidence.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.