Final Year Project Analysis of Bollinger Bands and Triple ...
Transcript of Final Year Project Analysis of Bollinger Bands and Triple ...
Final Year Project
Analysis of Bollinger Bands and Triple
Exponentially Smoothed Average for Hang Seng
Index
Supervisor: Liao, Li Zhi
WANG Jiawei
17250706
Hong Kong Baptist University
Abstract
With the development of stock market and its corresponding theory, nowadays more
and more people try to derive their own trading strategy to make profits. However, can
we really outperform the stock market as a whole in the long run based on their past
trends and some mathematical models? In technical analysis, which assumes that the
movements of stock prices are determined by the forces of demand and supply in the
whole stock market, it shows people that we can predict the future stock’s values and
changes by using its past information and relative mathematical models. In order to test
whether the stock market can be analyzed by the mathematical methods / models and
find out how well their effects are, I will develop a trading strategy by using the
combination of Bollinger Bands (BOLL) and Triple Exponentially Smoothed Average
(TRIX) to simulate the Hang Seng Index through MATLAB. In this trading strategy, I
set different cases to decide the signals for buying in as well as selling out. When I use
this strategy based on the historical closing price of the last 20 years’ Hang Seng Index,
the final outcome is quite well, as the Stock Yield is 7.4145 and the Maximum
Retracement Rate is 0.2734.
Introduction
As the stock market is composed of different types of numerical values and these
numbers have formed lots of unique patterns, it feels natural for us to believe that there
may be some regular patterns within. And with the deepening of people's understanding
of the stock market, nowadays more and more people choose to use mathematical
methods/models to analysis those patterns and wish to find out a perfect trading strategy
for the stocks them have invested. Therefore, in this project, through exploring the
meaning of three different mathematical stock models (BOLL, TRIX, ATR) and
analyzing the connection between them and the Hang Seng Index, I will try to derive
my own trading strategy on Hang Sang Index.
For the setting of this project, I will use daily closing price of the Hang Seng Index to
be the market daily capital, and then manipulate it through trading strategy to get the
personal daily capital. The time length of chosen historical data is from 2000/01/03 to
2020/12/24, and the commission fee I set include a 0.1% stamp tax and a 0.3%
brokerage charge. (In the following report, I will denote the nth day’s closing price as
Close(n), opening price as Open(n), highest price as High(n), and lowest price as
Low(n)).
The first stock model I use is the Bollinger Bands (BOLL), which is created by John
Bollinger and it is based on the principle of statistics. BOLL consists of three lines:
The middle one called Middle Band (MB) is the Simple Moving Average of N days:
𝑀𝐵 =∑ 𝐶𝑙𝑜𝑠𝑒(𝑖)𝑁
𝑖=1
𝑁.
The upper line is called Upper Band (UB) and is k standard deviations (SD) larger than
the Middle Band:
𝑆𝐷 = 𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 𝑜𝑓 𝑁 𝑐𝑜𝑛𝑠𝑒𝑐𝑢𝑡𝑖𝑣𝑒 𝑑𝑎𝑦𝑠′ 𝑐𝑙𝑜𝑠𝑖𝑛𝑔 𝑝𝑟𝑖𝑐𝑒,
𝑈𝐵 = 𝑀𝐵 + 𝑘 ∗ 𝑆𝐷.
The lower line is called Lower Band (LB) and is k standard deviations smaller than the
Middle Band:
𝐿𝐵 = 𝑀𝐵 − 𝑘 ∗ 𝑆𝐷.
According to Bollinger (2000), by using the assumption that the movement of stock
price always revolves around a certain value center (such as moving average, cost line,
etc.) within a certain range, we set Bollinger Bands in order to provide a relatively
specific range for the fluctuate of stock prices. It means that under normal
circumstances, the stock price should always move inside this range. And if the stock
price deviates from the range, it indicates that the market is in an extreme state.
About the functions of each line in BOLL, normally, the Upper Band and Lower Band
are to show the highest and the lowest price of the safe operation of the stock price.
Also, Bollinger (2000) states that sometimes the Lower Band and Middle Band play a
supporting role to the operation of stock price, while the Upper Band and Middle Band
sometimes exert pressure on the operation of stock price, and thus, we will know the
stock price is in a strong (weak) trend if the stock price moves above (below) the Middle
Band.
The second mathematical model I choose is the Triple Exponentially Smoothed
Average (TRIX), which smooth an average three times and then forecasts the long-term
trend of the stock price according to the change of the moving average. The reason that
I decide to combine this model with Bollinger Bands is that, according to Xu (2017),
TRIX can filter the interferences of short-term fluctuations, so as to avoid mistakes and
losses caused by frequent stock operation. Besides this, as TRIX is the most suitable
for the long-term trend of the market, it will do great help to the simulation of last 20
years’ historical data of Hang Seng Index.
Generally speaking, two lines are contained in TRIX model, one is TRIX, the other is
TRMA. The algorithm for each line is as follows: (EMA means Exponential Moving
Average)
𝑇𝑅 = 𝐸𝑀𝐴 (𝐸𝑀𝐴(𝐸𝑀𝐴(𝑁 𝑑𝑎𝑦𝑠′ 𝐶𝑙𝑜𝑠𝑖𝑛𝑔 𝑃𝑟𝑖𝑐𝑒))),
𝑇𝑅𝐼𝑋 =(𝑇𝑅(𝑖) − 𝑇𝑅(𝑖 − 1))
𝑇𝑅(𝑖 − 1),
𝑇𝑅𝑀𝐴 =∑ 𝑇𝑅𝐼𝑋(𝑖)𝑀
𝑖=1
𝑀.
The third stock model I used in the process of deriving my trading strategy (not used in
the final strategy) is the Average True Range (ATR) developed by Welles Wilder, for
which is usually used to stop loss or stopping profit during the stock trading. Carr (2019)
indicates that with a higher the value of ATR, the more likely the trend of stock price
will move dramatically; and when the ATR value is low, it shows that stock price has a
small volatility and is less likely to change widely.
Its construction is as follows:
𝑇𝑅 = max (|𝐻𝑖𝑔ℎ(𝑖) − 𝐿𝑜𝑤(𝑖)|, |𝐶𝑙𝑜𝑠𝑒(𝑖 − 1) − 𝐻𝑖𝑔ℎ(𝑖)|, |𝐶𝑙𝑜𝑠𝑒(𝑖 − 1) −
𝐿𝑜𝑤(𝑖)|),
𝐴𝑇𝑅 =∑ 𝑇𝑅(𝑖)𝑁
𝑖=1
𝑁.
Methodology
To derive a successful trading strategy for the stock index of 20 years, the most
important idea is to avoid the huge trend of sharp fall and keep up with the huge trend
of sharp rise of the stock market. If achieving this, our total revenue will increase
substantially, and the small fluctuations within the market will not affect it generally.
Therefore, in this section, I will explain the basic selling and buying conditions for each
of the three stock models.
Bollinger Bands:
When using Bollinger Bands in a trading strategy, we mainly focus on the relationships
between candlestick chart and each band (MB, UB, LB) within the BOLL. As for the
trading signals, there are mainly 3 kinds of situations.
First, we let k =1 and 2 and set two upper and lower bands, according to Mitchell (2020),
when the stock price is moving between the two upper bands, it means an upward trend
has formed and dealers should buy in and hold. On the contrary, Mitchell (2020) points
out if the price is moving between two lower bands, or if 75% of candlestick’s body is
below the two upper bands as well as the body is red (Close(n) < Open(n)), it indicates
the stock value is going down and dealers should sell out and wait.
The following graph is an example of the first situation: (The red and blue line are UB
and LB when k=2; the yellow lines are UB and LB when k=1)
Second, to ensure the happening of a trend, it feels safer and better to set the trading
condition to be extreme. From the above, we get that in normal situation, the stock price
would move between Upper Band and Lower Band, so here we can set the buying signal
to be the case when the candlestick’s body is above the Upper Band as well as the
closing price of that day is higher than its opening price. And set the selling condition
to be the case that the candlestick’s body is below the Lower Band as well as the
opening price of that day is higher than its closing price.
The following graph is an example of the second situation:
The third trading situation is aimed to solve the time lag problem which also means to
shorten the time distance between the happening of a trend and the trading action. The
reason for this strategy is that the happening of an extreme case is relatively low when
dealing with Bollinger Bands, and it is very hard to predict when the ongoing trend is
going to change after the extreme case (e.g.: the body of candlestick moves outside the
Bollinger Bands) happens. Also, as an extreme case often indicates the ongoing trend
has already last for a while, so if we make trading decision till then, a large amount of
money will be lost if the trend is going down, or we will miss a huge opportunity of
stock price appreciation if the trend is moving up. Apart from this, to avoid the
misjudgments which will cause the problem so called “buy high sell low”, we also need
some safety and lower the risk when decide this trading condition. On these grounds, I
choose to use and reform the basic idea that the stock price will go up (down) if the
daily candlestick charts move from below (above) the Middle Band to above (below)
the Middle Band. The general structure of the improved version is as follows (let today
be day t, and m, n, x, y be constants): Buying Signal: 1: The lowest prices of the last m
days are higher than their Middle Band. 2: The highest prices of the last n days before
the day t-m-1 are lower than their Middle Band. Selling Signal: 1: The highest prices
of the last x days are lower than their Middle Band. 2: The lowest prices of the last y
days before the day t-x-1 are higher than their Middle Band.
The following graph is an example of the third situation:
Besides these trading conditions, the M-Tops pattern and W-Bottoms pattern (Bollinger,
2000) are also very popular and relatively practical signals when using the Bollinger
Bands. However, as these two are too abstract and thus very difficult to build when
derive specific trading strategy, I will not use and explain them in this report.
Triple Exponentially Smoothed Average:
In the introduction, I introduce that there are two lines within the TRIX model: one is
TRIX, and another one is TRMA. During the stock transaction, the general usage of
these two lines mainly focuses on their intersection. As we combine Triple
Exponentially Smoothed Average with Bollinger Bands, we will avoid some false
trading points and thus get a more accurate outcome.
According to Xu and Wang (2017), once TRIX breaks through the TRMA from the
bottom to the top and forms a "golden fork", it indicates that the stock price begins to
enter a strong rising stage, and investors should buy in and hold. On the contrary, once
the TRIX breaks through the TRMA at a high level and forms a "dead fork", it indicates
that the strong rise of stock price has ended, and investors should resolutely sell the
remaining stocks and leave the market in time.
The following graph is an example of the “golden fork” and “dead fork”: (The red line
is the TRIX line; the blue line is the TRMA line)
However, when deriving a trading strategy, it is impossible for us to set an exact date
for the time of these two intersections. Instead, we will use a time range which contains
the intersection to ensure that the intersection of two lines occurs.
For example: (set the time range to be 5, and today is day t)
The buying signal:
𝑇𝑅𝐼𝑋(𝑡 − 6) < 𝑇𝑅𝑀𝐴(𝑡 − 6) && 𝑇𝑅𝐼𝑋(𝑡 − 1) > 𝑇𝑅𝑀𝐴(𝑡 − 1)
The selling signal:
𝑇𝑅𝐼𝑋(𝑡 − 6) > 𝑇𝑅𝑀𝐴(𝑡 − 6) && 𝑇𝑅𝐼𝑋(𝑡 − 1) < 𝑇𝑅𝑀𝐴(𝑡 − 1)
When getting the final strategy in this project, I use TRIX model as an auxiliary
indicator, which means that I only use this trading situation to help to narrow the range
of buying and selling signals set by Bollinger Bands. But I do try to just use TRIX to
simulate the total return, and as its only one trading situation is too broad to detail the
signals, the outcome is not good, for which the final total return is less than
corresponding closing price and the stock yield is -0.2369.
Average True Range:
As I only use this indicator in the process of getting the final trading strategy, I will
only briefly introduce how to use it during the stock transactions, and the reason that I
use it at first is to wish to stop loss from the trading of BOLL and TRIX. According to
Hall (2020), ATR is an indicator that measures the volatility of stock price and is used
to decide when to entry or exiting the stock market or used to stop loss or stopping
profit. The trading signals are as follows: (r is a constant, and today is day t)
The buying condition:
𝐶𝑙𝑜𝑠𝑒(𝑡) > 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) + 𝑟 ∗ 𝐴𝑇𝑅(𝑡 − 1).
The selling (stop loss) condition:
𝐶𝑙𝑜𝑠𝑒(𝑡) < 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) − 𝑟 ∗ 𝐴𝑇𝑅(𝑡 − 1).
Numerical Experiment
During the process of getting the final strategy, I have manually tried hundreds of
different combinations of parameters within those selling and buying situations and
choose the best strategy by comparing the total yield of each outcome. In this section,
we will begin with three examples from my deduced process first, and then introduce
the final trading strategy. And for these examples, the general idea of their buying and
selling signals are from the 5 situations I explained before, while their specific
structures are the result of many attempts.
Example 1: BOLL
The first example is one of my best early trading strategies which I only used the
Bollinger Bands to define the trading conditions. I use the Simple moving average for
the Middle Band and set N = 20 and k = 2. Apart from that, by reforming the second
and third trading situations I introduced for Bollinger Bands in the methodology, I
allocate two conditions to each of the buying and selling signal:
Buying signal:
𝐶𝑎𝑠𝑒1 = 𝐿𝑜𝑤(𝑡 − 1) > 𝑈𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑂𝑝𝑒𝑛(𝑡 − 1),
𝐶𝑎𝑠𝑒2 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) + (𝑈𝐵(𝑡 − 1) − 𝐿𝐵(𝑡 − 1)
100),
𝐵𝑢𝑦𝑖𝑛𝑔 𝑆𝑖𝑔𝑛𝑎𝑙 = 𝐶𝑎𝑠𝑒1 ∪ 𝐶𝑎𝑠𝑒2.
Selling signal:
𝐶𝑎𝑠𝑒3 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩ 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝐿𝐵(𝑡 − 1),
𝐶𝑎𝑠𝑒4 = 𝐻𝑖𝑔ℎ(𝑡 − 1) < 𝐿𝐵(𝑡 − 1) ∩
𝐻𝑖𝑔ℎ(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝐻𝑖𝑔ℎ(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝐿𝑜𝑤(𝑡 − 4) > 𝑀𝐵(𝑡 − 4),
𝑆𝑒𝑙𝑙𝑖𝑛𝑔 𝑆𝑖𝑔𝑛𝑎𝑙 = 𝐶𝑎𝑠𝑒3 ∪ 𝐶𝑎𝑠𝑒4.
The results of the first example are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
27 26 1.8945 0.3740 1.7457
From the table, the total number of transactions is quite large, which indicates that I
will lose certain amount of money on the commission fee. The total yield is not high
enough, only 1.8945, and the final total return is 1.7457 times bigger than that day’s
closing price. The maximum retracement rate is a little bit high, and it shows that
according to historical data, my future total revenue may fall by 37.40% at worst.
The following graph shows the total return of stock in 20 years:
Starting from here, in the graph of “The Return of Stock”, the red line indicates the
original closing price of Hang Seng Index in 20 years; the blue line shows the total
return after subtracting the commission fee; and the yellow line indicates the total return
without the commission fee. We can see that from 2000 to around 2011, the blue line
generally avoids the sharp fall in 2008 and keeps up with the rising trend of closing
price in 2004~2007 and 2009~2011. However, ever since the huge increase in 2010, the
overall trend of blue line keeps falling while the general trend of original closing price
keeps moving up. And at the same time, the length between the yellow line and blue
line starts to increase after 2013, which means there are too many useless trading actions
since 2013.
The following graph shows the specific times of buying and selling actions in 20 years:
This trading graph can reflect the specific trading situation more accurately, and if we
combine this picture with the last one, then we can confirm that there are too many
unnecessary buying and selling actions since 2013, for which reduce the total revenue
because of commission fee. Besides this, some trading points appear to “buy high” and
then “sell low”. Also, for certain points, there exist a huge time lag between the
happening of a trend and the corresponding trading action.
Example 2: BOLL+TRIX+ATR
In order to fix the problems in the first example, I need to find a way to make the trading
condition more specific and accurate. Therefore, I add two more stock indicators (TRIX
and ATR) to further narrow the range of buying and selling signal. As TRIX indicator
is through the intersection of two lines to determine the buying and selling time, when
we combine the intersection time in TRIX with the trading conditions in BOLL, it will
make the signals more accurate. And at the same time, with the help of ATR indicator
to stop loss, I think the total revenue will increase.
Based on the general trading conditions I derived in the first example, here I use
Bollinger Bands as a principal model and add two more supporting stock indicators
(TRIX, ATR) to analysis Hang Seng Index. After trying different values for the
parameters in each stock indicator: For BOLL, I use simple moving average to be the
Middle Band and set N = 20 and k = 2.05; for TRIX, I let N = 12 and M = 9; and for
ATR, I set N = 20.
The trading signals are as follows:
Buying signal:
𝐶𝑎𝑠𝑒1 = 𝐿𝑜𝑤(𝑡 − 1) > 𝑈𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑂𝑝𝑒𝑛(𝑡 − 1),
𝐶𝑎𝑠𝑒2 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑂𝑝𝑒𝑛(𝑡 − 5) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) + (𝑈𝐵(𝑡 − 1) − 𝐿𝐵(𝑡 − 1)
100),
𝐶𝑎𝑠𝑒3 = 𝑇𝑅𝐼𝑋(𝑡 − 6) < 𝑇𝑅𝑀𝐴(𝑡 − 6) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) > 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝑆𝑖𝑔𝑛𝑎𝑙𝐵𝑢𝑦 = (𝐶𝑎𝑠𝑒1 ∩ 𝐶𝑎𝑠𝑒3) ∪ (𝐶𝑎𝑠𝑒2 ∩ 𝐶𝑎𝑠𝑒3).
Selling signal:
𝐶𝑎𝑠𝑒4 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩ 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝐿𝐵(𝑡 − 1),
𝐶𝑎𝑠𝑒5 = 𝐻𝑖𝑔ℎ(𝑡 − 1) < 𝐿𝐵(𝑡 − 1) ∩
𝐻𝑖𝑔ℎ(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝐻𝑖𝑔ℎ(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝐿𝑜𝑤(𝑡 − 4) > 1.05 ∗ 𝑀𝐵(𝑡 − 4),
𝐶𝑎𝑠𝑒6 = 𝑇𝑅𝐼𝑋(𝑡 − 5) > 𝑇𝑅𝑀𝐴(𝑡 − 5) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) < 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝐶𝑎𝑠𝑒7 = 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) < 𝑀𝐵(𝑡 − 6),
𝐶𝑎𝑠𝑒8 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) − 2 ∗ 𝐴𝑇𝑅(𝑡 − 2),
𝑆𝑒𝑙𝑙𝑖𝑛𝑔 𝑆𝑖𝑔𝑛𝑎𝑙 = (𝐶𝑎𝑠𝑒4 ∩ 𝐶𝑎𝑠𝑒6) ∪ (𝐶𝑎𝑠𝑒5 ∩ 𝐶𝑎𝑠𝑒6) ∪
(𝐶𝑎𝑠𝑒7 ∩ 𝐶𝑎𝑠𝑒6) ∪ (𝐶𝑎𝑠𝑒8 ∩ 𝐶𝑎𝑠𝑒6).
These different cases are derived from the methodology and first example, as well as
many attempts.
The results of the second example are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
11 10 3.8005 0.2734 2.8954
Compared with the first example, the results have improved a lot. Not only the number
of transactions has decreased by more than half, but also the total yield doubled this
time. Besides, the maximum retracement rate decreases from 0.3740 to 0.2734, which
indicates that this trading strategy is a lot safer and stabler than before. From here we
can draw a preliminary conclusion that after adding TRIX and ATR to the BOLL, the
signals do become more accurate.
The following graph shows the total return of stock in 20 years:
If we ignore the small declines in the past 20 years, we can see that the total return (blue
line) is increasing in general this time. And it is also very clear that as the signals
become more accurate and the number of transactions decreases, the losses from those
useless buying and selling actions have also significantly reduced, which lead greatly
increased to the total return. Nevertheless, there are still some problems in this trading
strategy. The first one is about the sensitivity and accuracy. For the blue line, too many
unnecessary horizontal line segments are contained within these 20 years, which means
that when the overall trend of the original closing price is moving up slowly, the buying
signal is not triggered, and thus make the total return unchanged. For example, from
2016 to around 2018, the closing price is rising while the line of total return remains
horizontal. The second problem is still about the commission fee. From the graph, at
the end of 2020, the length between the yellow line and blue line is too big to be ignored,
which means that even though we only have 21 transactions, some of them are still
useless.
The following graph shows the specific times of buying and selling actions in 20 years:
From the transaction plot, we can observe that there are many useless trading actions
around 2000, 2004, and 2020, and this confirms the second problem mentioned above.
Also, this plot shows us that the buying action around 2006 as well as the selling action
around late 2015 are too slow, and there is no buying during the upward trend starts
from 2016. These phenomena confirm the sensitivity problem of this trading strategy.
Example 3: BOLL+TRIX
To fix the sensitivity and useless trading problems from the second example, my next
step here is to use the third method for Bollinger Bands that I explained in the
methodology to shorten the time lag and thus improve the sensitivity and accuracy.
During the process of finding a way to reduce the unnecessary transactions, while I was
trying to abandon the ATR in order to shorten the conditions for the selling signal, the
outcome improved significantly. Therefore, in this third example, I still choose BOLL
as my main model, but only use TRIX as the supporting indicator. Here, the values of
those parameters within BOLL and TRIX are the same as those in the second example.
I set the trading situations as follows:
Buying signal:
𝐶𝑎𝑠𝑒1 = 𝐿𝑜𝑤(𝑡 − 1) > 𝑈𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑂𝑝𝑒𝑛(𝑡 − 1),
𝐶𝑎𝑠𝑒2 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑂𝑝𝑒𝑛(𝑡 − 5) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) + (𝑈𝐵(𝑡 − 1) − 𝐿𝐵(𝑡 − 1)
100),
𝐶𝑎𝑠𝑒3 = 𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) > 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) > 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) > 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) > 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) > 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) > 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) > 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) > 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) > 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) > 𝑀𝐵(𝑡 − 6) ∩
𝑂𝑝𝑒𝑛(𝑡 − 7) > 𝑀𝐵(𝑡 − 7) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 7) > 𝑀𝐵(𝑡 − 7) ∩
𝑂𝑝𝑒𝑛(𝑡 − 8) > 𝑀𝐵(𝑡 − 8) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 8) > 𝑀𝐵(𝑡 − 8),
𝐶𝑎𝑠𝑒4 = 𝑇𝑅𝐼𝑋(𝑡 − 6) < 𝑇𝑅𝑀𝐴(𝑡 − 6) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) > 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝑆𝑖𝑔𝑛𝑎𝑙𝐵𝑢𝑦 = (𝐶𝑎𝑠𝑒1 ∩ 𝐶𝑎𝑠𝑒4) ∪ (𝐶𝑎𝑠𝑒2 ∩ 𝐶𝑎𝑠𝑒4) ∪ (𝐶𝑎𝑠𝑒3 ∩ 𝐶𝑎𝑠𝑒4).
Selling signal:
𝐶𝑎𝑠𝑒5 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩ 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝐿𝐵(𝑡 − 1),
𝐶𝑎𝑠𝑒6 = 𝐻𝑖𝑔ℎ(𝑡 − 1) < 𝐿𝐵(𝑡 − 1) ∩
𝐻𝑖𝑔ℎ(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝐻𝑖𝑔ℎ(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝐿𝑜𝑤(𝑡 − 4) > 1.05 ∗ 𝑀𝐵(𝑡 − 4),
𝐶𝑎𝑠𝑒7 = 𝑇𝑅𝐼𝑋(𝑡 − 5) > 𝑇𝑅𝑀𝐴(𝑡 − 5) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) < 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝐶𝑎𝑠𝑒8 = 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) < 𝑀𝐵(𝑡 − 6),
𝑆𝑒𝑙𝑙𝑖𝑛𝑔 𝑆𝑖𝑔𝑛𝑎𝑙 = (𝐶𝑎𝑠𝑒5 ∩ 𝐶𝑎𝑠𝑒7) ∪ (𝐶𝑎𝑠𝑒6 ∩ 𝐶𝑎𝑠𝑒7) ∪ (𝐶𝑎𝑠𝑒8 ∩ 𝐶𝑎𝑠𝑒7).
Because extreme situations often take a long time to happen after a major trend begins,
instead of using ATR, this time I focus on specifying the relationships between the
Middle Band and candles in the candlestick chart, like the comparison of closing price
and opening price with corresponding MB.
The results of the third example are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
16 15 5.2648 0.2734 3.7787
Although the number of buying and selling has gone up from 21 to 31, the total yield
as well as the total return increase a lot, and the maximum retracement rate remains the
same. From here, we can see the effectiveness and accuracy of the third method for
Bollinger Bands in the methodology.
The following graph shows the total return of stock in 20 years:
This total revenue plot reflects us some problems of this trading strategy that the last
table cannot show. First, since late 2010, too many small vibrations in the blue line
which cause the total return falls a lot of times. Second, the blue line is too easy to
fluctuate substantially with the small undulate of the original closing price. Third, the
difference between the yellow line and blue line starts to increase since 2011.
The following graph shows the specific times of buying and selling actions in 20 years:
As we take those three problems to the transaction plot, it shows us that despite some
useless transactions around 2000 and 2004, the performance of the first ten years is
quite well. Therefore, we need to draw our attention to the last ten years. We can find
out around 2011 as well as between 2015 and 2020, there are still some transaction
points with the “buy high” and “sell low” situation. These late transactions can not only
cause the blue line to fluctuate, but also create a large amount of unnecessary
commission fee.
Final Trading Strategy: BOLL+TRIX
To solve the late transaction problem in the third example, it is important to focus on
the patterns that happened before a trend has formed. Based on the former trading
signals and the third method for BOLL, I add one more trading case for each of the
buying and selling signal. In these two new cases, I detail the patterns before and during
the change of a trend of the closing price.
In my final trading strategy for Hang Seng Index, I set N = 20, k = 2.05 for Bollinger
Bands, and assign N = 12, M = 9 for TRIX indicator. The trading situations I derived
are as follows:
Buying signal:
𝐶𝑎𝑠𝑒1 = 𝐿𝑜𝑤(𝑡 − 1) > 𝑈𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑂𝑝𝑒𝑛(𝑡 − 1),
𝐶𝑎𝑠𝑒2 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑂𝑝𝑒𝑛(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩ 𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) + (𝑈𝐵(𝑡 − 1) − 𝐿𝐵(𝑡 − 1)
100),
𝐶𝑎𝑠𝑒3 = 𝑂𝑝𝑒𝑛(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) > 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) > 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) > 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) > 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) > 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) > 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) > 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) > 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) > 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) > 𝑀𝐵(𝑡 − 6) ∩
𝑂𝑝𝑒𝑛(𝑡 − 7) > 𝑀𝐵(𝑡 − 7) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 7) > 𝑀𝐵(𝑡 − 7) ∩
𝑂𝑝𝑒𝑛(𝑡 − 8) > 𝑀𝐵(𝑡 − 8) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 8) > 𝑀𝐵(𝑡 − 8),
𝐶𝑎𝑠𝑒4 = 𝐿𝑜𝑤(𝑡 − 1) > 𝑀𝐵(𝑡 − 1) ∩ 𝐿𝑜𝑤(𝑡 − 2) > 𝑀𝐵(𝑡 − 2) ∩
𝐿𝑜𝑤(𝑡 − 3) > 𝑀𝐵(𝑡 − 3) ∩ 𝐿𝑜𝑤(𝑡 − 4) > 𝑀𝐵(𝑡 − 4) ∩
𝐿𝑜𝑤(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑂𝑝𝑒𝑛(𝑡 − 5) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) < 𝑂𝑝𝑒𝑛(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) < 𝑂𝑝𝑒𝑛(𝑡 − 2) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) > 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) > 𝑂𝑝𝑒𝑛(𝑡 − 4),
𝐶𝑎𝑠𝑒5 = 𝑇𝑅𝐼𝑋(𝑡 − 6) < 𝑇𝑅𝑀𝐴(𝑡 − 6) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) > 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝑆𝑖𝑔𝑛𝑎𝑙𝐵𝑢𝑦 = (𝐶𝑎𝑠𝑒1 ∩ 𝐶𝑎𝑠𝑒5) ∪ (𝐶𝑎𝑠𝑒2 ∩ 𝐶𝑎𝑠𝑒5) ∪
(𝐶𝑎𝑠𝑒3 ∩ 𝐶𝑎𝑠𝑒5) ∪ (𝐶𝑎𝑠𝑒4 ∩ 𝐶𝑎𝑠𝑒5).
Selling signal:
𝐶𝑎𝑠𝑒6 = 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑂𝑝𝑒𝑛(𝑡 − 1) ∩ 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝐿𝐵(𝑡 − 1),
𝐶𝑎𝑠𝑒7 = 𝐻𝑖𝑔ℎ(𝑡 − 1) < 𝐿𝐵(𝑡 − 1) ∩ 𝐻𝑖𝑔ℎ(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝐻𝑖𝑔ℎ(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩ 𝐿𝑜𝑤(𝑡 − 4) > 1.05 ∗ 𝑀𝐵(𝑡 − 4),
𝐶𝑎𝑠𝑒8 = 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 7) > 𝑀𝐵(𝑡 − 7),
𝐶𝑎𝑠𝑒9 = 𝑂𝑝𝑒𝑛(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 1) < 𝑀𝐵(𝑡 − 1) ∩
𝑂𝑝𝑒𝑛(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 2) < 𝑀𝐵(𝑡 − 2) ∩
𝑂𝑝𝑒𝑛(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 3) < 𝑀𝐵(𝑡 − 3) ∩
𝑂𝑝𝑒𝑛(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 4) < 𝑀𝐵(𝑡 − 4) ∩
𝑂𝑝𝑒𝑛(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 5) < 𝑀𝐵(𝑡 − 5) ∩
𝑂𝑝𝑒𝑛(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩ 𝐶𝑙𝑜𝑠𝑒(𝑡 − 6) < 𝑀𝐵(𝑡 − 6) ∩
𝐶𝑙𝑜𝑠𝑒(𝑡 − 8) > 𝑀𝐵(𝑡 − 8) ∩ 𝐿𝑜𝑤(𝑡 − 9) > 𝑀𝐵(𝑡 − 9),
𝐶𝑎𝑠𝑒10 = 𝑇𝑅𝐼𝑋(𝑡 − 5) > 𝑇𝑅𝑀𝐴(𝑡 − 5) ∩ 𝑇𝑅𝐼𝑋(𝑡 − 1) < 𝑇𝑅𝑀𝐴(𝑡 − 1),
𝑆𝑖𝑔𝑛𝑎𝑙𝑆𝑒𝑙𝑙 = (𝐶𝑎𝑠𝑒6 ∩ 𝐶𝑎𝑠𝑒10) ∪ (𝐶𝑎𝑠𝑒7 ∩ 𝐶𝑎𝑠𝑒10) ∪
(𝐶𝑎𝑠𝑒8 ∩ 𝐶𝑎𝑠𝑒10) ∪ (𝐶𝑎𝑠𝑒9 ∩ 𝐶𝑎𝑠𝑒10).
In these 10 cases, Case 4 and Case 9 are newly derived in the final strategy, while the
general structures of other cases come from the earlier examples.
From the Case 4, I set the lowest price of last 4 days to be higher than their
corresponding Middle Band, which is the trend after the closing price starts to move up.
And I let Low(t-5) < MB(t-5) and Close(t-5) < Open(t-5) to be the patterns happened
during the change of the trend, which means during the time when the candlestick is
trying to break through the Middle Band from bottom to top. And as for the
relationships between the opening prices and closing prices of last 4 days, at first, I set
all their closing prices be larger than opening prices in order to strengthen and narrow
the range for the upper trend. However, as I change Close(t-2) > Open(t-2) and Close(t-
3) > Open(t-3) to Close(t-2) < Open(t-2) and Close(t-3) < Open(t-3) in order to try
different combinations, the result suddenly improves a lot, then I keep this pattern.
From Case 9, in order to define the downward trend after the changes, I set both the
opening prices and closing prices of the last 6 days to be smaller than their
corresponding Middle Band. And for the patterns before the changes, from the third
trading situation for BOLL, we conjecture that all or part of the candlesticks will be
above the Middle Band. And from many manually attempts, I let Close(t-8) > MB(t-8)
and Low(t-9) > MB(t-9).
The results of the final trading strategy are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
13 12 7.4145 0.2734 5.0739
From the table, there are 25 trading actions totally, and because the basic structure and
idea are similar for both the buying and selling signal, the number of buying and selling
are nearly the same. As we shorten the time lag and improve the sensitivity, the final
total yield has now increased from 5.2648 to 7.4145, with the maximum retracement
rate remains still at 0.2734. On December 24th, 2020, the total return is 5.0739 times
bigger than that day’s closing price.
The following table shows the yearly stock yield from 2000 to 2020:
2000 2001 2002 2003 2004 2005
-0.0702 0.1047 -0.0455 0.3662 0.0495 0.0449
2006 2007 2008 2009 2010 2011
0.3363 0.3792 0.0618 0.4941 0.0700 -0.0116
2012 2013 2014 2015 2016 2017
0.1974 0.0283 -0.0080 0.0538 0.0129 0.3002
2018 2019 2020 Average Max -Min
0.0205 0.0509 -0.0169 0.1152 0.5643
From 2000 to 2020, the average yearly stock yield is 0.1152, and there are 5 years that
have negative values, which means the total returns at year end are lower than the
corresponding investment capital at the beginning of those years. Although the total
yield is 7.4145, the yearly yield is not stable enough and the maximum range of its
change reaches 0.5643.
The following graph shows the total return of stock in 20 years:
By using the final trading strategy, the number of fluctuates and small declines on the
blue line has decrease a lot when we compare it with the third example. Besides, thanks
to the shorter decision time, which leads to more timely buying and selling, the range
of rise on the blue line increases as well as the range of decline shortens. If we look at
the yellow line, it shows that before 2019, the cost on commission fee has also
decreased a lot compared to the former examples, which means the decline of the
number of unnecessary transactions, and once again it indicates the accuracy of this
final strategy.
The following graph shows the specific times of buying and selling actions in 20 years:
Despite a few unnecessary transaction points, most of the buying and selling actions
from this graph are both timely and accurate, and follow the so called “buy low and sell
high” standard. So next, I will choose to illustrate some of the representative trading
points from this transaction plot:
For the buying actions start from year 2000, the third buying happens after a relatively
small upward trend has risen by 15.1780%. As for the fourth one, it happens during a
short downward wave, and that means it should be a useless transaction. However, the
time of this buying is right before the big rising trend starts around 2003/04, which
makes the total revenue increase more than 50%. The fifth buying keeps up with the
huge upward trend between 2004/05 and 2007/10. Although this transaction happens
after the closing price has risen by 18.6873%, it is still very timely when we look at the
whole trend. The sixth buying takes place on 2008/12/04, after the closing price has
risen by 8.4270%. This trading action catches the start of the sharp rise between 2008/11
and 2009/12, and leads to a significant increase on the total return. During the period
starts from 2011/12 and ends on 2015/04, the total trend of closing price increases
slowly through many fluctuates, and the seventh buying happens after the closing price
has risen by 3.7383%. As for the ninth buying action, if we choose to look at it through
the perspective of small fluctuates, it is not a good transaction point as it is at the highest
of the fluctuates well as the closing price has risen by 16.2664%. But if we put it in the
general trend, we can see that this transaction keeps up with the sharp rise started from
2016/02. The tenth buying happens after the closing price has risen by 6.3514%, and
the meaning of this transaction is to make up for the selling happened previously. For
the eleventh buying, although it is a little slow, it still keeps up with the small upward
trend after the closing price has risen by 6.7837%.
Now we turn to the selling points within these 20 years. The second selling happens
after the closing price has fall by 8.3474%. Even though 8.3474% is not a small number,
this transaction still let the total return avoid most of the downward trend between
2000/09 and 2001/09 successfully. Next, the performance of the fourth selling is not
good, the reasons are that not only did this transaction happen after the closing price
has fall by 11.0632%, but also the time lag between the start of the trend and the selling
action is too long. As for the fifth selling, it saves the total return from falling sharply.
Because of the sharp decline within a very short time, this selling action happens after
the closing price has fall by 11.0936%. For the eighth selling, same as the last one, due
to the sharp fall of closing price, it happens after the closing price has fall by 12.1351%.
Nevertheless, this selling still stops the loss between 2015/07 and 2016/02 in a way.
The tenth selling action happens after the general downward trend has formed for 2
months as well as the closing price has fall by 7.5415%. Although the result of this
transaction is not bad, the time lag is long, which indicates that it is not sensitive enough
to catch the start. For the eleventh selling, it is to stop the fast decline from 2020/01 to
2020/04, and it happens after the closing price has fall by 9.5664%.
Other Applications
Although the result is good when using my final strategy on Hang Seng Index from
2000/01/03 to 2020/12/24, we do not know whether it will also perform well when the
trading time is changed or in thousands of the other indexes and stock prices. Therefore
in this section, I will use the same final trading strategy to different indexes and different
time period of Hang Seng Index.
SSE Composite Index: (2000/01/03 – 2020/12/21)
The results are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
13 13 2.4536 0.5766 1.4791
From the outcome, there are totally 26 transactions throughout the 20 years, and as the
final yield is 2.4536, our revenue is more than twice as much as the beginning capital.
But the huge fluctuations have caused the total daily return (blue line) very unstable
and thus give us a large maximum retracement rate that reaches 0.5766.
The following graph shows the total return of stock in 20 years:
By using my trading strategy on 20 years’ SSE Composite Index, although the final
total return is not as good as the result before, the blue line is still higher than the red
line (daily closing price) in general, which means my strategy has outperformed the
market.
The following graph shows the specific times of buying and selling actions in 20 years:
As we change the index, the specific structure of my strategy does not match the new
patterns here contained in the SSE Composite Index. A lot of the buying and selling are
too slow to catch the changing trend and not accurate enough, and cause a large amount
of losses.
Nasdaq Composite Index: (2000/01/03 – 2020/12/23)
The results are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
15 14 1.9428 0.5317 0.8958
The following graph shows the total return of stock in 20 years:
The following graph shows the specific times of buying and selling actions in 20 years:
When using the strategy on 20 year’s historical data of Nasdaq Composite Index, the
general pattern of the blue line (total daily return) after 2004 is similar to that of the red
line (daily closing price), and it helps the total daily return to keep up with the general
rising trend of the closing price after around 2009 and thus makes the final total yield
reaches 1.9428. However, not only the blue line does not outperform the market this
time, but also there are lots of useless selling and buying actions from the transaction
plot, which indicates that the specific structure and parameters of this strategy does not
applicable to this Nasdaq Composite Index.
Dow Jones Industrial Average: (2000/01/03 – 2020/12/23)
The results are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
14 13 1.1917 0.2971 0.8331
The following graph shows the total return of stock in 20 years:
The following graph shows the specific times of buying and selling actions in 20 years:
For applications on Dow Jones Industrial Average, which is also an US stock index, the
results are also not so well. The total yield is 1.1917, but the final capital return is lower
than its corresponding closing price. From its transaction plot, despite I have solved the
accurate and sensitivity problem when deriving this strategy in Hang Seng Index, there
are still many false buying and selling actions as we change to a different index data.
Hang Seng Index: (1987/03/13 – 2020/12/24)
The results are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
21 20 19.1335 0.5312 2.1250
The following graph shows the total return of stock in 20 years:
The following graph shows the specific times of buying and selling actions in 20 years:
In my prior numerical experiments, I use the historical data of Hang Seng Index from
2000/01/03 to 2020/12/24 to derive my trading strategy. And here, I try my strategy on
the whole historical data start from 1987. Compared to the results that starts from 2000,
because the starting capital becomes lower this time, the total yield has increased a lot
from 7.4145 to 19.1335. There are totally 41 transactions and the maximum retracement
rate has gone up to 0.5312, and it means that as the time period starts to increase, the
risk and instability of the investment has also become bigger. And if we look at the final
total return on 2020/12/24, it has decrease from 5.0739 times bigger than that day’s
closing price to 2.1250 times, and the reason for this decrease may be that, from the
return plot, the blue line has never outperformed the red line of closing price for the
first 22 years. As we dig further into the transaction plot, we can see lots of transactions
before 2001 are not accurate enough and “buy at a high price” as well as “sell at a low
price”.
Hang Seng Index: (2010/01/04 – 2020/12/24)
The results are listed on the table:
Number of
Buying
Number of
Selling
Total Yield Maximum
Retracement
Rate
Total Return
/
Closing Price
8 7 0.8330 0.1939 1.4934
The following graph shows the total return of stock in 20 years:
The following graph shows the specific times of buying and selling actions in 20 years:
After trying the whole time period for HSI, here I start from the 2010/01/04. Because
of the relatively short time period, the final outcome is not as high as the last one, the
total yield is only 0.8330. But from the return plot, the daily capital line generally avoids
the huge downward trend and rises with the upward trend. And for the transaction plot,
apart from the first and fourth buying as well as the second and fourth selling, the rest
of the trading actions are basically accurate.
Conclusion
With the rapid development of the stock market and the maturity of the stock trading
theory, more and more investors begin to make profits by using mathematical methods
and models to analyze the stock market. In this paper, I began with a basic introduction
of the project settings, and then for the three stock indicators: Bollinger Bands, Triple
Exponentially Smoothed Average and Average True Range, I introduced the usage of
each of them and gave out their general mathematical forms.
I showed and explained five fundamental methods to determine the trading signals by
using these three stock indicators: three methods for BOLL, one method for TRIX, and
one method for ATR. Each of these methods can be derived into many different and
specific buying and selling conditions. And then, there are hundreds of ways to form
these conditions into different combinations, and each combination will have a unique
effect on the stock data.
Before getting the final trading strategy, I discussed three examples to show the process
of deriving the best buying and selling conditions. In these examples, I analyzed the
plots of each result, and summarized their advantages, shortcomings as well as how to
improve them. Finally, I derive a trading strategy that can make the stock yield reach
7.4145 and the maximum retracement rate reach 0.2734 when used in the 20 years’
historical data of Hang Seng Index. This trading strategy can avoid a lot of downward
trend within these 20 years and keep up with the most upward trends.
At last, I used my final strategy into three other different indexes and two different time
period of Hang Seng Index. Although their outcomes were not as good as the one when
using the strategy to Hang Seng Index from 2000/01/03 to 2020/12/24, the total yields
of them still bigger than zero as well as the total daily capital could keep up with the
major upward trend of the closing price.
Source Code (MATLAB)
% When to start to extract the data:
StartingDateNumber = 3221;
%% Extract historical data of Hang Seng Index (HSI):
opts = delimitedTextImportOptions("NumVariables", 7);
opts.DataLines = [StartingDateNumber, Inf];
opts.Delimiter = ";";
opts.VariableNames = ["Date", "Open", "High", "Low", "Close", "Var6",
"Var7"];
opts.SelectedVariableNames = ["Date", "Open", "High", "Low", "Close"];
opts.VariableTypes = ["datetime", "double", "double", "double",
"double", "string", "string"];
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts = setvaropts(opts, ["Var6", "Var7"], "WhitespaceRule",
"preserve");
opts = setvaropts(opts, ["Var6", "Var7"], "EmptyFieldRule", "auto");
opts = setvaropts(opts, "Date", "InputFormat", "dd/MM/yyyy");
% Import the data
HangSengIndex = readtable("C:\Users\xianc\OneDrive\桌面\^HSI (1).csv",
opts);
% Historical data extraction of Hang Seng Index completed
% Extraction of Date, Closing Price, Opening Price, Highest Price,
Lowest Price from HSI:
Close = HangSengIndex.Close;
Date = HangSengIndex.Date;
Open = HangSengIndex.Open;
High = HangSengIndex.High;
Low = HangSengIndex.Low;
% Establishing the Bollinger Bands (N = 20, K = 2.05):
N = 20;
kUP = 2.05;
kDOWN = 2.05;
MovingAverage = zeros(length(Close),1);
StandardDeviations = zeros(length(Close),1);
UP = zeros(length(Close),1);
DOWN = zeros(length(Close),1);
for t = N:length(Close)
MovingAverage(t) = mean(Close(t-N+1:t));
StandardDeviations(t) = (((Close(t-N+1)-
MovingAverage(t)).^2+(Close(t-N+2)-MovingAverage(t)).^2+(Close(t-
N+3)-MovingAverage(t)).^2+(Close(t-N+4)-
MovingAverage(t)).^2+(Close(t-N+5)-MovingAverage(t)).^2+(Close(t-
N+6)-MovingAverage(t)).^2+(Close(t-N+7)-
MovingAverage(t)).^2+(Close(t-N+8)-MovingAverage(t)).^2+(Close(t-
N+9)-MovingAverage(t)).^2+(Close(t-N+10)-
MovingAverage(t)).^2+(Close(t-N+11)-MovingAverage(t)).^2+(Close(t-
N+12)-MovingAverage(t)).^2+(Close(t-N+13)-
MovingAverage(t)).^2+(Close(t-N+14)-MovingAverage(t)).^2+(Close(t-
N+15)-MovingAverage(t)).^2+(Close(t-N+16)-
MovingAverage(t)).^2+(Close(t-N+17)-MovingAverage(t)).^2+(Close(t-
N+18)-MovingAverage(t)).^2+(Close(t-N+19)-
MovingAverage(t)).^2+(Close(t-N+20)-MovingAverage(t)).^2)/20).^0.5;
UP(t) = MovingAverage(t)+kUP*StandardDeviations(t);
DOWN(t) = MovingAverage(t)-kDOWN*StandardDeviations(t);
end
% Establishing the Triple Exponentially Smoothed Average (N = 12, M =
9):
Period1 = 12;
Period2 = 9;
EMA1 = zeros(length(Close),1);
EMA2 = zeros(length(Close),1);
TR = zeros(length(Close),1);
TRIX = zeros(length(Close),1);
TRMA = zeros(length(Close),1);
EMA1(1)=Close(1);
for t=2:length(Close)
EMA1(t)=Close(t)*(2/(Period1+1))+EMA1(t-1)*((Period1-
1)/(Period1+1));
end
EMA2(1)=EMA1(1);
for t=2:length(Close)
EMA2(t)=EMA1(t)*(2/(Period1+1))+EMA2(t-1)*((Period1-
1)/(Period1+1));
end
TR(1)=EMA2(1);
for t=2:length(Close)
TR(t)=EMA2(t)*(2/(Period1+1))+TR(t-1)*((Period1-1)/(Period1+1));
end
for t = 2:length(Close)
TRIX(t) = ((TR(t)-TR(t-1))/TR(t-1))*100;
end
for t = Period2+1:length(Close)
TRMA(t) = mean(TRIX(t-Period2+1:t));
end
% Draw the TRIX:
figure(1);
plot(Date,TRIX,'r');
hold on;
plot(Date,TRMA,'b');
datetick('x','yyyymmdd');
xlabel('Date');
ylabel('TRIX & TRMA');
title('TRIX Indicator');
hold off;
% Total initial capitial:
InitialCapital = Close(N-1);
% Set position: pos = 1 means hold stock,pos = 0 means hold money:
pos = zeros(length(Close),1);
% Set Total Returen and Total Return with no tax:
TotalReturn = zeros(length(Close),1);
TotalReturnNoTax = zeros(length(Close),1);
% Draw and mark the specific date of buying and selling:
figure(3);
plot(Date,Close,'r');
datetick('x','yyyymmdd');
xlabel('Date');
ylabel('Close Price');
title('Time Series of Stock');
hold on;
% Trading Strategy:
for t = N:length(Close)
% Set different cases for trading strategy:
% Cases for Bollinger Bands:
Case1 = Low(t-1)>UP(t-1) && Close(t-1)>Open(t-1);
Case2 = Close(t-1)<Open(t-1) && Open(t-1)<DOWN(t-1);
Case2a = High(t-1)<DOWN(t-1) && High(t-2)<MovingAverage(t-2) &&
High(t-3)<MovingAverage(t-3) && Low(t-4)>1.05*MovingAverage(t-4);
Case2b = Open(t-1)<MovingAverage(t-1) && Close(t-
1)<MovingAverage(t-1) && Open(t-2)<MovingAverage(t-2) && Close(t-
2)<MovingAverage(t-2) && Open(t-3)<MovingAverage(t-3) && Close(t-
3)<MovingAverage(t-3) && Open(t-4)<MovingAverage(t-4) && Close(t-
4)<MovingAverage(t-4) && Open(t-5)<MovingAverage(t-5) && Close(t-
5)<MovingAverage(t-5) && Open(t-6)<MovingAverage(t-6) && Close(t-
6)<MovingAverage(t-6) && Close(t-7)>MovingAverage(t-7);
Case2c = Open(t-1)<MovingAverage(t-1) && Close(t-
1)<MovingAverage(t-1) && Open(t-2)<MovingAverage(t-2) && Close(t-
2)<MovingAverage(t-2) && Open(t-3)<MovingAverage(t-3) && Close(t-
3)<MovingAverage(t-3) && Open(t-4)<MovingAverage(t-4) && Close(t-
4)<MovingAverage(t-4) && Open(t-5)<MovingAverage(t-5) && Close(t-
5)<MovingAverage(t-5) && Open(t-6)<MovingAverage(t-6) && Close(t-
6)<MovingAverage(t-6) && Close(t-8)>MovingAverage(t-8) && Low(t-
9)>MovingAverage(t-9);
Case3b = Close(t-5)<Open(t-5) && Close(t-1)<Open(t-1) && Open(t-
2)<MovingAverage(t-2) && Open(t-1)>MovingAverage(t-1) && Close(t-
1)>MovingAverage(t-1)+((UP(t-1)-DOWN(t-1))/100);
Case3c = Open(t-1)>MovingAverage(t-1) && Close(t-
1)>MovingAverage(t-1) && Open(t-2)>MovingAverage(t-2) && Close(t-
2)>MovingAverage(t-2) && Open(t-3)>MovingAverage(t-3) && Close(t-
3)>MovingAverage(t-3) && Open(t-4)>MovingAverage(t-4) && Close(t-
4)>MovingAverage(t-4) && Open(t-5)>MovingAverage(t-5) && Close(t-
5)>MovingAverage(t-5) && Open(t-6)>MovingAverage(t-6) && Close(t-
6)>MovingAverage(t-6) && Open(t-7)>MovingAverage(t-7) && Close(t-
7)>MovingAverage(t-7) && Open(t-8)>MovingAverage(t-8) && Close(t-
8)>MovingAverage(t-8);
Case3d = Low(t-1)>MovingAverage(t-1) && Low(t-2)>MovingAverage(t-
2) && Low(t-3)>MovingAverage(t-3) && Low(t-4)>MovingAverage(t-4) &&
Low(t-5)<MovingAverage(t-5) && Close(t-5)<Open(t-5) && Close(t-
3)<Open(t-3) && Close(t-2)<Open(t-2) && Close(t-1)>Open(t-1) &&
Close(t-4)>Open(t-4);
% Cases for TRIX:
Case7 = TRIX(t-6)<TRMA(t-6) && TRIX(t-1)>TRMA(t-1);
Case8 = TRIX(t-5)>TRMA(t-5) && TRIX(t-1)<TRMA(t-1);
% Set buying and selling signal:
SignalBuy= ((Case1 == 1 && Case7 == 1) || (Case3b == 1 && Case7 ==
1) || (Case3c == 1 && Case7 == 1) || (Case3d == 1 && Case7 == 1));
SignalSell = ((Case2 == 1 && Case8 == 1) || (Case2a == 1 && Case8
== 1) || (Case2b == 1 && Case8 == 1) || (Case2c == 1 && Case8 == 1));
if (SignalBuy==1 && pos(t-1)==0)
pos(t) = 1;
text(Date(t),Close(t),'\leftarrowbuy');
plot(Date(t),Close(t),'go');
elseif (SignalSell==1 && pos(t-1)==1)
pos(t) = 0;
text(Date(t),Close(t),'\leftarrowsell');
plot(Date(t),Close(t),'bo');
else
pos(t) = pos(t-1);
end
end
% Total Return minus the commission fee: 0.1% stamp tax (only happen
when selling the stock); 0.3% brokerage charge:
TotalReturn(N-1) = InitialCapital;
for t=N:length(Close)
if pos(t)==0 && pos(t-1)==0
TotalReturn(t) = TotalReturn(t-1);
continue;
end
% Buy in
if pos(t)==1 && pos(t-1)==0
TotalReturn(t) = TotalReturn(t-1)*(1-0.003);
continue;
end
if pos(t)==1 && pos(t-1)==1
TotalReturn(t) = TotalReturn(t-1)*(Close(t)/Close(t-1));
continue;
end
% Sell out
if pos(t)==0 && pos(t-1)==1
TotalReturn(t) = TotalReturn(t-1)*(Close(t)/Close(t-1))*(1-
0.004);
continue;
end
end
% Total return with no commission fee:
TotalReturnNoTax(N-1) = InitialCapital;
for t=N:length(Close)
if pos(t)==0 && pos(t-1)==0
TotalReturnNoTax(t) = TotalReturnNoTax(t-1);
continue;
end
% Buy in
if pos(t)==1 && pos(t-1)==0
TotalReturnNoTax(t) = TotalReturnNoTax(t-1);
continue;
end
if pos(t)==1 && pos(t-1)==1
TotalReturnNoTax(t) = TotalReturnNoTax(t-1)*(Close(t)/Close(t-
1));
continue;
end
% Sell out
if pos(t)==0 && pos(t-1)==1
TotalReturnNoTax(t) = TotalReturnNoTax(t-1)*(Close(t)/Close(t-
1));
continue;
end
end
hold off;
% Draw the position:
figure(4);
plot(Date,pos,'b');
datetick('x','yyyymmdd');
xlabel('Date');
ylabel('The state of your account');
InitialCapitalLine = Close;
% One red line for closing price; One blue line for total return; One
yellow line for total return with no tax:
figure(5);
plot(Date,InitialCapitalLine,'r');
hold on
plot(Date,TotalReturn,'b');
hold on
plot(Date,TotalReturnNoTax,'y');
datetick('x','yyyymmdd');
xlabel('Date');
ylabel('Total Return');
title('The Return of Stock');
% Stock Yield:
StockYield = (TotalReturn(length(Close))-
InitialCapital)/InitialCapital
% Maximum Retracement Rate with its date:
RetracementRate = zeros(length(Close),1);
for t1 = N:length(Close)
for t2 = N:t1
RetracementRate(t1) = (max(TotalReturn(N:t1))-
TotalReturn(t1))/max(TotalReturn(N:t1));
end
end
[m,index]=max(RetracementRate);
DateNumber = Date(index)
MaximumRetracementRate = max(RetracementRate)
Reference
Bollinger, J. (2000). Bollinger on Bollinger Bands. Blacklick, USA: McGraw-Hill
Professional Publishing.
Mitchell, C. (2020). Using Bollinger Bands to Gauge Trends. Investopedia Stock
Analysis. Retrieved November 16, 2020, from
https://www.investopedia.com/trading/using-bollinger-bands-to-gauge-trends/
Staff, I. (2020). Advantages of Triple Exponential Average (TRIX). Investopedia Stock
Analysis. Retrieved August 5, 2020, from
https://www.investopedia.com/articles/technical/02/092402.asp
徐英, & 王素霞. (2017). MACD和 TRIX在股票投资中的应用。泰山学院学报,
39(3), 40-43.
Chen, J. (2019). Triple Exponential Average (TRIX). Investopedia Stock Analysis.
Retrieved July 21, 2019, from
https://www.investopedia.com/terms/t/trix.asp
Carr, M. (2019). Measure Volatility With Average True Range. Investopedia Stock
Analysis. Retrieved November 8, 2019, from
https://www.investopedia.com/articles/trading/08/average-true-range.asp
Hall, M. (2020). Enter Profitable Territory With Average True Range. Investopedia
Stock Analysis. Retrieved September 2, 2020, from
https://www.investopedia.com/articles/trading/08/atr.asp