Stock average line similar mode searching method, system and device and medium
By using multi-feature weighted fusion and cross-pattern analysis, a multi-dimensional analysis system is constructed, which solves the problem of insufficient accuracy and comprehensiveness in the calculation of stock moving average similarity in existing technologies, and realizes more accurate similar segment search and investment decision support.
Patent Information
- Application Number
- CN202511707302.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-20
- Publication Date
- 2026-02-10
AI Technical Summary
Existing technologies for calculating the similarity of stock moving averages suffer from poor robustness of single-feature analysis, insufficient integration of multiple features, and superficial cross-pattern mining, resulting in inaccurate and incomplete analysis results that are difficult to support investors in making scientific investment decisions.
We employ a multi-feature weighted fusion and cross-pattern analysis approach to construct a multi-dimensional analysis system that encompasses single moving average patterns and data features, as well as multiple moving average cross-pattern features. By combining a weighted fusion strategy with a deep cross-pattern analysis model and customizing feature weights, we achieve efficient feature fusion and in-depth feature mining.
It improves the accuracy and comprehensiveness of stock moving average similarity calculation, enhances the controllability of the analysis process, supports investors in customizing feature weights according to their own strategies, provides more reliable technical support, and improves the scientificity and practicality of investment decisions.
Smart Images

Figure CN121504613A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for finding stock similarity patterns in financial data analysis, and more particularly to a method, system, computer equipment, and storage medium for finding stock moving average similarity patterns based on multi-feature weighted fusion and cross-pattern analysis.
[0002] In the fintech field, a moving average system segment formed by a specific stock within a specified time interval is defined as a definite moving average pattern. Based on this definition, stock moving average similarity pattern finding involves using specific technologies and calculation methods to quantitatively evaluate the similarity of this definite pattern to other stocks or the moving average systems of the same stock at different times in terms of morphological characteristics and operational patterns. Ultimately, this process accurately locates and outputs moving average time segments similar to this pattern. This process is based on historical data of stock moving averages, using various characteristics of moving averages as the analytical foundation. It quantifies the characteristics of individual moving averages and also performs similarity calculations by combining the relationships between multiple moving averages. This helps investors compare similar scenarios, explore classic patterns, and thus predict stock trends and make investment decisions. Because stock moving average similarity calculation involves a large number and wide range of features, how to scientifically and accurately measure the similarity of stock segments has become one of the most pressing issues in the field of financial technology analysis.
[0003] Currently, mainstream single moving average similarity measurement features can be divided into two categories based on their manifestation: intuitive features and data-dependent features. Intuitive features refer to those that can be directly reflected in the moving average trend, allowing observation of similar trends without complex data calculations. For example, trend direction consistency can be determined by observing whether the rise and fall of two moving averages are synchronized; the degree of trend alignment can be directly judged from the form, which is simple and direct. The non-linear time series pattern similarity that DTW similarity focuses on can also be perceived by comparing the bending, undulation, and other morphological features of the moving average trend. Conversely, data-dependent features are usually not directly observable from the moving average pattern and must rely on data calculations to quantify similarity. For example, trend strength similarity needs to be calculated using the slope of linear regression, volatility similarity depends on the standard deviation data of the moving average, correlation coefficient features (such as Pearson and Spearman) are entirely based on data association calculations, and mean level similarity also needs to be obtained by comparing mean data. In summary, while various features of a single moving average can provide a basis for similarity judgment from different dimensions, the calculation results of a single feature have obvious limitations and are easily affected by the external environment, resulting in poor robustness of similarity calculation. Therefore, only by organically integrating morphologically intuitive features with data-dependent features and obtaining more comprehensive similarity results through multi-feature evaluation can we provide more reliable support for the similarity calculation of a single moving average.
[0004] In the field of quantitative analysis, there are four main methods for calculating the interrelationships of multiple moving averages: First, quantitative analysis based on crossover events. This method counts the number of key crossover points such as golden crosses and death crosses, using crossover frequency as an indicator of similarity. It can intuitively reflect the crossover activity of the moving average system, but it is insufficient in characterizing the distribution characteristics of crossover points over time. Second, time-series matching of crossover positions. This method uses the Dynamic Time Warping (DTW) algorithm to calculate the distance between the occurrence positions of golden crosses and death crosses, which can effectively capture the correspondence of crossover events in the time dimension and can characterize the event distribution to a certain extent. While current methods for calculating the relationships between multiple moving averages can be categorized into several approaches, they all fall short in terms of their ability to accurately reflect spatial differences between moving averages. However, they lack quantitative measures of the degree of convergence and the rate of divergence. Thirdly, moving average convergence analysis identifies the convergence trend of a multi-moving average system by recognizing the morphological characteristics of moving average convergence (multiple moving averages clustering together) and divergence (multiple moving averages extending outwards in a discrete manner). Fourthly, spatial relationship quantification calculates the spatial distribution characteristics of multiple moving averages by calculating parameters such as the average distance and the rate of change of distance between different moving averages. While this method can accurately reflect the spatial differences between moving averages, it struggles to integrate similarity information at the morphological level, such as crossover patterns. In summary, although current methods for calculating the relationships between multiple moving averages analyze them from dimensions such as crossover, convergence, and space, they all have limitations in characterizing certain features or integrating multiple aspects of information. Combining these methods with calculations based on the characteristics of a single moving average is necessary for a more accurate measurement of the similarity of a moving average system.
[0005] Currently, while there are numerous technical analysis tools available for the stock market, their ability to calculate moving average similarity is relatively weak. Some traditional analysis software, while displaying stock moving averages, lacks effective methods for finding similar patterns, leading to significant discrepancies between the selected stocks and the target stocks, thus failing to provide investors with accurate and effective references. Some software can only perform simple comparisons of certain characteristics of moving averages, such as judging trend similarity solely by comparing moving average slopes. This fails to comprehensively consider the various characteristics of moving averages and makes it difficult for investors to freely set the weights of different moving average features based on their own investment strategies and experience. Consequently, it cannot achieve true multi-feature personalized integration, limiting investors' control over the analysis process to some extent. Furthermore, existing technologies for analyzing moving average crossover patterns often remain superficial, failing to delve into the trend reversal signals implied by crossover patterns. Due to the lack of comprehensive consideration of the spatiotemporal characteristics and dynamic changes of moving average crossovers, the analysis results are easily affected by short-term fluctuations, thus impacting the accuracy of the judgment. In the field of stock technical analysis, how to combine multi-feature fusion with in-depth analysis of cross-patterns to design a better algorithm to improve the accuracy of finding similar moving average patterns remains a technical challenge that needs to be addressed. Summary of the Invention
[0006] To address the aforementioned technical problems, this invention provides a method, system, device, and medium for finding similar patterns in stock moving averages. The aim is to more accurately and comprehensively measure the similarity of stock moving averages, thereby further improving the accuracy and practicality of finding similar segments.
[0007] To achieve the above objectives, the present invention adopts the following technical solution:
[0008] The first aspect of this invention discloses a method for finding similar patterns in stock moving averages, comprising the following steps:
[0009] Step 1: Data extraction and preprocessing, including raw data acquisition and moving average data generation;
[0010] Step 2: Feature model building, which includes three parts: feature dimension definition, feature quantification standard setting, and similarity measurement function construction;
[0011] Step 3: Single moving average feature calculation. Based on the feature model defined in Step 2, and combined with the moving average data of different periods obtained in Step 1, the single moving average feature is calculated.
[0012] Step 4: Calculate multiple moving average features. Based on the feature model defined in Step 2, and combined with the moving average data of different periods obtained in Step 1, calculate the multiple moving average features.
[0013] Step 5: Feature similarity calculation. Calculate the similarity results between single moving average features and multiple moving average features based on the calculation methods for single moving average features and multiple moving average features in Steps 3 and 4.
[0014] Step 6: Weighted fusion of feature results, including determining feature weights and calculating feature weighted fusion.
[0015] Furthermore, step 1 includes the following steps:
[0016] Step 1.1: Raw data collection. Extract historical trading data of the target stock from the securities trading database, including basic information such as daily opening price, closing price, highest price, lowest price, trading volume, and time of day.
[0017] Step 1.2: Define moving averages. Calculate the daily moving average data for stocks using the simple moving average method based on the historical trading data obtained in Step 1.1. On the basis of the daily moving averages, further obtain the weekly and monthly moving average data using daily market data.
[0018] Furthermore, step 2 includes the following steps:
[0019] Step 2.1: Feature dimension definition. Combining the feature attributes of single moving averages and multiple moving averages, construct a multi-dimensional feature system that includes morphological features and data features;
[0020] Step 2.2: Feature Quantification Standard Setting. Develop clear quantification rules for each single moving average and multi-moving average combination feature dimension defined in Step 2.1 to ensure that the features are calculable and comparable.
[0021] The single moving average feature is quantified as follows:
[0022] ① Trend direction: The slope of the moving average sequence is calculated by linear regression. A slope > 0 is defined as an upward trend, a slope < 0 is defined as a downward trend, and a slope ≈ 0 is defined as a horizontal trend.
[0023] ② Trend strength: quantified by the absolute value of the linear regression slope; the larger the value, the steeper the trend.
[0024] ③ Volatility: Quantified by the standard deviation (σ) of the moving average sequence, reflecting the degree of data dispersion;
[0025] ④ Mean level: Quantified by the arithmetic mean (μ) of the moving average sequence, reflecting the overall numerical center;
[0026] Multi-moving-line crossover feature quantification:
[0027] ① Golden / Death Cross Frequency: Directly counts the number of crossover points within a specified time range;
[0028] ② Golden / Death Cross Position: Normalize the index value of the cross point in the sequence to the [0,1] interval to quantify the relative time position;
[0029] Step 2.3: Constructing the similarity measurement function. Select an appropriate measurement function based on the feature attributes to provide a mathematical basis for subsequent similarity calculations.
[0030] Furthermore, the feature definition within the multidimensional feature system in step 2.1 is as follows:
[0031] The dimensions of single moving average crossover features extracted from moving average combinations of different periods are:
[0032] (1) Morphological characteristics: including three types: trend direction, trend strength, and bending pattern;
[0033] ① Trend direction: refers to the overall upward or downward trend of the moving average sequence;
[0034] ② Trend strength: refers to the steepness of the rise or fall of the moving average;
[0035] ③ Curved shape: refers to the overall shape outline of the moving average sequence, and captures subtle shape differences through dynamic time warping (DTW).
[0036] (2) Data characteristics: including fluctuation range and mean level;
[0037] ① Volatility: refers to the degree of dispersion of the moving average sequence;
[0038] ② Mean level: refers to the overall numerical level of the moving average sequence;
[0039] The dimensions of the multi-moving average crossover features extracted from moving average combinations of different periods are:
[0040] (1) Morphological characteristics: including golden cross position and death cross position;
[0041] ① Golden cross position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses above the long-term moving average;
[0042] ② Death Cross Position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses below the long-term moving average;
[0043] (2) Data characteristics: including the frequency of golden crosses and the frequency of death crosses;
[0044] ① Golden cross frequency: The number of times a golden cross occurs within a specified time range;
[0045] ② Death cross frequency: The number of times a death cross occurs within a specified time range.
[0046] Furthermore, step 3 includes the following steps:
[0047] Step 3.1: Trend Feature Calculation. First, a linear regression model is used to fit the single moving average sequence to obtain the slope value of the regression line, which quantifies the trend strength. The larger the absolute value of the slope, the stronger the trend. Let the single moving average sequence be... ,in The length of the time series (in days / weeks / months). Representing the The moving average value at time t. The sequence is fitted using the following linear regression model:
[0048]
[0049] In the above formula, For the residual term, For constant terms, regression coefficients The slope of the current moving average is calculated using the following formula:
[0050]
[0051] in The average of the time indices. The average of the moving average sequence represents the trend strength, which is determined by... express, The larger the value, the stronger the trend. Next, the first difference of the moving average sequence is calculated. The stability of the trend direction is judged by the consistency ratio of the difference signs. The first difference of the moving average sequence is defined as follows: ,in Indicates an upward trend. Indicates a downward trend. To represent a horizontal trend, based on this definition, the number of difference sign samples for a single moving average is calculated, and the following settings are made: for Quantity, for Quantity;
[0052] Step 3.2: Calculate volatility characteristics. Calculate the standard deviation of a single moving average sequence to measure the degree of volatility of the moving average around its mean. The moving window method is used to calculate the rolling standard deviation. The moving average sequence extraction method from Step 3.1 is used to obtain the data for a single moving average sequence. Set the movable window size to Then at time rolling standard deviation The calculation formula is:
[0053]
[0054]
[0055] in For the first The moving average within the window at any given time, i.e. ,in The current moving window value, when hour, ;when hour, Specifically, when When the rolling standard deviation is 0, the rolling standard deviation sequence that dynamically changes over time can be obtained using the method described above. The larger the sequence value, the stronger the fluctuation of the moving average within the corresponding window, which is used to depict the time-varying pattern of the fluctuation characteristics.
[0056] Step 3.3: Calculate the mean and median of the individual moving averages to be compared during the detection period, in order to prepare for measuring the overall similarity of different moving averages; obtain the individual moving average sequence data according to the moving average sequence extraction method. Let the arithmetic mean of the sequence be... ,but Where T is the rolling standard deviation time interval, and t represents a certain moment within the interval. The sequence is then sorted in ascending order to obtain the next sequence. The formula for calculating the median Med of this sequence is:
[0057] .
[0058] Furthermore, step 4 includes the following steps:
[0059] Step 4.1: Crossover pattern feature extraction. Traverse multiple moving average sequences, identify and record the occurrence times of golden crosses and death crosses, forming a crossover event dataset; define the first... The short-term moving average value at time is Long-term moving average value The positional difference between the short-term moving average and the long-term moving average is Based on this, considering the time interval T, if there exists a time interval... satisfy Then determine the first The time is the golden cross, and the set of golden cross time points is recorded as follows: If a time exists satisfy Then determine the first The time of the death cross is recorded as follows: ;
[0060] Step 4.2: Crossover frequency calculation. Count the number of golden crosses and death crosses within the time window to obtain the crossover frequency dataset of the moving average system; let the time window be... The entire time series of the moving average over the past few trading days is as follows: Then a sliding window sequence is generated. For each window The crossover frequency within the window is calculated using the following formula:
[0061]
[0062] in This represents the number of golden crosses within the window. This represents the number of death crosses within the window, which can be used to further construct a crossover frequency dataset for this moving average system. .
[0063] Furthermore, step 5 includes the following steps:
[0064] Step 5.1: Evaluate the similarity measure of individual moving average features in the moving average system. Individual moving average similarity is a similarity assessment calculation performed on two moving averages to be compared. After calculating the eigenvalues of each moving average, their similarity is examined. The specific calculation method for the eigenvalues is detailed in Step 3. Let the two moving averages to be compared be x and y. B represents the length of the two moving averages to be compared. The single moving average feature similarity evaluation method consists of the following seven aspects:
[0065] ① Similarity in trend direction Based on the calculation method in step 3.1, the result is as follows: and The number of difference sign samples representing the moving average x. and The number of difference sign samples representing the moving average y;
[0066] ② Similarity in trend strength Based on the calculation method in step 3.1, the result is as follows: This represents the slope of the moving average x. The slope of the moving average y represents its trend.
[0067] ③ Similarity in fluctuation amplitude Based on the calculation method in step 3.2, the result is as follows: This represents the rolling standard deviation of the moving average x within the window H. This represents the rolling standard deviation of the moving average y within the window H.
[0068] ④ Similarity of mean level Based on the calculation method in step 3.3, the result is as follows: This represents the average level of the moving average x within the window H. This represents the average level of the moving average y within the window H.
[0069] ⑤ Linear correlation similarity The results were obtained by mapping the Pearson correlation coefficient of two sequences to the [0,1] interval.
[0070] ⑥ Rank-related similarity The results of mapping the Spearman correlation coefficient of two sequences to the [0,1] interval;
[0071] ⑦ Similarity in bending shape The DTW similarity between the two sequences is used for representation, and the specific calculation method is as follows:
[0072] First, linear interpolation is used to unify the two moving average time series data to be compared. The length of the unified series is... If both original sequences have a length of 1, then directly expand them to a sequence with a length of 1. Otherwise, a new sequence is generated by mapping using a linear interpolation function, ensuring that trend characteristics are preserved. Let the sequence after uniform length be... , After linear interpolation, DTW similarity is calculated for different cases.
[0073] If the sequence length Q < 2, then the comparison method for short sequences is used. First, the absolute difference between the elements of the two sequences is calculated. Then, the dynamic range of the entire time series values is determined. If the calculation result Then another To avoid division by zero, the DTW similarity between the two sequences is ultimately defined as:
[0074]
[0075] If the sequence length Then, the comparison method for normal sequences is used; first, the DTW distance between the two sequences is calculated, denoted as... That is, by using the dynamic time warping algorithm to find the cumulative distance of the optimal alignment path between two sequences, the theoretical maximum possible distance is calculated using the following formula:
[0076]
[0077] Therefore, DTW similarity is defined as:
[0078]
[0079] The value range is [0,1]. The closer the value is to 1, the more similar the shape and trend of the two sequences are; the closer the value is to 0, the greater the difference is.
[0080] Step 5.2: Evaluate the similarity measure of multiple moving average crossover features in the moving average system. Multiple moving average crossover features are used to evaluate the similarity between two moving average systems to be compared. After calculating the multiple moving average crossover features of the two moving average systems respectively, the similarity between the two systems is examined. The specific calculation method for the feature values is detailed in Step 4. Let the two moving average systems to be compared be X and Y, then the specific evaluation method consists of the following two aspects:
[0081] ① Crossover frequency similarity Based on the calculation method in step 4.2, where This represents the crossover frequency dataset of the moving average system X within a sliding time window H. This represents the crossover frequency dataset of the moving average system Y within a sliding time window H.
[0082] ② Similarity of intersection positions The similarity to the bending morphology calculated in step 5.1 is used. Using the same method, the MA sequence is replaced with time series data of the golden cross and death cross points of the two moving averages to be compared. First, normalization and linear interpolation are performed to obtain sequences of the same length. Then, mean difference normalization and DTW distance normalization are applied to the short and long sequences respectively to quantify the similarity of the position distribution.
[0083] Step 6, which involves moving to the ground, includes the following steps:
[0084] Step 6.1: Determine feature weights. First, determine the weight allocation of a single moving average sub-feature, and then determine the weight allocation of multiple moving average crossover features.
[0085] Step 6.2: Integrate all single moving average features, normalize the calculation results of the 7 sub-features of each moving average to be compared, and then perform weighted summation according to the default weights to obtain the fusion result of single moving average features; take the average of the frequency similarity and position similarity of the golden cross and death cross of the moving average system to obtain the fusion result of multi-moving average features;
[0086] Step 6.3: Use the single moving average feature weight and the multi-moving average crossover feature weight to perform a weighted sum to obtain the overall similarity score.
[0087] In a second aspect, the present invention discloses a stock moving average similarity pattern search system, comprising a data layer module, a business logic layer module, and a result display layer module.
[0088] The data layer module is responsible for collecting historical stock trading data and, based on the system's default moving average parameters, converting the raw time series data into a visualized moving average pattern image, providing data for subsequent analysis and processing.
[0089] The business logic layer module first extracts multi-dimensional features from the preprocessed moving average pattern image based on rule definitions, covering the direction, intensity, volatility (not just "etc.", but also the full features) of a single moving average, as well as the crossover pattern features between multiple moving averages. Then, a weighted fusion strategy is used to assign corresponding weights according to the importance of different features in similarity judgment, achieving efficient feature fusion. At the same time, a deep crossover pattern analysis model is constructed to deeply analyze the dynamic evolution process of moving average crossovers and mine the similarity information contained therein.
[0090] The results display layer module presents the similar segment search results in a visual manner, provides investors with moving average similarity comparison charts, and gives reasonable investment decisions based on market conditions.
[0091] A third aspect of the present invention discloses a computer device including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the method according to any one of claims 1 to 7.
[0092] In a fourth aspect, the present invention discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the method of any one of claims 1 to 7.
[0093] Advantages and effects of the present invention:
[0094] This invention constructs a multi-dimensional analysis system encompassing single moving average patterns and data characteristics, as well as multiple moving average crossover features. Combined with a weighted fusion strategy and a deep crossover pattern analysis model, it effectively mitigates the problems of poor robustness of single-feature analysis, insufficient integration of multiple features, and superficial crossover pattern mining compared to traditional methods. Experimental verification using historical stock moving average data reveals that the search method of this invention not only more accurately and comprehensively quantifies the similarity of different stock moving average systems, further improving the accuracy and practicality of similar segment searching, but also allows users to customize feature weights according to investment strategies, enhancing the controllability of the analysis process. This provides investors with more reliable technical support for comparing similar market scenarios, predicting stock trends, and making scientific investment decisions, facilitating the efficient transformation from technical analysis to practical decision-making. Attached Figure Description
[0095] Figure 1 This is a system architecture diagram of the present invention.
[0096] Figure 2 This is a schematic diagram of the process of the present invention.
[0097] Figure 3 A diagram illustrating the overall process of performing similarity searches for users.
[0098] Figure 4 This invention provides a user interface for collecting stock similarity benchmark regions.
[0099] Figure 5 This invention provides an interface for users to use saved custom settings.
[0100] Figure 6 This is the user interface for obtaining algorithm features and weights in this invention.
[0101] Figure 7 This is the interface for displaying similarity results to users according to the present invention. Detailed Implementation
[0102] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0103] like Figure 1As shown, the first aspect discloses a stock moving average similarity pattern search system, comprising a data layer module, a business logic layer module, and a result display layer module. The data layer module acquires historical stock trading data and moving average parameters, and constructs moving average data with daily, weekly, and monthly periods based on basic market data, providing data support for the business logic layer module. In addition to the default supported data, the system can collect feature sets and weight sets that users focus on during similarity calculation, and construct a similarity calculation model by combining the system's default configuration with user-defined configurations, providing algorithm and model support for the business logic layer module.
[0104] The business logic layer module comprises four main parts: a moving average display submodule, a custom configuration submodule, a feature extraction submodule, and a similarity calculation submodule. It designs various business processes, such as custom mode stock selection, recommendation mode stock selection, custom mode evaluation, and recommendation mode evaluation, to meet the system's functional requirements and complete the overall system logic. The similarity calculation submodule, based on a similarity calculation model constructed by combining custom factors, first calculates the results of basic factors and single moving average features, and then combines a multi-feature weighted fusion method with the crossover pattern of moving average combinations to obtain the output result of the similarity calculation model.
[0105] The results display layer module presents the similarity pattern search results and pattern evaluation results, and allows for full interaction with the user. At the same time, it collects more detailed similarity calculation requirements to better provide decision support for the user.
[0106] The modules in the aforementioned stock moving average similarity pattern search system can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the corresponding operations of each module. By using this system, the aforementioned computational processing methods can be executed and the corresponding technical effects can be achieved.
[0107] In a second aspect, this invention discloses a method for finding similar patterns in stock moving averages. This method is implemented based on a system for finding similar patterns in stock moving averages, such as... Figure 2 As shown, the stock moving average similarity pattern finding method is based on data extraction and preprocessing methods and feature model establishment, and then applied to specific data to calculate moving average features, divided into two parts: single moving average feature calculation and multi-moving average feature calculation. Based on the calculated feature values, this method provides a feature similarity calculation method based on single moving averages and moving average combinations, and further weights and fuses the feature calculation results to finally obtain the complete similarity calculation result. The specific steps are as follows:
[0108] Step 1: Data extraction and preprocessing, including two parts: raw data acquisition and moving average system definition; in the embodiment, such as Figure 3 As shown, the user obtains two parts of raw data through the operating system: the process for obtaining the first part of the data is as follows... Figure 3 As shown in the "Benchmark Interval Setting" module, on the one hand, users can cycle through a selected stock and select and save one or more similarity search benchmark areas; on the other hand, users can also select the "Historical Mode" branch, click on the custom mode list, select an item of historical mode and click confirm to apply, using the rule definition method to supplement the benchmark interval, that is, using the saved mode for search; the second part of the data acquisition process is as follows: Figure 3 The "Search Configuration Settings" module allows users to set the stock selection observation range, set the candidate stock list, and determine the parameters of the moving average system. During parameter determination, users can choose to use the default configuration or customize feature selection and weight settings. This step defines the range of stock segments for similarity searching and completes the collection of raw data.
[0109] In practical implementation, the method by which users determine the selection area of the reference region is as follows: Figure 4 As shown. Figure 4 The system's main page displays the following content: the stock selection area in the upper left, the parameter configuration area in the lower left, the stock information preview area in the upper right, the stock market data visualization and selection area in the middle right, and the stock selection results area in the lower right. The main entry point is the market data visualization and selection area. Users click the page icon, drag the selection box to select a segment of moving average or candlestick pattern, and click save to define a benchmark area for similarity matching. If the user selects a historical reference mode, such as... Figure 5 As shown, the system will display a pop-up window showing the baseline selection area and some configuration parameters of the historical mode for the user to choose from.
[0110] Step 1.1: Raw data collection and similar pattern search system. Based on historical data of stock moving averages, the system first extracts historical trading data of the target stock from the securities trading database, including six basic pieces of information: daily opening price, closing price, highest price, lowest price, trading volume, and time of day. The single moving average features and multi-moving average combination features extracted subsequently are calculated based on the above six basic pieces of information.
[0111] Step 1.2: Define the moving average system. Based on the historical trading data obtained in Step 1.1, calculate the daily moving average data for the stock using the simple moving average method. Let the daily stock price time series data be... ,in Indicates the first The closing price data at each point in time is used, and the calculation period is set to a number of days. Then the first Simple moving average at a given time point The calculation formula is:
[0112]
[0113] In the formula, Indicates the period from the first From the point in time to the The closing price data at each time point is summed, and the average value is calculated after the summation. As time goes by, new data is continuously added and old data is removed for calculation, thereby obtaining dynamically changing moving average values. The moving average system defined in the example is MA4, MA8, MA12, MA16, MA20 and MA47. It can be seen that the calculation period in the system includes six types: 4, 8, 12, 16, 20 and 47, covering four types of moving averages: short, medium, medium-long and long-term, which can be combined to form a relatively rich set of characteristic results.
[0114] To meet the needs of multi-time-dimensional analysis, weekly and monthly moving average data are further derived from daily market data, based on the daily moving average. The specific calculation method is as follows:
[0115] For weekly moving average calculations, daily closing price data is aggregated according to the natural week, with the closing price of the last trading day of each week serving as the representative price for that week, forming a weekly time series. ,in Indicates the first Price data at each weekly time point. The number of weeks in the calculation period is set to... Then the first Simple moving average at 1000-12000 points in time The calculation formula is:
[0116]
[0117] In the formula, Indicates the period from the first From the point in time to the The weekly representative price data at each point in time is summed, and the average is calculated. Simultaneously, the weekly opening price is the opening price of the first trading day of each week, the weekly high price is the maximum of the highest prices within the week, the weekly low price is the minimum of the lowest prices within the week, and the weekly closing price is the closing price of the last trading day of the week. Line data.
[0118] For monthly moving average calculations, daily closing price data is aggregated by calendar month, with the closing price of the last trading day of each month serving as the representative price for that month, forming a monthly time series. ,in Indicates the first Price data at a specific point in time each month. The number of months in the calculation period is [number missing]. Then the first Simple moving average at a monthly time point The calculation formula is:
[0119]
[0120] In the formula, Indicates the period from the first From the point in time to the The monthly representative price data at each point in time is summed, and the average is calculated. Simultaneously, the monthly opening price is the opening price of the first trading day of each month, the monthly high price is the maximum of the highest prices within the month, the monthly low price is the minimum of the lowest prices within the month, and the monthly closing price is the closing price of the last trading day of each month. Moving average data. Thus, through the above method, the system can generate moving average data for three time dimensions—daily, weekly, and monthly—based on the same set of daily market data, forming a multi-period moving average analysis system. Moving average data for different periods are calculated independently but logically consistent, all following the principle of "rolling updates and dynamic adjustments." That is, as new trading day data is added, the daily moving average is updated in real time; after a week / month of accumulated trading days, the weekly / monthly moving average is updated synchronously, ensuring that the moving averages of each period always reflect the latest market trends. In this system embodiment, users can switch between daily, weekly, and monthly data for calculation by clicking an interface button. The feature extraction section below only uses one aspect based on daily data for explanation.
[0121] Step 2: Feature model establishment, which includes three parts: feature dimension definition, quantification standard setting, and similarity measurement function construction, including single moving average feature model establishment and multi-moving average feature model establishment;
[0122] Step 2.1: Feature Dimension Definition. Combining the feature attributes of single and multiple moving averages, a multi-dimensional feature system is constructed, encompassing both morphological and data features. In this embodiment, the dimensions of the single moving average crossover feature extracted from moving average combinations of different periods include:
[0123] 1. Morphological characteristics: including three aspects: trend direction, trend strength, and bending pattern;
[0124] ① Trend direction: refers to the overall upward / downward / horizontal trend of the moving average sequence;
[0125] ② Trend strength: refers to the steepness of the rise or fall of the moving average;
[0126] ③ Curved shape: refers to the overall shape outline of the moving average sequence, and captures subtle shape differences through dynamic time warping (DTW).
[0127] 2. Data characteristics: Includes both fluctuation range and mean level;
[0128] ① Volatility: refers to the degree of dispersion of the moving average sequence;
[0129] ② Mean level: refers to the overall numerical level of the moving average sequence;
[0130] The dimensions of the multi-moving average crossover features extracted from moving average combinations of different periods include:
[0131] 1. Morphological characteristics: Includes two types: golden cross and death cross;
[0132] ① Golden cross position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses above the long-term moving average;
[0133] ② Death Cross Position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses below the long-term moving average.
[0134] 2. Data characteristics: Includes two types: golden cross frequency and death cross frequency;
[0135] ① Golden cross frequency: The number of times a golden cross occurs within a specified time range;
[0136] ② Death cross frequency: The number of times a death cross occurs within a specified time range.
[0137] Step 2.2: Feature Quantization Standard Setting. Clear quantification rules are established for each single moving average and multi-moving average combination feature dimension defined in Step 2.1 to ensure the features are calculable and comparable. In this embodiment, the quantification standards for each feature are as follows:
[0138] 1. Single Moving Average Feature Quantization
[0139] ① Trend direction: The slope of the moving average sequence is calculated by linear regression. A slope > 0 is defined as an upward trend, a slope < 0 is defined as a downward trend, and a slope ≈ 0 (absolute value ≤ 1e-10) is defined as a horizontal trend.
[0140] ② Trend strength: quantified by the absolute value of the linear regression slope; the larger the value, the steeper the trend.
[0141] ③ Volatility: Quantified by the standard deviation (σ) of the moving average sequence, reflecting the degree of data dispersion;
[0142] ④ Mean level: Quantified by the arithmetic mean (μ) of the moving average sequence, reflecting the overall numerical center;
[0143] 2. Quantification of Multiple Moving Average Crossover Features
[0144] ① Golden / Death Cross Frequency: Directly counts the number of crossover points within a specified time range;
[0145] ② Golden / Death Cross Position: Normalize the index value of the cross point in the sequence to the [0,1] interval to quantify the relative time position.
[0146] Step 2.3: Constructing similarity measurement functions, selecting suitable measurement functions based on feature attributes for subsequent similarity calculations. In this embodiment, based on scenario requirements, seven similarity measurement functions are selected for single moving average features: trend direction consistency, trend strength similarity, volatility characteristic similarity, Pearson correlation coefficient, Spearman correlation coefficient, dynamic time warping distance, and mean level similarity; for multi-moving average combination features, two similarity measurement functions are selected: crossover number similarity and crossover position similarity.
[0147] Step 3: Single moving average feature calculation. Based on the feature model defined in Step 2, and combined with the moving average data of different periods obtained in Step 1, the single moving average feature is calculated. The quantification in this step uses the example data of the 12-day moving average (MA12) of the example stock for ten consecutive trading days, specifically [12.5, 12.8, 13.1, 13.0, 13.5, 13.9, 14.2, 14.5, 14.7, 15.0].
[0148] Step 3.1: Trend Feature Calculation. First, a linear regression model is used to fit the single moving average sequence to obtain the slope of the regression line, which quantifies the trend strength. The larger the absolute value of the slope, the stronger the trend. Specifically, let the single moving average sequence be... ,in The length of the time series (in days / weeks / months). Representing the The moving average value at time t. The sequence is fitted using the following linear regression model:
[0149]
[0150] In the above formula, For the residual term, For constant terms, regression coefficients The slope of the current moving average is calculated using the following formula:
[0151]
[0152] in The average of the time indices. This represents the mean of the moving average sequence. Trend strength is determined by... express, The larger the value, the stronger the trend. Next, the first difference of the moving average sequence is calculated, and the stability of the trend direction is judged by the consistency ratio of the difference signs. The first difference of the moving average sequence is defined as follows: ,in Indicates an upward trend. Indicates a downward trend. This indicates a horizontal trend. Based on this definition, the number of difference sign samples for a single moving average is calculated, and a value is set... for Quantity, for The quantity.
[0153] In this embodiment, the time index mean of the sequence is first calculated. and moving average Then substitute the result into the formula. Calculations were performed, and the results showed that the trend strength was... This indicates that the moving average is trending upwards with moderate strength. The next step, based on first-order difference statistics, calculates the trend direction stability to be 88.89%, indicating that the upward trend of this moving average is relatively stable.
[0154] Step 3.2: Calculate volatility characteristics. This step calculates the standard deviation of a single moving average sequence to measure the degree of volatility of the moving average around its mean. The moving window method is used to calculate the rolling standard deviation. The moving average sequence extraction method from Step 3.1 is used to obtain the data for a single moving average sequence. Set the movable window size to Then at time rolling standard deviation The calculation formula is:
[0155]
[0156]
[0157] in For the first The moving average within the window at any given time, i.e. ,in The current moving window value, when hour, ;when hour, Specifically, when When the rolling standard deviation is 0, the rolling standard deviation sequence that dynamically changes over time can be obtained using the method described above. The larger the sequence value, the stronger the fluctuation of the moving average within the corresponding window, which is used to depict the time-varying pattern of the fluctuation characteristics.
[0158] In this embodiment, the moving window size H is first set to 3, and the rolling standard deviation is calculated to measure the volatility characteristics. Then, the complete rolling standard deviation sequence is calculated sequentially. The results show that the 12-day moving average sequence exhibits the strongest volatility at t=3 (σ3≈0.424), with no volatility at t=1. The overall volatility changes dynamically over time, reflecting a time-varying pattern in the oscillation amplitude of the moving average around the mean.
[0159] Step 3.3: Calculate the mean and median of the individual moving averages to be compared within the search period. This prepares for measuring the overall similarity of different moving averages. Obtain the individual moving average sequence data according to the moving average sequence extraction method. Then the arithmetic mean of the sequence Where T is the rolling standard deviation time interval, and t represents a certain moment within the interval. The sequence is then sorted in ascending order to obtain the next sequence. The median of the sequence is defined by the following formula:
[0160]
[0161] In this embodiment, the arithmetic mean of the sequence is first calculated, and then the sequence is sorted in ascending order. According to the definition of the median, the median of the 10 data points is 13.5, and the mean is 13.72, which can be used to subsequently measure the similarity of the overall levels of different moving averages.
[0162] Step 4: Multi-moving-line feature calculation. This involves calculating the multi-moving-line features based on the feature model defined in Step 2, combined with the moving average data of different periods obtained in Step 1. Based on the moving average data extraction method in Step 3.1, the short-term moving average sequence is defined as follows: Correspondingly, the long-term moving average sequence is defined as follows: , as well as The first The short-term and long-term moving average values at any given time. The multi-moving average features of the model are extracted according to the following steps. In this embodiment, the 12-day moving average (MA12) and 47-day moving average (MA47) of the example stock are selected for calculation over twelve consecutive trading days. The specific data are: MA12=[14.5, 14.7, 14.9, 15.0, 15.3, 15.6, 15.8, 16.0, 15.9, 15.7, 15.5, 15.3], MA47=[14.8, 14.8, 14.8, 14.9, 14.9, 15.0, 15.1, 15.2, 15.3, 15.4, 15.5, 15.6].
[0163] Step 4.1: Crossover pattern feature extraction. Traverse multiple moving average sequences, identify and record the occurrence times of golden cross (short-term moving average crossing above long-term moving average) and death cross (short-term moving average crossing below long-term moving average), forming a crossover event dataset.
[0164] Specifically, the definition of the first The positional difference between the short-term moving average and the long-term moving average at any given time is If a time exists satisfy Then determine the first The time is the golden cross, and the set of golden cross time points is recorded as follows: ;
[0165] If a time exists satisfy Then determine the first The time of the death cross is recorded as follows: ;
[0166] In this embodiment, the position difference sequence of the moving average combination is first calculated, and then the crossover event is identified: at t=3: =-0.1 <0, =0.1≥0, which satisfies the golden cross condition, therefore ={3}. At t=11: =0.3 > 0, =0 ≤ 0, which satisfies the death cross condition, therefore ={11}.
[0167] Step 4.2: Crossover frequency calculation. Count the number of golden crosses and death crosses within the time window to obtain the crossover frequency dataset of the moving average system. Let the time window be... The entire time series of the moving average over the past few trading days is as follows: Then a sliding window sequence is generated. Then for each window The crossover frequency within the window is calculated using the following formula:
[0168]
[0169] in This represents the number of golden crosses within the window. This represents the number of death crosses within the window. Based on this, a crossover frequency dataset for this moving average system can be further constructed: .
[0170] In this embodiment, the time window is set to h = 5 trading days, and the sliding step size is step = 1. Based on the occurrence of golden crosses and death crosses in step 4.1, the statistical results of crossover events within the sliding window can be obtained. Dividing this by the window length yields the crossover frequency dataset: Fcross = {0.2, 0.2, 0.2, 0, 0, 0, 0.2, 0.2}. This dataset reflects the density of moving average crossover events within different time windows; a higher value indicates more frequent crossovers within the window.
[0171] Step 5: Feature Similarity Calculation. Based on the single-moving-line feature and multi-moving-line feature calculation methods defined in Steps 3 and 4, assume that two moving average systems to be compared are randomly selected within a specific time window. Choose any two moving averages to be compared from the two systems. Let the two moving averages be in the time window. The total number of samples are respectively and Then the time series of the moving average within the window can be obtained: , Based on the extracted data, the following steps can be performed. This step uses sample data from two moving average systems X and Y of the example stock for quantitative calculation. A time window of H = 10 trading days is selected. The 12-day moving average (x) is selected from system X, and the 47-day moving average (y) is selected from system Y. The specific data is as follows: =[14.5, 14.7, 14.9, 15.0, 15.3, 15.6, 15.8, 16.0, 15.9, 15.7], =[14.8, 14.8, 14.8, 14.9, 14.9, 15.0, 15.1, 15.2, 15.3, 15.4].
[0172] Step 5.1: Similarity Measurement of Single Moving Average Features in the Moving Average System. Based on the system definition of single moving average features in Step 3, single moving average similarity is a similarity assessment calculation performed on two moving averages to be compared. After calculating the feature values of each of the two moving averages, their similarity is examined. The specific calculation method for the feature values is detailed in Step 3. Let the two moving averages to be compared be x and y. B represents the lengths of the two moving averages to be compared. Specifically, in this embodiment, the following seven evaluation results can be obtained:
[0173] ① Similarity in trend direction Based on the calculation method in step 3.1, the result is as follows: and The number of difference sign samples representing the moving average x. and The number of difference sign samples representing the moving average y;
[0174] ② Similarity in trend strength Based on the calculation method in step 3.1, the result is as follows: This represents the slope of the moving average x. The slope of the moving average y represents its trend.
[0175] ③ Similarity in fluctuation amplitude Based on the calculation method in step 3.2, the result is as follows: This represents the rolling standard deviation of the moving average x within the window H. This represents the rolling standard deviation of the moving average y within the window H.
[0176] ④ Similarity of mean level Based on the calculation method in step 3.3, the result is as follows: This represents the average level of the moving average x within the window H. This represents the average level of the moving average y within the window H.
[0177] ⑤ Linear correlation similarity The results were obtained by mapping the Pearson correlation coefficient of two sequences to the [0,1] interval.
[0178] ⑥ Rank-related similarity The results of mapping the Spearman correlation coefficient of two sequences to the [0,1] interval;
[0179] ⑦ Similarity in bending shape The DTW similarity between the two sequences is used for representation.
[0180] First, linear interpolation is used to unify the two moving average time series data to be compared. The length of the unified data is... If the length of the two original sequences is 1, then they are directly expanded into sequences of length 1. A constant sequence (where the element value is uniquely the same as the original sequence); otherwise, a new sequence is generated by mapping using a linear interpolation function (based on equidistant sampling points within the interval [0,1]), ensuring that trend characteristics are preserved. Let the sequence after uniform length be... , After linear interpolation, DTW similarity is calculated for different cases.
[0181] If the sequence length Then, the comparison method for short sequences is used, first calculating the absolute difference between the elements of the two sequences. Then, the dynamic range of the entire time series values is determined. If the calculation result Then another To avoid division by zero, the DTW similarity between the two sequences is finally defined as:
[0182]
[0183] If the sequence length Then, the comparison method for normal sequences is used. First, the DTW distance between the two sequences is calculated, denoted as... This involves finding the cumulative distance of the optimal alignment path between two sequences using a dynamic time warping algorithm. The theoretically maximum possible distance is then calculated using the following formula:
[0184]
[0185] Therefore, DTW similarity is defined as:
[0186]
[0187] The value range is [0,1]. The closer the value is to 1, the more similar the shape and trend of the two sequences are. The closer the value is to 0, the greater the difference is.
[0188] In this specific embodiment, the specific value is calculated using the first-order difference result to obtain R1=0.45; the slope of x is calculated after fitting with linear regression. ≈0.09 (linear regression fit), the slope of y ≈0.06, resulting in R2≈0.8; taking a window of H=3, calculating the rolling standard deviation of x and y and substituting it into the formula, yields R3≈0.8; calculating the mean of x and y and substituting it into the formula, yields R4≈0.99; calculating the Pearson correlation coefficient of the two sequences, approximately 0.86, and mapping it to the [0,1] interval, yields R5≈0.93; calculating the Spearman correlation coefficient of the two sequences, approximately 0.89, and mapping it to the [0,1] interval, yields R6≈0.94; calculating the DTW distance, dynamic range, and theoretical maximum distance of the two sequences and substituting them into the formula, yields R7≈0.947. Finally, a comprehensive examination of the above similarity results shows that the two moving averages are highly similar in terms of mean level and morphological trend, but the consistency in trend direction is moderate.
[0189] Step 5.2: Similarity measurement of multiple moving average crossover features in the moving average system. Multiple moving average crossover features are used to evaluate the similarity between two moving average systems to be compared. After calculating the multiple moving average crossover features of the two moving average systems respectively, the similarity between the two systems is examined. The specific calculation method for the feature values is detailed in Step 4. Let the two moving average systems to be compared be X and Y, then the specific evaluation method consists of the following two aspects:
[0190] ① Crossover frequency similarity Based on the calculation method in step 4.2, where This represents the crossover frequency dataset of the moving average system X within a sliding time window H. This represents the crossover frequency dataset of the moving average system Y within a sliding time window H.
[0191] ② Similarity of intersection positions The similarity to the bending morphology calculated in step 5.1 is used. Using the same method, the MA sequence is replaced with time series data of the golden cross and death cross points of the two moving averages to be compared. First, normalization and linear interpolation are performed to obtain sequences of the same length. Then, mean difference normalization and DTW distance normalization are applied to the short and long sequences respectively to quantify the similarity of their location distributions.
[0192] In this embodiment, the crossover frequency sequences and crossover position sequences of systems X and Y are calculated based on the method in step 4.2. Substituting these sequences into the formula yields R8 = 0.95. The length of the crossover position sequences of both systems is 2 (Q = 2), requiring no interpolation. After normalization, the sequences are: System X: {0.27, 0.91}, System Y: {0.36, 0.82}. The DTW distance between the two systems is calculated, and substituting this into the formula yields R9 ≈ 0.922. Based on the comprehensive crossover feature similarity measurement results, it can be concluded that the two moving average systems have high similarity in crossover frequency and crossover position distribution, and the overall crossover pattern consistency is strong.
[0193] Step 6: Weighted fusion of feature results. In this embodiment, for example... Figure 3 As shown in the flowchart of the "Find Configuration Settings" module, users can select the "Parameter Configuration" option to use custom feature combination weights for feature weighted fusion calculation. If no settings are specified, the system defaults to using the initial weights for fusion calculation. After calculating the final result, as shown... Figure 3 As shown in the flowchart of the "Results Viewing and Saving" module, the system outputs the results to the results page, where users can view the search results and decide whether to save the current search mode to the history mode. Figure 6 A pop-up window displays user-defined parameters. Users can select and set weights to choose the metrics they are interested in, thereby obtaining more predictable and feature-rich similarity search results.
[0194] Step 6.1: Determine feature weights. First, determine the weight allocation for individual moving average sub-features, then determine the weight allocation for multi-moving average crossover features. The system defaults to setting the same weights for all features, but users can also customize the weights for calculation. The weight allocation for individual moving average features and crossover features is similar; the system defaults to the same weights, but users can customize them. For example... Figure 6As shown, users can select features they are interested in and configure weights through text-based question and answer, or they can intuitively view the features that the system supports configuration through image-based question and answer, and the system provides richer custom settings for similarity calculation in nested question and answer.
[0195] In this embodiment, the system defaults to the following weights for the seven sub-features of a single moving average: trend direction consistency (0.15), trend strength similarity (0.15), volatility similarity (0.15), Pearson correlation coefficient (0.2), Spearman correlation coefficient (0.15), dynamic time warping similarity (0.15), and mean level similarity (0.1). Users can customize and adjust the weights of these features through the front-end page. The system defaults to the following weights for the golden cross / death cross features: golden cross frequency (0.25), golden cross position (0.25), death cross frequency (0.25), and death cross position (0.25).
[0196] Step 6.2: Combining all single moving average features, normalize the calculation results of the 7 sub-features of each moving average to be compared, and then perform a weighted summation according to the default weights to obtain the fusion result of the single moving average features. Average the frequency similarity and position similarity of the golden cross and death cross of the moving average system to obtain the fusion result of the multi-moving average features.
[0197] In this embodiment, the default weight allocation between groups configured by the system is: single moving average feature (0.6) and crossover feature (0.4).
[0198] Step 6.3: The system performs a weighted summation of single moving average feature weights and crossover feature weights to obtain the overall similarity score. In this embodiment, the system fuses all single moving average features and crossover features according to default weights to calculate the overall similarity of the two moving average systems. The similarity results are displayed in a sorted list format. Users can save the current parameters (baseline interval, N-day range, weight configuration, etc.) using the "Save Configuration to Custom Mode" function for later direct retrieval. For example, when a user queries "stocks with similar price movements to stock 600036 from January 1, 2023 to June 30, 2023", the system first loads the default weight configuration (or user-defined weights), then calculates the single moving average feature and crossover feature scores of the candidate stock and the base stock; the scores are weighted and fused to obtain the overall similarity, which is then sorted and displayed in the system. Some results are: Shanghai Pudong Development Bank (0.9234), China Merchants Bank (0.8976); finally, users can save the current query parameters for future use.
[0199] Similarity score results as follows Figure 7As shown, the system displays the similarity search results on the page, including the stock name, stock code, stock source, benchmark region, moving average and candlestick chart performance of the search results, and the degree of similarity. Users can click "Save Configuration to Custom Mode" to save the current query configuration (such as benchmark selection set, recent N days, stock pool list, custom selection features and weights, etc.) to the system for easy retrieval in the future. This concludes the stock similarity pattern search process.
[0200] In a third aspect, this invention discloses a computer device, including a memory and a processor. Specifically, the memory stores data and related computer programs required for executing a method, and the processor can invoke the data and programs in the memory to implement all the steps of the aforementioned method. The computer device also includes input / output interfaces (I / O), a communication interface, an audio processor, a display, a power supply, and other components. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is connected to the system bus via the I / O interfaces; these are well known to those skilled in the art and therefore will not be described further. The processor of this computer device provides computational and control capabilities. The memory of this computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of this computer device stores historical stock trading data, including basic information such as daily opening price, closing price, highest price, lowest price, trading volume, and the time of day.
[0201] A fourth aspect of this invention discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements a method for finding similar patterns in stock moving averages. This storage medium can be any readable storage medium capable of storing program code, such as a USB flash drive, external hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk. For example, the computer-readable storage medium can be the aforementioned memory including program instructions, which can be executed by the processor of the stock moving average similarity pattern finding system to complete the aforementioned stock moving average similarity pattern finding method.
[0202] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0203] The above description is merely one embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present invention is not limited to the technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of the present invention.
Claims
1. A method for finding similar patterns in stock moving averages, characterized in that, Includes the following steps: Step 1: Data extraction and preprocessing, including raw data acquisition and moving average data generation; Step 2: Feature model building, which includes three parts: feature dimension definition, feature quantification standard setting, and similarity measurement function construction; Step 3: Single moving average feature calculation. Based on the feature model defined in Step 2, and combined with the moving average data of different periods obtained in Step 1, the single moving average feature is calculated. Step 4: Calculate multiple moving average features. Based on the feature model defined in Step 2, and combined with the moving average data of different periods obtained in Step 1, calculate the multiple moving average features. Step 5: Feature similarity calculation. Calculate the similarity results between single moving average features and multiple moving average features based on the calculation methods for single moving average features and multiple moving average features in Steps 3 and 4. Step 6: Weighted fusion of feature results, including determining feature weights and calculating feature weighted fusion.
2. The method for finding similar patterns in stock moving averages according to claim 1, characterized in that: Step 1 includes the following steps: Step 1.1: Raw data collection. Extract historical trading data of the target stock from the securities trading database, including basic information such as daily opening price, closing price, highest price, lowest price, trading volume, and time of day. Step 1.2: Define moving averages. Calculate the daily moving average data for stocks using the simple moving average method based on the historical trading data obtained in Step 1.
1. On the basis of the daily moving averages, further obtain the weekly and monthly moving average data using daily market data.
3. The method for finding similar patterns in stock moving averages according to claim 1, characterized in that: Step 2 includes the following steps: Step 2.1: Feature dimension definition. Combining the feature attributes of single moving averages and multiple moving averages, construct a multi-dimensional feature system that includes morphological features and data features. The multi-dimensional feature system includes single moving average crossover features and multiple moving average crossover features. The single moving average crossover feature extracted from moving average combinations of different periods includes the following dimensions: (1) Morphological characteristics: including three types: trend direction, trend strength, and bending pattern; ① Trend direction: refers to the overall upward or downward trend of the moving average sequence; ② Trend strength: refers to the steepness of the rise or fall of the moving average; ③ Curved shape: refers to the overall shape outline of the moving average sequence, and captures subtle shape differences through dynamic time warping (DTW). (2) Data characteristics: including fluctuation range and mean level; ① Volatility: refers to the degree of dispersion of the moving average sequence; ② Mean level: refers to the overall numerical level of the moving average sequence; The dimensions of the multi-moving average crossover features extracted from moving average combinations of different periods include: (1) Morphological characteristics: including golden cross position and death cross position; ① Golden cross position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses above the long-term moving average; ② Death Cross Position: refers to the distribution of time points in a moving average combination where the short-term moving average crosses below the long-term moving average; (2) Data characteristics: including the frequency of golden crosses and the frequency of death crosses; ① Golden cross frequency: The number of times a golden cross occurs within a specified time range; ② Death Cross Frequency: The number of times a death cross occurs within a specified time range; Step 2.2: Feature Quantification Standard Setting. Develop clear quantification rules for each single moving average and multi-moving average combination feature dimension defined in Step 2.1 to ensure that the features are calculable and comparable. The single moving average features quantification includes trend direction, trend strength, volatility, and mean level; Quantification of multiple moving average crossover features includes the frequency and location of golden / death crossovers; Step 2.3: Constructing the similarity measurement function, selecting an appropriate measurement function based on feature attributes for subsequent similarity calculations.
4. The method for finding similar patterns in stock moving averages according to claim 1, characterized in that: Step 3 includes the following steps: Step 3.1: Trend Feature Calculation. First, a linear regression model is used to fit the single moving average sequence to obtain the slope value of the regression line, which quantifies the trend strength. The larger the absolute value of the slope, the stronger the trend. Let the single moving average sequence be... ,in The length of the time series (in days / weeks / months). Representing the The moving average value at time t. The sequence is fitted using the following linear regression model: ; In the above formula, For the residual term, For constant terms, regression coefficients The slope of the current moving average is calculated using the following formula: ; in The average of the time indices. The average of the moving average sequence represents the trend strength, which is determined by... express, The larger the value, the stronger the trend. Next, the first difference of the moving average sequence is calculated. The stability of the trend direction is judged by the consistency ratio of the difference signs. The first difference of the moving average sequence is defined as follows: ,in Indicates an upward trend. Indicates a downward trend. To represent a horizontal trend, based on this definition, the number of difference sign samples for a single moving average is calculated, and the following settings are made: for Quantity, for Quantity; Step 3.2: Calculate volatility characteristics. Calculate the standard deviation of a single moving average sequence to measure the degree of volatility of the moving average around its mean. The moving window method is used to calculate the rolling standard deviation. The moving average sequence extraction method from Step 3.1 is used to obtain the data for a single moving average sequence. Set the movable window size to Then at time rolling standard deviation The calculation formula is: ; ; in For the first The moving average within the window at any given time, i.e. ; and when When the rolling standard deviation is 0, the rolling standard deviation sequence that dynamically changes over time can be obtained using the method described above. The larger the sequence value, the stronger the fluctuation of the moving average within the corresponding window, which is used to depict the time-varying pattern of the fluctuation characteristics. Step 3.3: Calculate the mean and median of the individual moving averages to be compared during the detection period, in order to prepare for measuring the overall similarity of different moving averages; obtain the individual moving average sequence data according to the moving average sequence extraction method. Then the arithmetic mean of the sequence The sequence is obtained by arranging the sequence in ascending order. Then the formula for the median of the sequence is: 。 5. The method for finding similar patterns in stock moving averages according to claim 1, characterized in that: Step 4 includes the following steps: Step 4.1: Crossover pattern feature extraction. Traverse multiple moving average sequences, identify and record the occurrence time points of golden crosses and death crosses, and form a crossover event dataset. Step 4.2: Crossover frequency calculation. Count the number of golden crosses and death crosses within the time window to obtain the crossover frequency dataset of the moving average system.
6. The stock moving average similarity pattern search method according to claim 1, characterized in that: Step 5 includes the following steps: Step 5.1: Evaluate the similarity measure of single moving average features in the moving average system. The evaluation method is as follows: ① Similarity in trend direction ; ② Similarity in trend strength ; ③ Similarity in fluctuation amplitude ; ④ Similarity of mean level ; ⑤ Linear correlation similarity The results were obtained by mapping the Pearson correlation coefficient of two sequences to the [0,1] interval. ⑥ Rank-related similarity The results were obtained by mapping the Spearman correlation coefficient of two sequences to the [0,1] interval. ⑦ Similarity in bending shape The DTW similarity between the two sequences is used for representation; First, linear interpolation is used to unify the two moving average time series data to be compared. The length of the unified series is... If both original sequences have a length of 1, then directly expand them to a sequence with a length of 1. Otherwise, a new sequence is generated by mapping using a linear interpolation function, ensuring that trend characteristics are preserved. Let the sequence after uniform length be... , After linear interpolation, DTW similarity is calculated for different cases. If the sequence length Q < 2, then the comparison method for short sequences is used. First, the absolute difference between the elements of the two sequences is calculated. Then, the dynamic range of the entire time series values is determined. If the calculation result Then another To avoid division by zero, the DTW similarity between the two sequences is ultimately defined as: ; If the sequence length Then, the comparison method for normal sequences is used; first, the DTW distance between the two sequences is calculated, denoted as... That is, by using the dynamic time warping algorithm to find the cumulative distance of the optimal alignment path between two sequences, the theoretical maximum possible distance is calculated using the following formula: ; Therefore, DTW similarity is defined as: ; The value range is [0,1]. The closer the value is to 1, the more similar the shape and trend of the two sequences are; the closer the value is to 0, the greater the difference is. Step 5.2: Evaluate the similarity measure of the crossover features of multiple moving averages in the moving average system. The evaluation method is as follows: ① Crossover frequency similarity ; ② Similarity of intersection positions The similarity to the bending morphology calculated in step 5.1 is used. Using the same method, the MA sequence is replaced with time series data of the golden cross and death cross points of the two moving averages to be compared. First, normalization and linear interpolation are performed to obtain sequences of the same length. Then, mean difference normalization and DTW distance normalization are applied to the short and long sequences respectively to quantify the similarity of the position distribution.
7. The method for finding similar patterns in stock moving averages according to claim 1, characterized in that: Step 6 includes the following steps: Step 6.1: Determine feature weights. First, determine the weight allocation of a single moving average sub-feature, and then determine the weight allocation of multiple moving average crossover features. Step 6.2: Combine all single moving average features, normalize the calculation results of the 7 sub-features of each moving average to be compared, and then perform weighted summation according to the default weights to obtain the fusion result of the single moving average features; The average value of the frequency similarity and position similarity of the golden cross and death cross of the moving average system is taken to obtain the fusion result of multiple moving average features; Step 6.3: Use the single moving average feature weight and the multi-moving average crossover feature weight to perform a weighted sum to obtain the overall similarity score.
8. A stock moving average similarity pattern search system, characterized in that... It includes a data layer module, a business logic layer module, and a results display layer module; The data layer module is responsible for collecting historical stock trading data and, based on the system's default moving average parameters, converting the raw time series data into a visualized moving average pattern image, providing data for subsequent analysis and processing. The business logic layer module first performs multi-dimensional feature extraction on the preprocessed moving average pattern image based on rule definition, covering the direction, intensity, volatility features of a single moving average, as well as the crossover pattern features between multiple moving averages. Then, a weighted fusion strategy is used to assign corresponding weights based on the importance of different features in the similarity judgment, so as to achieve efficient feature fusion; at the same time, a deep crossover pattern analysis model is constructed to deeply analyze the dynamic evolution process of moving average crossover and mine the similarity information contained therein. The results display layer module presents the similar segment search results in a visual manner, provides investors with moving average similarity comparison charts, and gives reasonable investment decisions based on market conditions.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.