Multi-factor fusion stock data analysis method and system based on graph neural network
By constructing heterogeneous graph networks and dynamically adjusting factor weights, the problem of ignoring topological structure and signal transmission effects in traditional stock market prediction methods is solved, thereby improving prediction accuracy during extreme market conditions and market style switching.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANJING UNIV OF POSTS & TELECOMM
- Filing Date
- 2026-02-25
- Publication Date
- 2026-05-29
AI Technical Summary
Traditional stock market forecasting methods ignore the market's inherent topological structure and the cross-asset transmission effect of signals, failing to accurately depict the 'domino effect' of public opinion spreading through related corporate networks. Furthermore, multi-factor models fail to fully explore the higher-order interaction relationships and dynamic weight allocation mechanisms between factors, resulting in decreased forecast accuracy during extreme market conditions or market style shifts.
A multi-factor fusion stock data analysis method based on graph neural networks is adopted. By constructing a heterogeneous graph network by combining a transaction subgraph and a stock commentary subgraph, and combining graph attention network, long short-term memory network and reinforcement learning, the weights of multiple factors are dynamically adjusted to achieve cross-modal information fusion and time series modeling.
It effectively simulates market topology and signal transmission effects across assets, improving prediction accuracy during extreme market conditions and market style shifts, solving the prediction lag problem of traditional models, and adapting to rapid changes in market structure.
Smart Images

Figure CN122115107A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data analysis, specifically relating to a multi-factor fusion stock data analysis method and system based on graph neural networks. Background Technology
[0002] The stock market, as a dynamic and complex system comprised of listed companies, industry sectors, and supply chain relationships, experiences price fluctuations influenced by a combination of heterogeneous factors, including fundamentals, technicals, and market sentiment. These factors are also subject to complex nonlinear dynamic coupling relationships. Traditional stock market forecasting methods primarily rely on time series models and shallow machine learning, which can identify linear or locally nonlinear patterns to a certain extent.
[0003] However, existing technologies have many problems in stock market forecasting that urgently need to be solved: On the one hand, traditional models often treat stocks as independent entities, ignoring the inherent topological structure of the market and the cross-asset transmission effect of signals, and cannot accurately depict the "domino effect" of public opinion spreading through the network of related companies, resulting in a lag in systemic risk warnings; on the other hand, multi-factor models often use linear weighting or simple integration to process factors, failing to fully explore the higher-order interaction relationships and dynamic weight allocation mechanisms between factors, making it difficult to adapt to rapid changes in market structure, and the prediction accuracy drops significantly during extreme market conditions or market style switching. Summary of the Invention
[0004] The present invention aims to at least partially solve one of the technical problems existing in the related art.
[0005] One objective of this invention is to provide a multi-factor fusion stock data analysis method based on graph neural networks. This method constructs a heterogeneous graph network by fusing stock market data and stock forum commentary data, combines graph attention networks, long short-term memory networks, and time series modeling, and utilizes reinforcement learning to dynamically adjust the weights of multiple factors to achieve effective analysis of the stock market.
[0006] Another objective of this invention is to provide a multi-factor fusion stock data analysis system based on graph neural networks.
[0007] To achieve the above objectives, the present invention provides a multi-factor fusion stock data analysis method based on graph neural networks, comprising the following steps:
[0008] S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively;
[0009] S2. Construct a transaction subgraph and a stock comment subgraph based on the preprocessed stock data and stock forum comment data, and form a heterogeneous graph network by sharing stock nodes;
[0010] S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features.
[0011] S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results.
[0012] S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
[0013] A further preferred embodiment of the present invention is that step S1, which involves collecting historical stock data and corresponding stock forum comment data, and preprocessing the stock data and stock forum comment data respectively, specifically includes:
[0014] S11. Collect historical stock quote data for at least 5 consecutive trading days, as well as corresponding stock forum comment data;
[0015] S12. The stock market data is decomposed into multiple scales using discrete wavelet transform, and the decomposed wavelet coefficients are denoised using an adaptive threshold function, which is expressed as:
[0016]
[0017] in, The threshold value for the wavelet coefficients of the j-th layer is... The standard deviation of the noise in this layer is N, and the data length is N. The attenuation coefficient;
[0018] S13. Using a Bi-LSTM-CRF model combined with a dynamically expanded financial domain dictionary, the stock forum comment data is segmented into words. The segmented length is limited to 128 words, and a segmented sequence is generated.
[0019] Preferably, step S2 involves constructing a trading subgraph and a stock commentary subgraph based on the preprocessed stock data and stock forum commentary data, respectively, and then forming a heterogeneous graph network by sharing stock nodes between the trading subgraph and the stock commentary subgraph; specifically including:
[0020] S21. Based on the processed stock data, the GraphSAGE framework is used to construct a trading subgraph with each stock as a node. Each stock node contains a multi-dimensional feature matrix for each trading day. The edge weights of the trading subgraph are calculated by combining industry relevance and investor attention.
[0021] S22. Based on the word segmentation sequence, the FinBERT model is used to extract semantic features and construct a stock commentary subgraph. The FinBERT model contains a 12-layer Transformer encoder, calculates the inter-word dependency relationship through the self-attention mechanism, and outputs a 768-dimensional text vector containing financial semantics as node features. The cosine similarity between comments is used as the edge weight of the stock commentary subgraph.
[0022] S23. By sharing stock nodes and associating transaction subgraphs and stock commentary subgraphs, a heterogeneous graph network containing market characteristics, semantic features, and topological relationships is formed.
[0023] Preferably, step S3 involves using a graph attention network to aggregate features from the heterogeneous graph network and calculating the attention weights between nodes using a multi-head attention mechanism to obtain node-level fused features; specifically including:
[0024] S31, Transaction Subgraph Features Features of stock commentary sub-charts Sum of edge features Performing linear transformations respectively, we can express the following as:
[0025]
[0026]
[0027]
[0028] in, For the transaction subgraph, As edge features, This is a sub-chart for stock commentary;
[0029] S32. The transformed features are then fused through a feature concatenation layer to generate a unified graph representation vector X, which is represented as follows:
[0030]
[0031] in, The result of linear transformation of the characteristics of the transaction subgraph. The result of the linear transformation of edge features. The result of linear transformation of the stock commentary subgraph features, where m is the feature dimension;
[0032] S33. Subsequently, the unified graph representation vector X generated in step S32 is input into the multi-head graph attention network to calculate the attention weights between nodes. Then, the outputs of each head are concatenated and projected back to the original dimension through a feedforward neural network to obtain the node-level fusion features. The calculation formula is as follows:
[0033]
[0034] in To provide the output features of the graph attention network, These are the features after projection.
[0035] Preferably, step S33 employs a multi-head graph attention network to calculate the attention weights between nodes, specifically as follows:
[0036] The unnormalized attention coefficients between nodes are calculated using the LeakyReLU activation function, and are expressed as follows:
[0037]
[0038] The attention weights between nodes are obtained through softmax normalization and are expressed as follows:
[0039]
[0040] in, Here is the parameter vector for the attention mechanism; L is the number of multi-head attention heads. For attention weights between nodes, This represents the splicing of node features, enabling the model to dynamically focus on key nodes; This is the feature transformation weight matrix in the attention network, used to map the original features of nodes to a high-dimensional feature space. and They are nodes and nodes eigenvectors, For feature splicing operators.
[0041] Preferably, step S4 involves inputting the node-level fusion features into a long short-term memory network for time-series modeling, then combining this with a gating mechanism to capture time-series dependencies and outputting prediction results; specifically including:
[0042] S41. Arrange the node-level fusion features obtained in step S3 in temporal order to form a time series of length T. ,in Indicates the first Node-level fusion features at each time step;
[0043] S42. Input the time series data into a single-layer Long Short-Term Memory (LSTM) network and perform time series modeling using the following gating mechanism:
[0044] Forgotten Gate:
[0045]
[0046] in, This is the output vector of the forget gate; It is the sigmoid activation function; Here is the weight matrix for the forget gate; This is the bias vector for the forget gate; The input features for the current time step; This represents the hidden state of the Long Short-Term Memory (LSTM) network at the previous time step.
[0047] Input Gate:
[0048]
[0049] in, The output vector of the input gate; The bias vector for the input gate;
[0050] Cell state update equation:
[0051]
[0052] in, This is a candidate new information vector generated by the tanh function, used to supplement new information at the current time step; This represents the cell state at the previous moment; This represents the updated cell state at the current moment.
[0053] S43. Using a gated recurrent unit (GRU) to capture time series dependencies, represented as:
[0054]
[0055] in, Attention features for the output multi-head graph; The result of feature splicing; This is the initial hidden state of GRU. This represents the initial cell state of GRU. The time-series feature sequence output by the GRU;
[0056] S44. Integrating spatiotemporal features, a temporal attention mechanism is introduced to weight the output of the gated recurrent unit (GRU). The calculation formula is as follows:
[0057]
[0058] in, The feature of the last time step of the GRU output sequence; As the prediction result, it is output.
[0059] Preferably, step S5 introduces a reinforcement learning framework, using the prediction result as the state input, and employs a policy gradient algorithm to dynamically adjust the multi-factor weight allocation to update subsequent predictions; specifically:
[0060] The reinforcement learning framework employs a proximal strategy to optimize the PPO algorithm, which optimizes factor weights by maximizing cumulative rewards. The cumulative reward function is designed by combining the return rate and the Sharpe ratio.
[0061] Using the prediction results as state input, the policy gradient algorithm, based on the Bellman equation, is expressed as:
[0062]
[0063] in, The value function representing the state; It is the immediate reward for performing an action in a given state; Discount factor; It is the subsequent state after the transition.
[0064] Another aspect of the present invention provides a multi-factor fusion stock data analysis system based on graph neural networks, comprising:
[0065] The data acquisition and processing module is used to collect historical stock data and corresponding stock forum comment data, and to preprocess the stock data and stock forum comment data respectively;
[0066] The graph construction module is used to construct a transaction subgraph and a stock commentary subgraph based on preprocessed stock data and stock forum commentary data, and to form a heterogeneous graph network by sharing stock nodes between the transaction subgraph and the stock commentary subgraph.
[0067] The feature fusion module is used to aggregate features of the heterogeneous graph network using a graph attention network and calculate the attention weights between nodes through a multi-head attention mechanism to obtain node-level fused features.
[0068] The temporal modeling module is used to input node-level fused features into the long short-term memory network for temporal modeling, and then combine the gating mechanism to capture time series dependencies and output prediction results.
[0069] The reinforcement learning optimization module is used to dynamically adjust the multi-factor weight allocation using the prediction result as the state input and the policy gradient algorithm.
[0070] Prediction module: Used to output stock market prediction results.
[0071] In another aspect, the present invention provides a non-transitory computer-readable storage medium having computer instructions stored thereon, which cause a computer to execute the above-described multi-factor fusion stock data analysis method based on graph neural networks.
[0072] In another aspect, the present invention provides an electronic device, comprising: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus, and the processor calls logical instructions in the memory to execute the above-mentioned multi-factor fusion stock data analysis method based on graph neural networks.
[0073] In another aspect, the present invention provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer executes the above-described multi-factor fusion stock data analysis method based on graph neural networks.
[0074] Beneficial Effects: This invention presents a multi-factor fusion stock data analysis method based on graph neural networks. It constructs a heterogeneous graph network by integrating a trading subgraph and a stock commentary subgraph. The trading subgraph uses stocks as nodes based on the GraphSAGE framework, with node features including a multi-dimensional technology matrix. Edge weights are calculated based on industry relevance and investor attention. The stock commentary subgraph uses the FinBERT model to extract semantic features of comments and constructs edge weights using cosine similarity. The heterogeneous graph network achieves cross-modal information fusion by sharing stock nodes, capturing dynamic correlations between stocks and the path of public opinion propagation. It effectively simulates market topology and the cross-asset transmission effect of signals, thus solving the problem of traditional models ignoring the domino effect.
[0075] This invention combines graph attention networks and proximal strategy optimization algorithms to dynamically adjust the weights of multiple factors. The graph attention network calculates the attention weights between nodes through a multi-head attention mechanism, integrating features from the trading subgraph and the stock commentary subgraph. The proximal strategy optimization algorithm designs a reward function based on the Bellman equation, combines the return rate and Sharpe ratio, and adjusts the factor weights in real time through reinforcement learning to adapt to market style switching and solve the problem of decreased prediction accuracy of linear weighted models in extreme market conditions. Attached Figure Description
[0076] Figure 1 This is a flowchart of the multi-factor fusion stock data analysis method based on graph neural networks of the present invention;
[0077] Figure 2 This is a schematic diagram of the market data noise reduction process of the present invention;
[0078] Figure 3 The transaction subgraph constructed for Embodiment 1 of the present invention;
[0079] Figure 4 This is a schematic diagram of the FinBERT model structure of the present invention. Detailed Implementation
[0080] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, embodiments of this invention, and should not be construed as limiting the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. In the description of this invention, it should be understood that the terminology used is for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0081] The following is combined Figures 1-4 This invention describes a multi-factor fusion stock data analysis method and system based on graph neural networks.
[0082] Example 1: This example provides a multi-factor fusion stock data analysis method based on graph neural networks, such as... Figure 1 As shown, it includes the following steps:
[0083] S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively.
[0084] S11. During the data collection phase, the Tushare platform API was used to obtain market data of the CSI 300 constituent stocks from 2017 to 2024, including 8-dimensional features such as price change rate, trading volume and technical indicators for 5 trading days; at the same time, stock forum comment data was crawled to form a multi-source dataset of structured and unstructured data; the collected data includes fields such as ts_code and transaction amount of brokerage firms. For example, the Donghao Securities brokerage firm of stock code 000151.SZ bought 35,193,475.42 yuan and sold 15,619,099.64 yuan, with a net purchase of 19,574,375.78 yuan.
[0085] S12. In the market data denoising stage, discrete wavelet transform is used to decompose the stock market data into multiple scales, and an adaptive threshold function is used to denoise the decomposed wavelet coefficients. The adaptive threshold function is expressed as:
[0086]
[0087] in, The threshold value for the wavelet coefficients of the j-th layer is... The standard deviation of the noise in this layer is N, and the data length is N. The attenuation coefficient is used; the decomposition process is as follows: Figure 2 As shown, by separating the low-frequency approximation component from the high-frequency detail component, the price mutation characteristics are preserved and random fluctuations are suppressed, resulting in a signal-to-noise ratio improvement of more than 15dB.
[0088] S13. In the text segmentation preprocessing stage, a Bi-LSTM-CRF model is adopted, combined with a dynamic financial dictionary containing stock codes, company abbreviations, policy terms, and popular online terms for segmentation. Regular expression matching is used to process numerical expressions (such as "10-for-5 stock split") and mixed Chinese and English words, solving the segmentation problem of ambiguous structures such as "China Ping An Bank". The recall rate of out-of-vocabulary words is improved to 92%. After segmentation, the length is limited to 128 words, and a segmented sequence is generated.
[0089] S2. Construct a transaction subgraph and a stock commentary subgraph based on the preprocessed stock data and stock forum commentary data respectively, and form a heterogeneous graph network by sharing stock nodes.
[0090] S21. Based on the processed stock data, the GraphSAGE framework is adopted, with stocks as nodes. Node features include an 8-dimensional technical matrix (price change rate, trading volume, RSI, etc.) for 5 trading days. Edge weights are calculated based on industry relevance and investor attention; for example, the edge weight of stocks in the same industry is increased by 30%. Investor attention is standardized based on the frequency of mentions in stock forum comments, constructing a framework such as... Figure 3 The transaction sub-chart shown captures the dynamic relationships between stocks;
[0091] S22. Based on the word segmentation sequence, semantic features are extracted using the FinBERT model to construct a stock commentary subgraph. The FinBERT model contains a 12-layer Transformer encoder and employs a self-attention mechanism.
[0092]
[0093] Calculate inter-word dependencies. Input comments are segmented and their length is limited to 128 words. Output a 768-dimensional text vector as node features. Construct a graph structure with cosine similarity between comments as edge weights. Optimize edge weights through a graph attention network and assign higher propagation weights to key comments.
[0094] During model training, a dataset from 2017 to 2024 was used, with input comment length limited to 128 words. The Dropout rate was set to 0.5, the learning rate to 0.00005, and the batch size to 64. Parameters were adjusted using cross-validation. The model is based on a Transformer encoder, such as... Figure 4 The FinBERT model shown learns the emotional polarity and semantic association of semantic representations in the financial field, such as "earnings report exceeds expectations" and "major players are selling off", through a 12-layer network structure and self-attention mechanism.
[0095] In the semantic feature extraction stage, positional encoding is added to the preprocessed comment segmentation sequence, which is then input into the FinBERT model. The inter-word dependencies are calculated through a self-attention mechanism, and the output text representation vector containing financial semantics is generated. Document-level features are generated through pooling operations and used for the construction of stock comment subgraphs. The correlation between the features and the stock price change the next day reaches 0.51, effectively capturing the impact of public opinion on the market.
[0096] S23. In the heterogeneous graph network formation stage, by associating stock code nodes with transaction subgraphs and stock commentary subgraphs, a heterogeneous graph network containing market characteristics, semantic features and topological relationships is formed, realizing cross-modal information mapping and improving the mutual information between node features and real market fluctuations by 40%.
[0097] S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features.
[0098] S31. In the feature linear transformation stage, the transaction subgraph features are transformed. Features of stock commentary sub-charts Sum of edge features Performing linear transformations respectively, we can express the following as:
[0099]
[0100]
[0101]
[0102] in, For the transaction subgraph, As edge features, This is a sub-chart for stock commentary;
[0103] S32. The transformed features are then fused through a feature concatenation layer to generate a unified graph representation vector X, which is represented as follows:
[0104]
[0105] in, The result of linear transformation of the characteristics of the transaction subgraph. The result of the linear transformation of edge features. The result of linear transformation of the stock commentary subgraph features, where m is the feature dimension;
[0106] S33. In the attention coefficient calculation stage, the LeakyReLU activation function is used to calculate the unnormalized attention coefficients between nodes, expressed as:
[0107]
[0108] The attention weights between nodes are obtained through softmax normalization and are expressed as follows:
[0109]
[0110] in, Here is the parameter vector for the attention mechanism; L is the number of multi-head attention heads. For attention weights between nodes, This represents the splicing of node features, enabling the model to dynamically focus on key nodes; This is the feature transformation weight matrix in the attention network, used to map the original features of nodes to a high-dimensional feature space. and They are nodes and nodes eigenvectors, For feature splicing operators.
[0111] S34. In the multi-head attention aggregation stage, a multi-head attention mechanism is used for parallel computation. The unified graph representation vector X generated in step S32 is input into the multi-head graph attention network to calculate the attention weights between nodes. Then, the outputs of each head are concatenated and projected back to the original dimension through a feedforward neural network to obtain the node-level fusion features. The calculation formula is as follows:
[0112]
[0113] in To provide the output features of the graph attention network, These are post-projection features. Multi-headed structures enhance the ability to capture multi-scale correlated features, such as simultaneously monitoring industry linkages and individual stock sentiment impacts.
[0114] S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results.
[0115] S41. Arrange the node-level fusion features obtained in step S3 in temporal order to form a time series of length T. ,in Indicates the first Node-level fusion features at each time step;
[0116] S42. Input the time series data into a single-layer Long Short-Term Memory (LSTM) network and perform time series modeling using the following gating mechanism:
[0117] Forgotten Gate:
[0118]
[0119] in, This is the output vector of the forget gate; It is the sigmoid activation function; Here is the weight matrix for the forget gate; This is the bias vector for the forget gate; The input features for the current time step; This represents the hidden state of the Long Short-Term Memory (LSTM) network at the previous time step.
[0120] Input Gate:
[0121]
[0122] in, The output vector of the input gate; The bias vector for the input gate;
[0123] Cell state update equation:
[0124]
[0125] in, This is a candidate new information vector generated by the tanh function, used to supplement new information at the current time step; This represents the cell state at the previous moment; This represents the updated cell state at the current moment.
[0126] S43. Using a gated recurrent unit (GRU) to capture time series dependencies, represented as:
[0127]
[0128] in, Attention features for the output multi-head graph; The result of feature splicing; This is the initial hidden state of GRU. This represents the initial cell state of GRU. The time-series feature sequence output by the GRU;
[0129] S44. Integrating spatiotemporal features, a temporal attention mechanism is introduced to weight the output of the gated recurrent unit (GRU). The calculation formula is as follows:
[0130]
[0131] in, The feature of the last time step of the GRU output sequence; As the prediction result, it is output.
[0132] S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
[0133] The reinforcement learning framework employs a proximal strategy to optimize the PPO algorithm, which optimizes factor weights by maximizing cumulative rewards. The cumulative reward function is designed by combining the return rate and the Sharpe ratio.
[0134] Using the prediction results as state input, the policy gradient algorithm, based on the Bellman equation, is expressed as:
[0135]
[0136] in, The value function representing the state; It is the immediate reward for performing an action in a given state; Discount factor; It is the subsequent state after the transition.
[0137] In summary, this multi-factor fusion stock data analysis method based on graph neural networks constructs a heterogeneous graph network by building a trading subgraph and a stock commentary subgraph. The trading subgraph uses stocks as nodes based on the GraphSAGE framework, and the node features include an 8-dimensional technical matrix for 5 trading days. The edge weights are calculated based on industry relevance and investor attention. The stock commentary subgraph uses the FinBERT model to extract the semantic features of the comments and constructs the edge weights through cosine similarity. The heterogeneous graph network achieves cross-modal information fusion by sharing stock nodes, capturing the dynamic correlation between stocks and the path of public opinion propagation, effectively simulating the market topology and the cross-asset transmission effect of signals, thereby solving the problem of traditional models ignoring the domino effect.
[0138] Furthermore, this multi-factor fusion stock market prediction method based on graph neural networks dynamically adjusts the weights of multiple factors by combining graph attention networks and proximal strategy optimization algorithms. The graph attention network calculates the attention weights between nodes through a multi-head attention mechanism, fusing features from the trading subgraph and the stock commentary subgraph. The proximal strategy optimization algorithm designs a reward function based on the Bellman equation, combining returns and Sharpe ratios, and adjusts factor weights in real time through reinforcement learning to adapt to market style shifts. This solves the problem of decreased prediction accuracy in extreme market conditions caused by linear weighted models. It also addresses the issue that traditional models often treat stocks as independent entities, ignoring the inherent topological structure of the market and the cross-asset transmission effect of signals, failing to accurately depict the "domino effect" of public opinion spreading through related enterprise networks, resulting in delayed systemic risk warnings. Multi-factor models often use linear weighting or simple ensemble methods to process factors, failing to fully explore the higher-order interaction relationships and dynamic weight allocation mechanisms between factors, making it difficult to adapt to rapid changes in market structure and causing a significant decrease in prediction accuracy in extreme market conditions or market style shifts.
[0139] Example 2: This example provides a multi-factor fusion stock data analysis system based on graph neural networks, including:
[0140] The data acquisition and processing module is used to collect historical stock data and corresponding stock forum comment data, and to preprocess the stock data and stock forum comment data respectively;
[0141] The graph construction module is used to construct a transaction subgraph and a stock commentary subgraph based on preprocessed stock data and stock forum commentary data, and to form a heterogeneous graph network by sharing stock nodes between the transaction subgraph and the stock commentary subgraph.
[0142] The feature fusion module is used to aggregate features of the heterogeneous graph network using a graph attention network and calculate the attention weights between nodes through a multi-head attention mechanism to obtain node-level fused features.
[0143] The temporal modeling module is used to input node-level fused features into the long short-term memory network for temporal modeling, and then combine the gating mechanism to capture time series dependencies and output prediction results.
[0144] The reinforcement learning optimization module is used to dynamically adjust the multi-factor weight allocation using the prediction result as the state input and the policy gradient algorithm.
[0145] Prediction module: Used to output stock market prediction results.
[0146] Example 3: This example provides a non-transitory computer-readable storage medium storing computer instructions that cause a computer to execute a multi-factor fusion stock data analysis method based on graph neural networks. The method includes the following steps:
[0147] S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively;
[0148] S2. Construct a transaction subgraph and a stock comment subgraph based on the preprocessed stock data and stock forum comment data, and form a heterogeneous graph network by sharing stock nodes;
[0149] S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features.
[0150] S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results.
[0151] S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
[0152] Example 4: This example provides an electronic device that may include a processor, a communication interface, a memory, and a communication bus. The processor, communication interface, and memory communicate with each other via the communication bus. The processor can call logical instructions from the memory to execute a multi-factor fusion stock data analysis method based on graph neural networks. This method includes the following steps:
[0153] S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively;
[0154] S2. Construct a transaction subgraph and a stock comment subgraph based on the preprocessed stock data and stock forum comment data, and form a heterogeneous graph network by sharing stock nodes;
[0155] S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features.
[0156] S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results.
[0157] S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
[0158] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0159] Example 5: This example provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute a multi-factor fusion stock data analysis method based on a graph neural network. This method includes the following steps:
[0160] S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively;
[0161] S2. Construct a transaction subgraph and a stock comment subgraph based on the preprocessed stock data and stock forum comment data, and form a heterogeneous graph network by sharing stock nodes;
[0162] S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features.
[0163] S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results.
[0164] S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
[0165] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0166] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0167] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A multi-factor fusion stock data analysis method based on graph neural networks, characterized in that, Includes the following steps: S1. Collect historical stock data and corresponding stock forum comment data, and preprocess the stock data and stock forum comment data respectively; S2. Construct a transaction subgraph and a stock comment subgraph based on the preprocessed stock data and stock forum comment data, and form a heterogeneous graph network by sharing stock nodes; S3. A graph attention network is used to aggregate features of the heterogeneous graph network, and the attention weights between nodes are calculated through a multi-head attention mechanism to obtain node-level fused features. S4. Input the node-level fusion features into the long short-term memory network for time series modeling, and then combine the gating mechanism to capture the time series dependencies and output the prediction results. S5. Introduce a reinforcement learning framework, using the prediction results as state input, and use the policy gradient algorithm to dynamically adjust the weight allocation of multiple factors to update subsequent predictions.
2. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 1, characterized in that, Step S1 involves collecting historical stock data and corresponding stock forum comment data, and preprocessing the stock data and stock forum comment data respectively, specifically including: S11. Collect historical stock quote data for at least 5 consecutive trading days, as well as corresponding stock forum comment data; S12. The stock market data is decomposed into multiple scales using discrete wavelet transform, and the decomposed wavelet coefficients are denoised using an adaptive threshold function, which is expressed as: ; in, The threshold for the wavelet coefficients of the j-th layer, Where N is the standard deviation of the noise level for this layer, and N is the data length. The attenuation coefficient; S13. Using a Bi-LSTM-CRF model combined with a dynamically expanded financial domain dictionary, the stock forum comment data is segmented into words. The segmented length is limited to 128 words, and a segmented sequence is generated.
3. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 2, characterized in that, Step S2 involves constructing a trading subgraph and a stock commentary subgraph based on the preprocessed stock data and stock forum commentary data, respectively, and then forming a heterogeneous graph network by sharing stock nodes between the trading subgraph and the stock commentary subgraph; specifically including: S21. Based on the processed stock data, the GraphSAGE framework is used to construct a trading subgraph with each stock as a node. Each stock node contains a multi-dimensional feature matrix for each trading day. The edge weights of the trading subgraph are calculated by combining industry relevance and investor attention. S22. Based on the word segmentation sequence, the FinBERT model is used to extract semantic features and construct a stock commentary subgraph. The FinBERT model contains a 12-layer Transformer encoder, calculates the inter-word dependency relationship through the self-attention mechanism, and outputs a 768-dimensional text vector containing financial semantics as node features. The cosine similarity between comments is used as the edge weight of the stock commentary subgraph. S23. By sharing stock nodes and associating transaction subgraphs and stock commentary subgraphs, a heterogeneous graph network containing market characteristics, semantic features, and topological relationships is formed.
4. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 1, characterized in that, Step S3 involves using a graph attention network to aggregate features from the heterogeneous graph network and calculating the attention weights between nodes using a multi-head attention mechanism to obtain node-level fused features; specifically, this includes: S31, Transaction Subgraph Features Stock commentary sub-chart features Sum of edge features Performing linear transformations respectively, we can express the following as: ; ; ; in, For the transaction subgraph, As edge features, This is a sub-chart for stock commentary; S32. The transformed features are then fused through a feature concatenation layer to generate a unified graph representation vector X, which is represented as follows: ; in, The result of linear transformation of the characteristics of the transaction subgraph. The result of the linear transformation of edge features. The result of linear transformation of the stock commentary subgraph features, where m is the feature dimension; S33. Subsequently, the unified graph representation vector X generated in step S32 is input into the multi-head graph attention network to calculate the attention weights between nodes. Then, the outputs of each head are concatenated and projected back to the original dimension through a feedforward neural network to obtain the node-level fusion features. The calculation formula is as follows: ; in To provide the output features of the graph attention network, These are the features after projection.
5. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 4, characterized in that, Step S33 employs a multi-head graph attention network to calculate the attention weights between nodes, specifically as follows: The unnormalized attention coefficients between nodes are calculated using the LeakyReLU activation function, and are expressed as follows: ; The attention weights between nodes are obtained through softmax normalization and are expressed as follows: ; in, Here is the parameter vector for the attention mechanism; L is the number of multi-head attention heads. For attention weights between nodes, This represents the splicing of node features, enabling the model to dynamically focus on key nodes; This is the feature transformation weight matrix in the attention network, used to map the original features of nodes to a high-dimensional feature space. and They are nodes and nodes eigenvectors, For feature splicing operators.
6. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 1, characterized in that, Step S4 involves inputting node-level fused features into a long short-term memory network for time-series modeling, then combining a gating mechanism to capture time-series dependencies and outputting prediction results; specifically including: S41. Arrange the node-level fusion features obtained in step S3 in temporal order to form a time series of length T. ,in Indicates the first Node-level fusion features at each time step; S42. Input the time series data into a single-layer Long Short-Term Memory (LSTM) network and perform time series modeling using the following gating mechanism: Forgotten Gate: ; in, This is the output vector of the forget gate; It is the sigmoid activation function; Here is the weight matrix for the forget gate; This is the bias vector for the forget gate; The input features for the current time step; This represents the hidden state of the Long Short-Term Memory (LSTM) network at the previous time step. Input Gate: ; in, The output vector of the input gate; The bias vector for the input gate; Cell state update equation: ; in, This is a candidate new information vector generated by the tanh function, used to supplement new information at the current time step; This represents the cell state at the previous moment; This represents the updated cell state at the current moment. S43. Using a gated recurrent unit (GRU) to capture time series dependencies, represented as: ; in, Attention features for the output multi-head graph; The result of feature splicing; This is the initial hidden state of GRU. This represents the initial cell state of GRU. The time-series feature sequence output by the GRU; S44. Integrating spatiotemporal features, a temporal attention mechanism is introduced to weight the output of the gated recurrent unit (GRU). The calculation formula is as follows: ; in, The feature of the last time step of the GRU output sequence; As the prediction result, it is output.
7. The multi-factor fusion stock data analysis method based on graph neural networks according to claim 1, characterized in that, Step S5 introduces a reinforcement learning framework, using the prediction result as the state input and employing a policy gradient algorithm to dynamically adjust the multi-factor weight allocation to update subsequent predictions; specifically: The reinforcement learning framework employs a proximal strategy to optimize the PPO algorithm, which optimizes factor weights by maximizing cumulative rewards. The cumulative reward function is designed by combining the return rate and the Sharpe ratio. Using the prediction results as state input, the policy gradient algorithm, based on the Bellman equation, is expressed as: ; in, The value function representing the state; It is the immediate reward for performing an action in a given state; Discount factor; It is the subsequent state after the transition.
8. A multi-factor fusion stock data analysis system based on graph neural networks, characterized in that, include: The data acquisition and processing module is used to collect historical stock data and corresponding stock forum comment data, and to preprocess the stock data and stock forum comment data respectively; The graph construction module is used to construct a transaction subgraph and a stock commentary subgraph based on preprocessed stock data and stock forum commentary data, and to form a heterogeneous graph network by sharing stock nodes between the transaction subgraph and the stock commentary subgraph. The feature fusion module is used to aggregate features of the heterogeneous graph network using a graph attention network and calculate the attention weights between nodes through a multi-head attention mechanism to obtain node-level fused features. The temporal modeling module is used to input node-level fused features into the long short-term memory network for temporal modeling, and then combine the gating mechanism to capture time series dependencies and output prediction results. The reinforcement learning optimization module is used to dynamically adjust the multi-factor weight allocation using the prediction result as the state input and the policy gradient algorithm. Prediction module: Used to output stock market prediction results.
9. A non-transitory computer-readable storage medium, characterized in that, It stores computer instructions that cause the computer to execute the multi-factor fusion stock data analysis method based on graph neural networks as described in any one of claims 1-7.
10. An electronic device, characterized in that, include: The system includes a processor, a communication interface, a memory, and a communication bus. The processor, communication interface, and memory communicate with each other via the communication bus. The processor calls logical instructions from the memory to execute the multi-factor fusion stock data analysis method based on graph neural networks as described in any one of claims 1-7.