Title: Constructing stock portfolio with transformer

Authors: Jinyuan Li; Linkai Luo

Addresses: Department of Automation, Xiamen University, Xiamen, China ' Department of Automation, Xiamen University, Xiamen, China

Abstract: Machine learning methods have been applied to quantitative investing, yet the application of transformer models remains limited. Stock prices are influenced by both long-term and short-term features. Existing methods usually treat the influencing factors as a whole and do not distinguish them. In this paper, we introduce a transformer encoder-decoder architecture tailored for the capture of long-term and short-term features. By partitioning historical data into long-term and short-term parts, the encoder module concentrates on extracting long-term features, while the decoder concentrates on short-term features and the integration of long and short-term features. Portfolios are then constructed from the top N predicted stocks. Experimental results show that the proposed transformer model outperforms the existing state-ofthe- art methods, LSTM, RNN, and GRU models, with improvements of 26%, 19%, and 14% in annualised returns for long-short portfolio combinations, respectively. It indicates the benefits of extracting long-term and short-term features separately.

Keywords: stock portfolio; transformer; factor model.

DOI: 10.1504/IJCSE.2025.147607

International Journal of Computational Science and Engineering, 2025 Vol.28 No.4, pp.446 - 457

Received: 15 Dec 2023
Accepted: 17 Jun 2024

Published online: 24 Jul 2025 *

Full-text access for editors Full-text access for subscribers Purchase this article Comment on this article