0% found this document useful (0 votes)
7 views8 pages

Provide Bitcoins Daily Optimal Trading Strategy B

This document presents a model for developing an optimal daily trading strategy for Bitcoin using an LSTM neural network based on historical price data. The model aims to maximize returns while considering trading constraints and costs associated with Bitcoin and gold. The results indicate that the LSTM model outperforms traditional methods in predicting price trends and constructing effective trading strategies.

Uploaded by

umaraslam9t9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Provide Bitcoins Daily Optimal Trading Strategy B

This document presents a model for developing an optimal daily trading strategy for Bitcoin using an LSTM neural network based on historical price data. The model aims to maximize returns while considering trading constraints and costs associated with Bitcoin and gold. The results indicate that the LSTM model outperforms traditional methods in predicting price trends and constructing effective trading strategies.

Uploaded by

umaraslam9t9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Highlights in Business, Economics and Management FTMM 2022

Volume 5 (2023)

Provide Bitcoin's daily optimal trading strategy based on LSTM


Songze Li1, *, Yixuan Zhang2, a, Xueli Dong1, b
1Institute of Science, China University of Petroleum(East China), Qingdao, Shandong, 266580
2College of Oceanographyand Space Informatics, China University of Petroleum(East China),
Qingdao, Shandong, 266580
* Corresponding Author Email: [email protected], [email protected],
b
[email protected]

Abstract. The purpose of this report is to develop a model that gives the best daily trading strategy
based only on the price data before the day. We want to provide traders with strategies that will
enable them to maximize their returns.we first utilize the LSTM time series neural network model
using the first 956 data sets are used for training , and the subsequent 300 test sets are used to
evaluate the model accuracy, calculate the prediction error and word comparison plots, and assess
the difference between the prediction performance of the model and the actual value,This method
has a better credibility. Finally, based on this model, we construct the optimal trading strategy model
with the maximum value of total assets held as the objective function, add constraints, and finally
arrive at an investment value of $1000.
Keywords: optimal trading strategy model; LSTM; BP; investment risk model.

1. Introduction
With the increase of per capital disposable income, people's financial awareness is growing, and
market traders often trade volatile assets to achieve the goal of maximizing total return, and how to
achieve this goal has been a key concern for people from all walks of life. As the application of
advanced mathematical theories and financial ideas has become more sophisticated, people have
gradually diversified their single trading capital, until now, the two main assets are gold and bitcoin.
According to statistics, 90% of day traders lose 90% of their capital within the first 90 days of
trading; 40% of traders will blow up their positions in less than 1 month, and only 13% will survive
after 3 years. As you can see, maximizing profit is not simple to achieve. Therefore, it is essential for
market traders, as the master of futures trading, to have a considerable strategy for analyzing price
fluctuations, buying and selling assets, and trading on a daily basis in order to make it possible to
maximize short-term profits. Therefore, it is particularly important to determine the trading strategy
to buy, hold or sell the trader's assets.
Give the best daily trading strategy and model based on the price data of the day, combine the
historical price float data and predict the future market trend. Considering the problems caused by
two different properties of capital, gold and bitcoin, for example, bitcoin can be traded daily but gold
can only be traded on days when the market is open, we have to make some adjustments to the trading
strategy.
we constructed a time prediction model to forecast two price series and make decisions about
trading based on future ups and downs by constructing a long and short term time series neural
network LSTM and a BP neural network time prediction to compare the prediction effect of both and
select the best strategy. We constructed and simulated a time prediction model of the stock closing
price direction based on the RBF neural network and time prediction model, and made some
adjustments using the BP neural network. With the adjusted model, we plotted the graphs of the
weighted average price of the five-day, ten-day, and twenty-day closing prices of the stock with the
help of the daily average manipulation method, which we used to predict the optimal way to trade
gold and bitcoin. Then, we initially determine whether to trade based on the distance between the
stock price and the five-day line, as there is a certain commission for each trade, and then substitute
the trading commission based on the model to finally give the best daily trading strategy. In contrast,

645
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

the long-short time series neural network LSTM forecasting model builds a nonlinear model that
allows for large nonlinear complex forecasting. Comparing the two, it is easy to see that the LSTM
possesses better prediction results, so we choose the LSTM model to determine the value of the initial
$1,000 investment on September 10, 2021.

Fig 1 Work Overview

2. Data pre-processing
The original data is integrated and cleaned, the missing data is completed, the bitcoin and gold
tables are combined, and the gold non-trading day data is completed, and the data is normalized.
As the data for Bitcoin and Gold are from the real world, there are inevitably a number of
anomalies, and by looking at the graph? Therefore, before constructing the LSTM prediction model,
we need to decompose the linear and nonlinear parts of the data, filter, smooth, and use the difference
method to deal with missing values and other operations, which will help to eliminate or repair the
outliers and improve the prediction accuracy of the model.

Fig 2 Data Cleaning for Bitcoin

646
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

For the processed data we normalize and use the first 956 sets of data to construct the LSTM time
series neural network prediction model and participate in network training, and the second 300 test
sets are used to evaluate the model accuracy.

3. LSTM model
3.1. Data description
The LSTM model is a special recurrent neural network model (RNN) with good support for long-
term dependence, and the core of the model is the state of the cell and the gate structure in it. The cell
state refers to the horizontal line running through the top with only a few linear interactions, and the
information is easier to keep constant on top, which is also very beneficial for us to predict the closing
price of this question, while the gate structure refers to the ability to remove or add information to the
cell structure, containing the sigmoid layer and tanh layer, and this structure has an important role in
our prediction of the closing price, see the figure 6 below for the specific model structure. The general
flow of the model is that after the input is trained to obtain four states:
𝑍𝑓 = 𝜎(𝑊𝑓 [ℎ𝑡−1 , 𝑥𝑡 ] + 𝑏𝑓 )
𝑍𝑖 = 𝜎(𝑊𝑖 [ℎ𝑡−1 , 𝑥𝑡 ] + 𝑏𝑖 )
𝑍 = 𝑡𝑎𝑛ℎ( 𝑊[ℎ𝑡−1 , 𝑥𝑡 ] + 𝑏)
𝑍𝑜 = 𝜎(𝑊𝑜 [ℎ𝑡−1 , 𝑥𝑡 ] + 𝑏𝑜 )
The output 𝑦𝑡 is obtained after the gate structure is operated,
𝑐𝑡 = 𝑍𝑓 ⊙ 𝐶𝑡−1 + 𝑍𝑖 ⊙ 𝑍
ℎ𝑡 = 𝑍𝑜 ⊙ 𝑡𝑎𝑛ℎ (𝑐𝑡 )
𝑦𝑡 = 𝜎(𝑊𝑦 ℎ𝑡 )
The flow is shown in figure 3 .

Fig 3 Structure Diagram


For this problem, we construct an LSTM model to predict the closing price for the next 1 unit of
time based on the closing price for the previous N units of time.
First, the data set is transformed into a three-dimensional array for input into the LSTM model,
tanh(x) is used as the activation function, linear is used as a fully connected artificial neural network,
each layer of the network node A is set, the error is calculated by MSE, the weight parameters are
iterated using the RMS prop algorithm, and finally the number of training iterations (epoch) and step
size (batch size) are determined, and the training set is used to predict the future price after the training
is completed.

647
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

Fig 4 Process Diagram


3.2. Model construction
Theoretically, the future price trends of gold and bitcoin can be predicted, but there are many
factors that affect their prices, and so far, their effects on prices cannot be clearly defined, because
price prediction is highly nonlinear, which requires prediction models to be able to handle nonlinear
problems, and, stocks have the characteristics of time series, so it is suitable to use recurrent neural
networks, for stock forecasting. Although recurrent neural networks (RNN), allow the persistence of
information, however, the general RNN models are weak in portraying time series data possessing
long memory, and in case the time series are too long, because of the presence of gradient dissipation
and gradient explosion phenomena RNN training becomes very difficult. Hochreiter and
Schmidhuber proposed a long and short-term memory LSTM model based on the RNN structure,
thus solving the problem that the RNN model cannot portray the long memory of time series.
By integrating and cleaning the existing data and normalizing them, we use the first 956 data sets
for training and constructing the LSTM model, and the subsequent 300 test sets are used to evaluate
the model accuracy, calculate the prediction error and the word comparison graph, and assess the
difference between the prediction performance of the model and the actual value.

Fig 5 Training Progress Chart


After 9600 iterations, we can see that the RMSE tends to be close to 0, which shows the high
accuracy of the LSTM training, while the loss is close to 0, which indicates that the training effect of
the model performs well, and the model can be used to predict how Bitcoin and gold will move in the

648
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

time dimension, providing a theoretical basis for the subsequent construction of the best strategy
model.
Using the results shown above can be seen, black is the original data, Figure 1 red is the test data,
Figure 2 red is the data after training and then prediction, we can see that our approximate trend is
very consistent, there are some places where the peak prediction is not enough, but the overall effect
is quite good, and can be used for gold and bitcoin future trend prediction.

Figure 6 Training set

Figure 7 Testing set

4. Best Trading Strategy Model


In the process of asset trading, people often model the optimal trading strategy based on the daily
closing price change curve in order to get a more reasonable trading strategy.
For the five-year trading market from September 11, 2016 to September 10, 2021, we find that
building a decision model with a highly targeted objective function and multiple constraints based on
the daily closing price change curve can be effective for risk-averse investment and optimal returns.
Building the optimal trading strategy model has the advantages of simplicity, ease of operation,
tradability and risk aversion.
The model is designed to give the best daily trading strategy to obtain the maximum return, and to
solve this problem, we use the maximum value of total assets held as the objective function. For a
total trading period of five years from September 11, 2016 to September 10, 2021, bitcoin can be
traded daily, but gold is only traded on days when the market is open, and the commission cost per
trade for gold and bitcoin is 1% and 2%, respectively, so the following objective function is
established:

649
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

𝑚𝑎𝑥𝑌𝑖 = 𝑊𝑖 × 𝜂𝑖 + 𝑄𝑖 × 𝛾𝑖
The constraint is as follows:
The daily investment amount should not be greater than the amount of all available investments,
the initial state is [1000,0,0], and the transaction cost per transaction (buy or sell) is a% of the
transaction amount, where gold a=1 and bitcoin a=2. Then for $1000, buy or sell, the only amount of
transactions we actually make is $940.
940, 𝑖=1
𝑍𝑖 = {
𝑌𝑖 , 𝑖 = 2,3,4. . .

The two asset weights should not be greater than 1.


𝑊𝑖 + 𝑄𝑖 < 1

The predicted tomorrow's gold price / today's gold price - 1 should be greater than 0.01 commission
(𝑥𝑖+1 /𝑥𝑖 ) − 1 > 0.01 × 𝑎%

Predicted tomorrow's bitcoin price / today's bitcoin price -1 to be greater than 0.01 commission
(𝑦𝑖+1 /𝑦𝑖 ) − 1 > 0.01 × 𝑎%

Gold is only traded on open market days


𝑥, 𝑖 = Market Trading Day
𝑥𝑖 = { 𝑖
𝑥𝑖−1 , 𝑖 = Non-market trading days

In summary, the single-objective optimization model of the problem is obtained as follows:


940, 𝑖=1
𝑍𝑖 = {
𝑌𝑖 , 𝑖 = 2,3,4. . .
𝑊𝑖 + 𝑄𝑖 < 1
(𝑥𝑖+1 /𝑥𝑖 ) − 1 > 0.01 × 𝑎%
(𝑦𝑖+1 /𝑦𝑖 ) − 1 > 0.01 × 𝑎%
𝑥, 𝑖 = Market Trading Day
𝑥 ={ 𝑖
{ 𝑖 𝑥𝑖−1 , 𝑖 = Non-market trading days
𝑚𝑎𝑥𝑌𝑖 = 𝑊𝑖 × 𝜂𝑖 + 𝑄𝑖 × 𝛾𝑖
Based on the above objective function, we use Lingo programming, combined with the LSTM
prediction model, to find the maximum value of the assets held, (in USD) as shown in the following
table.
Table 1: Results Show
Bitcoin Gold Bitcoin Gold Bitcoin Gold Total
price price increase increase holdings Holdings Assets
2016/9/12 609.67 1324.6 0.39% 0.29% 503.2 500.0 1237.71
2016/9/13 610.92 1323.65 0.10% 0.14% 519.5 499.37 1253.88
2016/9/14 608.82 1321.75 0.15% 0.56% 526.5 498.50 1266.23
2016/9/15 610.38 1310.8 -0.23% 0.09% 547.3 493.30 1279.33
2016/9/16 609.11 1308.35 0.81% 0.04% 551.4 491.81 1292.26
... ... ... ... ... ... ... ...
2019/5/28 8716.3 1899.95 -0.43% 0.48% 78422.7 0.000018 80827.34

Based on the results in the table above, the value of the initial $1,000 investment on September 10,
2021 is derived as $80827.34.

650
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

5. Sensitivity analysis
We conducted sensitivity analysis on the MSE values and the gradient of the predicted data, and
from the figure, we can see that the training accuracy is very high during the 50,000 training sessions,
and the mean square error value shows a decreasing trend as the number of training sessions increases.
For the gradient plot, we can see that the training gradient reaches a very considerable level during
50,000 training sessions, which positively reflects the stability of the deep learning prediction data.
We set the initial gold value as N and the initial allocation value of bitcoin as 1000-N,iterate N
from 1 to 1000 with a step size of 10 to get the initial gold value in the third step, and use the line
graph of the initial gold value versus the total asset value after five years to observe why N is smoother
at times and analyze the transaction cost sensitivity of the trading best strategy model.

Fig 8 Sensitivity Analysis Chart

6. Model Evaluation and Further Discussion


Before building the model, we normalized the raw data to make the machine learning used in the
problem solving have more powerful learning ability.
During the model building process, we considered the investment risk problem and built an
investment risk multi-objective planning model with maximizing investment utility and minimizing
risk value, and introduced several indicators, such as goods increase, investment share, investment
risk, holding share, and asset change rate, to improve the prediction accuracy.
After building the model for prediction, we verified the reasonableness and feasibility of the
prediction results by linear regression and gradient display.
But in the LSTM model, we found that the prediction trend is approximately the same, but there
is an error in the peak value, and there is a lag in the real predicted data, which looks like the original
data is shifted backward by one day.
As a good trader, we need to have a good grasp of market laws and financial knowledge to react
to different situations of market trends.
We first used the LSTM model to predict the market closing price, and then adjusted the training
results by RBF algorithm and BP algorithm to make the results very close to the real value.
We then used the five-day, ten-day and twenty-day averages to determine whether to trade or not,
and simulated how to trade in the presence of commissions in order to maximize the profit. We
verified the sensitivity of trading costs to trading results by varying the costs continuously through
theoretical analysis and numerical simulation methods.

References
[1] Wang Huiying, HAO Yongtao. Modern Computers, 201,27(27):43-47+52.]

651
Highlights in Business, Economics and Management FTMM 2022
Volume 5 (2023)

[2] Yao Haixiang, Li Junwei, Xia Shenghao, Chen Shumin. Fuzzy Transaction Decision Based on Apriori
Algorithm and Neural Network [J]. Journal of Systems Science and Mathematics, 201,41(10):2868-2891.
[3] Liu Lijun, LIANG Guopeng, Wang Haitao. Research on quantitative Trading Strategy System Model [J].
Shanghai Commerce,2021(09):158-159.]
[4] Peng Yaqi. price prediction and option strategy of sse 50ETF based on ga-lstm [D]. Northwestern
University,2021.
[5] Li Y. Research on community division and quantitative trading strategy of securities business Department
based on trading public information [D]. University of Electronic Science and Technology of China,2021.
[6] Wang Mengtian. Research on Futures Price Trend Prediction and Quantitative Trading Strategy based on
Machine Learning [D]. Nanjing University of Finance and Economics,2021.
[7] Xian Jing. Quantitative Trading strategy of A-shares based on KNN algorithm [J]. Bohai sea economic
outlook, 2020 (01) : 153. DOI: 10.16457 / j.carol carroll nki HBHJJLW. 2020.01.105.
[8] wang tong. Research on Quantitative Trading Strategy based on EMV Index in China's A-share Market
[J]. Tax, 2020, 14 (01) : 199.
[9] Lin Fuquan, XUE Xinbei. A study on the application of a homeopathic moving average strategy in China
sse 50ETF index fund [J]. Journal of hubei university of economics (humanities and social
sciences),2019,16(12):31-36.
[10] Wang Chenyang. Research on the effectiveness of trend investment in Shanghai and Shenzhen A-share
market: Based on moving average strategy [J]. Commercial economy, 2019 (9) : 178-180. the DOI:
10.19905 / j.carol carroll nki syjj1982.2019.09.066.
[11] He Qi-xiang, Ma Yu-Tong. Under different trading strategies, the classification of commodity futures risk
premium research [J]. Journal of management engineering, 2019 (3) : 52-60. doi: 10.13587 / j.carol carroll
nki jieem. 2019.03.007.

652

You might also like