| Literature DB >> 33935586 |
Milad Shahvaroughi Farahani1, Seyed Hossein Razavi Hajiagha2.
Abstract
Today, stock market has important function and it can be a place as a measure of economic position. People can earn a lot of money and return by investing their money in the stock exchange market. But it is not easy because many factors should be considered. So, there are many ways to predict the movement of share price. The main goal of this article is to predict stock price indices using artificial neural network (ANN) and train it with some new metaheuristic algorithms such as social spider optimization (SSO) and bat algorithm (BA). We used some technical indicators as input variables. Then, we used genetic algorithms (GA) as a heuristic algorithm for feature selection and choosing the best and most related indicators. We used some loss functions such as mean absolute error (MAE) as error evaluation criteria. On the other hand, we used some time series models forecasting like ARMA and ARIMA for prediction of stock price. Finally, we compared the results with each other means ANN-Metaheuristic algorithms and time series models. The statistical population of research have five most important and international indices which were S&P500, DAX, FTSE100, Nasdaq and DJI.Entities:
Keywords: Artificial neural network; Bat algorithm; Genetic algorithm; Social spider optimization algorithm
Year: 2021 PMID: 33935586 PMCID: PMC8070984 DOI: 10.1007/s00500-021-05775-5
Source DB: PubMed Journal: Soft comput ISSN: 1432-7643 Impact factor: 3.643
Limitations of the previous methods
| No | Methods | Purpose | Limitations |
|---|---|---|---|
| 1 | ARIMA (autoregressive integrated moving average model) | Forecasting and clustering | • Doesn't work well for nonlinear time series • Requires more data • Takes a long time processing for a large dataset |
| 2 | BPNN (back propagation neural network) | Forecasting | • Sensitive to noise • Actual performance based on initial values • Slow convergent speed • Easily converging to a local minimum |
| 3 | CART (classification and regression trees) | Classification and forecasting | • Unstable even when the training data are small changed |
| 4 | GP (Gaussian process) | Classification and forecasting | • Generates “black box” models which are difficult to interpret • Can be computationally expensive |
| 5 | GRNN (generalized regression neural network) | Classification and forecasting | • Requires more memory space to store the model • Can be computationally expensive because of its huge size |
| 6 | Hierarchical clustering | Clustering | • The length of each time series is the same because of the Euclidean distance • Useful only for small datasets because of its quadratic computational complexity |
| 7 | HMM (hidden Markov model) | Clustering, classification and clustering | • Requires parameters to be set and is based on user assumptions that may be false with the result that clusters would be inaccurate • Takes a long time processing for a large dataset |
| 8 | K-Mean | clustering | • The number of clusters must be specified in advance • Sensitive to noise • Only spherical shapes can be determined as clusters • Unable to handle long time series effectively because of poor scalability |
| 9 | KNN (K nearest neighbor) | Classification and forecasting | • The number of nearest neighbors must first be determined • Can be computationally expensive • Memory limitation • Sensitive to the local structure of the data |
| 10 | LR (logistic regression) | Classification and forecasting | • Sensitive to outliers • Strong assumptions |
| 11 | LSTM (long short-term memory) | Classification and forecasting | • Lacks a mechanism to index the memory while writing and reading the data the number of memory cells is linked to the size of the recurrent weight matrices |
| 12 | MLP (multi-layer perceptron) | Classification and forecasting | • Convergence is quite slow • Local minima can affect the training process • Hard to scale |
| 13 | PSO (particle swarm optimization) | Forecasting | • Lacks a solid mathematical foundation for analyzing future development of relevant theories |
| 14 | RBF (radial basis function neural network) | Classification and forecasting | • Classification process is slower than MLP |
| 15 | RF (random forest) | Classification and forecasting | • Requires more computational power and resources because it creates a lot of trees • Requires more time to train than decision trees |
| 16 | RNN (recurrent neural network) | Classification and forecasting | • Difficult to train |
| 17 | SOM (self optimizing maps) | Clustering and classification | • Does not work well for time series of unequal length because of the difficulty involved in determining the scale of weight vectors • Sensitive to outliers |
| 18 | SVM (support vector machine) | Classification and forecasting | • Sensitive to outliers • Sensitive to parameter selection |
| 19 | SVR (support vector regression) | Forecasting | • Sensitive to users’ defined free parameters |
| 20 | ANN (artificial neural network) | Classification and forecasting | • Over fitting • Sensitive to parameter selection—ANNs just give predicted target values for some unknown data without any variance information to assess the prediction |
Important technical indicators
| Row | Feature | Definition | Formula |
|---|---|---|---|
| 1 | Open | The first price | – |
| 2 | High | The highest price | – |
| 3 | Low | The lowest price | – |
| 4 | Close | The last price | – |
| 5 | Volume | Number of traded shares | – |
| 6 | SMA-5 | Simple moving average-5 days | |
| 7 | SMA-20 | Simple moving average-20 days | |
| 8 | EMA-5 | Exponential moving average-5 days | |
| 9 | ADL | Accumulation Distribution Line | ADLYesterday + Volume * CLV CLV = |
| 10 | CMF | Chaikin Money Flow | (((Close − Low) − (High − Close))/(High − Low)) * Volume)/Total (Volume, 21) |
| 11 | MFI | Money Flow Index | Money Flow Ratio = Raw Money Flow = TP * Volume TP = |
| 12 | TP | Typical Price | |
| 13 | RSI | Relative Strength Index | |
| 14 | ROC | Rate of change | |
| 15 | Upper Band | Upper Band of Bollinger | SMA(20) + dev(20) * 2 |
| 16 | Lower Band | Lower Band of Bollinger | SMA(20) − dev(20) * 2 |
| 17 | MP | Mean Price | |
| 18 | ATR | Average True Range | Current ART = [(Prior ATR × 13) + Current TR]/14 TRi = A particular true range |
| 19 | CCI | Commodity Channel Index | CCI = (TP − 20 Period SMA of TP)/(0.015 × Mean Deviation) (TP) = (High + Low + Close)/3 Constant = 0.015 |
| 20 | DX | Directional Movement Index | + DM (Directional Movement) = Current High-PH PH = Previous High − DM = Previous Low-Current Low Smoothed ± DM = CDM = Current DM ATR = Average True Range |
Fig. 1The structure of the desired artificial neural network (Ghasemiyeh 2017)
Fig. 2Research methodology
Parameters of GA
| Output error | Output activation function | Input activation function | Mutation rate | Crossover rate | Number of generation | Population size |
|---|---|---|---|---|---|---|
| SSE | Logistic | Logistic | 0.1 | 0.9 | 50 | 50 |
Fig. 3Considered GA flow chart for training ANN (Liu and Wang 2019)
GA-ANN pseudo-code
Bat algorithm parameters
| Fitness function | Mean square error (MSE) |
|---|---|
| Population size (typically between 10 and 40) | |
| Number of generations | |
| Maximum loudness | |
| Minimum loudness | |
| Pulse rate (constant or decreasing) | |
| Frequency minimum (0) | |
| Frequency maximum (1.5) | |
| Number of iteration (1000) | |
| Number of dimension (20) | |
| LB | Lower bound (− 100) |
| UB | Upper bound (+ 100) |
| Frequency | |
| Velocity |
BA pseudo-code
| Initialize the bat population Xi ( |
| Define pulse frequency |
| Initialize pulse rate |
| While ( |
| Generate new solutions by adjusting frequency, |
| Updating velocities and positions [Eqs. ( |
| Select a solution among the best solutions randomly |
| Generate a local solution around the selected best solution |
| Generate a new solution by flying randomly |
| Accept the new solutions |
| Increase |
| Rank the bats and find the current Gbest |
The above pseudocode interpretation and more details are briefly as follows
1. Bat is initialized then passes its first population to ANN as weight's values
2. Load data
3. ANN starts training and computes the accuracy of the model
4. Bat finds the initial best solution by means of the ANN's results,
5. While I < Max number of iterations
SSO Algorithm Parameters
| Dim | Dimension (30) |
|---|---|
| Bound | 100 |
| Max-iteration | 10,000 |
| Pop-size | 25 |
| Alpha | 0.99 |
| Beta | 0.7 |
| Gamma | 0.9 |
| Fitness function | Mean square error (MSE) |
Fig. 4ARIMA flowchart (Ma et al. 2018)
Statistical description of data
| Symbol | Time interval | Number of data (before normalizing) | Number of data (after normalizing) | Number of data (after normalizing) | Number of input variables | Number of output layer | Target indicator |
|---|---|---|---|---|---|---|---|
| DJI | 2018–2020 | 504 | 435 | 435 | 20 | 1 | Closing price |
| DAX | 2018–2020 | 504 | 436 | 436 | 20 | 1 | Closing price |
| FTSE100 | 2018–2020 | 504 | 443 | 443 | 20 | 1 | Closing price |
| NDAQ | 2018–2020 | 504 | 437 | 437 | 20 | 1 | Closing price |
| S&P500 | 2018–2020 | 504 | 438 | 438 | 20 | 1 | Closing price |
Training, validation and testing (T.V.T) error and network architecture
| indices | Architecture | Weights | Fitness | Train error | Validation error | Test error | AIC | Correlation | |
|---|---|---|---|---|---|---|---|---|---|
| DJI | [20-50-1] | 1101 | 0.0224 | 43.1729 | 48.8100 | 44.5219 | 1629.23 | 0.9991 | 0.9982 |
| DAX | [20-37-1] | 815 | 24.4495 | 0.0455 | 0.0446 | 0.0409 | − 988.45 | 0.9993 | 0.9986 |
| FTSE100 | [20-50-1] | 1101 | 0.05615 | 12.3556 | 15.9880 | 17.8072 | 1232.51 | 0.9979 | 0.9957 |
| S&P500 | [20-33-1] | 727 | 0.2096 | 5.0277 | 5.0658 | 4.7692 | 237.52 | 0.9989 | 0.9978 |
| NDAQ | [20-18-1] | 397 | 2.8119 | 0.3131 | 0.4033 | 0.3556 | − 1257.5 | 0.9986 | 0.9972 |
The DJI index details (T.V.T)
| DJI | Training | Validation | ||
|---|---|---|---|---|
| Absolute Error | 1.4611 | 9.9177 | ||
| Network Error | 4.49E−08 | 0 | ||
| Error Improvement | 3.57E−22 | |||
| Iteration | 371 | |||
| Training Speed, iter/sec | 7.1072 | |||
| Architecture | [20-10-1] | |||
| TA | LM | |||
| TSR | NEI | |||
TA training algorithm; TSR training stop reason, NEI no error improvement
Fig. 5Actual V.S output (testing) for DJI
T.V.T error and network architecture after using GA
| indices | Architecture | Weights | Fitness | Train error | Validation error | Test error | AIC | Correlation | Best fitness | |
|---|---|---|---|---|---|---|---|---|---|---|
| DJI | [10-16-1] | 193 | 0.0123 | 39.76 | 73.36 | 81.21 | − 211.23 | 0.9994 | 0.9989 | 89.81 |
| DAX | [11-10-1] | 131 | 22.18 | 0.0482 | 0.0608 | 0.0450 | − 2339.3 | 0.9994 | 0.9987 | 59.65 |
| FTSE100 | [8-13-1] | 131 | 0.0897 | 9.1412 | 12.79 | 11.38 | − 798.78 | 0.9990 | 0.9980 | 74.33 |
| S&P500 | [12-30-1] | 421 | 6.178 | 0.0721 | 0.1361 | 0.1618 | − 1648.3 | 0.9999 | 0.9999 | 69.58 |
| NDAQ | [10-21-1] | 253 | 0.1649 | 5.1365 | 6.4543 | 6.0617 | − 704.09 | 0.9994 | 0.9989 | 88.87 |
Bat-ANN optimum parameters and error
| Indices | Alpha | Gamma | Pop | Fitness function (MSE) | ||||
|---|---|---|---|---|---|---|---|---|
| DJI | 0.99 | 8.35E−03 | 0.9 | 10 | 10 | 30 | 1000 | 1.0E−55 |
| DAX | 0.99 | 6.43E−04 | 0.9 | 10 | 11 | 30 | 1000 | 1.0E−63 |
| FTSE100 | 0.99 | 5.51E−05 | 0.9 | 10 | 8 | 30 | 1000 | 1.0E−31 |
| NDAQ | 0.99 | 5.31E−03 | 0.9 | 10 | 12 | 30 | 1000 | 1.0E−33 |
| S&P500 | 0.99 | 1.33E−04 | 0.9 | 10 | 10 | 30 | 1000 | 1.0E−s22 |
SSO-ANN optimum parameters and error
| Indices | Alpha | Beta | Gamma | Epoch | Input layer | Hidden layer | Output layer | Global best fitness | Global best solution (average) |
|---|---|---|---|---|---|---|---|---|---|
| DJI | 0.7665 | 0.6439 | 0.7512 | 250 | 10 | 10 | 1 | 1.0E−64 | 1.0E−44 |
| DAX | 0.7521 | 0.5441 | 0.7591 | 357 | 11 | 22 | 1 | 1.0E−50 | 1.0E−20 |
| FTSE100 | 0.6314 | 0.5512 | 0.6371 | 550 | 8 | 13 | 1 | 1.0E−73 | 1.0E−51 |
| NDAQ | 0.5365 | 0.6891 | 0.8111 | 953 | 12 | 17 | 1 | 2.0E−68 | 2.0E−35 |
| S&P500 | 0.871 | 0.752 | 0.667 | 368 | 10 | 12 | 1 | 1.0E−30 | 1.0E−16 |
Fig. 6Correlogram of closing price (DJI)
Unit root test without differencing (DJI)
| Exogenous: Constant | ||||
| Lag Length (LLgth): 0 (Automatic—based on SIC (ABSIC), maxlag = 17) |
ADF test after differencing
| Exogenous: Constant | ||||
| LLgth: 0 (ABSIC, maxlag = 17) |
Fig. 7Correlogram of closing price after differencing (DJI)
ARIMA forecasting
| Dependent variable: | ||||
| Method: ARMA maximum likelihood (BFGS) | ||||
| Date: 04/10/20 Time: 11:41 | ||||
| Sample: 2435 | ||||
| Number of observations: 434 | ||||
| Failure to improve objective (non-zero gradients) after 188 iterations |
The models used to select criteria
| Model Selection Criteria Table | ||||
| Dependent variable: | ||||
| Date: 04/10/20 Time: 11:41 | ||||
| Sample: 1435 | ||||
| Number of observations: 434 |
Fig. 8Akaike information criteria (top 20 models)
ARIMA forecasting summary
| Automatic ARIMA Forecasting |
| Selected dependent variable: |
| Date: 04/10/20 Time: 11:41 |
| Sample: 1435 |
| Number of observations: 434 |
Comparative study
| Author and date | Proposed approaches | Data type | Data type | MSE | MAE | |
|---|---|---|---|---|---|---|
| Gogna and Tayal ( | GA-ANN | Train | Train | 0.0074 | 0.0584 | 0.9866 |
| Test | Test | 0.0079 | 0.0585 | 0.9895 | ||
| PSO-ANN | Train | Train | 0.0013 | 0.0253 | 0.9972 | |
| Test | Test | 0.0014 | 0.0260 | 0.9969 | ||
| ICS-ANN | Train | Train | 0.0076 | 0.0720 | 0.9966 | |
| Test | Test | 0.0068 | 0.0694 | 0.9995 | ||
| Sedighi et al. ( | ARIMA-SVM | Final outcome | Final outcome | 1.0042 | 0.0142 | |
| SVM-RF | Final outcome | Final outcome | 0.000295 | 0.0245 | ||
| ANFIS-SVM | Final outcome | Final outcome | 3.5849 | 0.0117 | ||
| FA-MSVR | Final outcome | Final outcome | 0.0014 | 0.0130 | ||
| Safa and Panahian ( | HS-ANN | Final outcome | Final outcome | 0.02776 | 0.05177 | 0.9641 |
| Emamverdi et al.( | ANN | Final outcome | Final Outcome | 0.00030 | 0.0174 | |
| ARIMA | Final Outcome | Final outcome | 0.00042 | 0.0162 | ||
| Zheng et al.( | Wavelet neural networks | Final outcome | Final outcome | 0.00510 | 6.742E−04 | 0.9877 |
| Dong et al.( | One-step ahead and multi-step ahead predictions | Final outcome | Final outcome | 0.0043 | 0.1043 | 0.9012 |
| Wang et al.( | Delayed neural network (DNN) | Final outcome | Final outcome | 1.60E−03 | 1.00E−07 | 0.9955 |
| Sin and Wang ( | Ensembles of neural network | Final outcome | Final outcome | 2.05E−05 | 2.045E−09 | 0.9963 |
| Current research | ANN | Train | Train | 12.1827 | 0.9975 | |
| Test | Test | 13.499 | ||||
| GA-ANN | Train | Train | 10.8316 | 0.9988 | ||
| Test | Test | 19.7717 | ||||
| BA | Final outcome | Final outcome | 1.0E−40 | 0.9993 | ||
| SSO | Final outcome | Final outcome | 1.0E−52 | 0.999 | ||
| ARIMA | Final Outcome | Final outcome | 0.0712846 | 0.6028 |
T.V.T details (DAX)
| DAX | Training | Validation | ||
|---|---|---|---|---|
| Absolute error | 0.0006 | 0.0036 | ||
| Network error | 6.34E−09 | 0 | ||
| Error improvement | 9.71E−14 | |||
| Iteration | 401 | |||
| Training speed, iter/sec | 6.937 | |||
| Architecture | [20-10-1] | |||
| TA | LM | |||
| TSR | NEI | |||
T.V.T details (FTSE100)
| FTSE100 | Training | Validation | ||
|---|---|---|---|---|
| Absolute error | 0.3548 | 3.5899 | ||
| Network error | 9.19E−08 | 0 | ||
| Error improvement | 5.31E−11 | |||
| Iteration | 501 | |||
| Training speed, iter/sec | 7.07 | |||
| Architecture | [20-10-1] | |||
| TA | LM | |||
| TSR | All iteration done | |||
T.V.T details (NDAQ)
| NDAQ | Training | Validation | ||
|---|---|---|---|---|
| Absolute error | 0.1354 | 0.261 | ||
| Network error | 1.50E−05 | 0 | ||
| Error improvement | 1.69E−21 | |||
| Iteration | 36 | |||
| Training speed, iter/sec | 6.428 | |||
| Architecture | [20-10-1] | |||
| TA | LM | |||
| TSR | No error improvement | |||
T.V.T details (S&P500)
| S&P500 | Training | Validation | ||
|---|---|---|---|---|
| Absolute error | 0.3538 | 3.09 | ||
| Network error | 1.50E−07 | 0 | ||
| Error Improvement | 6.69E−20 | |||
| Iteration | 327 | |||
| Training speed, iter/sec | 7.047 | |||
| Architecture | [20-10-1] | |||
| TA | LM | |||
| TSR | No error improvement | |||
Selection of most important technical indicators using GA
| Symbol | Technical indicators | Selected using GA | Selected (removed) |
|---|---|---|---|
| DJI | Open, High, Low, Close, Vol, SMA(5), SMA(10), EMA(5), ADL, CMF, MFI, RSI, Upper Band, Lower Band, MP, ROC, TP, DX, CCI, ATR | Open, High, Low, RS, Upper Band, SMA (5), SMA (10), ROC, Vol TP | (10)-10 |
| DAX | Open, High, Low, Close, Vol, SMA(5), SMA(10), EMA(5), ADL, CMF, MFI, RSI, Upper Band, Lower Band, MP, ROC, TP, DX, CCI, ATR | Low, MP, SMA(5), EMA(5), TP, ROC, SMA(10), %R, ADL, RSI, MFI | (11)-9 |
| FTSE100 | Open, High, Low, Close, Vol, SMA(5), SMA(10), EMA(5), ADL, CMF, MFI, RSI, Upper Band, Lower Band, MP, ROC, TP, DX, CCI, ATR | High, ROC, %R, EMA(5), SMA(5), SMA(10), RS, RSI | (8)-12 |
| NDAQ | Open, High, Low, Close, Vol, SMA(5), SMA(10), EMA(5), ADL, CMF, MFI, RSI, Upper Band, Lower Band, MP, ROC, TP, DX, CCI, ATR | Low, SMA(5), EMA(5), SMA(10), RS, RSI, ROC, TP, MP, ADL, VOL, CCI | (12)-8 |
| S&P500 | Open, High, Low, Close, Vol, SMA(5), SMA(10), EMA(5), ADL, CMF, MFI, RSI, Upper Band, Lower Band, MP, ROC, TP, DX, CCI, ATR | Open, Upper Band, Lower Band, RS, SMA(5), SMA(10), EMA(5), TP, RSI, High | (10)-10 |
Correlogram of closing price (DAX)
Unit root test without differencing (DAX)
| Exogenous: Constant | ||||
| LLgth: 0 (ABSIC, maxlag = 17) |
Correlogram of closing price after differencing (DAX)
ADF test after differencing
| Exogenous: Constant | ||||
| LLgth: 0 (ABSIC, maxlag = 17) |
ARIMA forecasting
| Dependent variable: | ||||
| Method: BFGS | ||||
| Date: 04/10/20 Time: 12:11 | ||||
| Sample: 2436 | ||||
| Number of observations: 435 | ||||
| Convergence achieved after 260 iterations |
ARIMA forecasting summary
| Automatic ARIMA Forecasting |
| Selected dependent variable: |
| Date: 04/10/20 Time: 12:11 |
| Sample: 1436 |
| Number of observations: 435 |
| Forecast length: 0 |
ARIMA forecasting (FTSE100)
| Dependent variable: CLOSE | ||||
| Method: BFGS | ||||
| Date: 04/10/20 Time: 12:29 | ||||
| Sample: 1443 | ||||
| Number of observations: 443 | ||||
| Convergence achieved after 195 iterations |
ARIMA forecasting summary
| Automatic ARIMA Forecasting |
| Selected dependent variable: CLOSE |
| Date: 04/10/20 Time: 12:29 |
| Sample: 1443 |
| Number of observations: 443 |
| Forecast length: 0 |
ARIMA forecasting (NDAQ)
| Dependent variable: | ||||
| Method: ARMA maximum likelihood (BFGS) | ||||
| Date: 04/10/20 Time: 12:38 | ||||
| Sample: 2437 | ||||
| Number of observations: 436 | ||||
| Convergence achieved after 33 iterations |
ARIMA forecasting summary
| Automatic ARIMA Forecasting |
| Selected dependent variable: |
| Date: 04/10/20 Time: 12:38 |
| Sample: 1437 |
| Number of observations: 436 |
| Forecast length: 0 |
ARIMA forecasting (S&P500)
| Dependent variable: | ||||
| Method: LSqr | ||||
| Date: 04/10/20 Time: 12:54 | ||||
| Sample (adjusted): 2438 | ||||
| Number of observations: 437 after set out |
ARIMA forecasting summary
| Automatic ARIMA Forecasting |
| Selected dependent variable: |
| Date: 04/10/20 Time: 12:54 |
| Sample: 1438 |
| Number of observations: 437 |
| Forecast length: 0 |