Applying Recurrent Neural Networks with Long Short-Term Memory in Clustered Stocks

  • Felipe Affonso CEFET-MG
  • Thiago Magela Rodrigues Dias CEFET-MG


Predicting the stock market is a widely studied field, either due to the curiosity in finding an explanation for the behavior of financial assets or for financial purposes. Among these studies the best techniques use neural networks as a prediction tool. More specifically, the best networks for this purpose are called recurrent neural networks (RNN), and provide an extra option when dealing with a sequence of values. However, a great part of the studies is intended to predict the result of few stocks, therefore, this work aims to predict the behavior of a large number of stocks. For this, similar stocks were grouped based on their correlation and later the algorithm K-means was applied so that similar groups were clustered. After this process, the Long Short-Term Memory (LSTM) - a type of RNN - was used in order to predict the price of a certain group of assets. Results showed that clustering stocks did not influence the effectiveness of the network and that investors and portfolio managers can use it to simply their daily tasks.


Affonso, F., de Oliveira, F., and Dias, T. M. R. (2017). Uma Análise dos Fatores que Influenciam o Movimento Acionário das Empresas Petrolíferas. In Ibero-Latin American Congress on Computational Methods in Engineering (CILAMCE).

Bengio, Y., Simard, P., and Frasconi, P. (1994). Learning long-term dependencies with gradient descent is difficult. IEEE transactions on neural networks, 5(2), 157-166.

Bini, B. S., and Mathew, T. (2016). Clustering and Regression Techniques for Stock Prediction. Procedia Technology, 24, 1248-1255.

Cavalcante, R. C., Brasileiro, R. C., Souza, V. L., Nobrega, J. P., and Oliveira, A. L. (2016). Computational intelligence and financial markets: A survey and future directions. Expert Systems with Applications, 55, 194-211.

Chollet, F. (2015). Keras. Available at

Chong, E., Han, C., and Park, F. C. (2017). Deep learning networks for stock market analysis and prediction: Methodology, data representations, and case studies. Expert Systems with Applications, 83, 187-205.

Filho, D. B. F. and Júnior, J. A. d. S. (2009). Desvendando os mistérios do coeficiente de correlacão de pearson (r). Universidade Federal de Pernambuco.

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.

Gan, G., Ma, C., and Wu, J. (2007). Data clustering: theory, algorithms, and applications (Vol. 20). Siam.

Gerlein, E. A., McGinnity, M., Belatreche, A., and Coleman, S. (2016). Evaluating machine learning classification for financial trading: An empirical approach. Expert Systems with Applications, 54, 193-207.

Hochreiter, S., and Schmidhuber, J. (1997). Long short-term memory. Neural computation, 9(8), 1735-1780.

Jung, S. S., and Chang, W. (2016). Clustering stocks using partial correlation coefficients. Physica A: Statistical Mechanics and its Applications, 462, 410-420.

Ketchen, D. J., and Shook, C. L. (1996). The application of cluster analysis in strategic management research: an analysis and critique. Strategic management journal, 17(6), 441-458.

Krauss, C., Do, X. A., and Huck, N. (2017). Deep neural networks, gradient-boosted trees, random forests: Statistical arbitrage on the S&P 500. European Journal of Operational Research, 259(2), 689-702.

Kumar, B. S. and Ravi, V. (2016). A survey of the applications of text mining in financial domain. Knowledge-Based Systems, 114, 128-147.

Längkvist, M., Karlsson, L., and Loutfi, A. (2014). A review of unsupervised feature learning and deep learning for time-series modeling. Pattern Recognition Letters, 42, 11-24.

LeCun, Y., Bengio, Y., and Hinton, G. (2015). Deep learning. nature, 521(7553), 436.

Li, Y., Jiang, W., Yang, L., and Wu, T. (2018). On neural networks and learning systems for business computing. Neurocomputing, 275, 1150-1159.

Liu, Y., Li, Z., Xiong, H., Gao, X., and Wu, J. (2010). Understanding of internal clustering validation measures, In ICDM , 911–916.

Mirkin, B. G. (1996). Mathematical classification and clustering. Dordrecht, The Netherlands: Kluwer Academic Publishing.

Momeni, M., Mohseni, M., and Soofi, M. (2015). Clustering Stock Market Companies via K-Means Algorithm. Kuwait Chapter of the Arabian Journal of Business and Management Review, 4(5), 1.

Nanda, S. R., Mahanty, B., and Tiwari, M. K. (2010). Clustering Indian stock market data for portfolio management. Expert Systems with Applications, 37(12), 8793-8798.

Nelson, D. M., Pereira, A. C., and de Oliveira, R. A. (2017). Stock market's price movement prediction with LSTM neural networks. In Neural Networks (IJCNN), 2017 International Joint Conference on (pp. 1419-1426). IEEE.

Python Software Foundation (2018). Python 3.5.5 documentation. Available at

Qiu, M., Song, Y., and Akagi, F. (2016). Application of artificial neural network for the prediction of stock market returns: The case of the Japanese stock market. Chaos, Solitons & Fractals, 85, 1-7.

Zhang, J., Cui, S., Xu, Y., Li, Q., and Li, T. (2018). A novel data-driven stock price trend prediction system. Expert Systems with Applications, 97, 60-69.

Como Citar

Selecione um Formato
AFFONSO, Felipe; DIAS, Thiago Magela Rodrigues. Applying Recurrent Neural Networks with Long Short-Term Memory in Clustered Stocks. In: ENCONTRO NACIONAL DE INTELIGÊNCIA ARTIFICIAL E COMPUTACIONAL (ENIAC), 15. , 2018, São Paulo. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2018 . p. 252-262. ISSN 2763-9061. DOI: