# An Improved Elman Network for Stock Price Prediction Service

Authors: Bo Liu; Qilin Wu; Qian Cao
Journal: Security and Communication Networks
 (2020)

---

## Abstract

The rapid development of edge computing drives the rapid development of stock market prediction service in terminal equipment. However, the traditional prediction service algorithm is not applicable in terms of stability and efficiency. In view of this challenge, an improved Elman neural network is proposed in this paper. Elman neural network is a typical dynamic recurrent neural network that can be used to provide the stock price prediction service. First, the prediction model parameters and build process are analysed in detail. Then, the historical data of the closing price of Shanghai composite index and the opening price of Shenzhen composite index are collected for training and testing, so as to predict the prices of the next trading day. Finally, the experiment results validate that it is effective to predict the short-term future stock price by using the improved Elman neural network model.


---

## Body

## 1. Introduction

The stock market can be regarded as a complex nonlinear system, and there are many factors that affect the stock price, especially the recent historical stock price, which has a great influence on the future short-term stock price. So, it is difficult, but valuable, to provide stock price prediction service. Fortunately, with the development of edge computing and neural network technologies, commercial service providers can benefit from the low-latency edge resources and nonlinear expression ability of neural network to provide their users with more efficient service acquisition for stock price prediction. Based on this well-known cognition, we can design a neural network to predict the stock price of the next period based on the historical stock price [1–4]. In this paper, we will use the historical data of the closing price of the Shanghai composite index to predict the closing price of the Shanghai composite index in the next trading day, and the historical data of the opening price of the Shenzhen composite index to predict the opening price of the Shenzhen composite index in the next trading day. In addition, our research could make stock prediction algorithms deployed on edge terminals more efficient.Over the years, although many scholars have established a large number of mathematical models to predict the stock price, they have not achieved good results and have little impact. However, the rise of big data technology and artificial intelligence technology will provide another effective solution for stock price prediction. This is the motivation of our research. Specifically, we hope to establish a reasonable artificial intelligence model and make a more accurate prediction of the future short-term stock price by inputting the latest stock price history. We expect this model can offer a reference for people of stock investment.In this paper, we propose an improved Elman neural network model to predict stock price, and our main contributions include the following:In order to apply traditional stock prediction algorithms to terminal devices such as edge computing and mobile phones, we build a stock price prediction model based on an improved Elman network with the aim to predict the stock price simpler and more stable. We give the specific model parameters and build process.In order to reflect the latest stock market situation, we trained and tested the proposed model with the latest dataset, namely, the Shanghai composite index and Shenzhen composite index in 2018, 2019, and 2020; the latest datasets are used to better reflect the current stock market.To analyse the new algorithm model more clearly, we quantitatively analysed the performance of the model with a variety of mathematical tools and error analysis methods. In addition, a large number of diagrams and tables are provided to further clarify the model.The rest of this paper is organized as follows. Section2 reviews and summarizes the related work, on this basis, to clarify the significance of this study. Section 3 is preliminaries in which the principle of Elman neural network is clarified. In Section 4, we proposed our model, and the specific model construction procedures are introduced in detail. Section 5 is experiments in which the model is built, trained, and tested. In addition, we devoted a great deal of space to the analysis of the results in this section. Finally, Section 6 concludes this paper.


## 2. Preliminaries

Elman neural network is a typical feedback neural network model widely used, which is generally divided into four layers: input layer, hidden layer, bearing layer, and output layer [5, 6].Figure1 shows the basic structure of an Elman neural network; the connection of the input layer, hidden layer, and output layer are similar to the feedforward network. The input layer unit only plays the role of signal transmission, and the output layer unit plays the role of weighting. There are linear and nonlinear excitation functions in the hidden layer element, and the excitation function usually takes the nonlinear function of Sigmoid. The bearing layer is used to remember the output value of the hidden layer unit at the previous time, which can be considered as a delay operator with one-step delay. The output of the hidden layer is self-linked to the input of the hidden layer by accepting the delay and storage of the layer, which makes it sensitive to historical data. In other words, Elman neural network adds a bearing layer to the hidden layer as a one-step delay operator to achieve the purpose of memory so that the system has the ability to adapt to time-varying characteristics and enhance the global stability of the network [7–9]. The mathematical expression of its network is(1)yk=gw3xk,xk=fw1xck+w2uk−1,xck=xk−1,where yt is the output node vector, xt is the nodal element vector of the hidden layer, ut−1 is the input vector, xct is the feedback state vector, w3 is the connection weight from the hidden layer to the output layer, w2 is the connection weight from the input layer to the hidden layer, w1 is the connection weight of the connecting layer to the hidden layer, g is the transfer function of the output neuron and the linear combination of the output of the hidden layer, and f is the transfer function of the hidden layer neuron, usually using the S function.Figure 1
The basic structure of an Elman neural network.This research takes MATLAB as the experimental platform. And the two datasets used in this study are the closing prices of 490 trading days of the Shanghai composite index from September 26, 2017, to September 30, 2019, and the opening prices of 420 trading days from August 15, 2018, to May 12, 2020. We will use the same model for training and testing based on these two datasets.


## 3. Related Work

In fact, many researchers have been studying stock price forecasts for years, some of these studies have improved the existing models and some have further processed the data. However, these studies are not perfect, and some of the models are too complex and some of the processing procedures are tedious. These shortcomings will increase the instability of the models and limit the application and extension of the research results.Shi et al. considered that traditional stock forecasting methods could not fit and analyse highly nonlinear and multifactors of stock market well, so there are problems such as low prediction accuracy and slow training speed. Therefore, they proposed a prediction method of the Elman neural network model based on the principal component analysis method. In order to compare the results better, BP network and Elman network with the same structure are established to predict the stock data [10]. Yu et al. used an improved Elman neural network as the forecasting model and the market price of Zhongji company (No. 000039) in Shenzhen stock market is forecasted; their experiment results get higher precision, steadier forecasting effect, and more rapid convergence speed [11]. Zheng et al. studied the forecast of opening stock price based on Elman neural network in 2015, and they selected the opening prices of Shanghai stock index of 337 trading days from December, 2012 to April, 2014 as the raw data for stimulated forecast, and the result proves the validity of their forecast model [12]. Zhang et al. successfully applied Elman regression neural network to the prediction of stock opening price. Specifically, the authors described the Particle Swarm Optimization (PSO) algorithm for learning optimization of the Elman Recurrent Neural Network, and the results showed that the model based on LSTM was more accurate than other machine learning models [13]. Jun used Adaptive Whale Optimization Algorithm and Elman neural network to predict the stock price and achieved better results based on their experiments [14]. Javad Zahedi et al. used the artificial neural network model and principal component analysis to evaluate the predictability of stock price in Teheran stock exchange with 20 accounting variables. Finally, the goodness of fit of principal component analysis was determined by actual values, and the effective factors of Teheran stock exchange price were accurately predicted and modelled by a new model composed of all variables [15]. Han et al. designed a three-ply BP network and the corresponding mathematical model. Therefore, using 140 days actual price of the stock 600688 as a sample, the network was trained through MATLAB; thereby, the 10 days predictions of the stock price and the dispersion Q = 0. 0146 to the practical data were made [16].Although scholars have made outstanding contributions in using artificial intelligence to predict stock prices, neither the stability of the models nor the accuracy of the predictions is satisfactory. Based on this fact, this study seeks to exploit the neural network model for the prediction of stock price based on Elman network with balancing the simplicity, stability, and accuracy.


## 4. Supposed Model

The general steps to build the supposed model of this study include data collection, data load, sample set construction, division of sample set and training set, construction of Elman neural network, and training of the neural network model. The specific flow chart is shown in Figure2.Figure 2
Elman neural network model construction steps.


### 4.1. Construction of Sample Set

The stock price prediction problem in this study is actually a time series problem, which can be expressed by the following formula:(2)xn=fxn−1,xn−2,⋯,xn−N.This formula means that the closing price of the previous N trading day can be used to predict the closing price of the next trading day. The data of 490 closing prices were divided into training samples and test samples; for the training samples,x1～xN are selected to form the first sample, where x1,x2,⋯,xN−1 are the independent variable and xN is the dependent variable, and x2～xN+1 are selected to form the second sample, where x2,x3,⋯,xN are the independent variable and xN+1 is the dependent variable; finally, a training matrix is formed as follows:(3)x1x2xix2x3xi+1⋯⋯⋯xN−1xNxNxN+1.In this matrix, each column is a sample, and the last row is the expected output. These samples are fed into the Elman neural network for training, and then the network model can be obtained [17–19].In this study,x1～xN are selected to form the first sample, and x2～xN+1 are selected to form the second sample; the rest can be carried out in the same manner. Here, N is randomly set to 8, which means that the closing price of the day is determined by the closing price of the previous seven trading days.Take the Shanghai composite index dataset as an example, the closing prices of the first eight trading days are 3,343.58, 3345.27, 3339.64, 3348.94, 3374.38, 3382.99, 3388.28, and 3386.10, which means 3,343.58, 3345.27,3339.64, 3348.94, 3374.38, 3382.99, and 3388.28 will be used to forecast the eighth data 3388.28 which we have already obtained. The closing prices of the first eight trading days are 2999.28, 3006.45, 2977.08, 2985.34, 2955.43, 2929.09, 2932.17, and 2905.19, and the same principle, 2999.28, 3006.45, 2977.08, 2985.34, 2955.43, 2929.09, and 2932.17, will be used to forecast the eighth data 2905.19 which we have already obtained. Therefore, 490 pieces of data will be converted into a8×483 matrix; 483 columns mean 483 samples, in which the first 7 data in each column are independent variables and the eighth data is the data to be predicted. The8×483 matrix is shown as follows:(4)3343.583345.273339.643390.52⋯2999.283378.47⋯3006.453372.04⋯2977.083348.943374.383382.993388.283386.13381.79⋯2985.343370.17⋯2955.433378.65⋯2929.093380.7⋯2932.173388.25⋯2905.19.The Shenzhen composite index dataset is 8786.3497, 8470.9094, 8573.5693, 8355.0002, 8419.7868, 8533.4289, 8446.9836, 8480.2244, 8511.3743, 8731.6394, 8716.8172, 8666.9025, 8509.2723, 8440.9528, 8454.1357, 8519.5698, ⋯⋯,10477.7614, 10460.9947, 10575.5242, 10618.1651, 10899.9169, 10923.6123, 11053.8157, 10972.0503. In the same way, the Shenzhen composite index dataset is formed as a8×413 matrix, which is as follows:(5)8786.34978470.90948573.56938511.3743⋯10477.76148731.6394⋯10460.99478716.8172⋯10575.52428355.00028419.78688533.42898446.98368480.22448666.9025⋯10618.16518509.2723⋯10899.91698440.9528⋯10923.61238454.1357⋯11053.81578519.5698⋯10972.0503.413 columns mean 413 samples, in which the first 7 data in each column are independent variables and the eighth data is the data to be predicted.


### 4.2. Construction of Elman Neural Network

Figure3 shows the proposed model structure, where u1,⋯,u7 are input data, x1,⋯,x18 are hidden-layer data, and xc1,⋯,xc18 are bearing-layer data. With the help of MATLAB neural network toolbox, Elman neural network can be easily built. To be specific, the MATLAB neural network toolbox provides an Elmannet function, and Elman network construction can be completed by setting three parameters in the Elmannet function, which are the delay time, the number of hidden layer neurons, and the training function, respectively. In this case, the number of hidden-layer neurons is set to be 18, and TRAINGDX is chosen to be the training function [20–22]. TRAINGDX, which is named gradient descent with momentum and adaptive learning rate backpropagation, is a network training function that updates weight and bias values according to gradient descent momentum and an adaptive learning rate. It will return a trained net and the training record. In addition, the maximum number of iterations in the training is set to 3000, the maximum number of validation failures is set to 6, and the error tolerance is set to 0.00001, which means that the training can be stopped if the error value is reached [23, 24]. Figure 4 shows the model structure graphic automatically generated by MATLAB.Figure 3
Model structure.Figure 4
The model structure graphic generated by MATLAB.To construct the Elman neural network, the MATLAB code can be like this. Firstly, three parameters in the Elmannet function are set, and codes are as follows:(6)net=Elmannet1:2,18,‘TRAINGDX’.Secondly, the maximum number of iterations in the training is set to 3000, and codes are as follows:(7)net.trainParam.epochs=3000.Thirdly, the maximum number of validation failures is set to 6, and the error tolerance is set to 0.00001, and codes are as follows:(8)net.trainParam.max_fail=6,net.trainParam.goal=0.00001.Finally, initialize the network, and codes are as follows:(9)net=initnet.After all the above steps, construction of Elman neural network is completed [25–27].


## 4.1. Construction of Sample Set

The stock price prediction problem in this study is actually a time series problem, which can be expressed by the following formula:(2)xn=fxn−1,xn−2,⋯,xn−N.This formula means that the closing price of the previous N trading day can be used to predict the closing price of the next trading day. The data of 490 closing prices were divided into training samples and test samples; for the training samples,x1～xN are selected to form the first sample, where x1,x2,⋯,xN−1 are the independent variable and xN is the dependent variable, and x2～xN+1 are selected to form the second sample, where x2,x3,⋯,xN are the independent variable and xN+1 is the dependent variable; finally, a training matrix is formed as follows:(3)x1x2xix2x3xi+1⋯⋯⋯xN−1xNxNxN+1.In this matrix, each column is a sample, and the last row is the expected output. These samples are fed into the Elman neural network for training, and then the network model can be obtained [17–19].In this study,x1～xN are selected to form the first sample, and x2～xN+1 are selected to form the second sample; the rest can be carried out in the same manner. Here, N is randomly set to 8, which means that the closing price of the day is determined by the closing price of the previous seven trading days.Take the Shanghai composite index dataset as an example, the closing prices of the first eight trading days are 3,343.58, 3345.27, 3339.64, 3348.94, 3374.38, 3382.99, 3388.28, and 3386.10, which means 3,343.58, 3345.27,3339.64, 3348.94, 3374.38, 3382.99, and 3388.28 will be used to forecast the eighth data 3388.28 which we have already obtained. The closing prices of the first eight trading days are 2999.28, 3006.45, 2977.08, 2985.34, 2955.43, 2929.09, 2932.17, and 2905.19, and the same principle, 2999.28, 3006.45, 2977.08, 2985.34, 2955.43, 2929.09, and 2932.17, will be used to forecast the eighth data 2905.19 which we have already obtained. Therefore, 490 pieces of data will be converted into a8×483 matrix; 483 columns mean 483 samples, in which the first 7 data in each column are independent variables and the eighth data is the data to be predicted. The8×483 matrix is shown as follows:(4)3343.583345.273339.643390.52⋯2999.283378.47⋯3006.453372.04⋯2977.083348.943374.383382.993388.283386.13381.79⋯2985.343370.17⋯2955.433378.65⋯2929.093380.7⋯2932.173388.25⋯2905.19.The Shenzhen composite index dataset is 8786.3497, 8470.9094, 8573.5693, 8355.0002, 8419.7868, 8533.4289, 8446.9836, 8480.2244, 8511.3743, 8731.6394, 8716.8172, 8666.9025, 8509.2723, 8440.9528, 8454.1357, 8519.5698, ⋯⋯,10477.7614, 10460.9947, 10575.5242, 10618.1651, 10899.9169, 10923.6123, 11053.8157, 10972.0503. In the same way, the Shenzhen composite index dataset is formed as a8×413 matrix, which is as follows:(5)8786.34978470.90948573.56938511.3743⋯10477.76148731.6394⋯10460.99478716.8172⋯10575.52428355.00028419.78688533.42898446.98368480.22448666.9025⋯10618.16518509.2723⋯10899.91698440.9528⋯10923.61238454.1357⋯11053.81578519.5698⋯10972.0503.413 columns mean 413 samples, in which the first 7 data in each column are independent variables and the eighth data is the data to be predicted.


## 4.2. Construction of Elman Neural Network

Figure3 shows the proposed model structure, where u1,⋯,u7 are input data, x1,⋯,x18 are hidden-layer data, and xc1,⋯,xc18 are bearing-layer data. With the help of MATLAB neural network toolbox, Elman neural network can be easily built. To be specific, the MATLAB neural network toolbox provides an Elmannet function, and Elman network construction can be completed by setting three parameters in the Elmannet function, which are the delay time, the number of hidden layer neurons, and the training function, respectively. In this case, the number of hidden-layer neurons is set to be 18, and TRAINGDX is chosen to be the training function [20–22]. TRAINGDX, which is named gradient descent with momentum and adaptive learning rate backpropagation, is a network training function that updates weight and bias values according to gradient descent momentum and an adaptive learning rate. It will return a trained net and the training record. In addition, the maximum number of iterations in the training is set to 3000, the maximum number of validation failures is set to 6, and the error tolerance is set to 0.00001, which means that the training can be stopped if the error value is reached [23, 24]. Figure 4 shows the model structure graphic automatically generated by MATLAB.Figure 3
Model structure.Figure 4
The model structure graphic generated by MATLAB.To construct the Elman neural network, the MATLAB code can be like this. Firstly, three parameters in the Elmannet function are set, and codes are as follows:(6)net=Elmannet1:2,18,‘TRAINGDX’.Secondly, the maximum number of iterations in the training is set to 3000, and codes are as follows:(7)net.trainParam.epochs=3000.Thirdly, the maximum number of validation failures is set to 6, and the error tolerance is set to 0.00001, and codes are as follows:(8)net.trainParam.max_fail=6,net.trainParam.goal=0.00001.Finally, initialize the network, and codes are as follows:(9)net=initnet.After all the above steps, construction of Elman neural network is completed [25–27].


## 5. Experiments

### 5.1. Training of the Supposed Model

When the Elman neural network is built, the model can be trained, but all the data has to be normalized first considering of the performance and stability of the model. The normalization operation can use the mapminmax function provided by MATLAB toolbox, and the default normalization interval of mapminmax function is [−1, 1]. The detailed MATLAB code is as follows:(10)trainx1,st1=mapminmaxtrainx,train_ty1=simnet,trainx1,train_ty=mapminmax‘reverse’,train_ty1,st2.After the normalized operation of training data, trainx and trainx1 were obtained. The normalized training data (trainx1) were input into the network model to obtain the current network output (train_ty1) and then reversely normalized into normal data to obtain train_ty, which is the corresponding stock price of the training data. What we want to emphasize is that the data used in the test should be normalized first and then the output should be unnormalized.


### 5.2. The Test Results and the Quantitative Analysis

Figure5 shows a graph of the actual and predicted values; the blue solid line is the actual value and the red dotted line represents the Elman network output value. Apparently, the model fits the training data well. In addition, we further calculated the residuals of test results on training; Figure 6 shows the residuals of training results on training data, and residual in mathematical statistics refers to the difference between the actual observed value and the estimated value (the fitting value).Figure 5
Test results for training data.Figure 6
Residuals of test results on training data.Figure7 shows a graph of the actual and predicted values; the black solid line is the actual value and the red dotted line represents the Elman network output value. In addition, we further calculate the residuals of test results on testing data; Figure 8 shows the residuals of test results on testing data. And, the relative errors of each prediction are also calculated for further study and analysis. All relative error values are shown in Tables 1 and 2. By analysing these graphs and data, it is clear that the prediction effect of the model is pretty good.Figure 7
Test results for testing data.Figure 8
Residuals of test results on testing data.Table 1
Relative error of test (Shanghai composite index).
Number1234567Relative error0.006674−0.0010900.010719−0.010057−0.0251530.0016900.000677Number891011121314Relative error0.012402−0.003898−0.002381−0.015004−0.023218−0.007697−0.002238Number15161718192021Relative error0.009203−0.000263−0.0093390.000532−0.022964−0.0005200.007789Number22232425262728Relative error0.006250−0.0049370.023693−0.0004880.004250−0.005476−0.003717Number29303132333435Relative error−0.0054920.0036120.0016760.010246−0.0091940.010889−0.007296Number36373839404142Relative error−0.006752−0.008459−0.001553−0.000139−0.0035530.0047420.005815Number43444546474849Relative error0.0137860.0143880.0147450.000828−0.0107760.005480−0.012749Number50515253545556Relative error0.009279−0.0046900.000227−0.006596−0.019610−0.002958−0.001138Number57585960616263Relative error0.000246−0.0076370.009974−0.0160510.002405−0.0026440.003361Number64656667686970Relative error−0.015557−0.002587−0.012756−0.009015−0.007153−0.009234−0.001688Number71727374757677Relative error0.002176−0.008728−0.0031100.015200−0.002282−0.005979−0.006169Number787980818283Relative error0.009414−0.0023980.0107430.006008−0.0011050.006332Table 2
Relative error of test (Shenzhen composite index).
Number1234567Relative error−0.0137470.002825−0.0171770.0043700.030084−0.001853−0.047231Number891011121314Relative error0.017591−0.0179270.0070110.0109860.026179−0.0440380.035607Number15161718192021Relative error0.061603−0.0434080.0479260.0089110.028250−0.0161420.039523Number22232425262728Relative error−0.012140−0.0216090.001765−0.0109770.036256−0.0050630.006179Number29303132333435Relative error0.003674−0.022697−0.014897−0.002466−0.0064320.0012600.023451Number36373839404142Relative error−0.009376−0.0167810.009971−0.0196860.001902−0.0023250.014443Number43444546474849Relative error−0.0246770.0092850.008341−0.003239−0.000341−0.010959−0.005216Number50515253545556Relative error−0.026052−0.000483−0.0127970.007071


## 5.1. Training of the Supposed Model

When the Elman neural network is built, the model can be trained, but all the data has to be normalized first considering of the performance and stability of the model. The normalization operation can use the mapminmax function provided by MATLAB toolbox, and the default normalization interval of mapminmax function is [−1, 1]. The detailed MATLAB code is as follows:(10)trainx1,st1=mapminmaxtrainx,train_ty1=simnet,trainx1,train_ty=mapminmax‘reverse’,train_ty1,st2.After the normalized operation of training data, trainx and trainx1 were obtained. The normalized training data (trainx1) were input into the network model to obtain the current network output (train_ty1) and then reversely normalized into normal data to obtain train_ty, which is the corresponding stock price of the training data. What we want to emphasize is that the data used in the test should be normalized first and then the output should be unnormalized.


## 5.2. The Test Results and the Quantitative Analysis

Figure5 shows a graph of the actual and predicted values; the blue solid line is the actual value and the red dotted line represents the Elman network output value. Apparently, the model fits the training data well. In addition, we further calculated the residuals of test results on training; Figure 6 shows the residuals of training results on training data, and residual in mathematical statistics refers to the difference between the actual observed value and the estimated value (the fitting value).Figure 5
Test results for training data.Figure 6
Residuals of test results on training data.Figure7 shows a graph of the actual and predicted values; the black solid line is the actual value and the red dotted line represents the Elman network output value. In addition, we further calculate the residuals of test results on testing data; Figure 8 shows the residuals of test results on testing data. And, the relative errors of each prediction are also calculated for further study and analysis. All relative error values are shown in Tables 1 and 2. By analysing these graphs and data, it is clear that the prediction effect of the model is pretty good.Figure 7
Test results for testing data.Figure 8
Residuals of test results on testing data.Table 1
Relative error of test (Shanghai composite index).
Number1234567Relative error0.006674−0.0010900.010719−0.010057−0.0251530.0016900.000677Number891011121314Relative error0.012402−0.003898−0.002381−0.015004−0.023218−0.007697−0.002238Number15161718192021Relative error0.009203−0.000263−0.0093390.000532−0.022964−0.0005200.007789Number22232425262728Relative error0.006250−0.0049370.023693−0.0004880.004250−0.005476−0.003717Number29303132333435Relative error−0.0054920.0036120.0016760.010246−0.0091940.010889−0.007296Number36373839404142Relative error−0.006752−0.008459−0.001553−0.000139−0.0035530.0047420.005815Number43444546474849Relative error0.0137860.0143880.0147450.000828−0.0107760.005480−0.012749Number50515253545556Relative error0.009279−0.0046900.000227−0.006596−0.019610−0.002958−0.001138Number57585960616263Relative error0.000246−0.0076370.009974−0.0160510.002405−0.0026440.003361Number64656667686970Relative error−0.015557−0.002587−0.012756−0.009015−0.007153−0.009234−0.001688Number71727374757677Relative error0.002176−0.008728−0.0031100.015200−0.002282−0.005979−0.006169Number787980818283Relative error0.009414−0.0023980.0107430.006008−0.0011050.006332Table 2
Relative error of test (Shenzhen composite index).
Number1234567Relative error−0.0137470.002825−0.0171770.0043700.030084−0.001853−0.047231Number891011121314Relative error0.017591−0.0179270.0070110.0109860.026179−0.0440380.035607Number15161718192021Relative error0.061603−0.0434080.0479260.0089110.028250−0.0161420.039523Number22232425262728Relative error−0.012140−0.0216090.001765−0.0109770.036256−0.0050630.006179Number29303132333435Relative error0.003674−0.022697−0.014897−0.002466−0.0064320.0012600.023451Number36373839404142Relative error−0.009376−0.0167810.009971−0.0196860.001902−0.0023250.014443Number43444546474849Relative error−0.0246770.0092850.008341−0.003239−0.000341−0.010959−0.005216Number50515253545556Relative error−0.026052−0.000483−0.0127970.007071


## 6. Conclusions

This study is based on a basic premise that the historical stock price will have a great impact on the future short-term stock price. On this premise, we established an improved Elman model and collected the historical data of the Shanghai composite index and the Shenzhen composite index as a dataset for the experiment. As for dataset processing, we divided two datasets, one for training and the other for testing. In addition, the data were normalized. Regarding model building, we take MATLAB as the platform, and set the number of hidden-layer neurons to be 18. TRAINGDX is chosen to be the training function. In terms of training, the maximum number of iterations in the training is set to 3000, the maximum number of validation failures is set to 6, and the error tolerance is set to 0.00001. Finally, we use the model to test the training data and the test data. In order to analyse the experimental results, we also calculated relative error and the residuals and drew a picture to show them. Based on Elman network, this study predicted the short-term stock price in the future and achieved a good prediction effect. However, it is unrealistic to predict the long-term stock price in the future, which is difficult to achieve [28–30]. This study provides an effective experimental method for predicting the near future stock price.



---

*Source: 8824430-2020-09-03.xml*