| Literature DB >> 36043118 |
Gourav Kumar1, Uday Pratap Singh2, Sanjeev Jain3.
Abstract
In this paper, we presented a long short-term memory (LSTM) network and adaptive particle swarm optimization (PSO)-based hybrid deep learning model for forecasting the stock price of three major stock indices such as Sensex, S&P 500, and Nifty 50 for short term and long term. Although the LSTM can handle uncertain, sequential, and nonlinear data, the biggest challenge in it is optimizing its weights and bias. The back-propagation through time algorithm has a drawback to overfit the data and being stuck in local minima. Thus, we proposed PSO-based hybrid deep learning model for evolving the initial weights of LSTM and fully connected layer (FCL). Furthermore, we introduced an adaptive approach for improving the inertia coefficient of PSO using the velocity of particles. The proposed method is an aggregation of adaptive PSO and Adam optimizer for training the LSTM. The adaptive PSO attempts to evolve the initial weights in different layers of the LSTM network and FCL. This research also compares the forecasting efficacy of the proposed method to the genetic algorithm (GA)-based hybrid LSTM model, the Elman neural network (ENN), and standard LSTM. Experimental findings demonstrate that the suggested model is successful in achieving the optimum initial weights and bias of the LSTM and FC layers, as well as superior forecasting accuracy.Entities:
Keywords: Adaptive particle swarm optimization; Deep learning; Genetic algorithm; Long short-term memory network; Stock price time series; Swarm intelligence; Technical analysis
Year: 2022 PMID: 36043118 PMCID: PMC9415266 DOI: 10.1007/s00500-022-07451-8
Source DB: PubMed Journal: Soft comput ISSN: 1432-7643 Impact factor: 3.732
Fig. 1The general framework of proposed work
Technical indicators
| Technical indicator | Formulation |
|---|---|
| – | |
| – | |
| – | |
| – | |
| On-balance volume (OBV |
n denotes a 10-days period, whereas k > n denotes a 15-days period
Fig. 2Long short-term memory (LSTM) neural network
Fig. 3Flowchart of adaptive PSO-based hybrid LSTM neural network
Fig. 4PSO particle (solution) representation
Fig. 5PSO-LSTM iterative process for evaluating the fitness of network parameters of LSTM
Fig. 6Searching scheme of adaptive PSO
Description of stock price time-series data
| Stock index | From | To | No. of samples | Training set | Validation set | Testing set |
|---|---|---|---|---|---|---|
| Nifty 50 | Jan 1, 2015 | March 31, 2021 | 1547 | 1237 | 155 | 155 |
| Sensex | Jan 1, 2015 | March 31, 2021 | 1541 | 1232 | 155 | 154 |
| S&P 500 | Jan 2, 2015 | March 31, 2021 | 1572 | 1257 | 158 | 157 |
Parameters of the model
| PSO | GA | LSTM | |||
|---|---|---|---|---|---|
| Parameters | Values | Parameters | Values | Parameters | Values |
| Swarm size (S) | 100 | Population size | 100 | Topology (input-hidden-output) | 20-100-1 |
| 0.9 | Crossover probability | 0.7 | Cell activation function | Tanh | |
| 0.4 | Mutation probability | 0.1 | Hidden state transfer function | Tanh | |
| 1.5 | Gamma | 0.4 | Gate transfer function | Log-sigmoid | |
| 1.5 | Selection pressure, beta | 8 | Epochs | 100 | |
| maxGen | 50 | maxGen | 50 | Batch size | 128 |
| tolerance | 10−8 | – | – | Learning rate, lr | 0.01 |
| – | – | – | – | GradientDecayFactor ( | 0.9 |
| – | – | – | – | SquaredGradientDecayFactor( | 0.999 |
1-Day ahead forecasting performance
| Stock Indices | Models | MSE | RMSE | Theil’s U | ||
|---|---|---|---|---|---|---|
| Nifty50 | ENN | 1.15E−01 | 3.39E−01 | 43.32 | 16.49 | 3.71E−01 |
| LSTM | 1.15E−02 | 1.07E−01 | 22.79 | 6.28 | 8.65E−02 | |
| GA-LSTM | 3.85E−02 | 1.96E−01 | 35.94 | 10.02 | 1.90E−01 | |
| PSO-LSTM | 8.20E−03 | 9.04E−02 | 20.74 | 5.30 | 7.23E−02 | |
| Adaptive PSO-LSTM | 2.98E−04 | 1.73E−02 | 10.17 | 2.77 | 1.44E−02 | |
| Sensex | ENN | 1.54E−01 | 3.93E−01 | 57.65 | 13.23 | 2.51E−01 |
| LSTM | 1.83E−02 | 1.35E−01 | 28.55 | 8.46 | 1.24E−01 | |
| GA-LSTM | 5.90E−03 | 7.65E−02 | 19.19 | 5.20 | 6.62E−02 | |
| PSO-LSTM | 3.60E−03 | 6.03E−02 | 14.09 | 3.99 | 5.00E−02 | |
| Adaptive PSO | 2.42E−04 | 1.56E−02 | 5.97 | 1.74 | 1.29E−02 | |
| S&P500 | ENN | 1.55E−01 | 3.93E−01 | 45.34 | 14.92 | 2.74E−01 |
| LSTM | 1.36E−02 | 1.16E−01 | 14.91 | 4.15 | 9.19E−02 | |
| GA-LSTM | 3.20E−03 | 5.70E−02 | 6.09 | 1.46 | 4.13E−02 | |
| PSO-LSTM | 8.20E−03 | 9.06E−02 | 6.08 | 1.48 | 6.53E−02 | |
| Adaptive PSO-LSTM | 1.31E−04 | 1.15E−02 | 0.99 | 0.24 | 8.30E−03 |
Fig. 71-Day ahead forecasting results of Nifty 50
Fig. 81-Day ahead forecasting results of Sensex
Fig. 91-Day ahead forecasting results of S&P 500
1-Week ahead forecasting performance
| Stock Indices | Models | MSE | RMSE | Theil’s U | ||
|---|---|---|---|---|---|---|
| Nifty50 | ENN | 8.48E−02 | 2.91E−01 | 44.55 | 14.35 | 2.53E−01 |
| LSTM | 2.88E−02 | 1.69E−01 | 34.83 | 11.08 | 1.46E−01 | |
| GA-LSTM | 1.58E−02 | 1.26E−01 | 30.57 | 8.74 | 1.09E−01 | |
| PSO-LSTM | 5.20E−03 | 7.24E−02 | 24.08 | 6.92 | 5.86E−02 | |
| Adaptive PSO-LSTM | 4.63E−04 | 2.15E−02 | 13.36 | 3.61 | 1.74E−02 | |
| Sensex | ENN | 1.11E−01 | 3.33E−01 | 49.95 | 19.19 | 3.59E−01 |
| LSTM | 8.24E−02 | 2.87E−01 | 48.37 | 15.95 | 2.94E−01 | |
| GA-LSTM | 1.31E−02 | 1.14E−01 | 27.04 | 7.84 | 9.87E−02 | |
| PSO-LSTM | 7.20E−03 | 8.47E−02 | 23.31 | 6.58 | 6.87E−02 | |
| Adaptive PSO | 4.49E−04 | 2.12E−02 | 9.84 | 3.21 | 1.72E−02 | |
| S&P500 | ENN | 5.91E−01 | 7.69E−01 | 79.62 | 42.69 | 9.01E−01 |
| LSTM | 1.08E−02 | 1.04E−01 | 15.83 | 4.12 | 8.41E−02 | |
| GA-LSTM | 8.90E−03 | 9.43E−02 | 13.12 | 3.48 | 1.41E−01 | |
| PSO-LSTM | 4.40E−03 | 6.61E−02 | 8.79 | 2.11 | 5.10E−02 | |
| Adaptive PSO-LSTM | 1.72E−04 | 1.31E−02 | 1.63 | 0.40 | 1.01E−02 |
Fig. 101-Week ahead forecasting results of Nifty 50
Fig. 111-Week ahead forecasting results of Sensex
Fig. 121-Week ahead forecasting results of S&P 500
2-Week ahead forecasting performance of the models
| Stock Index | Model | MSE | RMSE | MAAPE (%) | SMAPE (%) | Theil’s U |
|---|---|---|---|---|---|---|
| Nifty50 | ENN | 9.04E−02 | 3.11E−01 | 56.38 | 25.15 | 2.93E−01 |
| LSTM | 5.19E−02 | 2.28E−01 | 44.49 | 13.35 | 2.04E−01 | |
| GA-LSTM | 3.46E−02 | 1.85E−01 | 41.30 | 11.76 | 1.66E−01 | |
| PSO-LSTM | 8.50E−03 | 9.25E−02 | 24.91 | 7.64 | 7.34E−02 | |
| Adaptive PSO-LSTM | 7.54E−04 | 2.75E−02 | 12.51 | 3.82 | 2.16E−02 | |
| Sensex | ENN | 1.03E−01 | 3.20E−01 | 48.32 | 16.80 | 3.35E−01 |
| LSTM | 5.83E−02 | 2.41E−01 | 39.38 | 12.82 | 2.33E−01 | |
| GA-LSTM | 3.68E−02 | 1.91E−01 | 36.87 | 10.98 | 1.75E−01 | |
| PSO-LSTM | 7.80E−03 | 8.84E−02 | 19.54 | 5.46 | 7.08E−02 | |
| Adaptive PSO | 2.87E−04 | 1.70E−02 | 7.75 | 2.27 | 1.34E−02 | |
| S&P500 | ENN | 1.02E−01 | 3.19E−01 | 42.91 | 15.31 | 3.27E−01 |
| LSTM | 2.06E−02 | 1.43E−01 | 25.12 | 6.47 | 1.09E−01 | |
| GA-LSTM | 1.62E−02 | 1.27E−01 | 17.86 | 4.56 | 9.87E−02 | |
| PSO-LSTM | 7.77E−03 | 8.76E−02 | 11.52 | 2.77 | 7.06E−02 | |
| Adaptive PSO-LSTM | 7.43E−04 | 2.73E−02 | 3.89 | 0.93 | 2.20E−02 |
Fig. 132-Week ahead forecasting results of Nifty 50
Fig. 142-Week ahead forecasting results of Sensex
Fig. 152-Week ahead forecasting results of S&P 500
4-Week ahead forecasting performance
| Stock indices | Models | MSE | RMSE | Theil’s U | ||
|---|---|---|---|---|---|---|
| Nifty50 | ENN | 1.06E−01 | 3.25E−01 | 47.86 | 17.06 | 2.73E−01 |
| LSTM | 3.74E−02 | 1.93E−01 | 29.79 | 9.60 | 1.60E−01 | |
| GA-LSTM | 1.11E−02 | 1.05E−01 | 21.14 | 6.15 | 7.91E−02 | |
| PSO-LSTM | 8.00E−03 | 8.93E−02 | 23.78 | 8.19 | 6.73E−02 | |
| Adaptive PSO-LSTM | 3.90E−03 | 6.23E−02 | 20.09 | 5.59 | 4.63E−02 | |
| Sensex | ENN | 2.14E−01 | 4.62E−01 | 64.47 | 29.08 | 7.08E−01 |
| LSTM | 1.77E−01 | 4.12E−01 | 52.14 | 20.63 | 6.18E−01 | |
| GA-LSTM | 4.48E−03 | 6.69E−02 | 17.60 | 5.91 | 5.11E−02 | |
| PSO-LSTM | 2.30E−02 | 1.19E−01 | 26.70 | 11.51 | 1.15E−01 | |
| Adaptive PSO | 3.30E−03 | 5.74E−02 | 15.29 | 4.02 | 4.33E−02 | |
| S&P500 | ENN | 1.78E−01 | 4.24E−01 | 56.89 | 24.23 | 4.93E−01 |
| LSTM | 1.48E−02 | 1.22E−01 | 17.96 | 5.19 | 9.62E−02 | |
| GA-LSTM | 2.49E−02 | 1.58E−01 | 23.49 | 5.26 | 1.19E−01 | |
| PSO-LSTM | 5.00E−03 | 7.05E−02 | 11.98 | 2.84 | 5.49E−02 | |
| Adaptive PSO-LSTM | 4.18E−04 | 2.04E−02 | 2.68 | 0.71 | 1.61E−02 |
Fig. 164-Week ahead forecasting results Nifty 50
Fig. 174-Week ahead forecasting results of Sensex
Fig. 184-Week ahead forecasting results of S&P 500
6-Week ahead forecasting performance
| Stock indices | Models | MSE | RMSE | MAAPE (%) | SMAPE (%) | Theil’s U |
|---|---|---|---|---|---|---|
| Nifty50 | ENN | 1.18E−01 | 3.45E−01 | 48.21 | 21.66 | 2.97E−01 |
| LSTM | 7.01E−02 | 2.64E−01 | 39.19 | 16.18 | 2.13E−01 | |
| GA-LSTM | 2.90E−03 | 5.34E−02 | 10.81 | 2.53 | 3.78E−02 | |
| PSO-LSTM | 8.01E−03 | 8.98E−02 | 13.28 | 3.58 | 6.42E−02 | |
| Adaptive PSO-LSTM | 9.41E−04 | 3.07E−02 | 6.20 | 1.48 | 2.18E−02 | |
| Sensex | ENN | 6.26E−01 | 7.91E−01 | 83.21 | 46.50 | 9.19E−01 |
| LSTM | 2.84E−01 | 5.32E−01 | 58.23 | 27.91 | 5.86E−01 | |
| GA-LSTM | 5.10E−03 | 7.17E−02 | 13.90 | 3.20 | 5.18E−02 | |
| PSO-LSTM | 1.63E−02 | 1.28E−01 | 17.20 | 4.09 | 9.20E−02 | |
| Adaptive PSO | 1.80E−03 | 4.21E−01 | 9.27 | 2.25 | 3.04E−02 | |
| S&P500 | ENN | 9.31E−02 | 3.05E−01 | 38.69 | 13.79 | 2.90E−01 |
| LSTM | 1.64E−02 | 1.28E−01 | 16.96 | 4.86 | 9.97E−02 | |
| GA-LSTM | 6.20E−03 | 9.89E−02 | 11.92 | 4.09 | 6.03E−02 | |
| PSO-LSTM | 4.80E−03 | 6.96E−02 | 9.82 | 2.64 | 5.28E−02 | |
| Adaptive PSO-LSTM | 3.19E−04 | 1.79E−02 | 2.65 | 0.67 | 1.35E−02 |
Fig. 196-Week ahead forecasting results of Nifty 50
Fig. 206-Week ahead forecasting results of Sensex
Fig. 216-Week ahead forecasting results of S&P 500
12-Week ahead forecasting performance of the models
| MSE | Stock index | Model | SMAPE (%) | Theil’s U | |
|---|---|---|---|---|---|
| ENN | 2.57E−01 | 5.07E−01 | 58.45 | 25.94 | 5.19E−01 |
| LSTM | 7.45E−01 | 8.64E−01 | 83.32 | 43.29 | 8.00E−01 |
| GA-LSTM | 1.97E−02 | 1.40E−01 | 17.59 | 4.08 | 9.50E−02 |
| PSO-LSTM | 2.50E−03 | 4.98E−02 | 6.81 | 1.73 | 3.42E−02 |
| Adaptive PSO-LSTM | 1.11E−03 | 3.36E−02 | 4.44 | 1.19 | 2.30E−02 |
| ENN | 6.77E−01 | 8.29E−01 | 83.13 | 48.87 | 4.94E−02 |
| LSTM | 2.84E−01 | 5.32E−01 | 58.91 | 27.91 | 3.50E−03 |
| GA-LSTM | 2.84E−02 | 1.68E−01 | 21.89 | 7.04 | 2.00E−03 |
| PSO-LSTM | 1.04E−02 | 1.02E−01 | 10.32 | 2.41 | 2.67E−03 |
| Adaptive PSO | 1.30E−03 | 3.54E−02 | 3.12 | 0.92 | 8.96E−05 |
| ENN | 6.28E−01 | 7.93E−01 | 81.31 | 48.33 | 9.43E−01 |
| LSTM | 4.80E−01 | 6.93E−01 | 61.60 | 30.11 | 6.50E−01 |
| GA-LSTM | 4.00E−03 | 6.34E−02 | 6.67 | 1.98 | 4.30E−02 |
| PSO-LSTM | 8.00E−03 | 8.97E−02 | 8.83 | 2.41 | 6.07E−02 |
| Adaptive PSO-LSTM | 1.43E−03 | 3.79E−02 | 3.55 | 0.94 | 2.56E−02 |
Fig. 2212-Week ahead forecasting results of Nifty 50
Fig. 2312-Week ahead forecasting results of Sensex
Fig. 2412-Week ahead forecasting results of S&P 500
Fig. 25Training versus validation loss for standard LSTM
Fig. 26Training versus validation loss for adaptive PSO-LSTM
Fig. 27Best fitness value (MSE) for Nifty 50
Fig. 28Best fitness value (MSE) for Sensex
Fig. 29Best fitness value (MSE) for S&P 500