Stock price trend prediction method based on heterogeneous graph neural network and LLM fine tuning

By constructing heterogeneous knowledge graphs and graph neural networks, and combining multi-scale convolutional kernels and cross-feature attention networks, the problem of multi-source heterogeneous data fusion is solved, thereby improving the accuracy and stability of stock price trend prediction and providing an efficient financial market analysis solution.

CN120875945APending Publication Date: 2025-10-31BEIJING INST OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510758438.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-09
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

Existing stock price prediction methods struggle to effectively integrate multi-source heterogeneous data and relationships between market entities, resulting in insufficient accuracy in stock price trend prediction. Traditional graph neural networks also have limitations in processing heterogeneous data and dynamic evolutionary characteristics in financial markets.

Method used

By constructing a heterogeneous knowledge graph and combining graph neural networks with a pre-trained large language model, market features are captured through multi-scale convolutional kernels and cross-feature attention networks. Homogeneous domain message passing and heterogeneous fusion modules are introduced to integrate heterogeneous data sources and improve the accuracy of stock price trend prediction.

Benefits of technology

It significantly improves the accuracy and stability of stock price trend prediction, reduces the complexity of system implementation, enhances the model's generalization ability and computational efficiency, and enables rapid response to market changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120875945A_ABST
    Figure CN120875945A_ABST
Patent Text Reader

Abstract

The invention discloses a stock price trend prediction method based on a heterogeneous graph neural network and LLM fine tuning, and belongs to the technical field of artificial intelligence and financial risk control. The implementation method comprises the following steps: 1, constructing a heterogeneous knowledge graph G; 2, acquiring technical plane features and basic plane features; 3, isomorphic features are extracted and diffused, and cross-modal heterogeneous fusion is carried out; 4, mapping the heterogeneous fusion features to a token sequence by modifying position codes, performing fine adjustment on a pre-trained large language model, and performing binary classification output through a full connection layer; 5, performing optimization training on the stock price trend prediction model and the large language model by using cross entropy loss; and 6, constructing a multi-hop connected sub-graph, inputting the multi-hop connected sub-graph into the trained stock price trend prediction model and the big language model, and outputting dichotomy prediction data of the stock price of the specified listed company. Compared with the prior art, the method solves the technical problem of fusing the relation between the multi-source heterogeneous data and the market entity and improving the accuracy of stock price trend prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning, belonging to the fields of artificial intelligence and financial risk control technology, and applied to stock price trend prediction. Background Technology

[0002] In recent years, with the globalization of financial markets and the rapid development of information technology, the stock market has become increasingly complex and volatile. Accurately predicting stock price trends has become crucial for investment decisions and collateral management; however, traditional stock price prediction methods face numerous challenges.

[0003] Currently, stock price prediction technologies in the market are mainly divided into two categories: methods based on technical analysis and methods based on fundamental analysis. Technical analysis mainly relies on historical price and trading data, capturing price patterns through statistical learning or deep learning models. However, these methods often ignore the influence of external market information and are difficult to cope with market fluctuations caused by sudden events. Fundamental analysis focuses on the study of company financial conditions, industry environment, and macroeconomic factors. However, traditional fundamental analysis methods are difficult to handle unstructured text data and lack consideration for the complex relationship networks between listed companies. In addition, existing prediction models usually treat data from different sources in isolation, lacking an effective mechanism for integrating heterogeneous information. At the same time, traditional graph neural networks have limitations in processing heterogeneous data and dynamic evolution characteristics in financial markets, and cannot fully capture the complex relationships and information transmission patterns between different types of nodes.

[0004] Therefore, how to integrate multi-source heterogeneous data and the relationships between market entities to improve the accuracy of stock price trend prediction has become an urgent technical problem to be solved. Summary of the Invention

[0005] The purpose of this invention is to address the technical problem of improving the accuracy of stock price trend prediction by fusing multi-source heterogeneous data and relationships between market entities. This invention proposes a stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning. Specifically, this invention aims to improve the accuracy of stock price trend prediction by capturing market features at different time windows through multi-scale convolutional kernels and cross-feature attention networks. It processes heterogeneous data from both technical and fundamental aspects in parallel, and further introduces homogeneous domain message passing and heterogeneous fusion modules to integrate heterogeneous data sources, thereby enhancing the accuracy of stock price trend prediction.

[0006] The objective of this invention is achieved through the following technical solution:

[0007] The stock price trend prediction method disclosed in this invention, based on heterogeneous graph neural networks and LLM fine-tuning, includes the following steps:

[0008] Step 1: Construct a heterogeneous knowledge graph G with relational node connections, and set initial data for the nodes of the heterogeneous knowledge graph;

[0009] Step 1.1: Construct a heterogeneous knowledge graph G consisting of listed company nodes, historical data nodes, event nodes, news nodes, public opinion nodes, and relationship nodes;

[0010] Step 1.1.1: Designate the listed company node as the root node; historical data nodes, event nodes, news nodes, and public opinion nodes as child nodes; connect the root node and child nodes through directed edges;

[0011] Step 1.1.2: Connect adjacent root nodes through relation nodes;

[0012] Step 1.2: Use the entity data of listed companies as listed company nodes; use financial statistics and market sentiment indicators as historical data nodes; use objectively categorized market event data in a fixed format, news messages, and public opinion data without objective categorization as event nodes, news nodes, and public opinion nodes, respectively.

[0013] Step 2: Construct a stock price trend prediction model, using the TCN-Transformer model and Transformer encoder to obtain technical and fundamental features respectively;

[0014] Step 2.1: Use the characteristics of historical data nodes as technical features; use the characteristics of event nodes, news nodes, and public opinion nodes as basic features;

[0015] Step 2.2: Construct a stock price trend prediction model and use the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales;

[0016] Step 2.2.1: Extract time-series features at the time granularity of historical data nodes using a one-dimensional convolutional layer with the kernel of the stock price trend prediction model;

[0017] Step 2.2.2: Use a cross-feature attention network to obtain the attention weights of the temporal features as shown in Equation (1);

[0018]

[0019] Where Q, K, and V are the query matrix, key matrix, and value matrix of the historical data node, respectively, and d k The dimension of the key vector; the softmax function transforms the input into a probability distribution of temporal features, ensuring that all weights sum to 1 and are all positive values;

[0020] Step 2.2.3: Concatenate the attention weights of the time series features with the time series features at the time granularity of historical data nodes, and input them into the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales;

[0021] Step 2.3: Use the pre-trained Transformer encoder of the stock price trend prediction model to extract the embedded representations of event nodes, news nodes, and public opinion nodes with the same dimensions as the technical time series features;

[0022] Step 3: Within the stock price trend prediction model, a graph attention network is used to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality, and multi-head attention is used to perform cross-modal heterogeneous fusion of the isomorphic features.

[0023] Step 3.1: Construct subgraphs for listed companies, historical data, events, news, and public opinion using adjacent adjacency relationships, respectively, forming a unimodal isomorphic subgraph from the original multimodal subgraphs.

[0024] Step 3.2: Use the graph attention network shown in Equation (2) to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality;

[0025]

[0026] in, This represents the technical or fundamental characteristics of node i at layer l. Let i represent the set of neighbors of node i. W represents the attention coefficient. ( l ) Let σ be the weight matrix, and σ be the nonlinear activation function.

[0027] Step 3.3: Utilize multi-head attention to perform cross-modal heterogeneous fusion of isomorphic features;

[0028] Step 3.3.1: Use the isomorphic features of a single modality as the query, key, and value of the attention mechanism;

[0029] Step 3.3.2: Concatenate the query, key, and value of the attention mechanism with the attention weight, and fuse them with the technical features and basic features to form a cross-modal heterogeneous fusion feature as shown in Equation (3);

[0030] Z=MultiHead(Q,K,V)=Concat(head1,head2,…,head h W O (3)

[0031] Among them, head i =Attention(QW i Q ,KW i K VW iV ), W i Q W i K W i V and W O The parameter matrix is ​​learnable; MultiHead represents a multi-head attention mechanism, which captures richer feature relationships by computing multiple attention heads in parallel, each focusing on different parts of the input data; the Concat operation concatenates the outputs of multiple attention heads into a larger matrix according to their dimensions, and then passes the result through the parameter matrix W. O Perform a linear transformation to obtain the final attention output;

[0032] Step 4: Map the heterogeneous fusion features to the token sequence by modifying the positional encoding, fine-tune the pre-trained large language model, and output the hidden layer of the fine-tuned large language model in binary classification through a fully connected layer;

[0033] Step 4.1: Map heterogeneous fusion features to token sequences using modified positional encoding, and fine-tune the pre-trained large language model;

[0034] Step 4.1.1: Set the token sequence for the cross-modal heterogeneous fusion feature as shown in equation (4);

[0035] X input =[x GNN,1 ,x GNN,2 ,…,x GNN,m ,x text,1 ,x text,2 ,…,x text,n (4)

[0036] Where, x GNN,i This indicates the token position reserved for the embedded representation, x text,j This represents the token of the original text input.

[0037] Step 4.1.2: Map the heterogeneous fusion features to the token sequence using the modified position encoding as shown in equation (5);

[0038]

[0039] Among them, E pos [i] is the position code of position i, E GNN [i] represents the heterogeneous fusion feature, Eoriginal [i] is the positional encoding of the original text;

[0040] Step 4.1.3: Fine-tune the pre-trained large language model in the manner shown in Equation (6);

[0041]

[0042] where, δ(i < m) is an indicator function, which is 1 when i < m and 0 otherwise, indicating that the embedding is only applied at the reserved token positions; and are learnable parameter matrices that project the cross-modal heterogeneous fusion features into the query, key, and value spaces;

[0043] Step 4.2: Perform binary classification output as shown in Equation (7) on the hidden layer of the fine-tuned large language model through a fully connected layer;

[0044]

[0045] where, h (L) is the output representation of the last layer of the large language model, W o and b o are the weights and biases of the output layer respectively, σ is the sigmoid activation function, and the output value represents the probability of the stock price rising; when it is predicted that the stock price will rise; otherwise, it is predicted that the stock price will fall;

[0046] Step 5: Optimize and train the stock price trend prediction model and the large language model using the cross-entropy loss as shown in Equation (8);

[0047]

[0048] where, N is the number of samples, y i is the true label, is the predicted value;

[0049] Step 6: Construct a multi-hop connected subgraph and input it into the trained stock price trend prediction model and large language model to output binary classification prediction data of the stock price of a specified listed company;

[0050] Step 6.1: Form a multi-hop connected subgraph by depth-first traversal of the root node;

[0051] Step 6.2: Input the multi-hop connected subgraph into the trained stock price trend prediction model and large language model to output binary classification prediction data of the stock price of a specified listed company;

[0052] Compared with the prior art, the following beneficial effects are achieved:

[0053] This method effectively integrates heterogeneous data by constructing a heterogeneous knowledge graph and combining it with graph neural networks and pre-trained models, significantly improving the accuracy and stability of stock price trend prediction. The standardized directed market knowledge graph makes the structured representation of financial data clearer and reduces the complexity of system implementation; multi-scale convolutional kernels and cross-feature attention networks effectively identify price trend patterns across different time windows; homogeneous domain message passing and heterogeneous fusion mechanisms achieve deep integration of technical and fundamental information, overcoming the information silo problem in traditional methods; feature embedding and inference based on pre-trained models improve the model's generalization ability without adding trainable parameters; and the parallel processing architecture significantly improves computational efficiency, enabling the model to respond quickly to market changes. This method provides a more comprehensive, accurate, and efficient technical solution for financial market analysis. Attached Figure Description

[0054] Figure 1 This is a flowchart illustrating the present invention; Detailed Implementation

[0055] To better illustrate the purpose and advantages of this invention, the invention will be further described below with reference to the accompanying drawings and examples. It should be noted that the implementation of this invention is not limited to the following embodiments, and any modifications or alterations made to this invention will fall within the scope of protection of this invention.

[0056] Example

[0057] like Figure 1 As shown, the specific implementation steps of the stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning in this embodiment are as follows:

[0058] Step 1: Construct a heterogeneous knowledge graph G with relational node connections, and set initial data for the nodes of the heterogeneous knowledge graph;

[0059] Step 1.1: Construct a heterogeneous knowledge graph G consisting of listed company nodes, historical data nodes, event nodes, news nodes, public opinion nodes, and relationship nodes;

[0060] Step 1.1.1: Designate the listed company node as the root node; historical data nodes, event nodes, news nodes, and public opinion nodes as child nodes; connect the root node and child nodes through directed edges;

[0061] Step 1.1.2: Connect adjacent root nodes through relation nodes;

[0062] Step 1.2: Use the entity data of listed companies as listed company nodes; use financial statistics and market sentiment indicators as historical data nodes; use objectively categorized market event data in a fixed format, news messages, and public opinion data without objective categorization as event nodes, news nodes, and public opinion nodes, respectively.

[0063] In this embodiment, 100 listed companies in the A-share market were selected as the research subjects, spanning from January 1, 2020 to December 31, 2023. The entity data of the listed companies included basic company information (stock code, industry classification, market capitalization level) and financial indicators (return on equity, price-to-earnings ratio, and debt ratio).

[0064] Historical data nodes include the following 15-dimensional feature vectors: basic price data includes opening price, closing price, highest price, lowest price, trading volume, and trading value; technical indicators include the 5-day moving average, 20-day moving average, RSI (Relative Strength Index), MACD indicator, KDJ stochastic indicator, Bollinger Band upper band, Bollinger Band lower band, Williams %R indicator, and volume-weighted average price. Market sentiment indicators use two macroeconomic sentiment data points: the VIX fear index and the investor confidence index.

[0065] Event node data is sourced from announcements in the Wind financial database, categorized into eight main types: financial report releases, management changes, major contract signings, mergers and acquisitions, equity incentives, dividend distributions, earnings forecasts, and trading suspensions / resumptions. Each event type uses one-hot encoding. News node data is derived from news reports on four financial media platforms: Sina Finance, Eastmoney, Securities Times, and Shanghai Securities News, averaging approximately 500 related news articles collected daily. Public opinion node data is sourced from user discussions on three social media platforms: Weibo, Guba, and Xueqiu, collecting approximately 2,000 related comments daily. Relationship nodes describe the relationships between listed companies, including supply chain relationships, competitive relationships, industry peer relationships, and litigation relationships, constructed using corporate annual reports and publicly available information.

[0066] Step 2: Construct a stock price trend prediction model, using the TCN-Transformer model and Transformer encoder to obtain technical and fundamental features respectively;

[0067] Step 2.1: Use the characteristics of historical data nodes as technical features; use the characteristics of event nodes, news nodes, and public opinion nodes as basic features;

[0068] Step 2.2: Construct a stock price trend prediction model and use the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales;

[0069] Step 2.2.1: Extract time-series features at the time granularity of historical data nodes using a one-dimensional convolutional layer with the kernel of the stock price trend prediction model;

[0070] Step 2.2.2: Use a cross-feature attention network to obtain the attention weights of the temporal features as shown in Equation (1);

[0071]

[0072] Where Q, K, and V are the query matrix, key matrix, and value matrix of the historical data node, respectively, and d k The dimension of the key vector; the softmax function transforms the input into a probability distribution of temporal features, ensuring that all weights sum to 1 and are all positive values;

[0073] Step 2.2.3: Concatenate the attention weights of the time series features with the time series features at the time granularity of historical data nodes, and input them into the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales;

[0074] Step 2.3: Use the pre-trained Transformer encoder of the stock price trend prediction model to extract the embedded representations of event nodes, news nodes, and public opinion nodes with the same dimensions as the technical time series features;

[0075] In this embodiment, the TCN-Transformer model employs a three-layer temporal convolutional network with kernel sizes of 3, 5, and 7, corresponding to time windows of 1 day, 1 week, and 1 month. Each layer contains 64 filters. The dilation rate is set to 1, 2, and 4, with the receptive field increasing layer by layer. The cross-feature attention network uses eight attention heads, with a hidden layer dimension of 512 and a feedforward network dimension of 2048. The time series length of historical data nodes is set to 60 days, and after processing by the TCN-Transformer, a 256-dimensional technical surface temporal feature vector is output.

[0076] The pre-trained Transformer encoder uses the BERT-base-chinese model, containing a 12-layer Transformer structure with 768 hidden layers. Event nodes' text is transformed using a pre-defined template formatted as "Company {stock code} experienced {event type} on {date}". News nodes retain the title and summary, with a length limit of 512 characters. Sentiment nodes perform sentiment analysis preprocessing on the original comments, categorizing them as positive, neutral, or negative. All text data is encoded using BERT to output a 768-dimensional embedding vector, which is then projected to 256 dimensions through a linear layer, aligning with the technical feature dimensions.

[0077] Step 3: Within the stock price trend prediction model, a graph attention network is used to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality, and multi-head attention is used to perform cross-modal heterogeneous fusion of the isomorphic features.

[0078] Step 3.1: Construct subgraphs for listed companies, historical data, events, news, and public opinion using adjacent adjacency relationships, respectively, forming a unimodal isomorphic subgraph from the original multimodal subgraphs.

[0079] Step 3.2: Use the graph attention network shown in Equation (2) to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality;

[0080]

[0081] in, This represents the technical or fundamental characteristics of node i at layer l. Let i represent the set of neighbors of node i. W represents the attention coefficient. (l) Let σ be the weight matrix, and σ be the nonlinear activation function.

[0082] Step 3.3: Utilize multi-head attention to perform cross-modal heterogeneous fusion of isomorphic features;

[0083] Step 3.3.1: Use the isomorphic features of a single modality as the query, key, and value of the attention mechanism;

[0084] Step 3.3.2: Concatenate the query, key, and value of the attention mechanism with the attention weight, and fuse them with the technical features and basic features to form a cross-modal heterogeneous fusion feature as shown in Equation (3);

[0085] Z=MultiHead(Q,K,V)=Concat(head1,head2,…,head h W O (3)

[0086] Among them, head i =Attention(QW i Q ,KW i K VW i V ), W i Q W i K W i V and W OThe parameter matrix is ​​learnable; MultiHead represents a multi-head attention mechanism, which captures richer feature relationships by computing multiple attention heads in parallel, each focusing on different parts of the input data; the Concat operation concatenates the outputs of multiple attention heads into a larger matrix according to their dimensions, and then passes the result through the parameter matrix W. O Perform a linear transformation to obtain the final attention output;

[0087] In this embodiment, isomorphic subgraphs are constructed for each type of node. For each listed company in the sample set, a connected subgraph within a two-hop range is obtained using a depth-first search. The construction of the isomorphic subgraphs adopts a topological mapping method: the historical data subgraph contains all listed company nodes and their corresponding historical data nodes in the connected subgraphs, with each historical data node connected only to its corresponding listed company node, maintaining the original relationship topology (supply chain relationship, competitive relationship, industry relationship) between listed company nodes; the event subgraph contains all listed company nodes and their corresponding event nodes in the connected subgraphs, with each event node connected only to its corresponding listed company node, and the connection method is the same as in the historical data subgraph; the news subgraph contains all listed company nodes and their corresponding news nodes in the connected subgraphs, and the connection method is the same as in the historical data subgraph; the public opinion subgraph contains all listed company nodes and their corresponding public opinion nodes in the connected subgraphs, and the connection method is the same as in the historical data subgraph.

[0088] The graph attention network employs a two-layer GAT structure, with each layer containing eight attention heads and an attention dimension of 32, ultimately outputting a 256-dimensional node embedding. The attention coefficients are calculated using the LeakyReLU activation function. A multi-head attention mechanism is implemented with 16 attention heads, each with a dimension of 16, capturing the interactions between different modalities through parallel computation. After cross-modal heterogeneous fusion, the technical aspect feature weights are set to 0.6, and the basic aspect feature weights are set to 0.4, forming a final 512-dimensional heterogeneous fused feature vector.

[0089] Step 4: Map the heterogeneous fusion features to the token sequence by modifying the positional encoding, fine-tune the pre-trained large language model, and output the hidden layer of the fine-tuned large language model in binary classification through a fully connected layer;

[0090] Step 4.1: Map heterogeneous fusion features to token sequences using modified positional encoding, and fine-tune the pre-trained large language model;

[0091] Step 4.1.1: Set the token sequence for the cross-modal heterogeneous fusion feature as shown in equation (4);

[0092] X input =[x GNN,1 ,x GNN,2 ,…,xGNN,m , x text,1 , x text,2 , …, x text,n (4)

[0093] Among them, x GNN,i represents the token position reserved for the embedding representation, and x text,j represents the token of the original text input.

[0094] Step 4.1.2: Map the heterogeneous fusion features to the token sequence using the modified positional encoding shown in Equation (5);

[0095]

[0096] Among them, E pos [i] is the positional encoding at position i, E GNN [i] is the heterogeneous fusion feature, and E original [i] is the positional encoding of the original text;

[0097] Step 4.1.3: Fine-tune the pre-trained large language model in the manner shown in Equation (6);

[0098]

[0099] Among them, δ(i < m) is an indicator function that is 1 when i < m and 0 otherwise, indicating that the embedding is only applied at the reserved token positions; and are learnable parameter matrices that project the cross-modal heterogeneous fusion features into the query, key, and value spaces;

[0100] Step 4.2: Perform binary classification output as shown in Equation (7) on the hidden layer of the fine-tuned large language model through a fully connected layer;

[0101]

[0102] Among them, h (L) is the output representation of the last layer of the large language model, W o and b o are the weights and biases of the output layer respectively, σ is the sigmoid activation function, and the output value represents the probability of the stock price rising; when , it is predicted that the stock price will rise; otherwise, it is predicted that the stock price will fall; [[ID=6l]]

[0103] In this embodiment, ChatGLM-6B was selected as the pre-trained large language model for fine-tuning. The token sequence length m of the heterogeneous fusion features was set to 32, the original text token length n was set to 256, and the total input sequence length was 288. The positional encoding was modified to use a learnable embedding layer with a dimension of 768, consistent with the dimension of the model's hidden layers.

[0104] The fine-tuning process employs LoRA to reduce computational complexity. The rank r of LoRA is set to 16, and the scaling factor α is set to 32. Fine-tuning only involves the query and value projection matrices of the attention mechanism, freezing the remaining parameters. The projection matrix W... GNN,Q and W GNN,V Initialize to a Xavier normal distribution with a learning rate of 5e-5. The fully connected output layer uses a three-layer MLP for progressive dimensionality reduction, while the input hidden layer has a dimension of 256 and uses the ReLU activation function. The binary classification threshold is set to 0.5; when the output probability is ≥0.5, the stock price is predicted to rise, and the output label is 1; otherwise, the stock price is predicted to fall, and the output label is 0.

[0105] Step 5: Optimize and train the stock price trend prediction model and the large language model using the cross-entropy loss shown in Equation (8);

[0106]

[0107] Where N is the number of samples, y i For real labels, This is a predicted value;

[0108] In this embodiment, model training is conducted end-to-end, with cross-entropy loss as the primary optimization objective. The training, validation, and test sets are divided in a 6:2:2 ratio to ensure the continuity of the time series. The batch size is set to 32, and the training runs for 100 epochs. An early stopping strategy is employed, halting training when the validation set loss fails to decrease for 10 consecutive epochs. The optimizer used is AdamW, with a learning rate of 1e-4 and weight decay of 1e-5. Cosine annealing is used for learning rate scheduling, with a minimum learning rate of 1e-6. To improve training stability, gradient pruning is employed, with a pruning threshold of 1.0.

[0109] Step 6: Construct a multi-hop connected subgraph and input it into the trained stock price trend prediction model and large language model, and output binary classification prediction data of the stock price of the specified listed company.

[0110] Step 6.1: Form a multi-hop connected subgraph from the root node using depth-first traversal;

[0111] Step 6.2: Input the multi-hop connected subgraph into the trained stock price trend prediction model and large language model, and output the binary classification prediction data of the stock price of the specified listed company.

[0112] In this embodiment, the multi-hop connected subgraph employs a 2-hop depth-first search strategy. Starting from the specified target listed company, a complete connected subgraph within a 2-hop range is obtained through depth-first traversal, containing all relevant listed company nodes and their corresponding feature nodes. For the prediction task, 20 representative listed companies are selected for testing, covering four major industries: finance, technology, manufacturing, and consumer goods, including companies with three different market capitalizations: large-cap, mid-cap, and small-cap. The prediction time window is set to the next 5 trading days, with daily rolling predictions. Input data includes historical data for all listed companies in the connected subgraph over the previous 60 trading days, news event data for the previous 10 days, and public opinion data for the previous 5 days.

[0113] The above detailed description further illustrates the purpose, technical solution, and beneficial effects of the invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning, characterized by: Includes the following steps, Step 1: Construct a heterogeneous knowledge graph G with relational node connections, and set initial data for the nodes of the heterogeneous knowledge graph; Step 2: Construct a stock price trend prediction model, using the TCN-Transformer model and Transformer encoder to obtain technical and fundamental features respectively; Step 2.1: Use the characteristics of historical data nodes as technical features; use the characteristics of event nodes, news nodes, and public opinion nodes as basic features; Step 2.2: Construct a stock price trend prediction model and use the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales; Step 2.3: Use the pre-trained Transformer encoder of the stock price trend prediction model to extract the embedded representations of event nodes, news nodes, and public opinion nodes with the same dimensions as the technical time series features; Step 3: Within the stock price trend prediction model, a graph attention network is used to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality, and multi-head attention is used to perform cross-modal heterogeneous fusion of the isomorphic features. Step 4: Map the heterogeneous fusion features to the token sequence by modifying the positional encoding, fine-tune the pre-trained large language model, and output the hidden layer of the fine-tuned large language model in binary classification through a fully connected layer; Step 5: Optimize and train the stock price trend prediction model and the large language model using the cross-entropy loss shown in Equation (8); Where N is the number of samples, y i For real labels, This is a predicted value; Step 6: Construct a multi-hop connected subgraph and input it into the trained stock price trend prediction model and large language model, and output binary prediction data of the stock price of the specified listed company.

2. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 1, characterized in that: Step 1 is implemented as follows: Step 1.1: Construct a heterogeneous knowledge graph G consisting of listed company nodes, historical data nodes, event nodes, news nodes, public opinion nodes, and relationship nodes; Step 1.2: Use the entity data of the listed company as the listed company node; Financial statistics and market sentiment indicators are used as historical data nodes; objectively categorized market event data in a fixed format, news messages, and public opinion data without objective categorization are used as event nodes, news nodes, and public opinion nodes, respectively.

3. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 2, characterized in that: Step 1.1 is implemented as follows: Step 1.1.1: Designate the listed company node as the root node; historical data nodes, event nodes, news nodes, and public opinion nodes as child nodes; connect the root node and child nodes through directed edges; Step 1.1.2: Connect adjacent root nodes through relation nodes.

4. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 1, characterized in that: Step 2.2 is implemented as follows: Step 2.2.1: Extract time-series features at the time granularity of historical data nodes using a one-dimensional convolutional layer with the kernel of the stock price trend prediction model; Step 2.2.2: Use a cross-feature attention network to obtain the attention weights of the temporal features as shown in Equation (1); Where Q, K, and V are the query matrix, key matrix, and value matrix of the historical data node, respectively, and d k The dimension of the key vector; the softmax function transforms the input into a probability distribution of temporal features, ensuring that all weights sum to 1 and are all positive values; Step 2.2.3: Concatenate the attention weights of the time series features with the time series features at the time granularity of historical data nodes, and input them into the TCN-Transformer model to obtain technical time series features that include market patterns at different time scales.

5. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 1, characterized in that: Step 3 is implemented as follows: Step 3.1: Construct subgraphs for listed companies, historical data, events, news, and public opinion using adjacent adjacency relationships, respectively, forming a unimodal isomorphic subgraph from the original multimodal subgraphs. Step 3.2: Use the graph attention network shown in Equation (2) to extract and diffuse isomorphic features in the isomorphic subgraphs of a single modality; in, This represents the technical or fundamental characteristics of node i at layer l. Let i represent the set of neighbors of node i. W represents the attention coefficient. ( l ) Let σ be the weight matrix, and σ be the nonlinear activation function. Step 3.3: Utilize multi-head attention to perform cross-modal heterogeneous fusion of isomorphic features.

6. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 5, characterized in that: Step 3.3 is implemented as follows: Step 3.3.1: Use the isomorphic features of a single modality as the query, key, and value of the attention mechanism; Step 3.3.2: Concatenate the query, key, and value of the attention mechanism with the attention weight, and fuse them with the technical features and basic features to form a cross-modal heterogeneous fusion feature as shown in Equation (3); Z=MultiHead(Q,K,V)=Concat(head1,head2,…,head h )W O (3) Among them, head i =Attention(QW i Q ,KW i K VW i V ), W i Q W i K W i V and W O For learnable parameter matrix; MultiHead represents multi-head attention mechanism, which captures richer feature relationships by computing multiple attention heads in parallel, each head focusing on different parts of the input data; The Concat operation concatenates the outputs of multiple attention heads into a larger matrix along its dimensions, and then passes the concatenation through the parameter matrix W. O A linear transformation is performed to obtain the final attention output.

7. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 1, characterized in that: Step 4 is implemented as follows: Step 4.1: Map heterogeneous fusion features to token sequences using modified positional encoding, and fine-tune the pre-trained large language model; Step 4.2: The hidden layers of the fine-tuned large language model are processed by a fully connected layer to produce a binary classification output as shown in Equation (7); Among them, h (L) W is the output representation of the final layer of the large language model. o and b o These are the weights and biases of the output layer, respectively. σ is the sigmoid activation function, and the output value represents the probability of a stock price increase. If the stock price is expected to rise, then the stock price is predicted to fall; otherwise, the stock price is predicted to fall.

8. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 7, characterized in that: Step 4.1 is implemented as follows: Step 4.1.1: Set the token sequence for the cross-modal heterogeneous fusion feature as shown in equation (4); X input =[x GNN,1 ,x GNN,2 ,…,x GNN,m ,x text,1 ,x text,2 ,…,x text,n ] (4) Where, x GNN,i This indicates the token position reserved for the embedded representation, x text,j The token represents the original text input; Step 4.1.2: Map the heterogeneous fusion features to the token sequence using the modified position encoding as shown in equation (5); Among them, E pos [i] is the position code of position i, E GNN [i] represents the heterogeneous fusion feature, E original [i] is the positional encoding of the original text; Step 4.1.3: Fine-tune the pre-trained large language model using the method shown in equation (6); Among them, δ(i<m) is an indicator function, which is 1 when i<m and 0 otherwise, indicating that the embedding is only applied at the reserved token positions; and are learnable parameter matrices that project the cross-modal heterogeneous fusion features into the query, key, and value spaces.

9. The stock price trend prediction method based on heterogeneous graph neural networks and LLM fine-tuning as described in claim 1, characterized in that: Step 6 is implemented as follows: Step 6.1: Form a multi-hop connected subgraph from the root node using depth-first traversal; Step 6.2: Input the multi-hop connected subgraph into the trained stock price trend prediction model and large language model, and output the binary classification prediction data of the stock price of the specified listed company.

Citation Information

Cited By

  • Financial knowledge graph data fusion and retrieval platform system for investment suggestions

    CN121166763A