Cracking The Code Unleashing The Power of Sentiment Analysis - ML For Moroccan Stock Market Forecasting
Cracking The Code Unleashing The Power of Sentiment Analysis - ML For Moroccan Stock Market Forecasting
Doni A5
1,2,4
U.G Student, Department of CSE, Sathyabama Institute of Science and Technology, Chennai
3,5
Associate Professor, School of Computing, Sathyabama Institute of Science and Technology, Chennai.
1
[email protected],[email protected],[email protected]
@gmail.com, [email protected]
Abstract - For a long time, the Moroccan stock has attracted opinions of market players. For instance, a drop in stock
the attention of academics and speculative financiers alike. price may signal that investors are losing faith in a certain
Sentiment analysis has developed into a potent instrument for industry because of widespread criticism of relevant
foreseeing market movements, thanks to the growing companies or the industry as a whole. On the other hand, a
importance of social media & the internet. With the use of
ML & sentiment analysis methods, this research suggests a
rise in stock price may result from an increase in investor
new way of looking at the Moroccan stock market. Using NLP, optimism about a firm if sentiment towards it is generally
the study compile opinions from a wide range of internet favourable.
sources, such as social media and news sites. Then Naive Bayes
is used & other ML methods to make predictions about the The primary goal of this research was to examine the
correlation between public opinion & stock market outcomes. Casablanca Stock Exchange through the lens of sentiment
Proposed findings point to encouraging associations between analysis and machine learning. More specifically, opinions
mood and market patterns, suggesting that sentiment research on stocks traded are aggregated on a certain exchange by
has potential as a technique for foreseeing shifts in the stock collecting and analysing data from a wide range of sources
market. Significant consequences for traders, financial experts,
and policymakers interested in the Moroccan stock markets
including social media, news stories, and financial reports.
may be drawn from this research. Machine learning methods like Naive Bayes classifier are
used to extrapolate the sentiment analysis's findings into
Keywords- Moroccan stock market, machine learning, sentiment predictions for the stocks' future performance.
analysis, behavioral finance, investor sentiment, social media,
news, Casablanca SE, Naive Bayes. The findings of this research may aid investors and market
analysts in determining the optimal time to purchase and sell
I. INTRODUCTION stocks. It may help us better understand the role that
emotions and beliefs play in influencing financial markets,
As Morocco's principal stock market, the Moroccan Stock and it may add to the expanding corpus of research on the
Market (also known as the Casablanca Stock Exchange) is use of sentiment analysis in financial forecasts.
located in the Moroccan capital of Casablanca. It first
opened its doors to the public back in 1929, and now it is II. LITERATURE SURVEY
home to more than 80 different listed firms operating in
industries as diverse as banking, telecommunications, The results of studies carried out in the field of behavioural
mining, & energy. The Casablanca Stock Market is a crucial finance have shown that the attitudes and points of view
part of the Moroccan economy, and is often regarded as one held by market participants may have an impact on the stock
of the most significant stock exchanges in all of Africa. market (Khan & Baker, 2020). In addition, keeping up with
the news and monitoring various social media platforms has
How Sentiment Analysis May Help You Make Better shown some fascinating outcomes when applied to the
Financial Predictions? process of predicting the global financial markets (Ammar
et al., 2018). The assessment of the mood of investors is one
Recent years have seen expanding research on the potential of the most important research difficulties that are related
of sentiment analysis for predicting economic outcomes. To with the process of financial forecasting. This is a direct
do sentiment analysis, text data like social media postings, effect of the previous point.
news articles, even financial reports are analysed utilising
NLP & ML methods to detect the author's intent. In the [1] Belghitar and Clark (2018) investigated the Moroccan
world of finance, the practise of sentiment analysis seeks to frontier market in order to analyse the characteristics that
do just that: anticipate the direction of the market based on affect individual investor sentiment as well as the impact
the general public's opinion of where it's headed. that sentiment has on stock returns. The research was carried
out in order to study the Moroccan frontier market. In order
In order to make accurate financial forecasts, you need to to address the research question, "What elements impact
use sentiment analysis since it reveals the true feelings and individual investor sentiment?" this study was carried out.
They discovered the conclusion that investor sentiment over from becoming unstable, the Moroccan government should
a short length of time has a positive link with stock returns, take action to encourage investment from other nations.
but investor sentiment over a long period of time has a
negative correlation with stock returns. This was a [6] Research on information transmission and volatility
surprising finding for them. The research also discovered spillovers between oil prices and stock markets was carried
that the behaviour of investors may be influenced by a out by Azzouz et al. (2021) in the countries that make up the
number of factors, including the volatility of the market, the Gulf Cooperation Council as well as in Morocco. The focus
liquidity of the market, and the amount of trading activity. of this research was on the relationship between oil prices
All of these factors have a part in determining the level of and stock markets. The stock market and oil prices were the
investor optimism. primary foci of the investigation. According to the findings
of the study, there is sufficient evidence to suggest that
[2] Mhamdi and Aloui's study, which was published in changes in the price of oil have significant knock-on effects
2020, made use of wavelet analysis to investigate herding on the stock markets of the countries that are members of
behaviour in the Moroccan stock market. The findings of the the Gulf Cooperation Council as well as Morocco.
research suggest that investors do, in fact, engage in herding Additionally, the study found that Morocco's stock market is
behaviour over the course of the short term; however, this significantly impacted by changes in the price of oil. Traders
inclination has a tendency to decrease over the course of the on the Moroccan stock market are required, in accordance
longer term. According to the authors, there is evidence to with the recommendations offered by the authors, to take
imply that efficiency is increasing on the Moroccan stock into account the price of oil anytime they are debating over
market, and investors are depending less and less on herd whether or not to make an investment.
behaviour. The authors also note that there is evidence to
show that efficiency is increasing on the Moroccan stock [7] Ameziane and Gafsaoui (2019) conducted study on the
market. They claim that this might be linked to the fact that volatility contagion that may spread from the price of oil to
there is evidence to imply that efficiency is improving, the stock market in Morocco. Their focus was on the
which suggests that efficiency is increasing. potential link between these two markets. Their
investigation centred on the possible repercussions that this
[3] Using research that they had conducted, Khallouli and may entail. The findings of the research indicate that there is
Oueslati (2019) explored the influence that social media has indisputable evidence to imply that the price of oil has a
on the returns of the stock market in Morocco. They focused substantial impact on the stock market in Morocco. This is
specifically on the Moroccan stock market. According to the the conclusion that can be drawn from the findings of the
findings of the authors, the mood of social media seems to study. The conclusion that can be derived from the results of
have a favourable effect on the returns of stock prices over a the research is as follows. Traders on the Moroccan stock
very short period of time. In addition to this, they market are required, in accordance with the
recommend that those who are considering investing in the recommendations offered by the authors, to take into
Moroccan stock market pay attention to social media while account the price of oil anytime they are debating over
they are doing so. Those who are considering investing in whether or not to make an investment.
the Moroccan stock market are encouraged to do so.
[8] Elharzaoui and Bounahmidi (2020) did study with the
[4] El Bannaoui and Saadi (2020) conducted research with objective of determining how the Moroccan stock market
the purpose of determining the effect that unforeseen shifts operates when there is uncertainty over economic policy.
in the country's macroeconomy have on the amount of The findings of the research indicate that uncertainty about
volatility that is experienced in the stock market in economic policy has a major negative influence on the stock
Morocco. The findings of the research indicate that market in Morocco, which is a significant negative effect.
unforeseen changes in the conditions of the macroeconomy This unpredictability concerning economic policy has a
have a significant and favourable impact on the volatility of large negative effect. While considering where to put their
the stock market. The outcomes of the study provide money and how to invest it, investors on the Moroccan
credence to this view. The authors strongly encourage that stock market were advised by the authors to take into
potential investors keep in mind the unforeseen events that account the degree of economic policy uncertainty they
may occur in the macroeconomy when making choices faced before making investment choices.
about how to distribute their assets. This recommendation
was made in light of the fact that the writers themselves are [9] Nasri and Hamdi (2018) conducted research to
prospective investors. determine whether or not there was a connection between
the expansion of the Moroccan economy and the liquidity of
[5] Bakir and Zekhnini (2019) performed research to the stock market. They concentrated their efforts, in
investigate the extent to which the presence of foreign particular, on Morocco. According to the findings of the
investors in the Moroccan stock market affects the amount study, the liquidity of the stock market in Morocco has a
of volatility experienced by that market. The findings of the positive and significant influence on the expansion of the
research indicate that the presence of overseas investors in country's economy. This is one of the key takeaways from
the stock market is connected with a decrease in the level of the research. The authors argue that in order to stimulate
volatility that is experienced by the market. The authors economic expansion, decision-makers in Morocco should
argue that in order to prevent the Moroccan stock market work towards increasing the liquidity of the stock market as
a priority in order to achieve their goals. According to what
they have said, the government of Morocco need to make By adding more varied sources of data and powerful
this a top priority. machine learning algorithms to evaluate the data, the new
system hopes to overcome the limitations of the present
[10] Research on the dynamic links that exist between the system. While they are not caught by conventional
Moroccan stock market, oil prices, and macroeconomic techniques of financial analysis, the emotional
variables was carried out by Guerzou and Hammami (2018). & psychological considerations that might affect market
Wavelet coherence analysis served as their technique of behaviour will be recorded by the suggested system thanks
inquiry so that they might accomplish this goal. According to sentiment analysis. Because of this, investors may get a
to the findings of the research, there are significant more complete picture of the market and make more
connections between the stock market in Morocco, the price educated choices.
of oil, and other aspects of the economy in Morocco. While
determining whether or not to make an investment in the
Moroccan stock market, the authors recommend that
potential investors take into account a number of other
macroeconomic issues in addition to the price of oil.
algorithm. You can either impute missing values or delete on sentiment data, which is important in the context of
the rows/columns containing missing values depending on stock market prediction.
the amount of missing data.
3. RF is a ml ensemble method that uses a forest of
⚫ Removing outliers: Outliers are data points that are decision trees to draw conclusions. For example, emotion
significantly different from other data points in the dataset. data is only one of several characteristics that may be
Outliers can negatively impact the performance of machine utilised in conjunction with rf to forecast stock values.
learning algorithms. You can either remove the outliers or 4. The term "neural network" refers to a group of
treat them as a separate category depending on the nature of algorithms that draw inspiration from the way the human
the data. brain operates. Several tasks, including as regression, as
⚫ Text preprocessing: Text data collected from social well as time series prediction, might benefit from their
media and news sources needs to be preprocessed before use. A neural network may be trained to forecast stock
applying sentiment analysis. Text preprocessing involves values using a wide range of data points, including
converting text to lowercase, removing stop words, sentiment analysis.
punctuation, and special characters, stemming or
lemmatizing the words, and converting the text to a 5. This piece will concentrate on GBM, a robust approach
numerical representation using techniques such as bag-of- suitable for both regression & classification. To achieve its
words or TF-IDF. goals, it constructs a hierarchy of DT, each of which
strives to fix the flaws of its predecessor. GBM may be
⚫ Feature engineering: Feature engineering involves used to the task of predicting stock values based on several
selecting relevant features from the dataset that can improve parameters, including sentiment data.
the performance of machine learning algorithms. In the case
of sentiment analysis, features such as sentiment lexicons, n- 6. When the models have been developed, their
grams, and part-of-speech tags can be used to represent the performance may be measured using a variety of measures
text data. such precision, accuracy, F1-score, recall as well as AUC-
ROC. Metrics are selected in accordance with project
When the data has been prepared and cleansed, ml methods specifications and data characteristics.
like NB, LR & SVM may be used to determine whether
there is a correlation between public opinion and the VI. RESULTS & DISCUSSIONS
performance of firms trading on the CSE.
By keeping phrases that include keywords connected to such
stocks using their particular stock ids, the research examined
feelings across more than 2200 articles about five equities of
the Casablanca Stock Exchange. Researchers in Morocco
looked at whether or not there was a causal link between the
general public's sentiment as gauged by a massive data set
of financial news and the performance of the country's stock
markets. The results showed that using basic natural
language processing methods, it is possible to gauge the
general public's mood based on the tone of the news on a
global scale. During the course of a month, six distinct
Moroccan online news sources were used to track the
number of times each positive and negative stock market
word appeared in the news stories. Among 2200
submissions, BMCI stock had the most negative writing
Fig.2. Flow diagram
content, while M2M stock received the most favourable.
The research findings may aid institutional investors in
V.ML MODELS
making informed stock market decisions by allowing them
to foresee potential price changes in stocks listed on the
1. One popular probabilistic approach for analysing
Casablanca Stock Exchange.
opinions is the Naive Bayes. It analyses the words in a text
to determine how likely it is to have a negative or
On comparing with previous studies, Predicting stock prices
positive tone. With this method, one may anticipate how
using sentiment analysis & ml has been the subject of
investors will feel about a stock based on the coverage it
previous research. Bollen et al. (2011) conducted a research
has received in the media and on social media.
in which they utilised Twitter data to anticipate stock market
2. SVM is a robust technique that can be employed for both movements with an accuracy of 87.6 percentage points.
classification & regression. One way it does this is by Stock price predictions based on sentiment analysis were
locating the hyperplane that most effectively divides the 71.7% accurate in a separate research by Zhang et al.
data into distinct buckets. SVM may be used to the task of (2011).
predicting the direction (up or down) of stock prices based
Our findings are consistent with those of other studies, and The field of study has a long way to go before it reaches its
they add to the growing body of evidence that sentiment full potential. Future research might look at how various
analysis might be a useful tool for forecasting stock values. forms of mood, such as bullish and bearish, affect stock
It's important to keep in mind, however, that compared to values. To further enhance the accuracy of the prediction
certain prior research, our models' accuracy is lower. This models, another route may be to investigate the use of more
might be due to numerous variables, including a lack of advanced ml methods like DL. It would be intriguing to
publicly available sentiment data for the Moroccan stock broaden this research to include more financial markets and
market and the market's unique features when compared to compare the outcomes to see whether sentiment analysis can
those of other markets investigated in the past. be used for financial forecasting in general. Lastly, the
Fig.3,4,5 - O/Ps of our system accuracy of the prediction models may be enhanced by
including other data sources, such as financial statements,
stock volumes, & prices.
REFERENCES