Abstract

The “classical pattern” of stock price formation has long been widely used in the determination of future price trends of stocks, and the identification and analysis of classical price patterns have an important guiding role in investors’ decision-making and trading. The wavelet transform is a useful tool to remove some of the noise of time series because it has the characteristic of multiresolution. In this study, we propose a method for stock price pattern recognition based on the wavelet transform and dynamic time warp (DTW). A pattern recognition method with similar quantified results is developed to obtain accurate pattern recognition results. That is, using the wavelet transform to smooth the original price graph, and then using the DTW algorithm improved in this study to find the graph with the smallest distance from the target graph under the sliding window method, the identification and analysis of the target graph can be realized. In order to improve the recognition rate of the target graph, we preprocessed the raw price sequence using the moving average convergence and divergence (MACD) algorithm based on the control experiments set up in this study. The pattern recognition method used in this study will identify the price patterns of a certain time window as a whole, thus avoiding the problem of how to objectively select the important points that constitute a price pattern and the mathematical definition of different price patterns in the previous traditional methods.

1. Introduction

Technical analysis based on trading pattern curves is an important method for quantitative analysis of stocks, and in recent years, there have been a number of scholars who have proved the effectiveness of technical analysis from different perspectives as an effective means of extracting information from market prices [13]. With the development of financial engineering, computer technology, and mathematical algorithms, technical analysts using traditional trading model analysis methods now regularly use statistical software packages and other data processing techniques. The use of data analytics can minimize or even completely eliminate human subjective influences and turn trading into a scientific practice. Therefore, it is important to find a method that can quickly and efficiently identify trading pattern curves automatically to help investors grasp the volatility patterns of the stock market.

Existing stock pattern recognition methods can be divided into rule-based pattern recognition and template-based pattern recognition, both of these methods are based on the extraction of important points and are subjective in nature. Therefore, this study attempts to use the overall graphical identification, that is, the overall identification of the price pattern of a certain time window the abovementioned approach can avoid the problem of how to objectively select the important points that constitute the price pattern and the mathematical definition of different price patterns. Based on this, this study selects an arbitrary time window from the A-share market as the target graph, which avoids mathematical definition of price patterns and increases the universality of the method. The appropriate wavelet parameters are then selected by empirical analysis and the original price series is smoothed using the wavelet transform. An improved DTW algorithm is used to accurately identify the target pattern by finding the stock among the remaining stocks that is most similar to the target pattern. Scholars also recently used machine learning or other intelligent algorithms for financial time series graph identification, but the basic approach is consistent with the abovementioned two categories [46].

The main tasks of this study include the following: (1) the entropy weighting method is used to determine the weights of the two indicators of information extraction rate and information extraction error, and then to determine the composite indicators according to their weights, and finally to determine the number of optimal decomposition layers of the wavelet and the selection of the wavelet threshold function based on the value of the composite indicators. (2) The DTW algorithm is improved to overcome the problem that the algorithm itself is far away from similar shapes with certain phase differences. This study uses an improved DTW algorithm with a sliding time window algorithm to find the most similar time window to the target graph. (3) Attempt to compare the average rise and fall of the target graph to its similar graph sixty days later and determine that it is a realistic guide.

The overall structure of this article is as follows. Section 1 is an introduction that reviews the background of graphic recognition technology and the main work of this study. Section 2 presents work on graph recognition. Section 3 briefly introduces wavelet denoising and the theoretical foundations of MACD metrics and explains the principles of the wavelet threshold function. Section 4 describes technological improvements related to the characteristics of financial time series. Section 5 empirically determines the number of layers of the wavelet optimal decomposition as well as the threshold function and the graphs most similar to the target graphs found by the abovementioned methods. Section 6 compares the optimal graph with the forty-day rise and fall of the target graph. Finally, we conclude this study in Section 7. The specific research ideas are shown in Figure 1.

The current research on automatic price pattern recognition has fallen into two main categories as rule-based pattern recognition and template-based pattern recognition.

Lo et al. [7] were the first to mathematically define ten price patterns such as head-and-shoulders and double-bottoms using the partial pole method. He proposed a systematic, automated method for technical pattern identification using nonparametric kernel regression and applies the method to a large number of U.S. stocks from 1962 to 1996 to evaluate its effectiveness for technical analysis. The abovementioned method creatively realizes the automatic recognition of price patterns by computer. Suh et al. [8] defined a Bezier curve as consisting of seven significant points and then identifies the pattern of the “cup with handle” by calculating the correlation coefficient between the time window and the Bezier curve. Savin et al. [9] used the pattern recognition algorithm of Andrew W with some modifications to determine whether “head-and-shoulders” (HS) price patterns have predictive power for future stock returns. Zapranis and Tsinaslanidis [10] represented the ideal circular base as an isosceles triangle formed by three key points and then used the two congruent circles on the outer ring of this triangle to control price fluctuations. The final two-dimensional coordinates of price and time were used for automatic pattern recognition.

Template-based pattern recognition is the network lattice method represented by Leigh et al. [11]. Leigh represented the flag as a weight-based grid and used it as a template to compare it with a time series window and determined whether the sequence matches the template based on the price percentile and a genetic algorithm. Wang and Chan [12] used the flag template method, which represents the top and bottom of the dome as a network lattice based on price fluctuations, as a template for identifying and examining buy signals. Royo et al. [13] defined flags from a new perspective and modified the grid weights.

Directly using an existing stock pattern curve as a template before using either of these methods will likely lead to overfitting and will be inefficient, also the accuracy and reliability of the analysis will be compromised [14, 15]. Therefore, when studying complex time series, scholars will first perform some preprocessing on the raw data. In order to improve the mining efficiency, scholars have proposed an approximate representation of the time series, which is a compressed representation of the time series, by retaining the main information of the time series and ignoring the tiny details. The current time series approximation methods have included discrete Fourier transform [16], discrete wavelet transform [17], piecewise aggregate approximation [18], symbolic aggregate approximation [19], and singular value decomposition [20]. Pattern recognition belongs to a type of time series mining. In conjunction with the above overview of price pattern recognition, time preprocessing before pattern recognition can be broadly divided into two categories. (1) Nonlinear curve description. Commonly used methods are nonparametric kernel regression methods and Gaussian kernel estimation methods. Dong used a Gaussian kernel estimation method to smooth the estimation process on the raw data [21]. (2) Approximate representation based on segmentation. For example, Keogh et al. [22] proposed a bottom-up approach for segmenting time series and extracting their features. Gong reduced the complexity of time series using perceived important points proposed by Chung [23, 24].

Wavelet transform has been an important way to preprocess time series, especially for nonstationary, nonlinear, and heteroskedastic signals [25]. Therefore, many scholars have used wavelet transforms to preprocess the raw data before building stock prediction models. The most used predictive model is the neural network algorithm [2628]. The abovementioned prediction models show that the prediction accuracy of the original data is greatly improved after wavelet transform processing. In addition to neural network algorithms, there are other algorithms such as SVMs that are combined with wavelet transforms. The experimental results also showed that the hybrid model incorporating the wavelet transform is better than the prediction using a single algorithm [2932]. DTW is a kind of elastic measurement for calculating time series similarity [3335]. As DTW can extract morphological features of time series and handle time transformations and distortions, it can be used for pattern representation of stock time series. For example, Han developed a portfolio optimization model with strict constraints to obtain a pattern representation of stock time series based on DTW [35].

According to the abovementioned research, at present for the price pattern automatic identification has achieved some results, there is still room for improvement: (1) in the study of automatic price pattern recognition, the time series preprocessing method is relatively homogeneous. Due to the needs of pattern recognition, the automatic identification of price patterns uses a single method. (2) The extraction of important points in the perception of important points method is highly subjective. (3) In identifying patterns, most studies have used the sliding window method, which allows for the existence of other points between the extreme points of the pattern, but does not consider the relationship between the extreme points of the pattern and other points, which is prone to misjudgment. For this reason, the study will combine the advantages of DTW and wavelet transform to establish a time series expression based on holistic graphs.

3. Theoretical Foundation

3.1. Wavelet Denoising Principle

Set a noise-containing sequence F(t), which can be represented by the following model:

In the above equation, s(t) is the true sequence and e(t) is the white noise.

Suppose that the noise e(t) is white noise with zero mean and variance . Set the wavelet function to , to be the wavelet transform of e(t), which is obtained from the continuous wavelet transform theory.

It is known from the hypothesis that

Substituting the formula in (2) into (3) gives the following reasoning:

The purpose of sequence f(t) denoising is to suppress the noisy part of the sequence e(t) to obtain the true sequence s(t); it follows from the abovementioned reasoning that the noise wavelet transformed is inversely proportional to the scale a. Therefore, it is possible to denoise the sequence using the different characteristics exhibited at each scale after the noise and sequence wavelet transform.

3.2. Wavelet Denoising Principle

The method was proposed by Donoho and Johnstone [36]. The basic principle is that the orthogonal wavelet decomposition has the ability of time-frequency local decomposition. When performing sequence processing, the wavelet component exhibits a large amplitude, in contrast to the uniform variation of the noise in the high-frequency part. The larger amplitude wavelet coefficients are overwhelmingly useful sequences; the smaller amplitude coefficients are generally noise after wavelet decomposition. That is, it can be assumed that the wavelet transformation coefficient of the useful sequence is greater than the wavelet transformation coefficient of the noise. Then, a suitable threshold is selected according to certain rules, wavelet coefficients greater than the threshold are retained while wavelet coefficients smaller than the threshold are processed accordingly, and finally the useful sequence is reduced according to the processed wavelet coefficients. The key to the threshold denoising method is to pick an appropriate threshold value. According to the relationship between wavelet coefficients and the threshold, the threshold function can be divided into hard threshold denoising, soft threshold denoising, and zero-threshold denoising method. In addition, there are other threshold denoising methods, such as suppressing detail denoising (suppressing certain layers to obtain detail coefficients based on actual denoising requirements). These four threshold denoising methods are compared in detail in the experimental section of this study.

Suppose that the time series equation is as follows:

The result of doing the wavelet transform on both sides of the above equation simultaneously is as follows:

The wavelet transform of the actual sequence is equal to the sum of multiple wavelet transforms. The orthogonal wavelet transform of the original time series is able to remove the f(t) correlation to the greatest extent possible, retaining a few and relatively large amplitudes on the wavelet coefficients to a large extent, while the noise e(t) will be distributed across all time axes at all scales with relatively small amplitude after wavelet transformations. According to the abovementioned principle, the wavelet coefficients of the noise are minimized at each scale of the wavelet transform, and then the processed wavelet coefficients are used for sequence reconstruction to suppress the noise. The specific steps of the abovementioned method are shown in Figure 2.

3.3. MACD Fundamentals

In order to get better experimental results, this study uses the MACD algorithm to process the raw data to form a new MACD curve and then uses the DTW algorithm to compare the distance between the MACD curves. The MACD algorithm is a trend-following momentum indicator that shows the relationship between two moving averages of a security’s price. This preprocessing method can be used to eliminate price disturbances and enhance the trend of the original price graphs, ultimately resulting in a better fit. The mathematical principle of the MACD algorithm is as follows:

EMA(t) is a moving average of t days, EMA(t − 1) is yesterday’s moving average, n is the period, and price is the original price series. t-day maps t different weights. From the above equation, the weights increase over time, so EMA(t) is a better reflection of the future trend of the price chart line. DIF (the difference between the short-term average price of a stock and its long-term average price) is defined as follows:

is a fast-moving average and is a slow-moving average; the difference between the two can reflect the future upward or downward trend of the price chart line. DEA (difference exponential average) is defined as follows:

A weighted average was applied to the abovementioned DIFs, with the same weight settings as EMA. In the above equation, is the previous period DEA. HIST (histogram) is defined as follows:

From the above formula, the HIST can better reflect the rise and fall of the original price series and eliminate the influence of price on the DTW algorithm. In this study, the closing price of 000009.sz from January 1, 2019, to July 24, 2020, is selected and the relevant graph line is plotted as shown in Figure 3.

It is obvious from the abovementioned chart, the original price sequence chart line (signal line in the chart) increase is basically consistent with the MACD column in the chart, so the MACD column line can reflect the increase of the original chart line. In addition to the above advantages, MACD removes price distractions when fitting graphs. Therefore, this study converts the standard graph line to an MACD line as shown in Figure 4.

3.4. The Process of Rolling Window with DTW

The article selected the raw price series with m data points as the target graphic. The remaining stock price series with n data points is then divided chronologically into subsegments with m data points. A total of (n/m) subsequence fragments can be obtained, and the subsequence fragments are labeled using Window(i). The window(i) with the smallest distance from the target graph is obtained using the DTW algorithm. The rolling window process with DTW is shown in Figure 5.

4. Financial Time Series Wavelet Denoising Analysis and DTW Improvements

The time series can be smoothed using the abovementioned theory, but there is still the problem of parameter determination. According to the flow of financial time series processing by Lan and Ma [37], there are three important parameters that affect the final denoising effect: the choice of the wavelet base function, the number of decomposition layers, and the choice of the threshold function.

4.1. Characteristics of Financial Time Series

Stock price data, which is typical of financial data, commonly includes stock trading data and yield data calculated from trading data. However, both types of data exhibit an unsteady nature and the data are more volatile. In particular, financial time series are densely populated with singularities, so it is generally difficult to smooth out the financial time series. In addition to large fluctuations, there are small fluctuations in the data, which are highly stochastic and spread throughout the time window. Generally, large fluctuations contain more useful information and are therefore generally retained as useful information; a large number of small fluctuations are generally chosen to be removed due to their randomness and lack of value for analysis and prediction.

4.2. Selection of the Wavelet Function

At present, wavelet functions are more diverse and have different properties, which are suitable for different scenarios. The purpose of this study is to identify the graph of a stock in a given time window. Different wavelet functions have different denoising effects, so it is important to choose the right wavelet function. The following analysis of wavelet function characteristics is closely related to denoising.

Because there is often a correlation between wavelet function properties (it has been shown that there is no symmetric tightly-branched orthogonal wavelet base, except for the Harr wavelet), it is impossible to find a wavelet function that has all the optimal properties. The purpose of this study is to smooth the financial time series and different wavelet functions correspond to different denoising effects; it is crucial to choose the appropriate wavelet function. The following analysis focuses on a number of features that are closely related to the noise removal effect.(1)Orthogonality: the wavelet function with orthogonality can maintain the noncorrelation between the wavelet coefficients to improve the denoising performance of the wavelet function. More importantly, orthogonality is necessary to achieve fast wavelet transforms, and thus orthogonality is necessary to achieve wavelet denoising.(2)Compact support: it means that the wavelet function is nonzero in the effective interval, so the smaller the support width of the wavelet or scale function, the better the local resolution of the wavelet and the finer the denoising effect.(3)Vanishing moment: since there are a certain number of singularities in the financial time series, it is necessary to apply a certain vanishing moment so that as many wavelet coefficients as possible are zero or generate as few nonzero wavelet coefficients as possible to increase the denoising effect. The larger the vanishing moment, the more wavelet coefficients are zero, so there is a positive correlation between the vanishing moment and the width of the support. That is why there is a compromise between the vanishing moment and the width of the support. The vanishing moment is proportional to the number of singularities present in the sequence, while the stock price sequence has more singularities, so the vanishing moment can be increased accordingly.(4)Symmetry: the wavelet function with symmetry will reduce the error after wavelet transformation, so this property is conducive to the recovery and reconstruction of the sequence after noise removal. However, this property has less influence on the noise removal effect than other properties. This study finds a number of commonly used wavelet functions to examine, the properties of which are shown in Table 1.

For the aforementioned wavelet function, SymN is the best choice for the following reasons: (1) it is orthogonal, enabling wavelet denoising. (2) There are more “spikes” in the stock price sequence, so it is necessary to ensure that the wavelet has a vanishing moment. SymN is the best choice because of the compromise between the vanishing moment and the width of the support. (3) SymN has better symmetry than DbN as well as Conif, which can reduce errors during sequence reconstruction.

4.3. Determination of the Number of Decomposition Layers
4.3.1. Wavelet Noise Reduction Evaluation Index

Since wavelet denoising is mostly used inside engineering, the requirements for denoising in engineering are different from the requirements for denoising in finance. In order to measure the effect of sequence denoising, the article defines two variables, information extraction rate (IER) and information extraction error (IEE), drawing on the wavelet threshold method selected by Liu [38] to measure the effect of sequence denoising, considering f as the original time series, as the denoised time series, and IEE and IER defined as follows:

From the above equation, the information extraction rate is positively related to the similarity of the denoised sequence to the original sequence. The larger the information extraction error, the smoother the denoised sequence is compared to the original sequence. The abovementioned two indicators are negatively correlated, and if the information extraction rate is combined with the information extraction error to form a composite evaluation indicator, the process of increasing the number of decomposition layers will inevitably result in a maximum value. The graphical interpretation of this maximum value is the optimal ratio of the sequence in retaining detail information to its approximation information, which corresponds to the number of decomposition layers. The above demonstrates the feasibility of using a combination of information extraction rates and information extraction errors to form new composite evaluation indicators through theoretical analysis and also based on the numerical characteristics of the indicator changes.

4.3.2. Establishment of Composite Evaluation Indicators

Different evaluation indicators have different scales and units, and in order to eliminate the incommensurability this brings, the study treats each evaluation indicator as nonquantitative. In order to preserve the difference between the information extraction rate and the information extraction error, this study chooses to use the averaging method in the no-quantization method. If there are m indicators in the composite evaluation, each with n units, the indicators are (i = 1, 2, ..., n; j = 1, 2, ..., m), which represents the jth indicator value of the i-th unit, and represents the jth index value of the i-th unit after dimensionless homogenization. The formula is as follows:

The mean value of each indicator after the mean method is 1 and its variance is as follows:

The variance of each indicator after averaging is the square of the coefficient of variation of each indicator, which retains information on the degree of variation of each indicator. After averaging, the indicators become the same order of magnitude, and if they are to be combined linearly, weights need to be assigned to each indicator. Since the averaging method preserves the variability among the indicators, then weighting requires the elimination of the variability among the indicators, for which entropy weighting is chosen in this study. Entropy is an ideal metric for multiobjective decision-making and evaluation. It relies on the amount of decision-making information to improve the accuracy of decision-making, so it can objectively reflect the implicit information of the indicator data, improve the resolution of the indicators, avoid the selection bias caused by small differences in indicators, and reflect a full range of indicator information. There is an inverse relationship between the entropy of an indicator and its weight. According to the concept of entropy, entropy Q is defined as follows:

In the above equation, is defined as follows:

In the above equation, is defined as follows:

The above equation satisfies .

The use of entropy weighting allows for the combination of multiple metrics to determine weights, both to account for associations between multiple samples and to weaken the effect of outliers. The choice of entropy weighting and a measureless mean, i.e., a combination of differential and nondifferential, would theoretically be a good one.

According to the abovementioned method, wavelet decomposition is first performed on the original time series to calculate the and for different decomposition scales J. Then, the dimensionless averaging process is performed to get the and . Finally, the information extraction rate weights and the information extraction error weights are calculated from the entropy weights. Then, the formula for the value of composite indicator S is as follows:

4.4. DTW Algorithm Improvement

The main objective of the study is to fit the graphs formed by stock prices in a particular time window, and the degree of similarity of the fit is achieved by the DTW algorithm. In order to improve the fit to the target graph, this study makes improvements to the traditional DTW algorithm. The article randomly constructs three sequences of length 20, where s2 is derived from s1 translation and s3 has no relationship with either of the above. The three sequences are shown in Figure 6.

The distance between s1 and s2 is 5 and the distance between s1 and s3 is 4.12, calculated using the traditional DTW algorithm. Thus, it can be seen that the traditional DTW algorithm is not very effective for the distance of the postshift sequence. This study proposes an improved DTW algorithm.(1)Determine the largest common substring of the two sequences seq1 and seq2, the length of which is given by a.(2)seq1 and seq2 are numerical sequences that set a maximum standard deviation of the offset tolerance in finding the longest public sequence. In other words, two values within this standard deviation are considered to be part of the public sequence as well.(3)Define the attenuation factor as follows:The length of the common subsequence of both sequences is negatively correlated with its attenuation coefficient, thus enabling improvement of the algorithm. The distance between s1 and s2 is 0.982 and the distance between s1 and s3 is 2.512, as recalculated by the improved algorithm. It follows that the improved DTW algorithm effectively reduces the distance between the periodic sequences after translation.

5. Experimental Demonstration and Analysis

5.1. Methodology

This study arbitrarily selects five stocks in the A-share market as the target graphics and determines the wavelet denoising parameters by the abovementioned entropy weighting method. An improved DTW algorithm is then used to find other stock time windows from the stock market that are the least distant from it. In order to achieve better experimental results, this study introduces MACD algorithm to convert the original price series into “MACD graph line” on the basis of wavelet denoising. Then, the distance between the calculated original price series is transformed into the distance between “MACD lines,” which improves the accuracy of the result.

5.2. Source of Experimental Data

All stock data in this study are from the Tushare website (https://tushare.pro) and include trading date, opening price, high price, low price, closing price before compounding, and uncompounded upside and downside. Stock data are daily data and the time frame studied is from the listing of each stock to July 24, 2020.

5.3. Wavelet Denoising Preprocessing
5.3.1. Stock Price Sequence Wavelet Denoising Process
(1)Choose the appropriate wavelet base function and decomposition layer N for the time series f.(2)Threshold quantification of the decomposed high-frequency coefficients is performed, and for each layer from 1 to N, the appropriate threshold and the appropriate threshold function are selected to obtain the estimated wavelet coefficients.(3)The original time series is reconstructed (performing wavelet inversion) based on the low-frequency coefficients (scale coefficients) of the Nth layer after wavelet decomposition and the high-frequency coefficients (wavelet coefficients) of each layer after threshold quantization. The wavelet reconstruction is then performed using the reconstruction algorithm to obtain the denoised postdecomposition sequence.Because the daily stock closing price sequence is essentially a one-dimensional discrete sequence, this focuses on the wavelet decomposition of the one-dimensional discrete sequence. Experiments show that when a white noise sequence is wavelet decomposed, it can be found that the decay rate of the high-frequency coefficient after wavelet decomposition is proportional to the number of layers of wavelet decomposition, and the variance of the same coefficient is inversely proportional to the number of layers of wavelet decomposition. Thus, for the general case, there is a positive relationship between the number of decomposed layers and the smoothness of the denoised sequence. Therefore, in this study, we have to find the most suitable wavelet denoising parameters based on the characteristics of the stock price sequence.
5.3.2. Wavelet Denoising Parameter Investigation

This study selects five stocks in the China A-share market (ticker symbols: 300327.SZ, 300332.SZ, 300336.SZ, 601567.SH, and 601616.SH) as target patterns I–V, respectively. The results of denoising the abovementioned five target graphics using hard threshold, soft threshold, zero threshold, and inhibited detail factor threshold functions combined with the wavelet decomposition layer number method are shown in Tables 25.

From Table 5, it can be seen that the integrated index score of wavelet decomposition layers and threshold function shows a trend of increasing and then decreasing, and when the number of wavelet decomposition layers is 4 and the suppression detail factor threshold method is selected, the integrated evaluation index value is the largest, and this experimental result is consistent with the results of the previous mathematical derivation. The data of the abovementioned five stocks are obtained by random sampling, but they all show the maximum value on the same parameters as above, which fully demonstrates the generalizability of the method.

The abovementioned five graphics are compared with the original graphics after the abovementioned wavelet denoising method which is shown in Figure 7.

5.4. Finding Time Windows Similar to the Target Graph Using the DTW Algorithm

This study selects five stocks in the China A-share market (ticker symbols: 300327.SZ, 300332.SZ, 300336.SZ, 601567.SH, and 601616.SH) as target patterns I–V, respectively. The optimal DTW distances and similarities found using the abovementioned methods, respectively, are shown in Table 6. The time complexity of all the abovementioned algorithms is .

The above results show that there is a significant improvement in the final similarity of the original data smoothed using wavelet denoising compared to using the original data directly (the average similarity of the five graphs of the three methods is 0.3612, 0.5075, and 0.8936). This result verifies the need for wavelet denoising. The final similarity of using MACD data compared to direct use of raw data is also significantly improved. Therefore, the final graph recognition method used in this study is to first transform the original data into MACD graphs, then use wavelet denoising to smooth the MACD graphs, and finally use the improved DTW algorithm to achieve effective recognition of the target graphs. The most similar graphs of the five abovementioned SDs after wavelet preprocessing and direct search using the DTW algorithm are shown in Figure 8. The most similar graphs found using the DTW algorithm after the abovementioned five target graphs were processed by MACD and then denoised using wavelets, as shown in Figure 9.

6. Empirical Analysis of China’s A-Share Market

In order to find out the pattern of the stock market in the short-term and to compare the effectiveness of the abovementioned two methods, the article calculates the average upside and downside of the current time window of the underlying graph and the average upside and downside of the 40-day time window of the optimal graph after the two treatments. The forty-day average increase and decrease in the underlying and optimal graphs are shown in Table 7:

As can be seen from Table 7, the average rise and fall of the optimal graph obtained using the MACD preprocessing method compared to the direct use of the raw data is closer to the average rise and fall of the base graph over the next forty days. This result confirms the lagging nature of the MACD indicator and the effectiveness of the graphical stock selection, fully demonstrating the practicality of the method in practice.

7. Conclusions and Discussion

In this study, the wavelet transform is used to denoise the original stock price series, the SymN4 wavelet function is selected according to the characteristics of the stock time series, and the comprehensive scores of different wavelet decomposition layers and wavelet threshold functions are calculated based on the entropy weight method; the results show that the 4-layer decomposition layers and the suppression detail factor threshold method have the highest scores, so the wavelet denoising parameters finally selected in this study are SymN4 wavelet function, 4-layer decomposition layers, and suppression detail factor threshold method. The improved DTW algorithm was then used to calculate the distance between the two sequences to select the optimal graph that is most similar to the target graph. To overcome the effect of price and other factors on the DTW algorithm, the raw sequence data were standardized using the MACD algorithm and then the optimal graph most similar to the target graph was selected using the DTW algorithm. The comparison experimental results show that the similarity between the final graph and the target graph after the MACD algorithm processing is greater than 85%, which fully demonstrates the effectiveness of the graph recognition method. Finally, by comparing the target graphs with the optimal graphs, it is found that the optimal graphs obtained by MACD preprocessing method are closer to the forty-day average increase/decrease of the underlying graphs (the difference between them is within 0.2), indicating that the method has strong practical guidance significance.

The graph recognition methods in this study can be nested in stock analysis software, and stock investors can select existing classical patterns or K-line patterns to find stocks that are similar to them for the purpose of graphical stock selection. This provides a practical technical basis for graphical stock selection techniques.

The graph recognition methods used in this study are all based on a consistent time window size, so it will result in finding the optimal graph with the same time window size as the target graph, and the DTW algorithm can calculate the similarity of graphs with different size time windows, in addition to the overall recognition of the target graph. Therefore, this study does not fully use all the advantages of the DTW algorithm, and in real-life applications, if the problem of matching different size time window graphics can be solved, it will have more far-reaching implications for stock investors. In future work, this study will try to use genetic algorithm to further find the optimal time window size.

Data Availability

The stock price data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest

The author declares no conflicts of interest.

Acknowledgments

The author greatly appreciates the reviewers’ suggestions, and Shanxi University of Finance and Economics. This research was funded by National Natural Science Foundation of China, grant no. 61173144, and the Science and Technology Innovation Project of Higher Education Department of Shanxi Province, grant no. 2019L0493.