Back
 OJAppS  Vol.11 No.10 , October 2021
Some Results of Stock Trading Strategy Based on Fuzzy System
Abstract: In order to better study the stock trend and master the basic rules of stock trading, this paper uses the fuzzy system theory to transform the technology trading strategy in stock into the membership function in fuzzy mathematics, so as to study the trend change of technology trading rules in dynamic stock price with mathematical language. It can be seen from the experimental results that when only the moving average rule is adopted, the stock price trend is relatively flat, and the specific changes of the price cannot be accurately obtained. However, when the bull and bear rule is added, the stock price jumps greatly, so that the changes of the price can be easily captured, so as to make corresponding strategic adjustments to maximize the income.

1. Introduction

With development of the society and improvement of economy, more and more people began to contact the stock and become shareholders. However, the stock market is like a sea, and blind purchase or following may bring economic losses. On the contrary, if reliable technical strategies are used for transactions, additional benefits may also be generated [1]. Therefore, it is necessary to understand some technical trading rules in the stock market.

There are many technical trading rules for studying stocks, such as MACD, KDJ, MA, etc., of which MA (Moving Average) is widely used. However, sometimes one indicator may not be able to directly determine the trend of stock price changes. For example, BBI (Bull And Bear) has only one average line, no comparison object, and cannot directly observe the price changes. Therefore, a better result can be obtained by combining with other indicators. For example, by combining BBI with MACD, we can find stocks in multi dominant and medium-term upward trend [2]. Wang [3] translated 12 trading strategies into price dynamic equation by using the fuzzy system in his article, including moving average rule, support and resistance rule, trend line rule, etc. These models were compared with random walk model; And through the simulation, it illustrates how the simple technical trading rules generate complex price changes. From the article, we can see that there is no significant difference between the individual moving average rule model and the random walk model in the price curve generated, but when other models such as the support and resistance rule are added to the price dynamic equation, the price curve has changed a lot. This further illustrates that sometimes using two trading strategies at the same time can better capture the price trend. In this paper, we use Wang’s method to combine MA and BBI, and study the trend changes of the stock price under these two trading strategies by transforming the technical trading rules into a mathematical function.

2. Moving Average Rule

Let N-day moving average of stock price p t be

p ¯ t , N = 1 N i = 0 N 1 p t i (1)

and

x t ( M , N ) = ln ( p ¯ t , M p ¯ t , N ) ( M < N ) (2)

is defined as the relative change of M-day and N-day price moving average.

Next, we define the membership function. Firstly, we divide the range of relative change x t ( M , N ) of stock price moving average into seven fuzzy sets: Positive Small, Positive Medium, Positive Large, Around Zero, Negative Small, Negative Medium, Negative Large. The membership functions corresponding to them are shown in Figure 1, and each fuzzy set can be represented by a piece-wise function. For example, the membership function of the fuzzy set NM is

μ N M ( x t ( M , N ) ) = { 1 | x t ( M , N ) + 2 w | w , x t ( M , N ) [ 3 w , w ] 0 , otherwise (3)

where w is a positive constant to describe the small or large. In this paper, we take w = 0.01 , which means that the difference between M-day moving average price and N-day moving average price is about 1%.

In order to transform technical trading rules into mathematical functions, we first transform technical trading rules into If-Then rules in fuzzy system theory, and then combine If-Then rules into fuzzy system, namely excess demand function. First, let a i ( t ) be the trading strength of a group of traders, then we can get the price dynamic model:

Figure 1. Membership functions of fuzzy sets (above) and trading signal (below).

ln ( p t + 1 ) = ln ( p t ) + i = 0 K a i ( t ) e d i ( x t ) (4)

where i = 0 , , K means there are K + 1 groups of traders who trade from t to t + 1 , and the same group of traders use the same trading technical.

Let ed be the trading intensity, which is used to represent excess demand. Then the buying and selling signal corresponding to the change of stock price is represented by fuzzy sets, which can also be divided into seven fuzzy sets: Buy Small, Buy Medium, Buy Big, Neutral, Sell Small, Sell Medium and Sell Big. The membership functions corresponding to them are shown in Figure 1, and each fuzzy set can also be represented by a piece-wise function. For example, the membership function of the fuzzy set SM is

μ S M ( e d ) = { e d + 0.4 0.2 , e d [ 0.4 , 0.2 ] e d + 0.1 0.1 , e d [ 0.2 , 0.1 ] 0 , otherwise (5)

Next, we transform the moving average rules into seven fuzzy If-Then rules in fuzzy system theory.

If x t ( M , N ) is Positive Small, Then e d 0 is Buy Small;

If x t ( M , N ) is Positive Medium, Then e d 0 is Buy Big;

If x t ( M , N ) is Positive Large, Then e d 0 is Sell Medium;

If x t ( M , N ) is Negative Small, Then e d 0 is Sell Small;

If x t ( M , N ) is Negative Medium, Then e d 0 is Sell Big;

If x t ( M , N ) is Negative Large, Then e d 0 is Buy Medium;

If x t ( M , N ) is Around Zero, Then e d 0 is Neutral.

The fuzzy rules used here are a corresponding formal transformation based on their corresponding rule definitions and fuzzy system theory. From the above seven rules, we can conclude that the excess demand function of the moving average rules is

e d 0 ( x t ( M , N ) ) = i = 1 7 c i μ A i ( x t ( M , N ) ) i = 1 7 μ A i ( x t ( M , N ) ) (6)

where A 1 = P S , A 2 = P M , A 3 = P L , A 4 = N S , A 5 = N M , A 6 = N L , A 7 = A Z , and c 1 = 0.1 , c 2 = 0.4 , c 3 = 0.2 , c 4 = 0.1 , c 5 = 0.4 , c 6 = 0.2 , c 7 = 0 are the centers of the fuzzy sets B S , B B , S M , S S , S B , B M , N , respectively.

Substitute (6) for (4) to get

ln ( p t + 1 ) = ln ( p t ) + a 0 ( t ) e d 0 ( x t ( M , N ) ) (7)

Equation (7) shows that traders use the moving average strategy to observe the change of stock prices. Let ( M , N ) = ( 1 , 5 ) , a 0 ( t ) = 0.2 , p 0 = 10 simulate equation (7), as shown in Figure 2.

The first 100 stock prices are generated by random walk model

ln ( p t + 1 ) = ln ( p t ) + σ ε t (8)

where ε t is a Gaussian random variable with a mean value of 0 and a variance of 1, and we take σ = 0.05 ; we take the random walk model as a contrast. The last 400 stock prices are generated by (7). From Figure 2, we can see that there is no big difference between the stock price curve generated by moving average rule and random walk model. In the next section, we will add the BBI to observe the stock prices trend changes.

3. Bull and Bear Rule

BBI is a common indicator to judge whether the stock is in a Bull or Bear state. Before converting the BBI index into the If-Then rule in the theory of fuzzy system, we first define the formula for calculating the Bull and Bear index. Here we understand that for the average value, the longer the period, the greater the change in the mean value, then for the original definition of BBI taking the average of different periods, the impact of the long period on the overall will be relatively large, so we adjust the weight of different periods in this paper. We give the maximum weight of 3 days average value of 0.4, and the weight of 6 days, 12 days and 24 days average value decreases by 0.1 in turn. It can be expressed by formula

b b i t ( N ) = 0.4 p ¯ t , 3 + 0.3 p ¯ t , 6 + 0.2 p ¯ t , 12 + 0.1 p ¯ t , 24 (9)

Figure 2. Three times dynamic simulation of stock price generated by random walk (0 - 100) and moving average (100 - 500).

If we record r = ( 0.4 , 0.3 , 0.2 , 0.1 ) , P ¯ t = ( P ¯ t , 3 , P ¯ t , 6 , P ¯ t , 12 , P ¯ t , 24 ) T , then (9) becomes

b b i t ( N ) = r P ¯ t (10)

The basic idea of BBI is that when the price breaks the short lines, it indicates that the situation of Bear positions or Bull positions is changing, and the trading decision can be made at this time. Specifically, we can write the following heuristics:

BBI heuristics:

A sell signal is generated if the stock price in the high price area with the closing price breaking through the BBI lines from the top to bottom;

A buy signal is generated if the stock price in the low price area with the closing price breaking through the BBI lines from the bottom up to.

Next, we translate the BBI heuristics into the If-Then rule in the theory of the fuzzy system. Before that, we first define the relative changes of the current price p t and the BBI line b b i t ( N ) as follows:

x t ( N ) = ln ( p t b b i t ( N ) ) (11)

Now we transform the BBI heuristics into the If-Then rules in the theory of the fuzzy system:

If x t ( N ) is Negative Small, Then e d 1 is Sell Small;

If x t ( N ) is Negative Medium, Then e d 1 is Sell Medium;

If x t ( N ) is Negative Large, Then e d 1 is Sell Big;

If x t ( N ) is Positive Small, Then e d 1 is Buy Small;

If x t ( N ) is Positive Medium, Then e d 1 is Buy Medium;

If x t ( N ) is Positive Large, Then e d 1 is Buy Big.

The combination of these rules into a fuzzy system is as follows:

Figure 3. Three times stock price dynamic simulation generated by random walk (0 - 100) and model (12) (100 - 500).

e d 1 ( x t ( N ) ) = i = 1 6 c i μ A i ( x t ( N ) ) i = 1 6 μ A i ( x t ( N ) ) (12)

where A 1 = N S , A 2 = N M , A 3 = N L , A 4 = P S , A 5 = P M , A 6 = P L , c 1 = 0.1 , c 2 = 0.4 , c 3 = 0.2 , c 4 = 0.1 , c 5 = 0.4 , c 6 = 0.2 are the centers of the fuzzy sets S S , S M , S B , B S , B M , B B , respectively.

Substituting (6) and (11) into (4) gives

ln ( p t + 1 ) = ln ( p t ) + a 0 e d 0 ( x t ( M , N ) ) + a 1 e d 1 ( x t ( N * ) ) (13)

Formula (13) indicates that 2 groups of traders conduct a transaction at the same time, with one group using the moving average strategy and the other group using the BBI strategy. We simulated (13) three times with p 0 = 10 , a 0 = 0.2 , a 1 = 0.01 , ( M , N ) = ( 1 , 5 ) , N * = 100 , w = 0.01 as shown in Figure 3, in which the first 100 pt were still generated by the random walk model (8) and the last 400 pt were generated by the model (13).

From Figure 3, we can see that compared with the first 100 pt curves generated by the random walk model, the pt curves generated by the latter 400 moving average rules and BBI rules at the same time fluctuate more sharply, which indicates that after we add BBI indicators into the dynamic equation, the stock price shows more trends. Therefore, we can see that the combination of the two indices can better observe the trend of stock prices.

4. Conclusions

People who understand the stock know that the stock price is not all spontaneous, but can be controlled by people, mainly determined by the behavior of stock traders. And with the in-depth understanding of the stock, we can understand the importance of technical trading. Although it is a fuzzy system, it is also a fuzzy set divided according to the actual problems, and the last step in the whole process is accurate calculation. Therefore, as long as the division is reasonable and in line with the reality, the final calculation result of the fuzzy system is accurate enough. At the same time, the speed is also considerable. The model of hundreds of data takes only a few seconds [4]. As for the stability and robustness of fuzzy control, firstly, fuzzy control has strong stability and robustness, because it is constructed by people’s experience and knowledge, and has certain reliability in application. Secondly, for the fuzzy system, we only input the required variables without redundant interference, which makes the system relatively simple and has no other complex programs, so it can run stably [5].

In this paper, the stock technical trading strategy is combined with the theory of fuzzy system, which is further transformed into a specific mathematical language to study the dynamic changes of the stock prices, and explains how the rules of technical trading affect the prices. From Figure 2 and Figure 3, we can see that when the BBI is added to the dynamic equation, the price will change significantly, that is, when the moving average strategy and the BBI strategy are combined to observe the stock price, we are more likely to capture the price changes. Therefore, we conclude that sometimes it is clearer and easier to capture the trend by combining the two indices to observe the changes in the stock prices. In the future, we can convert more technical trading rules into dynamic price equation, and combine more indicators to better observe the trend of changes in the stock market.

Cite this paper: Xu, S. (2021) Some Results of Stock Trading Strategy Based on Fuzzy System. Open Journal of Applied Sciences, 11, 1102-1108. doi: 10.4236/ojapps.2021.1110082.
References

[1]   Wang, L. (2015) Dynamical Models of Stock Prices Based on Technical Trading Rules— Part III: Application to Hong Kong Stocks. IEEE Transactions on Fuzzy Systems, 23, 1680-1697.
https://doi.org/10.1109/TFUZZ.2014.2374193

[2]   Song, J. (2015) Theory and Practice of Technical Analysis of Stock Market. Lanzhou University, Lanzhou.

[3]   Wang, L. (2015) Dynamical Models of Stock Prices Based on Technical Trading Rules Part I: The Models. IEEE Transactions on Fuzzy Systems, 23, 787-801.
https://doi.org/10.1109/TFUZZ.2014.2327994

[4]   Xie, J.J. and Liu, C.P. (2013) Fuzzy Mathematics Method and Its Application. 4th Edition, Huazhong University of Science and Technology Press, Wuhan.

[5]   Li, C.J., Wang, L. and Dai, G.Z. (1999) Study on Stability of Fuzzy Control System. Measurement and Control Technology, 7, 4-7.

 
 
Top