In traditional portfolio optimization models, prediction errors of excess returns in asset selection can lead to performance degradation. This paper employs the Transformer deep learning model to predict the return rates of candidate assets, aiming to enhance the accuracy of return predictions and thereby improve portfolio performance. Using the CSI 800 Index’s constituent stocks as candidate assets, we conduct 72-period rolling investments and compare the results with LSTM and SVR models. The empirical results demonstrate the superiority of the Transformer model in improving predictive accuracy and portfolio model performance.