## 3 Methodology
### Prediction Model  
In this section, we proposed LSTM network to predict the stock price and construct the portfolio based on the prediction outputs.  
Figure 2: The overview of architecture.  
LSTM network is a variant of RNN, which has memory blocks (cells) in the hidden layer that are recurrently connected. There are two states that are being transferred to the next cell: the cell state and the hidden state. The memory blocks are responsible for remembering things and manipulations to this memory are done through three major mechanisms, called gates. A forget gate is responsible for removing information from the cell state. The input gate is responsible for the addition of information to the cell state. The output gate decides which next hidden state should be selected. Operations performed on LSTM network units are explained in (1-6), where \(x_{t}\) is the input at time \(t\) and \(f_{t}\) is the forget gate at time \(t\), which clears information from the memory cell when needed and keeps a record of the previous frame whose information needs to be cleared from the memory. The output gate \(o_{t}\) keeps the information about the upcoming step, where \(g\) is the recurrent unit, having activation function \"_tanh_\", and is computed from the input of the current frame and state of the previous frame \(h_{t-1}\). In all input \((I_{t})\), forget \((f_{t})\), and output \((O_{t})\) gates, as well as the recurrent unit \((g_{t})\), we use \(\left(W_{i},W_{f},W_{o},W_{g}\right)\) and \(\left(b_{i},b_{f},b_{o},b_{g}\right)\) as weights and bias, respectively. The input gate determines what parts of the transformed input \(g_{t}\) need to be added to the long-term state \(c_{t}\). This process updates the long-term state \(c_{t}\), which is directly transmitted to the next cell. Finally, the output gate transforms the updated long-term state \(c_{t}\) through \(tanh(.)\); filters it by \(o_{t}\); and produces the output \(y_{t}\), which is also sent to the next cell as the short-term state \(h_{t}\).  
The equations for LSTM computations are given by the following:  
\[i_{t}=\sigma\Big{(}W_{x_{t}}^{T}x_{t}+W_{h_{t}}^{T}h_{t-1}+b_{i}\Big{)}, \tag{1}\]  
\[f_{t}=\sigma\Big{(}W_{x_{t}}^{T}x_{t}+W_{h_{t}}^{T}h_{t-1}+b_{f}\Big{)}, \tag{2}\]  
\[o_{t}=\sigma\Big{(}W_{x_{0}}^{T}x_{t}+W_{h_{0}}^{T}h_{t-1}+b_{O}\Big{)}, \tag{3}\]  
\[g_{t}=tanh\Big{(}W_{x_{g}}^{T}x_{t}+W_{h_{g}}^{T}h_{t-1}+b_{g}\Big{)}, \tag{4}\]  
\[c_{t}=f_{t}c_{t-1}+i_{t}g_{t}, \tag{5}\]  
\[y_{t}=h_{t}=o_{t}tanhc_{t}, \tag{6}\]  
where \(\sigma(.)\) is the logistic function, and \(tanh(.)\) is the hyperbolic tangent function. The three gates open and close according to the value of the gate controllers \(f_{t}\), \(i_{t}\), and \(o_{t}\), all of which are fully connected layers of neurons. The range of their outputs is \([0,1]\), as they use the logistic function for activation. In each gate, their outputs are fed into element-wise multiplication operations, so, if the output is close to 0, the gate is narrowed and less memory is stored in \(c_{t}\), while if the output is close to 1, the gate is more widely open, letting more memory flow through the gate. Given LSTM cells, it is common to stack multiple layers of the cells to make the model deeper to be able to capture the nonlinearity of the data. Figure 3 illustrates how computation is carried out in an LSTM cell. To keep the wealth of a stock market, we have to have an efficient prediction model that can predict based on the previous data generated from the stock market. In this paper, we used LSTM networks to build a model that can predict the stock price [34; 35]. On the basis of the output of the forecasted price, a portfolio is constructed.  
Figure 3: A recurrent neural network with LSTM network architecture.