Skip to content
All library documents

StockFormer: Predictive Coding and Reinforcement Learning for Trading

Article MQL5 articles

Summary

The article presents StockFormer, a hybrid framework that combines Transformer-based predictive coding with an Actor–Critic reinforcement-learning agent. Three branches learn representations for long-horizon trends, next-day returns, and changing dependencies among assets. A diversified multi-head attention module splits features into groups processed by separate feed-forward networks, aiming to capture varied patterns without increasing the parameter count. Attention blocks fuse the branches into a state representation for policy learning.

Predictive coding is trained with masked cross-asset statistics and return forecasts, using regression and ranking losses; critic feedback also improves the learned representations during policy optimization. The article reports that experiments on three public datasets outperformed comparison methods in prediction accuracy and investment returns, but the supplied account gives no dataset names, numerical results, or robustness details. It also walks through an MQL5 implementation of the modified network components. The findings should be treated as reported experimental results, not evidence of live-trading performance or generalization to other markets.

Key ideas

  • StockFormer uses separate Transformer branches to represent short-term returns, long-term trends, and cross-asset dependencies.
  • Its diversified attention module processes feature groups with distinct feed-forward networks while retaining the representation’s dimensionality.
  • Masked statistics train the model to reconstruct relationships among assets, while forecasting branches predict returns over different horizons.
  • Attention fuses the branch representations before an Actor–Critic agent learns trading decisions.
  • The article reports favorable tests on three public datasets but provides limited detail for judging robustness or live-market applicability.

Tags

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