Research Article | | Peer-Reviewed

Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange

Received: 20 October 2026     Accepted: 6 November 2026     Published: 26 November 2026
Views:       Downloads:
Abstract

Accurate stock price prediction is challenging due to the dynamic, non-linear, and noisy nature of financial markets. Traditional methods, such as technical and fundamental analysis, are often subjective and limited. However, machine learning techniques offer significant potential for improved forecasting. This study compared the performance of Artificial Neural Network (ANN) and Random Forest (RF) models in predicting the next-day closing stock prices for five companies listed on the Nairobi Securities Exchange (NSE-20 Index): British American Tobacco Kenya Ltd (BAT), East African Breweries Ltd (EABL), Kenya Commercial Bank (KCB), Equity Group Holdings (EQTY), and Safaricom (SCOM). The study utilized a longitudinal financial dataset of 6,176 daily trading observations, spanning five years from January 2, 2020, to January 2, 2025. The implementation of the predictive models was based on three historical lagging features (Lagt-1, Lagt-2, and Lagt-3) and a 5-day rolling moving average (MA5) which were created to capture localized momentum. Furthermore, a strict chronological data split involving 80% observations (n =4,941) for training partition and 20% observations (n =1,235) for testing partition was enforced to minimize data leakage and enhance model evaluation. The test partition was then used to evaluate model performance using Root Mean Square Error (RMSE), Mean Absolute Percentage Error (MAPE), Mean Bias Error (MBE), and the coefficient of determination (R2). The findings depicted high out-of-sample goodness-of-fit metrics, with R2 values consistently exceeding 0.9300 for both ANN and RF models across all five equities. The ANN model tracking KCB Group achieved the highest R2 of 0.9881. For BAT, the ANN achieved a lower RMSE of 4.48 (MAPE = 0.61%); however, the RF model deviated by 5.93 (MAPE = 1.01%). Moreover, the ANN model achieved a significantly lower error rate for SCOM (RMSE = 0.31) outperforming the RF model (RMSE = 0.38). The RF model depicted a highly persistent, negative bias across all equities except EABL, peaking at MBE of 0.32 for BAT Kenya. However, the ANN model depicted a mixed directional bias error, generating a positive bias of 0.19 for BAT (MBE = 0.19), while minimal negative bias errors across the remaining four companies. The persistent out-of-sample predictive achievements decisively reject the strict application of the semi-strong form of the Efficient Market Hypothesis (EMH) on the NSE, instead validating the use of the Adaptive Market Hypothesis (AMH). This implies persistent price predictability at the NSE, therefore, necessitating the need for stronger marketing strategies, improvement in investor sentiment, and enhancement of disclosure frameworks.

Published in Science Journal of Business and Management (Volume 14, Issue 4)
DOI 10.11648/j.sjbm.20261404.16
Page(s) 211-233
Creative Commons

This is an Open Access article, distributed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution and reproduction in any medium or format, provided the original work is properly cited.

Copyright

Copyright © The Author(s), 2026. Published by Science Publishing Group

Keywords

Stock Price Prediction, Artificial Neural Network, Random Forest, Nairobi Securities Exchange, Time Series Forecasting, Machine Learning, Efficient Market Hypothesis

References
[1] Akhtar, M. M., Zamani, A. S., Khan, S., Shatat, A. S. A., Dilshad, S., & Samdani, F. (2022). Stock market prediction based on statistical data using machine learning algorithms. Journal of King Saud University-Science, 34(4), 101940.
[2] Bansal, M., Goyal, A., & Choudhary, A. (2022). Stock market prediction with high accuracy using machine learning techniques. Procedia Computer Science, 215, 247-265.
[3] Biau, G., & Scornet, E. (2016). A random forest guided tour. Test, 25(2), 197-227.
[4] Chang, V., Xu, Q. A., Chidozie, A., & Wang, H. (2024). Predicting economic trends and stock market prices with deep learning and advanced machine learning techniques. Electronics, 13(17), 3396.
[5] Chong, E., Han, C., & 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.
[6] Cleveland, W. S., & McGill, R. (1984). Graphical perception: Theory, experimentation, and application to the development of graphical methods. Journal of the American statistical association, 79(387), 531-554.
[7] Contreras, I., Hidalgo, J. I., & Núñez-Letamendia, L. (2012). A GA combining technical and fundamental analysis for trading the stock market. In European Conference on the Applications of Evolutionary Computation (pp. 174-183). Springer.
[8] Dar, A. A., Jain, A., Malhotra, M., Farooqi, A. R., Albalawi, O., Khan, M. S., & Hiba. (2024). Time Series analysis with ARIMA for historical stock data and future projections. Soft computing, 28(21), 12531-12542.
[9] Dhyani, B., Jain, A., Barthwal, A., & Kumar, M. (2022, November). The prediction of closing prices of company stocks using random forests and artificial neural networks. In AIP Conference Proceedings (Vol. 2481, No. 1, p. 020016). AIP Publishing LLC.
[10] Dietterich, T. G. (2000). Ensemble methods in machine learning. In International Workshop on Multiple Classifier Systems (pp. 1-15). Springer.
[11] Durairaj, D. M., & Mohan, B. K. (2022). A convolutional neural network based approach to financial time series prediction. Neural Computing and Applications, 34(16), 13319-13337.
[12] Eiamkanitchat, N., Moontuy, T., & Ramingwong, S. (2017). Fundamental analysis and technical analysis integrated system for stock filtration. Cluster Computing, 20(1), 883-894.
[13] Fama, E. F. (1970). Efficient capital markets: A review of theory and empirical work. The Journal of Finance, 25(2), 383-417.
[14] Gandhmal, D. P., & Kumar, K. (2019). Systematic analysis and review of stock market prediction techniques. Computer Science Review, 34, 100190.
[15] Goel, H., & Singh, N. P. (2022). Dynamic prediction of Indian stock market: An artificial neural network approach. International Journal of Ethics and Systems, 38(1), 35-46.
[16] HaBib, H., Kashyap, G. S., Tabassum, N., & Tabrez, N. (2023). Stock price prediction using artificial intelligence based on LSTM--deep learning model. In Artificial Intelligence & Blockchain in Cyber Physical Systems (pp. 93-99). CRC Press.
[17] Hiransha, M. E. A. G., Gopalakrishnan, E. A., & Soman, K. P. (2018). NSE stock market prediction using deep-learning models. Procedia computer science, 132, 1351-1362.
[18] Ho, S. Y., & Njindan Iyke, B. (2017). Determinants of stock market development: a review of the literature. Studies in Economics and Finance, 34(1), 143-164.
[19] Jiang, W. (2021). Applications of deep learning in stock market prediction: recent progress. Expert Systems with Applications, 184, 115537.
[20] Kayit, A. D., & Ismail, M. T. (2025). Advancing stock price prediction through the development of hybrid ensembles: a comprehensive comparative analysis of machine learning approaches. Journal of Big Data, 12(1), 232.
[21] Krauss, C., Do, X. A., & Huck, N. (2017). Deep neural networks, gradient-boosted trees, random forests: Statistical arbitrage on the S&P 500. European Journal of Operational Research, 264(3), 1000–1015.
[22] Kumar, D., Sarangi, P. K., & Verma, R. (2022). A systematic review of stock market prediction using machine learning and statistical techniques. Materials Today: Proceedings, 49, 3187-3191.
[23] Kumar, M., & Thenmozhi, M. (2014). Forecasting stock index returns using ARIMA-SVM, ARIMA-ANN, and ARIMA-random forest hybrid models. International Journal of Banking, Accounting and Finance, 5(3), 284-308.
[24] Kurani, A., Doshi, P., Vakharia, A., & Shah, M. (2023). A comprehensive comparative study of artificial neural network (ANN) and support vector machines (SVM) on stock forecasting. Annals of data science, 10(1), 183-208.
[25] Lehkonen, H., & Heimonen, K. (2015). Democracy, political risks and stock market performance. Journal of International Money and Finance, 59, 77-99.
[26] Liu, X., & Wang, W. (2025). Improving sliding window effect of LSTM in stock prediction based on econometrics theory. Computational Economics, 65(4), 2057-2080.
[27] Macharia, K. (2025). Enhancing Stock Market Forecasting with ARIMA and Artificial Neural Networks. Africa Journal of Technical and Vocational Education and Training, 10(1), 129-137.
[28] Macharia, K., Atitwa, E., Mugo, D., & Kawira, M. (2025). Modeling stock price trends and volatility in emerging markets using ARIMA and GARCH approaches. International Journal of Advanced and Applied Sciences, 12(7), 134.
[29] Maingo, I., Ravele, T., & Sigauke, C. (2025). A fusion of statistical and machine learning methods: GARCH-XGBoost for improved volatility modelling of the JSE Top40 index. International Journal of Financial Studies, 13(3), 155.
[30] Mehtab, S., Sen, J., & Dutta, A. (2020). Stock price prediction using machine learning and LSTM-based deep learning models. In Symposium on Machine Learning and Metaheuristics Algorithms, and Applications (pp. 88-106). Springer.
[31] Mehtarizadeh, H., Mansouri, N., Mohammad Hasani Zade, B., & Hosseini, M. M. (2025). Stock price prediction with SCA-LSTM network and Statistical model ARIMA-GARCH. The Journal of Supercomputing, 81(2), 366.
[32] Mintarya, L. N., Halim, J. N., Angie, C., Achmad, S., & Kurniawan, A. (2023). Machine learning approaches in stock market prediction: A systematic literature review. Procedia Computer Science, 216, 96-102.
[33] Mohan, N., Jha, P., Laha, A. K., & Dutta, G. (2005). Artificial Neural Network Models for forecasting stock price index in Bombay stock exchange. IIMA Working Papers, (2005-10), 01.
[34] Naeem, M., Jassim, H. S., & Korsah, D. (2024). The application of machine learning techniques to predict stock market crises in Africa. Journal of Risk and Financial Management, 17(12), 554.
[35] Nti, I. K., Adekoya, A. F., & Weyori, B. A. (2020). A systematic review of fundamental and technical analysis of stock market predictions. Artificial Intelligence Review, 53(4), 3007-3057.
[36] Nyabuto, F. (2026). Cross-Sectional Return Prediction in a Small, Illiquid Equity Market: Machine Learning Evidence from the Nairobi Securities Exchange. Illiquid Equity Market: Machine Learning Evidence from the Nairobi Securities Exchange (March 31, 2026).
[37] Omar, A. B., Huang, S., Salameh, A. A., Khurram, H., & Fareed, M. (2022). Stock market forecasting using the random forest and deep neural network models before and during the COVID-19 period. Frontiers in Environmental Science, 10, 917047.
[38] Osas, I. O., & Alfa, M. L. (2026). Machine learning and stock return prediction: evidence from the Nigerian emerging markets. International Journal of Accounting, Management and Economic Review, 2(2), 641-658.
[39] Oukhouya, H., Lmakri, A., El Yahyaoui, M., Guerbaz, R., El Melhaoui, S., Faizi, M., & El Himdi, K. (2025). Predictive modeling for the Moroccan financial market: a nonlinear time series and deep learning approach. Future Business Journal, 11(1), 218.
[40] Oyedele, o. (2026). Comparative analysis and ranking of hybrid machine learning and garch models for stock market volatility in SADC financial markets. Prizren Social Science Journal, 10(2), 56.
[41] Pan, H., Tang, Y., & Wang, G. (2024). A stock index futures price prediction approach based on the MULTI-GARCH-LSTM mixed model. Mathematics, 12(11), 1677.
[42] Pan, L., & Mishra, V. (2018). Stock market development and economic growth: Empirical evidence from China. Economic Modelling, 68, 661-673.
[43] Pang, X., Zhou, Y., Wang, P., Lin, W., & Chang, V. (2020). An innovative neural network approach for stock market prediction. The Journal of Supercomputing, 76(3), 2098-2118.
[44] Pinker, S. (2014). A theory of graph comprehension. In Artificial intelligence and the future of testing (pp. 73-126). Psychology Press.
[45] Pokou, F., Sadefo Kamdem, J., & Benhmad, F. (2024). Hybridization of ARIMA with Learning Models for Forecasting of Stock Market Time Series: F. POKOU et al. Computational Economics, 63(4), 1349-1399.
[46] Richardson, S., Tuna, I., & Wysocki, P. (2010). Accounting anomalies and fundamental analysis: A review of recent research advances. Journal of Accounting and Economics, 50(2-3), 410-454.
[47] Rouf, N., Malik, M. B., Arif, T., Sharma, S., Singh, S., Aich, S., & Kim, H. C. (2021). Stock market prediction using machine learning techniques: a decade survey on methodologies, recent developments, and future directions. Electronics, 10(21), 2717.
[48] Rout, S. B., Mishra, S., & Mishra, S. (2017). A review on application of artificial neural network (ANN) on protein secondary structure prediction. In 2017 Second International Conference on Electrical, Computer and Communication Technologies (ICECCT) (pp. 1-6). IEEE.
[49] Saberironaghi, M., Ren, J., & Saberironaghi, A. (2025). Stock market prediction using machine learning and deep learning techniques: A review. AppliedMath, 5(3), 76.
[50] Speiser, J. L., Miller, M. E., Tooze, J., & Ip, E. (2019). A comparison of random forest variable selection methods for classification prediction modeling. Expert systems with applications, 134, 93-101.
[51] Umoru, D., Damudi, A., Igbinovia, B., & Obomeghie, M. A. (2026). Rethinking Financial Markets’ Forecasting: The Superiority of Neural Networks Over KNN and Random Forest. British Journal of Business Sciences, 41-66.
[52] Urquhart, A., & McGroarty, F. (2016). Are stock markets really efficient? Evidence of the adaptive market hypothesis. International Review of Financial Analysis, 47, 130-141.
[53] Uzoaga, G., Adenomon, M., Nweze, N., & Maijamaa, B. (2025). Predictive machine learning methods for stock returns among emerging economies in Africa. Science World Journal, 20(3), 941–947.
[54] Vochozka, M., Horák, J., Krulický, T., & Pardal, P. (2020). Predicting future Brent oil price on global markets. Acta Montanistica Slovaca, 25(3), 375.
[55] Yetis, Y., Kaplan, H., & Jamshidi, M. (2014). Stock market prediction by using artificial neural network. In 2014 World Automation Congress (WAC) (pp. 718-722). IEEE.
Cite This Article
  • APA Style

    Chepngetich, J., Koech, J., Otieno, A., Koech, E. (2026). Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange. Science Journal of Business and Management, 14(4), 211-233. https://doi.org/10.11648/j.sjbm.20261404.16

    Copy | Download

    ACS Style

    Chepngetich, J.; Koech, J.; Otieno, A.; Koech, E. Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange. Sci. J. Bus. Manag. 2026, 14(4), 211-233. doi: 10.11648/j.sjbm.20261404.16

    Copy | Download

    AMA Style

    Chepngetich J, Koech J, Otieno A, Koech E. Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange. Sci J Bus Manag. 2026;14(4):211-233. doi: 10.11648/j.sjbm.20261404.16

    Copy | Download

  • @article{10.11648/j.sjbm.20261404.16,
      author = {Jackline Chepngetich and Julius Koech and Argwings Otieno and Eliud Koech},
      title = {Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange},
      journal = {Science Journal of Business and Management},
      volume = {14},
      number = {4},
      pages = {211-233},
      doi = {10.11648/j.sjbm.20261404.16},
      url = {https://doi.org/10.11648/j.sjbm.20261404.16},
      eprint = {https://article.sciencepublishinggroup.com/pdf/10.11648.j.sjbm.20261404.16},
      abstract = {Accurate stock price prediction is challenging due to the dynamic, non-linear, and noisy nature of financial markets. Traditional methods, such as technical and fundamental analysis, are often subjective and limited. However, machine learning techniques offer significant potential for improved forecasting. This study compared the performance of Artificial Neural Network (ANN) and Random Forest (RF) models in predicting the next-day closing stock prices for five companies listed on the Nairobi Securities Exchange (NSE-20 Index): British American Tobacco Kenya Ltd (BAT), East African Breweries Ltd (EABL), Kenya Commercial Bank (KCB), Equity Group Holdings (EQTY), and Safaricom (SCOM). The study utilized a longitudinal financial dataset of 6,176 daily trading observations, spanning five years from January 2, 2020, to January 2, 2025. The implementation of the predictive models was based on three historical lagging features (Lagt-1, Lagt-2, and Lagt-3) and a 5-day rolling moving average (MA5) which were created to capture localized momentum. Furthermore, a strict chronological data split involving 80% observations (n =4,941) for training partition and 20% observations (n =1,235) for testing partition was enforced to minimize data leakage and enhance model evaluation. The test partition was then used to evaluate model performance using Root Mean Square Error (RMSE), Mean Absolute Percentage Error (MAPE), Mean Bias Error (MBE), and the coefficient of determination (R2). The findings depicted high out-of-sample goodness-of-fit metrics, with R2 values consistently exceeding 0.9300 for both ANN and RF models across all five equities. The ANN model tracking KCB Group achieved the highest R2 of 0.9881. For BAT, the ANN achieved a lower RMSE of 4.48 (MAPE = 0.61%); however, the RF model deviated by 5.93 (MAPE = 1.01%). Moreover, the ANN model achieved a significantly lower error rate for SCOM (RMSE = 0.31) outperforming the RF model (RMSE = 0.38). The RF model depicted a highly persistent, negative bias across all equities except EABL, peaking at MBE of 0.32 for BAT Kenya. However, the ANN model depicted a mixed directional bias error, generating a positive bias of 0.19 for BAT (MBE = 0.19), while minimal negative bias errors across the remaining four companies. The persistent out-of-sample predictive achievements decisively reject the strict application of the semi-strong form of the Efficient Market Hypothesis (EMH) on the NSE, instead validating the use of the Adaptive Market Hypothesis (AMH). This implies persistent price predictability at the NSE, therefore, necessitating the need for stronger marketing strategies, improvement in investor sentiment, and enhancement of disclosure frameworks.},
     year = {2026}
    }
    

    Copy | Download

  • TY  - JOUR
    T1  - Comparing Artificial Neural Network and Random Forest Models for Predicting Stock Prices at the Nairobi Securities Exchange
    AU  - Jackline Chepngetich
    AU  - Julius Koech
    AU  - Argwings Otieno
    AU  - Eliud Koech
    Y1  - 2026/11/26
    PY  - 2026
    N1  - https://doi.org/10.11648/j.sjbm.20261404.16
    DO  - 10.11648/j.sjbm.20261404.16
    T2  - Science Journal of Business and Management
    JF  - Science Journal of Business and Management
    JO  - Science Journal of Business and Management
    SP  - 211
    EP  - 233
    PB  - Science Publishing Group
    SN  - 2331-0634
    UR  - https://doi.org/10.11648/j.sjbm.20261404.16
    AB  - Accurate stock price prediction is challenging due to the dynamic, non-linear, and noisy nature of financial markets. Traditional methods, such as technical and fundamental analysis, are often subjective and limited. However, machine learning techniques offer significant potential for improved forecasting. This study compared the performance of Artificial Neural Network (ANN) and Random Forest (RF) models in predicting the next-day closing stock prices for five companies listed on the Nairobi Securities Exchange (NSE-20 Index): British American Tobacco Kenya Ltd (BAT), East African Breweries Ltd (EABL), Kenya Commercial Bank (KCB), Equity Group Holdings (EQTY), and Safaricom (SCOM). The study utilized a longitudinal financial dataset of 6,176 daily trading observations, spanning five years from January 2, 2020, to January 2, 2025. The implementation of the predictive models was based on three historical lagging features (Lagt-1, Lagt-2, and Lagt-3) and a 5-day rolling moving average (MA5) which were created to capture localized momentum. Furthermore, a strict chronological data split involving 80% observations (n =4,941) for training partition and 20% observations (n =1,235) for testing partition was enforced to minimize data leakage and enhance model evaluation. The test partition was then used to evaluate model performance using Root Mean Square Error (RMSE), Mean Absolute Percentage Error (MAPE), Mean Bias Error (MBE), and the coefficient of determination (R2). The findings depicted high out-of-sample goodness-of-fit metrics, with R2 values consistently exceeding 0.9300 for both ANN and RF models across all five equities. The ANN model tracking KCB Group achieved the highest R2 of 0.9881. For BAT, the ANN achieved a lower RMSE of 4.48 (MAPE = 0.61%); however, the RF model deviated by 5.93 (MAPE = 1.01%). Moreover, the ANN model achieved a significantly lower error rate for SCOM (RMSE = 0.31) outperforming the RF model (RMSE = 0.38). The RF model depicted a highly persistent, negative bias across all equities except EABL, peaking at MBE of 0.32 for BAT Kenya. However, the ANN model depicted a mixed directional bias error, generating a positive bias of 0.19 for BAT (MBE = 0.19), while minimal negative bias errors across the remaining four companies. The persistent out-of-sample predictive achievements decisively reject the strict application of the semi-strong form of the Efficient Market Hypothesis (EMH) on the NSE, instead validating the use of the Adaptive Market Hypothesis (AMH). This implies persistent price predictability at the NSE, therefore, necessitating the need for stronger marketing strategies, improvement in investor sentiment, and enhancement of disclosure frameworks.
    VL  - 14
    IS  - 4
    ER  - 

    Copy | Download

Author Information
  • Sections