Next Article in Journal
Reinforcement Learning Pair Trading: A Dynamic Scaling Approach
Previous Article in Journal
Bachelier’s Market Model for ESG Asset Pricing
Previous Article in Special Issue
Forecasting Agriculture Commodity Futures Prices with Convolutional Neural Networks with Application to Wheat Futures
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

The Application of Machine Learning Techniques to Predict Stock Market Crises in Africa

by
Muhammad Naeem
1,2,*,
Hothefa Shaker Jassim
1 and
David Korsah
3
1
Mathematics & Computer Science Department, Modern College of Business and Science, Muscat 133, Oman
2
UCP Business School, University of Central Punjab, Lahore 54782, Pakistan
3
Department of Finance, University of Ghana Business School, Legon, Accra LG78, Ghana
*
Author to whom correspondence should be addressed.
J. Risk Financial Manag. 2024, 17(12), 554; https://doi.org/10.3390/jrfm17120554
Submission received: 24 October 2024 / Revised: 29 November 2024 / Accepted: 2 December 2024 / Published: 10 December 2024
(This article belongs to the Special Issue Investment Management in the Age of AI)

Abstract

:
This study sought to ascertain a machine learning algorithm capable of predicting crises in the African stock market with the highest accuracy. Seven different machine-learning algorithms were employed on historical stock prices of the eight stock markets, three main sentiment indicators, and the exchange rate of the respective countries’ currencies against the US dollar, each spanning from 1 May 2007 to 1 April 2023. It was revealed that extreme gradient boosting (XGBoost) emerged as the most effective way of predicting crises. Historical stock prices and exchange rates were found to be the most important features, exerting strong influences on stock market crises. Regarding the sentiment front, investors’ perceptions of possible volatility on the S&P 500 (Chicago Board Options Exchange (CBOE) VIX) and the Daily News Sentiment Index were identified as influential predictors. The study advances an understanding of market sentiment and emphasizes the importance of employing advanced computational techniques for risk management and market stability.

1. Introduction

Over the years, stock markets across the globe have suffered the devastation of numerous crisis episodes in the financial sector, which, in many cases, has resulted in the complete depletion of investors’ gains. Notable among them are the Great Depression of the 1930s, the Black Monday crash of 1987, the Dot-Com bubble burst of 2000, the Global Financial Crisis (GFC) of 2008, and the COVID-19 pandemic. The impacts of these phenomena have become more pronounced in recent times due to increased interdependence and connectedness among financial markets (Mensi et al. 2018; Choi 2021).
Emerging stock markets, particularly in Africa, are affected the worst by such crises, given that most of the markets are generally at the nascent stage (Mu et al. 2013). Evidently, stock markets in Africa witnessed a sharp decline in portfolio investment during the 2007–2009 GFC (Brambila-Macias and Massa 2010; Osakwe et al. 2020). The crisis further occasioned significant divestments and a reversal of capital flow in various stock markets in Africa, a development largely attributed to the overvaluation of equities and an increase in expected return uncertainty (Maimbo et al. 2011).
It is pertinent to note that such crises in the stock market could be evasive, in many cases, outwitting the most vigilant investors. Generally, a stock market crisis occurs when there is a sudden and significant decline in the value of stock prices in a particular or multiple markets (Lu et al. 2021). This is mostly characterized by the panic sale of stocks among investors, resulting in a further decline in prices. In light of the attendant ramifications of crisis episodes, the literature is replete with studies on the prediction of crises in the financial sector, with a focus on debt crises (Savona and Vezzoli 2015; Dawood et al. 2017), currency crises (Oet et al. 2013) and banking crises (Geršl and Jašová 2018).
Regrettably, the few studies that sought to predict crises in the stock market were largely concentrated in developed countries (Chatzis et al. 2018; Samitas et al. 2020; Javid et al. 2022; Naik and Mohan 2021), with the majority of recent research stressing the significance of macroeconomic factors (Abbas and Wang 2020; Acosta-González et al. 2019) and political factors (Herrera et al. 2020; Hillier and Loncan 2019; Gandhmal and Kumar 2019) in stock market crisis predictions. Even more worrying is the dearth of literature on the role of investor sentiment in inducing stock market crises in emerging markets, particularly in Africa.
In light of this, we seek to achieve three critical objectives. Firstly, employ different machine learning algorithms to predict crises in the African stock market, taking into consideration daily stock market prices and investor sentiment indicators as the main variables of interest and exchange rates, a key determinant of price movements in stock markets in Africa (Zubair and Aladejare 2017; Sikhosana and Aye 2018; Baranidharan and Alex 2020). Secondly, discover the feature importance of the input variables, paying critical attention to sentiment indicators, and finally, bring to bear the relative importance or contribution of each feature (input variable) in predicting stock market crises.
We found that extreme gradient boosting (XGBoost) emerged as the most effective in predicting crises. Historical stock prices and exchange rates were found to be the most important features. On the sentiment front, investors perceptions’ of possible volatility on the S&P 500 (Chicago Board Options Exchange (CBOE) VIX) and the Daily News Sentiment Index were identified as influential predictors.
To the best of our knowledge, this is the first study to predict stock market crises in eight carefully selected stock markets across five geographical zones in Africa, namely, North Africa, South Africa, East Africa, West Africa, and Central Africa. Additionally, this study stands out in the literature as the first of its kind to employ various sentiment indicators’ key sources, namely social media, stock markets, and newspapers.
Overall, this study advances the understanding of market sentiment and its role in predicting stock market crises in Africa. The combination of sentiment indicators, historical stock prices, exchange rates, and machine learning algorithms, with XGBoost leading the way, opens up a new avenue for research and practical applications in the domain of financial market analysis. The findings underscore the importance of considering investor sentiment and employing advanced computational techniques in improving risk management strategies and promoting market stability.
The remaining sections of the paper delve into the Section 2, Section 3, Section 4 and Section 5.

2. Literature Review

The evolution of behavioral finance theories has sparked debate about the impact of investor attitudes on asset returns and volatilities. Several empirical and theoretical studies have probed investor mood and its unavoidable implications for stock prices, portfolio selection, and asset management. Baker and Wurgler (2007) describe investor sentiment’s impact on returns and volatility as a combination of investors’ reactions to prevailing market conditions and unwarranted expectations of future cash flows.
Verma and Verma (2008) assess the effect of retail and noisy traders on price volatility and discover that the emotions of individual and institutional investors influence the market. The study further contends that stock market reactions to volatility are diverse and depend largely on variances in shareholder sentiment. Similarly, Yang and Copeland (2014) discovered that investor sentiment has an unbalanced long-term and short-term impact on volatility. They concluded that bullish feelings have a beneficial effect on short-term volatility while having a negative effect on long-term volatility, consistent with a study by Qiang and Shu-e (2009), who established that positive and negative sentiments have differing effects on stock price variation. Chi et al. (2012) investigated the impact of investor sentiment on stock returns and volatility in the Chinese stock market by using mutual fund flows as an investor sentiment proxy and noticed that investor attitude has a significant influence on stock performance.
It is worth stating that there is an apparent bone of contention regarding the impact of sentiment on stock market performance. While a replete of studies found a positive relationship between sentiment and stock market returns and volatilities, others found a negative relationship between same. Nonetheless, negative investor sentiment appears to have a greater impact on stock performance than positive investor sentiment. Ryu et al. (2017) investigated the daily stock prices of various manufacturing companies as well as the trading volumes classified by three investor groups in the Korean market. The psychological line index (PLI), relative strength index (RSI), logarithm of trade volume (LTV), and adjusted turnover rate (ATR) are employed as daily measures of market attitude and expectations. It was revealed that there is a positive relationship between sentiment and stock return. A subsequent study by Kim et al. (2019) found that negative news tends to have a stronger impact on stock returns than positive news. Seok et al. (2019) used firm-specific investor sentiment and daily stock returns to investigate the relationship between investor sentiment and asset returns in the Korean stock market. The study employed regression analysis on long-short portfolios and principal component analysis of a relative strength index, logarithm of trading volume, adjusted turnover rate, and psychological line indicator to measure the sentiment of individual firms on a daily basis.
Kumari and Mahakud (2016) researched the impact of investor sentiment on the Indian stock market performance. We observed that investor sentiment significantly influences market volatility, consistent with an earlier finding by Chandra and Thenmozhi (2013). Using monthly data from the National Stock Exchange of India from July 2001 to December 2013, Naik and Padhi (2016) explore the relationship between investor sentiment and stock return volatility. A sentiment index was created using principal component analysis and seven implicit market-related indicators. The analysis employed ordinary least squares, vector autoregression, Granger causality, and EGARCH-M models. The findings confirm a strong relationship between the sentiment index and excess market returns. The study further discovered that when the sentiment index is separated into positive and negative sentiment fluctuations, they tend to have asymmetric effects on excess return volatility. Similarly, Aggarwal and Mohanty (2018) investigate the impact of the investor sentiment index on the Indian stock market and discover a favorable correlation between stock returns and investor moods. Bathia and Bredin (2013) assessed the impact of investor sentiment, specifically, the consumer confidence index, equity fund flow, CEEF discount, and equity PCR, on the overall performance of the G7 markets. The panel’s findings indicate that investor sentiment frequently affects stock values. They also find that future returns are low (high) when investor mood is positive (negative).
Recently, Wang et al. (2021) used the consumer confidence index as a sentiment indicator to examine the effect of investor sentiment on the future stock performance of 24 established markets and 26 emerging markets using panel fixed-effect regressions on all sample markets. The results show that, while the effects of investor sentiment are longer-lasting in developed economies, they are more immediate in emerging markets. Small and large equities in developed countries are frequently affected by investor mood over the next two to three years. In emerging nations, there is an instantaneous and often three-year negative correlation between investor sentiment and stock returns. Compared to value stocks, growth equities seem to be less affected by investor sentiment in terms of persistence and economic impact. The study concludes that investor mood has a negative effect on all stock categories, although to varying degrees.
In a recent study, Wang et al. (2022) examined the impact of investor sentiment on 40 international stock markets across the globe. The study applied GARCH-type models and observed evidence of the conditional impact of investor sentiment on stock returns through direct and indirect channels; that is, in bullish (bearish) regimes, optimistic (pessimistic) shifts in investor sentiment would increase (decrease) stock returns.

Theoretical Review

This study is underpinned by two seemingly contrasting theories: the behavioral finance theory and the efficient market hypothesis. While behavioral finance recognizes that humans are prone to cognitive biases, emotions, and heuristics (mental shortcuts) that can lead to systematic errors in judgment and decision-making (Tversky and Kahneman 1973; Odlyzko 2010), the EMH propounded by Fama (1995) and Samuelson (1967) proposed that investors behave in a rational and emotionless manner, and that markets are “information efficient”. Proponents further argue that the prices at which equilibrium is reached are always created by rational investors, and they always equal the discounted value of prospective cash flows.
The foregoing assumptions underlying each theory necessitate a study of this kind to establish whether sentiment (behavioral tendencies) influences stock market crises, as espoused by behavioral finance theorists, or whether sentiment does not play any role in crises, in line with the EMH.

3. Methodology

Different algorithms were considered for building the machine models. These include logistic regression, K-nearest neighbor, decision tree, support vector machine (SVM), random forest, gradient boost, and extreme gradient boosting (XGBoost). A series of steps was employed to build a model from each algorithm. First, a simple model was fitted to the training data, and accuracies were calculated on the training data and test data to determine whether the model is overfitting or underfitting.

3.1. Machine Learning Algorithms

3.1.1. Logistic Regression Classifier

A logistic regression classifier is a common machine learning approach for binary and multi-classification cases. A logistic regression was implemented as a binary case using the scikitlearn framework in Python. Although logistic regression is mostly used for binary cases, it can also be used for multiclass cases. In the multiclass case, the training algorithm uses the one-vs-rest (OvR) scheme if the ‘multi_class’ option is set to ‘ovr’, and uses the cross-entropy loss if the ‘multi_class’ option is set to ‘multinomial’ in scikit learn.
The default scikitlearn regularized logistic regression was implemented using C-ordered arrays for optimal performance. To obtain the best logistic regression for each country dataset, an initial model was built on each country’s training set to obtain knowledge of model performance. The C hyper-parameter was tuned using five-fold grid search cross-validation.

3.1.2. K-Nearest Neighbors (KNN)

K-nearest neighbors (KNN) is a renowned classification algorithm that uses the relationship between observations. It involves a voting system, where the majority class label determines the class label of a new data point among its nearest ‘k’ (where k is an integer) neighbors in the feature space.
A lower K leads to a lower bias and higher variance. In other words, when K is very small, the model becomes complex and may pick up patterns that do not exist. On the other hand, a larger value of K makes the model too simple, highly biased, and unable to identify actual underlying patterns. The model becomes linear. The challenge of choosing the correct K value to optimize the model performance was handled through hyperparameter tuning using grid-search cross-validation.

3.1.3. Decision Tree

The decision tree algorithm adopts a divide-and-conquer strategy, in which a greedy search is conducted to identify the optimal split points within a tree. The splitting process is performed repeatedly and recursively from top to bottom, until the observations are classified under specific class labels. Although decision tree models are good predictors, they are prone to overfitting during the training. As a tree grows in size, it becomes more complex and faces the challenge of maintaining its purity. This usually causes decision trees to overfit. We addressed this challenge using a technique called pruning. Pruning is a process that removes branches that split into features with low importance. Pruning was employed by tuning the max_depth and max_leag_node hyperparameters using grid search cross-validation with five folds, leaving other hyperparameters at their default values. The final decision models were fitted on the training sets with the optimum hyperparameter values.

3.1.4. Support Vector Machine (SVM)

The learning algorithm has a track record that performs well in binary classification cases. This algorithm works by finding a hyperplane that maximizes the margin between two classes. This algorithm can be used to solve nonlinear problems using kernel functions. For instance, (radial basis function) kernel can be used to map data points into a higher-dimensional space, making them linearly separable. Once the data points are mapped, the SVM determines the optimal hyperplane in this new space that can separate the data points into two classes. Other available kernels include polynomial and sigmoid.
Hyperparameter tuning was employed to select the hyperparameters of the evaluated kernels as well as the cost hyperparameter, C, of the SVM using grid search cross-validation. The final models were fitted on the entire training set with the selected hyperparameter values.

3.1.5. Random Forest

Random forest (RF) is an ensemble method that combines the output of multiple decision trees to make predictions. Similarly to decision trees, random forest can also be used for handling both classification and regression problems. Basically, random forest combines many weaker decision trees to form a more robust and accurate model. The intuition behind the random forest algorithm is that by creating a diverse set of decision trees and aggregating their predictions, we reduce the risk of overfitting (fitting noise in the data) and improve the model’s generalization ability. A few hyperparameters, which strongly influence the performance of the random forest algorithm, include the node size, number of trees, and number of features sampled. In implementing random forest in this study, hyperparameter tuning was employed to help select the best hyperparameter values and optimize the model performance. The final models were fitted on the entire training set with the selected hyperparameter values.

3.1.6. Gradient Boost

Gradient boosting is an algorithm that combines several weak models into strong models. It is an ensemble method that involves the sequential correction of the predecessor’s errors and can handle both classification and regression cases. In gradient boosting, the models are trained using their predecessor’s residual errors as labels. It uses a learning rate Eta with values between 0 and 1 to shrink the errors and minimize the loss function, such as the mean squared error or cross-entropy of the previous model based on the use case employing gradient descent. The intuition behind the gradient boosting algorithm is to minimize the loss function by adding decision trees one at a time. The final prediction is the sum of predictions from all the trees. To ensure that the gradient boost algorithm generalizes well, hyperparameter tuning was performed with grid search cross-validation using the Python 3.12.1 machine learning framework scikitlearn. After hyperparameter tuning, the final models were built with the selected values for the entire training set.

3.1.7. Extreme Gradient Boosting (XGBoost)

XGBoost, which stands for “Extreme Gradient Boosting”, is a popular and widely used machine learning algorithm for both regression and classification cases because of its ability to handle large datasets and give high performance. The extreme gradient boosting models can be built using XGBoost which is an optimized distributed gradient boosting library designed for efficient and scalable training of machine learning models. Similarly to any other boosting ensemble, the extreme gradient boosting algorithm combines the predictions of multiple weak models to produce a stronger prediction. The algorithm offers regularization, which allows for the control of overfitting by introducing L1/L2 penalties on the weights and biases of each tree. To enhance the generalization of the algorithm, a hyperparameter was performed using grid-search cross-validation. The models were constructed using the XGBoost 2.1.1 library.

3.2. Stock Market Crisis Variable

This study adopts the crisis indicator ( C M A X t ) advanced by Patel and Sarkar (1998) to identify crises in the respective markets at a point in time. Patel and Sarkar (1998) define a crisis as a significant drop in stock prices relative to the maximum historical price up to time t .
C M A X t = P t max P t 250 ,   P t
where P t represents stock price of the respective 8 markets under consideration in this study at time t , and max P t 250 ,   P t is the maximum value of the stock price index ( P t ) in the last year (250 trading days).
This is followed by identifying crisis episodes. According to Patel and Sarkar (1998), a particular stock market is said to be in crisis at time t if:
C M A X t < μ t λ σ t
where μ t   and   λ σ t   are the mean and the standard deviation of C M A X t , respectively, with the λ set to 3 in line with the study by Duan and Bajona (2008). To ascertain the sensitivity of the λ = 3 to the result, the study set the λ to 2, following studies by Coudert and Gex (2008) and Zouaoui et al. (2011), both conducted in developing markets context, similar to this study, and did not observe any significant variations in the crisis episodes.
To put this in proper perspective, a particular market (each of the 8 markets under consideration) is said to be in crisis at a particular time ( C t ) , as expressed in Equation (3)
C r i s i s   ( C t ) = 1 ,     i f   C M A X t < μ t λ σ t 0 ,     o t h e r w i s e
where C t equals 1 if there is a crisis, and 0 if otherwise.

3.3. Model Evaluation

Model evaluation is the process of using different evaluation metrics to assess a model’s strengths and weaknesses. We considered three main evaluation metrics: confusion matrix, F1 score, and receiver operating characteristic (ROC).

3.3.1. Confusion Matrix

Confusion matrix is a summary of the number of correct and incorrect predictions made by the classification model. It provides measures for calculating other classification metrics, such as accuracy, precision, recall, F1-score, sensitivity, and specificity. At a glance, the confusion matrix presents how well a model generalizes by displaying the number of times it correctly or wrongly classifies the classes involved. In other words, the confusion matrix shows how many Type I and Type II errors a model commits as it displays the number of true positives (the number of times the actual positive values are predicted as positive), true negatives (the number of times actual negative values are predicted as correctly negative values), false positives (the number of times a model incorrectly predicts negative values as positive), and false negatives (the number of times a model incorrectly predicts negative values as positive) produced by the model on the test data. The presence of an event of interest is termed positive, whereas its absence is termed negative.

3.3.2. F1 Score

The F1-score is a classification metric calculated from the precision and recall. This is the harmonic mean of precision and recall, as shown in the formula below.
F 1 = 2 r e c a l l 1 + p r e c i s i o n 1 = 2 p r e c i s i o n r e c a l l p r e c i s i o n + r e c a l l = 2 t p 2 t p + f p + f n
The F1-score values ranged from 0 to 1. High values of the F1-score indicate good model performance, whereas a low F1-score indicates poor performance. Unlike accuracy, the F1-score provides more information, even when the classes are imbalanced, as it combines both precision and recall.
Precision measures the general ability of a model to classify a sample as a positive class. It is the ratio of the number of positive samples correctly classified to the total number of samples classified as positive, irrespective of whether it is correct or incorrect.
P r e c i s i o n = T r u e p o s i t i v e T r u e p o s i t i v e + F a l s e p o s i t i v e
On the other hand, recall measures a model’s ability to detect or predict a positive class. It is the ratio of the number of positive samples correctly classified as positive to the total number of positive samples.
R e c a l l = T r u e p o s i t i v e T r u e p o s i t i v e + F a l s e n e g a t i v e

3.3.3. Receiver Operating Characteristic (ROC)

The (ROC) curve is a probability graph that shows the performance of a model at different threshold levels. This is a plot of the true positive rate (TPR) against the false positive rate (FPR).
TPR is basically a synonym for recall and is calculated as:
TPR   = T P T P + F N  
whilst FPR can be calculated as:
FPR   = F P T P + F N
A good model has TPR and low FPR.

3.4. Data

The study carefully selected eight stock markets from each of the five geographical zones, namely North Africa, South Africa, East Africa, West Africa, and Central Africa, to obtain a fair representation from the continent. The data for the stock market are in daily frequency and are obtained from Bloomberg, spanning from 1 May 2007 to 1 April 2023. The choice of these markets was predicated on the availability of data during the period under consideration, market capitalization of the various stock exchanges, and ensuring fair representation of the geographical zones in Africa. It needs mentioning that stock markets in Africa are riddled with data paucity, hence the data span.
The Daily News Sentiment Index, sourced from the Federal Reserve Bank of San Francisco, Twitter’s Daily Happiness, and the Chicago Board Options Exchange (CBOE) VIX were selected to serve as proxies for investor sentiment. The utilization of US-based investor sentiment indicators stems from the fact that the US equity market has increasingly become a gauge for the rest of the world (Ko and Lee 2015), owing to the significant influence the latter wields on other markets, including Africa (Das and Kumar 2018). The study also extracted data on the exchange rate of the currencies of various countries under consideration against the US dollar from Yahoo Finance, owing to the significant role of the exchange rate in inducing stock market volatility (Celebi and Hönig 2019).
It is worth noting that an exploratory analysis was employed to investigate the relationship among the variables, and also check for data constraints, including missing values, data types of constraints, duplicates, and data inconsistencies. All the variables in the datasets of each country were duly explored prior to building the machine learning models. The variables in each dataset are as follows: VIX Index, VXN Index, sentiment, stock exchange prices, and exchange rate; as was explained above. Whilst VIX Index, VXN Index, and sentiment are the same across the datasets for the different countries, stock exchange prices and exchange rates are peculiar to the respective countries under consideration.

3.4.1. Data Splitting

To ensure that the models generalize well, the data were split into a training set (75% of the entire dataset) and a test set (25% of the entire dataset) for fitting and testing models, respectively. The choice of the aforementioned percentages for data training and testing hinged primarily on the fact they provide superior generalization compared to the default percentage split of 66% training and 34% test after performing a five-fold cross-validation hyper-parameter tuning of the models.

3.4.2. Data Balancing

The exploratory data analysis revealed that there were less crises events than non-crisis events in the datasets for each country because of the scarce nature of global stock crash events. The severe imbalance in the target variable may influence the performance of the fitted machine learning models and make them biased in favor of non-crisis events. To help prevent this possibility, the minority class (crises events) in the training datasets were oversampled using the synthetic minority oversampling technique (SMOTE) with the imblearn library in Python to balance the data.

4. Findings and Discussions

4.1. Confusion Matrix and Recall

Table 1 presents the confusion matrix for the markets under consideration. For brevity, the study concentrates on the first two models with the highest accuracy and the model with the least accuracy in the markets of the respective countries. It is worth emphasizing that true negative (TN) represents the non-crisis episodes that the models were able to accurately classify (predict); false positive (FP) is the number of non-crisis events that were misclassified as crises; false negative (FN) reveals the number crises that were wrongly classified as non-crisis; whilst true positive (TP) reveals the crisis instances that have been accurately predicted out of the total number of instances in the test dataset.
In the case of Ghana (GSE), it can be observed that XGBoost correctly predicted 599 (82.73% of the input data) of non-crisis events, and 113, comprising 15.61% of the test data on crisis. The number of false positive (FP) and false negative (FN) are 3 and 9, representing 0.41% and 1.24%, respectively. This means only 12 (1.65%) of the crisis data were misclassified.
The random forest model correctly predicted 598 non-crisis events and 109 crises. The gradient boost model followed closely, accurately predicting 598 (82.60%) of non-crisis events and 108 (14.92%) crisis episodes. However, the model misclassified 4 (0.55%) non-crisis events as crisis events and 14 (1.93%) crisis events as non-crisis events. In all, 2.48% of the crisis and non-crisis episodes were misclassified.
Further, the logistic regression model recorded the lowest accuracy. It can be observed that 120 (16.57%) of non-crisis events were classified as crisis events. This implies that the model could not correctly predict crisis from the test data, as compared to the rest of the models. This is consistent with a similar study by Liu et al. (2022) which found that, among the machine learning algorithms considered, logistic regression yielded the least accuracy in predicting financial market crisis.
Considering Morocco, the XGBoost and random forest models topped prediction accuracy. The XGBoost misclassified a total of 24 crises and non-crisis events, while the random forest misclassified a total of 24 non-crisis events as crises and four crisis events as non-crisis. Again, the logistic regression recorded the least prediction accuracy, with 204 no-crisis events wrongly classified as crises.
In the case of Tanzania, the XGBoost and the gradient boost were the most accurate classification of crisis and non-crisis events, yielding the same number of TN OF 488 and TP of 152. Similarly to the confusion matrix of the preceding models, the random forest algorithm came up as the weakest predictor, misclassifying 81 crisis events as non-crisis, and 126 non-crisis as crisis. A careful observation of the confusion matrix for the rest of the markets reveals a similar trend. The XBoost recorded the highest number of accurate classifications, with the exception of Tanzania and South Africa, where k-nearest neighbor and random forest algorithms yielded the highest prediction accuracy, respectively. The logistic regression recorded the least accurate predictors across the markets, evidenced by the number of TN, FP, FN, and TP.
Turning to the recall for the minority class (financial crisis), it can be observed from Table 1 that the logistic regression consistently showed very low recall values for the minority class (financial crisis), especially in Ghana (1.6%) and Kenya (3.5%). While better in Morocco (74.6%) and Nigeria (63%), the overall Recall performance is subpar compared to other algorithms. This indicates that logistic regression struggles to predict minority class instances accurately in highly imbalanced datasets. While it might show high overall accuracy (due to good predictions of the majority class), it fails to capture crucial minority events like financial crises, rendering it unreliable for critical decision-making in such contexts.
KNN achieved moderate to high recall in most countries, with the highest performance in Tanzania (95.6%) and Ghana (78%). However, its performance varied across countries, being lower in Nigeria (88%) and Kenya (78%). KNN can perform well in scenarios where the data distribution allows close grouping of minority class instances. However, its sensitivity to class imbalance and data dimensionality may lead to inconsistent results. While better than logistic regression, its variability suggests a need for tuning or alternative approaches in imbalanced datasets.
Decision tree models provided high recall values in most countries, exceeding 90% in Morocco, Tanzania, Nigeria, and Egypt. Performance was slightly lower in Kenya (87.9%) and Ghana (82.8%). The decision tree’s ability to capture patterns in minority classes makes it a strong contender for imbalanced datasets. However, its potential to overfit can lead to inflated recall without generalization, especially in small datasets or those with noisy features.
SVM showed moderate recall performance, with values ranging between 67.6% (Kenya) and 84.1% (Egypt). Ghana and Tanzania saw lower recall (70.5% and 78.9%, respectively). SVM is effective in separating classes but struggles with extreme class imbalances. While it is moderately reliable for minority class prediction, it does not outperform ensemble models and may require oversampling or advanced kernel techniques to improve.
The random forest consistently exhibited excellent recall values, exceeding 90% in Morocco, Tanzania, Nigeria, Egypt, and Kenya. Ghana also had a strong recall of 89.3%. The random forest algorithm excels in handling imbalanced datasets due to its ensemble nature and ability to capture complex relationships. Its high recall across various datasets makes it one of the most robust algorithms for predicting financial crises in this study. It is well-suited for critical applications where minority class accuracy is essential.
The gradient boosting models performed comparably to random forest, with high recall values exceeding 88% in most countries. Egypt (98.4%) and Morocco (95.9%) saw outstanding performance. Gradient boosting is effective at learning minority class patterns while maintaining overall accuracy. However, its longer training time and sensitivity to parameter tuning might make it less efficient compared to random forest in real-time decision systems.
XGBoost had the best overall recall performance, with values exceeding 90% in most countries. Ghana (92.6%), Morocco (95.9%), and Egypt (99.2%) were notable highlights. XGBoost’s handling of class imbalance through weighting and advanced boosting techniques makes it the most reliable algorithm for this task. Its exceptional recall, combined with scalability, makes it ideal for predicting minority-class events like financial crises.

4.2. Test Accuracy and F1-Score

Table 2 presents the test accuracy and F1-score for the countries/markets under consideration. As already highlighted, the F1-score measures the accuracy of a model based on precision and recall, whereas the test accuracy represents the percentage of correct instances out of the total number of instances in the test dataset.
From the test accuracy and F1-score results for the various markets, as presented in Table 2, it is evident that the XGBoost algorithm recorded the highest F1-score and test accuracy across all countries, with the exception of South Africa, Nigeria and Tanzania. It is worth noting that even in South Africa, Tanzania and Nigeria, the XGBoost model recorded a very high F1-score and test accuracy, making it a reliable model for predictions in these countries (markets), in line with Raza and Akhtar (2024) who recorded high test accuracies with data from an emerging market (Pakistan).
The high F1-score implies that the model attains a good balance between precision and recall. In essence, the model performs well in terms of correctly identifying positive instances and capturing them. The high-test accuracy, ranging from 0.966547 to 0.991701, indicates that the model successfully learned and generalized patterns from the training data to make accurate predictions on unseen data.

4.3. Model Performance Across Countries

Figure 1 presents a graphical representation of the performance of each model across the countries, taking into consideration the F1-score. As has already been used, XGBoost recorded the highest F1-score in almost all markets, whereas the logistic regression consistently yielded the lowest F1-score.

4.4. Receiver Operating Characteristic (ROC)

The ROC curve provides a comprehensive visualization of a model’s performance across different classification thresholds. The ROC curve plots the TPR on the y-axis and FPR on the x-axis, with each point on the curve depicting the performance of the model at a particular threshold for classifying positive and negative instances. The ROC curve typically starts at the bottom-left corner (0,0) and moves towards the top-right corner (1,1). The closer the curve is to the top-right corner, the better the performance of the model. A model is said to offer superior performance if its curve is consistently above that of the others.
From Figure 2, the XGBoost, gradient boost and random forest curves, portrayed in red, pink, and blue, respectively, are consistently closer to the top-right corner across all markets. Meanwhile, the ROC curve for XGBoost appears to be slightly above the gradient boost and random forest curves in almost all markets.
Consistent with the test accuracy and F1-score, the logistic regression curve, represented by peach, is below the rest of the curves across the markets, rendering it a weaker predictor.
The result for the ROC is critical in establishing the most accurate algorithm. Indeed, the ROC is deemed as a robust evaluation metric, given that it is threshold-independent, effectively handles imbalanced dataset, and provides comprehensive evaluation of model performance across all operating points.

4.5. Feature Importance

The results, as observed in Figure 3, reveal that historical stock market prices are crucial for stock crisis predictions. Therefore, it is not surprising that stock prices, throughout history, have been the most reliable data source for predicting events (movements) in the stock market, consistent with contemporary findings by Xu and Cohen (2018). Strangely, the exchange rate in Tanzania was found to be more influential in predicting crises on the Dar es Salaam Stock Exchange (DSE) than historical prices. This is in line with a recent study by John and Kisava (2018) and Mwenda et al. (2021), which underlines the significant role of the exchange rate on the DSE. A similar trend was recorded in Rwanda, where the exchange rate had the greatest influence on prediction. This finding is in agreement with a study by Innocent et al. (2018), who underscored the substantial impact of exchange rates on the performance of the Rwandan stock market.
On the sentiment front, Figure 3 presents the heterogeneous findings. The relevance of various sentiment indicators varies from one market to another. In the case of Ghana and Rwanda, Figure 3 shows that the Daily News Sentiment Index, sourced from the website of the Federal Reserve Bank of San Francisco, was very prominent in stock crisis predictions, followed closely by the CBOE VIX. This implies that newspaper-based sentiment and how investors envisage price movements on the S&P 500 are significant sentiment indicators that play a critical role in crisis predictions on the GSE and the Rwanda Stock Exchange. The least important sentiment indicator is Twitter sentiment; thus, it goes without saying that sentiments expressed on social media platforms are less influential in stock crisis predictions on the GSE. In all, it can be argued that sentiment helps improve prediction accuracy, as evidenced by the important contribution of the individual sentiment indicators. This corroborates findings in an earlier study by Khan et al. (2020), suggesting that incorporating sentiment index into a model is capable of increasing prediction accuracy by 3%.
In Nigeria, South Africa, Tanzania, and Morocco, the CBOE VIX recorded the highest feature importance among the sentiment indicators. In the case of Egypt, the CBOE VIX was seemingly at par with the Daily News Sentiment Index as the highest sentiment indicator.
From the foregoing, it can be deduced that expected volatilities on the S&P 500 exert significant importance on the accurate prediction of crises in African stock markets. It can be inferred that investors extend their overall feelings about the future performance of stocks on the S&P 500 to African markets. This makes a lot of sense in real-world situations, given the influence of S&P 500 wields as the main stock benchmark in the USA and other markets across the globe (Fernandes et al. 2014).

5. Conclusions

In conclusion, the effectiveness of the XGBoost algorithm, as the most robust predictor in capturing the complex relationships between the input variables and stock crises in the African context, highlights its ability to handle complex interactions and patterns within the dataset, making it a suitable choice for predicting stock market crises in Africa based on sentiment indicators.
Furthermore, the identification of the CBOE as the most important feature highlights the significance of incorporating human sentiment and perception in market analyses. These surveys provide valuable information on market participants’ opinions and expectations, offering distinct insights into investor sentiment, which considerably influences market dynamics and potential crises. This supports the assertion that investors are not always rational and that their attitudes towards a particular market or asset feed into the general price movement in stock markets.

5.1. Implications of the Study

The findings present implications for various stakeholders, including investors, financial institutions, and policymakers. Accurate predictions of stock market crises enable investors to make informed decisions, manage risks effectively, and potentially enhance investment strategies. Financial institutions can leverage these findings to develop early warning systems and implement risk management practices. Policymakers, on the other hand, can benefit from the insights to design proactive measures aimed at mitigating market instability and fostering investor confidence.

5.2. Limitations of the Study

We concentrated on eight stock markets in Africa. This leaves much to be desired as the findings may not be a true reflection of crisis episodes and, thus, cannot be used for the purpose of generalization. Additionally, we employed general sentiment indexes.

5.3. Recommendations

This study lays the groundwork for further exploration into stock market crisis predictions. Accordingly, future studies could delve deeper into market-specific sentiments that drive stock market dynamics in respective African countries. By expanding the understanding of market sentiment and its impact on crises, researchers can enhance predictive models and risk assessment methodologies, ultimately contributing to more accurate and reliable predictions.

Author Contributions

Conceptualization, M.N. and D.K.; methodology, M.N. and D.K.; software, M.N.; validation, M.N.; formal analysis, M.N. and D.K.; investigation, M.N., D.K. and H.S.J.; resources, D.K.; data curation, M.N. and D.K.; writing—original draft preparation, M.N. and D.K.; writing—review and editing, M.N., D.K. and H.S.J.; visualization, M.N. and D.K.; supervision, M.N. and H.S.J.; project administration, M.N. and H.S.J. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

The data for the stock market are in daily frequency and were gleaned from Bloomberg. Data on exchange rate were sourced from Yahoo Finance, and that of Twitter’s Daily Sentiment Index, Daily News Sentiment Index, CBOE VIX were gleaned from hedonometer, the website of Federal Reserve Bank of San Francisco (https://www.frbsf.org/economic-research/indicators-data/daily-news-sentiment-index/), and https://www.cboe.com/vix/, respectively. The dataset for this study would be made available upon request. Accessed on 1 March 2023.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Abbas, Ghulam, and Shouyang Wang. 2020. Does macroeconomic uncertainty really matter in predicting stock market behavior? A comparative study on China and USA. China Finance Review International 10: 393–427. [Google Scholar] [CrossRef]
  2. Acosta-González, Eduardo, Fernando Fernández-Rodríguez, and Hicham Ganga. 2019. Predicting corporate financial failure using macroeconomic variables and accounting data. Computational Economics 53: 227–57. [Google Scholar] [CrossRef]
  3. Aggarwal, Divya, and Pitabas Mohanty. 2018. Do Indian stock market sentiments impact contemporaneous returns? South Asian Journal of Business Studies 7: 332–46. [Google Scholar] [CrossRef]
  4. Baker, Malcolm, and Jeffrey Wurgler. 2007. Investor sentiment and the cross-section of stock returns. The Journal of Finance 62: 2085–123. [Google Scholar]
  5. Baranidharan, Subburayan, and Aruldoss Alex. 2020. Volatility spillover of exchange rate on stock market evidence from South Africa. Asian Journal of Economics, Finance and Management 2: 131–39. [Google Scholar]
  6. Bathia, Deven, and Don Bredin. 2013. An examination of investor sentiment effect on G7 stock market returns. The European Journal of Finance 19: 909–37. [Google Scholar] [CrossRef]
  7. Brambila-Macias, José, and Isabella Massa. 2010. The global financial crisis and Sub-Saharan Africa: The effects of slowing private capital inflows on growth. African Development Review 22: 366–77. [Google Scholar] [CrossRef]
  8. Celebi, Kaan, and Michaela Hönig. 2019. The impact of macroeconomic factors on the German stock market: Evidence for the crisis, pre-and post-crisis periods. International Journal of Financial Studies 7: 18. [Google Scholar] [CrossRef]
  9. Chandra, Abhijeet, and M. Thenmozhi. 2013. Investor sentiment, volatility and stock return comovements. Volatility and Stock Return Comovements, October 17. [Google Scholar]
  10. Chatzis, Sotirios P., Vassilis Siakoulis, Anastasios Petropoulos, Evangelos Stavroulakis, and Nikos Vlachogiannakis. 2018. Forecasting stock market crisis events using deep and statistical machine learning techniques. Expert Systems with Applications 112: 353–71. [Google Scholar] [CrossRef]
  11. Chi, Lixu, Xintian Zhuang, and Dalei Song. 2012. Investor sentiment in the Chinese stock market: An empirical analysis. Applied Economics Letters 19: 345–48. [Google Scholar] [CrossRef]
  12. Choi, Sun-Yong. 2021. Analysis of stock market efficiency during crisis periods in the US stock market: Differences between the global financial crisis and COVID-19 pandemic. Physica A: Statistical Mechanics and Its Applications 574: 125988. [Google Scholar] [CrossRef]
  13. Coudert, Virginie, and Mathieu Gex. 2008. Does risk aversion drive financial crises? Testing the predictive power of empirical indicators. Journal of Empirical Finance 15: 167–84. [Google Scholar] [CrossRef]
  14. Das, Debojyoti, and Surya Bhushan Kumar. 2018. International economic policy uncertainty and stock prices revisited: Multiple and Partial wavelet approach. Economics Letters 164: 100–8. [Google Scholar] [CrossRef]
  15. Dawood, Mary, Nicholas Horsewood, and Frank Strobel. 2017. Predicting sovereign debt crises: An early warning system approach. Journal of Financial Stability 28: 16–28. [Google Scholar] [CrossRef]
  16. Duan, Peng, and Claustre Bajona. 2008. China’s vulnerability to currency crisis: A KLR signals approach. China Economic Review 19: 138–51. [Google Scholar]
  17. Fama, Eugene F. 1995. Random walks in stock market prices. Financial Analysts Journal 51: 75–80. [Google Scholar] [CrossRef]
  18. Fernandes, Marcelo, Marcelo C. Medeiros, and Marcel Scharth. 2014. Modeling and predicting the CBOE market volatility index. Journal of Banking & Finance 40: 1–10. [Google Scholar]
  19. Gandhmal, Dattatray P., and K. Kumar. 2019. Systematic analysis and review of stock market prediction techniques. Computer Science Review 34: 100190. [Google Scholar] [CrossRef]
  20. Geršl, Adam, and Martina Jašová. 2018. Credit-based early warning indicators of banking crises in emerging markets. Economic Systems 42: 18–31. [Google Scholar] [CrossRef]
  21. Herrera, Helios, Guillermo Ordonez, and Christoph Trebesch. 2020. Political booms, financial crises. Journal of Political Economy 128: 507–43. [Google Scholar] [CrossRef]
  22. Hillier, David, and Tiago Loncan. 2019. Stock market integration, cost of equity capital, and corporate investment: Evidence from Brazil. European Financial Management 25: 181–206. [Google Scholar] [CrossRef]
  23. Innocent, Gatsimbazi, Jaya Shukla, and Patrick Mulyungi. 2018. Effects of macroeconomic variables on stock market performance in Rwanda. Case study of Rwanda Stock Exchange. European Journal of Economic and Financial Research 3. [Google Scholar] [CrossRef]
  24. Javid, Irfan, Rozaida Ghazali, Irteza Syed, Muhammad Zulqarnain, and Noor Aida Husaini. 2022. Study on the Pakistan stock market using a new stock crisis prediction method. PLoS ONE 17: e0275022. [Google Scholar] [CrossRef] [PubMed]
  25. John, Fredynandy M., and Zakayo S. Kisava. 2018. The relationship between stock prices and exchange rates: The focus on Dar Es Salaam stock exchange (DSE). Business and Economic Research 8: 1–12. [Google Scholar] [CrossRef]
  26. Khan, Wasiat, Usman Malik, Mustansar Ali Ghazanfar, Muhammad Awais Azam, Khaled H. Alyoubi, and Ahmed S. Alfakeeh. 2020. Predicting stock market trends using machine learning algorithms via public sentiment and political situation analysis. Soft Computing 24: 11019–43. [Google Scholar] [CrossRef]
  27. Kim, Karam, Doojin Ryu, and Heejin Yang. 2019. Investor sentiment, stock returns, and analyst recommendation changes: The KOSPI stock market. Investment Analysts Journal 48: 89–101. [Google Scholar] [CrossRef]
  28. Ko, Jun-Hyung, and Chang-Min Lee. 2015. International economic policy uncertainty and stock prices: Wavelet approach. Economics Letters 134: 118–22. [Google Scholar] [CrossRef]
  29. Kumari, Jyoti, and Jitendra Mahakud. 2016. Investor sentiment and stock market volatility: Evidence from India. Journal of Asia-Pacific Business 17: 173–202. [Google Scholar] [CrossRef]
  30. Liu, Lanbiao, Chen Chen, and Bo Wang. 2022. Predicting financial crises with machine learning methods. Journal of Forecasting 41: 871–910. [Google Scholar] [CrossRef]
  31. Lu, Shan, Chenhui Liu, and Zhensong Chen. 2021. Predicting stock market crisis via market indicators and mixed frequency investor sentiments. Expert Systems with Applications 186: 115844. [Google Scholar] [CrossRef]
  32. Maimbo, Samuel Munzele, Issa Faye, and Thouraya Triki. 2011. Financing Africa: Through the Crisis and Beyond. Washington, DC: World Bank Publications. [Google Scholar]
  33. Mensi, Walid, Ferihane Zaraa Boubaker, Khamis Hamed Al-Yahyaee, and Sang Hoon Kang. 2018. Dynamic volatility spillovers and connectedness between global, regional, and GIPSI stock markets. Finance Research Letters 25: 230–38. [Google Scholar] [CrossRef]
  34. Mu, Yibin, Janet G. Stotsky, and Peter Phelps. 2013. Bond markets in Africa. Review of Development Finance 3: 121–35. [Google Scholar] [CrossRef]
  35. Mwenda, Beny, B. O. Ndiege, and D. Pastory. 2021. External Factors Influencing Performance of Listed Firms on Dar es Salaam Stock Exchange. In Sustainable Education and Development 9. Cham: Springer International Publishing, pp. 284–96. [Google Scholar]
  36. Naik, Nagaraj, and Biju R. Mohan. 2021. Novel stock crisis prediction technique—A study on indian stock market. IEEE Access 9: 86230–42. [Google Scholar] [CrossRef]
  37. Naik, Pramod Kumar, and Puja Padhi. 2016. Investor sentiment, stock market returns and volatility: Evidence from National Stock Exchange of India. International Journal of Management Practice 9: 213–37. [Google Scholar] [CrossRef]
  38. Odlyzko, Andrew. 2010. Collective hallucinations and inefficient markets: The British Railway Mania of the 1840s. Available online: https://ssrn.com/abstract=1537338 (accessed on 1 September 2024).
  39. Oet, Mikhail V., Timothy Bianco, Dieter Gramlich, and Stephen J. Ong. 2013. SAFE: An early warning system for systemic banking risk. Journal of Banking & Finance 37: 4510–33. [Google Scholar]
  40. Osakwe, Charity, Kelechukwu Stanley Ogbonna Ifunanya, and Victoria Ogochukwu Obi-Nwosu. 2020. Stock Market capitalization and economic growth of Nigeria and South Africa (2000–2018). European Academic Research Journal 7: 5605–23. [Google Scholar]
  41. Patel, Sandeep A., and Asani Sarkar. 1998. Crises in developed and emerging stock markets. Financial Analysts Journal 54: 50–61. [Google Scholar] [CrossRef]
  42. Qiang, Zhang, and Yang Shu-e. 2009. Noise trading, investor sentiment volatility, and stock returns. Systems Engineering-Theory & Practice 29: 40–47. [Google Scholar]
  43. Raza, Hassan, and Zafar Akhtar. 2024. Predicting stock prices in the Pakistan market using machine learning and technical indicators. Modern Finance 2: 46–63. [Google Scholar] [CrossRef]
  44. Ryu, Doojin, Hyeyoen Kim, and Heejin Yang. 2017. Investor sentiment, trading behavior and stock returns. Applied Economics Letters 24: 826–30. [Google Scholar] [CrossRef]
  45. Samitas, Aristeidis, Elias Kampouris, and Dimitris Kenourgios. 2020. Machine learning as an early warning system to predict financial crisis. International Review of Financial Analysis 71: 101507. [Google Scholar] [CrossRef]
  46. Samuelson, Paul A. 1967. Efficient portfolio selection for Pareto-Lévy investments. Journal of Financial and Quantitative Analysis 2: 107–22. [Google Scholar] [CrossRef]
  47. Savona, Roberto, and Marika Vezzoli. 2015. Fitting and forecasting sovereign defaults using multiple risk signals. Oxford Bulletin of Economics and Statistics 77: 66–92. [Google Scholar] [CrossRef]
  48. Seok, Sang Ik, Hoon Cho, and Doojin Ryu. 2019. Firm-specific investor sentiment and the stock market response to earnings news. The North American Journal of Economics and Finance 48: 221–40. [Google Scholar] [CrossRef]
  49. Sikhosana, Ayanda, and Goodness C. Aye. 2018. Asymmetric volatility transmission between the real exchange rate and stock returns in South Africa. Economic Analysis and Policy 60: 1–8. [Google Scholar] [CrossRef]
  50. Tversky, Amos, and Daniel Kahneman. 1973. Availability: A heuristic for judging frequency and probability. Cognitive Psychology 5: 207–32. [Google Scholar] [CrossRef]
  51. Verma, Rahul, and Priti Verma. 2008. Are survey forecasts of individual and institutional investor sentiments rational? International Review of Financial Analysis 17: 1139–55. [Google Scholar] [CrossRef]
  52. Wang, Wenzhao, Chen Su, and Darren Duxbury. 2021. Investor sentiment and stock returns: Global evidence. Journal of Empirical Finance 63: 365–91. [Google Scholar] [CrossRef]
  53. Wang, Wenzhao, Chen Su, and Darren Duxbury. 2022. The conditional impact of investor sentiment in global stock markets: A two-channel examination. Journal of Banking & Finance 138: 106458. [Google Scholar]
  54. Xu, Yumo, and Shay B. Cohen. 2018. Stock movement prediction from tweets and historical prices. Paper presented at 56th Annual Meeting of the Association for Computational Linguistics, Melbourne, Australia, July 15–20, vol. 1, pp. 1970–79. [Google Scholar]
  55. Yang, Yan, and Laurence Copeland. 2014. The Effects of Sentiment on Market Return and Volatility and the Cross-Sectional Risk Premium of Sentiment-Affected Volatility. No. E2014/12. Cardiff Economics Working Papers. Cardiff: Cardiff Business School, Cardiff University. [Google Scholar]
  56. Zouaoui, Mohamed, Genevieve Nouyrigat, and Francisca Beer. 2011. How does investor sentiment affect stock market crises? Evidence from panel data. Financial Review 46: 723–47. [Google Scholar] [CrossRef]
  57. Zubair, Z. A., and S. A. Aladejare. 2017. Exchange rate volatility and stock market performance in Nigeria. Asian Journal of Multidisciplinary Studies 5: 194–201. [Google Scholar]
Figure 1. Model performance across countries. Source: the authors’ construct (2024).
Figure 1. Model performance across countries. Source: the authors’ construct (2024).
Jrfm 17 00554 g001
Figure 2. Receiver operating characteristic (ROC). Source: the authors’ construct (2024).
Figure 2. Receiver operating characteristic (ROC). Source: the authors’ construct (2024).
Jrfm 17 00554 g002aJrfm 17 00554 g002b
Figure 3. Feature importance. Source: the authors’ construct (2024).
Figure 3. Feature importance. Source: the authors’ construct (2024).
Jrfm 17 00554 g003
Table 1. Confusion matrix and recall.
Table 1. Confusion matrix and recall.
Ghana
ModelTNFPFNTPRecall
Logistic regression601 (83.01%)1 (0.14%)120 (16.57%)2 (0.28%)1.6%
K-nearest neighbors570 (78.73%)32 (4.42%)27 (3.73%)96 (13.12%)78%
Decision tree578 (79.83%)24 (3.31%)21 (2.9%)101 (13.95%)82.8%
SVM575 (79.42%)27 (3.73%)36 (4.97%)86 (11.88%)70.5%
Random forest598 (82.60%)4 (0.55%)13 (1.80%)109 (15.06%)89.3%
Gradient boost598 (82.60%)4 (0.55%)14 (1.93%)108 (14.92%)88.5%
XGBoost599 (82.73%)3 (0.41%)9 (1.24%)113 (15.61%)92.6%
Morocco
ModelTNFPFNTPRecall
Logistic regression374 (51.66%)204 (28.18%)37 (5.11%)109 (15.06%)74.6%
K-nearest neighbors493 (68.09%)85 (11.74%)41 (5.66%)105 (14.40%)71.9%
Decision tree547 (75.55%)31 (4.28%)9 (1.24%)137 (18.92%)93.8%
SVM555 (76.66%)23 (3.18%)36 (4.97%)110 (15.19%)75.3%
Random forest554 (76.52%)24 (3.31%)4 (0.55%)142 (19.61%)97.2%
Gradient boost550 (75.97%)28 (3.87%)6 (0.83%)140 (19.34%)95.9%
XGBoost560 (77.35%)18 (2.49%)6 (0.83%)140 (19.34%)95.9%
Tanzania
ModelTNFPFNTPRecall
Logistic regression324 (53.03%)126 (20.62%)81 (13.26%)80 (13.09%)49.7%
K-nearest neighbors447 (73.16%)3 (0.49%)7 (1.15%)154 (25.20%)95.6%
Decision tree445 (72.83%)5 (0.82%)11 (1.80%)150 (24.55%)93.2%
SVM424 (69.39%)26 (4.26%)34 (5.56%)127 (20.79%)78.9%
Random forest446 (73%)4 (0.65%)9 (1.47%)152 (24.88%)94.4%
Gradient boost448 (73.32%)2 (0.33%)9 (1.47%)152 (24.88%)94.4%
XGBoost448 (73.32%)2 (0.33%)9 (1.47%)152 (24.88%)94.4%
Kenya
ModelTNFPFNTPRecall
Logistic regression546 (75.41%)5 (0.69%)167 (23.07%)6 (0.83%)3.5%
K-nearest neighbors490 (67.68%)61 (8.43%)38 (5.25%)135 (18.65%)78%
Decision tree531 (73.34%)20 (2.76%)21 (2.90%)152 (20.99%)87.9%
SVM531 (73.34%)20 (2.76%)56 (7.73%)117 (16.16%)67.6%
Random forest543 (75.00%)8 (1.10%)13 (1.80%)160 (22.10%)92.5%
Gradient boost540 (74.59%)11 (1.52%)12 (1.66%)161 (22.24%)93.1%
XGBoost540 (74.50%)11 (1.52%)9 (1.24%)164 (22.65%)94.8%
Nigeria
ModelTNFPFNTPRecall
Logistic regression304 (51.35%)188 (31.76%)37 (6.25%)63 (10.64%)63%
K-nearest neighbors463 (78.21%)29 (4.90%)12 (2.03%)88 (14.86%)88%
Decision tree497 (8.91%)13 (2.20%)9 (1.52%)91 (15.37%)91%
SVM464 (78.38%)28 (4.73%)9 (1.52%)91 (15.37%)91%
Random forest486 (82.09%)6 (1.01%)3 (0.51%)97 (16.39%)97%
Gradient boost486 (82.09%)6 (1.10%)4 (0.68%)96 (16.22%)96%
XGBoost488 (82.43%)4 (0.68%)5 (0.84%)95 (16.05%)95%
Egypt
ModelTNFPFNTPRecall
Logistic regression422 (58.37%)175 (24.20%)43 (5.95%)83 (11.48%)65.9%
K-nearest neighbors536 (74.14%)61 (8.44%)20 (2.77%)106 (14.66%)84.1%
Decision tree589 (81.47%)8 (1.11%)12 (1.66%)114 (15.77%)90.5%
SVM559 (77.32%)38 (5.26%)20 (2.77%)106 (14.66%)84.1%
Random forest587 (81.19%)10 (1.38%)1 (0.14%)125 (17.29%)99.2%
Gradient boost587 (81.19%)10 (1.38%)2 (0.28%)124 (17.15%)98.4%
XGBoost592 (81.88%)5 (0.69%)1 (0.14%)125 (17.29%)99.2%
South Africa
ModelTNFPFNTPRecall
Logistic regression363 (48.76%)271 (37.43%)31 (4.28%)69 (9.53%)69%
K-nearest neighbors566 (78.18%)58 (8.01%)27 (3.73%)73 (10.08%)73%
Decision tree598 (82.60%)26 (3.59%)17 (2.35%)83 (11.46%)83%
SVM594 (82.04%)30 (4.14%)14 (1.93%)86 (11.88%)86%
Random forest614 (84.81%)10 (1.38%)14 (1.93%)86 (11.88%)86%
Gradient boost601 (83.01%)23 (3.18%)15 (2.07%)85 (11.74%)85%
XGBoost610 (84.25%)14 (1.93%)11 (1.52%)89 (12.29%)89%
Rwanda
ModelTNFPFNTPRecall
Logistic regression363 (48.76%)271 (37.43%)31 (4.28%)69 (9.53%)69%
K-nearest neighbors566 (78.18%)58 (8.01%)27 (3.73%)73 (10.08%)73%
Decision tree598 (82.60%)26 (3.59%)17 (2.35%)83 (11.46%)83%
SVM594 (82.04%)30 (4.14%)14 (1.93%)86 (11.88%)86%
Random forest614 (84.81%)10 (1.38%)14 (1.93%)86 (11.88%)86%
Gradient boost601 (83.01%)23 (3.18%)15 (2.07%)85 (11.74%)85%
XGBoost610 (84.25%)14 (1.93%)11 (1.52%)89 (12.29%)89%
Source: the authors’ construction.
Table 2. Accuracies and F1-score.
Table 2. Accuracies and F1-score.
Ghana
ModelTrain AccuracyTest AccuracyF1 Score
XGBoost1.00000.98340.9496
Random forest1.00000.97650.9276
Gradient boost1.00000.97510.9231
Decision tree0.99860.93780.8178
K-nearest neighbors1.00000.91850.7630
SVC0.99590.91290.7319
Logistic regression0.83080.83290.0320
Morocco
ModelTrain AccuracyTest AccuracyF1 Score
XGBoost1.00000.96680.9211
Random forest0.99770.96130.9103
Gradient boost0.99970.95300.8917
Decision tree0.99420.94470.8726
SVC0.99940.91850.7885
K-nearest neighbors1.00000.82590.6250
Logistic regression0.69190.66710.4749
Tanzania
ModelTrain AccuracyTest AccuracyF1 Score
K-nearest neigbors1.00000.98360.9685
Gradient boost1.00000.98190.9651
XGBoost1.00000.98190.9651
Random forest1.00000.97870.9589
Decision tree1.00000.97380.9494
SVC0.99850.90180.8089
Logistic regression0.81050.66120.4359
Nigeria
ModelTrain AccuracyTest AccuracyF1 Score
Random forest1.00000.98480.9557
XGBoost1.00000.98470.9547
Gradient boost1.00000.98310.9505
Decision tree1.00000.96280.8922
SVC0.98610.93750.8310
K-nearest neighbors1.00000.93070.8110
Logistic regression0.65450.61990.35897
Kenya
ModelTrain AccuracyTest AccuracyF1 Score
XGBoost1.00000.97240.9425
Random forest0.99950.97090.9384
Gradient boost1.00000.96820.9333
Decision tree0.99030.94330.8812
SVC0.99860.89500.7548
K-nearest neighbors1.00000.86320.7317
Logistic regression0.76290.76240.0652
Egypt
ModelTrain AccuracyTest AccuracyF1 Score
XGBoost1.00000.99170.9766
Random forest0.99800.98470.9578
Gradient boost0.99970.98340.9538
Decision tree1.00000.97230.9194
SVC0.97820.91970.7852
K-nearest neighbors1.00000.88790.7235
Logistic regression0.66090.69840.4323
South Africa
ModelTrain AccuracyTest AccuracyF1 Score
Random forest1.00000.96690.8776
XGBoost1.00000.9650.8768
Gradient boost0.99910.94750.8173
SVC0.98950.93920.7963
Decision tree0.99910.94060.7943
K-nearest neighbors1.00000.88260.6320
Logistic regression0.61920.58290.3136
Rwanda
ModelTrain AccuracyTest AccuracyF1 Score
Random forest1.00000.96340.8776
XGBoost1.00000.9560.8768
Gradient boost0.99910.94570.8173
SVC0.98950.93290.7963
Decision tree0.99910.94600.7943
K-nearest neighbors1.00000.87260.6320
Logistic regression0.61920.52290.3136
Source: the authors’ construct (2024).
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Naeem, M.; Jassim, H.S.; Korsah, D. The Application of Machine Learning Techniques to Predict Stock Market Crises in Africa. J. Risk Financial Manag. 2024, 17, 554. https://doi.org/10.3390/jrfm17120554

AMA Style

Naeem M, Jassim HS, Korsah D. The Application of Machine Learning Techniques to Predict Stock Market Crises in Africa. Journal of Risk and Financial Management. 2024; 17(12):554. https://doi.org/10.3390/jrfm17120554

Chicago/Turabian Style

Naeem, Muhammad, Hothefa Shaker Jassim, and David Korsah. 2024. "The Application of Machine Learning Techniques to Predict Stock Market Crises in Africa" Journal of Risk and Financial Management 17, no. 12: 554. https://doi.org/10.3390/jrfm17120554

APA Style

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. https://doi.org/10.3390/jrfm17120554

Article Metrics

Back to TopTop