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 . 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 . Wang  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

${\stackrel{¯}{p}}_{t,N}=\frac{1}{N}\underset{i=0}{\overset{N-1}{\sum }}{p}_{t-i}$ (1)

and

${x}_{t}^{\left(M,N\right)}=\mathrm{ln}\left(\frac{{\stackrel{¯}{p}}_{t,M}}{{\stackrel{¯}{p}}_{t,N}}\right)\left(M (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}^{\left(M,N\right)}$ 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

${\mu }_{NM}\left({x}_{t}^{\left(M,N\right)}\right)=\left\{\begin{array}{l}1-\frac{|{x}_{t}^{\left(M,N\right)}+2w|}{w},{x}_{t}^{\left(M,N\right)}\in \left[-3w,-w\right]\\ 0,\text{otherwise}\end{array}$ (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}\left(t\right)$ 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).

$\mathrm{ln}\left({p}_{t+1}\right)=\mathrm{ln}\left({p}_{t}\right)+\underset{i=0}{\overset{K}{\sum }}{a}_{i}\left(t\right)e{d}_{i}\left({x}_{t}\right)$ (4)

where $i=0,\cdots ,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

${\mu }_{SM}\left(ed\right)=\left\{\begin{array}{l}\frac{ed+0.4}{0.2},\text{}ed\in \left[-0.4,-0.2\right]\\ -\frac{ed+0.1}{0.1},ed\in \left[-0.2,-0.1\right]\\ 0,\text{otherwise}\end{array}$ (5)

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

If ${x}_{t}^{\left(M,N\right)}$ is Positive Small, Then $e{d}_{0}$ is Buy Small;

If ${x}_{t}^{\left(M,N\right)}$ is Positive Medium, Then $e{d}_{0}$ is Buy Big;

If ${x}_{t}^{\left(M,N\right)}$ is Positive Large, Then $e{d}_{0}$ is Sell Medium;

If ${x}_{t}^{\left(M,N\right)}$ is Negative Small, Then $e{d}_{0}$ is Sell Small;

If ${x}_{t}^{\left(M,N\right)}$ is Negative Medium, Then $e{d}_{0}$ is Sell Big;

If ${x}_{t}^{\left(M,N\right)}$ is Negative Large, Then $e{d}_{0}$ is Buy Medium;

If ${x}_{t}^{\left(M,N\right)}$ 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}\left({x}_{t}^{\left(M,N\right)}\right)=\frac{\underset{i=1}{\overset{7}{\sum }}{c}_{i}{\mu }_{{A}_{i}}\left({x}_{t}^{\left(M,N\right)}\right)}{\underset{i=1}{\overset{7}{\sum }}{\mu }_{{A}_{i}}\left({x}_{t}^{\left(M,N\right)}\right)}$ (6)

where ${A}_{1}=PS$, ${A}_{2}=PM$, ${A}_{3}=PL$, ${A}_{4}=NS$, ${A}_{5}=NM$, ${A}_{6}=NL$, ${A}_{7}=AZ$, 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 $BS,BB,SM,SS,SB,BM,N$, respectively.

Substitute (6) for (4) to get

$\mathrm{ln}\left({p}_{t+1}\right)=\mathrm{ln}\left({p}_{t}\right)+{a}_{0}\left(t\right)e{d}_{0}\left({x}_{t}^{\left(M,N\right)}\right)$ (7)

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

The first 100 stock prices are generated by random walk model

$\mathrm{ln}\left({p}_{t+1}\right)=\mathrm{ln}\left({p}_{t}\right)+\sigma {\epsilon }_{t}$ (8)

where ${\epsilon }_{t}$ is a Gaussian random variable with a mean value of 0 and a variance of 1, and we take $\sigma =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

$bb{i}_{t}^{\left(N\right)}=0.4{\stackrel{¯}{p}}_{t,3}+0.3{\stackrel{¯}{p}}_{t,6}+0.2{\stackrel{¯}{p}}_{t,12}+0.1{\stackrel{¯}{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=\left(0.4,0.3,0.2,0.1\right)$, ${\stackrel{¯}{P}}_{t}={\left({\stackrel{¯}{P}}_{t,3},{\stackrel{¯}{P}}_{t,6},{\stackrel{¯}{P}}_{t,12},{\stackrel{¯}{P}}_{t,24}\right)}^{\text{T}}$, then (9) becomes

$bb{i}_{t}^{\left(N\right)}=r{\stackrel{¯}{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 $bb{i}_{t}^{\left(N\right)}$ as follows:

${x}_{t}^{\left(N\right)}=\mathrm{ln}\left(\frac{{p}_{t}}{bb{i}_{t}^{\left(N\right)}}\right)$ (11)

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

If ${x}_{t}^{\left(N\right)}$ is Negative Small, Then $e{d}_{1}$ is Sell Small;

If ${x}_{t}^{\left(N\right)}$ is Negative Medium, Then $e{d}_{1}$ is Sell Medium;

If ${x}_{t}^{\left(N\right)}$ is Negative Large, Then $e{d}_{1}$ is Sell Big;

If ${x}_{t}^{\left(N\right)}$ is Positive Small, Then $e{d}_{1}$ is Buy Small;

If ${x}_{t}^{\left(N\right)}$ is Positive Medium, Then $e{d}_{1}$ is Buy Medium;

If ${x}_{t}^{\left(N\right)}$ 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}\left({x}_{t}^{\left(N\right)}\right)=\frac{{\sum }_{i=1}^{6}{c}_{i}{\mu }_{{A}_{i}}\left({x}_{t}^{\left(N\right)}\right)}{{\sum }_{i=1}^{6}{\mu }_{{A}_{i}}\left({x}_{t}^{\left(N\right)}\right)}$ (12)

where ${A}_{1}=NS$, ${A}_{2}=NM$, ${A}_{3}=NL$, ${A}_{4}=PS$, ${A}_{5}=PM$, ${A}_{6}=PL$, ${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 $SS,SM,SB,BS,BM,BB$, respectively.

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

$\mathrm{ln}\left({p}_{t+1}\right)=\mathrm{ln}\left({p}_{t}\right)+{a}_{0}e{d}_{0}\left({x}_{t}^{\left(M,N\right)}\right)+{a}_{1}e{d}_{1}\left({x}_{t}^{\left({N}^{*}\right)}\right)$ (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$, $\left(M,N\right)=\left(1,5\right)$, ${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 . 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 .

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

   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

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

   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

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

   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