# Machine Learning for Stock Price Prediction on the Casablanca Stock Exchange: A Comparative Study of ANN and LSTM Approaches

Imad Talhartit, Sanae Ait Jillali, Mounime El Kabbouri

► To cite this version:

Imad Talhartit, Sanae Ait Jillali, Mounime El Kabbouri. Machine Learning for Stock Price Prediction on the Casablanca Stock Exchange: A Comparative Study of ANN and LSTM Approaches. Archives of Business Research, 2025, 13 (05), pp.46-57. 10.14738/abr.1305.18770. hal-05063012

HAL Id: hal-05063012

https://hal.science/hal-05063012v1

Submitted on 11 May 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Machine Learning for Stock Price Prediction on the Casablanca Stock Exchange: A Comparative Study of ANN and LSTM Approaches

Imad Talhartit

National School of Trade and Management - ENCG Settat,
Hassan First University, Kingdom of Morocco

Sanae Ait Jillali

National School of Trade and Management - ENCG Settat,
Hassan First University, Kingdom of Morocco

Mounime El Kabbouri

National School of Trade and Management - ENCG Settat,
Hassan First University, Kingdom of Morocco

## ABSTRACT

Capital markets play a fundamental role in the economy by facilitating the flow of funds between investors with capital surpluses and those with financing needs. However, these markets' inherent complexity and high volatility—amplified by economic crises and geopolitical events—make decision-making particularly challenging. In this context, artificial intelligence (AI), especially machine learning (ML) and deep learning (DL), has become increasingly relevant for modeling complex financial time series such as stock prices. Among various learning approaches, Long Short-Term Memory (LSTM) networks stand out for their ability to capture long-term dependencies in sequential data. This study compares the predictive performance of LSTM and Artificial Neural Networks (ANN) models, on ten stocks comprising the MADEX index of the Casablanca Stock Exchange, across three forecasting horizons (10, 20, and 30 days). Results demonstrate that the LSTM model consistently outperforms the ANN model in terms of accuracy and trend detection. For instance, over a 30-day horizon, the LSTM correctly predicted 8 out of 10 stocks, compared to only 4 for the ANN. This work is part of a broader research effort aimed at identifying the most effective model for stock price forecasting. Building on the results of this and previous studies, particularly those involving LSTM models optimized using genetic algorithms, future research will explore other models such as Gated Recurrent Units (GRU) and Support Vector Machines (SVM) to further enhance prediction accuracy and robustness.

**Keywords:** Stock price forecasting, Casablanca Stock Exchange, Long Short-Term Memory (LSTM), Artificial Neural Networks (ANN), Prediction accuracy.

## INTRODUCTION

A consensus among researchers on the crucial role played by the capital market in the economic sphere, being one of the engines of finance in terms of investment and financing, bringing together economic agents with excess capital and agents with financing needs. These agents, by
choosing to operate in this market, find themselves faced with decision-making in order to act and react in an environment subject to phenomena such as economic shocks, financial crises, and unforeseen geopolitical events, alongside the great complexity and high volatility that characterizes the financial market as a whole.

With technological advancements, humans are trying to make their lives and decision-making easier through computer science. Artificial intelligence, being a field of computer science, aims to create intelligent systems that can perform tasks that require human intelligence. This can include natural language recognition, pattern recognition, and decision-making to solve complex problems.

In a financial stock market context, we have machine learning (ML) and deep learning (DL) which are deployed to facilitate decision-making for financial market actors, being two essential subsets of artificial intelligence (AI), they represent facets of the broader field of machine learning with similarities and differences, at the levels of: Functioning, Feature Extraction, Data Dependency, Computation Power, Training and Inference Time, Problem-solving Technique, Industry Uses, Output. Deep learning is a specialized branch of machine learning that utilizes multi-layered artificial neural networks to process data and make intelligent decisions. The "deep" in deep learning refers to the multiple layers used to analyze data, allowing for more detailed and advanced insights. On the other hand, machine learning, which includes deep learning, is focused on creating algorithms capable of learning from data to make predictions or decisions, employing a variety of techniques such as neural networks.

<figure><img src="image_2.png" /><figcaption>Figure 1: The difference between Machine Learning and Deep Learning</figcaption></figure>

Source: Dargan and Kumar (2019).

In this wake, financial market players have tried to introduce algorithms developed in Machine Learning to solve this complex problem related to the forecasting of stock prices, influenced by several endogenous and exogenous factors and which contribute to making time series non-linear and difficult to model. These algorithms can be classified into three main categories already discussed by many authors (Meena and Suriya, 2020; Li, 2017), to which we can add another one called Ensemble Learning, which combines multiple models to improve overall performance:
**Supervised learning:** The goal is for the machine to learn the rule mapping inputs and outputs. It is particularly used to make predictions about future data. This type of learning is of two types, namely: Classification and Regression algorithms. On the one hand, Classification predicts the outcome of a given sample for output variables that are presented in the form of a category. Regression, on the other hand, is used to predict the outcome of a sample when the output variable is a specific real value.

**Unsupervised learning:** also called feature learning, unlike the previous one, the machine explores the data to identify patterns; the algorithm only determines the structure of the input data. In this case, the machine can determine relationships that can easily escape the attention of humans. Unsupervised learning is of three types: Clustering, Association, and Dimensionality Reduction. Clustering, as its name suggests, groups homogeneous samples into groups or clusters containing elements similar to, or different from other groups. While in Association, it is used to rather identify the rules that allow the definition of large groups of data. As for Dimensionality Reduction, it simply reduces the number of variables in a dataset without biasing the information transmitted.

**Reinforcement learning:** In this program what differs is its interaction with the environment in which it must carry out its precise task, its algorithms develop by learning from their errors and train themselves to carry out optimal actions, it is of two types: Monte-Carlo; in which the program receives its rewards only at the end, and Machine Learning by Temporal Difference (TD); when it receives it in each step.

This paper is part of a series of studies exploring the most effective machine learning models for stock price forecasting, aimed at supporting decision-making in the financial market. Indeed, an accurate forecast can maximize financial returns as reducing the risks associated with unpredictable market fluctuations, while avoiding abnormal returns; that call into question the financial markets efficiency and reflecting underperformance in the medium to long term, which is a phenomenon that is affirmed on global stock markets (Jillali and Belkasseh, 2022). Knowing that financial markets are characterized by great complexity and high volatility, choosing a specific algorithm is not easy; to find a more flexible and accurate approach that will process large, complex and non-linear data, it is necessary to test several existing models and compare them to be able to judge their performance and margin of error.

For this purpose, the subject of this paper is very important in its context to the extent that our results can be a basis for financial market players.

In the following, we will present our comparative study of simple LSTM networks and ANN to judge their performance in forecasting stock prices using data from the Moroccan stock market. The structure of our paper will therefore be as follows: We will first start with a literature review defining these chosen models, namely LSTM and ANN, then we will give an overview of the studies carried out in this direction using these tools. Afterward, we will specify our methodology in data collection and the application of the previously defined models. Thereafter, we will move on to the results obtained and the discussion of the findings, concluding with a proposal for a new line of research to test other approaches that may be more efficient in this study context.
FRAMEWORK FROM EXISTING LITERATURE

Neural networks come in various architectures, each designed to handle different types of data and tasks but they all came to take a further step in modeling complex time series of financial markets, as being more accurate in capturing long-term dependencies in sequential data and handling massive volumes. In what follows, a table summarizing the characteristics of ANN and LSTM showing the similarities and differences:

<table><caption>Table 1: Understanding the Differences in Neural Networks ANN and LSTM</caption><thead><tr><th></th><th>Artificial Neural Network (ANN)</th><th>Long Short-Term Memory Network (LSTM)</th></tr></thead><tbody><tr><th>Definition</th><td>ANNs are the simplest form of neural networks, consisting of layers of interconnected neurons that process and transmit information.</td><td>LSTMs are a type of RNN designed to learn long-term dependencies and retain information over longer sequences.</td></tr><tr><th>Structure</th><td><ul><li>Input Layer: Receives input data.</li><li>Hidden Layers: Intermediate layers that transform the input data.</li><li>Output Layer: Produces the final prediction or classification.</li></ul></td><td><ul><li>Memory Cell: Maintains information over time.</li><li>Gates: Control the flow of information in and out of the cell (input gate, forget gate, output gate).</li></ul></td></tr><tr><th>Applications</th><td><ul><li>Basic image recognition</li><li>Simple pattern recognition</li><li>Regression tasks</li></ul></td><td><ul><li>Long-term time series prediction</li><li>Advanced NLP tasks (e.g., machine translation)</li><li>Speech synthesis</li></ul></td></tr><tr><th>Advantages</th><td><ul><li>Easy to implement and understand.</li><li>Suitable for a wide range of problems.</li></ul></td><td><ul><li>Overcomes the vanishing gradient problem.</li><li>Effective at capturing long-term dependencies.</li></ul></td></tr><tr><th>Challenges</th><td><ul><li>Limited in handling complex data structures.</li><li>Performance depends on the number of hidden layers and neurons.</li></ul></td><td><ul><li>More complex and computationally intensive than standard RNNs.</li><li>Requires careful tuning of hyperparameters.</li></ul></td></tr></tbody></table>

Source: Elaborated by authors based on the literature review.

The Long Short-Term Memory (LSTM) network was proposed by Sepp Hochreiter and Jürgen Schmidhuber in their 1997 paper titled "Long Short-Term Memory." They developed the LSTM architecture to overcome the issue of vanishing gradients in standard recurrent neural networks (RNNs), enabling more effective training on longer sequences.

Here is a curated list of research studies that have employed the LSTM networks for stock market prediction, detailing their methodologies and findings:

The study by Budiharto (2021) titled: Data Science Approach to Stock Prices Forecasting in Indonesia during Covid-19 using Long Short-Term Memory (LSTM). Utilized LSTM to forecast stock prices during the COVID-19 pandemic in Indonesia. Through this study, the LSTM model demonstrated effectiveness in predicting stock prices during volatile market conditions.
Then, Sen et al. (2021), developed an LSTM-based deep learning model for stock investment profitability analysis. The findings of their paper titled “Profitability Analysis in Stock Investment Using an LSTM-Based Deep Learning Model” demonstrated effectiveness in analyzing stock investment profitability using this model.

In the same year, Touzani and Douzi (2021) developed a trading strategy tailored for the Moroccan stock market, utilizing LSTM for short-term predictions and GRU for medium-term forecasts within a Moroccan context. The models are trained on data from the US and French markets, with Moroccan data used for validation. The strategy achieved an annualized return of 27.13% and a monthly return of 2.02%, outperforming local indices and sectors, except for the Software & IT Services sector during the COVID-19 pandemic.

In 2023, Xiao published the study “Stock Prediction using LSTM Model,” utilizing LSTM to predict stock prices. He determined the optimal structure and training parameters experimentally and achieved a Mean Absolute Error (MAE) of 69.15, demonstrating accurate prediction of stock prices.

Pardeshi et al. (2023), in turn, proposed an LSTM model integrated with a Sequential Self-Attention Mechanism (LSTM-SSAM) for stock price prediction, and achieved improved prediction accuracy on datasets from SBIN, HDFCBANK, and BANKBARODA.

Last year, Hu (2024), developed a high-performance stock prediction system using LSTM neural networks, and achieved as a result a low loss of 0.00067, demonstrating the model's effectiveness in modeling complex, nonlinear dependencies in stock data.

In addition to these studies, they are many others who compared the LSTM to other models to show at the end its effectiveness, namely: Fischer and Krauß (2018); who utilized LSTM networks to predict directional movements of S&P 500 from 1992 to 2015, and compared LSTM performance with Random Forest, Deep Neural Networks, and Logistic Regression, showing that the LSTM outperformed other models with daily returns of 0.46% and a Sharpe ratio of 5.8 before transaction costs. However, profitability diminished post-2010, suggesting potential market efficiency.

Zhang (2023), applied LSTM to predict stock prices of companies like Apple, Google, Microsoft, and Amazon using historical data obtained from Yahoo Finance. Incorporated techniques like moving averages and correlation analysis. LSTM demonstrated superior accuracy and stability in stock prediction compared to other neural network models such as RNN and GRU. About Olotu (2023), in his research, he applied a multivariate LSTM model to predict stock market trends using data from the Nigerian Stock Exchange Index. The model is evaluated using performance metrics such as MAPE, MAE, MSE, and rRMSE. At the end, the LSTM model outperformed traditional and other deep learning methods, demonstrating its effectiveness in forecasting stock market trends.

Now moving to the list of research studies that have employed Artificial Neural Networks (ANNs) for stock market prediction:
Starting with the study of Stock Market Index Prediction using Artificial Neural Network conducted by Hedayati Moghaddam et al. (2016), who developed ANNs trained on daily NASDAQ stock exchange rates from January 28 to June 18, 2015, using short-term historical stock prices and day of the week as inputs. As a result, ANNs demonstrated higher accuracy in forecasting stock prices compared to ARIMA modeling, suggesting their potential for short-term stock market predictions.

Sezer et al. (2017), in turn, developed a feedforward multi-layer perceptron (MLP) ANN with backpropagation, configured as 5:21:21:1, trained over 130,000 cycles using 80% of the data from the Nairobi Securities Exchange and New York Stock Exchange. Finding out a Mean Absolute Percentage Error (MAPE) between 0.71% and 2.77%, demonstrating the model's capability in predicting stock prices across different markets.

In India, Goel and Singh (2022), utilized an ANN with the Scaled Conjugate Gradient (SCG) algorithm to forecast the Bombay Stock Exchange (BSE) Sensex, incorporating macroeconomic variables and a global stock market factor. Achieved 93% accuracy in predicting the BSE Sensex closing prices, with the Morgan Stanley Capital International World Index identified as the most influential variable.

Other studies comparing several models and the ANN, are among others; the study by Shahrour and Dekmak (2022), who affirmed that deep learning techniques, particularly ANNs and LSTMs, outperformed machine learning models like Support Vector Regression (SVR) in price prediction. In addition to Varshney and Srivastava (2023), who compared the performance of ANN and ARIMA models in forecasting NIFTY 50 stock prices from December 2005 to July 2019, and found that the ANN model outperformed ARIMA in terms of accuracy, indicating its superiority in capturing complex patterns in stock price movements. We can also cite the work of Wen (2024), who compared the efficacy of Convolutional Neural Networks (CNN), Long Short-Term Memory (LSTM), and Artificial Neural Networks (ANN) in forecasting stock prices, and showed that the LSTMs generally outperformed CNNs and ANNs in predicting stock prices, highlighting their suitability for complex financial forecasting tasks.

Through our literature review of studies comparing both; ANN and LSTM, we find that many authors approve of the strong power and effectiveness of the LSTM as a deep learning model, outperforming other machine learning models in forecasting stock prices and predicting the movement of different markets. For instance, following Ma (2020) and Abdullah et al. (2024), LSTM can capture complex, nonlinear patterns, and requires more data preprocessing. A head back on Wen (2024), LSTM demonstrated superior performance in capturing temporal dependencies, while CNN excelled in feature extraction. ANNs, despite their simplicity, offered a robust baseline for comparison. In this vein, proving the importance of both LSTM and ANN, Liu et al. (2024), chose to combine both, and proved that the LSTM+ANN ensemble model achieved the lowest MSE and RMSE, outperforming individual models.

In the subsequent part of our paper related to the methodology, we are going to study, in turn, in a Moroccan context, the performance of both LSTM and ANN to see which one is tailored to our context in predicting stock prices and market movement.
## STUDY DESIGN AND DATA OVERVIEW

The objective of this study is to predict the price evolution of ten stocks comprising the MADEX index of the Casablanca Stock Exchange (Morocco). To do this, two forecasting models were developed.

The first is based on the Long Short-Term Memory (LSTM) architecture, a type of recurrent neural network suitable for modeling time series.

The second model is based on an artificial neural network (ANN). The historical data required for this analysis were extracted from the Investing.com and Yahoo Finance websites, using the Investpy library or importing yfinance in Python.

Machine learning models require a significant amount of historical data on the stocks being studied in order to optimize their predictive accuracy. This methodological requirement justifies our approach of integrating a corpus of data that is as exhaustive as possible for each financial asset, which induces heterogeneity in the number of observations* available depending on the actions analyzed.

As already mentioned, our objective is to compare the predictive performance of two machine learning models, namely Long Short-Term Memory (LSTM) and Artificial Neural Network (ANN), over different forecast time horizons (10 days, 20 days, and 30 days).

The comparative evaluation is based on each model's ability to accurately predict several stocks' price evolution. The model considered to be the best performer is the one that manages to provide the most accurate predictions for the majority of stocks over different time horizons.

The following table represents our sample of listed companies and the study period.

<table><caption>Table 2: Sample study and observation period</caption><thead><tr><th>Index</th><th>Stock</th><th>Period</th><th>Observation' Number*</th></tr></thead><tbody><tr><td rowspan="8">MADEX Maroc</td><td>MSA</td><td>From 22/02/1973 to 30/01/2025</td><td>13097</td></tr><tr><td>ADI</td><td>From 17/03/1980 to 30/01/2025</td><td>11312</td></tr><tr><td>SLF</td><td>From 23/03/2000 to 30/01/2025</td><td>6252</td></tr><tr><td>SAH</td><td>From 12/11/1997 to 30/01/2025</td><td>6846</td></tr><tr><td>SID</td><td>From 18/11/1996 to 30/01/2025</td><td>7095</td></tr><tr><td>CRS</td><td>From 21/02/1973 to 30/01/2025</td><td>13098</td></tr><tr><td>HPS</td><td>From 17/06/2003 to 30/01/2025</td><td>5442</td></tr><tr><td>CTM</td><td>From 13/10/2022 to 30/01/2025</td><td>576</td></tr><tr><td></td><td>CMA</td><td>From 17/03/1980 to 30/01/2025</td><td>11312</td></tr><tr><td></td><td>SMI</td><td>From 10/09/2021 to 30/01/2025</td><td>851</td></tr></tbody></table>

Source: Authors.

## FINDINGS AND INTERPRETATION

Tables 3, 4 and 5 show the results of the predictions of the ANN and LSTM models in different time horizons (10 days, 20 days and 30 days) of the stocks in our sample from the MADEX Morocco index.
<table><caption>**Table 3: Forecasts from the ANN and LSTM models over a 10-day horizon of our sample of stocks from the MADEX Maroc index.**</caption><thead><tr><th rowspan="2">Index</th><th rowspan="2">Symbol</th><th colspan="2">10 Days Projection</th></tr><tr><th>ANN Prediction</th><th>LSTM Prediction</th></tr></thead><tbody><tr><td rowspan="10">MADEX Morocco</td><td>MSA</td><td>Predicted stock, bullish trend</td><td>Stock not predicted</td></tr><tr><td>ADI</td><td>Stock not predicted</td><td>Stock not predicted</td></tr><tr><td>SLF</td><td>Stock not predicted</td><td>Stock not predicted</td></tr><tr><td>SAH</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>SID</td><td>Predicted stock, bullish trend</td><td>Stock not predicted</td></tr><tr><td>CRS</td><td>Predicted stock, bearish trend</td><td>Predicted stock, bearish trend</td></tr><tr><td>HPS</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>CTM</td><td>Predicted stock, bearish trend</td><td>Predicted stock, bearish trend</td></tr><tr><td>CMA</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>SMI</td><td>Predicted stock, bullish trend</td><td>Predicted stock, bullish trend</td></tr></tbody></table>

Source: Authors.

From Table 3, the results show that the ANN model correctly predicted 5 out of 10 stocks, while the LSTM model correctly predicted 6 out of 10 stocks. This indicates that the LSTM model has a better prediction ability than the ANN model over a 10-day horizon. Therefore, the LSTM model outperforms the ANN model for 10-day prediction because it predicts more stocks.

<table><caption>**Table 4: Forecasts from the ANN and LSTM models over a 20-day horizon of our sample of stocks from the MADEX Maroc index.**</caption><thead><tr><th rowspan="2">Index</th><th rowspan="2">Symbol</th><th colspan="2">20 Days Projection</th></tr><tr><th>ANN Prediction</th><th>LSTM Prediction</th></tr></thead><tbody><tr><td rowspan="10">MADEX Morocco</td><td>MSA</td><td>Predicted stock, bearish trend</td><td>Stock not predicted</td></tr><tr><td>ADI</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>SLF</td><td>Stock not predicted</td><td>Stock not predicted</td></tr><tr><td>SAH</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr><tr><td>SID</td><td>Predicted stock, bearish trend</td><td>Stock not predicted</td></tr><tr><td>CRS</td><td>Predicted stock, bearish trend</td><td>Predicted stock, bearish trend</td></tr><tr><td>HPS</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr><tr><td>CTM</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>CMA</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr><tr><td>SMI</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr></tbody></table>

Source: Authors.

The analysis of Table 4 shows that over a 20-day horizon, the ANN model predicted correctly only 3 out of 10 stocks, while the LSTM model predicted 7 out of 10. This indicates that the LSTM model has a much better prediction ability compared to the ANN model, based on the criterion of the number of predicted stocks.

The ANN model has a high rate of unpredictable stocks (70%), which significantly reduces its performance over this 20-day horizon. The LSTM model performs significantly better than the ANN model for 20-day forecasts, as it predicted a larger number of stocks in the context of the MADEX Maroc index.
<table><caption>Table 5: Forecasts from the ANN and LSTM models over a 30-day horizon of our sample of stocks from the MADEX Maroc index.</caption><thead><tr><th rowspan="2">Index</th><th rowspan="2">Symbol</th><th colspan="2">30 Days Projection</th></tr><tr><th>ANN Prediction</th><th>LSTM Prediction</th></tr></thead><tbody><tr><td rowspan="8">MADEX Morocco</td><td>MSA</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>ADI</td><td>Stock not predicted</td><td>Predicted stock, bearish trend</td></tr><tr><td>SLF</td><td>Stock not predicted</td><td>Stock not predicted</td></tr><tr><td>SAH</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr><tr><td>SID</td><td>Stock not predicted</td><td>Stock not predicted</td></tr><tr><td>CRS</td><td>Predicted stock, bearish trend</td><td>Predicted stock, bearish trend</td></tr><tr><td>HPS</td><td>Predicted stock, bullish trend</td><td>Predicted stock, bullish trend</td></tr><tr><td>CTM</td><td>Predicted stock, bearish trend</td><td>Predicted stock, bearish trend</td></tr><tr><td></td><td>CMA</td><td>Stock not predicted</td><td>Predicted stock, bullish trend</td></tr><tr><td></td><td>SMI</td><td>Predicted stock, bullish trend</td><td>Predicted stock, bullish trend</td></tr></tbody></table>

Source: Authors.

Table 5 shows that over a 30-day horizon, the ANN model was able to correctly predict 4 out of 10 stocks, while the LSTM model predicted 8 out of 10 stocks. This indicates that the LSTM model has a significantly higher prediction ability than the ANN model, when based on the criterion of the number of predicted stocks. Indeed, LSTM was able to identify not only more stocks, but also to specify the bullish or bearish trend.

To sum up, the analysis of the forecasts made over different time horizons (10 days, 20 days, and 30 days) consistently shows that the LSTM model outperforms the ANN model. At each horizon, the LSTM model could predict a greater number of stocks than the ANN model, while identifying bullish or bearish trends more accurately. Specifically, for a 10-day horizon, LSTM predicted 6 out of 10 stocks compared to 5 for ANN. For 20 days, LSTM predicted 7 out of 10 stocks compared to only 3 for ANN. Finally, for 30 days, LSTM predicted 8 out of 10 stocks compared to 4 for ANN. In addition to this, the ANN model has a significant proportion of unpredictable stocks at each horizon, which limits its reliability and effectiveness. In conclusion, the LSTM model emerges as the most efficient model for forecasting the shares of the MADEX Maroc index, regardless of the time horizon considered.

## CONCLUSION

The capital market, marked by high complexity and volatility, is influenced by various factors and events such as economic and geopolitical crises. To assist decision-making in this uncertain environment, artificial intelligence (AI), and more specifically machine learning (ML) and deep learning (DL), are increasingly used in the financial sector. These tools make it possible to analyze complex time series such as stock prices, which are difficult to model due to numerous internal and external factors. Four main learning approaches were presented: supervised, unsupervised, reinforcement learning, and ensemble learning, each with its own specificities.

The present paper aims to compare the performance of two models—LSTM and ANN—in forecasting stock prices on the Moroccan market. This study hopes to provide a basis for decision-makers to improve financial predictions and better manage risks associated with market volatility.
Neural networks, particularly Long Short-Term Memory (LSTM), have demonstrated great effectiveness in modeling complex financial time series, thanks to their ability to capture long-term dependencies. LSTM, designed to solve the gradient vanishing problem in recurrent neural networks (RNNs), has been widely adopted for stock price forecasting. Several recent studies have highlighted its performance in various contexts (Indonesia, Morocco, United States, India, Nigeria, etc.), often in comparison with other models such as artificial neural networks (ANNs), random forests, or convolutional networks. Overall, the results show that LSTM outperforms most other approaches, particularly in terms of accuracy and ability to handle market volatility.

ANNs, although simpler, have also proven their usefulness, especially for short-term predictions and specific markets. Some studies have achieved very accurate results using optimized ANN configurations. Comparatively, research highlights that LSTMs generally perform better than ANNs, although integrating the two in hybrid models can yield excellent results, as shown by the LSTM+ANN approach.

In conclusion, the literature review highlights the superiority of LSTM in stock price forecasting, while recognizing the value of ANNs and the growing interest in hybrid models combining their respective strengths.

Our study aims to predict the price evolution of ten stocks comprising the MADEX index of the Casablanca Stock Exchange, using two forecasting models: an LSTM-type neural network, adapted to time series, and an artificial neural network (ANN). The necessary historical data were collected via Investing.com and Yahoo Finance using the Python libraries Investpy and yfinance. To ensure better predictive accuracy, the most exhaustive data volume possible was integrated, although this leads to heterogeneity in the number of observations depending on the stocks. The main objective is to compare the predictive performance of the two models over three time horizons (10, 20, and 30 days), identifying the one that provides the most accurate forecasts for the majority of stocks.

Analysis of forecasts over three time horizons (10, 20, and 30 days) shows that the LSTM model consistently outperforms the ANN model. At each time horizon, the LSTM predicted a greater number of stocks more accurately and identified bullish or bearish trends more effectively. Specifically, it correctly predicted 6, 7, and 8 out of 10 stocks for the 10, 20, and 30-day horizons, respectively, compared to 5, 3, and 4 for the ANN. The latter also has a high rate of unpredicted stocks, reducing its reliability. In conclusion, the LSTM proves to be the best-performing model for forecasting MADEX index stocks, regardless of the time horizon.

This paper is part of a series of research carried out to find the most accurate model that can faithfully predict the stock prices of listed companies. Following our comparative study between simple LSTM networks and LSTM optimized by genetic algorithms (Talhartit et al., 2024), and based on the results obtained in this paper, we open other avenues of research in this direction to integrate other models and compare their performances such as GRU (Gated Recurrent Unit) and SVM (Support Vector Machine) demonstrating the most powerful model in predicting stock prices.
References

Abdullah, H. S., Ali, N. H., Jassim, A. H., & Hussain, S. H. (2024). An analytical comparison of the behavior of machine learning and deep learning in stock market prediction. Baghdad Science Journal.
https://doi.org/10.21123/bsj.2024.10017

Budiharto, W. (2021). Data science approach to stock prices forecasting in Indonesia during Covid-19 using Long Short-Term Memory (LSTM). Journal of Big Data, 8(1), 47. https://doi.org/10.1186/s40537-021-00430-0

Dargan, S., & Kumar, M. (2019). A survey of deep learning and its applications: A new paradigm to machine learning. Archives of Computational Methods in Engineering, 27, 1071-1092. https://doi.org/10.1007/s11831-019-09344-w

Fischer, T., & Krauß, C. (2018). Deep learning with Long Short-Term Memory networks for financial market predictions. European Journal of Operational Research, 270(2), 654-669.
https://doi.org/10.1016/j.ejor.2018.03.029

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. https://doi.org/10.1108/IJOES-11-2020-0184

Hedayati Moghaddam, M., Hedayati Moghaddam, S., & Esfandyari, M. (2016). Stock market index prediction using artificial neural network. Journal of Economics and Finance, 40(3), 551-563. https://doi.org/10.1007/s12197-015-9310-4

Hu, J. (2024). A high-performance stock prediction system leveraging LSTM neural networks. Applied and Computational Engineering, 114, 65-72. https://doi.org/10.54254/2755-2721/2024.18219

Jillali, S. A., & Belkasseh, M. (2022). Financial performance of initial public offerings: Exploratory study. Archives of Business Research, 10(3), 171-190. https://doi.org/10.14738/abr.103.12067

Li, Y. (2017). Deep reinforcement learning: An overview. arXiv:1701.07274. https://arxiv.org/abs/1701.07274

Liu, F., Guo, S., Xing, Q., Sha, X., Chen, Y., Jin, Y., Zheng, Q., & Yu, C. (2024). Application of an ANN and LSTM-based ensemble model for stock market prediction. arXiv. https://arxiv.org/abs/2410.20253

Ma, Q. (2020). Comparison of ARIMA, ANN, and LSTM for stock price prediction. E3S Web of Conferences, 218, 01026. https://doi.org/10.1051/e3sconf/202021801026

Meena, K. S., & Suriya, S. (2020). A survey on supervised and unsupervised learning techniques. Proceedings of the International Conference on Artificial Intelligence, Smart Grid, and Smart City Applications.
https://doi.org/10.1007/978-3-030-24051-6_58

Olotu, S. I. (2023). A multivariate LSTM-based deep learning model for stock market prediction. Journal of Financial Engineering and Applications, 9(2), 45-52. https://doi.org/10.1016/j.jfea.2023.01.017

Pardeshi, K., Gill, S.S., & Abdelmoniem, A.M. (2023). Stock market price prediction: A hybrid LSTM and sequential self-attention based approach. arXiv. https://arxiv.org/abs/2308.04419

Sen, J., Dutta, A., & Mehtab, S. (2021). Profitability analysis in stock investment using an LSTM-based deep learning model. arXiv. https://arxiv.org/abs/2104.06259

Sezer, S., Ozbayoglu, A., & Dogdu, E. (2017). An artificial neural network-based stock trading system using technical analysis and big data framework. Proceedings of the 2017 IEEE 16th International Symposium on Network Computing and Applications, 1-8. https://doi.org/10.1109/INCA.2017.8368255
Shahrour, M.H., & Dekmak, M. (2022). Intelligent stock prediction: A neural network approach. International Journal of Financial Engineering, 9(4), 2250016. https://doi.org/10.1142/S2424786322500165

Talhartit, I., Ifleh, A., & El Kabbouri, M. (2024). Prédire les cours des actions à l'aide d'algorithmes de machine learning : Étude comparative entre les réseaux LSTM (Long Short-Term Memory) simples et les LSTM optimisés par des algorithmes génétiques. African Scientific Journal, 3(25), 0686.
https://doi.org/10.5281/zenodo.13388410

Touzani, Y., & Douzi, K. (2021). An LSTM and GRU based trading strategy adapted to the Moroccan market. Journal of Big Data, 8, 126. https://doi.org/10.1186/s40537-021-00512-z

Varshney, A., & Srivastava, S. (2023). A comparative study of future stock price prediction through artificial neural network and ARIMA modelling. International Journal of Computer Applications, 175(1), 1-5.
https://doi.org/10.5120/ijca2023922642

Wen, H. (2024). Prediction of stock price by neural network based on CNN, LSTM, ANN. Advances in Economics, Management and Political Sciences, 87, 229-237. https://doi.org/10.54254/2754-1169/87/20240899

Xiao, J. (2023). Stock prediction using LSTM model. Applied and Computational Engineering, 8, 74-79.
https://doi.org/10.54254/2755-2721/8/20230084

Zhang, J. (2023). Stock price prediction based on the Long Short-Term Memory network. Applied and Computational Engineering, 115, 50-58. https://doi.org/10.1016/j.apceng.2023.04.014