Stock price prediction method based on emotion data
By extracting comment representation data from stock text evaluation data, building emotional data and combining with deep learning models, the problems of high operational difficulty, large subjective influence and insufficient accuracy of stock price prediction in the existing technology are solved, and more accurate and stable stock price forecast.
Patent Information
- Application Number
- CN202411181268.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-12-13
AI Technical Summary
The existing stock price prediction technology is difficult to operate, has a large subjective impact and insufficient accuracy, and ignores the complex interactions within the financial market.
By obtaining stock text evaluation data, extracting comment representation data to construct emotional data, and building stock price prediction model based on emotional data, including stock price prediction model and sector sharing model, using deep learning model combined with pre-training ideas, considering different stocks and sectors relationship between.
Effectively integrating into the internal relationships of the financial market improves the accuracy and stability of stock price predictions, and provides new ideas for subsequent stock price prediction models.
Smart Images

Figure CN119130516A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer artificial intelligence and financial science, and in particular to a stock price prediction method based on sentiment data. Background Art
[0002] Since the development of the stock market, a large number of research methods have been proposed and studied. Among them, the following two investment analysis methods are recognized by the majority of investors: fundamental analysis and technical analysis. However, the existing stock price analysis methods are relatively vague in judging the trend of stock prices, have high experience requirements for users, and are largely limited by subjective judgment.
[0003] The rapid development of deep neural networks has promoted their integration with the financial technology industry. Experts in the field of computer application technology build deep learning models and let them learn stock index data to establish stock price prediction models. However, the existing models use a single type of data and ignore the complex interactions within the financial market, resulting in the accuracy and stability of price predictions still being difficult to meet usage requirements.
[0004] In summary, the existing stock price prediction technology has the following disadvantages: high difficulty in operation, large subjective influence and insufficient accuracy. Summary of the invention
[0005] In view of the shortcomings of the prior art, the purpose of the present invention is to provide a stock price prediction method based on sentiment data, which predicts the rise and fall trend of stock prices by mining sentiment texts, and provides a new idea for the development and application of subsequent stock price prediction models. In order to achieve the above-mentioned purpose and other advantages according to the present invention, a stock price prediction method based on sentiment data is provided, comprising:
[0006] Get stock text evaluation data;
[0007] Extracting comment representation data from stock text evaluation data, and constructing sentiment data through the comment representation data;
[0008] Building a stock price prediction model based on the sentiment data, the stock price prediction model including a stock price prediction model and a sector sharing model;
[0009] Among them, the stock text evaluation data belonging to the same sector is input into the stock price prediction model for pre-training to obtain a sector sharing model;
[0010] Input the comment representation data into the shared model for formal training;
[0011] The latest stock text evaluation data are input into the stock price prediction model to predict the stock price trend of the next trading cycle.
[0012] Preferably, the stock text evaluation data is divided according to the stocks to which it belongs, into text information of each stock, the text information of each stock is sorted according to the chronological order, and divided according to a specific time span into training set data and test set data;
[0013] All stocks are preliminarily screened according to the start time of the first training set and the end time of the last test set, and the stocks that meet the requirements are screened out from all stocks according to the predetermined screening requirements to form a stock pool.
[0014] Preferably, the stocks in the screened stock pool are subjected to trading day inspection and missing value filling, the published content of the obtained stock evaluation is segmented using natural language processing technology, and the text information is extracted as comment representation using bidirectional vector embedding coding, and the correlation coefficient between sectors is calculated through the verbs in the evaluation.
[0015] Preferably, the bidirectional vector embedding coding extracts text information into comment representations specifically as follows:
[0016] The evaluation text is segmented at two levels using the window-level segmentation method and the sentence-level segmentation method respectively; the core verb words in each segmented window are converted into word embedding vectors using the word2vc method as key embedding vectors, and the words in the sentence to which the window belongs, excluding the core verb words used in the window, are converted into word embedding vectors using the word2vc method as value embedding vectors;
[0017] The window-level segmentation method and the sentence-level segmentation method are respectively specifically two text segmentation methods for segmenting a sequence of words composed of a fixed window size and a complete sentence.
[0018] Preferably, the stock price prediction model includes a data distiller module and a stock price trend classifier module;
[0019] The data distiller module specifically includes: inputting the evaluation bidirectional vector embedding result obtained by calculation into the distiller module to obtain a hidden market vector;
[0020] The stock price trend classifier module includes a long short-term memory model layer and a multi-layer perceptron module.
[0021] Preferably, the stock text evaluation data belonging to the same sector is input into the stock price prediction model for pre-training to obtain the sector sharing model, specifically:
[0022] List the sectors to which all stocks in the stock pool belong and summarize them, divide and organize the stocks according to the sectors they belong to, input the training set data of the stocks belonging to the same sector at a specified time into the stock price prediction model in sequence for a small number of trainings, and save the trained model parameters as a shared model for the sector at the training time.
[0023] Compared with the prior art, the present invention has the following beneficial effects: constructing sentiment data by extracting comment representations from text evaluation data, constructing sector correlation coefficients based on text comments, using deep learning models to predict stock prices, and training sector sharing models in combination with pre-training ideas. This method can effectively incorporate the relationship between different stocks and sectors into the model, thereby solving the problem of neglecting the internal relationships of the financial market in previous studies. Predicting the rise and fall trends of stock prices by mining sentiment texts provides new ideas for the development and application of subsequent stock price prediction models. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 is a flow chart of a method for predicting stock prices based on sentiment data according to the present invention;
[0025] Figure 2 A detailed diagram of data obtained from part of the method for predicting stock prices based on sentiment data according to the present invention;
[0026] Figure 3 A schematic diagram of a data set division method for a stock price prediction method based on sentiment data according to the present invention;
[0027] Figure 4 Schematic diagram of the data training process of the stock price prediction method based on sentiment data according to the present invention. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] Reference Figure 1-4 , a stock price prediction method based on sentiment data, comprising:
[0030] Obtain stock text evaluation data; the stock text evaluation data uses a web page text information crawler program to collect text content in web pages from a stock information communication platform, and filter out stock evaluation related information from it. A stock information communication platform is a website that provides stock price information display, provides a special discussion area for specific stocks, and permanently stores and fully displays discussion information. Stock evaluation related information includes the name or nickname of the evaluator, the time of publication of the evaluation, the content of the evaluation, the browsing status of the evaluation, and other evaluation related data. Figure 1 Shows some details of the acquired data.
[0031] Download historical stock data from a stock data service provider, specifically: download historical daily stock opening prices from a stock data service provider. Stock data service providers are supply channels for websites, servers, and databases that provide historical stock information data downloads.
[0032] The stock text evaluation data is divided into training set data and test set data according to the stocks and time, and the stocks are screened according to the start and end time of the data set, and the stocks that meet the requirements are screened from all stocks to form a stock pool. The data set is divided as follows Figure 2 As shown, the ordinate shows different data sets, and the abscissa is a fixed-length time period, such as day, month, year. In the invention, the time period is year. In addition, except for the first data set that uses a training set data of one time period length and a test set data of one time length, the remaining data sets use training set data of two time period lengths and one time length test set data.
[0033] Then, the stocks within the time period between the start time of the first training set and the end time period of the last test set are screened, and the stocks that meet the abnormal conditions of no delisting or ST during the time period and have always been in the stock pool of the CSI 300 Index are screened out to form the stock pool.
[0034] The stocks in the screened stock pool are processed, the stock text evaluation data is extracted as comment representation data, and the sector correlation coefficient is calculated. First, the trading day test and missing value filling are performed on the stocks in the target stock set. By comparing the stock price date with the trading day, it is checked whether there is any missing trading day data. For the missing stock historical information data on some trading days, the price data of the previous trading day is used to fill the missing values.
[0035] Then, the natural language processing technology is used to segment the published content of the stock reviews. Specifically, a trained semantic analysis model such as hnlp is used to perform semantic analysis on each word in the review information text, and the words are classified according to nouns, verbs, adjectives, adverbs, and prepositions. The words with the same part of speech and adjacent positions are merged, and the sentences are segmented according to the words. For example, the sentence: "It seems that it is a rebound again, and it is in place again. It seems that there is no hope. This stock is too weak and needs to be measured." After segmentation, it becomes: "It seems that / v is / c a / v rebound / v, / w it is / d in place / v / u it seems that / v there is no hope / v, / w this / r / q stock / n is / d weak / a / u it needs to be / v measured / v." This article mainly focuses on verbs (v), adverbs (vd), gerunds (vn), and nouns (n) in the sentences, so only these four types of words are extracted for analysis.
[0036] Then, bidirectional vector embedding coding is used to extract text information into comment representations, and the evaluation text is segmented at two levels using window-level segmentation methods and sentence-level segmentation methods. The verb core words in each segmented window are converted into word embedding vectors using the word2vc method as key embedding vectors, and the words in the sentence to which the window belongs, excluding the verb core words used in the window, are converted into word embedding vectors using the word2vc method as value embedding vectors. The window-level segmentation method and the sentence-level segmentation method are two text segmentation methods: the segmentation object is a sequence of words composed of a fixed window size and a complete sentence. That is, for the evaluation S=s1s2…s k , using the sentence-level segmentation method to split into s1, s2, …, s k , where s n is a sentence in the evaluation; for evaluation S = w1w2…w s , using the window-level segmentation method to split into w1w2…w p ,w p+1 w p+2 …w 2p ,…,w lp+1 w lp+2 ..w s , where w n is a word in the evaluation. c =w a …w b The window w m …w n , whose key embedding vector in w i The word vector of w i ∈w m …w n , w iis the core verb; its value is embedded in the vector in w i The word vector of w i ∈w a …w b .
[0037] Finally, the correlation coefficient between the sections is calculated by the verbs in the evaluation. The correlation coefficient is expressed as SR v,p , which indicates the correlation between verb v and stock bar p, and the calculation expression is:
[0038] SR v,p =STTF v,p ×STISF p,q ×SETF v,q ×SEIDF q
[0039] Where, STTF p,v The frequency of verb v in stock forum p is expressed as:
[0040]
[0041] Where n p,v Indicates the number of times the verb v appears in the stock forum p, m p Indicates the number of all verbs in the stock bar p.
[0042] Where, STISF q,p It represents the inverse sector frequency of stock p for sector q, and the expression is:
[0043]
[0044] Where M q represents the number of all stocks in sector q, N q,v represents the number of stocks in sector q that contain verb v. q,v The frequency of verb v in section q is expressed as:
[0045]
[0046] In the formula, en q,v Indicates the number of times verb v appears in section q, em q Represents the number of all verbs in section q.
[0047] Where, SEIMF q It represents the reverse market frequency of sector q, and the expression is:
[0048]
[0049] In the formula, MM represents the number of sectors in the market, MN q,v Represents the number of all sectors in the market that contain verb v.
[0050] The classification of stock sectors adopts the classification standards of Oriental Fortune.
[0051] Extracting comment representation data from stock text evaluation data, and constructing sentiment data through the comment representation data;
[0052] Building a stock price prediction model based on the sentiment data, the stock price prediction model including a stock price prediction model and a sector sharing model;
[0053] The stock text evaluation data belonging to the same sector is input into the stock price prediction model for pre-training to obtain a sector sharing model; in order to improve the generalization performance of the data and enhance the prediction effect of the model, the present invention introduces a module sharing mechanism in the training, and the training process is as follows: Figure 3 As shown. First, list the sectors to which all stocks in the stock pool belong and summarize them, and divide and organize the stocks according to the sectors to which they belong. Then, the training set data of the stocks belonging to the same sector at a specified time is sequentially input into the stock price prediction model for a small number of trainings. Subsequently, the trained model parameters are saved as a shared model for the sector at the training time, where the order of stock training is in ascending order of stock codes.
[0054] The comment representation data is input into the plate sharing model for formal training; the bidirectional vector embedding encoded by the comments is sequentially input into the plate sharing model for formal training and testing in the order of training set and test set.
[0055] The latest stock text evaluation data is input into the stock price prediction model to predict the stock price trend of the next trading cycle. The latest stock evaluation related information is obtained using a crawler program, encoded as a bidirectional vector embedding, and input into the trained stock price prediction model and the stock price prediction model to predict the stock price trend of the next trading day.
[0056] The stock price prediction model based on sentiment data includes two main modules: data distiller module and stock price trend classifier module.
[0057] The data distiller module embeds the evaluation bidirectional vector obtained in step 3 into the distiller module to obtain the hidden market vector. The calculation formula is as follows:
[0058]
[0059] In the formula, v s,irepresents the value embedding vector of the i-th evaluation of stock s, i∈N, N is the set of all evaluations on the t-th day, Score s,i is the attention score of the i-th sentence evaluation of stock s, calculated as follows:
[0060]
[0061] In the formula, represents the key embedding vector of the jth verb core word in the i-th review of stock s, represents the sector correlation coefficient between the jth verb core word in the i-th evaluation of stock s and the current sector, s s Represents the stock representation used to represent stock s, initialized with random values.
[0062] The stock price trend classifier module consists of a long short-term memory model (LSTM) layer and a multi-layer perceptron module. t =LSTM([X1,X2,…,X t ]), then use the multi-layer perceptron to extract and obtain M t =MLP(Y t ), and finally obtain the probability of the stock price trend rising and falling.
[0063] The number of devices and processing scales described here are used to simplify the description of the present invention, and the application, modification and variation of the present invention will be obvious to those skilled in the art.
[0064] Although the embodiments of the present invention have been disclosed as above, they are not limited to the applications listed in the specification and implementation modes. They can be fully applied to various fields suitable for the present invention. For those familiar with the art, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the scope of equivalents, the present invention is not limited to the specific details and the illustrations shown and described herein.
Claims
1. A stock price prediction method based on sentiment data, characterized in that: include: Get stock text evaluation data; Extracting comment representation data from stock text evaluation data, and constructing sentiment data through the comment representation data; Building a stock price prediction model based on the sentiment data, the stock price prediction model including a stock price prediction model and a sector sharing model; Among them, the stock text evaluation data belonging to the same sector is input into the stock price prediction model for pre-training to obtain a sector sharing model; Input the comment representation data into the shared model for formal training; The latest stock text evaluation data are input into the stock price prediction model to predict the stock price trend of the next trading cycle.
2. A stock price prediction method based on sentiment data as claimed in claim 1, characterized in that: The stock text evaluation data is divided according to the stocks to which it belongs, into respective text information of the stocks, the respective text information of the stocks is sorted in chronological order, and divided according to a specific time span, into training set data and test set data; All stocks are preliminarily screened according to the start time of the first training set and the end time of the last test set, and the stocks that meet the requirements are screened out from all stocks according to the predetermined screening requirements to form a stock pool.
3. A stock price prediction method based on sentiment data as claimed in claim 2, characterized in that: The stocks in the screened stock pool are tested for trading days and missing values are filled. The published content of the obtained stock reviews is segmented using natural language processing technology, and the text information is extracted as comment representation using bidirectional vector embedding coding. The correlation coefficient between sectors is calculated using the verbs in the reviews.
4. A method for predicting stock prices based on sentiment data as claimed in claim 3, characterized in that: The bidirectional vector embedding coding extracts text information into comment representation as follows: The evaluation text is segmented at two levels using the window-level segmentation method and the sentence-level segmentation method respectively; the core verb words in each segmented window are converted into word embedding vectors using the word2vc method as key embedding vectors, and the words in the sentence to which the window belongs, excluding the core verb words used in the window, are converted into word embedding vectors using the word2vc method as value embedding vectors; The window-level segmentation method and the sentence-level segmentation method are respectively specifically two text segmentation methods for segmenting a sequence of words composed of a fixed window size and a complete sentence.
5. A method for predicting stock prices based on sentiment data as claimed in claim 1, characterized in that: The stock price prediction model includes a data distiller module and a stock price trend classifier module; The data distiller module specifically includes: inputting the evaluation bidirectional vector embedding result obtained by calculation into the distiller module to obtain a hidden market vector; The stock price trend classifier module includes a long short-term memory model layer and a multi-layer perceptron module.
6. A method for predicting stock prices based on sentiment data as claimed in claim 1, characterized in that: The stock text evaluation data belonging to the same sector is input into the stock price prediction model for pre-training to obtain a sector sharing model, specifically: List the sectors to which all stocks in the stock pool belong and summarize them, divide and organize the stocks according to the sectors they belong to, input the training set data of the stocks belonging to the same sector at a specified time into the stock price prediction model in sequence for a small number of trainings, and save the trained model parameters as a shared model for the sector at the training time.
7. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Stock trend prediction method and system based on text abstract emotion mining
CN111723127A
Stock closing price prediction method fusing news data
CN115660855A
Stock price index prediction method based on investor emotion and numerical data
CN116071155A
Multi-feature stock trend prediction method fusing shareholder emotion and stock event
CN116541484A
