# Important Trading Point Prediction Using a Hybrid Convolutional Recurrent Neural Network
## 4 Deep Learning Framework for Important Trading Point Prediction
### Threshold Search Mechanism  
With the proposed HCRNN model, the prediction of important trading points is straightforward. Figure 5 depicts the flow chart of the proposed framework, which consists of three parts:  
(1) Model training: The first 80% of the whole dataset is used as the training set for feature learning, and the HCRNN model is trained by the RMSprop optimizer with a fixed learning rate of 0.01. At each iteration, all training sequences are input to update the weights and biases. In this way, the weights of the model are shared among all the stocks. The model parameters are stored every 20 iterations until a maximum of _MaxIter_ iterations is reached. (2) Threshold search: The next 10% of the dataset is the validation set for choosing the best epoch that has the smallest validation loss \(J\) and searching for the threshold \(\lambda\) that  
Figure 5: The flow chart of the proposed important trading point prediction framework based on a hybrid convolutional recurrent neural network (HCRNN). achieves the highest profit on the validation set; the reason is that the market situation in this period is most similar to the test set that is the last 10% of the dataset. Both the model parameters and the threshold \(\lambda\) that show the best performance on the validation set are used for the final test to simulate the real trading environment. As discussed in Section 4.2, the threshold \(\theta\) plays an important role in the prediction performance. The lower the threshold, the more time points will be predicted as belonging to a SIP (\"1\"); stock trading will increase, and the profit per transaction will decrease in the fund simulation because more trading points will be mistakenly detected as IPs. A feasible method of setting an appropriate threshold is to estimate the threshold by backtesting on the most recent historical data, and the procedures are as follows:  
1. Obtain the output \(y_{t}\) of the validation set, where \(y_{t}=[y_{1},y_{2},y_{3},\ldots,y_{t}]\), and then sort \(y_{t}\) from largest to smallest as \(r_{t}=[r_{1},r_{2},r_{3},\ldots,r_{t}](r_{1}>r_{2}\cdots>r_{t})\), where \(r_{t}\) denotes the reordered output. 2. Count the number of \"1\" values (belonging to a SIP) on the training set \(N_{t}\); then, calculate the estimated number of \"1\" values (belonging to a SIP) on the validation set \(N_{v}\) in proportion to the lengths of these two sets. Formally, \[N_{v}=N_{t}\frac{\text{length of the validation set}}{\text{length of the training set}}.\] (16)
3. According to the experience of professional human investors, the actual number of \"1\" values (belonging to a SIP) in the validation set \(N_{a}\) is approximately \(N_{v}\). Considering the situation of stock market changes over time, we multiply \(N_{v}\) by a coefficient \(\varepsilon\) ranging from \(1/2\) to \(2\) (based on the statistical results shown in Section 5.1.2) as an estimate of \(N_{a}\), denoted by \[N_{a}=\varepsilon N_{v}\quad\varepsilon\in\left[\frac{1}{2},2\right].\] (17)
4. Set the threshold \(\theta\) as the \(N_{a}\)th value of \(r_{t}=[r_{1},r_{2},r_{3},\ldots,r_{t}]\), expressed as \[\theta=r_{N_{a}}.\] (18) Then, this threshold is used to classify the output \(y_{t}\) of the validation set into two types, and the number of time points classified as \"1\" (belonging to a SIP) will be \(N_{a}\). We can obtain a trading module based on this classification and calculate the profit on the validation set with this threshold. 5. Increase \(\varepsilon\) by a step size of 0.1 and calculate the profit of each threshold. Finally, output the threshold \(\lambda\) that achieves the highest profit on the validation set as the threshold used for the model test. (3) Evaluation with the test set: With the model and threshold \(\lambda\) that show the best performance on the validation set, a test set is utilized to test the effectiveness of the proposed framework.