A stock trading algorithm based on trend forecasting and time series classification

  • Matheus Rosisca Padovani UNICAMP
  • João Roberto Bertini Junior UNICAMP


Algorithm trading relies on the automatic identification of buying and selling points of a given asset to maximize profit. In this paper, we propose the Trend Classification Trading Algorithm (TCTA) which is based on time series classification and trend forecasting to perform trade. TCTA first employs the K-means to cluster 5-days closing price segments and label them according to its trend. A deep learning classification model is then trained with these label sequences to estimate the next trend. Trading points are given by the alternation on trend estimates. Results considering 20 shares from Ibovespa show TCTA present higher profit than buy-and-hold and trading schemes based on Moving Average Converge Divergence (MACD) or Bollinger bands.


Achelis, S. B. (2001). Technical analysis from A to Z. McGraw Hill, 2nd edition.

Aggarwal, C. C. (2018). Neural Networks and Deep Learning. Springer, 1st edition.

Bagnall, A., Lines, J., Bostrom, A., Large, J., and Keogh, E. (2016). The great time series classification bake off: a review and experimental evaluation of recent algorithmic advances. Data Mining and Knowledge Discovery.

Box, G. E. P., Jenkins, G. M., Reinsel, G. C., and Ljung, G. M. (2016). Time Series Analysis Forecasting and Control, volume 5. John Wiley and Sons, Inc.

Brogaard, J., Hagströmer, B., and Lars Nordén, R. R. (2015). Trading fast and slow: Colocation and liquidity. The Review of Financial Studies, 28:3407–3443.

Bustos, O. and Pomares-Quimbaya, A. (2020). Stock market movement forecast: A systematic review. Expert Systems with Applications, 156:113464.

Fawaz, H. I., Forestier, G., Weber, J., Idoumghar, L., and Muller, P.-A. (2018). Deep learning for time series classification: a review. Data Mining and Knowledge Discovery, pages ”917–963”.

Gandhmal, D. P. and Kumar, K. (2019). Systematic analysis and review of stock market prediction techniques. Computer Science Review, 34:100190.

Graves, A., Liwicki, M., Fernández, S., Bertolami, R., Bunke, H., and Schmidhuber, J. (2009). A novel connectionist system for unconstrained handwriting recognition. IEEE Transactions on Pattern Analysis and Machine Intelligence, 31(5):855–868.

Huang, B. and Kim, Y. S. (2006). A test of MACD trading strategy. Master’s thesis, Faculty of Business Administration Simon Fraser University.

Ozbayoglu, A. M., Gudelek, M. U., and Sezer, O. B. (2020). Deep learning for financial applications : A survey. Applied Soft Computing, 93:106384.

Pascanu, R., Mikolov, T., and Bengio, Y. (2013). On the difficulty of training recurrent In Proceedings of the 30th International Conference on Machine neural networks. Learning, volume 28, pages 1310–1318. PMLR.

Rachev, S. T., Mittinik, S., Fabozzi, F. J., Focardi, S. M., and Jasíc, T. (2007). Financial Econometrics: From Basics to Advanced Modeling Techniques. John Wiley & Sons, Inc, 1st edition.

Rajab, S. and Sharma, V. (2019). An interpretable neuro-fuzzy approach to stock price forecasting. Soft Computing, 23:921–936.

Shao, X., Ma, D., Liu, Y., and Yin, Q. (2017). Short-term forecast of stock price of multibranch lstm based on k-means. In The 2017 4th International Conference on Systems and Informatics (ICSAI 2017), pages 1546–1551.

Thakkar, A. and Chaudhari, K. (2021). A comprehensive survey on deep neural networks for stock market: The need, challenges, and future direction. Expert Systems with Applications, 177:114800.

Williams, O. (2006). Empirical optimization of bollinger bands for profitability. Master’s thesis, Faculty of Business Administration Simon Fraser University.

Xu, Y., Yang, C., Peng, S., and Nojima, Y. (2020). A hybrid two-stage financial stock forecasting algorithm based on clustering and ensemble learning. Applied Intelligence.

Yang, Q. and Wu, X. (2005). 10 challenging problems in data mining research. International Journal of Information Technology and Decision Making, 5:”597–604”.
PADOVANI, Matheus Rosisca; BERTINI JUNIOR, João Roberto. A stock trading algorithm based on trend forecasting and time series classification. In: ENCONTRO NACIONAL DE INTELIGÊNCIA ARTIFICIAL E COMPUTACIONAL (ENIAC), 18. , 2021, Evento Online. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2021 . p. 422-433. ISSN 2763-9061. DOI: https://doi.org/10.5753/eniac.2021.18272.