skip to main content
research-article

Forecasting the Market with Machine Learning Algorithms: An Application of NMC-BERT-LSTM-DQN-X Algorithm in Quantitative Trading

Published: 08 January 2022 Publication History

Abstract

Although machine learning (ML) algorithms have been widely used in forecasting the trend of stock market indices, they failed to consider the following crucial aspects for market forecasting: (1) that investors’ emotions and attitudes toward future market trends have material impacts on market trend forecasting (2) the length of past market data should be dynamically adjusted according to the market status and (3) the transition of market statutes should be considered when forecasting market trends. In this study, we proposed an innovative ML method to forecast China's stock market trends by addressing the three issues above. Specifically, sentimental factors (see Appendix [1] for full trans) were first collected to measure investors’ emotions and attitudes. Then, a non-stationary Markov chain (NMC) model was used to capture dynamic transitions of market statutes. We choose the state-of-the-art (SOTA) method, namely, Bidirectional Encoder Representations from Transformers (BERT), to predict the state of the market at time t, and a long short-term memory (LSTM) model was used to estimate the varying length of past market data in market trend prediction, where the input of LSTM (the state of the market at time t) was the output of BERT and probabilities for opening and closing of the gates in the LSTM model were based on outputs of the NMC model. Finally, the optimum parameters of the proposed algorithm were calculated using a reinforced learning-based deep Q-Network. Compared to existing forecasting methods, the proposed algorithm achieves better results with a forecasting accuracy of 61.77%, annualized return of 29.25%, and maximum losses of −8.29%. Furthermore, the proposed model achieved the lowest forecasting error: mean square error (0.095), root mean square error (0.0739), mean absolute error (0.104), and mean absolute percent error (15.1%). As a result, the proposed market forecasting model can help investors obtain more accurate market forecast information.

References

[1]
R. Adhikari and R. K. Agrawal. 2014. A combination of artificial neural network and random walk models for financial time series forecasting. Neural. Comput. Appl. 24, 6 (2014), 1441–1449.
[2]
R. C. Ahana, A. Soheila, T. Michael, and K. Piyush. 2020. Enhancing profit from stock transactions using neural networks. AI Commun. 33, 1 (2020), 1–12.
[3]
Y. Amihud. 2002. Illiquidity and stock returns: cross-section and time-series effects. J. Financ. Mark. 5, 1 (2002), 31–56.
[4]
A. Andrikopoulos, T. Angelidis, and V. Skintzi. 2014. Illiquidity, return and risk in G7 stock markets: Interdependencies and spillovers. Int. Rev. Financ. Anal. 35, 1 (2014), 118–127.
[5]
S. Asadi, E. Hadavandi, F. Mehmanpazir, and M. M. Nakhostin. 2012. Hybridization of evolutionary Levenberg-Marquardt neural networks and data pre-processing for stock market prediction. Knowl-Based. Syst. 35, 15 (2012), 245–258.
[6]
C. S. Asness, T. J. Moskowitz, and L. H. Pedersen. 2013. Value and momentum everywhere. J. Financ. 68, 3 (2013), 929–985.
[7]
M. Baker and J. C. Stein. 2004. Market liquidity as a sentiment indicator. J. Financ. Mark. 7, 3 (2004), 271–299.
[8]
M. Baker and J. Wurgler. 2007. Investor sentiment in the stock market. J. Econ. Perspect. 21, 2 (2007), 129–151.
[9]
G. Bekaert, C. R. Harvey, and C. Lundblad. 2007. Liquidity and expected returns: Lessons from emerging markets. Rev. Financ. Stud. 20, 6 (2007), 1783–1831.
[10]
L. Bauwens and E. Otranto. 2016. Modeling the dependence of conditional correlations on market volatility. J. Bus. Econ. Stat. 34, 2 (2016), 254–268.
[11]
A. Brav, J. Wei, F. Partnoy, and R. Thomas. 2010. Hedge fund activism, corporate governance, and firm performance. J. Financ. 63, 4 (2010), 1729–1775.
[12]
A. Breaban and C. N. Noussair. 2018. Emotional state and market behavior. Rev. Financ. 22, 1 (2018), 279–309.
[13]
R. Cervell´o-Royo, F. Guijarro, and K. Michniuk. 2015. Stock market trading rule based on pattern recognition and technical analysis: Forecasting the DJIA index with intraday data. Expert Systems with Applications 42, 14 (2015), 5963–5975.
[14]
P. Chelley-Steeley, P. L. Lambertides, and C. S. Savva. 2013. Illiquidity shocks and the comovement between stocks: New evidence using smooth transition. J. Empir. Financ. 23, 5 (2013), 1–15.
[15]
H. Chen, T. T. Chong, and Y. She. 2014. A principal component approach to measuring investor sentiment in China. Quantitative Finance 14, 4 (2014), 573–579.
[16]
J. A. Cheng, J. B. Fu, Y. C. Kang, H. D. Zhu, and W. E. Dai. 2019. Sentiment analysis of social networks’ comments to predict stock return. Lecture Notes in Computer Science. 2019, 11956, 67–74.
[17]
J. S Chou and T. K. Nguyen. 2018. Forward Forecast of stock price using sliding-window metaheuristic-optimized machine learning regression. IEEE. T. Ind. Inform. 14, 7 (2018), 3132–3142.
[18]
F. Di Martino, S. Senatore, and S. Sessa. 2019. A lightweight clustering-based approach to discover different emotional shades from social message streams. Int. J. Intell. Syst. 34, 7 (2019), 1505–1523.
[19]
O. M. E. Ebadati and M. T. Mortazavi. 2018. An efficient hybrid machine learning method for time series stock market forecasting. Neural. Netw. World. 28, 1 (2018), 41–55.
[20]
L. Fang and J. Peress. 2009. Media coverage and the cross section of stock returns. J. Financ. 64, 5 (2009), 2023–2052.
[21]
E. J. D. Fortuny, T. D. Smedt, D. Martens, and W. Daelemans. 2014. Evaluating and understanding text-based stock price prediction models. Inform. Process. Manag. 50, 2 (2014), 426–441.
[22]
X. Gong and B. Lin. 2018. Structural breaks and volatility forecasting in the copper futures market. J. Futures. Markets. 38, 3 (2018), 290–339.
[23]
J. Griffith, M. Najand, and J. Shen. 2020. Emotions in the stock market. J. Behav. Financ. 21, 1 (2020), 42–56.
[24]
E. Guresen, G. Kayakutlu, and T. U. Daim. 2011. Using artificial neural network models in stock market index prediction. Expert. Syst. Appl. 38, 8 (2011), 10389–10397.
[25]
Z. He and A. Krishnamurthy. 2013. Intermediary asset pricing. Am. Econ. Rev. 103, 2 (2013), 732–770.
[26]
A. A. Kasgari, M. Divsalar, M. R. Javid, and S. J. Ebrahimian. 2013. Prediction of bankruptcy Iranian corporations through artificial neural network and probit-based analyses. Neural. Comput. Appl. 23, 3–4 (2013), 927–936.
[27]
R. W. Kristjanpoller and V. K. Michell. 2018. A stock market risk forecasting model through integration of switching regime, ANFIS and GARCH techniques. Appl. Soft. Comput. 67, 1 (2018), 106–116.
[28]
A. Kumar. 2010. Who gambles in the stock market? J. Financ. 64, 4 (2010), 1889–1933.
[29]
Gourav Kumar, Sanjeev Jain, and Uday Pratap Singh. 2020. Stock market forecasting using computational intelligence: A survey. Archives of Computational Methods in Engineering 28, 3 (2020), 1069--1101.
[30]
M. Li, L. Chen, J. Zhao, and Q. Li. 2021. Sentiment analysis of Chinese stock reviews based on BERT model. Appl. Intell. 51, 7 (2021), 5016–5024. DOI:
[31]
Daiki Matsunaga, Toyotaro Suzumura, and Toshihiro Takahashi. 2019. Exploring graph neural networks for stock market predictions with rolling window analysis. Retrieved November 1, 2021 from https://arxiv.org/abs/1909.10660.
[32]
L. Menggang, L. Wenrui, F. Wang, X. Jia, and G. Rui. 2020. Applying Bert to analyze investor sentiment in stock market. Neural Computing and Applications 33, 10 (2020), 4663–4676. DOI:
[33]
K. Nakagawa, T. Uchida, and T. Aoshima. 2019. Deep factor model. In ECML PKDD 2018 Workshops. Springer, Cham.
[34]
T. H. Nguyen, K. Shirai, and J. Velcin. 2015. Sentiment analysis on social media for stock movement prediction. Expert. Syst. Appl. 42, 24 (2015), 9603–9611.
[35]
R. Nyman and P. Ormerod. 2014. Big data, socio-psychological theory, algorithmic text analysis and predicting the Michigan consumer sentiment index. Retrieved November 1, 2021 from https://arxiv.org/abs/1405.5695.
[36]
J. Patel, S. Shah, P. Thakkar, and K. Kotecha. 2015a. Predicting stock and stock price index movement using trend deterministic data preparation and machine learning techniques. Expert. Syst. Appl. 42, 1 (2015), 259–268.
[37]
J. Patel, S. Shah, P. Thakkar, and K. Kotecha. 2015b. Predicting stock market index using fusion of machine learning techniques. Expert. Syst. Appl. 42, (2015), 2162–2172.
[38]
Prozil Pinto and Ana Filipa. 2018. A principal component approach to measure investor sentiment and its impact on ipo's underpricing. Retrieved from https://repositorio-aberto.up.pt/bitstream/10216/116313/2/294407.pdf.
[39]
R. Sadka. 2006. Momentum and post-earnings-announcement drift anomalies: The role of liquidity risk. J. Financ. Econ. 80, 2 (2006), 309–349.
[40]
S. S. Rangapuram, M. W. Seeger, J. Gasthaus, L. Stella, Y. Wang, and T. Januschowski. 2018. Deep state space models for time series forecasting. In Proceedings of the 32nd International Conference on Neural Information Processing Systems. 7796–7805
[41]
Ruofeng Wen, Kari Torkkola, Balakrishnan Narayanaswamy, and Dhruv Madeka. 2017. A multi-horizon quantile recurrent forecaster. In Proceedings of the 31st Conference on Neural Information Processing Systems (NIPS’17).
[42]
Y. Shynkevich, T. M. McGinnity, S. Coleman, A. Belatreche, and Y. Li. 2017. Forecasting price movements using technical indicators: investigating the impact of varying input window length. Neurocomputing 264, 1 (2017), 71–88.
[43]
J. L. Ticknor. 2013. A Bayesian regularized artificial neural network for stock market forecasting. Expert. Syst. Appl. 40, 14 (2013), 5501–5506.
[44]
P. Tsang, S. Kwok, S. Choy, R. Kwan, and S. Ng. 2007. Design and implementation of NN5 for Hong Kong stock price forecasting. En. Appl. Artif. Intel. 20, 4 (2007), 453–461.
[45]
B. Weng, M. A. Ahmed, and F. M. Megahed. 2017. Stock market one-day ahead movement prediction using disparate data sources. Expert Syst. Appl. 79, 8 (2017), 153–163.
[46]
B. Weng, L. Lu, X. Wang, F. M. Megahed, and W. Martinez. 2018. Predicting short-term stock prices using ensemble methods and online data sources. Expert Syst. Appl. 112, 1 (2018), 258–273.
[47]
H. C. Xu and W. X. Zhou. 2018. A weekly sentiment index and the cross-section of stock returns. Financ. Res. Lett. 27, 1 (2018), 135–139.
[48]
Z. Yang, O. Fu, and X. Peng. 2020. A decision-making algorithm for online shopping using deep-learning-based opinion pairs mining and q-rung orthopair fuzzy interaction Heronian mean operators. Int. J. Intell. Syst. 35, 5 (2020), 783–825. DOI:
[49]
P. D. Yoo, M. H. Kim, and T. Jan. 2005. Financial forecasting: advanced machine learning techniques in stock market analysis. In Proceedings of the 2005 Pakistan Section Multitopic Conference.
[50]
Jun Zhang, Yu-Fan Teng, and Wei Chen. 2018. Support vector regression with modified Firefly algorithm for stock price forecasting. Applied Intelligence 49, 5 (2018), 1658--1674.
[51]
Y. Zuo and E. Kita. 2012a. Stock price forecast using Bayesian network. Expert Syst. Appl. 39, 8 (2012), 6729–6737.
[52]
Y. Zuo and E. Kita. 2012b. Up/down analysis of stock index by using Bayesian network. Engineering Management Research 1, 2 (2012), 46–52.

Cited By

View all
  • (2025)A Framework for Market State Prediction with Ontological Asset Selection: A Multimodal ApproachApplied Sciences10.3390/app1503103415:3(1034)Online publication date: 21-Jan-2025
  • (2024)Transformers and attention-based networks in quantitative trading: a comprehensive surveyProceedings of the 5th ACM International Conference on AI in Finance10.1145/3677052.3698684(822-830)Online publication date: 14-Nov-2024
  • (2024)Enhancing efficiency in recurrent reinforcement learning for automated data-driven investmentProcedia Computer Science10.1016/j.procs.2024.09.435246(2627-2634)Online publication date: 2024
  • Show More Cited By

Index Terms

  1. Forecasting the Market with Machine Learning Algorithms: An Application of NMC-BERT-LSTM-DQN-X Algorithm in Quantitative Trading

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM Transactions on Knowledge Discovery from Data
    ACM Transactions on Knowledge Discovery from Data  Volume 16, Issue 4
    August 2022
    529 pages
    ISSN:1556-4681
    EISSN:1556-472X
    DOI:10.1145/3505210
    Issue’s Table of Contents

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 08 January 2022
    Accepted: 01 September 2021
    Revised: 01 July 2021
    Received: 01 October 2020
    Published in TKDD Volume 16, Issue 4

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Machine learning
    2. forecasting
    3. quantitative trading
    4. eXogenous variables
    5. SOTA

    Qualifiers

    • Research-article
    • Refereed

    Funding Sources

    • Social Science Foundation in Sichuan
    • Fundamental Research Funds for the Central Universities

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)263
    • Downloads (Last 6 weeks)23
    Reflects downloads up to 14 Feb 2025

    Other Metrics

    Citations

    Cited By

    View all
    • (2025)A Framework for Market State Prediction with Ontological Asset Selection: A Multimodal ApproachApplied Sciences10.3390/app1503103415:3(1034)Online publication date: 21-Jan-2025
    • (2024)Transformers and attention-based networks in quantitative trading: a comprehensive surveyProceedings of the 5th ACM International Conference on AI in Finance10.1145/3677052.3698684(822-830)Online publication date: 14-Nov-2024
    • (2024)Enhancing efficiency in recurrent reinforcement learning for automated data-driven investmentProcedia Computer Science10.1016/j.procs.2024.09.435246(2627-2634)Online publication date: 2024
    • (2024)Artificial intelligence techniques in financial tradingJournal of King Saud University - Computer and Information Sciences10.1016/j.jksuci.2024.10201536:3Online publication date: 1-Mar-2024
    • (2024)Multi-factor stock trading strategy based on DQN with multi-BiGRU and multi-head ProbSparse self-attentionApplied Intelligence10.1007/s10489-024-05463-554:7(5417-5440)Online publication date: 22-Apr-2024
    • (2023)The analysis of double average strategy for Chinese famous liquor stocks Evidence from the MA5-MA10 and the MA-MA20 strategyBCP Business & Management10.54691/bcpbm.v36i.338736(71-76)Online publication date: 13-Jan-2023
    • (2023)Application of Machine Learning Algorithm in Financial Industry2023 3rd International Conference on Mobile Networks and Wireless Communications (ICMNWC)10.1109/ICMNWC60182.2023.10435662(1-5)Online publication date: 4-Dec-2023
    • (2023)Sentiment Analysis of Animated Online Education Texts Using Long Short-Term Memory Networks in the Context of the Internet of ThingsIEEE Access10.1109/ACCESS.2023.332130311(109121-109130)Online publication date: 2023
    • (2023)Mining frequent Itemsets from transaction databases using hybrid switching frameworkMultimedia Tools and Applications10.1007/s11042-023-14484-082:18(27571-27591)Online publication date: 16-Feb-2023
    • (2022)An Intelligent Stock Market Automation with Conversational Web Based Build Operate Transfer (BOT)2022 International Conference on Trends in Quantum Computing and Emerging Business Technologies (TQCEBT)10.1109/TQCEBT54229.2022.10041477(1-6)Online publication date: 13-Oct-2022
    • Show More Cited By

    View Options

    Login options

    Full Access

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Full Text

    View this article in Full Text.

    Full Text

    HTML Format

    View this article in HTML Format.

    HTML Format

    Figures

    Tables

    Media

    Share

    Share

    Share this Publication link

    Share on social media