Research on Quantitative Trading Model

. With the rapid development of data science, quantitative trading models have become prevalent in financial markets. Based on Apriori algorithm, we analyze the rise characteristics of gold and bitcoin. Based on the principle of financial investment, BiLSTM with attention mechanism and VaR, the transaction decision model was established. We also establish a exponential model to identify how much money should be invested each time. Simultaneously, we apply a modified greedy algorithm to decide our investing decisions and it turns out to be quiet successful. Generally, the trading model established in this paper has good sensitivity to adapt to market changes and has strong risk resistance.


Introduction
In recent years, quantitative investment has gradually become prevalent. Quantitative investment has been widely used in Europe and American countries for more than 30 years and its investment performance is stable. So far, more and more traders have recognized the importance of quantitative trading models. Quantitative trading refers to the transaction that takes a large number of investmentrelated data as a sample, establishes appropriate mathematical models and formulas in a quantitative way, writes efficient programs using computer technology, studies and analyze the future returns and risks of financial products, judge various market trends and issue buying and selling instructions to realize investment [1]. Market transactions often buy and sell volatile assets with the goal to maximize their total returns. Quantitative transactions have the advantages of high computational efficiency, strong discipline, high return probability, and rapid analysis and optimization process. Using quantitative trading models can help investors make better decisions.
In order to establish a reasonable model, we first analyzed and processed the pricing data of gold and bitcoin. Then, based on the Apriori algorithm, we analyze the distribution of the consecutive rise or fall times of gold and bitcoin. After fully understanding the characteristics of gold and bitcoin as short-term financial products, we established a trading strategy model. Our trading strategy model mainly consists of two parts, one is the forecasting model based on BiLSTM, the other is the position management model in the form of index based on the short-term financial market investment law of financial market. At last, we use the greedy algorithm, VaR and adjusted the transaction costs to prove the optimal.

Prediction model
As shown in Figure 1, assuming that when the given window size is 100, taking 1 as the step, we divide the historical series into multiple price series for prediction In the real prediction process, the window size needs to be set according to the actual situation, and all the data will be used to train the prediction model. Bi-directional long short-term memory (BiLSTM) is a classical model of recurrent neural network [2]. As an outstanding variant of LSTM [3], it can be competent for generation, prediction, classification and other work, and is widely used in natural language processing, computer vision, data mining and other fields. Figure 2 shows the structure of a LSTM cell, where , , represent the forgetting gate, input gate and output gate respectively. The forgetting gate indicates how much information is retained at the last time, the input gate indicates how much information is retained, and the output gate indicates how much information is output. The calculation process of LSTM can be summarized as forgetting and memorizing the information in and ̃ by controlling three gates, so that the key information can be retained in the subsequent calculation. Attention mechanism [4] is used by human beings in processing information, which was born from cognitive science. Its mathematical expression can be expressed as: where ( , ) indicates the attention scoring mechanism, this paper adopts the commonly used point product model. is called attention distribution. In the mathematical sense, ( , ) is a kind of weighted average of information, which can be interpreted as the degree of attention of different information in context query q.  Figure 3 shows the structure of our prediction model. Based on the previous explanation of LSTM model, the prediction model in this paper actually transmits the relationship between prices in different time periods through the input price sequence, and provides back propagation to optimize various parameters in the model by outputting a result and the real value. The measurement method of the model in this paper is that the loss in the neural network is MAE.
In order to prevent over-fitting of the model, which means excellent prediction performance in training data but poor performance in practical application, we use the Dropout layer to ignore 20% of each incoming data. Meanwhile, the training data is randomly arranged in advance to avoid the characteristics observed by the model when the data is continuously entered. In addition, we chose a smaller batch size to avoid falling into sharp minima [5].
RMSprop is used as the activation function in this paper. Both RMSprop and Adam are commonly used activation functions in deep learning. Figure 4 shows the comparison of the price of Bitcoin in the last 200 days predicted by the BiLSTM model with the attention mechanism with the real data. Compared with LSTM model, gated recurrent unit (GRU) only modifies the gating mechanism [6]. As shown in Figure 5, it adopts a simpler gating scheme to accelerate the prediction speed. Autoregressive comprehensive moving average model (ARIMA) is a method commonly used in econometrics to process time series [7][8]. In this paper, we use Python's auto_arima library to complete price series prediction. Hidden Markov model (HMM) is a probability model about time series in the field of statistics [9]. In this paper, we use the Viterbi algorithm to calculate the state transition matrix based on the given data, and uses the dynamic programming algorithm to take the price sequence as the observation matrix and calculate the optimal path to get the predicted value.
XGBoost (extreme gradient boosting) [10] is an outstanding integrated learning model based on decision tree. In the prediction task, XGBoost takes the square error as the loss function and performs the first derivative and second derivative gradient descent through the second order Taylor expansion. At the same time, it reduces the amount of computation through random forest and uses regular terms to prevent overfitting. Holt-winters method is an effective method to predict trend and seasonal nonstationary series [11].
We select LSTM, GRU, BiLSTM, Holt-Winters, ARIMA, HMM, XGB (XGBoost) for comparison. We divide all price sequences into training sets and test sets in a 7:3 ratio, and test sets are strictly not involved in the training process. In order to ensure the fairness of the experiment, all parameters of the deep learning models are consistent, and the results of other models are debugged to the optimal solution. Table. 1 shows our experimental results. The experimental results show that our model is obviously better than other domain models. Figure 6 shows the prediction results of each model on the gold and Bitcoin datasets respectively. In short, BiLSTM with attention mechanism has a stronger ability to mine the potential semantics of price sequences, and its prediction effect is better than other models.

Position management model
According to the investment law, in order to establish a model, it is necessary to process data on the existing historical data, and count the pricing increase law of gold and bitcoin respectively. The continuous increase and fall law is an important basis for the formulation of scientific and reasonable investment strategies.
Data were performed on historical data given in MATLAB. The rise and fall of financial products can be expressed as: is the rise or fall degree， is the current price of financial products， −1 is the prices of the previous issue of financial products.
Using Apriori algorithm, the number of subsets of 2 consecutive, 3,4,5,6,..., j , represents the number of j consecutive rises, represents and the number of j consecutive drops. The number of all consecutive rises or falls above 90% is . The 90th percentile of all gains is 0.9，the 10th percentile of all declines was 0.1. Ideally, if each drop is the same, when the number of drops is ，Just down 0.1，Each decline will choose to add positions，If the next day the rise is 0.5 then can make a profit. The commission cost per transaction (sale) is a% of the transaction amount.
The amount of the first added position is 1 . The second add warehouse added amount is 2 . We The third add warehouse added amount is: When the number of positions is n，added the amount is: Using a linear regression model, the parameters were fitted to obtain the formula: If the maximum number of drops is x，the amount of each addition is: According to formula, we can get the gold rise curve and the rise curve of bitcoin, which is shown in Figure 7. Separating the rise and fall, and get the rise curve and fall curve of gold and bitcoin, which is shown in Figure 8.

Quantitative investment model and income analysis
The quantitative investment model consists of a predictive model and a position management model. Predictive model to determine when to trade, and position management model to determine the amount of investment. Invest according to the above strategies and rules to get the returns of gold and Bitcoin. The calculation eventually costs $646 for investing with $500 in gold, and investing bitcoin with $500 for $215487. The initial $1000 investment worth on 9/10/202 is $216133. The results is shown in Figure 9 and Figure 10. From Figure 9 and Figure 10, it can be seen that the return of investment on both gold and bitcoin is quiet ideal. The return of gold increases constantly with the moving of time. The return of bitcoin increases sharply in the last 500 days and the profit is really attractive. Further it is showed that the trading strategy constructed by this model strike a balance between short term interests and long term interests. At the same time, the model avoids certain transaction risks.
According to the results predicted by the LSTM neural network, the average predicted increase of gold is 0.43%, and the average predicted value of the increase is 0.41%. The initial transaction fee for this model is as high as 1%, which is much higher than average increasing rate. We set the value of transaction fee to be 0.2%,0.4%,0.6%,0.8%,1.0%,1.2% respectively. We put these values into the model and get the sensitivity between transaction fees and ultimate benefit of gold, which is shown in Figure 11. At the same time, the single-day value of bitcoin can increase by more than 20% at the highest, and the minimum decline is also more than 20%. From this, it can be seen that the variation range of the handling fee in Bitcoin transactions can be relatively large. Therefore, we set the value of transaction fee to be 1.5%,2%,2.5%,3%,3.5% respectively. We put these values into the model and get the the sensitivity between transaction fees and ultimate benefit of bitcoin, which is shown in Figure 12.

Conclusion
In this paper, multiple models are used for horizontal comparison to produce the optimal model. When considering the decision making, through the forecast of the next three days as trading conditions. We calculate VaR and apply it to the decision model to avoid the potential grey swan event in the market, so as to improve the risk resistance of the model. By comparing with econometrics, statistics, deep learning and other models, we can prove the accuracy of BiLSTM with attention mechanism in predicting the price of gold and bitcoin.