Abstract
With the continuous development of the domestic stock market and the increasing importance of financial systems, accurate stock market prediction has become a critical research focus. To address the low precision and poor accuracy of short-term stock price prediction, this paper proposes a hybrid model: the bi-directional long- and short-term memory network with an attention mechanism optimized by the whale optimization algorithm (WOA-BiLSTM-Attention). This architecture reduces historical information loss and emphasizes critical features while utilizing the Whale Optimization Algorithm (WOA) for automated hyperparameter selection to minimize human interference. Experimental results demonstrate that the WOA-BiLSTM-Attention model outperforms BP, LSTM, BiLSTM, and BiLSTM-Attention models, achieving a Root Mean Square Error (RMSE) of 13.9446 and an $R^2$ value of 0.9477.
Introduction
Predicting stock prices is a "holy grail" in finance, yet it remains notoriously difficult due to the non-linear, high-frequency, and noisy nature of market data. Traditional statistical models like ARIMA often fail to capture complex patterns in large-scale datasets. While standard deep learning models like LSTMs offer improvements, they can suffer from information loss over long sequences or require extensive manual hyperparameter tuning. This research addresses these gaps by introducing a robust, automated prediction framework that combines bidirectional processing, attention mechanisms, and meta-heuristic optimization.
Methodology
The proposed WOA-BiLSTM-Attention architecture integrates three sophisticated components to enhance predictive performance.
1. Bi-directional Long Short-Term Memory (BiLSTM)
Unlike standard LSTMs that process data chronologically, BiLSTMs process sequences in both forward and backward directions. This dual-path approach allows the model to capture "future" context relative to a specific data point, uncovering deeper intrinsic connections in time-series data.
2. Attention Mechanism
The attention layer acts as a filter, assigning varying weights to different parts of the input data. By focusing on the most influential historical time steps and ignoring irrelevant noise, the model improves its ability to capture critical market shifts.
3. Whale Optimization Algorithm (WOA)
The core optimization component is the Whale Optimization Algorithm, a meta-heuristic inspired by the "spiral bubble net" hunting behavior of humpback whales. WOA is used to automatically search for optimal hyperparameters—such as learning rate, batch size, and hidden units—thereby removing the trial-and-error typically performed by human engineers.
Experimental Setup and Results
The study utilized a real-world dataset of Ping An Bank stock (000001.SZ) from January 2010 to January 2024. The data included seven dimensions: opening price, closing price, high, low, previous closing price, change amount, and trading volume. The model was trained on data from 2010–2020 and tested on the 2020–2024 period.
The researchers compared the hybrid model against four benchmarks. The results indicate a clear linear improvement in performance as each architectural component was added:
| Model | RMSE (Lower is Better) | $R^2$ (Higher is Better) |
|---|---|---|
| BP Neural Network | 74.4799 | 0.9119 |
| LSTM | 55.3879 | 0.9155 |
| BiLSTM | 36.3151 | 0.9188 |
| BiLSTM-Attention | 21.5360 | 0.9412 |
| WOA-BiLSTM-Attention | 13.9446 | 0.9477 |
The final model achieved an $R^2$ of 0.9477, explaining nearly 95% of the variance in the stock's closing price. Notably, the model performed exceptionally well at capturing "valley" values (local price minimums), where standard models often lag or overshoot.
Conclusion
The WOA-BiLSTM-Attention model provides a highly accurate and automated solution for stock price prediction. By leveraging bidirectional context and attention-driven weighting, and optimizing these via the Whale Optimization Algorithm, the framework achieves superior stability and fit. Future work will explore the model's generalizability across different sectors and the inclusion of exogenous factors like news sentiment and macroeconomic indicators.
Summary updated