Stock trend prediction model based on long and short term relationship and improved GRU
By constructing a long-term and short-term relationship matrix in the stock trend prediction model and embedding the GRU model, the shortcomings of the existing models in capturing stock relationships and dynamic changes are solved, and higher prediction accuracy and robustness are achieved.
Patent Information
- Application Number
- CN202510253589.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-06-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing stock price prediction model has shortcomings in capturing the complex relationships and dynamic changes between stocks, resulting in low prediction accuracy.
Using a stock trend prediction model based on long-term and short-term relationships and improved GRU, we can build a long-term and short-term relationship matrix of stocks and embed it into each step of the input of the GRU model to capture the dynamic changes and correlations of the stock market.
It significantly improves the accuracy and robustness of stock trend change predictions, can better capture relationship information on different time scales, and enhances the flexibility and adaptability of the model.
Smart Images

Figure BDA0005297675280000041 
Figure BDA0005297675280000061 
Figure BDA0005297675280000062
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of fintech, and particularly relates to a stock trend prediction model based on long - short - term relationships and an improved GRU. Background Art
[0002] The stock market is one of the important financial investment markets and has always been the focus of researchers, especially in the field of stock price prediction. According to the theoretical framework of the Efficient Market Hypothesis, stock prices reflect all available information. However, the volatility of stock prices poses a great challenge to accurately predicting their trends. In recent years, with the continuous development of cutting - edge technologies such as deep learning and graph neural networks (GNNs), these methods have been widely applied to stock price prediction tasks to address this challenge.
[0003] Traditional stock prediction methods usually only consider the time - series information of stocks, use historical trading volume and price data to predict future trends, and have achieved certain results. However, the changes in stock prices often show correlations. For example, stocks in the same industry or related fields tend to be affected similarly. This correlation provides new opportunities to improve the accuracy of stock prediction. Methods based on graph neural networks capture this correlation by exploring the relationships between stocks, thereby improving the prediction accuracy. For example, use historical price data to construct a daily corporate relationship graph, and use graph neural networks to learn and predict the correlations between different stocks to assist in stock price prediction.
[0004] However, although GNNs have the potential in exploring stock relationships, their applications often face a series of challenges. First, the large amount of data in the stock market places high demands on the training and computing resources of GNNs. Second, although existing methods have considered the relationships between stocks, there are still challenges in refining and accurately modeling these relationships. For example, even within the same industry, the degree of correlation between stocks in different sub - industries may vary, which requires a more complex model to capture such complex relationships. In addition, current research mainly focuses on directly splicing the time - series and relationship representations of stocks, and then performing weighted sum and prediction through an attention mechanism. However, the relationships and time characteristics between stocks are often intertwined and dynamically changing, and these methods ignore the potential complex associations between the two representations. For example, the relationship on a certain day may affect future trading conditions. Summary of the Invention
[0005] In view of the deficiencies existing in the prior art, the object of the present invention is to provide a stock trend prediction model based on long short-term relationship and improved GRU, which improves the input of the GRU model at each time step, enables the model to more effectively integrate time information and long short-term relationship information, and thus significantly improves the accuracy of predicting stock trend changes. To achieve the above object and other advantages of the present invention, there is provided a stock trend prediction model based on long short-term relationship and improved GRU, including the following steps:
[0006] S1. Collect stock data;
[0007] S2. Construct the long-term relationship of stocks through the data;
[0008] S3. Construct the short-term relationship of stocks by calculating the overnight price fluctuations of stocks;
[0009] S4. Embed the representations of the long-term relationship and the short-term relationship into the input of each step of the GRU model, so that the long-term and short-term relationships of stocks can affect the time representation and features of the next day, thereby better capturing the dynamic changes and correlations in the stock market.
[0010] Preferably, by connecting stock-stock nodes, stock-industry nodes, and industry-industry nodes, the present invention can not only more accurately describe the long-term relationships between stocks in different industries, capture the potential associations and co-evolution trends in the stock market, but also reduce the number of parameters of the relationship representation in the process of training the graph model.
[0011] Preferably, a higher opening price in the morning session indicates that investors generally believe that the information of the previous day is favorable for the stock; conversely, a lower opening price indicates that the information of the previous day may have an adverse impact on the stock. If the overnight price fluctuations of two stocks are highly similar, it may indicate that they are affected by similar types of overnight information and show a high correlation. Therefore, the overnight price fluctuations of stocks can reflect their short-term relationships. Based on this theory, the present invention calculates the overnight price fluctuations of any two stocks within a certain period of time and evaluates their correlation by calculating their cosine similarity. Compared with the correlation coefficient, the cosine similarity better considers the directional and amplitude synergy of overnight price changes, and its value range is [-1, 1]. Through translation and scaling, the correlation between stocks can be transformed into an index ranging from [0, 1].
[0012] Preferably, compared with the traditional GRU model, the present invention has made improvements in the input design. The traditional GRU model uses the daily time series features of stocks as input at each time step, while the present invention uses the obtained long-term relationship representation, short-term relationship representation, and time series representation as the input at each time step. This input design takes into account the dual effects of long-term and short-term relationships on stock dynamics, making the model more flexible and adaptable. This method enables the long-term and short-term relationships of stocks to influence the representation of the next day's relationship and time series during the GRU model training process. By comprehensively considering the relationship information at different time scales, the model can more comprehensively capture the dynamic changes and correlations in the stock market, thereby improving the accuracy and robustness of predictions. Detailed implementation manners
[0013] The technical solutions in the embodiments of the present invention will be clearly and completely described below. Apparently, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0014] A stock trend prediction model based on long-term and short-term relationships and an improved GRU includes the following steps:
[0015] First, the present invention constructs its long-term relationship using the secondary industry information of stocks. Second, the present invention calculates the overnight price changes of any two stocks over a period of time and evaluates their correlation by calculating their cosine similarity, which is used as the short-term relationship of stocks. Then, the present invention embeds the representations of the long-term and short-term relationships into the input of each step of the GRU model, enabling the long-term and short-term relationships of stocks to affect the time representation and features of the next day, thereby better capturing the dynamic changes and correlations in the stock market.
[0016] Further, the present invention defines the set of all stocks as S = {s1, s2, …, s m}, where s i represents any stock, and m represents the total number of stocks. For each stock s i , its corresponding primary and secondary industry codes are respectively defined as Industry and Industry', where the numbers of Industry and Industry' are n and n' respectively.
[0017] For any given stock s i , its data on the t-th day is defined as:
[0018]
[0019] Where, and represent the opening price, closing price, highest price, lowest price, trading volume, and turnover amount respectively; and represent the primary industry code and secondary industry code of the stock respectively.
[0020] Stock s i The data for all days is represented as:
[0021] x i ={x i1 ,x i2 ,…,x it}
[0022] where t represents the number of days of the stock. The data for all stocks is represented as:
[0023] X={x1,x2,…,x m}
[0024] The data for all primary and secondary industries is the average of the data for all stocks related to that industry.
[0025] The present invention defines the long-term relationship matrix of stocks as R long , and the short-term relationship matrix as R short .
[0026] Furthermore, the long-term relationship matrix is constructed as follows:
[0027] First, the present invention uses the secondary industry information of stocks to construct the long-term relationship between stocks. The present invention regards the primary industry corresponding to each stock as a node in the graph. Since there may be potential associations between these industry nodes, they are connected to each other. Each primary industry contains multiple secondary industries, and these secondary industries are also regarded as different nodes and are connected to each other. Under each secondary industry, there are corresponding stocks, and these stocks are connected to each other. By connecting stock-stock nodes, stock-industry nodes, and industry-industry nodes, the present invention can not only more accurately describe the long-term relationship between stocks in different industries, capture the potential associations and co-evolution trends in the stock market, but also reduce the number of parameters for relationship representation in the process of graph model training.
[0028] According to the previous definition, if the number of stocks is m, and the number of primary and secondary industries are n and n' respectively, then the long-term relationship matrix R long ∈R d×d has a dimension of d = m + n + n', and is represented as follows:
[0029]
[0030] where, when r ijWhen it is equal to 1, it indicates that there is a connection between two entities; otherwise, they are not connected. In addition, each row corresponds to the nodes of stocks, primary and secondary industries.
[0031] Furthermore, construct the short-term relationship matrix as follows:
[0032] The present invention deeply studies the overnight price fluctuations of stocks. A higher opening price in the early trading session indicates that investors generally believe that the information of the previous day is favorable for the stock; conversely, a lower opening price indicates that the information of the previous day may have had an adverse impact on the stock. If the overnight price fluctuations of two stocks are highly similar, it may indicate that they are affected by similar types of overnight information and show a high correlation. Therefore, the overnight price fluctuations of stocks can reflect their short-term relationships. Based on this theory, the present invention calculates the overnight price fluctuations of any two stocks within a certain period of time and evaluates their correlation by calculating their cosine similarity. Compared with the correlation coefficient, the cosine similarity better considers the directionality and amplitude synergy of overnight price changes, and its value range is [-1, 1]. Through translation and scaling, the correlation between stocks can be transformed into an index ranging from [0, 1].
[0033] The present invention uses the overnight changes of any two stocks s i and s j to calculate the short-term relationship within a period of time, denoted as:
[0034] Corr ij ={corr1, corr2,..., corr t}
[0035] where any corr i is expressed as:
[0036]
[0037] corr i =(corr i +1) / 2
[0038] where t' represents the number of days of backtracking in the calculation process.
[0039] Using the same method, the short-term relationships between stocks and industries and between industries can be obtained. The dimension of the short-term relationship matrix R short ∈R d×d is also d = m + n + n', expressed as follows:
[0040]
[0041] Furthermore, through GAT, the representations of long-term relationships and short-term relationships are respectively obtained, specifically as follows:
[0042] To obtain the long-term relationship representation of stocks and industries, the present invention constructs a graph G for the stock data of any day t =(V, E), where V represents the set of nodes, V = {s1, s2, …, s m , s m+1 , …, s m+n , s m+n+1 , …, s m+n+n'}; E represents the set of edges, which can be derived from the matrix R long . If r ij ∈ R long is a non-zero value, it means there is an edge between nodes s i and s j , and m represents the number of stocks.
[0043] First, for each node s i , the present invention calculates the attention coefficient α j of its adjacent node s ij , which represents the importance of node s i to node s j . The calculation formula is:
[0044] e ij = a(W[x it || x jt )
[0045]
[0046] Where, is a learnable weight matrix, || represents the concatenation operation, x it ∈ R F and x jt ∈ R F respectively represent the feature representations of node s i and s j on the t-th day, N i represents the set of neighbor nodes of node s j , a is a mapping parameter, and F is the feature dimension.
[0047] Next, the present invention uses the attention coefficient to aggregate the neighbor node features of node s i to generate a new representation:
[0048]
[0049] Where σ represents the non-linear activation function ReLU. In this model, the present invention uses two layers of GAT and obtains the representation after two layers according to the above method For the short-term relationship representation, the present invention uses the same two layers of GAT for training and representation, denoted as Where F' is the feature dimension.
[0050] Furthermore, the improved GRU network is specifically as follows:
[0051] Compared with the traditional GRU model, the present invention has made improvements in the input design. The traditional GRU model uses the daily time series features of stocks as input at each time step, while the present invention uses the obtained long-term relationship representation, short-term relationship representation, and time series representation as the input at each time step. This input design takes into account the dual effects of long-term and short-term relationships on stock dynamics, making the model more flexible and adaptable. This method enables the long-term and short-term relationships of stocks to influence the representation of the next day's relationship and time series during the GRU model training process. By comprehensively considering the relationship information at different time scales, the model can more comprehensively capture the dynamic changes and correlations in the stock market, thereby improving the accuracy and robustness of prediction.
[0052]
[0053] Where, W z , W r , W h are the corresponding weight matrices, U z , U r , U h are the weight matrices of the previous hidden state, b z , b r , b h are the bias terms, σ is the sigmoid activation function, ⊙ represents element-wise multiplication, and || represents the concatenation operation.
[0054] Furthermore, the optimization objective is specifically as follows:
[0055] After obtaining the time series representation and long-term and short-term relationship representation h it , the present invention inputs them into a multi-layer perceptron (MLP) for dimensionality reduction to obtain the predicted value. Finally, the present invention compares the predicted value with the actual label and calculates the loss, and the formula is as follows:
[0056] h' it = MLP(h it )
[0057]
[0058] Where, d' is the number of samples per day, y is the true value of the i-th sample on the t-th day, h' it is the corresponding predicted value, and the loss function Loss() is the mean squared error.
[0059] The number of devices and the processing scale described herein are used to simplify the description of the present invention, and applications, modifications, and variations of the present invention will be apparent to those skilled in the art. Although the embodiments of the present invention have been disclosed above, they are not limited to the applications listed in the specification and embodiments. It can be fully applied to various fields suitable for the present invention. For those familiar with the field, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the equivalent scope, the present invention is not limited to specific details and the illustrated and described examples herein.
Claims
1. A stock trend prediction model based on long-term and short-term relationships and improved GRU, characterized in that: The following steps are involved: S1. Collect stock data; S2. constructing long-term relationships of stocks through the data; S3. Construct short-term relationships of stocks by calculating overnight price fluctuations of stocks; S4. The representation of long-term and short-term relationships is embedded into the input of each step of the GRU model, so that the long-term and short-term relationships of stocks can affect the time representation and characteristics of the next day, thereby better capturing the dynamic changes and correlations in the stock market.
2. A stock trend prediction model based on long-term and short-term relationships and improved GRU as claimed in claim 1, characterized in that: The data in step S1 include opening price, closing price, highest price, lowest price, trading volume and transaction amount, industry information, primary industry data and secondary industry data, and the primary and secondary industry data are the average values of all stock data related to the industry.
3. A stock trend prediction model based on long-term and short-term relationships and improved GRU as claimed in claim 2, characterized in that: In step S2, the long-term relationship between stocks is constructed through the secondary industry information of the stocks.
4. A stock trend prediction model based on long-term and short-term relationships and improved GRU as claimed in claim 1, characterized in that: In step S3, the overnight price fluctuations of any two stocks within a certain period of time are calculated, and the correlation is evaluated by calculating the cosine similarity of the prices of any two stocks within a period of time, thereby obtaining the short-term relationship between stocks and industries and between industries.
5. A stock trend prediction model based on long-term and short-term relationships and improved GRU as claimed in claim 1, characterized in that: The representations of long-term relationships and short-term relationships are obtained through GAT respectively. The representation of long-term relationships is obtained through GAT as follows: Construct graph G for any day's stock data t =(V,E) where V represents the node set, V = s1, s2, ..., s m ,s m+1 ,…,s m+n ,s m+n+1 ,…,s m+n+n' }; E represents the edge set, which can be represented by the matrix R long Derived; if r ij ∈R long is a non-zero value, it means that the node s i and j There is an edge between them, m represents the number of stocks; Calculate its adjacent nodes s j The attention coefficient α ij , represents node s i For node s j The importance of Use the attention coefficient to the node s i The neighbor node features of are aggregated to generate a new representation.
6. A stock trend prediction model based on long-term and short-term relationships and improved GRU as claimed in claim 1, characterized in that: After obtaining the time series representation and the long-term short-term relationship representation h it Afterwards, the present invention inputs it into a multi-layer perceptron for dimensionality reduction to obtain a predicted value; the predicted value is compared with the actual label to calculate the loss.
Citation Information
Patent Citations
Stock trend prediction method of fused graph convolutional network
CN113393050A
Stock trend prediction method, system and equipment based on multi-source feature fusion and graph neural network, and medium
CN118037340A