Stock prices are known to vary nonlinearly, which makes stock price forecasting quite difficult. Therefore linear models cannot accurately predict frequently fluctuating stock prices; instead, nonlinear models such as gated recurrent unit (GRU) and temporal convolutional network (TCN) tend to outperform linear models in stock price prediction. And yet, nonlinear models that are not well optimized to forecast unstable stock data generally result in poor fit and instability problems. To improve the fitting and stability of a model for share price forecasting, it is essential to optimize the parameters of a model. Dung beetle optimizer (DBO) is a novel bee colony intelligent optimization algorithm that can be used to optimize nonlinear models to enhance the precision of stock price forecasting. In the paper, we first present the GRU-TCN hybrid model with the dung beetle optimization algorithm for stock price prediction, which alleviates the poor fitting and instability problems of stock price prediction to a certain extent and improves the accuracy of stock price prediction. We conducted extensive experiments to show that GRU-TCN-DBO has better performance on MSE and 𝑹 𝟐 evaluation metrics compared to GRU-TCN, GRU, TCN, and LSTM by using 30 stocks of the Dow Jones Industrial Average.