not-yet-known not-yet-known not-yet-known unknown Given the complexity and noise present in market data, accurately predicting stock prices is a crucial difficulty in financial analytics. Feature selection is essential for increasing computational efficiency and prediction accuracy. In this study, we propose a novel hybrid framework that integrates metaheuristic feature selection algorithms with an advanced Transformer-based prediction model fine-tuned with temporal embedding and adaptive attention pruning. We evaluate and compare the performance of three nature-inspired metaheuristic algorithms—Bat Algorithm (BAT), Gray Wolf Optimization (GWO), and Beluga Whale Optimization (BWO)—for selecting the most relevant features from a time-series stock dataset. Following feature selection, the selected subsets are input into a Transformer model designed to capture temporal dependencies and reduce redundant computations through adaptive attention pruning. Extensive experiments conducted on the Bharat Heavy Electricals Limited (BHEL) dataset demonstrate that the proposed hybrid framework outperforms traditional approaches in terms of predictive accuracy. Among the evaluated methods, the combination of BWO and the fine-tuned Transformer achieved the best results, with a Test RMSE of 0.0030 and a Test MAPE of 0.0108, highlighting the superiority of the BWO algorithm in identifying informative features. This work provides a comprehensive comparative analysis of hybrid metaheuristic–deep learning models for stock price prediction and establishes a foundation for further integration of explainable and scalable AI techniques in financial forecasting.