# A Stock Prediction Method Based on Heterogeneous Bidirectional LSTM
## 4 Experiment
### Predicting the Price for Multiple Future Days  
To validate the generalization capability of He-BiLSTM, it is employed to predict the prices of the 12 th and 13 th days based on the prices of the first 10 days, and the results are compared with those of BiLSTM. The specific evaluation metrics are shown in Table 2.  
When predicting the prices for the next two days, it can be observed that the test accuracy of He-BiLSTM can still reach 92.79%. Compared to predicting the price for the next day, the accuracy only drops by less than 2% from 94.22%. However, for BiLSTM, although the accuracy on the test set can still exceed 85%, it drops by nearly 4% compared to 90.36% when predicting the price for the next day. This indicates that in terms of robustness and generalization ability, He-BiLSTM performs better.  
As can be seen from Table 3, When predicting the prices for the next three days, He-BiLSTM's test set accuracy is 90.03%, still maintaining a benchmark above 90%. In contrast, BiLSTM's test set accuracy has dropped to 74.28%. Comparatively, He-BiLSTM's evaluation metrics are now significantly ahead of BiLSTM's. This demonstrates that He-BiLSTM has excellent capability for predicting prices over multiple future days, which, in the practical field of financial investment, can provide investors and decision makers with a broader range of strategies.  
Since the He-BiLSTM model achieves an accuracy of 94.2% in predicting the stock index price for the next day, it is considered a high-probability event. Therefore, in real market conditions (excluding the impact of sudden news events), if the predicted lowest price for the next day is within a 6% fluctuation range from the current price, buying at that point and selling when the predicted highest price is within a 6% fluctuation range from the current price can maximize profits. If the He-BiLSTM predicts a higher price within the next two days and one aims for greater returns, the accuracy decreases to 92.8%; thus, the buying and selling price fluctuation range should be around 8%. Similarly, if a higher price is predicted within the next three days, the accuracy is 90.3%, and the fluctuation range for buying and selling should be around 10%.  
In individual stock price predictions, Microsoft and Kweichow Moutai were also selected for further stock price forecasting. The prediction results are shown in Figures 6 and 7, respectively. The experiments showed that the overall performance of the He-BiLSTM model surpassed that of the BiLSTM.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Evaluation Indicators** & **MSE (Train)** & **MSE (Test)** & **MAE (Train)** & **MAE (Test)** & \(R^{2}\) (Train)** & \(R^{2}\) **(Test)** \\ \hline BiLSTM & \(9.1886\times 10^{-5}\) & 0.000422057 & 0.00730022 & 0.0153276 & 0.920295 & 0.862634 \\ He-BiLSTM & \(8.09596\times 10^{-5}\) & 0.000265874 & 0.00636295 & 0.0103576 & 0.938024 & 0.927856 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Comparison of evaluation metrics for predicting the next two days.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Evaluation Indicators** & **MSE (Train)** & **MSE (Test)** & **MAE (Train)** & **MAE (Test)** & \(R^{2}\) (Train)** & \(R^{2}\) **(Test)** \\ \hline BiLSTM & \(0.000114456\) & \(0.000707841\) & \(0.00809543\) & \(0.0209139\) & \(0.888085\) & \(0.742807\) \\ He-BiLSTM & \(9.67334\times 10^{-5}\) & \(0.000333368\) & \(0.00686506\) & \(0.012031\) & \(0.926151\) & \(0.90033\) \\ \hline \hline \end{tabular}
\end{table}
Table 3: Comparison of evaluation metrics for predicting the next three days.  
Additionally, to further demonstrate the model's generalization capability, He-BiLSTM is applied to futures data and compared with BiLSTM in experiments, with results also showing that He-BiLSTM is superior to BiLSTM.The prediction results are shown in Figure 8.