Bayesian optimization-based CLATT stock correlation prediction method
Through Bayesian optimized CLATT method, combined with CNN and BiLSTM models, the multi-factor model and attention mechanism are used to solve the problem of poor stock correlation prediction results in the existing technology, achieving higher prediction accuracy and robustness sex.
Patent Information
- Application Number
- CN202410455903.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-16
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2044-04-16
AI Technical Summary
It is difficult for the existing technology to accurately predict stock correlations in non-stationary time series, traditional statistical methods are insufficient, and machine learning methods have limited fit to complex data, resulting in poor stock correlation prediction results.
Using the CLATT stock correlation prediction method based on Bayesian optimization, the database is constructed, the data is preprocessed, the factor correlation matrix is calculated, the stock yield data is decomposed using a multi-factor model, the stock yield and correlation data are integrated, and the CNN and BiLSTM model makes predictions, combining attention mechanisms and Bayesian algorithms to optimize hyperparameters.
It improves the accuracy and robustness of stock correlation prediction, is suitable for various stock portfolio conditions, captures complex relationships and patterns, reduces the impact of noise and missing data, and improves algorithm efficiency.
Smart Images

Figure CN119048229A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of data processing technology and time series data prediction technology, and in particular to a CLATT stock correlation prediction method based on Bayesian optimization. Background Art
[0002] Market conditions, economic environment and other factors may cause the correlation between assets to change. These different factors make assets with certain similar characteristics have similar trends in the market. Accurate ex ante estimation of the correlation between portfolio assets has become an important area of research and development. Stock correlation prediction can further promote asset optimization, price discovery, provide liquidity diversification and transfer risks, and reduce the search cost and information cost of financial transactions.
[0003] Different methods and techniques are used to improve the prediction of short-term stock correlation. Traditional statistical methods are only applicable to the prediction of stationary random processes, but not to the prediction of non-stationary time series. Machine learning and other methods are limited by their ability to model historical and current data, and have a certain degree of inadequacy in fitting complex data. Therefore, a CLATT stock correlation prediction method based on Bayesian optimization is urgently needed to solve the above problems. Summary of the invention
[0004] The purpose of the present invention is to provide a CLATT stock correlation prediction method based on Bayesian optimization, which can effectively solve the problems existing in the above-mentioned prior art.
[0005] In order to solve the above technical problems, the present invention adopts the following technical solution: a CLATT stock correlation prediction method based on Bayesian optimization, comprising the following steps:
[0006] S1. Build a database, including stock data and corresponding factor data for at least a period of time;
[0007] S2. Preprocess the data in the database, calculate the correlation matrix between different factors, and eliminate the strongly correlated factors;
[0008] S3. Decompose the stock return data based on the multi-factor model, calculate the corresponding factor values, and use the Pearson correlation coefficient to calculate the correlation data between stocks;
[0009] S4. The stock return data and the correlation data are fused and spliced to obtain an input vector, which is then input into the prediction model to output the prediction result.
[0010] Preferably, in step S1, the stock data includes the stock code, opening price, closing price and transaction date.
[0011] Preferably, in step S2, the preprocessing is: processing the outliers in the stock data and factor data so that they return to a reasonable level, dividing and standardizing the original data using a zero-mean standardization method, and neutralizing the standardized data.
[0012] Preferably, the outlier processing is specifically as follows:
[0013] Calculate the median of the input sequence: Mid = Median(X i );
[0014] Calculate X i sequential The value of the quantile M 1 / 4 ,and The value of the quantile M 3 / 4 ;
[0015] gap1=M 3 / 4 -M 1 / 4 , gap2=M 1 / 2 -M 1 / 4 ;
[0016] Among them, the sequence after extreme value processing is:
[0017] When X i <M 1 / 4 -1.5*gap2, then X i =M 1 / 4 -1.5*gap2;
[0018] When X i >M 1 / 4 +1.5*gap1, then X i =M 3 / 4 +1.5*gap1.
[0019] Preferably, in step S2, the relevant factor calculation formula is:
[0020]
[0021] Among them, ρ is the correlation coefficient, E is the expected calculation method, N is the number of factors, i represents the i-th factor, X and Y are the values of two variables, and μ X and μ Y is the mean of X and Y.
[0022] Preferably, in step S3, the multi-factor model decomposes the stock return data into the following formula:
[0023]
[0024] Among them, R j represents the rate of return of the jth stock; Xjk represents the exposure of the jth stock to the kth factor; f k is the factor yield of the kth factor; u j It represents the pricing error between the actual expected return of the jth stock and the expected return implied by the multi-factor model.
[0025] Preferably, in step S3, the correlation calculation formula between stocks is:
[0026]
[0027] Where R i and R j is the daily stock return, two groups of sample points (R i ,R j ) is calculated as follows:
[0028]
[0029]
[0030]
[0031] Among them, Cov(R i ,R j ) is the covariance coefficient, n is the number of returns, R i and R j is the daily return of the stock, X i is the daily stock return, is the mean stock return rate in the interval, σ i is the standard deviation.
[0032] Preferably, in step S4, the input vector includes:
[0033] Time series X of multivariate factors t :
[0034] in, represents the correlation feature column, Represents the stock return feature column, c represents the correlation data, r represents the corresponding return data, and the sum of c and r is the same as i.
[0035] Preferably, in step S4, the prediction model is composed of a CNN and several BiLSTM layers superimposed and an attention mechanism, and is optimized using a Bayesian algorithm until the optimal hyperparameters are determined.
[0036] Preferably, the prediction model includes:
[0037] Input layer, used to receive input vector;
[0038] CNN layer, extracts each feature information in the input vector and retains the time series characteristics of the input stock correlation data;
[0039] BiLSTM layer, processes time series information and captures the temporal features in the input stock data and correlation data;
[0040] The attention mechanism layer receives the stock correlation data processed by the BiLSTM layer and captures the intrinsic relationship between the input stock data and the correlation data;
[0041] Output layer, outputs the prediction results of the correlation.
[0042] Beneficial effect: In the present invention, the input vector is obtained by fusing and splicing the stock yield data with the correlation data, so as to enhance the multi-source of the input data and improve the prediction accuracy. The prediction model adopts a combination of CNN and several BiLSTM layers and an attention mechanism. The attention mechanism focuses on the most relevant features in the output data, thereby improving the robustness of the model to noise and missing data. The model can capture the complex relationships and patterns in the data, so it is suitable for various stock combination conditions. The Bayesian optimization algorithm can be used to train with historical results to obtain the best hyperparameter values, thereby improving the efficiency of the algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0044] In the attached picture:
[0045] Figure 1 It is a schematic diagram of a stock prediction model based on multi-source data fusion of the present invention;
[0046] Figure 2 A schematic diagram of a coding prediction network structure for predicting correlation between stocks according to an embodiment of the present invention;
[0047] Figure 3 Schematic diagram of the steps of the multi-factor model of an embodiment of the present invention. DETAILED DESCRIPTION
[0048] The embodiments of the present invention are described below in conjunction with the drawings in the embodiments of the present invention. The terms used in the implementation mode of the present invention are only used to explain the specific embodiments of the present invention, and are not intended to limit the present invention. The embodiments of the present application are described below in conjunction with the drawings.
[0049] refer to Figure 1, is a method and flow chart of predicting the correlation between stocks according to an embodiment of the present invention, which is a CLATT stock correlation prediction method based on Bayesian optimization, comprising the following steps:
[0050] Build a database, including stock data and corresponding factor data for at least a period of time;
[0051] Preprocess the data in the database, calculate the correlation matrix between different factors, and eliminate the strongly correlated factors;
[0052] Based on the multi-factor model, the stock return data (the return calculated by the closing price) is decomposed, the corresponding factor values are calculated, and the correlation data between stocks is calculated using the Pearson correlation coefficient;
[0053] The stock return data and correlation data are fused and spliced to obtain the input vector, which is then input into the prediction model to output the prediction result.
[0054] Based on the above method, taking a financial quantitative enterprise as an example, the details are as follows:
[0055] Select a period of time including stock codes, opening prices, closing prices, transaction dates and corresponding factor data to build a database;
[0056] The factor data and stock data yield data were screened, and then the factor data was preprocessed, including extreme value processing, null value processing, factor data normalization and neutralization processing; the outlier processing used the quartile method, and the quartile method calculation method is as follows:
[0057] Calculate the median of the input sequence: Mid = Median(X i );
[0058] Calculate X i sequential The value of the quantile M 14 ,and The value of the quantile M 34 ;
[0059] gap1=M 3 / 4 -M 1 / 4 , gap2=M 1 / 2 -M 1 / 4 ;
[0060] Among them, gap1 represents the distance between the upper half of the data set (i.e., the upper quartile to the median of the upper quartile); it is the distance between the upper quartile (Q3) and the lower quartile (Q1);
[0061] gap2 represents the distance between the lower quartile (Q1) and the median (Q2);
[0062] Among them, the sequence after extreme value processing is:
[0063] When X i <M 1 / 4 -1.5*gap2, then X i =M 1 / 4 -1.5*gap2;
[0064] When X i >M 1 / 4 +1.5*gap1, then X i =M 3 / 4 +1.5*gap1;
[0065] As mentioned above, the two thresholds are calculated based on the distribution and quartiles of the data to identify and handle possible outliers;
[0066] The first threshold is M 1 / 4 -1.5*gap2, this value represents the distance between the lower quartile (Q1) minus 1.5 times the lower quartile and the median (Q2); this threshold is used to identify possible outliers in the lower half of the data set.
[0067] The second threshold is M 3 / 4 +1.5*gap1. This value represents the distance from the upper quartile (Q3) plus 1.5 times the distance from the upper quartile to the median (Q2). This threshold is used to identify possible outliers in the upper half of the data set.
[0068] Through these two thresholds, we can reasonably determine the outliers that may exist in the data set and process them to ensure the accuracy and robustness of the data.
[0069] The calculation formula for the relevant factors is:
[0070]
[0071] Among them, ρ is the correlation coefficient, E is the expected calculation method, N is the number of factors, i represents the i-th factor, X and Y are the values of two variables, and μ X and μ Y It is the mean of X and Y. If the correlation between the two is closer to 1 or -1, the correlation is stronger, and if it is closer to 0, the correlation is weaker.
[0072] There are many factors that affect stock returns, and stock correlation data also includes many attributes. Based on the multi-factor model, the Barra model is used to quantify fundamental factors. The multi-factor model decomposes the daily stock returns into the following formula:
[0073]
[0074] Among them, R j represents the rate of return of the jth stock; X jk represents the exposure of the jth stock to the kth factor; f k is the factor yield of the kth factor; u j It represents the pricing error between the actual expected return of the jth stock and the expected return implied by the multi-factor model.
[0075] The specific quantitative indicators are market capitalization, Beta, momentum, volatility, nonlinear market capitalization, price-to-book ratio, liquidity, profitability, growth rate, leverage and other important factor variable characteristics with strong correlation with stocks, which are used to measure the return rate of stocks; the following table gives the characteristic factors and factor interpretations used in this article:
[0076]
[0077] Quantify the factor exposure of the asset on each factor; factor exposure is a measure of the deviation of the asset return from the market benchmark, which is used to characterize the multiple factors of the asset, and then use these indicators to calculate the correlation of the assets; the formula for calculating stock correlation is as follows:
[0078]
[0079] Where R i and R j The daily return of stocks is quantified using a multi-factor model. Two groups of sample points (R i ,R j ) is calculated as follows:
[0080]
[0081]
[0082]
[0083] Among them, Cov(R i ,R j ) is the covariance coefficient, n is the number of returns, R i and R j is the daily return of the stock, X i is the daily stock return, is the mean stock return rate in the interval, σ i is the standard deviation, which determines the input of the model data. The specific description of multi-source data fusion is as follows: In terms of form, multivariate is used to predict the data at time t, then the multivariate time series representing the observation at time t can be expressed as:
[0084]
[0085] Where i represents the feature of a column, and w represents the length of the observation sequence. Then the input matrix at time t can be expressed as:
[0086]
[0087] in represents the correlation feature column, represents the stock return feature column, the sum of c and r is the same as i. At time step t, y t is the correlation data, X t is a typical multivariate factor vector, then the corresponding correlation prediction The prediction problem of correlation uses the time series X of multivariate factors t and the real correlation data y t As input, the final model estimates future time steps.
[0088] For the above, the prediction model is composed of a CNN and several BiLSTM layers stacked together with an attention mechanism, and is optimized using the Bayesian algorithm until the optimal hyperparameters are determined, that is, the weight value that minimizes the MSE of the model's loss function.
[0089] Among them Figure 2 As shown in the figure, the prediction model mainly consists of five parts: input layer, CNN layer, BiLSTM layer, attention mechanism layer and output layer.
[0090] The function of the input layer is to accept the normalized stock correlation data; the CNN module extracts the feature information of the input data and retains the time series characteristics of the input stock correlation data; a wide convolution kernel can be used in the convolutional network to obtain a larger receptive field, extract more feature information, and effectively suppress noise interference; then, the stock processing time series information processed in the CNN module captures the time series features of the input stock data and correlation data. The yield data and correlation data will be sent to the next layer; the role of the BiLSTM layer is; then, the stock correlation data processed by the BiLSTM layer is input into the attention layer; the role of the self-attention layer is to capture the intrinsic correlation between the input stock data and the correlation data, which helps to improve the prediction accuracy of stock correlation; the attention layer transmits the processed data results to the output layer; finally, the output layer outputs the prediction results of the correlation.
[0091] Furthermore, the following experiments are conducted to further verify its effect:
[0092] The dataset randomly selects 8 stocks from the fund holdings as candidate assets. The codes of the 8 stocks are 300015, 300274, 300347, 603799, 300014, 300122, 300207, and 300450. Finally, in order to ensure the consistency of the data, the null values are removed and the trading date segments with common values are selected. Finally, a total of 1227 days from 2017 / 01 / 04 to 2022 / 01 / 28 are selected to calculate the stock correlation data, and the corresponding stock returns are one trading day ahead of the correlation data date, totaling 1127 trading days.
[0093] The Bayesian optimization algorithm is used to determine the optimal value of the hyperparameters for the proposed model. Based on a large number of experiments, the four methods select the hyperparameter combination corresponding to the minimum MAE value as the hyperparameter combination finally applied to stock correlation prediction. The results are shown in the following table:
[0094]
[0095] The optimal model mean square error (MSE) model was used to examine the accuracy of correlation prediction. For further evaluation, the mean absolute error (MAE), root mean square error (RMSE) model and regression effect related index R2 model were also used; MSE gives the error generated in the regression. The formula for calculating the MSE formula is given below:
[0096]
[0097] where m is the number of instances in the dataset on which the MSE is measured, x (i) is the vector of all features (excluding labels) of the i-th instance in the dataset, and y (i) is its label (the expected output value of the instance). The root mean square error model is as follows:
[0098]
[0099] For a given model, the mean absolute error is calculated, and the formula is defined as follows:
[0100]
[0101] R2 is a measure of the effect of fitting the time series values;
[0102]
[0103] The numerator of the formula is the error sum of squares, which is used to directly judge the effect of model fitting; the denominator is the sample standard deviation sum of squares, which is used as a comparison object for the error sum of squares. i represents the true value of the actual stock correlation, is the predicted stock correlation value, i represents the i-th data, is the average of the true values.
[0104] In order to verify the prediction performance of the CNN-BiLSTM hybrid neural network based on the attention mechanism in stock correlation, an experimental comparison of the regression effects of different models under the same data set input was set up. By comparing the data values and change trends of various evaluation indicators in the experiment, the effectiveness of the proposed improved model was analyzed and verified; the comparison of the out-of-sample loss functions of different models is shown in the following table:
[0105]
[0106] The experimental results show that the CLATT model has a 36.89% improvement in MAE. Looking further, the CLATT model has a 30.30% improvement over CNN-LSTM and a 27.62% improvement over CNN-BiLSTM. Based on the MSE measurement, CLATT has achieved a 45.76% improvement over CNN-BiLSTM on both datasets. Therefore, the CLATT model has a more accurate prediction result and is more robust.
[0107] In order to verify the effectiveness of multivariate data input, that is, to simultaneously integrate data sources directly related to stock correlation data as sample input of the model to verify the improvement effect of the model, the same deep learning model is set, the specific parameters are consistent with the above, the sample data variable input is changed, and the comparative experimental results are observed.
[0108] Specifically, the experimental process used the CNN-BiLSTM hybrid deep learning model with an integrated attention mechanism, and on this basis, the return data directly related to stock correlation was added and subtracted separately to verify the validity of multivariate data. The performance of each evaluation indicator attribute value in the model experimental results on different stock data sample sets was compared, and the overall average of different indicators on each group of different stock data sets was calculated. The specific experimental results are shown in the following table, where "+" represents multivariate data input and "-" represents single stock correlation time series data input:
[0109]
[0110] The experimental result graph shows that compared with the return rate data without adding stocks, the prediction error indicators MAE, MSE, and RMSE of the model proposed by the present invention have a certain downward trend, and the fitting degree of the model is also improved. This shows that the variables added by the present invention are all valid inputs, and the flat and comprehensive data can significantly improve the prediction effect.
[0111] refer to Figure 3, BARRA multi-factor model; data processing, select the common factors that affect stock risks according to the BARRA multi-factor model, calculate the stock correlation through risk factors, and use a sliding window to define the format of the model input data.
[0112] The embodiments of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above embodiments. For ordinary technicians in this technical field, after knowing the contents recorded in the present invention, they can make several equivalent changes and substitutions without departing from the principle of the present invention. These equivalent changes and substitutions should also be regarded as belonging to the protection scope of the present invention.
Claims
1. A CLATT stock correlation prediction method based on Bayesian optimization, characterized in that: The steps include: S1. Build a database, including stock data and corresponding factor data for at least a period of time; S2. Preprocess the data in the database, calculate the correlation matrix between different factors, and eliminate the strongly correlated factors; S3. Decompose the stock return data based on the multi-factor model, calculate the corresponding factor values, and use the Pearson correlation coefficient to calculate the correlation data between stocks; S4. The stock return data and the correlation data are fused and spliced to obtain an input vector, which is then input into the prediction model to output the prediction result.
2. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S1, the stock data includes the stock code, opening price, closing price and trading date.
3. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S2, the preprocessing is: processing the outliers in the stock data and factor data to make them return to a reasonable level, and using the zero-mean normalization method to divide and normalize the original data, and neutralizing the standardized data.
4. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 3 is characterized by: The specific processing of outliers is as follows: Calculate the median of the input sequence: Mid = Median(X i ); Calculate X i sequential The value of the quantile M 1 / 4 ,and The value of the quantile M 3 / 4 ; gap1=M 3 / 4 -M 1 / 4 ,gap2=M 1 / 2 -M 1 / 4 ; Among them, the sequence after extreme value processing is: When X i <M 1 / 4 -1.5*gap2, then X i =M 1 / 4 -1.5*gap2; When X i >M 1 / 4 +1.5*gap1, then X i =M 3 / 4 +1.5*gap1.
5. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S2, the relevant factor calculation formula is: Among them, ρ is the correlation coefficient, E is the expected calculation method, N is the number of factors, i represents the i-th factor, X and Y are the values of two variables, and μ X and μ Y is the mean of X and Y.
6. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S3, the multi-factor model decomposes the stock return data into the following formula: Among them, R j represents the rate of return of the jth stock; X jk represents the exposure of the jth stock to the kth factor; f k is the factor yield of the kth factor; u j It represents the pricing error between the actual expected return of the jth stock and the expected return implied by the multi-factor model.
7. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S3, the correlation calculation formula between stocks is: Where R i and R j is the daily stock return, two groups of sample points (R i ,R j ) is calculated as follows: Among them, Cov(R i ,R j ) is the covariance coefficient, n is the number of returns, R i and R j is the daily return of the stock, X i is the daily stock return, is the mean stock return rate in the interval, σ i is the standard deviation.
8. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1 is characterized in that: In step S4, the input vector includes: Time series X of multivariate factors t : in, represents the correlation feature column, Represents the stock return feature column, c represents the correlation data, r represents the corresponding return data, and the sum of c and r is the same as i.
9. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 1, characterized in that: In step S4, the prediction model is composed of a CNN and several BiLSTM layers stacked together with an attention mechanism, and is optimized using a Bayesian algorithm until the optimal hyperparameters are determined.
10. The CLATT stock correlation prediction method based on Bayesian optimization according to claim 9 is characterized in that: Predictive models include: Input layer, used to receive input vector; CNN layer, extracts each feature information in the input vector and retains the time series characteristics of the input stock correlation data; BiLSTM layer, processes time series information and captures the temporal features in the input stock data and correlation data; The attention mechanism layer receives the stock correlation data processed by the BiLSTM layer and captures the intrinsic relationship between the input stock data and the correlation data; Output layer, outputs the prediction results of the correlation.
Citation Information
Patent Citations
Grouping Naive Bayes model based multi-factor online prediction method and system
CN105912690A
Stock factor revenue analysis method and device, computer equipment and storage medium
CN109584076A
Method for predicting correlation risk between stocks and terminal equipment
CN113379546A
Stock price prediction method combining network public opinion and dependency
CN114022179A
AU2020102461A4
