Adaptive stock market subject risk early warning method based on Transform-GL model

By using the Transformer-GL model and graph convolutional neural network in the stock market risk assessment, integrating multi-dimensional financial indicators and massive stock data, the problem of existing technology being difficult to effectively evaluate and early warning of risks of stock market entities is solved, and higher risk prediction accuracy and market change response capabilities are achieved.

CN119762224AInactive Publication Date: 2025-04-04EAST CHINA NORMAL UNIV
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411891135.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-04-04
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing technology has shortcomings in risk assessment and early warning of stock market entities, and it is difficult to effectively integrate multi-dimensional financial indicators and massive stock data, and it is difficult to quickly respond to changes in market structure and the evolution of relationship networks.

Method used

Adaptive stock market entity risk warning method based on Transformer-GL model is adopted, and complex relationship network information in the knowledge graph is embedded into the prediction model by integrating historical price data, financial index factors and graph structure data, combined with graph convolutional neural network (GCN).

Benefits of technology

It improves the comprehensiveness and accuracy of risk prediction of stock entities, enhances the real-time response to market structure changes, provides more reliable, timely and accurate risk warnings, provides a better basis for investor decision-making, reduces investment risks and optimizes investment strategies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119762224A_ABST
    Figure CN119762224A_ABST
Patent Text Reader

Abstract

The invention discloses an adaptive stock market subject risk early warning method based on a Transform-GL model. The method is characterized by comprising the following steps: collecting open source stock data; constructing a knowledge graph; calculating an inter-stock correlation matrix; selecting top k similar stocks related to the target stock; calculating an adjacent matrix of the distance between the similar stocks; obtaining price data and financial index factors of similar stocks in near d days; selecting the first p high-quality factors; constructing an early warning model and training the model; and predicting the risk level of the target stock subject. Compared with the prior art, the method has the advantages that multi-dimensional financial index factors and mass stock data information are integrated, complex relation network information contained in a knowledge graph is embedded into a prediction model by means of a graph convolutional neural network, and meanwhile, the characteristics of Transform are exerted to adapt to market structure changes in a self-adaptive mode; a more reliable, timely and accurate basis is provided for investors to make decisions, the investment risk is reduced, the investment strategy is optimized, and the overall stability and efficiency of the market are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of financial quantitative risk analysis, and in particular to an adaptive stock market subject risk early warning method based on a Transformer-GL model. Background Art

[0002] With the increasing complexity of financial markets and the acceleration of globalization, the volatility and uncertainty of stock markets have increased significantly. In such an environment, investors, financial institutions and regulators have an urgent need for technologies that can accurately predict stock market dynamics and detect potential risks in a timely manner.

[0003] Traditional stock market analysis methods are mostly based on simple statistical analysis and basic technical indicators, which are incapable of dealing with complex market environments. For example, although fundamental analysis can evaluate stock value from aspects such as company financial statements, it is difficult to reflect market sentiment and sudden macroeconomic changes in real time; technical analysis mainly focuses on the historical trends of stock prices and trading volumes, and has extremely limited use of deep-level correlation information in the market, and ignores many key financial technical indicators, which greatly limits its comprehensive assessment and accurate grasp of stock subject risks. Due to the lack of an effective fusion mechanism, traditional methods find it difficult to deeply embed relational information into prediction models. When processing relational data between stocks, simple empirical rules are often relied on. This method cannot accurately analyze the complex logic and potential value contained in relational data, and it is difficult to effectively sort out and integrate the diversity and hierarchy of relations between stocks, resulting in key information being submerged in massive data, and unable to give full play to the important role of relational information in assessing risks, which greatly reduces the reliability and accuracy of prediction results.

[0004] In recent years, with the continuous progress of information technology and data analysis methods, deep learning models have been gradually introduced into the field of stock market prediction. However, existing mainstream models such as LSTM, although they can capture the time series characteristics of stock prices to a certain extent, have poor adaptability to changes in market structure and are difficult to quickly respond to the evolving relationship network in the stock market, such as the reshaping of the market structure caused by changes in holders and regulators.

[0005] To sum up, although the existing technology has made some breakthroughs to a certain extent, the risk assessment and early warning work of stock market entities still faces many difficulties. It is urgent to explore more systematic methods to enhance the effectiveness of market risk early warning and thus optimize the allocation of market resources. Summary of the invention

[0006] The purpose of the present invention is to provide an adaptive stock market subject risk warning method based on the Transformer-GL model in response to the deficiencies of the prior art. The method adopts a method of combining historical price data and financial indicator factors with graph structure data, and combines the Transformer-GL model to perform adaptive stock market subject risk warning. The method builds a comprehensive and rich data foundation by deeply integrating multi-dimensional financial indicator factors with massive stock data information. At the same time, the complex relationship network information contained in the knowledge graph is embedded into the prediction model with the help of a graph convolutional neural network (GCN), thereby improving the comprehensiveness and accuracy of stock subject risk prediction. At the same time, the characteristics of the Transformer are used to adapt to changes in the market structure to enhance the real-time and effectiveness of the stock subject risk warning, providing investors with a more reliable, timely and accurate basis for decision-making in the stock market, helping to reduce investment risks, optimize investment strategies and improve the overall stability and efficiency of the market. The method is simple, practical, and has good application prospects and commercial development value.

[0007] The specific technical solution for achieving the purpose of the present invention is: an adaptive stock market subject risk early warning method based on the Transformer-GL model, which is characterized in that the method specifically includes the following steps:

[0008] Step 1: Collect open source stock data and build a data set;

[0009] Step 2: Use the stock data information obtained in step 1 to build a stock knowledge graph;

[0010] Step 3: Calculate the correlation matrix between stocks based on the stock knowledge graph established in step 2;

[0011] Step 4: Select topk similar stocks related to the target stock;

[0012] Step 5: Calculate the adjacency matrix of distances between similar stocks based on the stock knowledge graph;

[0013] Step 6: Obtain the price data of similar stocks in the past d days and financial indicator factors;

[0014] Step 7: Perform single factor check and select the top p high-quality factors;

[0015] Step 8: Build an adaptive stock market risk warning model based on Transformer-GL;

[0016] Step 9: Conduct model training;

[0017] Step 10: Predict the risk level of the target stock entity.

[0018] The step 1 of collecting open source stock data includes the following steps:

[0019] Step A1: Use Python+Selenium combined crawler to access the stock company page on Sina Finance website;

[0020] Step A2: Extract stock company information by selecting XPath and element name;

[0021] Step A3: Screen and extract the more useful stock data information;

[0022] Step A4: Obtain information about regulators and stockholders in the same way;

[0023] Step A5: Construct the above-obtained information into a data set.

[0024] In step A2, a Python+Selenium combined crawler is used to access the stock company page on the Sina Finance website, and finally the stock data of 5362 companies are crawled; the information screened and extracted in step A3 includes: stock code, stock name, industry, total market value, circulating market value, total share capital, circulating shares, and listing time.

[0025] The method of constructing a stock knowledge graph according to the stock data information obtained in step 1 in step 2 includes the following steps:

[0026] Step B1: Create a stock entity node based on the stock data information obtained in step 1;

[0027] Step B2: Based on the stock data information obtained in step 1, establish relationship connections between stock entities.

[0028] In step B1, five types of entities, including industry, concept stock, stock company, holding company, and industry executives, are created, with a total of 125,728 nodes; in step B2, four types of relationships, including industry_of, concept_of, holder_of, and holder_of, are created, with a total of 200,301 entity relationships.

[0029] The method of calculating the correlation matrix between stocks according to the stock knowledge graph established in step 2 in step 3 comprises the following steps: step C1: respectively calculating the contribution values ​​of four types of connection nodes between two stocks, namely, industry, concept stocks, holders and regulators; step C2: adding the four contribution values ​​calculated in step C1 to obtain the correlation value between two directly connected stocks;

[0030] Step C3: Calculate the path distance between two stocks;

[0031] Step C4: When the path between two stocks contains other stocks, the distances between each pair of adjacent stocks on the path need to be added together to obtain the final path distance.

[0032] The industry contribution value in step C1 is calculated by the following formula (a):

[0033] Contribution industry =∑(Weight A +Weight B )(a).

[0034] Among them, Weight A and Weight B is the index.

[0035] The concept stock contribution value in step C1 is calculated by the following formula (b):

[0036]

[0037] Among them, degree Concept is the number of concept stocks that belong to the same concept.

[0038] The supervisor contribution value in step C1 is calculated by the following formula (c):

[0039]

[0040] Among them, degree Regulator is the number of regulators for these two stocks.

[0041] The holder contribution value in step C1 is calculated by the following formula (d):

[0042]

[0043] Among them, degree Holder is the number of shareholders holding these two stocks.

[0044] In step C2, the four contribution values ​​calculated in step C1 are added together to obtain the correlation value between the two directly connected stocks. The specific calculation is expressed by the following formula (e): Correlation (A, B) = Contribution Industury +Contribution Concept +Contribution Regulator +Contribution Holder (e).

[0045] The path distance between stocks in step C3 is inversely proportional to the correlation value in step C2, and its specific calculation is expressed by the following formula (f):

[0046]

[0047] The step 4 selects the five stocks that are most similar to the target prediction.

[0048] The method for calculating the adjacency matrix of distances between similar stocks based on the stock Transformer-GL model in step 5 comprises the following steps:

[0049] Step D1: Select a distance threshold;

[0050] Step D2: If the distance between two stocks is greater than the threshold, it is marked as 1 in the matrix, otherwise it is marked as 0, and the final adjacency matrix is ​​obtained.

[0051] In step 6, the price data of similar stocks in the past five days are selected and 69 related financial indicator factors can be obtained through the toolkit stockstats.

[0052] The method of performing single factor inspection and selecting the first p high-quality factors in step 7 comprises the following steps:

[0053] Step E1: Build a simple logistic regression model;

[0054] Step E2: Divide the data set obtained in step 1 into a training set and a test set in a ratio of 8:2, make predictions on the test set for each factor and calculate the accuracy;

[0055] Step E3: Select the top 15 factors as high-quality factors based on the accuracy.

[0056] The step eight constructs an adaptive stock market risk warning model based on Transformer-GL, which includes three parts: Transformer, GCN and LSTM; uses the self-attention mechanism of Transformer to adapt to market change information; uses GCN to grasp the complex structural relationship of the stock market as a whole, and finally uses LSTM to adapt to different time scales for prediction.

[0057] The model training of step nine comprises the following steps:

[0058] Step F1: preprocessing the data;

[0059] Step F2: construct feature and label data;

[0060] Step F3: Divide the data set obtained in step 1 into a training set, a test set, and a validation set in a ratio of 8:1:1, that is, 80% of the data set is a training set, 10% of the data set is a validation set, and 10% of the data set is a test set;

[0061] Step F4: Initialize training parameters;

[0062] Step F5: Select training performance evaluation indicators;

[0063] Step F6: The feature data set and the adjacency matrix constructed in step F2 are used together as feature input models for training, and the training result with the best performance evaluation index is selected as the final model.

[0064] The performance evaluation indicators of step F5 are Accuracy, Precision, Recall, F1 (F1 value) and AUC (area under the characteristic curve).

[0065] The method for predicting the risk level of the target stock entity in step 10 comprises the following steps:

[0066] Step G1: Input the target stock into the model and obtain the target stock price forecast value through model inference calculation;

[0067] Step G2: Calculate the expected rate of return through the forecast results;

[0068] Step G3: Output the predicted result of the subject risk level based on the expected rate of return.

[0069] Compared with the prior art, the present invention has built a comprehensive and rich data foundation by deeply integrating multi-dimensional financial indicator factors and massive stock data information. At the same time, the complex relationship network information contained in the knowledge graph is embedded into the prediction model with the help of a graph convolutional neural network (GCN), thereby improving the comprehensiveness and accuracy of the risk prediction of the stock subject. At the same time, the characteristics of Transformer are used to adapt to changes in market structure to enhance the real-time and effectiveness of the risk warning of the stock subject, providing investors with a more reliable, timely and accurate basis for decision-making in the stock market, helping to reduce investment risks, optimize investment strategies and improve the overall stability and efficiency of the market. The method is simple, highly practical, and has good application prospects and commercial development value. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] Figure 1 It is a flow chart of the present invention;

[0071] Figure 2 An example of a knowledge graph constructed;

[0072] Figure 3 Schematic diagram of the framework structure of the Transformer-GL model constructed in the present invention. DETAILED DESCRIPTION

[0073] The present invention is further described in detail with reference to the following specific examples and drawings. The process, conditions, experimental methods, etc. for implementing the present invention, except for the contents specifically mentioned below, are all common knowledge and common common sense in the art and are not particularly limited by the present invention.

[0074] Example 1

[0075] See also Figure 1 , a risk warning based on the financial numerical Transformer-GPT4 model, specifically including the following steps:

[0076] Step S1: Collect open source stock data and build a data set;

[0077] Step S2: Using the stock data information obtained in step 1, construct a stock knowledge graph;

[0078] Step S3: Calculate the correlation matrix between stocks based on the stock knowledge graph established in step 2;

[0079] Step S4: Select topk similar stocks related to the target stock;

[0080] Step S5: Calculate the adjacency matrix of distances between similar stocks based on the stock knowledge graph;

[0081] Step S6: Obtain the price data of similar stocks in the past d days and financial indicator factors;

[0082] Step S7: Perform single factor check and select the top p high-quality factors;

[0083] Step S8: constructing an adaptive stock market risk warning model based on Transformer-GL;

[0084] Step S9: Perform model training;

[0085] Step S10: Predict the risk level of the target stock.

[0086] The step S1 comprises the following steps:

[0087] Step A1: Use Python+Selenium combined crawler to access the stock company page on Sina Finance website;

[0088] Step A2: Extract stock company information by selecting XPath and element name;

[0089] Step A3: Screen and extract the more useful stock data information;

[0090] Step A4: Obtain information about regulators and stockholders in the same way;

[0091] Step A5: Construct the above-obtained information into a data set.

[0092] In the process of obtaining open source stock data, the open source financial database Akshare is also needed. The data obtained by the Akshare tool library comes from the original data published by authoritative financial data websites, and it also provides a full range of tools from data collection, data cleaning to data landing.

[0093] The stock data examples after screening in step A3 are shown in Table 1 below:

[0094] Table 1 Screened stock data

[0095]

[0096] The step S2 comprises the following steps:

[0097] Step B1: Create a stock entity node based on the stock data information obtained in step 1;

[0098] Step B2: Based on the stock data information obtained in step 1, establish relationship connections between stock entities.

[0099] The step B1 creates five types of entities including industry, concept stock, stock company, holding company, and industry executives, with a total of 125,728 nodes; the step B2 creates four types of relationships including industry_of, concept_of, holder_of, and holder_of, with a total of 200,301 entity relationships.

[0100] See also Figure 2 , taking the two stocks of Bank A and Bank B as examples, the entities are described in the form of triples: {entity, attribute, value}, and the relationship between entities is described in the form of triples: {head entity, relationship, tail entity}.

[0101] The step S3 comprises the following steps:

[0102] Step C1: Calculate the contribution values ​​of four types of connection nodes between two stocks: industry, concept stocks, holders and regulators; Step C2: Add the four contribution values ​​calculated in step C1 to obtain the correlation value between two directly connected stocks;

[0103] Step C3: Calculate the path distance between two stocks;

[0104] Step C4: When the path between two stocks contains other stocks, the distances between each pair of adjacent stocks on the path need to be added together to obtain the final path distance.

[0105] In step C1, the industry contribution of any two stocks is calculated by the following formula (a): industry =∑(Weight A +Weight B )(a).

[0106] Among them, Weight A and Weight B Represents the index.

[0107] The concept stock contribution value in step C1 is calculated by the following formula (b):

[0108]

[0109] Among them, degree Concept is the number of concept stocks that belong to the same concept.

[0110] The supervisor contribution value in step C1 is calculated by the following formula (c):

[0111]

[0112] Among them, degree Regulator is the number of regulators for these two stocks.

[0113] The holder contribution value in step C1 is calculated by the following formula (d):

[0114]

[0115] Among them, degree Holder is the number of shareholders holding these two stocks.

[0116] The correlation value between two directly connected stocks in step C2 is calculated by the following formula (e): Correlation (A, B) = Contribution Industury +Contribution Concept +Contribution Regulator +Contribution Holder (e).

[0117] In step C3, the path distance between stocks is calculated by the following formula (f):

[0118]

[0119] The step S4 selects the five stocks most similar to the target prediction.

[0120] The step S5 comprises the following steps:

[0121] Step D1: Select a distance threshold;

[0122] Step D2: If the distance between two stocks is greater than the threshold, it is marked as 1 in the matrix, otherwise it is marked as 0, and the final adjacency matrix is ​​obtained.

[0123] In step D1, 0.2 is selected as the distance threshold. If the distance between two stocks is greater than 0.2, the median of the adjacency matrix is ​​marked as 1, otherwise the median of the adjacency matrix is ​​marked as 0.

[0124] The step S6 selects the price data of similar stocks in the past 5 days and obtains 69 related financial indicator factors through the toolkit stockstats, which are: The stockstats toolkit provides a wrapper StockDataFrame for pandas.DataFrame, so that it supports inline stock statistics data / indicators. Currently, it supports the calculation of 69 related financial indicators, including: delta, permutation (zero-based), log return, max in range, min in range, middle (the middle value obtained by closing price + highest price + lowest price) / 3), le, ge, lt, gt, eq, ne (less than or equal to (le), greater than or equal to (ge), less than (lt), greater than (gt), equal to (eq), not equal to (ne)), count: both backward (c) and forward (fc), cross: including upward cross and downward cross, SMA (Simple Moving Average), EMA (Exponential Moving Average), MSTD (Moving Standard Deviation), MVAR (Moving Variance), RSV (Raw Stochastic Value), RSI (Relative Strength Index, relative strength index), KDJ (Stochastic Oscillator), Bollinger Band (Bollinger Band), MACD (Moving Average Convergence Divergence), CR (Energy Index (Intermediate Willingness Index), WR (Williams Overbought / Oversold Index), CCI (Commodity Channel Index), TR (True Range), ATR (Average TrueRange,Average True Range), DMA(Different of Moving Average(10,50)), DMI(Directional Moving Index), +DI(Positive Directional Indicator), -DI(Negative Directional Indicator), ADX(Average Directional Movement Index), ADXR(Smoothed Moving Average of ADX), TRIX(Triple Exponential Moving Average), TEMA(Another Triple Exponential Moving Average), VR(Volume Variation Index), MFI(Money Flow Index), VWMA(Volume Weighted Moving Average), CHOP(Choppiness Index), KER(Kaufman's efficiency ratio, Kaufman efficiency ratio), KAMA (Kaufman's Adaptive Moving Average), PPO (Percentage Price Oscillator), StochRSI (Stochastic RSI), WT (Lazy Bear's Wave Trend), Supertrend (with the Upper Band and Lower Band), Aroon (Aroon Oscillator), Z (Z-Score), AO (Awesome Oscillator), BOP (Balance of Power), MAD (Mean Absolute Deviation), ROC (Rate of Change), Coppock (Coppock Curve,Coppock curve), Ichimoku (Ichimoku Cloud), CTI (Correlation Trend Indicator), LRMA (Linear Regression Moving Average), ERI (Elder-Ray Index), FTR (the Gaussian Fisher Transform Price Reversals indicator), RVGI (Relative Vigor Index), Inertia (Inertia Indicator), KST (Know Sure Thing), PGO (Pretty Good Oscillator), PSL (Psychological Line), PVO (Percentage Volume Oscillator) and QQE (Quantitative Qualitative Estimation). ,

[0125] The step S7 comprises the following steps:

[0126] Step E1: Build a simple logistic regression model;

[0127] Step E2: Divide the data set into a training set and a test set in a ratio of 8:2, make predictions on the test set for each factor and calculate the accuracy;

[0128] Step E3: Select the top 15 factors as high-quality factors based on the accuracy.

[0129] Here is a code example of a one-way check using a logistic regression model:

[0130]

[0131]

[0132] See also Figure 3 , an adaptive stock market risk warning model based on Transformer-GL, mainly including Transformer layer, GCN layer, LSTM layer and linear layer.

[0133] The step S9 comprises the following steps:

[0134] Step F1: preprocessing the data;

[0135] Step F2: construct feature and label data;

[0136] Step F3: Divide the data set obtained in step 1 into a training set, a test set, and a validation set in a ratio of 8:1:1, that is, 80% of the data set is a training set, 10% of the data set is a validation set, and 10% of the data set is a test set;

[0137] Step F4: Initialize training parameters;

[0138] Step F5: Select training performance evaluation indicators, the performance evaluation indicators are Accuracy, Precision, Recall, F1 (F1 value) and AUC (area under the characteristic curve);

[0139] Step F6: Use the constructed feature data set and adjacency matrix as feature input models for training, and select the training result with the best performance evaluation index as the final model.

[0140] The main algorithm for preprocessing the data in step F1 is to use the Pandas framework to align the transaction dates, filter the stock data with a start date of 2023-01-01 and an end date of 2023-12-31, filter out default values ​​and abnormal data, and normalize the filtered data.

[0141] The main algorithm for constructing features in step F2 is to extract the list data containing the normalized opening, highest, lowest, closing prices and 15 high-quality factors in consecutive days_for_train according to the set training days days_for_train, and put them into the feature list as feature data, so as to construct a feature data set.

[0142] The main algorithm for constructing the label data in step F2 is to cyclically compare the normalized closing prices of the next day in data_list. If the closing price of the next day is greater than or equal to that of the previous day, the corresponding label is set to 1, indicating that the stock price has risen or remained the same; if it is less than, it is set to 0, indicating that the stock price has fallen. These labels are put into the list in sequence to construct the label data.

[0143] In step F3, the data set is divided mainly according to the amount of transaction data in a ratio of 8:1:1, that is, 80% of the data is used as a training set, 10% of the data is used as a validation set, and 10% of the data is used as a test set.

[0144] The step F4 initializes the training parameters. Before model training, parameters such as learning rate, optimizer, and training rounds need to be initialized.

[0145] In step F5, Accuracy, Precision, Recall, F1 and AUC are selected as performance evaluation indicators, and Accuracy is defined by the following formula (g):

[0146]

[0147] Among them, Accuracy is the accuracy rate, where TP represents true positive examples, that is, the number of samples that are actually positive examples and predicted as positive examples by the model; TN represents true negative examples, that is, the number of samples that are actually negative examples and predicted as negative examples by the model; FP represents false positive examples, that is, the number of samples that are actually negative examples but predicted as positive examples by the model; FN represents false negative examples, that is, the number of samples that are actually positive examples but predicted as negative examples by the model.

[0148] The Precision is defined by the following formula (h):

[0149]

[0150] Among them, Precision is the accuracy rate, TP represents true positive examples, that is, the number of samples that are actually positive examples and predicted as positive examples by the model; FP represents false positive examples, that is, the number of samples that are actually negative examples but predicted as positive examples by the model.

[0151] The Recall is defined by the following formula (i):

[0152]

[0153] Among them, Recall is the recall rate, TP represents true positive examples, that is, the number of samples that are actually positive examples and predicted as positive examples by the model; FN represents false negative examples, that is, the number of samples that are actually positive examples but predicted as negative examples by the model.

[0154] The F1 is defined by the following formula (j):

[0155]

[0156] Among them, Pricision is the precision and Recall is the recall.

[0157] The AUC refers to the area under the characteristic curve.

[0158] Finally, the model is trained and the model with the best performance index is selected as the final model.

[0159] The step S10 comprises the following steps:

[0160] Step G1: Input the target stock into the model and obtain the target stock price forecast value through model inference calculation;

[0161] Step G2: Calculate the expected rate of return through the forecast results;

[0162] Step G3: Output the predicted result of the subject risk level based on the expected rate of return.

[0163] The expected rate of return in step G2 is calculated by the following formula (k):

[0164]

[0165] Among them, prediction represents the predicted value of the target stock price, and current_stock_price represents the closing price of the target stock on the last day.

[0166] In step G3, if the expected rate of return is greater than 0, the output entity risk level is 0, otherwise the output entity risk level is 1.

[0167] The protection content of the present invention is not limited to the above embodiments. Without departing from the spirit and scope of the inventive concept, changes and advantages that can be thought of by those skilled in the art are included in the present invention and are protected by the attached claims.

Claims

1. An adaptive stock market subject risk early warning method based on Transformer-GL model, characterized in that: The method specifically comprises the following steps: Step 1: Build a dataset A1: Use Python+Selenium combined crawler to access the stock company page on Sina Finance website; A2: Extract stock company information by selecting XPath and element name; A3: Filter and extract stock data information; A4: Same as step A2, obtain information about regulators and stock holders; A5: Build the above collected open source stock data into a data set; Step 2: Construction of stock knowledge graph B1: Create a stock entity node based on the acquired stock data information; B2: Establish relationship connections between stock entities based on the acquired stock data information; B3: Use the relationship connections between stock entity nodes and stock entities to build a stock knowledge graph; Step 3: Calculation of correlation matrix between stocks C1: Calculate the contribution values ​​of four types of connection nodes between any two stocks: industry, concept stocks, holders and regulators; C2: Add the four calculated contribution values ​​to get the correlation value between two directly connected stocks; C3: Calculate the path distance between two stocks; C4: When the path between two stocks contains other stocks, the distances between each pair of adjacent stocks on the path need to be added together to obtain the final path distance; C5: Calculate the correlation matrix between stocks based on the constructed stock knowledge graph; Step 4: Selection of similar stocks Select the topk stocks that are most similar to the target prediction; Step 5: Calculation of the adjacency matrix D1: Calculate the distance between similar stocks based on the stock knowledge graph and select a distance threshold; D2: If the distance between two stocks is greater than the threshold, it is marked as 1 in the matrix, otherwise it is marked as 0, and the final adjacency matrix is ​​obtained; Step 6: Obtaining financial indicator factors Select the price data of similar stocks in the past d days and obtain several related financial indicator factors through the tool package stockstats, where d is greater than 5 days; Step 7: Acquisition of high-quality factors E1: build a logistic regression model; E2: Divide the data set obtained in step 1 into a training set and a test set at a ratio of 8:2, predict each factor on the test set and calculate the accuracy; E3: According to the accuracy of the single factor check, the first p factors are selected as high-quality factors, where p is greater than 15; Step 8: Construction of adaptive stock market risk warning model Construct an adaptive stock market risk warning model based on Transformer-GL. The model includes Transformer, GCN and LSTM. Transformer's self-attention mechanism is used to adapt to market change information; GCN is used to grasp the complex structural relationship of the stock market; LSTM is used to adapt to different time scales for prediction; Step 9: Training of Adaptive Stock Market Risk Warning Model F1: preprocess the data; F2: Construct feature and label data; F3: Divide the data set obtained in step 1 into training set, test set and validation set according to the ratio of 8:1:1; F4: Initialize training parameters; F5: Select training performance evaluation indicators; F6: Use the constructed features, label data and adjacency matrix as feature inputs to train the adaptive stock market risk warning model based on Transformer-GL, and select the training result with the best performance evaluation index as the final model; Step 10: Predict the risk level of the target stock Step G1: Input the target stock into the trained Transformer-GL-based adaptive stock market risk warning model to obtain the target stock price prediction value; Step G2: Calculate the expected rate of return based on the predicted value of the target stock price; Step G3: Output the predicted result of the subject risk level based on the expected rate of return.

2. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: In step A2, a Python+Selenium combined crawler is used to access the stock company page on the Sina Finance website to crawl the stock data of several companies.

3. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: The information screened and extracted in step A3 includes: stock code, stock name, industry, total market value, circulating market value, total share capital, circulating shares and listing time.

4. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: In the step B1, five types of entities including industries, concept stocks, stock companies, holding companies and industry executives and several entity nodes thereof are created.

5. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: In step B2, four types of relationships including industry_of, concept_of, holder_of and holder_of and several entity relationships thereof are created.

6. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: The contribution values ​​of the four types of connection nodes between any two stocks in step C1, namely, industry, concept stocks, regulators and holders, are calculated by the following formulas (a) to (d): Contribution industry =∑(Weight A +Weight B ) (a); Among them, Weight A and Weight B is the index; Among them, degree Concept is the number of concept stocks that belong to the same concept; Among them, degree Regulator The number of regulators for these two stocks; Among them, degree Holder is the number of shareholders holding these two stocks.

7. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: The correlation value between two directly connected stocks in step C2 is calculated by the following formula (e): Correlation(A,B)=Contribution Industury +Contribution Concept +Contribution Regulator +Contribution Holder (e); Among them, Correlation(A,B) is the correlation value between stocks A and B.

8. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: The path distance in step C3 is calculated by the following formula (f):

9. The adaptive stock market subject risk early warning method based on the Transformer-GL model according to claim 1 is characterized in that: The performance evaluation indicators of step F5 are accuracy, precision, recall, F1 value and area under the characteristic curve.

Citation Information

Patent Citations

  • Stock risk prediction method and system based on user portrait and knowledge graph

    CN112734569A

  • Risk early warning method based on knowledge graph and storage medium

    CN113592641A

  • Stock trend prediction method based on technical factor graph attention network

    CN115018152A

  • Cellular network fault diagnosis method based on deep learning and knowledge graph

    CN115734274A

  • Knowledge graph prediction model training method, system, device and medium

    CN116561329A