# Prediction of Stock Performance Using Deep Neural Networks
## 3 Deep Neural Network-Based Model for Stock Performance Prediction
### Concatenated Double-Layered LSTM for Stock Performance Prediction  
This study proposes a LSTM-based network to predict the future performance of stocks by classification. The proposed network classifies stocks into two categories (buying or not) based on the historical sequence data. The \"Many to one\" model has been widely used in sequence data processing. To fully use the memory and forget ability of LSTM, our proposed network is also a \"many to one\" model. The architecture of the proposed classification network is shown in Figure 2. This means that when classifying the stocks into two categories (buying or not), the historical sequence  
Figure 1: Visualization of a Long Short-Term Memory (LSTM) unit. data from time \(t-n\) to \(t\): \((\mathbf{r}_{t-n},\ldots,\mathbf{r}_{t})\) are input into the network together. In the proposed network, \(n\) was empirically decided as 52 by considering the experience of professional traders. Figure 3 corresponds to the model in Figure 2. It shows the architecture of the model block. There are double-layered LSTMs. Finally, the output is connected with the last LSTM layer. Here, \(\mathbf{x}_{t}\) denotes the input data at week \(t\). The double-layered LSTM model can be explained by:  
\[\left(\mathbf{h}_{t}^{1},\mathbf{c}_{t}^{1}\right) =\text{LSTM}\big{(}\mathbf{x}_{t},\mathbf{h}_{t-1}^{1},\mathbf{c}_ {t-1}^{1},\mathbf{W}^{1},\mathbf{b}^{1}\big{)} \tag{12}\] \[\left(\mathbf{h}_{t}^{2},\mathbf{c}_{t}^{2}\right) =\text{LSTM}\big{(}\mathbf{h}_{t}^{1},\mathbf{h}_{t-1}^{2}, \mathbf{c}_{t-1}^{2},\mathbf{W}^{2},\mathbf{b}^{2}\big{)} \tag{13}\]  
In Figure 3, \(\mathbf{s}_{t}^{n}\) stands for \(\left(\mathbf{h}_{t}^{n},\mathbf{c}_{t}^{n}\right),n=1\)_or_ 2. To reduce the complexity of the task, in this study, a binary-class classification system was developed for stock performance prediction. This means that the classification system is expected to recognize two categories. Therefore, the output of the final hidden layer connects two nodes to indicate the probabilities for two categories, the probabilities can be estimated from the output of the second LSTM layer as:  
\[\mathbf{P}_{t}=\mathbf{W}_{2}\;\mathbf{h}_{t}^{2}+\mathbf{b}_{2} \tag{14}\]  
where \(\mathbf{W}_{2}\) is a weight matrix from the hidden layer to the output layer, and \(\mathbf{b}_{2}\) is the bias vector. \(\mathbf{P}_{t}\) is a vector to indicate the probability of the sample for two categories: 0 and 1. The category  
Figure 3: Architecture of double-layer LSTM model for the stock performance prediction. Figure 2: “Many to one” architecture for the classification of stocks. \"0\" means not buying a stock, and the category \"1\" means buying a stock. The softmax layer and classification layer are responsible for normalization and category selection which are explained in the following equations:  
\[\text{Normalization:}\;\sigma(\mathbf{P}_{t})_{i}=\frac{e^{p_{i,j}}}{\sum_{k=0}^{ 1}e^{p_{i,k}}}\;\text{for}\;\;i=0\;\;\text{or}\;\;1\;\;\text{and}\;\;\;\mathbf{P} _{t}=[P_{t,0},P_{t,1}\;] \tag{15}\]  
\[\text{Category selection }=\left\{ \begin{array}{l}[1,0]\;\;\text{if}\;\sigma( \mathbf{P}_{t})_{0}>\sigma(\mathbf{P}_{t})_{1}\\ [0,1]\;\text{else}\end{array} \right. \tag{16}\]  
The double-layer LSTM model can predict whether the automatic trading system should buy or not buy a stock, given the past 52-week history information of that stock. The output of the double-layer LSTM model could be [1, 0] or [0, 1]. [1, 0] means not buying the stock, and [0, 1] means buying the stock. The output ([1, 0] or [0, 1]) is decided in the category selection block based on the comparison of the normalized probabilities provided by the softmax layer. If the probability of category \"0\" (not buying a stock) is higher than the probability of category \"1\" (buying a stock), the output is [1, 0]. Otherwise, the output will be [0, 1]. In the training of the network, \([(\mathbf{r}_{t-n},\ldots,\mathbf{r}_{t});\text{Ground Truth }([1,0] \text{or}[0,1]))\) is used as the sample data because of the \"many to one\" architecture.