The original whale optimization algorithm (WOA) has a low initial population quality and tends to converge to local optimal solutions. To address these challenges, this paper introduces an improved whale optimization algorithm called OLCHWOA, incorporating a chaos mechanism and an opposition-based learning strategy. This algorithm introduces chaotic initialization and opposition-based initialization operators during the population initialization phase, thereby enhancing the quality of the initial whale population. Additionally, including an elite opposition-based learning operator significantly improves the algorithm's global search capabilities during iterations. The work and contributions of this paper are primarily reflected in two aspects. Firstly, an improved whale algorithm with enhanced development capabilities and a wide range of application scenarios is proposed. Secondly, the proposed OLCHWOA is used to optimize the hyperparameters of the Long Short-Term Memory (LSTM) networks. Subsequently, a prediction model for Realized Volatility (RV) based on OLCHWOA-LSTM is proposed to optimize hyperparameters automatically. To evaluate the performance of OLCHWOA, a series of comparative experiments were conducted using a variety of advanced algorithms. These experiments included 38 standard test functions from CEC2013 and CEC2019 and three constrained engineering design problems. The experimental results show that OLCHWOA ranks first in accuracy and stability under the same maximum fitness function calls budget. Additionally, the China Securities Index 300 (CSI 300) dataset is used to evaluate the effectiveness of the proposed OLCHWOA-LSTM model in predicting RV. The comparison results with the other eight models show that the proposed model has the highest accuracy and goodness of fit in predicting RV. This further confirms that OLCHWOA effectively addresses real-world optimization problems.