Recurrent Neural Networks with Transformers to Trade Financial Instruments
摘要
This paper presents the results of comparing and combining Long Short-Term Memory (LSTM) models with Transformers models in predicting financial market prices. LSTM, a type of Recurrent Neural Network (RNN) has shown great promise in dealing with sequential data and Transformers excel at sequence transduction. Their strengths are tested in this paper through a series of experiments which use data from five financial instruments (Gold, EURUSD, GBPUSD, S&P500 and CF Industries). The research method initially tests the basic structures of the proposed models (LSTM and Transformer). To cover all bases Bi-directional LSTMs are also included. Thereafter, a series of combinations are tested on the financial instruments which produces a performance ranking based on price prediction. Eventually, three models stand out; LSTM with 1 layer of 32 units combined with a base Transformer model (95.9154%), a base Transformer model (93.2079%) and a base Bidirectional LSTM model (91.6369%). The first combination is later used to develop a trading agent that is deployed on a Gymnasium environment from the CF Industries dataset. This trading agent has varying returns but the best trading runs yield a positive P/L (profit/loss), ranging from 0.8% to 5.68% on initial investment. Therefore, with improvements, like addition of market heuristics and good risk management, a trading agent based on the combination of LSTM and Transformers can give good market returns.