Resumen
Esta pesquisa analisa se os preços históricos de negociação dos principais índices das maiores bolsas de valores do mundo explicam o retorno futuro dos ativos, por meio da aplicação do algoritmo de Aprendizado de Máquina (Machine Learning – ML) K-Nearest Neighbors (k-NN). Para tal, utilizou-se uma amostra composta pelas cotações diárias de 37 índices de tais bolsas no período de 2001 a 2019. Os modelos foram estimados por índice, conforme os preços de fechamento e de máximo, assim como o período completo e a divisão em subperíodos, cujos resultados se apresentaram superiores aos do desempenho médio do mercado. Com base na cotação máxima dos índices, os modelos obtiveram desempenho superior aos dos preços de fechamento, e os de subperíodos conseguiram melhores desempenhos. A eficiência dos mercados sob a forma fraca foi questionada no contexto contemporâneo de forte ascensão de algoritmos de ML para a previsão em finanças. Nesse contexto, os principais índices das maiores bolsas de valores do mundo foram analisados, com a obtenção de subsídios gerais que podem auxiliar na orientação de pesquisas futuras na área, em que o tema é relevante devido a contribuições sobre o uso de algoritmos de ML na previsão de preços de ativos de investimento.
Palavras-chave: k-Nearest Neighbors. Machine Learning. Previsão de Preços. Hipótese de Mercados Eficientes. Bolsa de Valores.
APPLICATION OF THE ALGORITM K-NEAREST NEIGHBORS (K-NN) FOR FORECASTING INDEXES IN FINANCIAL MARKETS
ABSTRACT
This research analyzes whether the historical trading prices of the main indexes of the largest stock exchanges in the world explain the future return of assets, through the application of Machine Learning (ML) algorithm K-Nearest Neighbors (k-NN). To this end, a sample composed of the daily quotations of 37 indexes of such exchanges in the period from 2001 to 2019 was used. The models were estimated by index, according to the closing and maximum prices, as well as the full period and the division into subperiods, whose results were superior to the average market performance. Based on the maximum quotation of the indexes, the models obtained superior performance than the closing prices, and those ones of subperiods achieved better performance. The efficiency of markets in the weak form has been questioned in the contemporary context of strong rise of ML algorithms for forecasting in finance. In this context, the main indexes of the largest stock exchanges in the world were analyzed, obtaining general subsidies that can help guide future research in the area, in which the topic is relevant due to contributions on the use of ML algorithms in predicting the prices of investment assets.
Keywords: k-Nearest Neighbors. Machine Learning. Price Forecasting. Efficiency Market Hypothesis. Stock Exchanges.
Citas
AWAN, M. J.; RAHIM, M. S. M.; NOBANEE, H.; MUNAWAR, A.; YASIN, A.; ZAIN, A. M. Social media and stock market prediction: a big data approach. Computers, Materials & Continua, [s.l.], v. 67, n. 2, p. 2569-2583, 2021. Disponível em: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3827106. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.32604/cmc.2021.014253
ALKHATIB, K.; NAJADAT, H.; HMEIDI, I.; SHATNAWI, M. K. A. Stock price prediction using k-Nearest Neighbor (kNN) algorithm. International Journal of Business, Humanities and Technology, [s.l.], v. 3, n. 3, p. 32-44, 2013. Disponível em: https://www.ijbhtnet.com/journals/Vol_3_No_3_March_2013/4.pdf. Acesso em: 1º ago. 2024.
AVELAR, E. A.; OREFICI, J. B. P.; BORGES, S. L.; CAMPOS, O. V.; FERREIRA, P. O. The COVID-19 pandemic effects on the financial performance of Brazilian listed companies. Revista de Administração da UFSM, Santa Maria, v. 15, n. 3, p. 389-410, 2022. Disponível em: https://periodicos.ufsm.br/reaufsm/article/view/67372. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.5902/1983465967372
BALL, R. The global financial crisis and the efficient market hypothesis: what have we learned? Journal of Applied Corporate Finance, Chicago, v. 21, n. 4, p. 8-16, 2009. Disponível em: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1502815. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1111/j.1745-6622.2009.00246.x
BATISTA, A. R. A; MAIA, U.; ROMERO, A. Stock market under the 2016 Brazilian presidential impeachment: a test in the semi-strong form of the efficient market hypothesis,. Contabilidade & Finanças, São Paulo, v. 29, n. 78, 405-417, 2018. Disponível em: https://www.scielo.br/j/rcf/a/qsDPvq9R349gn8GqstnXgSr/?lang=en. Acesso em: 1º ago. 2024. DOI: http://dx.doi.org/10.1590/1808-057x201805560
BORGES, M. R. Efficient market hypothesis in European stock markets. The European Journal of Finance, Lisboa, v. 16, n. 7, p. 711-726, 2010. Disponível em: https://www.repository.utl.pt/bitstream/10400.5/26311/1/MRBORGES.2010.pdf. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1080/1351847X.2010.495477
CAMARGOS, M. A.; ROMERO, J. A. R. Reaction of Sao Paulo stock exchange corporative events: a test of the Efficient Market Hypothesis. Revista de Gestão, São Paulo, v. 13, n. 3, p. 57-74, 2006. Disponível em: https://www.revistas.usp.br/rege/article/view/36566. Acesso em: 1º ago. 2024.
DOI: https://doi.org/10.5700/issn.2177-8736.rege.2006.36566
CAO, H.; LIN, T.; LI, Y.; ZHANG, H. Stock price pattern prediction based on complex network and Machine Learning. Complexity, [s.l.], v. 1, p. 1-12, 2019. Disponível em: https://onlinelibrary.wiley.com/doi/10.1155/2019/4132485. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1155/2019/4132485
CAVALCANTE, R. C.; BRASILEIRO, R. C.; SOUZA, V. L. F.; NÓBREGA, J. P.; OLIVEIRA, L. I. Computational intelligence and financial markets: a survey and future directions. Expert Systems with Applications, [s.l.], v. 55, p. 194-211, 2016. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S095741741630029X. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.eswa.2016.02.006
CARTA, Salvatore et al. Explainable AI for financial forecasting. In: International Conference on Machine Learning, Optimization, and Data Science. Cham: Springer International Publishing, 2021. p. 51-69. Disponível em: https://www.researchgate.net/publication/353483959_Explainable_AI_for_Financial_Forecasting. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1007/978-3-030-95470-3_5
CHEN, Y.; HAO, Y. A feature weighted support vector machine and k-nearest neighbor algorithm for stock market indices prediction. Expert Systems with Applications, [s.l.], v. 80, p. 3400355, 2017. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S0957417417301367. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.eswa.2017.02.044
DEMIREL, U.; ÇAM, H.; ÜNLÜ, R. Predicting stock prices using machine learning methods and deep learning algorithms: the sample of the Istanbul Stock Exchange. Gazi University Journal of Science, [s.l.], v. 34, n. 1, p. 63-82, 2021. Disponível em: https://dergipark.org.tr/en/pub/gujs/issue/60264/679103. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.35378/gujs.679103
DIXON, M. F.; HALPERIN, I.; BILOKON, P. Machine learning in finance. New York: Springer International, 2020. DOI: https://doi.org/10.1007/978-3-030-41068-1
FACELI, K.; LORENA, A. C.; GAMA, J.; CARVALHO, A. C. P. L. F. Inteligência Artificial: uma abordagem de Aprendizado de Máquina. Rio de Janeiro: LTC, 2011.
FAMA, E. F. Efficient capital markets: a review of theory and empirical work. The Journal of Finance, New York, v. 25, n. 2, p. 383-417, 1970. Disponível em: https://www.jstor.org/stable/2325486. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.2307/2325486
FAMA, E. F. Efficient capital markets: II. The Journal of Finance, New York, v. 46, n. 5, p. 1575-1617, 1991. Disponível em: https://www.jstor.org/stable/2328565. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.2307/2328565
FERREIRA, F. G. D. C.; GANDOMI, A. H.; CARDOSO, R. T. N. Artificial Intelligence applied to stock market trading: a review. IEEE Access, [s.l.], v. 9, p. 30898-30917, 2021. Disponível em: https://ieeexplore.ieee.org/document/9350582. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1109/ACCESS.2021.3058133
FREIRE, A. P. F.; MAIA, P. A. A informação contábil e a Hipótese do Mercado Eficiente: um estudo empírico utilizando o setor de petróleo, gás e biocombustível do Brasil no período 2006-2009. Revista de Finanças Aplicadas, São Paulo, v. 1, p. 1-20, 2012. Disponível em: http://www.financasaplicadas.fia.com.br/index.php/financasaplicadas/article/view/37. Acesso em: 1º ago. 2024.
FUKUNAGA, K.; NARENDRA, P. M. A branch and bound algorithm for computing k-Nearest Neighbors. IEEE Transactions on Computers, [s.l.], v. C-24, n. 7, p. 750-753, 1975. Disponível em: https://ieeexplore.ieee.org/document/1672890. Acesso em: 1º ago. 2024. https://doi.org/10.1109/T-C.1975.224297
GABRIEL, F. S.; RIBEIRO, R. B.; RIBEIRO, K. C. S. Hipóteses de mercado eficiente: um estudo de eventos a partir da redução do IPI. Revista de Gestão, Finanças e Contabilidade, Salvador, v. 3, n. 1, p. 36-52, 2013. Disponível em: https://revistas.uneb.br/index.php/financ/article/view/95/199%26amp%3Bgt%3B%26lt%3B. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.18028/rgfc.v3i1.95
GANDHMAL, D. P.; KUMAR, K. Systematic analysis and review of stock market prediction techniques. Computer Science Review, [s.l.], v. 34, p. 100190, 2019. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S157401371930084X. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.cosrev.2019.08.001
GHODDUSI, H.; CREAMER, G. G.; RAFIZADEH, N. Machine learning in energy economics and finance: a review. Energy Economics, [s.l.], v. 81, p. 709-727, 2019. Disponível em: https://ideas.repec.org/a/eee/eneeco/v81y2019icp709-727.html. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.eneco.2019.05.006
GIL, A. C. Métodos e técnicas de pesquisa social. 6. ed. São Paulo: Atlas, 2008.
GITE, S.; KHATAVKAR, H.; KOTECHA, K.; SRIVASTAVA, S.; MAHESHWARI, P.; PANDEY, N. Explainable stock prices prediction from financial news articles using sentiment analysis. Peer Journal of Computer Science, [s.l.], v. 7, e340, 2021. Disponível em: https://peerj.com/articles/cs-340/. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.7717%2Fpeerj-cs.340
HUANG, C.; YANG, D.; CHUANG, Y. Application of wrapper approach and composite classifier to the stock trend prediction. Expert Systems with Applications, [s.l.], v. 34, n. 4, 2870-2875, 2008. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S0957417407001819. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.eswa.2007.05.035
INVESTING. Classificação das maiores bolsas mundiais. São Paulo, 2022. Disponível em: https://br.investing.com/. Acesso em: 1º ago. 2024.
JEON, S.; HONG, B.; CHANG, V. Pattern graph tracking-based stock price prediction using big data. Future Generation Computer Systems, [s.l.], v. 80, p. 171-187, 2018. Disponível em: https://sciencedirect.com/science/article/abs/pii/S0167739X17301991. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.future.2017.02.010
KIESEL, F.; MANZ, F.; SCHIERECK, D. The conditional stock market response to banks’ distressed asset sales on CDS availability. Applied Economics, [s.l.], v. 52, n. 56, p. 6123-6135, 2020. Disponível em: https://www.tandfonline.com/doi/abs/10.1080/00036846.2020.1784388. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1080/00036846.2020.1784388
KUMAR, I.; DOGRA, K.; UTREJA, C.; YADAV, P. A comparative study of supervised Machine Learning algorithms for stock market trend prediction. In: INTERNATIONAL CONFERENCE ON INVENTIVE COMMUNICATION AND COMPUTATIONAL TECHNOLOGIES, 2., 2018, [s.l]. Proceedings... [s.l.]: ICICCT, 2018, p. 1003-1007. Disponível em: https://www.semanticscholar.org/paper/A-Comparative-Study-of-Supervised-Machine-Learning-Kumar-Dogra/4ed67297d994da53b84332d98b0d02f3bccfa155. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1109/ICICCT.2018.8473214
LI, D.; LI, Z.; LI, R. Automate the identification of technical patterns: a K-nearest-neighbour model approach. Applied Economics, [s.l.], v. 50, n. 17, p. 1978-1991, 2018. Disponível em: https://ideas.repec.org/a/taf/applec/v50y2018i17p1978-1991.html. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1080/00036846.2017.1383596
LIM, K. P.; BROOKS, R. The evolution of stock market efficiency over time: a survey of the empirical literature. Journal of Economic Surveys, [s.l.], v. 25, n. 1, p. 69-108, 2011. Disponível em: https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1467-6419.2009.00611.x. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1111/j.1467-6419.2009.00611.x
LO, A. W. Reconciling efficient markets with behavioral finance: the adaptive markets hypothesis. Journal of Investment Consulting, [s.l.], v. 7, n. 2, p. 21-44, 2005. Disponível em: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1702447. Acesso em: 1º ago. 2024.
MALKIEL, B. G. The efficient market hypothesis and its critics. Journal of Economic Perspectives, [s.l.], v. 17, n. 1, p. 59-82, 2003. Disponível em: https://www.aeaweb.org/articles?id=10.1257/089533003321164958. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1257/089533003321164958
MALKIEL, B. G. Reflections on the efficient market hypothesis: 30 years later. The Financial Review, [s.l.], v. 40, n. 1, p. 1-9, 2005. Disponível em: http://ww.e-m-h.org/Malkiel2005.pdf. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1111/j.0732-8516.2005.00090.x
MOON, K. S.; JUN, S.; KIM, H. Speed up of the majority voting ensemble method for the prediction of stock price directions. Economic Computation and Economic Cybernetics Studies and Research, [s.l.], v. 52, n. 1, p. 215-228, 2018. Disponível em: https://www.researchgate.net/publication/323890209_Speed_up_of_the_Majority_Voting_Ensemble_Method_for_the_Prediction_of_Stock_Price_Directions. Acesso em: 1º ago. 2024. DOI: http://dx.doi.org/10.24818/18423264/52.1.18.13
NOVAK, M. G.; DEJAN, V. Prediction of stock price movement based on daily high prices,
Quantitative Finance, v. 16, n. 5, 793-826, 2016. Disponível em: https://www.tandfonline.com/doi/full/10.1080/14697688.2015.1070960. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1080/14697688.2015.1070960
PUJITHA, J.; MAHESH, G. Stock market price predictions using Python. In: INTERNATIONAL CONFERENCE ON FORENSICS, ANALYTICS, BIG DATA, SECURITY, 1., 2021, Bengaluru. Proceedings... Bengaluru: FABS, 2021, p. 1-5. Disponível em: https://ieeexplore.ieee.org/document/9702683. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1109/FABS52071.2021.9702683
QIAN, B.; RASHEED, K. Stock market prediction with multiple classifiers. Applied Intelligence, v. 26, p. 25-33, 2007. Disponível em: https://link.springer.com/article/10.1007/s10489-006-0001-7. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1007/s10489-006-0001-7
RICHARDSON, M. Fundamentos da metodologia cientifica. São Paulo: Atlas, 1999.
RYAN, J. A.; ULRICH, J. M.; SMITH, E. B.; THIELEN, W.; TEETOR, P.; BRONDER, S. Package ‘quantmod’. [s.l.], 2020. Disponível em: https://cran.r-project.org/web/packages/quantmod/quantmod.pdf. Acesso em: 2 fev. 2022.
RUNDO, F.; TRENTA, F.; STALLO, A. L.; BATTIATO, S. Machine Learning for quantitative finance applications: a survey. Applied Sciences, [s.l.], v. 9, n. 24, p. 5574, 2019. Disponível em: https://www.mdpi.com/2076-3417/9/24/5574. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.3390/app9245574
SHYNKEVICH, Y.; MCGINNITY, T. M.; COLEMAN, S. A.; BELATRECHE, A.; LI, Y. Forecasting price movements using technical indicators: investigating the impact of varying input window length. Neurocomputing, [s.l.], v. 264, p. 71-88, 2017. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S0925231217311074. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/j.neucom.2016.11.095
TIMMERMANN, A.; GRANGER, C. W. J. Efficient market hypothesis and forecasting. International Journal of Forecasting, [s.l.], v. 20, n. 1, p. 15-27, 2004. Disponível em: https://www.sciencedirect.com/science/article/abs/pii/S0169207003000128. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1016/S0169-2070(03)00012-8
WANG, D. D. S.; GUO, C.; YANG, Y.; ZHANG, Y.; WANG, Z. Stock prediction method based on integrated learning. International Core Journal of Engineering, [s.l.], v. 7, n. 12, p. 678-682, 2021. Disponível em: http://www.icj-e.org/download/ICJE-7-12-678-682.pdf. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.6919/ICJE.202112_7(12).0093
WANG, W.; HO, K.-Y.; LIU, W.-M.; WANG, K. The relation between news events and stock price jump: an analysis based on neural network. In: INTERNATIONAL CONGRESS ON MODELLING AND SIMULATION, 20., 2013, Adelaide. Proceedings... Adelaide, 2013, p. 1406-1411. Disponível em: https://www.mssanz.org.au/modsim2013/F8/wang.pdf. Acesso em: 1º ago. 2024.
WU, Mengyun; COLEMAN, Martha; BAWUAH, Jonas. The predictive power of K-nearest neighbor (KNN): The effect of corporate governance mechanisms on earnings management. Sage Open, v. 10, n. 3, p. 2158244020949537, 2020. Disponível em: https://ideas.repec.org/a/sae/sagope/v10y2020i3p2158244020949537.html. Acesso em: 1º ago. 2024. Acesso em: 1º ago. 2024. DOI: https://doi.org/10.1177/2158244020949
YAHOO!FINANCE. Tickers. New York, 2022. Disponível em: https://finance.yahoo.com/. Acesso em: 1º ago. 2024.
ZHAO, W.; SUN, C.; WANG, J. The research on price prediction of second-hand houses based on KNN and stimulated annealing algorithm. International Journal of Smart Home, [s.l.], v. 8, n. 2, p. 191-200, 2014. Disponível em: https://gvpress.com/journals/IJSH/vol8_no2/19.pdf. Acesso em: 1º ago. 2024. DOI: http://dx.doi.org/10.14257/ijsh.2014.8.2.19
Esta obra está bajo licencia Creative Commons Attribution-NonCommercial 4.0 International License.
Derechos de autor 2024 Array