Stock trend prediction method and system based on space-time hypergraph quadruple attention network, and electronic equipment
Through the method based on the quadruple attention network of time and space supermap, the problem of failure to fully explore the data relationship between stocks in the existing technology is solved, and more accurate data analysis and stronger prediction capabilities are achieved, which are suitable for stock trend prediction.
Patent Information
- Application Number
- CN202510239703.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-07-04
AI Technical Summary
The existing technology fails to fully explore the data relationship between the market and multi-dimensional stocks in stock forecasts, resulting in confusion in data analysis and inaccurate processing, and the inability to effectively capture the potential correlation between stocks.
The method based on the four-fold attention network of time and space supermap is adopted. By pre-processing the stock historical price data, extracting features, using the weighted graph attention mechanism and the three-layer attention network to process the explicit relationship between stocks, combining the industry supermap and fund holding supermap, it is embedded and integrated, and finally three-class classification is performed through the fully connected network.
It improves the accuracy and robustness of stock forecasts, can analyze data more completely, enhance prediction capabilities, and adapt to different market environments.
Smart Images

Figure CN120258994A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data mining, and particularly relates to a stock trend prediction method, system and electronic device based on a Spatial-Temporal hypergraph Quad-Attention Networks (STQAN). Figure 4 Background Art
[0002] Stock market prediction is a complex technology that combines finance and computer science, and it has important practical significance and wide application value. Accurate stock prediction can not only help investors optimize their decisions and formulate more scientific investment strategies, but also effectively avoid potential risks. For regulatory agencies, stock prediction provides a powerful tool to insight market dynamics, support policy making, identify potential systemic risks, and thus maintain the stability of the financial system. However, the fluctuation of stock prices is essentially a highly complex and dynamic process. It is not only affected by macroeconomic indicators, but also closely related to the company-level financial policies and market performance. In addition, investors' emotions and behavior patterns, international political events, and sudden socio-economic events will also have an impact on the market that cannot be ignored, and the interaction between these factors often has non-linear characteristics, making the prediction work extremely challenging.
[0003] Traditional methods for stock market prediction mainly regard stock prediction as a time series problem and use statistical models for analysis. To better capture the non-linear relationships in time series, machine learning and deep learning methods have received extensive attention. Akita et al. used long short-term memory networks (LSTM) combined with historical stock data and text information for stock price prediction. Zhang et al. combined the Transformer model and multiple attention mechanisms to achieve effective analysis of feature extraction and financial data, and thus predict stock trends. However, these models all process each stock independently and do not fully consider the potential correlations between stocks.
[0004] In the financial market, there are extensive correlations among companies, which means that the stock price fluctuations of one company may be affected by other related companies. Graph neural networks are one of the common models for capturing such correlation relationships. They use nodes to represent stocks, edges to represent the relationships between stocks, and represent the correlation between stocks through an adjacency matrix, and use nodes to learn to capture the mutual influence between stocks. Cheng and Li proposed an attribute-driven graph attention network (AD-GAT) that combines a recurrent neural network (RNN) and a graph neural network. This model adjusts the price momentum spillover effect between stocks according to relevant attributes. However, stocks are often interrelated in groups in practice, rather than just pairwise connections, and it may be difficult for graph neural networks to fully describe these complex relationships. For example, multiple stocks may belong to the same industry or be held by the same fund, and thus have similar intrinsic attributes. As an extension of graph neural networks, hypergraphs establish a group relationship representation of stocks through an incidence matrix and can express richer information. In a hypergraph, a hyperedge can connect multiple stocks in the same group, and a stock can also belong to multiple hyperedges at the same time, reflecting its multi-dimensional characteristics. Ma et al. proposed an attribute-driven fuzzy hypergraph network (AFHGN), which constructs an incidence matrix through fuzzy clustering to describe the relationship between stocks and introduces an attribute-driven gate unit to simulate the mutual influence of stocks in the real market. Currently, most stock prediction techniques use simple graphs or hypergraphs to represent pairwise or group relationships between stocks. Although there are technical effects, relying solely on these two will lead to the loss of some information, resulting in technical problems such as chaotic data analysis and inaccurate data processing.
[0005] Chinese Invention Patent Authorization Publication No. CN116957140B discloses a stock prediction method and system based on NLP factors. This patent obtains the score of target stock information through in-depth analysis of text content, and constructs an NLP quantitative factor portfolio for stock prediction. However, it does not deeply mine the data relationship between the market and multi-dimensional stocks, so there are technical defects in stock prediction. Summary of the Invention
[0006] In view of the above problems existing in the prior art, the present invention proposes a stock trend prediction method, system and electronic device based on a spatio-temporal hyper Figure 4 multi-attention network.
[0007] To achieve the above object, the present invention adopts the following technical solutions:
[0008] A stock trend prediction method based on a spatio-temporal hyper Figure 4 multi-attention network, which includes the following steps:
[0009] Step 1: First, preprocess the historical stock price data, and then extract features to obtain stock embeddings;
[0010] Step 2: Correlation graph attention. Divide the stocks into two categories of positive and negative correlation, and use a weighted graph attention mechanism to aggregate information from both types respectively;
[0011] Step 3: Hypergraph attention network. Introduce an industry hypergraph and a fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network;
[0012] Step 4: Embedding fusion. Extract complementary information from different stock embeddings through two-stage attention and perform sufficient fusion;
[0013] Step 5: Prediction. Perform three-classification after passing through a fully connected network.
[0014] Furthermore, step 1), specifically includes the following steps:
[0015] Step 1.1: Process the historical price data of N stocks, and normalize the opening price, highest price, lowest price, closing price, trading volume, and trading amount of the stocks by dividing them by their maximum values within the entire trading range;
[0016] Step 1.2: Extract features from the stock price data of T trading days using GAFormer (see the paper GAFormer: Enhancing Timeseries Transformers Through Group-Aware Embeddings) and GRU (GRU gated recurrent unit, abbreviated as GRU) to obtain stock embeddings H; Input each stock into GAFormer respectively:
[0017] Z s = GAFormer(X s ),
[0018] where, is the 6 types of price data of stock s in T trading days, is the segment embedding representation of stock s, P is the number of segments, D is the embedding dimension; Use GRU to fuse to obtain stock embeddings:
[0019] H = GRU(Z1,...,Z N ).
[0020] Furthermore, step 2), specifically includes the following steps:
[0021] Step 2.1: Calculate the Pearson correlation coefficient using the stock price data of T trading days to generate a correlation matrix Subsequently, divide the positive correlation matrix P and the negative correlation matrix O according to the threshold ∈, as follows:
[0022]
[0023] where a ij is the (i, j)-th element of the correlation matrix A;
[0024] Step 2.2: Perform a non-linear transformation to generate the positive adjacency matrix A p and the negative adjacency matrix A n :
[0025] M i = Tanh(αP), M o = Tanh(αO),
[0026] A p = ReLU(Tanh(αM i A)), A n = ReLU(Tanh(αM o A)),
[0027] where M i and M o are the attraction matrix and the repulsion matrix respectively, and the hyperparameter α is the threshold;
[0028] Step 2.3: Use a weighted graph attention network (WGAT) to update the hidden embedding matrix of stock H. Specifically, for the positive adjacency matrix A p , consider the hidden embedding h s of stock s. The embedding update formula is expressed as:
[0029]
[0030] where h s , h r , h k are the embedding representations of stocks s, r, and k, α sr is the attention weight between stock s and stock r, α sk is the attention weight between stock s and stock k, || represents the concatenation operation, δ represents the activation function, δ represents the (s, r)-th element of A p (s, r), represents the trainable parameter vector, represents the adjacent nodes of s in A p . After applying a single layer of WGAT, the embedding matrix of all stocks is obtained, denoted as
[0031] Step 2.4: To ensure the stability of the output, a multi-head attention mechanism is adopted. Therefore, after processing H by WGAT based on A p , it is transformed into:
[0032] H p = (H1′ ||... || H h ′)W g ,
[0033] where H i ′ represents the output of the i-th attention head, and W represents the learnable parameter matrix. Similarly, H can be updated according to the negative adjacency matrix A n to obtain
[0034] Furthermore, step 3) specifically includes the following steps:
[0035] Step 3.1: Hyperedge internal attention, aggregating the information of other stock nodes within the hyperedge where the stock is located to obtain the embedding of the stock in each hyperedge; Given the hypergraph representing the industry The embedding of stock s in hyperedge E j is obtained according to the following formula:
[0036]
[0037] where and represent learnable parameters. R represents the set of real numbers, D is the vector dimension; The embedding of hyperedge E j is generated through pooling:
[0038]
[0039] where pool(·) represents the element-wise max pooling operation;
[0040] Step 3.2: Line graph attention; Convert the hypergraph to a line graph: The hyperedges become the nodes of the line graph. If hyperedges E i and E j share a stock, then their corresponding nodes in the line graph are connected with weight . Subsequently, update the hyperedge embedding according to the structure of the line graph as follows:
[0041]
[0042] where E k is the hyperedge, q i , q j are the embedding representations of hyperedges E i and E j , e ij is the weight of the edge between E i and E j , and α ij is for hyperedges E i and E jThe attention weights between represent learnable parameters, and denote the set of all hyperedges that share common points with the hyperedge E. Then, the embedding of stock s within the hyperedge E i is calculated as follows j
[0043]
[0044] where, is the embedding representation of stock s in the hyperedge E j , q′ j is the embedding representation of the hyperedge E j ;
[0045] Step 3.3: Attention between hyperedges. A stock node can belong to multiple hyperedges simultaneously. The node embeddings of all specific hyperedges where the target stock node is located are fused through attention between hyperedges; use to denote the set of all hyperedges containing stock s, and calculate the importance of the hyperedge to stock s:
[0046]
[0047] where, is the set of hyperedges containing stock s, q′ k is the embedding representation of the hyperedge E k , c s,j is the attention score between the hyperedges E s and E j , c s,k is the attention score between the hyperedges E s and E k ; and represent trainable parameters. Then, the stock embedding can be updated as follows:
[0048]
[0049] where, β s,k is the weight of the hyperedge E k to stock s, v s,k is the embedding of stock s in the hyperedge E k ;
[0050] Finally, based on the industry sector hypergraph the hypergraph and line graph attention network (HLGAT, Hypergraph and Line Graph Attention Networks) outputs the updated stock embedding Similarly, based on the fund shareholding hypergraph We apply the HLGAT module to update the stock embeddings and obtain
[0051] Furthermore, in step 3, the specific processing process of the three-layer attention network is as follows: Step 3.1 is the intra-hyperedge attention, which aggregates the information of other stock nodes within the hyperedge where the stock is located to obtain the embedding of the stock in each hyperedge Obtain the hyperedge embedding q through pooling j ; Step 3.2 is the line graph attention. First, convert the hypergraph into a line graph: the hyperedges become the nodes of the line graph. If hyperedges E i and E j contain the same stock, then the corresponding nodes in the line graph are connected, and the edge weight is Then calculate the weight α ij using attention and update the hyperedge embedding q i '; Step 3.3 is the inter-hyperedge attention, which calculates the weight β s,j using the hyperedges, multiplies it with the intra-hyperedge embedding of the stock and sums them up to obtain the embedding representation of the stock
[0052] Furthermore, step 4) specifically includes the following steps:
[0053] Step 4.1: Input H p , H I and H F into the complementary attention module, and extract the complementary information between stock embeddings from different perspectives in the following way:
[0054]
[0055] where ⊙ represents the Hadamard product.
[0056] Step 4.2: Integrate different stock embeddings:
[0057] H pif =H p +H I +H F , H nif =H n +H I +H F .
[0058] Subsequently, combine the obtained supplementary information with the merged stock embeddings to form a unified embedding matrix:
[0059] C p =([C pi ||C ip +[C pf ||C fp )||H pif ,
[0060] C n = ([C ni ||C in +[C nf ||C fn )||H nif ,
[0061] where N is the number of stocks.
[0062] Step 4.3: Finally, use the attention mechanism to merge C p and C n . For stock s, the fused embedding is calculated as follows:
[0063]
[0064] where and are the positive and negative correlation attention scores, γ s is the weight, f s is the embedding vector of stock s, and are learnable parameters, and represent the s-th row of C p and C n respectively.
[0065] Therefore, the embedding matrix generated by the fusion module is
[0066] Furthermore, step 5) specifically includes the following steps:
[0067] Perform three-class classification after passing through a fully connected network (FCN):
[0068]
[0069] where σ is the softmax activation function, and y s ∈ {0, 1} 3 represent the predicted value and the actual value of stock s respectively, and represent learnable parameters, represents the cross-entropy loss function.
[0070] The present invention also discloses a stock trend prediction system based on a spatio-temporal hyper Figure 4 attention network for performing the above method, including the following modules:
[0071] Feature extraction module: Preprocess the historical stock price data, and then use GAFormer and GRU to extract features to obtain stock embeddings;
[0072] Correlation graph attention module: Divide stocks into two categories of positive and negative correlation, and use a weighted graph attention mechanism to aggregate information from both types respectively;
[0073] Hypergraph attention module: Introduce an industry hypergraph and a fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network;
[0074] Embedding fusion module: Extract complementary information from different stock embeddings through two-stage attention and perform sufficient fusion.
[0075] Prediction module: Perform three-class classification through a fully connected network.
[0076] The present invention also discloses a storage medium storing computer instructions for causing a computer to execute the method or system according to the above.
[0077] The present invention also discloses an electronic device, including:
[0078] A processor;
[0079] A memory for storing a program, which when called and executed by the processor causes the processor to execute the above method or system.
[0080] The present invention is a data mining technology that introduces a spatio-temporal hyper Figure 4 multi-attention network to advance stock trend prediction by mining and combining the data relationship between market time dynamics and multi-dimensional stocks. In the technical solution of the present invention, a simple graph is used to capture implicit pairwise stock relationships, and a hypergraph is used to model explicit collective relationships between stocks. A two-stage fusion mechanism based on attention is proposed, which can adaptively integrate the embeddings of time features, correlation graphs, and hypergraph structures, thereby enhancing the prediction ability of the proposed model. Therefore, in the stock prediction technical solution of the present invention, the data analysis is complete and the data processing is accurate, solving the technical problems existing in the prior art. Furthermore, the robustness and accuracy of the technical solution proposed by the present invention are verified through experiments on three data sets. Brief Description of the Drawings
[0081] Figure 1 It is a flowchart of a stock trend prediction method based on a spatio-temporal hyper Figure 4 multi-attention network according to an embodiment of the present invention.
[0082] Figure 2 It is the correlation graph attention module according to an embodiment of the present invention.
[0083] Figure 3The hypergraph and line graph attention module of the embodiment of the present invention.
[0084] Figure 4 The embedding fusion module of the embodiment of the present invention.
[0085] Figure 5 For an embodiment of the present invention, a Figure 4 model framework diagram related to a stock trend prediction method based on a spatio-temporal hyper
[0086] Figure 6 For an embodiment of the present invention, a Figure 4 block diagram of a stock trend prediction system based on a spatio-temporal hyper
[0087] Figure 7 The complementary attention graph in the embedding fusion module of the embodiment of the present invention. Detailed implementation manners
[0088] The following is further described in conjunction with the drawings and embodiments.
[0089] This embodiment is a stock trend prediction method based on a spatio-temporal hyper Figure 4 attention network. As Figure 1 shown, it includes the following steps:
[0090] Step 1: First, preprocess the historical price data of stocks, and then use GAFormer and GRU to extract features to obtain stock embeddings.
[0091] Step 2: Correlation graph attention. Divide the stocks into two categories of positive and negative correlations, and use a weighted graph attention mechanism to aggregate information from the two types respectively.
[0092] Step 3: Hypergraph attention network. Introduce an industry hypergraph and a fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network.
[0093] Step 4: Embedding fusion. Extract complementary information of different stock embeddings through two-stage attention and fully fuse them.
[0094] Step 5: Prediction. Perform three-classification after passing through a fully connected network.
[0095] The following details each step of this implementation.
[0096] Step 1), specifically including the following steps:
[0097] Step 1.1: Process the historical price data of N stocks, and normalize the opening price, highest price, lowest price, closing price, trading volume, and trading amount of the stocks by dividing them by the maximum value within the entire trading range.
[0098] Step 1.2: Extract features from the stock price data of T trading days using GAFormer and GRU to obtain the stock embedding H. Input each stock into GAFormer respectively:
[0099] Z s = GAFormer(X s ),
[0100] where, is the 6 types of price data of stock s in T trading days, is the segment embedding representation of stock s, P is the number of segments, and D is the embedding dimension; Use GRU to fuse to obtain the stock embedding:
[0101] H = GRU(Z1,…,Z N ).
[0102] Step 2), as Figure 2 shown, specifically includes the following steps:
[0103] Step 2.1: Calculate the Pearson correlation coefficient using the stock price data of T trading days to generate the correlation matrix The calculation method of the Pearson correlation coefficient is as follows:
[0104]
[0105] where, X i,t and X j,t are the closing prices of stocks i and j on the t-th trading day respectively, is the average closing price of stocks i and j within T trading days. Subsequently, we divide the positive correlation matrix P and the negative correlation matrix O according to the threshold ∈, as follows:
[0106]
[0107] Step 2.2: Perform a non-linear transformation to generate the positive adjacency matrix A p and the negative adjacency matrix A n :
[0108] M i = Tanh(αP), M o = Tanh(αO),
[0109] A p = ReLU(Tanh(αM i A)), A n = ReLU(Tanh(αM o A)),
[0110] Step 2.3: Use the Weighted Graph Attention Network (WGAT) to update the hidden embedding matrix of stock H. Specifically, for the positive adjacency matrix A p , consider the hidden embedding h s of stock s. The embedding update formula is expressed as:
[0111]
[0112] where || represents the concatenation operation, δ represents the activation function, A p (s,r) represents the (s,r)-th element of, represents the vector of trainable parameters, represents A p and the adjacent nodes of s in. After applying a single layer of WGAT, the embedding matrix of all stocks is obtained, denoted as
[0113] Step 2.4: To ensure the stability of the output, the multi-head attention mechanism is implemented. Therefore, after processing H by WGAT based on A p , it is transformed into:
[0114] H p = (H1′||...||H h ′)W g ,
[0115] where H i ′ represents the output of the i-th attention head, represents the learnable parameter matrix. Similarly, we can update H according to the negative adjacency matrix A n to obtain
[0116] Step 3), as Figure 3 shown, specifically includes the following steps:
[0117] Step 3.1: Intra-hyperedge attention, aggregating the information of other stock nodes within the hyperedge where the stock is located to obtain the embedding of the stock in each hyperedge; Given the hypergraph representing the industry The embedding of stock s within the hyperedge E j is obtained according to the following formula:
[0118]
[0119] where, and represent the learnable parameters. The embedding of the hyperedge E j is generated through pooling:
[0120]
[0121] Among them, pool(·) represents the element-wise maximum pooling operation;
[0122] Step 3.2: Line graph attention; Convert the hypergraph into a line graph: The hyperedges become the nodes of the line graph. If hyperedges E i and E j share a stock, then their corresponding nodes in the line graph are connected with a weight . Subsequently, update the hyperedge embedding according to the structure of the line graph as follows:
[0123]
[0124] where, represents the learnable parameter, represents the set of all hyperedges that share a common point with hyperedge E i . Then, the embedding of stock s within hyperedge E j is calculated as follows:
[0125]
[0126] Step 3.3: Attention between hyperedges. A stock node can belong to multiple hyperedges simultaneously. Fuse the node embeddings of all specific hyperedges where the target stock node is located through attention between hyperedges; Use to represent the set of all hyperedges containing stock s, and calculate the importance of hyperedge to stock s:
[0127]
[0128] where, and represent the trainable parameters. Then, the stock embedding can be updated as follows:
[0129]
[0130] Finally, based on the industry sector hypergraph HLGAT (see Figure 3 ), output the updated stock embedding Similarly, apply the HLGAT module to update the stock embedding based on the fund shareholding hypergraph , and obtain
[0131] Step 4), as Figure 4 shown, specifically includes the following steps:
[0132] Step 4.1: Input H p , H I and H F into the complementary attention module (see Figure 7) Among them, complementary information between stock embeddings is extracted from different perspectives in the following way:
[0133]
[0134] Among them, ⊙ represents the Hadamard product.
[0135] Step 4.2: Integrate different stock embeddings:
[0136] H pif = H p + H I + H F , H nif = H n + H I + H F .
[0137] Subsequently, the obtained supplementary information is combined with the merged stock embeddings to form a unified embedding matrix:
[0138] C p = ([C pi || C ip + [C pf || C fp ) || H pif ,
[0139] C n = ([C ni || C in + [C nf || C fn ) || H nif ,
[0140] Among them,
[0141] Step 4.3: Finally, use the attention mechanism to merge C p and C n , calculate the positive and negative correlation attention scores of stock s and Then calculate the weight γ s , so as to obtain the final stock embedding f s . For stock s, the fused embedding is calculated as follows:
[0142]
[0143] Among them, and are learnable parameters, and respectively represent the s-th row of C p and C n .
[0144] Therefore, the embedding matrix generated by the fusion module (see its structure in Figure 4 ) is
[0145] Step 5) specifically includes the following steps:
[0146] Perform three-class classification after passing through the fully connected network (FCN):
[0147]
[0148] Among them, and y s ∈{0,1} 3 respectively represent the predicted value and the actual value of stock s, and represent learnable parameters, represents the cross-entropy loss function.
[0149] To verify the effectiveness of the method in this embodiment, it will be further illustrated by comparing the experimental results below:
[0150] This embodiment was verified on three datasets: CAS-758, NASDAQ-1026, and NYSE-1737. CAS-758 contains 758 stocks, 104 industry relationships, and 61 fund holding relationships in the Chinese A-share market. NASDAQ-1026 contains 1026 stocks, 112 industry relationships, and 42 wiki relationships in the NASDAQ stock market. NYSE-1737 contains 1737 stocks, 130 industry relationships, and 32 wiki relationships in the New York stock market. Accuracy, precision, recall, and F1-score were used as evaluation metrics, and the experimental results were compared with models such as MR, GRU, LSTM, GCN, TGC, HATS, THGNN, and HGTAN.
[0151] Table 1
[0152]
[0153]
[0154] Table 1 shows the performance of the model (STQAN) proposed in the present invention in predicting stock price changes compared with the baseline methods in the three datasets. Except for the accuracy metric obtained on the NYSE-1026 dataset, the model proposed in the present invention outperforms the existing comparison methods in all evaluation metrics. This confirms the excellent performance of the technical solution proposed in the present invention in the field of stock prediction.
[0155] To verify whether the predictions made by the model are accurate, the present invention conducted an investment simulation experiment. First, the investment budget was evenly distributed among each stock. Then, the model was used to predict the change trend of the stock price the next day. If the model predicted that a certain stock would decline the next day, the trader would sell it at the closing price. If the model predicted that a certain stock would rise the next day, the trader would buy the stock at the closing price. If the model predicted that a certain stock would remain stable the next day, the trader would continue to hold the stock. To evaluate the model's prediction ability, the present invention implemented a buy-and-hold strategy, that is, evenly distributing the funds among all stocks and holding them all the time. The cumulative investment return rate (IRR) and the Sharpe ratio (SR) were used as evaluation indicators.
[0156] The backtest results are shown in Table 2. It can be seen that the model proposed by the present invention performs excellently on all evaluation data sets. Specifically, on the CAS-758, NASDAQ-1026, and NYSE-1737 data sets, the IRR of the model of the present invention is 5.94%, 20.7%, and 16.81% higher than that of the second-ranked model respectively. This shows that the model of the present invention can adapt to different market environments and effectively utilize historical trading data and the relationships between stocks for prediction.
[0157] Table 2
[0158]
[0159] As Figure 6 shown, this embodiment discloses a stock trend prediction system based on a spatio-temporal hyper Figure 4 weighted attention network for performing the above method, including the following modules:
[0160] Feature extraction module: Preprocess the historical stock price data, and then use GAFormer and GRU to extract features to obtain stock embeddings;
[0161] Correlation graph attention module: Divide the stocks into two categories of positive and negative correlation, and use a weighted graph attention mechanism to aggregate information from the two types respectively;
[0162] Hypergraph attention module: Introduce an industry hypergraph and a fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network;
[0163] Embedding fusion module; Extract complementary information from different stock embeddings through two-stage attention and perform sufficient fusion;
[0164] Prediction module: Perform three-classification through a fully connected network.
[0165] Other contents of this embodiment can refer to the above method embodiment.
[0166] The present invention also discloses a storage medium storing computer instructions for causing a computer to execute the method or system according to the above.
[0167] The present invention also discloses an electronic device, comprising:
[0168] a processor;
[0169] a memory for storing a program which, when called and executed by the processor, causes the processor to execute the method or system according to the above.
[0170] The above embodiments will help those skilled in the art to further understand the present invention, but do not limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made. These all belong to the protection scope of the present invention.
Claims
1. A stock trend prediction method based on a spatio-temporal hypergraph quadruple attention network, characterized in that It includes the following steps: Step 1: Preprocess the historical stock price data, extract features, and obtain stock embeddings; Step 2: Divide the stocks into two categories of positive and negative correlation, and use the weighted graph attention mechanism to aggregate information from the two types respectively; Step 3: Introduce the industry hypergraph and the fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network; Step 4: Extract complementary information from different stock embeddings through two-stage attention and fuse them; Step 5: Perform three-class classification after passing through a fully connected network.
2. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 1, wherein Step 1 specifically includes the following steps: Step 1.1: Process the historical price data of N stocks, and normalize the opening price, highest price, lowest price, closing price, trading volume, and trading amount of the stocks by dividing them by their maximum values within the entire trading range; Step 1.2: Use GAFormer and GRU to extract features from the stock price data of T trading days to obtain stock embeddings H; input each stock into GAFormer respectively: Z s = GAFormer(X s ), Among them, are 6 kinds of price data of stock s in T trading days, is the segment embedding representation of stock s, P is the number of segments, and D is the embedding dimension; the stock embedding is obtained by fusing with GRU: H = GRU(Z1, …, Z N ).
3. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 1 or 2, characterized in that Step 2 specifically includes the following steps: Step 2.1: Calculate the Pearson correlation coefficient using the stock price data of T trading days to generate a correlation matrix Divide the positive correlation matrix P and the negative correlation matrix O according to the threshold ∈ as follows: where a ij is the (i,j)-th element of the correlation matrix A; Step 2.2: Perform a non-linear transformation to generate a positive adjacency matrix A p and a negative adjacency matrix A n : M i = Tanh(αP), M o = Tanh(αO), A p = ReLU(Tanh(αM i A)), A n = ReLU(Tanh(αM o A)), Among them, M i and M o are the attraction matrix and the repulsion matrix respectively, and the hyperparameter α is the threshold value; Step 2.3: Update the hidden embedding matrix of the stock embedding H using the weighted graph attention network WGAT; for the positive adjacency matrix A p , consider the hidden embedding h of stock s s ; the embedding update formula is expressed as: Among them, h s , h r , h k are the embedded representations of stocks s, r, and k, α sr is the attention weight between stock s and stock r, α sk is the attention weight between stock s and stock k, || represents the concatenation operation, δ represents the activation function, and δ represents the (s, r)-th element of A p (s, r), represents the trainable parameter vector, represents A p the adjacent node of s in; after applying a single layer of WGAT, the embedded matrix of all stocks is obtained, denoted as Step 2.4: After the WGAT based on A p processes H, it is converted to: H p = (H′1||...||H′ h )W g , Among them, H′ i represents the output of the i-th attention head, represents the learnable parameter matrix.
4. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 3, wherein In step 2, for the negative adjacency matrix A n , consider the hidden embedding h of stock s s ; the embedding update formula is expressed as: Among them, h s , h r , h k are the embedded representations of stocks s, r, and k, α sr is the attention weight between stock s and stock r, α sk is the attention weight between stock s and stock k, || represents the concatenation operation, δ represents the activation function, and δ represents the (s, r)-th element of A p (s, r), represents the trainable parameter vector, represents A n the adjacent node of s in; after applying a single layer of WGAT, the embedded matrix of all stocks is obtained, denoted as After the WGAT processing based on A n for H, it is converted to: H n = (H′1||...||H′ h )W g , Among them, H′ i represents the output of the i-th attention head, represents the learnable parameter matrix.
5. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 4, wherein Step 3 specifically includes the following steps: Step 3.1: Hyperedge internal attention, aggregating the information of other stock nodes within the hyperedge where the stock is located, to obtain the embedding of the stock in each hyperedge; given a hypergraph representing the industry The embedding of stock s in hyperedge E j is obtained according to the following formula: Among them, and represent learnable parameters; R represents the set of real numbers, D is the vector dimension; the hyperedge E j is embedded by pooling: Among them, pool(·) represents the element-wise maximum pooling operation; Step 3.2: Line graph attention; Convert the hypergraph into a line graph: The hyperedges become the nodes of the line graph. If hyperedges E i and E j share a stock, then their corresponding nodes in the line graph are connected with weight ; Update the hyperedge embedding according to the structure of the line graph as follows: Among them, E k is a hyperedge, q i , q j are the embedding representations of hyperedges E i and E j , e ij is the weight of the edge between E i and E j , α ij is the attention weight between hyperedges E i and E j , represents learnable parameters, represents the set of all hyperedges sharing common points with hyperedge E i ; The embedding calculation of stock s within hyperedge E j is as follows: Among them, is the embedding representation of stock s in hyperedge E j q′ j is the embedding representation of hyperedge E j ; Step 3.3: Hyperedge - to - hyperedge attention. A stock node can belong to multiple hyperedges simultaneously. The node embeddings of all specific hyperedges where the target stock node is located are fused through hyperedge - to - hyperedge attention. Let denote the set of all hyperedges containing stock s, and calculate the importance of hyperedge to stock s: Among them, is the set of hyperedges containing stock s, q′ k is the embedding representation of hyperedge E k and c s,j is the attention score between hyperedges E s and E j ; c s,k is the attention score between hyperedges E s and E k ; and represent trainable parameters; the stock embedding is updated as follows: Among them, β s,k is the weight of the hyperedge E k on the stock s, and v s,k is the embedding of the stock s in the hyperedge E k ; Hypergraph based on industry sectors Output the updated stock embeddings 6. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 5, wherein In step 3, replace the industry hypergraph in step 3.1 with the fund holding hypergraph Execute steps 3.1, 3.2, and 3.3 to implement based on the fund shareholding hypergraph Update the stock embedding to obtain 7. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 6, wherein, Step 4 specifically includes the following steps: Step 4.1: Extract the complementary information between stock embeddings from different perspectives for H p , H I and H F in the following manner: Among them, ⊙ represents the Hadamard product; Step 4.2: Integrate different stock embeddings: H pif = H p + H I + H F , H nif = H n + H I + H F . Combine the obtained supplementary information with the merged stock embeddings to form a unified embedding matrix: C p = ([C pi || C ip + [C pf || C fp ) || H pif , C n = ([C ni || C in + [C nf || C fn ) || H nif , Among them, N is the number of stocks; Step 4.3: Use the attention mechanism to merge C p and C n ; For stock s, the fusion embedding is calculated as follows: Among them, and are the positive and negative correlation attention scores, γ s is the weight, f s is the embedding vector of stock s, and are learnable parameters, and respectively represent the sth row of C p and C n ; The generated embedding matrix is 8. The stock trend prediction method based on the spatio-temporal hypergraph quadruple attention network according to claim 7, characterized in that In Step 5, perform three-class classification after passing through a fully connected network: where σ is the softmax activation function, and y s ∈{0,1} 3 represent the predicted value and the actual value of stock s respectively, and represent learnable parameters, represents the cross-entropy loss function.
9. A stock trend prediction system based on a spatio-temporal hypergraph quadruple attention network for performing the method according to any one of claims 1-8, characterized in that, It includes the following modules: Feature extraction module: Preprocess the historical stock price data, extract features, and obtain stock embeddings; Correlation graph attention module: Divide the stocks into two categories of positive and negative correlation, and use the weighted graph attention mechanism to aggregate information from the two types respectively; Hypergraph attention module: Introduce the industry hypergraph and the fund holding hypergraph and process the explicit relationships between stocks through a three-layer attention network; Embedding fusion module; Extract complementary information from different stock embeddings through two-stage attention and fully fuse them; Prediction module: Perform three-class classification after passing through a fully connected network.
10. An electronic device, characterized in that, It includes: A processor; A memory for storing a program, which when called and executed by the processor, causes the processor to execute the method according to any one of claims 1 to 8 or the system according to claim 9.