A novel trading strategy based on BiLSTM prediction model

. In order to assist traders with scientiﬁc transaction strategy, this paper constructs a decision model including a prediction model and a trading model. Our predicting model is based on a BiLSTM (Bi-direction Long Short-Term Memory) neural network, and two linear layers trained by previous known data, which obtains a high accurate prediction of price. For the trading model, we construct it with several impact and quantitative artiﬁcial-selected-factors including market potential, deviation rate, risk score, etc. To use the model, we ﬁrstly uses previous known data to train the deep neural network and utilize it to make future predictions, the results of which is then imported into our trading model for decision making and better conﬁgure the portfolio. Generally speaking, our whole decision system achieves eﬀective prediction of price, enables timely risk assessment, and makes scientiﬁc decisions by considering these factors together.


Introduction
With the advent of block-chain technology, the cryptocurrency market, mainly represented by Bitcoin, has been growing rapidly over the past few years, with an 80-fold increase in market capitalization in the last decade [1]. As Bitcoin is a decentralized currency, independent of government involvement has a faster rate of appreciation in terms of value, it has become a similar form of wealth storage to gold that has gained attention. As such, investing in bitcoin and gold to maximize returns by weighing up principal has become a hot topic in recent years, and exploring the question also provides a window into how to make analyses and predictions about investment [2]. We propose a quantitative prediction model based on a neural network to make investment decisions with limited capital. The model needs to be scientific in nature, able to give reasonable predictions beforehand from previous data and make scientific strategies. It should have a clear advantage over other models that solve this type of problem. Secondly, the model should be built to be stable, applicable to a wide range of problems, and able to withstand perturbations in the data. Finally, the model should be built with timeliness and foresight, with the model predicting through the previous period of data, making daily recommendations for the next day's trading situation, and at the same time giving and predicting the future direction of investment for a period of time to maximize returns and avoid repeated trading.
Based on the previous analysis, the decision model we identified consists of a prediction model and a trading model. The data is first pre-processed, followed by forecasting using a bi-directional LSTM model. The trading model scores gold and bitcoin separately considering the bull and bear market and forecast price and risk, and makes a decision by comparing with the critical scores.

BiLSTM prediction model
The prediction of gold and bitcoin prices is a prerequisite for correct decision making [3]. In the prediction part, a bi-directional LSTM model is chosen, which takes into account the characteristics of the time distribution of gold and bitcoin prices in a deep learning architecture and introduces other characteristic variables to achieve higher prediction accuracy through data iterative training. The bi-directional network structure captures both forward and backward price movements, making it more sensitive to price movements and meeting the need for more accurate price forecasting [4].
The earliest Artificial Neural Networks (ANN) were used for traffic flow forecasting, but their simple network structure had limitations in processing longer time series data [5]. As the prediction time step increases, the problem of gradient explosion and disappearance occurs during error back propagation, making it difficult to capture the characteristics of long time series data [6]. The Long Short Term Memory Network (LSTM) is an improvement on the traditional RNN network consisting of an input layer, a recursive hidden layer and an output layer. Its states are divided into two vectors: a hidden state h that deals with short-term information and a unitary state c that deals with long-term information and is used to control the updating of memory information, allowing for more accurate modeling of time series data where there are long-term and short-term dependencies [7].
The forgetting gate, the most critical component of the LSTM network, controls the retention of important sequence state information and the forgetting of minor information by calculating weight values, thus effectively avoiding gradient explosion and disappearance problems during the processing of long sequences and allowing important state information to be retained during multiple passes. The input gate controls how much of the new information currently available through computation can flow into the memory cell state. First the current sequence of information is fed into the sigma neural layer to determine which information needs to be updated, next the cell state information discarded by the forgetting gate is added to the current information that needs to be added to make up the new cell state under the current sequence [8]. Finally, the output gate decides which information of the current state needs to be exported to control the cell state.
Based on the unidirectional LSTM, a bi-directional LSTM as Figure 1 network is formed by superimposing the top and bottom inversions. The model input contains the time series before and after, which enables the processing of both forward and reverse time series data. The bi-directional LSTM network has proven to be more accurate for speech analysis, sentiment analysis and air pollution prediction. In contrast to predictions based solely on information from the forward time period, in the actual Bitcoin and gold price datasets, changes in data characteristics in the backward time period can also influence the model output in the current time period. The bi-directional structure of the BiLSTM captures both forward and backward time periods, allowing for more comprehensive learning of the interrelationships between variables during model training and more accurate prediction results.

Development of model
In this section, a gold and bitcoin prediction model based on BiLSTM network is constructed, the structure is shown in Figure 2. To make full use of the previous price rise and fall and time attributes to consider the impact of relevant feature variables on gold and bitcoin prices comprehensively, they are import into the model. Where the time attribute is obtained by data formatting through the time in the dataset, containing whether it is a working day or some specific date with adjusting on price. Next, the resulting BiLSTM network is trained, and finally the data from the previous date is imported into the trained network to export the prediction results.

Training of model
In the part of model training, it is worth noting that the training set is gradually supplemented by the initial 60 sets of data to continuously improve the model matching [9]. Compared with the direct application of the entire data set, this method is less efficient, but the prediction for each day is based on the previous data similar to the actual situation, so our proposed training model is more realistic. The detailed Algorithm of BiLSTM and training process are shown in Figure 3.

Development of model
In this section, we have developed a trading model that uses the holding score as the basis for evaluation, taking into account the growth rate and risk level to give a quantitative evaluation, from which a critical score can be further selected and a scientific strategy can be made based on, as shown in the Figure 5. The holding score is calculated by. Then, based on the data predicting model, we calculate the current share and share of gold investment and Bitcoin investment, the change rate of total assets, and the profits of gold and Bitcoin. At the same time, we predict the share of gold and Bitcoin in the future, as well as the total assets and rate of change. Next, the above parameters are normalized, using the normalization formula.

Judgment of bull and bear market
In this section, we forecast the price movements of gold and bitcoin, which are commonly referred to as bull and bear markets. The evaluation is judged by indicators, and we choose the most matching parameters, set up a parameter calculation formula, and evaluate the bull and bear markets by comparing the average value of the evaluation indicators. Greater than the average value indicates a bull market and less than means a bear market.
The calculating equation. Analysis and scoring for GOLD and BTC bull and bear market is shown in Figure 6.

Prediction of risk
Continuously, risk is predicted by calculating the risk score following the equation.
The results are shown in the figure Figure 7.

Establishing evaluation indicators
According to the scoring equation, we calculated the holding scores for each day separately, as well as the corresponding holding amounts [10]. As shown, the upper troughs are bought and the peaks are sold, and the score and holding amount graphs maintain opposite trends.
Holding score and shareholding prediction and Holding score comparison are shown in Figure 8 and Figure 9.

Define trading strategies
We first normalized the scoring data to obtain a continuous curve without abrupt crossings. In case a value is too large and affects other results, remove the maximum value and reset it to 1 after normalization. Then obtained critical scores by plotting scatter plots comparing the shareholding of gold and bitcoin holdings at different points in time, which in turn led to the development of a trading strategy. Gold score is greater than 0.58 buy and less than 0.3 sell, bitcoin score is greater than 0.71 buy and less than 0.56 sell. When bitcoin and gold can be bought at the same time, if the judgment formula is true then buy gold, vice versa buy bitcoin.
By the strategy, the final returns, which are shown in the Figure 10.

Conclusion
In this paper, the data is first preprocessed, followed by prediction using BiLSTM, and the prediction results are imported into the trading model for decision making. The decision model we build achieves accurate prediction, timely grasp of price rise and fall as well as timely assessment of risk, and makes scientific decisions taking these factors into account. The advantages of our model are first and foremost in its accurate forecasting and scientific decision making. Our model integrates more indicators and factors to find a balanced and optimal solution among multiple parameters. Besides, the adaptation of the neural network brings more stable performance to the system, which gives investors more effective investment guidance advice in practical applications. Another advantage of the model is that it has enough sensitivity and stability to meet the needs of multiple scenarios. At the same time, the model can dynamically put the process of formulating the strategy to ensure a more flexible and accurate grasp for each point in time.
Since the data given in the question is limited and there are few influencing factors, the expansion of the model needs to rely on more data to complete. Figure 11 is the component of our model.