Unsupervised stock k line trend segmentation method

Through the unsupervised stock K-line trend segmentation method, using deep neural network and least squares method fitting technology, the problem of difficult to automatically analyze stock K-line trends in the existing technology is solved, and efficient and automated trend segmentation and analysis are achieved.

CN119622519APending Publication Date: 2025-03-14SHENYANG LINLONG INVESTMENT CONSULTING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411767918.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

It is difficult for existing technology to effectively analyze and segment stock K-line trends, especially in the case of variability in stock data, and lack of automated and unsupervised methods.

Method used

Unsupervised stock K-line trend segmentation method is used to obtain stock data through network crawlers, perform data preprocessing and least squares fitting, and train the model with deep neural network algorithm to realize automated trend segmentation.

Benefits of technology

It realizes automated stock K-line trend segmentation without manual annotation, improves analysis efficiency and accuracy, and can independently perform the segmentation or identification of stock K-line trend segments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119622519A_ABST
    Figure CN119622519A_ABST
Patent Text Reader

Abstract

The invention provides an unsupervised stock k-line trend segmentation method, which relates to the technical field of finance, and mainly comprises two stages, the first stage is unsupervised stock oscillation fragment data set construction based on a least square method, and the stage aims at providing a basic training set for a deep learning method of the next stage; and the second stage is stock k-line segmentation based on deep learning. In the stage, the stock oscillation fragments given in the first stage serve as training data, a stock k-line segmentation model is constructed, and stock k-line segmentation model training is carried out; performing stock k-line segmentation by using the trained stock k-line segmentation model; and finally merging segmentation results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of financial technology, and in particular to an unsupervised stock K-line trend segmentation method. Background Art

[0002] Quantitative trading refers to replacing human subjective judgment with advanced mathematical models, and using computer technology to find multiple high-probability times that bring excess returns in a large amount of historical data, and then formulate corresponding strategies. As an important branch of quantitative trading, stock historical data analysis has a very high status in quantitative trading, and stock analysis can be broken down into many tasks, such as stock price and trend forecasting, risk analysis, and return forecasting, etc.

[0003] The analysis of stock K-line has always attracted people's attention. Although there are endless solutions, due to the variability of stock data, this problem is still a challenging task. The current solutions to this problem can be mainly divided into machine learning solutions and deep learning solutions. Deep learning methods have the advantages of strong adaptability, high accuracy, strong feature capture ability and less human intervention. Therefore, the invention uses deep learning methods to carry out research work.

[0004] As a new research direction in the field of machine learning, deep learning brings machine learning closer to the original goal of achieving artificial intelligence. Its concept originates from artificial neural networks, which imitate the human brain mechanism to interpret data. It forms high-level representations of attribute categories or features by combining underlying features. Nowadays, with the rise of deep learning, deep learning has also been widely used in various fields, such as search technology, data mining, natural language processing, image recognition, etc. Its effect is often better than previous related technologies, and it can also be used to solve many problems that traditional technologies could not solve. As the number of problems solved increases, deep learning is also constantly developing. Today, there are many types of deep learning technologies, and typical representatives include recurrent neural networks, convolutional networks, autoencoders, generative adversarial networks, etc. With the development of deep learning, more and more people have become interested in it. Therefore, in order to facilitate research, a large number of tools have also emerged, such as TensorFlow, PyTorch, Caffe, MxNet, etc.

[0005] Because the input data of the stock K-line segmentation problem belongs to the time series data prediction problem, a recurrent neural network with certain advantages in time series prediction problems is selected to solve the stock investment portfolio problem.

[0006] The reason why the recurrent neural network (CNN) is called a recurrent neural network is mainly related to its characteristics. Its characteristics are specifically reflected in the fact that the input value of the back layer must carry the output value of the previous hidden layer, so it will repeat the same operation on a set of sequence inputs, so it is called a recurrent neural network. Recurrent neural networks are mainly used in speech analysis, text analysis, and time series analysis. The key point is that these data have a front-to-back dependency and a sequence relationship. The effect achieved is also obvious to all. The core part of RNN is a directed graph. The elements connected in a chain in the expansion of the directed graph are called recurrent units (RNN cells). Generally, the chain connection composed of recurrent units can be compared to the hidden layer in the feedforward neural network, but the "layer" of RNN may refer to the recurrent unit of a single time step or all recurrent units. The current time step state of each recurrent unit is determined by the input of the time step and the state of the previous time step. Its output mode changes with the different problems solved. For the stock yield prediction problem, its corresponding input and output are sequences. The reason why RNN is better than ordinary DNN in predicting stock yields is that stock yields are related to time. Today's price may be related to yesterday, last week, and last month. RNN has a strong "memory" ability. This "memory" ability is due to the fact that RNN can repeat operations on a set of input sequences. This feature ensures that some previous data features can be preserved, so there is a "memory" that can "simulate" the dependency between data. In order to strengthen this "memory ability", people have developed a variety of RNN variants, such as the very famous long short-term memory model (LSTM), which can be used to solve "long-term and long-distance dependencies". Summary of the invention

[0007] In view of the shortcomings of the prior art, the present invention provides an unsupervised stock K-line trend segmentation method; the overall application of the present invention to the above technology can be summarized as follows: first, stock data is obtained through a web crawler and an API provided by a data organization, and after data preprocessing, the stock trend is segmented by a stock K-line segmentation method based on the least squares method, and then the model is trained according to the segmentation category combined with a deep neural network algorithm, and finally the trend segmentation result of the stock K-line is given according to the segmentation result.

[0008] An unsupervised stock K-line trend segmentation method includes the following steps:

[0009] Step 1: Get the corresponding stock historical data of the selected stock;

[0010] Step 2: Preprocess the historical stock data obtained in step 1, including filling in empty values, segmenting by year, and normalizing the data;

[0011] Step 2.1: Fill and remove missing values ​​of stock historical data;

[0012] Step 2.2: Optimize the peak-shaving and valley-filling of the stock historical data of time series type;

[0013] Step 2.3: Normalize the data after peak elimination and valley filling. The normalization algorithm formula is:

[0014]

[0015] Where x i is the normalized data, is the data after peak elimination and valley filling, ∈ is the minimum value set to prevent the denominator from being zero;

[0016] Step 3: After data preprocessing, the stock data is segmented into 30-day segments, and the least squares method is used to fit each time segment obtained after segmentation;

[0017] Step 3.1: The stock data after data preprocessing is segmented into 30-day units. The segmented data is:

[0018] X=x [0,29] ,x [30,59] ,…,x [n-29,n]

[0019] Where x [n-29,n] is a time segment divided into 30-day periods, and n is the number of days;

[0020] Step 3.2: Perform the least squares fitting on each time segment obtained after segmentation to obtain the fitted piecewise straight line. The formula of the straight line is:

[0021] y=kx+b

[0022] In the formula, k is the slope of the fitted straight line, b is the intercept of the straight line, and (x, y) is the coordinate of any point on the straight line;

[0023] Step 4: Calculate the difference between the fitted straight line and the preprocessed stock historical data for each time segment, select the two points with the largest difference as the new segment endpoints, and recompose into three segments;

[0024] Step 4.1: Calculate the difference between the fitted straight line and each point of the preprocessed stock historical data;

[0025] Step 4.2: Find the two points with the largest difference and record them as x p and x q ;

[0026] Step 4.3: Set x p and x qThe two endpoints corresponding to the time segment, a total of four points recompose three segments; for any segment x [n-29,n] The point x corresponding to the segment p and x q , the new three fragments are:

[0027]

[0028] Step 5: Calculate the slope of the straight line connecting the endpoints of the new time segment and the residual of the stock historical data. If the preset slope and residual requirements are met, the segmentation is completed, otherwise return to step 3 to continue segmentation;

[0029] Step 5.1: For the three segments obtained in step 4, the original data coordinate points of the start and end positions of the segments are used as the endpoints of the new fitting lines;

[0030] Step 5.2: Set three hyperparameters, namely slope, residual and length;

[0031] Step 5.3: Calculate the slope of the new fitting line corresponding to each segment;

[0032] Step 5.4: Calculate the residual between the fitted straight line and the stock historical data;

[0033] Step 5.5: Compare the slope and residual of each segment obtained according to step 5.3 and step 5.4 in turn to determine whether they meet the set value in step 5.2;

[0034] Step 5.6: If the requirements of step 5.5 are met, the segment is retained and segmentation is stopped; if the requirements of step 5.5 are not met, the length of the segment is compared with the length set in step 5.2. If the length of the compared segment is greater than the set length, return to step 3 to continue segmentation, otherwise the segmentation is stopped and the segment is not retained;

[0035] Step 6: Construct a data set based on the segmented results; the data set includes m stock K-line time segments, each segment contains three attributes, namely slope, start time and end time;

[0036] Step 6.1: Count all the fragments retained in step 5;

[0037] Step 6.2: Record the three attributes of all segments, namely slope, start time and end time; after counting, there are m stock K-line time segments in total;

[0038] Step 7: Construct a stock K-line segmentation model;

[0039] Step 7.1: Select the time series analysis model, specifically select GRU as the GRU layer;

[0040] Step 7.2: Build a stock K-line segmentation model, which includes a GRU layer, a linear layer and a fully connected layer;

[0041] Step 7.3: Set the parameters of the stock K-line segmentation model, where the input feature dimension of the GRU layer is 13, the feature dimension of the hidden layer is 32; the input dimension of the linear layer is 32, the output dimension is 32; the input dimension of the fully connected layer is 32, and the output dimension is 3.

[0042] Step 8: Preprocess the data set obtained in step 6 to meet the requirements for stock K-line segmentation model training;

[0043] Step 8.1: Segment the entire stock K-line data according to a sliding window of 10 days in length;

[0044] Step 8.2: Compare each sliding window segment with the segments retained in step 5 in turn; if the sliding window can be covered by any retained segment or can cover any retained segment, then record the label of the sliding window as the positive and negative slope types of the corresponding segment;

[0045] Step 8.3: According to the comparison results of step 8.2, obtain two attributes of each sliding window, the start time and the label type;

[0046] Step 8.4: Divide all sliding windows into training set and test set in a ratio of 7:3;

[0047] Step 9: Train the stock K-line segmentation model. The input data is the sliding window of K-line data every 10 days. The corresponding label is the slope type corresponding to each time segment in the data set in step 8.

[0048] Step 9.1: Initialize model parameters;

[0049] Step 9.2: Slide the window S in the training set to S = {s i ,s i+1 ,…,s i+9} is input into the stock K-line segmentation model, where s i The daily closing price of the stock historical data x normalized in step 2.3 is combined into a sliding window S with a length of 10 days;

[0050] Step 9.3: After calculating the stock K-line segmentation model, the prediction probability corresponding to each sliding window is obtained. The calculation formula is as follows:

[0051] p i =Softmax(Linear(GRU(s i )))

[0052] Where Softmax(·), Linear(·) and GRU(·) are the softmax layer, linear layer and GRU layer of the model respectively, and the output result is is a vector representing the probability of the sliding window entering the downtrend, uptrend, and non-oscillating boxes.

[0053] Step 9.4: Take the category with the highest probability as the prediction result of the model. The calculation formula is as follows:

[0054]

[0055] The argmax(·) in the formula is used to find the index of the maximum value in the vector;

[0056] Step 9.5: Select the cross entropy loss function as the loss function of the stock K-line segmentation model. The calculation formula is as follows:

[0057]

[0058] Where e i is the sliding window s i The slope type label obtained in step 8;

[0059] Step 9.6: Select Adam as the optimizer.

[0060] Step 9.7: Set the learning rate of the optimizer.

[0061] Step 9.8: Optimize the model parameters using the optimizer based on the loss;

[0062] Step 9.9: Repeat steps 9.2 to 9.8 until the set number of rounds is reached, observe the final training results and adjust the hyperparameters based on the results;

[0063] Step 10: Use the trained model to segment the stock K-line. The input is the stock K-line data. The model gives the trend types of all sliding windows with 10 days as units, including rising, falling and non-oscillating trends, as well as the start and end time of these sliding windows.

[0064] Step 11: Traverse all sliding windows, merge all continuous or adjacent segments with similar slopes, and use the merged result as the final segmentation result;

[0065] Step 11.1: Traverse all sliding windows and find other windows that are less than or equal to three days apart or intersect with each sliding window;

[0066] Step 11.2: Merge all sliding windows with similar slopes and related in step 11.1, and the length of the merged sliding windows shall not exceed 30; where similar slope means the difference is less than 0.01;

[0067] Step 11.3: The merged result is taken as the final segmentation result.

[0068] So far, the overall process of this method from the original stock historical data to the K-line trend segmentation results has been completed.

[0069] The beneficial effects of adopting the above technical solution are:

[0070] The present invention provides an unsupervised stock K-line trend segmentation method, which can independently perform the segmentation or identification of stock K-line trend segments. Compared with the existing stock K-line segmentation method, the method does not need to manually label the K-line. The method proposes an automatic stock trend segmentation based on the least squares method, and then realizes a fully unsupervised stock K-line trend segmentation method with a custom length based on the segmented data through a deep learning method. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] Figure 1 It is the overall framework diagram of the stock K-line trend segmentation method of the present invention;

[0072] Figure 2 The present invention is a stock time series segmentation method flow based on the least squares method;

[0073] Figure 3 This is the stock K-line process of the present invention. DETAILED DESCRIPTION

[0074] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0075] An unsupervised stock K-line trend segmentation method, such as Figure 1 As shown, the following steps are included:

[0076] Step 1: Get the corresponding stock historical data of the selected stock;

[0077] Step 2: Preprocess the historical stock data obtained in step 1, including filling in empty values, segmenting by year, and normalizing the data;

[0078] Step 2.1: Fill and remove missing values ​​of stock historical data;

[0079] Step 2.2: Optimize the peak-shaving and valley-filling of the stock historical data of time series type;

[0080] Step 2.3: Normalize the data after peak elimination and valley filling. The normalization algorithm formula is:

[0081]

[0082] Where x i is the normalized data, is the data after peak elimination and valley filling, ∈ is the minimum value set to prevent the denominator from being zero;

[0083] Step 3: After data preprocessing, the stock data is segmented into 30-day segments, and each time segment obtained after segmentation is fitted by the least squares method, as shown in Figure 2 As shown;

[0084] Step 3.1: The stock data after data preprocessing is segmented into 30-day units. The segmented data is:

[0085] X=x [0,29] ,x [30,59] ,…,x [n-29,n]

[0086] Where x [n-29,n] is a time segment divided into 30-day periods, and n is the number of days;

[0087] Step 3.2: Perform the least squares fitting on each time segment obtained after segmentation to obtain the fitted piecewise straight line. The formula of the straight line is:

[0088] y=kx+b

[0089] In the formula, k is the slope of the fitted straight line, b is the intercept of the straight line, and (x, y) is the coordinate of any point on the straight line;

[0090] Step 4: Calculate the difference between the fitted straight line and the preprocessed stock historical data for each time segment, select the two points with the largest difference as the new segment endpoints, and recompose into three segments;

[0091] Step 4.1: Calculate the difference between the fitted straight line and each point of the preprocessed stock historical data;

[0092] Step 4.2: Find the two points with the largest difference and record them as x p and x q ;

[0093] Step 4.3: Set x p and x q The two endpoints corresponding to the time segment, a total of four points recompose three segments; for any segment x [n-29,n] The point x corresponding to the segment p and x q , the new three fragments are:

[0094]

[0095] Step 5: Calculate the slope of the straight line connecting the endpoints of the new time segment and the residual of the stock historical data. If the preset slope and residual requirements are met, the segmentation is completed, otherwise return to step 3 to continue segmentation;

[0096] Step 5.1: For the three segments obtained in step 4, the original data coordinate points of the start and end positions of the segments are used as the endpoints of the new fitting lines;

[0097] Step 5.2: Set three hyperparameters, namely slope, residual and length;

[0098] Step 5.3: Calculate the slope of the new fitting line corresponding to each segment;

[0099] Step 5.4: Calculate the residual between the fitted straight line and the stock historical data;

[0100] Step 5.5: Compare the slope and residual of each segment obtained according to step 5.3 and step 5.4 in turn to determine whether they meet the set value in step 5.2;

[0101] Step 5.6: If the requirements of step 5.5 are met, the segment is retained and segmentation is stopped; if the requirements of step 5.5 are not met, the length of the segment is compared with the length set in step 5.2. If the length of the compared segment is greater than the set length, return to step 3 to continue segmentation, otherwise the segmentation is stopped and the segment is not retained;

[0102] Step 6: Construct a data set based on the segmented results; the data set includes m stock K-line time segments, each segment contains three attributes, namely slope, start time and end time;

[0103] Step 6.1: Count all the fragments retained in step 5;

[0104] Step 6.2: Record the three attributes of all segments, namely slope, start time and end time; after counting, there are m stock K-line time segments in total;

[0105] Step 7: Build a stock K-line segmentation model; most time series analysis models can be used as candidate models, including GRU, LSTM, Informer, Transformer, etc. GRU is selected as the main body of the model;

[0106] Step 7.1: Select the time series analysis model, specifically select GRU as the GRU layer;

[0107] Step 7.2: Build a stock K-line segmentation model, which includes a GRU layer, a linear layer and a fully connected layer;

[0108] Step 7.3: Set the parameters of the stock K-line segmentation model, where the input feature dimension of the GRU layer is 13, the feature dimension of the hidden layer is 32; the input dimension of the linear layer is 32, the output dimension is 32; the input dimension of the fully connected layer is 32, and the output dimension is 3.

[0109] Step 8: Preprocess the data set obtained in step 6 to meet the requirements for stock K-line segmentation model training;

[0110] Step 8.1: Segment the entire stock K-line data according to a sliding window of 10 days in length;

[0111] Step 8.2: Compare each sliding window segment with the segments retained in step 5 in turn; if the sliding window can be covered by any retained segment or can cover any retained segment, then record the label of the sliding window as the positive and negative slope types of the corresponding segment;

[0112] Step 8.3: According to the comparison results of step 8.2, obtain two attributes of each sliding window, the start time and the label type;

[0113] Step 8.4: Divide all sliding windows into training set and test set in a ratio of 7:3;

[0114] Step 9: Train the stock K-line segmentation model. The input data is the sliding window of K-line data every 10 days. The corresponding label is the slope type corresponding to each time segment in the data set in step 8.

[0115] Step 9.1: Initialize model parameters;

[0116] Step 9.2: Slide the window S in the training set to S = {s i ,s i+1 ,…,s i+9} is input into the stock K-line segmentation model, where s i The daily closing price of the stock historical data x normalized in step 2.3 is combined into a sliding window S with a length of 10 days;

[0117] Step 9.3: After calculating the stock K-line segmentation model, the prediction probability corresponding to each sliding window is obtained. The calculation formula is as follows:

[0118] p i =Softmax(Linear(GRU(s i )))

[0119] Where Softmax(·), Linear(·) and GRU(·) are the softmax layer, linear layer and GRU layer of the model respectively, and the output result is It is a vector representing the probability of the sliding window entering the downtrend, uptrend and non-oscillating boxes.

[0120] Step 9.4: Take the category with the highest probability as the prediction result of the model. The calculation formula is as follows:

[0121]

[0122] The argmax(·) in the formula is used to find the index of the maximum value in the vector;

[0123] Step 9.5: Select the cross entropy loss function as the loss function of the stock K-line segmentation model. The calculation formula is as follows:

[0124]

[0125] Where e i is the sliding window s i The slope type label obtained in step 8;

[0126] Step 9.6: Select Adam as the optimizer.

[0127] Step 9.7: Set the learning rate of the optimizer.

[0128] Step 9.8: Optimize the model parameters using the optimizer based on the loss;

[0129] Step 9.9: Repeat steps 9.2 to 9.8 until the set number of rounds is reached, observe the final training results and adjust the hyperparameters based on the results;

[0130] Step 10: Use the trained model to segment the stock K-line. The input is the stock K-line data. The model gives the trend types of all sliding windows with 10 days as units, including rising, falling and non-oscillating trends, as well as the start and end times of these sliding windows, such as Figure 3 As shown;

[0131] Step 11: Traverse all sliding windows, merge all continuous or adjacent segments with similar slopes, and use the merged result as the final segmentation result;

[0132] Step 11.1: Traverse all sliding windows and find other windows that are less than or equal to three days apart or intersect with each sliding window;

[0133] Step 11.2: Merge all sliding windows with similar slopes and related in step 11.1, and the length of the merged sliding windows shall not exceed 30; where similar slope means the difference is less than 0.01;

[0134] Step 11.3: The merged result is taken as the final segmentation result.

[0135] So far, the overall process of this method from the original stock historical data to the K-line trend segmentation results has been completed.

[0136] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) to form a technical solution.

Claims

1. An unsupervised stock K-line trend segmentation method, characterized in that: The following steps are involved: Step 1: Get the corresponding stock historical data of the selected stock; Step 2: Preprocess the historical stock data obtained in step 1, including filling in empty values, segmenting by year, and normalizing the data; Step 3: After data preprocessing, the stock data is segmented into 30-day segments, and the least squares method is used to fit each time segment obtained after segmentation; Step 4: Calculate the difference between the fitted straight line and the preprocessed stock historical data for each time segment, select the two points with the largest difference as the new segment endpoints, and recompose into three segments; Step 4.1: Calculate the difference between the fitted straight line and each point of the preprocessed stock historical data; Step 4.2: Find the two points with the largest difference and record them as x p and x q ; Step 4.3: Set x p and x q The two endpoints corresponding to the time segment, a total of four points recompose three segments; for any segment x [n-29,n] The point x corresponding to the segment p and x q , the new three fragments are: Step 5: Calculate the slope of the straight line connecting the endpoints of the new time segment and the residual of the stock historical data. If the preset slope and residual requirements are met, the segmentation is completed, otherwise return to step 3 to continue segmentation; Step 6: Construct a data set based on the segmented results; the data set includes m stock K-line time segments, each segment contains three attributes, namely slope, start time and end time; Step 6.1: Count all the fragments retained in step 5; Step 6.2: Record the three attributes of all segments, namely slope, start time and end time; after counting, there are m stock K-line time segments in total; Step 7: Construct a stock K-line segmentation model; Step 8: Preprocess the data set obtained in step 6 to meet the requirements for stock K-line segmentation model training; Step 8.1: Segment the entire stock K-line data according to a sliding window of 10 days in length; Step 8.2: Compare each sliding window segment with the segments retained in step 5 in turn; if the sliding window can be covered by any retained segment or can cover any retained segment, then record the label of the sliding window as the positive and negative slope types of the corresponding segment; Step 8.3: According to the comparison results of step 8.2, obtain two attributes of each sliding window, the start time and the label type; Step 8.4: Divide all sliding windows into training set and test set in a ratio of 7:3; Step 9: Train the stock K-line segmentation model. The input data is the sliding window of K-line data every 10 days. The corresponding label is the slope type corresponding to each time segment in the data set in step 8. Step 10: Use the trained model to segment the stock K-line. The input is the stock K-line data. The model gives the trend types of all sliding windows with 10 days as units, including rising, falling and non-oscillating trends, as well as the start and end time of these sliding windows. Step 11: Traverse all sliding windows, merge all continuous or adjacent segments with similar slopes, and use the merged result as the final segmentation result.

2. An unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 2 comprises the following steps: Step 2.1: Fill and remove missing values ​​of stock historical data; Step 2.2: Optimize the peak-shaving and valley-filling of the stock historical data of time series type; Step 2.3: Normalize the data after peak elimination and valley filling. The normalization algorithm formula is: Where x i is the normalized data, is the data after peak elimination and valley filling, and ∈ is the minimum value set to prevent the denominator from being zero.

3. An unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 3 comprises the following steps: Step 3.1: The stock data after data preprocessing is segmented into 30-day units. The segmented data is: X=x [0,29] ,x [30,59] ,…,x [n-29,n] Where x [n-29,n] is a time segment divided into 30-day periods, and n is the number of days; Step 3.2: Perform the least squares fitting on each time segment obtained after segmentation to obtain the fitted piecewise straight line. The formula of the straight line is: y=kx+b Where k is the slope of the fitted line, b is the intercept of the line, and (x, y) is the coordinate of any point on the line.

4. The unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 5 comprises the following steps: Step 5.1: For the three segments obtained in step 4, the original data coordinate points of the start and end positions of the segments are used as the endpoints of the new fitting lines; Step 5.2: Set three hyperparameters, namely slope, residual and length; Step 5.3: Calculate the slope of the new fitting line corresponding to each segment; Step 5.4: Calculate the residual between the fitted straight line and the stock historical data; Step 5.5: Compare the slope and residual of each segment obtained according to step 5.3 and step 5.4 in turn to determine whether they meet the set value in step 5.2; Step 5.6: If the requirements of step 5.5 are met, the segment is retained and segmentation is stopped; if the requirements of step 5.5 are not met, the length of the segment is compared with the length set in step 5.

2. If the length of the compared segment is greater than the set length, return to step 3 to continue segmentation, otherwise the segmentation is stopped and the segment is not retained.

5. The unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 7 comprises the following steps: Step 7.1: Select the time series analysis model, specifically select GRU as the GRU layer; Step 7.2: Build a stock K-line segmentation model, which includes a GRU layer, a linear layer and a fully connected layer; Step 7.3: Set the parameters of the stock K-line segmentation model, where the input feature dimension of the GRU layer is 13, the feature dimension of the hidden layer is 32; the input dimension of the linear layer is 32, the output dimension is 32; the input dimension of the fully connected layer is 32, and the output dimension is 3.

6. An unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 9 comprises the following steps: Step 9.1: Initialize model parameters; Step 9.2: Slide the window S in the training set to S = {s i ,s i+1 ,…,s i+9 } is input into the stock K-line segmentation model, where s i The daily closing price of the stock historical data x normalized in step 2.3 is combined into a sliding window S with a length of 10 days; Step 9.3: After calculating the stock K-line segmentation model, the prediction probability corresponding to each sliding window is obtained. The calculation formula is as follows: p i =Softmax(Linear(GRU(s i ))) Where Softmax(·), Linear(·) and GRU(·) are the softmax layer, linear layer and GRU layer of the model respectively, and the output result is is a vector representing the probability of the sliding window entering the downtrend, uptrend, and non-oscillating boxes; Step 9.4: Take the category with the highest probability as the prediction result of the model. The calculation formula is as follows: The argmax(·) in the formula is used to find the index of the maximum value in the vector; Step 9.5: Select the cross entropy loss function as the loss function of the stock K-line segmentation model. The calculation formula is as follows: Where e i is the sliding window s i The slope type label obtained in step 8; Step 9.6: Select Adam as the optimizer. Step 9.7: Set the learning rate of the optimizer. Step 9.8: Optimize the model parameters using the optimizer based on the loss; Step 9.9: Repeat steps 9.2 to 9.8 until the set number of rounds is reached, observe the final training results and adjust the hyperparameters based on the results.

7. An unsupervised stock K-line trend segmentation method according to claim 1, characterized in that: The step 11 comprises the following steps: Step 11.1: Traverse all sliding windows and find other windows that are less than or equal to three days apart or intersect with each sliding window; Step 11.2: Merge all sliding windows with similar slopes and related in step 11.1, and the length of the merged sliding windows shall not exceed 30; where similar slope means the difference is less than 0.01; Step 11.3: The merged result is taken as the final segmentation result.