Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

2022 IEEE 2nd International Conference on Data Science and Computer Application (ICDSCA)

Research on the Quantitative Trading Strategy


Based on Bollinger Band Strategy and Polynomial
Regression Model
Yuhao Zheng* Xinyi Li Yuanjun Feng
School of Economics and School of Economics and School of Information Science and
Management Management Technology
2022 IEEE 2nd International Conference on Data Science and Computer Application (ICDSCA) | 978-1-6654-7200-5/22/$31.00 ©2022 IEEE | DOI: 10.1109/ICDSCA56264.2022.9988398

Beijing Forestry University Beijing Forestry University Beijing Forestry University


Beijing, 100089, China Beijing, 100089, China Beijing, 100089, China
zhengyuhao0422@126.com 13622353139@163.com 1341524165@qq.com
*Corresponding author

Abstract—First, this paper made time-price line charts for Markov method (HMM) to predict stock prices, Ballings. M
gold and bitcoin and analyzed their primary trend of flat-rising. et al.[4] uses the random forest algorithm to predict financial
Subsequently, we established the Bollinger Bands strategy and market trends, R. Soujanya et al.[5] used the linear regression
a regression polynomial combinatorial model in Python to make model to predict asset price change, with a significant effect.
the trade points precise. We import gold and bitcoin data into However, the data used in the above research are relatively
the model, respectively, and let it automatically perform extensive. The research data in this paper only use the price
graphing and data processing to obtain the fitting images, data of gold and Bitcoin, and the previous research studies the
optimal fitting times, model coefficient list, and model intercept price change trend of Bitcoin. This paper innovatively
of the gold and bitcoin PR models. Afterward, we determined
introduces the Bringband channel method and combines the
the trading conditions, stop-loss levels, and commissions and
used the Bollinger Bands strategy to backtest the five-year
regression polynomial, combination model.
trading to obtain the trading results of a single strategy. Based II. INTRODUCTION
on the conservative principle of risk hedging and split-position
trading, we reset the position distribution combined the The raw amount of data is large. We checked the data
Bollinger Bands strategy and the regression polynomial according to chronological order and found that the data is
combination model into a comprehensive model. This paper comprehensive and less missing values.
plotted the fluctuations of gold and bitcoin in the time dimension.
The comprehensive model shows the characteristics of high total The data preprocessing process of this paper is mainly
return, low total transaction cost, and small maximum carried out in two ways: data null value processing and data
drawdown, which proves that the comprehensive model standardization processing. The data for the two research
provides the best strategy. subjects in this paper are price data from September 11, 2016,
to September 10, 2021. Since Bitcoin is a digital virtual
Keywords—quantitative trading strategy, quantitative trading currency and can be traded daily, and gold trading is affected
strategy, polynomial regression model, the Bollinger bands by the international market shut down and will stop trading,
we think the discontinuity of the date of gold price data is
I. INTRODUCTION reasonable.
Traders generally sell riskier assets such as stocks to favor • Data null-value processing By examining the data given,
traditional safe-haven assets such as gold. "Bitcoin is a digital we found that the attached table "BCHAIN-MKPRU" was
virtual currency, compared with gold, Bitcoin yield, high complete, ten were missing in the USD (PM) column in the
volatility, and free from regulation and tax exemption, in the Table "LBMA- GOLD," and the rows corresponding to these
financial field has a huge development space, many investors ten null values were directly deleted, leaving 1256 lines of
think bitcoin is a new gold, can become a new haven asset, data.
complementary to gold to hedge."[1] For traders, their
investment goal is to maximize total returns. • Data standardization After processing the null values, we
normalized the data to facilitate further analysis of the data.
This paper is an article on daily trading decisions for gold The time-series format was not unified in the original data
and Bitcoin, designed to build a decision model that table. We adjusted the time format to the YYYY - MM - DD
maximizes the total return. We will build a Quantitative using the basic Excel table function skills.
Transaction Decision Model (QTDM) to determine the
optimal strategy in the time dimension to help traders achieve III. THE GOLD AND BITCOIN PR MODELS
the goal of maximizing returns. Meanwhile, we performed a
sensitivity analysis of this optimal strategy to the transaction A. The Bollinger Bands
cost to verify that the transaction cost has less impact on the "The Bollinger Bands is a non-heap analysis method
strategy yield. consisting of the upper, middle, and lower track lines,
representing the price pressure and the moving average
Early studies proposed a variety of quantitative trading
supporting the upper and lower track lines and the middle."[6]
models, Kong[2] proposed the concept and effectiveness of
To build The Bollinger Bands, we first used data processing
quantitative trading, Somani P and others [3] used the hidden

978-1-6654-7200-5/22/$31.00 ©2022 IEEE 1255 October 28-30, 2022 Dalian, China

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.
methods to handle the outlier null and ununified format data (2) Specifications of the road breakthrough trading
in the original dataset. After the outlier null data deletion strategy
process and the time data format, we obtained the accurate
data corresponding to the time price. By calling the pandas • Price curve down the Brbelt: buy signal.
library in Python, the data was removed, and we visualized the • Price curve upward through the Bollinger Bands on the
data using the matplotlib library. The results are as follows in rail: sell the signal.
Figure 1 and Figure 2.
• Price curve fluctuates between the Bollinger Bands:
position.
B. Build a regression polynomial combination model
(1) Call python' sklearn, numpy, pandas libraries for model
building. Build the gold polynomial model (Polynomial
Regression Gold Model, by using the gold price data), and fit
the original data to the model for n times to obtain the optimal
fitting number of times, model coefficient, and model
intercept of the gold PR model. The results are shown in the
following Figure 3.
Figure 1. Visualize the data using the matplotlib library.

Figure 2. Visualize the data using the matplotlib library.


Figure 3. Polynomial regression gold model.
Then, we start building strategies: This strategy consists of
three parts, and in this subsection, we will introduce the After multiple fitting experiments, the optimal number of
modeling idea of task one. In the first part, through The fits n = 6 of the gold model was found as in Figure 4.
Bollinger Bands index, the gold and bitcoin prices containing
the upper rail, the middle track, the lower track, and the
original data curve are made, respectively.
(1) Calculate The Bollinger Bands For the calculation
method of the Brin belt channel, as follows: Brin belt middle
rail: 20-day mean:

 ߤ௡ = σ௡௜ୀଵ ԝ ܲ݅  
௡ Figure 4. The optimal number of n=6.

It is the average of the first n period observed in phase t. The bitcoin polynomial model (Polynomial Regression
Bollinger Bands on rail: 20-day mean + a time 20-day Bitcoin Model) is established using bitcoin price data. The
standard deviation Phase t observed that the standard original data is fitted to the model for n times to obtain the
deviation of the stock price in the last n period was: optimal fitting number of times, model coefficient, and model
intercept of the bitcoin PR model. The results are shown in the
following Figure 5.

 ߪ௡ = ට σ௡௜ୀଵ ԝ (‫ ݅݌‬െ ߤ௡ )ଶ   

 ‫݌ݑܤ‬௡ = u୬ + ܽ × ߪ௡   

Bollinger Bands down rail: the 20-day mean-a times the


20-day standard deviation.

 ‫݊ݓ݋݀ܤ‬௡ = u୬ െ ܽ × ߪ௡   

(A indicates a multiple of the standard deviation)


According to the Bollinger Bands theory[7], the usual n Figure 5. Polynomial regression gold model.
values are 10,20,50, etc. By analyzing the volatility of bitcoin
and gold. n = 20, and set the initial a = 2. After multiple fitting experiments, the optimal number of
fits of the bitcoin model n = 11 as in Figure 6.

1256

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.
Figure 7. The following test of gold and Bitcoin.

The chart shows that gold in the strategy rose from $200
to $361.549649, and a total yield of 80.774824%, an
annualized yield of 20.193706%, maximum retracement of
Figure 6. The optimal number of n=11. 8.811874,29 total transactions, 55.172414%.
C. Establishment of the comprehensive model Bitcoin surged from $800 in initial funding to
The comprehensive model combines Bollinger Bands $4486.79834 with a total yield of 460.849792%, an
index and polynomial regression combination model, annualized yield of 115.212448%, and maximum retracement
including the optimal fitting number, model coefficient, and of 40.88216,33 transactions and a winning percentage of
model intercept, and automatically calculates the optimal 39.4%.
transaction time, transaction price, and income. Total proceeds from the strategy were $4,848.34,799.
D. Use, trading situation, and income calculation of the Because the ratio of gold to Bitcoin yield is: 80.774824%:
comprehensive model 460.849792%, about equal to 1:6, and the risk distribution is
(1) Determine trading conditions, stop losses, commission uneven, the initial proportion of the two available funds needs
to be changed and used to manage positions and risk hedging.
1) To calculate the final investment value, we need to
determine the funds available for gold and Bitcoin. Since the Set the initial available funds for gold and Bitcoin as 1:6,
purpose of quantitative trading is to maximize the long-term [C_gold, C_bit, G, B] = [1000 / 7,6000 / 7,0,0], and use the
and stable returns for gold and bitcoin, and the cumulative comprehensive model backtest to automatically mine the
yield can reflect the total yield obtained after starting trading optimal buying and selling points consistent with the strategy
in the entire trading period, we use the cumulative yield as one and model. The results are as follows in Figure 8.
of these indicators.
We calculate the cumulative yield of gold and Bitcoin and
compare them:
Gold: 2016 / 09 / 12 Price is: 1324.6; 2021 / 09 / 10 price
is: 1794.6. The cumulative yield of gold: 35.48241%. Bitcoin:
2016 / 09 / 11 price is: 621.65; 2021 / 09 / 10 price is: 46368 /
69. The cumulative yield of Bitcoin: 7358.97048%.
Figure 8. The strategy and model.
Data show that bitcoin buying and holding gains are high.
Therefore, we set up higher available funds for Bitcoin Pre-set The chart shows that the total yield of gold in the strategy
Initial Gold Transaction Available Funds: is 131.857458%, an annualized yield of 32.9643645%, a
Bitcoin Transaction Available Funds = 200:800, namely maximum retracement of 8.811874%, 22 total transactions
the initial [C_gold, C_bit, G, B] = [200,800,0,0] Set each buy, and a winning percentage of 68.182%.
sell for the full ware house trading. The total yield of bitcoin in this strategy is 823.524004 %,
2) Set the stop loss at 1 times the standard deviation below an annualized return of 205.881001%, a maximum
the purchase price: Stop-loss price = Buy Price-1* standard retracement of 16.394341%, a total of 26 transactions, and a
deviation winning rate of 50 %.

3) Gold trading commission is 1%, and Bitcoin transaction By comparing this model with the single Bollinger Bands
commission is: 2% strategy, we found that this model has good performance in
increasing total return, reducing maximum pullback, and
(2) Income calculation under a single Bollinger Bands increasing the winning rate.
index
IV. THE OPTIMAL VALIDATION
We used Python to traverse the daily price data with the
Bollinger Bands index to automatically calculate the A. Optimal stability of the indexes
automated trading gain value under a single a = 2 index. The "The cumulative return can reflect the total return over
following test of gold and Bitcoin shows the following results some time, but it cannot reflect the fluctuation of the return,
as in Figure 7. and its stability cannot be judged."[3] Therefore, we have
drawn a graph reflecting the price fluctuation, which can be
intuitively viewed in the time dimension to see how gold and
bitcoin prices fluctuate. The Bollinger Bands indicator relies
on large price fluctuations to generate income, so the strength

1257

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.
of volatility is an essential basis for measuring whether the the Bollinger Bands and whether it can track the upward trend
Bollinger Bands are influential, as in Figure 9 and Figure 10. in time).

Figure 12. Analyze the validity of the indicators.

Since the Bollinger Band cannot effectively wrap the price


Figure 9. Gold volatility. curve, excessive invalid transactions are formed, so a = 1 is
invalid, as in Figure 13.

Figure 10. Bitcoin volatility.


Figure 13. a = 1 is invalid.
As shown in the picture above, gold and bitcoin prices are
Because after a group of buying and selling transactions,
characterized by strong volatility. Therefore, the Bollinger the price curve has crossed the upper rail of the Bollinger
Bands indicator is the optimal one. Bands many times, so it cannot effectively track a strong
B. Optimal analysis of the a-values upward trend, so a = 1.5 is invalid, as in Figure 14.
Other conditions remain unchanged. We test the Bollinger
Bands with different a-values of gold and Bitcoin to find the
appropriate a-value to determine the appropriate number of
valid transactions (valid transactions: the number of buys and
sell is in the interval [10, 30] and the benefits are reasonable)
(1) First, test the different a-values of the gold Bollinger
Bands, and the a-values are 1, 1.5, 2, 2.5, 3, 3.5. The image is
analyzed from this: (1) First, the Bollinger Bands of gold are
tested with different a-values, and the values are 1,1.5,2,2.5,3
and 3.5. The images were analyzed as in Figure 11:
Figure 14. a = 1. 5 is invalid.

Figure 11. The Bollinger Bands of gold.


Figure 15. a = 2 is invalid.
Due to the characteristics of the Bollinger Bands indicator,
it is necessary to analyze the validity of the indicators on the The Bollinger Band has a good wrapping effect on the
six images, respectively, as shown in Figure 12(that is, to price curve. The intersection point between the upper and
judge the number of times the daily price penetrates and exits

1258

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.
lower rails of the Bollinger Band and the price curve is
extreme. The number of valid transactions is large, so a = 2 is
valid, as in Figure 15.
The Bollinger Band is too large, resulting in a part of the
price that does not cross the upper and lower bands of the
Bollinger Bands in time, and the number of valid transactions
decreases. Therefore, the effectiveness of a = 2.5 is lower than
that of a = 2. When a = 3, 3.5, the Bollinger Bandwidth further
increases, and the effective trade decreases further.
From this, it is reasonable to infer that a = 2 is the optimal Figure 19. a = 2 is invalid.
value of the Golden Bollinger Bands indicator.
Compared with a = 1.5, the effective transactions increase
(2) Test the Bollinger Bands of Bitcoin with different
significantly, and a = 2 is relatively effective, as in Figure 19.
values, and the values of a are 1, 1.5, 2, 2.5, 3, 3.5, as in Figure
16. The number of times the price curve crosses the upper
Bollinger Band is greatly reduced, indicating that buying
cannot be sold in time, so a = 2.5 is more ineffective than a =
2. When a = 3 or 3.5, the Bollinger Bandwidth further
increases, and the effective trade decreases further. It is
reasonable to infer that a = 2 is a better value for the Bitcoin
Bollinger Bands indicator.

Figure 16. Test the Bollinger Bands of Bitcoin.

Figure 20. Gold trading.

Figure 17. a = 1 is invalid.


Figure 21. Bitcoin trading.
The Bollinger Band is too narrow, there are too many
invalid transactions, and a = 1 is invalid, as in Figure 17. Based on the above description and data to judge the
effective transaction, as in Figure 20 and Figure 21. It is
concluded that: Gold Bollinger Band a = 2; Bitcoin Bollinger
Band a = 2.
C. Optimal analysis of mining times
Without changing other conditions, the number of
excavations was adjusted to obtain the following data:

Figure 18. a = 1.5 is invalid.

The transaction time of each buying and selling group is Figure 22. Gold trading.
too short of capturing higher selling prices and obtaining
higher returns, and a = 1.5 is invalid, as in Figure 18.

Figure 23. Bitcoin trading.

After data validation, when r = 100, the comprehensive

1259

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.
model has the best results, as in Figure 22 and Figure 23. regression polynomial combinatorial model in Python to make
the trade points precise. We import gold and bitcoin data into
D. Optimal analysis of comprehensive model the model, respectively, and let it automatically perform
When other conditions remain unchanged, in the case of graphing and data processing to obtain the fitting images,
the initial capital of 1:6, compare the trading results of the optimal fitting times, model coefficient list, and model
comprehensive model with the trading results of the single intercept of the gold and bitcoin PR models. Afterward, we
Bollinger Bands indicator as in Figure 24. determined the trading conditions, stop-loss levels, and
commissions and used the Bollinger Bands strategy to
backtest the five-year trading to obtain the trading results of a
single strategy. Based on the prudent principle of risk hedging
and split-position trading, we reset the position distribution,
combined the Bollinger Bands strategy and the regression
polynomial combination model into a comprehensive model,
passed in the obtained parameters, and finally got a list of the
best trading dates, harvesting 719.063463% the total return on
Figure 24. The trading results of the comprehensive model. the $1,000 initial investment was $8,190.63463 after five
years. We verified the optimal Bollinger Bands strategy,
The comprehensive model is shown in Figure 25. model coefficients, and the number of data mining to prove
that the model is optimal. Firstly, we plotted the fluctuations
of gold and bitcoin in the time dimension. The comprehensive
model shows the characteristics of high total return, low total
transaction cost, and small maximum drawdown, which
proves that the comprehensive model provides the best
strategy.
REFERENCES
[1] Ye Wuyi, Sun Liping, Miao Baiqi, "The dynamic cointegration study
Figure 25. Comprehensive model. of gold and Bitcoin —— is based on a semiparametric MIDAS locus
regression model," Systems Science and Mathematics, 2020,40 (07),
pp. 1270-1285.
The chart shows that compared with the single Bollinger
[2] Black FScholes M S, "The Pricing of Options and Corporate
Bands strategy, the gold and Bitcoin in the comprehensive Liabilitics," Journal of Political Economy,1973,81(3), pp. 637-654
model have higher yields, fewer transactions, significantly
[3] Ross,Stephen, "The arbitrage theory of capital asset pricing," Jounal of
lower Bitcoin maximum retracement, and significantly higher Economic Theory, 1976,13(3), pp. 341-360
total strategy returns, proving that the comprehensive model [4] Liqi Kong, "Application of Quantitative Investment Principles in
is superior. Market of Financial Derivatives," Scientific Journal of Economics and
Management Research2021.3(1).
V. CONCLUSION [5] BallingsMPoelD.VD, Hespeels.N, "Evaluating multiple classifiers for
It is a modeling problem to minimize transaction costs and stock price direction prediction," Expert Systems with Applications,
2015,42(20):7046-7056.
maximize returns. First, we made time-price line charts for
[6] Zhou Xu, "Application of Bollinger Bands Trend Breakthrough
gold and bitcoin and analyzed their basic trend of flat-rising. Strategy in the Digital Money Market," Zhejiang Industrial and
Subsequently, we established the Bollinger Bands strategy, Commercial University, 2021.
selected the 20-day average and 2 times the standard deviation DOI:10.27462/d.cnki.ghzhc.2021.000281.
as the model coefficients, and formulated the basic trading [7] R.Soujanya, P.Akshith Goud, Abhishek Bhandwalkar, et al,
strategy of price crossing the lower rail standing for buying "Evaluating future stockvalue asset using machine learning," Materials
and price crossing the upper rail for selling. We then built a Today: Proceedings, 2020,33(7):48084813,ISSN 2214-7853.

1260

Authorized licensed use limited to: BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE. Downloaded on March 26,2023 at 21:36:49 UTC from IEEE Xplore. Restrictions apply.

You might also like