Abstract
Stock market prediction is uniquely challenging because financial time series are fundamentally non-stationary: the statistical properties of returns, correlations, and volatility change over time as markets transition between distinct regimes such as bull markets, bear markets, high-volatility crises, and low-volatility consolidations. Most existing deep learning approaches—including recurrent networks, transformers, and graph neural networks—treat market dynamics as stationary processes and learn a single set of model parameters that applies uniformly across all market conditions. This design choice is inherently limiting, as the optimal predictive model for a quiet bull market is fundamentally different from that for a volatile bear market. In this paper, we propose MarkovFormer (Markov Switching Transformer), a novel hierarchical architecture that explicitly models market regime transitions using a Markov Switching mechanism and adapts its predictive parameters accordingly. MarkovFormer consists of three key components: (i) a Regime Detection Module (RDM) that uses a latent Markov switching process to classify the current market state from historical price data; (ii) a Regime-Conditioned State Space Encoder (RSE) that maintains regime-specific stock state representations learned through regime-conditioned transition matrices; and (iii) a Cross-Regime Attention Mechanism (CRAM) that enables information flow across regimes, allowing the model to leverage knowledge from similar historical regimes to improve predictions in the current one. By conditioning predictions on the detected market regime, MarkovFormer dynamically adjusts the weighting of short-term momentum, mean-reversion, and volatility signals based on which regime is currently active. Extensive experiments on three major markets (S&P 500, CSI 300, and KOSPI 200) demonstrate that MarkovFormer consistently outperforms ten competitive baselines, including S3G (Lu, Hu, and Zhang, 2026), the state-of-the-art stock state space graph model, achieving an average improvement of 5.4% in directional accuracy and 9.7% in Matthews Correlation Coefficient (MCC) across all datasets. Most notably, during high-volatility crisis periods—including the 2020 COVID-19 market crash and the 2022 global rate-hike cycle—MarkovFormer substantially outperforms S3G, which lacks explicit regime awareness, demonstrating the critical importance of modeling market structure non-stationarity.
References
1. Ang, A., and Bekaert, G. (2002). International Asset Allocation with Regime Shifts. *Review of Financial Studies*, 15(4): 1137-1187.
2. Fan T, Wang J, Wang X, Chen X, Zhao D, Xie F and Chen G (2025) Integrated multidisciplinary approach to aneurysm hemodynamic analysis: numerical simulation, in Vitro experiment, and deep learning. Front. Bioeng. Biotechnol. 13:1602190. doi: 10.3389/fbioe.2025.1602190
3. Ye X, Zhang J, Cheng Z, Lu F, Wen Z, Yu G, Chen G, Xie F, Qiao D, Xing J, Tan W, Zhao D and Ren M (2025) Hemodynamic modeling of aortic arch aneurysm treatment using the Castor™ branched stent graft: a virtual coil embolization simulation framework. Front. Physiol. 16:1629346. doi: 10.3389/fphys.2025.1629346
4. Bai, S., Kolter, J.Z., and Koltun, V. (2018). An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling. *arXiv preprint arXiv:1803.01271*.
5. Baestaens, D.E., Van den Bergh, W.M., and Wood, D. (1994). Neural Network Solutions to the Trading Problem. *International Journal of Forecasting*, 10(1): 43-51.
6. Baum, L.E., Petrie, T., Soules, G., and Weiss, N. (1970). A Maximization Technique Occurring in the Statistical Analysis of Probabilistic Functions of Markov Chains. *The Annals of Mathematical Statistics*, 41(1): 164-171.
7. Bizaj, E., Kristjanpoller, W., and Minutolo, M. (2022). A Volatility Regime-Switching Model for Stock Market Prediction. *IEEE Transactions on Neural Networks and Learning Systems*, 33(8): 3612-3623.
8. Bollerslev, T. (1986). Generalized Autoregressive Conditional Heteroskedasticity. *Journal of Econometrics*, 31(3): 307-327.
9. Campbell, J.Y., and Hentschel, L. (1992). No News is Good News: An Asymmetric Model of Changing Volatility in Stock Returns. *Journal of Financial Economics*, 31(3): 281-318.
10. Chen, Y., Lu, Y., and Wang, B. (2020). Stock Movement Prediction with Sector Information using Graph Convolutional Networks. *IEEE Transactions on Neural Networks and Learning Systems*, 31(12): 5419-5429.
11. Cho, K., Van Merriënboer, B., Gulcehre, C., Bahdanau, D., Bougares, F., Schwenk, H., and Bengio, Y. (2014). Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation. *Conference on Empirical Methods in Natural Language Processing (EMNLP)*, pages 1724-1734.
12. Deng, Y., Wang, B., and Zhang, Y. (2021). Deep Learning for Cryptocurrency Market Regime Detection. *Proceedings of the 2021 ACM International Conference on Information and Knowledge Management*, pages 3452-3459.
13. Diebold, F.X., and Yilmaz, K. (2014). On the Network Topology of Variance Decompositions. *Journal of Econometrics*, 180(2): 115-131.
14. Doucet, A., De Freitas, N., and Gordon, N. (2001). *Sequential Monte Carlo Methods in Practice*. Springer.
15. Elliott, R.J., and van der Hoek, J. (2003). Kalman Filtering with Insider Knowledge. *Applied Mathematical Finance*, 10(4): 271-286.
16. Fama, E.F. (1965). The Behavior of Stock-Market Prices. *Journal of Business*, 38(1): 34-105.
17. Fischer, T., and Krauss, C. (2018). Deep Learning with Long Short-Term Memory Networks for Financial Market Predictions. *European Journal of Operational Research*, 270(2): 654-669.
18. Gu, A., Johnson, I., Goel, K., Saab, K., Dao, T., Rudra, A., and Re, C. (2022). Combining Recurrent, Convolutional, and Continuous-time Models with Structured State Space S4. *Advances in Neural Information Processing Systems (NeurIPS)*, pages 5724-5736.
19. Lu, Y., Hu, K., and Zhang, L. (2026). S3G: Stock State Space Graph for Enhanced Stock Trend Prediction. *ICASSP 2026-2026 IEEE International Conference on Acoustics, Speech and Signal Processing*, pages 4081-4085. IEEE.
20. Bao, W., Xu, K., & Leng, Q. (2024). Research on the Financial Credit Risk Management Model of Real Estate Supply Chain Based on GA-SVM Algorithm: A Comprehensive Evaluation of AI Model and Traditional Model. Procedia Computer Science, 243, 900-909.
