Intelligent optimal investment strategy model based on LSTM

. This paper proposes a trade planning model based on deep learning, which aims to help investors make decisions on how to make trade choices every day. Firstly, we establish a value prediction model to predict the future prices of gold and bitcoin. We use the LSTM model as the basis to extract the historical semantics and context information of the price curve to help investors predict the possible price trend in the next few days. We will re predict the historical price with the trained model and compare it with the historical price curve. Then, we establish a daily trade strategy model, which can accurately guide investors how to deal with their capital every day. According to the existing market rules and general assumptions, we propose the expression of daily fund holding, and give the corresponding constraint condition. Through our calculation and planning, we can obtain the income of 194283 dollars on September 10, 2021. The calculation results of some dates are shown in table below. The model we established in this paper is simple, easy to be popularized, reasonable and practical. It has good robustness and generalization ability in the face of new data sets.


Introduction
The history of quantitative investment can be traced back to the early 20th century. As early as 1900, Louis Bachellier has studied and analyzed the stock market trading data in Paris over the years and came to the conclusion that the trading behavior of assets is related to the expected stock price. His research results not only opened the prelude to quantitative investment in this industry, but also provided a lot of help for subsequent research work. As a traditional general equivalent, gold is a regular customer in asset allocation. As an emerging virtual currency, bitcoin also provides investors with new investment channels. Reasonable formulation of trade strategy cannot only effectively help fund managers avoid risks and reduce the loss of subjective judgment, but also help researchers calculate investment income and refer to future investment direction.

Model Establishment
According to the requirements of the topic, we need to predict the price of tomorrow according to the price data of gold and bitcoin up to now. This is a typical time series prediction problem. Therefore, our primary task is to find and reveal the law of phenomenon development and change through the analysis of these time series, and use these knowledge and information for prediction.
The mainstream methods of time series include grey prediction model, time series analysis model, LSTM neural network model and so on. LSTM is a special RNN model for time series prediction.

The Introduction Of LSTM
The traditional neural network has no memory function and only establishes the static relationship between input and output. Unable to capture time series information.
By adding a hidden layer, RNN can obtain the current output from the current input and the output of the previous time. However, RNN is sensitive to short-term input and difficult to capture longterm information. When the prediction point is far from the dependent relevant information, the gradient will disappear. In order to capture long-term and short-term information, LSTM introduces cellular state Memory ℎ . The internal structure is as follows: represents the weight of the function， represents the function offset， anℎ denotes the anℎ activation function. indicates that sigmoid processing is performed， Is to output a probability value within the range of (0, 1).

The Introduction Of Grey Forecasting Model
Grey system refers to the uncertain system that can be reflected by the sample data with some known information. Since the factors affecting gold and bitcoin prices are unknown, the problem can be solved by grey prediction model.
Grey system prediction is to explore the law of system change by distinguishing the similarity or dissimilarity (correlation analysis) of the development trend between system factors and generating and processing the original data. It establishes the corresponding differential equation model by generating the strong regularity of data sequence, so as to predict the future development trend of things.

Model Design
The overall design and processing flow chart of the model is as follows:

Figure 2. Flow Chart
Firstly, the standardized data is divided into training set and test set according to the relationship of 8:2. The training set is used to train the model and the test set is used to evaluate the quality of the model. After that, divide the time window, and finally determine that the gold time window is 3 and the bitcoin time window is 5 Use flow to generate a static calculation diagram. Then, initialize these parameters. These parameters can be divided into weight and deviation. All deviations are initialized to 0. This

EDMI 2022
Volume 21 (2022) 359 initialization can prevent the neural network from falling into local minimum to some extent. The gradient descent-based method Adam is used to optimize the loss function of neural network.
By observing the loss function of the verification set, we can evaluate the quality of the model. Specifically, if the monitored verification loss does not decrease in K periods, the training process is terminated.
It is worth noting that bitcoin and gold have different data characteristics. With the passage of time, the numerical variation range of bitcoin is large, so we use the loss function mean squared logarithmic error loss (MSLE) for model training. The variation range of gold data is appropriate, so the loss function mean squared error loss (MSE) commonly used in neural network is adopted. The two formulas are as follows: (1)

Data Preprocessing
Firstly, the data of the two spreadsheets are preprocessed. For missing data, we use the average method before and after filling.
In order to better train the neural network and give full play to the advantages of gradient descent method, normalization is adopted according to the maximum and minimum values. The basic formula is as follows: Where min is the minimum value in the time series data and ax is the maximum value in the time series data.

Model Solution
As we all know, neural network is a black box model. We can't know its specific physical model. We can only get the output from the input, so the optimization of its model super parameters is very important and difficult.
There are three main methods of neural network superparameter Optimization: Bayesian optimization algorithm estimates and updates the Gaussian process through sample points, and extracts functions to guide new sampling. Grid search algorithm divides each parameter into effective range, and then simply let the computer cycle to obtain the combination of parameters and calculate the results. The random search algorithm uses the random combination of parameters and looks for the optimized parameters. In order to find the optimal model in the shortest possible running time, we use the grid search algorithm in this paper. The first mock exam is the same as the 10 data model.
The final superparameter results are as follows: Batch-size indicates the size of small batch data, Epochs indicates the number of iterative learning, Hidden-layer indicates the number of hidden layers, and LSTM-unit indicates the number of neurons in LSTM layer.

Quantitative Investment Strategy
According to the title statement, on the trading day, we have all the data before that day. Now we hope to find a reasonable quantitative trading strategy to ensure that the total amount of assets owned on the last trading day is maximized and has a small risk coefficient Tomorrow, we will add today's data to the historical data and make a backward prediction again This dynamic process is a typical dynamic programming process. We specify today's adjustment strategy through the previous prediction results, and then carry out recursion until the last day.

Value of assets actually owned on that day (unit: USD) Dollar (t)
According to the description in the title, we designed a three-dimensional vector similar to the asset status Dollar(t) = f(R(t), (G(t),B(t))), After a certain investment strategy function, this threedimensional vector finally obtains the current asset status on that day. Dollar(t) Represents the dollar assets actually owned on day t. So there is the following function expression: In the formula, G (t) represents the grams of gold invested and held, and B(t) represents the number of bitcoins invested and held.
2. Predicted value shock ias ( ) We set two variations ias ( ) and ias ( ) represents the predicted value fluctuation change of gold and bitcoin in the market every day. Their expressions are as follows: The above two expressions are used to evaluate the risk coefficient and value return of the investment, that is, the predicted profit on day t is calculated through the predicted data on the next day. Therefore, we use the predicted value of gold on the next day and the shock value on that day, as well as the predicted price of bitcoin and the shock value on that day for subsequent analysis.
3. Operation strategy We use ( ) and ( ) two variables to represent the operation decision variables of gold and bitcoin on day t, and their expressions are as follows: (5) We use the information given by the quantitative trading strategy model to calculate the daily value of the trading decision variable. In the formula, 1 means to buy gold or bitcoin, 0 means not to buy or sell, i.e. hold, -1 means to sell gold or bitcoin. In addition, we note that gold cannot be traded on holidays, so the operation decision variables of gold during holidays are marked as 0.

Model Establishment
Below are the construction of quantitative investment strategy model based on dynamic programming.
We assume that the number of gold operation transactions is X Yuan and the number of bitcoin operation transactions is n yuan, which is the transaction that occurs on day T. according to the basic assumptions of this paper, since a certain commission will be charged every time we buy or sell gold or bitcoin, we also deduct the Commission of transaction loss from all assets, Therefore, after buying or selling gold and bitcoin on the same day, the situation of the last real asset dollar is as follows: In the above expression, ( ) − ( ) • − ( ) • represents the remaining available cash flow after the operation on day t. Combined with the predicted value of day t + 1 predicted by the LSTM prediction model, we can calculate the net profit Δ that can be obtained after the operation of the day, and the expression is as follows: To sum up, we take the maximum and isolated returns that can be obtained during daily trading as the target constructor axΔ .
In addition to the quantitative investment operation, it is also necessary to consider that there are some constraints that can not be ignored during the operation of the model, as shown below: 1. The number of gold and bitcoin bought or sold cannot be negative, so the following inequality is obtained: (8) 2. In order to ensure that our investment has a certain low risk, high yield and operability, our disposable cash should be kept positive, so we have: In this formula, in order to have a surplus of operable funds after the operation on the same day and the operation on the next day, we can make a sustainable distribution of subsequent assets, where ( ) and ( ) represents the operation decisions of gold and bitcoin respectively. 3. No matter what operation is carried out on that day, the shares held by gold and bitcoin must be greater than 0, as shown below: (10)

Model Solution
According to the LSTM prediction results we used, the following table is made: Finally, the specific trading operations and assets of our dynamic programming quantitative investment plan are shown in the table below. After the quantitative investment from 9/11/16 to 9/10/21, our total assets are: $194,283.

Conclusion
Good price forecasting is the primary key task of investment decision-making. Therefore, we have established a value prediction model based on LSTM to predict the future prices of gold and bitcoin. This model is a cutting-edge technology for this problem and has played an excellent role in many trading markets.
It can be seen from the results that we finally controlled the errors of gold and Bitcoin to be 2.9% and 4.7% respectively.
We then built a daily trading strategy model that can be used to guide you precisely on what to do with your capital on a daily basis. According to the existing market laws and general assumptions, we propose an expression X for daily capital holdings, and give the corresponding constraints X-X. After our calculation and planning, according to our investment strategy, the income you can obtain on September 10, 2021 is $194,283.