# Enhancing Stock Price Forecasting with LSTM Networks: A Comparative Study of Classic and PSO-Optimized Models on S&P 500 Stocks

Imad Talhartit, Sanae Ait Jillali, Mounime El Kabbouri

► To cite this version:

Imad Talhartit, Sanae Ait Jillali, Mounime El Kabbouri. Enhancing Stock Price Forecasting with LSTM Networks: A Comparative Study of Classic and PSO-Optimized Models on S&P 500 Stocks. International Journal of Economics and Finance, 2025, 17 (8), pp.87. 10.5539/ijef.v17n8p87. hal-05177777

HAL Id: hal-05177777

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

Submitted on 22 Jul 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>
# Enhancing Stock Price Forecasting with LSTM Networks: A Comparative Study of Classic and PSO-Optimized Models on S&P 500 Stocks

Imad Talhartit<fnref n="1" />, Sanae Ait Jillali<fnref n="1" /> & Mounime El Kabbouri<fnref n="1" />

Correspondence: Sanae Ait Jillali, Ph.D., LARFAGO Laboratory, ENCG-UHP, Settat – Kingdom of Morocco.
E-mail: s.aitjillali@uhp.ac.ma; sanaeaitjillali@gmail.com

Received: May 24, 2025

Accepted: July 3, 2025

Online Published: July 18, 2025

doi:10.5539/ijef.v17n8p87

URL: https://doi.org/10.5539/ijef.v17n8p87

## Abstract

This study is part of an empirical and quantitative approach aimed at improving stock market fluctuation forecasting through the application of artificial intelligence models. More specifically, it evaluates the performance of two methods based on Long Short-Term Memory (LSTM) neural networks, one of the most powerful algorithms for analyzing financial time series. The first method is grounded in a classic LSTM model, while the second incorporates hyperparameter optimization using the Particle Swarm Optimization (PSO) metaheuristic method, allowing for better convergence and enhanced prediction accuracy. The study is conducted on ten stocks representing the US S&P 500 index, with historical data spanning several decades, collected via the Investing.com and Yahoo Finance platforms.

The empirical results demonstrate a clear superiority of the LSTM-PSO model regarding predictive accuracy, with significant reductions in errors (MSE, RMSE, MAE, MSLE, and RMSLE) compared to the traditional model. These findings emphasize the advantages of combining artificial intelligence and algorithmic optimization for handling complex financial data. In the global context of digitization and automation of investment decisions, this research contributes significantly to the development of reliable predictive systems.

Finally, the study raises the question of whether this methodological framework could be effectively adapted to emerging markets, such as the Moroccan Stock Market, where financial environments are characterized by lower trading volumes, different volatility patterns, and more limited historical data. This opens up avenues for future research into the challenges and opportunities of applying advanced AI-based forecasting models in less mature financial markets.

**Keywords:** stock market forecasting, artificial intelligence, LSTM neural networks, Particle Swarm Optimization, financial time series, predictive modeling

## 1. Introduction

Stock price forecasting has long been a pivotal area in financial research, lying at the crossroads of theoretical modeling and practical investment strategies. In recent years, this field has become increasingly complex due to the rising availability of large-scale financial data and the dynamic nature of modern markets. Consequently, the challenge of identifying accurate and robust predictive models has intensified.

Building on a substantial body of international research aimed at refining stock price prediction methods, including contributions by Fischer and Krauß (2018), Ma (2020), Budiharto (2021), Sen, Dutta, and Mehtab (2021), Touzani and Douzi (2021), Goel and Singh (2022), Olotu (2023), Pardeshi, Gill, and Abdelmoniem (2023), Zhang (2023), Xiao (2023), Wen (2024), Abdullah, Jassim, and Hussain (2024), Hu (2024), Liu et al. (2024), and Talhartit, Ait Jillali, and El Kabbouri (2025b), this study continues the exploration of deep learning-based approaches to time series forecasting. We specifically focus on Long Short-Term Memory (LSTM) networks, which have shown superior performance over traditional models such as Artificial Neural Networks (ANN), Gated Recurrent Units (GRU), Convolutional Neural Networks (CNN), and AutoRegressive Integrated Moving Average (ARIMA).

<footnote n="1">¹ National School of Trade and Management (ENCG), Hassan First University (UHP), Settat – Kingdom of Morocco</footnote>
Our research compares two architectures of LSTM networks: a standard (or classic) LSTM and an LSTM model whose hyperparameters are optimized using Particle Swarm Optimization (PSO). This comparison is grounded in established performance metrics: Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), Mean Squared Logarithmic Error (MSLE), and Root Mean Squared Logarithmic Error (RMSLE). These metrics have been widely adopted in similar studies to assess the accuracy of predictive models. For instance, Olotu (2023) employed MAPE, MAE, MSE, and RMSE to evaluate LSTM performance on the Nigerian Stock Exchange Index, while Xiao, Feng, Yan, and Ma (2022) used MAE, MSE, and RMSE to compare ARIMA and LSTM models across data from 50 listed companies. Similarly, Mehtab, Sen, and Dutta (2021) analyzed the NIFTY 50 index using a range of indicators, including MAPE and R², highlighting the efficiency of LSTM in univariate forecasting. Zhang, Sjarif, and Ibrahim (2024), in a review of deep learning models for financial time series, found that stacked GRU and LSTM configurations outperformed other models using metrics such as RMSE, MAE, SMAPE, TIC, and R².

This study continues our line of research comparing advanced neural network architectures. Following earlier work comparing simple LSTM models with those optimized via genetic algorithms (Talhartit, Ifleh, & El Kabbouri, 2024), as well as comparative analyses of ANN and LSTM models (Talhartit et al., 2025b), we now evaluate the performance gains achieved through PSO optimization. Our approach aligns with findings by Han, Zhang, and Zhang (2022), who demonstrated that PSO-optimized LSTM models improve investment timing and decision-making in volatile markets.

Based on our literature review, we articulate the following research questions:

* **Q1:** Is the LSTM model effective in predicting stock price movements within the S&P 500 index using long historical datasets?

* **Q2:** Does PSO-based optimization of LSTM hyperparameters significantly enhance predictive performance?

* **Q3:** Which performance metrics (MSE, RMSE, MAE, MSLE, and RMSLE) most sensitively reflect improvements from PSO optimization?

To answer these questions, we propose the following hypotheses:

* **H1:** The PSO-optimized LSTM model outperforms the classic LSTM across all selected evaluation metrics.

* **H2:** The benefits of PSO optimization are more pronounced in stocks with high volatility or deeper historical data.

* **H3:** Combining long-term historical data with PSO optimization significantly reduces predictive errors in S&P 500 stock forecasts.

In a global financial environment characterized by volatility and uncertainty, accurate prediction of stock price fluctuations remains a key objective for investors, analysts, and financial institutions. This study contributes to that objective by proposing a hybrid approach that integrates deep learning (via LSTM networks) with metaheuristic optimization (through PSO). By targeting stocks listed in the S&P 500; one of the most tracked indices worldwide, and leveraging extensive historical data (spanning over six decades for some stocks), our research provides a rare depth of analysis in the context of financial forecasting. Moreover, as automated, data-driven investment tools become more prevalent, our findings offer valuable insights for enhancing decision-support systems through a combination of computational intelligence and financial modeling.

The general aim of our study is to assess and compare the predictive accuracy of a classic LSTM model versus a PSO-optimized LSTM model on a sample of S&P 500 stocks. Our specific objectives are threefold: (1) evaluate the forecasting capabilities of a classical LSTM model using historical data, (2) analyze the impact of PSO-based optimization on LSTM performance, and (3) compare the models using established performance metrics, namely: MSE, RMSE, MAE, MSLE, and RMSLE.

This paper follows the IMRAD structure. After contextualizing the research through a previous research overview in this introduction, we detail the methodology and design of our study in the second section, then present the results and their evaluation, and conclude with a discussion of the implications and future research directions.

## 2. Method

The objective of this study is to predict the price evolution of ten stocks in the American S&P 500 stock index. To achieve this, two forecasting models were developed. The first model is based on the Long Short-Term Memory (LSTM) architecture, a type of Recurrent Neural Network (RNN) particularly suited for modeling time series to forecast stock price fluctuations. The second model extends the first by optimizing the hyperparameters
found by the LSTM network using the Particle Swarm Optimization (PSO) method.

Machine learning models require a substantial amount of historical data to produce robust and accurate predictions. With this in mind, we systematically collected all available historical data for each stock we analyzed. This methodological approach accounts for the observed variations in the number of observations among different stocks, which depend on their respective historical availability.

The historical stock price data used in this study were collected from the Investing.com and Yahoo Finance platforms using the Investpy and yfinance libraries implemented in Python. The study period ranges from January 1, 1960, to April 30, 2025, with observation counts varying depending on the availability of data for each stock (see Table 1).

During the data collection process, some columns retrieved from Yahoo Finance, particularly Dividends and Stock Splits, contained missing values (NaN). Since these variables were not essential for the objectives of this study and could interfere with normalization or learning processes, they were removed using the following Python command:

$$Data = data.drop colons = ['Dividends', 'Stock Splits']) \quad (1)$$

This preprocessing decision ensured a cleaner dataset and avoided potential disruptions in model training caused by non-informative or incomplete features. The remaining data formed the core time series used for model training and evaluation.

<table><caption>Table 1. 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="10">S&P500 (USA)</td><td>JPM</td><td>From 17/03/1980 to 29/04/2025</td><td>11 373</td></tr><tr><td>IBM</td><td>From 02/01/1962 to 29/04/2025</td><td>15 938</td></tr><tr><td>PFE</td><td>From 01/06/1972 to 29/04/2025</td><td>13 339</td></tr><tr><td>MDT</td><td>From 02/05/1973 to 29/04/2025</td><td>13 110</td></tr><tr><td>DIS</td><td>From 02/01/1962 to 29/04/2025</td><td>15 938</td></tr><tr><td>KO</td><td>From 02/01/1962 to 29/04/2025</td><td>15 938</td></tr><tr><td>NEE</td><td>From 21/02/1973 to 29/04/2025</td><td>13 159</td></tr><tr><td>XOM</td><td>From 02/01/1962 to 29/04/2025</td><td>15 938</td></tr><tr><td>CVX</td><td>From 02/01/1962 to 29/04/2025</td><td>15 938</td></tr><tr><td>ABM</td><td>From 17/03/1980 to 29/04/2025</td><td>11 373</td></tr></tbody></table>

The performance of the classic LSTM network and the LSTM optimized by the Particle Swarm Optimization (PSO) metaheuristic is measured using the following indicators:

* MSE (Mean Squared Error): the difference between predicted values and actual values, it measures the mean square error, and is sensitive to large errors;

* RMSE (Root Mean Squared Error): the square root of the MSE, interpretable in the same units as prices, and it gives an idea of the magnitude of the errors.;

* MSLE (Mean Squared Logarithmic Error): places more emphasis on relative errors, and it is useful when target values vary over several orders of magnitude;

* RMSLE (Root Mean Squared Logarithmic Error): root of the MSLE;

* MAE (Mean Absolute Error): average of absolute errors, less sensitive to extreme values than the MSE.

These indicators quantify the deviation between predicted and observed values, providing an objective basis for determining which model has the best predictive accuracy, thereby facilitating decision-making by traders and investors.

This study is part of a hypothetico-deductive approach based on a positivist postulate, where we seek to model and predict financial phenomena based on quantitative historical data and computational techniques. The choice of machine learning, and more specifically of the LSTM (Long Short-Term Memory) architecture, is based on its ability to capture the non-linear and sequential dynamics specific to stock market time series. In a logic of searching for predictive performance, a second approach is introduced as already mentioned, combining LSTM with the PSO (Particle Swarm Optimization) metaheuristic in order to automatically optimize the model's hyperparameters. This methodological choice reflects a technical and experimental orientation, focused on the continuous improvement of performance through algorithmic optimization processes. The rigor of the study is
also based on the exhaustive collection of historical data available for each S&P 500 stock analyzed, over an extended period extending to April 2025, which reinforces the reliability of the empirical tests. The evaluation of the models is conducted using standardized statistical indicators (MSE, RMSE, MSLE, RMSLE, MAE) as already defined, guaranteeing an objective and reproducible framework for comparing performances and drawing conclusions for decision-making purposes for financial players.

### 3. Results

Table 2 presents the performance of the classic (unoptimized) LSTM model applied to predict the price of 10 S&P 500 stocks.

<table><caption>Table 2. Quantitative evaluation of classic LSTM on S&P 500 stocks</caption><thead><tr><th rowspan="2">Index</th><th rowspan="2">Share</th><th colspan="5">Classic LSTM Model</th></tr><tr><th>MSE</th><th>RMSE</th><th>MSLE</th><th>RMSLE</th><th>MAE</th></tr></thead><tbody><tr><td rowspan="10">S&P 500 (USA)</td><td>JPM</td><td>2081.37</td><td>45.62</td><td>0.10</td><td>0.31</td><td>28.22</td></tr><tr><td>IBM</td><td>231.61</td><td>15.22</td><td>0.01</td><td>0.08</td><td>6.99</td></tr><tr><td>PFE</td><td>38.64</td><td>6.22</td><td>0.03</td><td>0.18</td><td>4.18</td></tr><tr><td>MDT</td><td>237.53</td><td>15.41</td><td>0.03</td><td>0.18</td><td>11.50</td></tr><tr><td>DIS</td><td>1102.64</td><td>33.21</td><td>0.08</td><td>0.29</td><td>23.75</td></tr><tr><td>KO</td><td>108.39</td><td>10.41</td><td>0.04</td><td>0.21</td><td>6.92</td></tr><tr><td>NEE</td><td>782.06</td><td>27.97</td><td>0.33</td><td>0.57</td><td>21.52</td></tr><tr><td>XOM</td><td>545.32</td><td>23.35</td><td>0.09</td><td>0.30</td><td>14.16</td></tr><tr><td>CVX</td><td>1043.91</td><td>32.31</td><td>0.08</td><td>0.28</td><td>20.12</td></tr><tr><td>ABM</td><td>16.68</td><td>4.08</td><td>0.01</td><td>0.09</td><td>2.59</td></tr></tbody></table>

The analysis of Table 2 shows three levels of performance:

High errors and limited performance: JPM, DIS, CVX, and NEE exhibit very high MSE values (ranging from over 780 to over 2000), indicating significant inaccuracy in their predictions. For instance, JPM displays an RMSE of 45.62 and an MAE of 28.22, which is very high for a stock price forecast. These results suggest that the classical model struggles to accurately model these time series, likely due to data volatility or complexity.

Intermediate performance: XOM, MDT, IBM, and KO have lower but still significant errors, with RMSEs ranging from 10 to 23 and MAEs around 7 to 15. This reflects moderate accuracy, insufficient for sensitive applications such as algorithmic trading.

Best relative performance: ABM shows the best performance in the table, with an MSE of 16.68, an RMSE of 4.08, and an MAE of only 2.59, which shows an acceptable ability of the classical model to predict this stock, probably due to more stable or predictable stock market behavior.

The classical LSTM model shows overall poor to moderate performance, with significant errors on the majority of stocks. It appears particularly ineffective at predicting stocks like JPM, DIS, or NEE, which may be explained by its inability to capture complex dynamics or pronounced nonlinearities in financial time series.

Table 3 shows the performance of the LSTM-PSO (Long Short-Term Memory powered by Particle Swarm Optimization) model applied to the price prediction of the same 10 stocks comprising the S&P 500 index. The results are evaluated using the same previously defined error metrics.

<table><caption>Table 3. Quantitative evaluation of LSTM-PSO on S&P 500 stocks</caption><thead><tr><th rowspan="2">Index</th><th rowspan="2">Share</th><th colspan="5">LSTM-PSO Model</th></tr><tr><th>MSE</th><th>RMSE</th><th>MSLE</th><th>RMSLE</th><th>MAE</th></tr></thead><tbody><tr><td rowspan="10">S&P 500 (USA)</td><td>JPM</td><td>65.51</td><td>8.09</td><td>0.0050</td><td>0.071</td><td>7.03</td></tr><tr><td>IBM</td><td>74.16</td><td>8.61</td><td>0.0035</td><td>0.059</td><td>6.66</td></tr><tr><td>PFE</td><td>0.62</td><td>0.79</td><td>0.0006</td><td>0.024</td><td>0.53</td></tr><tr><td>MDT</td><td>11.37</td><td>3.37</td><td>0.0016</td><td>0.040</td><td>2.84</td></tr><tr><td>DIS</td><td>13.22</td><td>3.64</td><td>0.0009</td><td>0.030</td><td>2.49</td></tr><tr><td>KO</td><td>6.73</td><td>2.60</td><td>0.0025</td><td>0.05</td><td>2.11</td></tr><tr><td>NEE</td><td>2.99</td><td>1.73</td><td>0.0008</td><td>0.03</td><td>1.08</td></tr><tr><td>XOM</td><td>13.28</td><td>3.64</td><td>0.0016</td><td>0.04</td><td>2.24</td></tr><tr><td>CVX</td><td>73.99</td><td>8.60</td><td>0.0064</td><td>0.08</td><td>7.43</td></tr><tr><td>ABM</td><td>1.57</td><td>1.25</td><td>0.0011</td><td>0.03</td><td>0.87</td></tr></tbody></table>
The analysis of Table 3 also shows three levels of performance:

Best performance (low errors): PFE has very low MSE (0.62), RMSE (0.79), and MAE (0.53), which demonstrates the model's excellent predictive ability for this stock. ABM and NEE also exhibit low errors, indicating good model accuracy.

Average performance: Actions such as MDT, DIS, KO or XOM show moderate errors, indicating an overall satisfactory performance of the model.

Poorer performance: JPM, IBM, and especially CVX have high error values (MSE greater than 65), reflecting lower model efficiency on these securities.

The LSTM-PSO model shows variable predictive power across stocks. It performs well for some companies with moderate volatility or whose prices follow predictable trends, for instance, PFE, ABM, but struggles with more complex or unstable stocks, like JPM, and CVX. This highlights the importance of adapting the model to the specific nature of each stock market time series.

Compared with the results of the classical LSTM model (presented in Table 2), these LSTM-PSO model performances highlight the significant contribution of Particle Swarm Optimization (PSO) in improving the model accuracy.

In what follows, the interpretation and comparison of the two models' findings.

## 4. Discussion

Tables 2 and 3 present, respectively, the performance of the classical LSTM model and the PSO-optimized LSTM model (LSTM-PSO) for predicting the stock prices of 10 companies within the S&P 500 index. Evaluation was carried out using five widely accepted performance metrics: Mean Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Squared Logarithmic Error (MSLE), Root Mean Squared Logarithmic Error (RMSLE), and Mean Absolute Error (MAE).

The analysis of results reveals a consistent and substantial performance advantage of the LSTM-PSO model over the classical LSTM across all stocks and all metrics. For instance, the MSE for JPM drops sharply from 2081.37 with the classic LSTM to just 65.51 with LSTM-PSO. Similarly, for DIS, MSE decreases from 1102.64 to 13.22. These improvements are not isolated; every stock studied shows comparable performance gains across all error metrics.

In support of Hypothesis 1 (H1), we affirm that the PSO-optimized LSTM model consistently outperforms the classic LSTM model across all evaluation metrics. The improvements are evident in both absolute error measures (MSE, RMSE, MAE) and logarithmic error measures (MSLE, RMSLE), confirming the enhanced accuracy, stability, and generalization capacity of the LSTM-PSO.

Further analysis indicates that the most substantial performance gains are observed in stocks with either higher volatility or longer historical depth, such as NEE and DIS, where error reduction is particularly pronounced. For NEE, the MAE dropped from 21.52 to 1.08, highlighting how PSO optimization allows the model to better handle complex patterns and large fluctuations. This observation provides strong empirical backing for Hypothesis 2 (H2): the benefits of PSO optimization are indeed more pronounced in stocks characterized by high volatility or extended historical data.

Moreover, the integration of long-term historical data with the PSO-optimized model structure results in significant error minimization across the board. For instance, in the case of IBM, which has extensive historical data, MSE is reduced from 231.61 to 74.16. These findings validate Hypothesis 3 (H3): combining long historical data with PSO optimization substantially reduces prediction errors, particularly in large-cap, well-established stocks typical of the S&P 500.

In summary, our findings reinforce the value of coupling deep learning models with metaheuristic optimization techniques. The LSTM-PSO model not only enhances accuracy but also ensures robustness and reliability in stock price forecasting. Table 4 encapsulates these improvements, offering a side-by-side comparison of performance indicators between the two models across all stocks studied. The significant reduction in both absolute and logarithmic error metrics underscores the LSTM-PSO's suitability for complex financial time series forecasting, where precision is not merely beneficial, but essential.
<table><caption>Table 4. Summary of the performance comparison between classic LSTM and LSTM-PSO</caption><thead><tr><th>Share</th><th>Model</th><th>MSE</th><th>RMSE</th><th>MSLE</th><th>RMSLE</th><th>MAE</th></tr></thead><tbody><tr><td rowspan="2">JPM</td><td>Classic LSTM</td><td>2081.37</td><td>45.62</td><td>0.10</td><td>0.31</td><td>28.22</td></tr><tr><td>LSTM-PSO</td><td>65.51</td><td>8.09</td><td>0.0050</td><td>0.071</td><td>7.03</td></tr><tr><td rowspan="2">IBM</td><td>Classic LSTM</td><td>231.61</td><td>15.22</td><td>0.01</td><td>0.08</td><td>6.99</td></tr><tr><td>LSTM-PSO</td><td>74.16</td><td>8.61</td><td>0.0035</td><td>0.059</td><td>6.66</td></tr><tr><td rowspan="2">PFE</td><td>Classic LSTM</td><td>38.64</td><td>6.22</td><td>0.03</td><td>0.18</td><td>4.18</td></tr><tr><td>LSTM-PSO</td><td>0.62</td><td>0.79</td><td>0.0006</td><td>0.024</td><td>0.53</td></tr><tr><td rowspan="2">MDT</td><td>Classic LSTM</td><td>237.53</td><td>15.41</td><td>0.03</td><td>0.18</td><td>11.50</td></tr><tr><td>LSTM-PSO</td><td>11.37</td><td>3.37</td><td>0.0016</td><td>0.040</td><td>2.84</td></tr><tr><td rowspan="2">DIS</td><td>Classic LSTM</td><td>1102.64</td><td>33.21</td><td>0.08</td><td>0.29</td><td>23.75</td></tr><tr><td>LSTM-PSO</td><td>13.22</td><td>3.64</td><td>0.0009</td><td>0.030</td><td>2.49</td></tr><tr><td rowspan="2">KO</td><td>Classic LSTM</td><td>108.39</td><td>10.41</td><td>0.04</td><td>0.21</td><td>6.92</td></tr><tr><td>LSTM-PSO</td><td>6.73</td><td>2.60</td><td>0.0025</td><td>0.05</td><td>2.11</td></tr><tr><td rowspan="2">NEE</td><td>Classic LSTM</td><td>782.06</td><td>27.97</td><td>0.33</td><td>0.57</td><td>21.52</td></tr><tr><td>LSTM-PSO</td><td>2.99</td><td>1.73</td><td>0.0008</td><td>0.03</td><td>1.08</td></tr><tr><td rowspan="2">XOM</td><td>Classic LSTM</td><td>545.32</td><td>23.35</td><td>0.09</td><td>0.30</td><td>14.16</td></tr><tr><td>LSTM-PSO</td><td>13.28</td><td>3.64</td><td>0.0016</td><td>0.04</td><td>2.24</td></tr><tr><td rowspan="2">CVX</td><td>Classic LSTM</td><td>1043.91</td><td>32.31</td><td>0.08</td><td>0.28</td><td>20.12</td></tr><tr><td>LSTM-PSO</td><td>73.99</td><td>8.60</td><td>0.0064</td><td>0.08</td><td>7.43</td></tr><tr><td rowspan="2">ABM</td><td>Classic LSTM</td><td>16.68</td><td>4.08</td><td>0.01</td><td>0.09</td><td>2.59</td></tr><tr><td>LSTM-PSO</td><td>1.57</td><td>1.25</td><td>0.0011</td><td>0.03</td><td>0.87</td></tr></tbody></table>

These outcomes suggest that LSTM-PSO should be prioritized over traditional LSTM models when developing automated prediction systems or algorithmic trading strategies, especially in volatile or long-horizon market scenarios. This research thereby makes a meaningful contribution to the development of more intelligent, adaptive, and effective forecasting tools in the domain of financial analytics.

The findings of our study also open up interesting perspectives on both a practical and academic level. Operationally, the predictive models developed can be integrated into decision support systems for investors, investment funds, or fintechs, providing them with advanced indicators to better manage risks and optimize their trading strategies.

While this study demonstrates the effectiveness of combining LSTM neural networks with Particle Swarm Optimization (PSO) for forecasting stock price movements in a developed market context, it also invites reflection on the potential adaptability of such models to emerging markets. In particular, the Moroccan financial market, where the use of artificial intelligence in financial forecasting remains limited, presents a relevant case for further investigation. As Morocco advances its New Development Model (2021), which aims to enhance the attractiveness, transparency, and efficiency of its capital markets, the introduction of advanced predictive tools like LSTM-PSO could support more informed investment decisions and strengthen investor confidence.

This study is part of a broader series of research efforts aimed at identifying the most appropriate models for forecasting the stock prices of Moroccan-listed shares. In previous works, we have explored various deep learning and machine learning techniques in this context, including the integration of macroeconomic and sentiment data (Talhartit et al., 2025a), comparative analyses of ANN and LSTM models (Talhartit et al., 2025b), and the use of LSTM networks optimized by genetic algorithms (Talhartit et al., 2024). These studies reflect our ongoing commitment to advancing predictive modeling for the Casablanca Stock Exchange.

Future research will focus on adapting and rigorously testing the LSTM-PSO forecasting model, whose strong performance has been demonstrated in developed markets, under the specific conditions of emerging financial environments such as Morocco. These markets are often characterized by lower trading volumes, irregular volatility patterns, and limited historical data. By applying the LSTM-PSO framework to Moroccan stocks, particularly those listed on the Casablanca Stock Exchange, we aim to evaluate its robustness, generalizability, and practical relevance in less mature market contexts. This line of inquiry holds strong potential to contribute to applied research in computational finance and to support the modernization of financial analysis tools in developing economies.

## 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*, 22(1), 297-309.
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

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.2017.11.054

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

Han, K., Zhang, W., & Zhang, Y. (2022). Investment strategy based on LSTM network and PSO model. In *Proceedings of the 2022 International Conference on Artificial Intelligence, Internet and Digital Economy (ICΑΙD 2022)* (pp. 330-339). Atlantis Press. https://doi.org/10.2991/978-94-6463-010-7_34

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

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://doi.org/10.48550/arXiv.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

Mehtab, S., Sen, J., & Dutta, A. (2021). Stock price prediction using machine learning and LSTM-based deep learning models. In S. M. Thampi, S. Piramuthu, K. C. Li, S. Berretti, M. Wozniak, & D. Singh (Eds.), *Machine learning and metaheuristics algorithms, and applications. SoMMA 2020* (Communications in Computer and Information Science, Vol. 1366, pp. 88-106). Springer. https://doi.org/10.1007/978-981-16-0419-5_8

Olotu, S. I. (2023). A multivariate LSTM-based deep learning model for stock market prediction. *Applied and Computational Engineering*, 2(1), 187-195. https://doi.org/10.54254/2755-2721/2/20220602

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

Talhartit, I., Ait Jillali, S., & El Kabbouri, M. (2025a). Forecasting the Moroccan Stock Market: A Theoretical Approach Integrating Macroeconomic and Sentiment Data through Deep Learning. *International Journal of Management Sciences and Business Research*, 14(5), 10-23. https://dx.doi.org/10.5281/zenodo.15576354

Talhartit, I., Ait Jillali, S., & El Kabbouri, M. (2025b). Machine Learning for Stock Price Prediction on the Casablanca Stock Exchange: A Comparative Study of ANN and LSTM Approaches. *Archives of Business Research*, 13(05), 46-57. https://doi.org/10.14738/abr.1305.18770

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

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

Xiao, R., Feng, Y., Yan, L., & Ma, Y. (2022). Predict stock prices with ARIMA and LSTM. *arXiv*.
https://doi.org/10.48550/arXiv.2209.02407

Zhang, C., Sjarif, N. N. A., & Ibrahim, R. (2024). Deep learning models for price forecasting of financial time series: A review of recent advancements: 2020-2022. *WIREs Data Mining and Knowledge Discovery*, 14(1), e1519. https://doi.org/10.1002/widm.1519

Zhang, S. (2023). Stock price prediction based on the Long Short-Term Memory network. *Applied and Computational Engineering, 18*, 28-32. https://doi.org/10.54254/2755-2721/18/20230958

## Copyrights

Copyright for this article is retained by the author(s), with first publication rights granted to the journal.

This is an open-access article distributed under the terms and conditions of the Creative Commons Attribution
license (http://creativecommons.org/licenses/by/4.0/).