A Stock Forecasting Method Based on Seasonal Analysis
Through the stock prediction method based on seasonal analysis, stock data is decomposed into trend, seasonal and residual components, and prediction is performed using the Informer model, the prediction problem of the existing technology when dealing with the complexity and nonlinear characteristics of stock data is solved, and higher prediction accuracy and effectiveness are achieved.
Patent Information
- Application Number
- CN202411818051.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-04-08
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, when dealing with the complexity, nonlinear characteristics and long-term time series prediction of stock data, there is a problem of accurately predicting stock market trends.
The stock prediction method based on seasonal analysis is used, and the stock data is decomposed into trend components, seasonal components and residual components through the STL algorithm, and the Informer model is used for prediction.
It significantly improves the accuracy and effectiveness of stock market trend forecasts, can better capture long-term dependencies and multiple frequency components, and provide more accurate stock price prediction information.
Smart Images

Figure CN119784417A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of stock prediction, and more specifically, relates to a stock prediction method based on seasonal analysis. Background Art
[0002] With the rapid development of the global economy and society, the stock market has become increasingly popular among investors. Stock market forecasts can provide important reference value for investors to select investment portfolios. Stock market fluctuations are affected by a variety of internal and external factors, which are complex and difficult to quantify, including the company's operating conditions, macroeconomic policies, industry development trends, etc. Due to the complexity and nonlinearity of the financial market, processing large and complex stock data requires a lot of computing resources and energy. With the rapid advancement of big data, artificial intelligence and machine learning technologies, the academic community generally recognizes that stock prices are predictable. In this context, researchers are committed to developing optimal nonlinear models to predict stock price trends.
[0003] Due to the complexity, variability and nonlinearity of stock data, it is very difficult to establish an accurate mathematical model to predict its price trend. The rise and fall of stock prices are affected by both internal and external factors, and the complexity of market fluctuations makes accurate prediction of stock prices an unresolved problem.
[0004] Chinese Patent CN118505362A: A Transformer model optimization prediction method based on particle swarm algorithm, using Transformer as the prediction model, the computational complexity of Transformer's self-attention mechanism is O(n 2 ) where n is the sequence length. This results in a significant increase in memory and computing resource consumption when processing long sequences.
[0005] Chinese Patent CN116957140A: A stock prediction method and system based on NLP factors: This method requires a large amount of text data as training data, and the data quality has a great impact on the prediction results.
[0006] Chinese Patent CN114861965A: A Stock Prediction System Based on Long Short-Term Memory Neural Network: The LSTM used performs well in processing short-term dependencies, but its ability to capture long-term dependencies decreases as the sequence length increases. However, stock market data often has long-term dependencies, and LSTM cannot fully capture these long-term trends and patterns.
[0007] The methods mentioned in the above patents have obvious defects when dealing with long-term stock data series, facing the problems of complex fluctuation trends and difficult feature analysis. Specifically, these methods show obvious limitations in capturing long-standing dependencies and multiple frequency components in the stock market. They have difficulty accurately identifying and separating different characteristic patterns in the market, resulting in incomplete and inaccurate analysis results. Overall, existing methods lack sufficient flexibility and adaptability when faced with the complexity and variability of stock market data, and cannot provide reliable prediction and analysis results. These defects limit their effectiveness in practical applications and are in urgent need of improvement and optimization.
[0008] In this context, the Informer model, as a sequence modeling architecture based on the attention mechanism, has attracted widespread attention due to its excellent performance in long time series prediction tasks. By introducing an efficient attention mechanism, the Informer model can better capture the long-range dependencies in time series data and improve prediction accuracy. In addition, the model performs well in processing large-scale data sets and long time series, overcoming the shortcomings of traditional methods in these aspects. Combined with seasonal analysis, the model's predictive ability and stability are further improved. Therefore, the stock prediction method based on seasonal analysis is expected to make breakthroughs in practical applications, provide investors with more accurate prediction results, and assist in their investment decisions. Summary of the invention
[0009] The present invention aims to solve the following problems: Due to the complexity and nonlinear characteristics of stock data and the unsatisfactory prediction effect of long-term time series, it is very difficult to accurately predict the stock market trend. Therefore, the present invention proposes a stock prediction method based on seasonal analysis to improve the accuracy and effectiveness of stock data analysis and prediction.
[0010] To solve the above problems, according to one aspect of the present invention, a stock prediction method based on seasonal analysis is provided, which includes the following processing methods: S1, data acquisition and cleaning; S2, data decomposition and standardization; S3, data division; S4, data prediction; S5, prediction result integration.
[0011] To achieve the above object, the present invention adopts the following technical solutions:
[0012] Obtaining daily stock market data: Use crawler tools to obtain historical daily trading data of target stocks from reliable data sources, providing a basis for subsequent data analysis and model training.
[0013] Data cleaning: Perform comprehensive data cleaning on the acquired stock data, detect and process the null values and outliers in the data. Missing values can be processed by methods such as mean filling and interpolation to ensure the integrity and accuracy of the data. In addition, obvious erroneous data and noise data must be eliminated to ensure data quality.
[0014] Modal decomposition: It uses the seasonal analysis STL algorithm to decompose the data into trend components, seasonal components, and residual components and then standardize them. STL can handle situations where seasonal components change over time, allowing seasonal fluctuations in different periods to show inconsistencies. It can adapt to different data characteristics without the need for strict noise reduction preprocessing of the data. STL uses the local weighted regression (Loess) smoothing method, which can effectively resist the influence of outliers, so it has good robustness to noise and outliers in the data. STL clearly decomposes the time series into three parts: trend, seasonality, and residual, making the analysis and explanation of the reasons for data changes clearer. The smoothing parameters of STL (such as the span of seasonality and trend) can be adjusted according to the characteristics of the data, thereby improving the adaptability and accuracy of the model. The algorithm optimizes the estimation of trend and seasonal components through an iterative process, thereby improving the accuracy of the decomposition. The computational complexity of STL is relatively low, suitable for processing large-scale time series data, and can quickly obtain results. The S2 step includes the following steps: S21 basic model: STL converts the time series y t Broken down into three parts: y t =T t +S t +R t (1) Where: y t is the original time series data, the observed value at time point t; T t S is the trend component, which indicates the long-term trend of the time series. t It is a seasonal component, indicating periodic changes or seasonal fluctuations. t is the residual component, which represents the part that cannot be explained by trend and seasonality, and usually contains random noise. S22 Extraction of trend components: Trend component T t It is estimated by locally weighted regression (Loess) smoothing. Loess is a nonparametric regression method with the formula: T t =Loess(y t ,span) (2) Among them: Loess refers to the method of using local weighted regression to smooth data; span is used to control the number or proportion of neighboring observations for calculating the trend of each point, which determines the degree of smoothing. In specific calculations, Loess selects a certain number of neighboring points around each point t for weighted regression. For each point t, it can be expressed as: Where: w i for y i The weight of the point is usually calculated using a smoothing kernel function; n is the total number of observations. Extraction of S23 seasonal components: After obtaining the trend component, calculate the residual: R' t =y t -T t (4) The Loess method is then used to extract the seasonal component of the residuals: S t =Loess(R' t ,span_seasonal) (5) Where: R' t It is the residual after removing the trend, which is used to capture seasonal fluctuations; span_seasonal is used to control the degree of smoothing of the seasonal component. Calculation of S24 residual components: Once the trend and seasonal components are obtained, the residual components can be calculated: R t =y t -T t -S t (6) S25 Iterative Update: STL uses an iterative method to update the trend and seasonal components until convergence. The specific steps are as follows: Preliminary estimate T t and S t ; Calculate the residual R t ; Update the seasonal component based on the new residuals; Re-estimate the trend component using the updated seasonal component; Repeat the above process until the trend and seasonal components are stable. S26 Standardization: In S2, the standardization process uses the Z-score standardization method to scale the data so that it falls into a specific range to ensure stability and effectiveness when the data is input into the model.
[0015] Dataset division: Divide the processed dataset into training set and validation set.
[0016] Model training and prediction: Build and train a stock prediction model based on the Informer architecture. The model includes the ProbSparse Self-attention layer, the Self-attention Distilling layer, and the Layer stacking replicas layer.
[0017] Prediction result integration: By adding up these prediction values, we get the final prediction sum. The calculation formula for the final prediction result Y is: Y=T t1 +S t1 +R t1 (7) Here, T t1 , S t1 and R t1 They represent the predicted values of the trend component, seasonal component, and residual component after being processed by the Informer model, and Y represents the sum of the component prediction results.
[0018] The present invention effectively solves the shortcomings of traditional methods in dealing with the complexity and nonlinear characteristics of stock data by introducing seasonal analysis, and significantly improves the accuracy and effectiveness of stock market trend prediction. This method can be applied not only to the stock market, but also to other financial and economic fields that require long-term series prediction. By using this method, investors can obtain more accurate stock price prediction information, thereby optimizing investment decisions, reducing investment risks, and increasing investment returns. BRIEF DESCRIPTION OF THE DRAWINGS Figure 1 is a flow chart of a stock prediction method based on seasonal analysis of the present invention; Figure 2 Flowchart for stock data preprocessing; Figure 3 It is a structural schematic diagram of the stock prediction model in the present invention; Figure 4 This is the sample prediction effect diagram; DETAILED DESCRIPTION In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment 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. Unless otherwise defined, the technical or scientific terms used herein shall have the common meanings understood by persons with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one" or "a" do not indicate a quantity limitation, but indicate the existence of at least one. like Figure 1 As shown, the present invention provides a stock prediction method based on seasonal analysis, and the specific steps are as follows: S1. Data acquisition and cleaning: acquiring the daily market data of the target stock and cleaning the obtained data; S2, data decomposition and standardization, the stock data is decomposed using seasonal algorithms and then standardized; S3, data division, the data is divided into training set and validation set; S4, data prediction, build the Informer stock prediction model for seasonal analysis, and input the processed data into the model for prediction; S5. Integrate the forecast results, adding and integrating the forecast results of the trend component, seasonal component and residual component of the seasonal analysis; The prediction model includes a ProbSparse Self-attention layer, a Self-attentionDistilling layer, and a Layer stacking replicas layer. Specifically, the stock prediction method based on seasonal analysis provided in this embodiment includes the following steps: S1. Data acquisition and cleaning: acquiring the daily market data of the target stock and cleaning the obtained data. Specifically, Figure 2 As shown in the figure, the historical daily trading data of the target stock is obtained from a reliable data source by using a crawler tool, which provides a basis for subsequent data analysis and model training. The acquired stock data is fully cleaned to detect and process null values and outliers in the data. Missing values can be processed by methods such as mean filling and interpolation to ensure the integrity and accuracy of the data. In addition, obvious erroneous data and noise data must be eliminated to ensure data quality. S2. Data decomposition and standardization: seasonal analysis STL algorithm is used to decompose the data into trend component, seasonal component and residual component and then standardize them. Specifically, step S2 includes the following steps: S21 basic model: STL converts the time series y t Broken down into three parts: yt =T t +S t +R t (1) Where: y t is the original time series data, the observed value at time point t; T t S is the trend component, which indicates the long-term trend of the time series. t It is a seasonal component, indicating periodic changes or seasonal fluctuations. t is the residual component, which represents the part that cannot be explained by trend and seasonality, and usually contains random noise. S22 Extraction of trend components: Trend component T t It is estimated by locally weighted regression (Loess) smoothing. Loess is a nonparametric regression method with the formula: T t =Loess(y t ,span) (2) Among them: Loess refers to the method of using local weighted regression to smooth data; span is used to control the number or proportion of neighboring observations for calculating the trend of each point, which determines the degree of smoothing. In specific calculations, Loess selects a certain number of neighboring points around each point t for weighted regression. For each point t, it can be expressed as: Where: w i for y i The weight of the point is usually calculated using a smoothing kernel function; n is the total number of observations. Extraction of S23 seasonal components: After obtaining the trend component, calculate the residual: R' t =y t -T t (4) The Loess method is then used to extract the seasonal component of the residuals: S t =Loess(R' t ,span_seasonal) (5) Where: R' t It is the residual after removing the trend, which is used to capture seasonal fluctuations; span_seasonal is used to control the degree of smoothing of the seasonal component. Calculation of S24 residual components: Once the trend and seasonal components are obtained, the residual components can be calculated: R t =y t -T t -S t (6) S25 Iterative Update: STL uses an iterative method to update the trend and seasonal components until convergence. The specific steps are as follows: Preliminary estimate T t and S t ; Calculate the residual R t ; Update the seasonal component based on the new residuals; Re-estimate the trend component using the updated seasonal component; Repeat the above process until the trend and seasonal components are stable. S26 Standardization: In S2, the standardization process uses the Z-score standardization method to scale the data so that it falls into a specific range to ensure stability and effectiveness when the data is input into the model. S3. Data division: The data is divided into training set and validation set. S4. Data prediction: construct a stock prediction model for seasonal analysis and input the processed data into the model for prediction. Specifically, several standardized decompositions are divided into trend components, seasonal components, and residual components and are input into the prediction model respectively. S5. Integrate the forecast results. Add and integrate the forecast results of the decomposed trend component, seasonal component, and residual component. Specifically, by adding up these predicted values, the final predicted sum is obtained. The calculation formula for the final prediction result Y is: Y=T t1 +S t1 +R t1 (7) Here, T t1 , S t1 and R t1 They represent the predicted values of the trend component, seasonal component, and residual component after being processed by the Informer model, and Y represents the sum of the component prediction results. The above description is merely an exemplary embodiment of the present invention and is not intended to limit the protection scope of the present invention. The protection scope of the present invention is determined by the appended claims.
Claims
1. A stock forecasting method based on seasonal analysis, characterized by , including the following steps; S1. Data acquisition and cleaning: acquiring the daily market data of the target stock and cleaning the obtained data; S2, data decomposition and standardization, the stock data is decomposed using seasonal algorithms and then standardized; S3, data division, the data is divided into training set and validation set; S4, data prediction, build the Informer stock prediction model for seasonal analysis, and input the processed data into the model for prediction; S5. Integrate the forecast results, adding and integrating the forecast results of the trend component, seasonal component and residual component of the seasonal analysis; The prediction model includes a ProbSparse Self-attention layer, a Self-attention Distilling layer, and a Layer stacking replicas layer.
2. A stock prediction method based on seasonal analysis as claimed in claim 1, characterized in that: The S1 step includes the following steps: S11: Determine the target stock and time range, determine which stocks' historical transaction data are to be obtained and the specific time range, which can be determined by stock code and start and end dates. S12: Set up the crawler tool to ensure that it can send HTTP requests to the target website and obtain the required data, parse the response data returned by the target website, and extract the daily market data of the target stock. This step involves converting data in HTML or JSON format into a structured form. S13: Check and clean the stock market data. First, check whether the data contains null values or outliers. Null values refer to the lack of necessary data information in the data set, while outliers refer to values that significantly deviate from other data points. For the detected null values, insert equivalent data to fill and other missing value processing methods are adopted. The selection of equivalent data can be based on the average value of adjacent data, the trend of historical data or other statistical methods to ensure that the filled data is reasonable and does not affect subsequent analysis and prediction. In addition, for the detected outliers, it is necessary to further analyze the source and rationality of these values. If it is determined to be erroneous data, it is also necessary to perform appropriate processing or replacement to ensure the accuracy and completeness of the entire data set. Through these steps, the data quality of subsequent model training and prediction can be guaranteed, and the reliability and accuracy of the prediction results can be improved. S14: Save the data, and save the finally processed stock daily market data to a designated storage medium, which may be a local file, a database or other storage system, for subsequent use and analysis.
3. A stock prediction method based on seasonal analysis as claimed in claim 1, characterized in that: The data decomposition and standardization described in S2 is to use the seasonal analysis STL algorithm to decompose the data into trend components, seasonal components, and residual components and then standardize them. STL can handle the situation where the seasonal component changes over time, allowing seasonal fluctuations in different periods to show inconsistency. It can adapt to different data characteristics without the need for strict noise reduction preprocessing of the data. STL uses the local weighted regression (Loess) smoothing method, which can effectively resist the influence of outliers, so it has good robustness to noise and outliers in the data. STL clearly decomposes the time series into three parts: trend, seasonality, and residual, making the analysis and explanation of the reasons for data changes clearer. The smoothing parameters of STL (such as the span of seasonality and trend) can be adjusted according to the characteristics of the data, thereby improving the adaptability and accuracy of the model. The algorithm optimizes the estimation of trend and seasonal components through an iterative process, thereby improving the accuracy of the decomposition. The computational complexity of STL is relatively low, suitable for processing large-scale time series data, and can quickly obtain results. The S2 step includes the following steps: S21 basic model: STL converts the time series y t Broken down into three parts: y t =T t +S t +R t (1) Where: y t is the original time series data, the observed value at time point t; T t S is the trend component, which indicates the long-term trend of the time series. t It is a seasonal component, indicating periodic changes or seasonal fluctuations. t is the residual component, which represents the part that cannot be explained by trend and seasonality, and usually contains random noise. S22 Extraction of trend components: Trend component T t It is estimated by locally weighted regression (Loess) smoothing. Loess is a nonparametric regression method with the formula: T t =Loess(y t ,span) (2) Among them: Loess refers to the method of using local weighted regression to smooth data; span is used to control the number or proportion of neighboring observations for calculating the trend of each point, which determines the degree of smoothing. In specific calculations, Loess selects a certain number of neighboring points around each point t for weighted regression. For each point t, it can be expressed as: Where: w i for y i The weight of the point is usually calculated using a smooth kernel function; n is the total number of observations. Extraction of S23 seasonal components: After obtaining the trend component, calculate the residual: R’ t =y t -T t (4) The Loess method is then used to extract the seasonal component of the residuals: S t =Loess(R’ t ,span_seasonal) (5) Where: R' t It is the residual after removing the trend, which is used to capture seasonal fluctuations; span_seasonal is used to control the degree of smoothing of the seasonal component. Calculation of S24 residual components: Once the trend and seasonal components are obtained, the residual components can be calculated: R t =y t -T t -S t (6) S25 Iterative Update: STL uses an iterative method to update the trend and seasonal components until convergence. The specific steps are as follows: Preliminary estimate T t and S t ; Calculate the residual R t ; Update the seasonal component based on the new residuals; Re-estimate the trend component using the updated seasonal component; Repeat the above process until the trend and seasonal components are stable. S26 Standardization: In S2, the standardization process uses the Z-score standardization method to scale the data so that it falls into a specific range to ensure stability and effectiveness when the data is input into the model.
4. A stock forecasting method based on seasonal analysis as claimed in claim 1, characterized in that: In S3, the processed data set is divided into a training set and a validation set.
5. A stock prediction method based on seasonal analysis as claimed in claim 1, characterized in that: The ProbSparse Self-attention layer, Self-attention Distilling layer, and Layer stacking replicas layer constitute the core structure of the Informer model. The ProbSparse Self-attention layer improves computational efficiency and the generalization ability of the model by sparsely sparse attention weights; the Self-attention Distilling layer uses knowledge distillation technology to extract key information from complex attention distribution to enhance the learning ability and stability of the model; Layerstacking replicas increases the depth of the model by stacking multiple layers of the same structure, thereby improving its representation ability and prediction accuracy.
6. A method for stock prediction based on seasonal analysis as claimed in claim 5, characterized in that: Several standardized trend components, seasonal components, and residual components are input into the prediction model respectively.
7. A stock prediction method based on seasonal analysis as claimed in claim 1, characterized in that: The step S5 includes the following steps: the prediction results outputted by the step S6 are accumulated to obtain the final prediction sum. The calculation formula of the final prediction result Y is: Y=T t1 +S t1 +R t1 (7) Here, T t1 , S t1 and R t1 They represent the predicted values of the trend component, seasonal component, and residual component after being processed by the Informer model, and Y represents the sum of the component prediction results.
8. A stock prediction method based on seasonal analysis according to claim 1, characterized in that: In S4, the Adam optimizer is used in the training process of the Informer model to improve the convergence speed and prediction accuracy of the model.
9. A stock prediction method based on seasonal analysis according to claim 1, characterized in that: The method also includes a result evaluation step, in which the prediction results are evaluated using indicators such as mean square error (MSE) and mean absolute error (MAE) to verify the effectiveness and reliability of the model.
Citation Information
Patent Citations
Stock prediction system based on long short-term memory neural network
CN114861965A
Stock prediction method and system based on NLP factor
CN116957140A
Product recommendation method and device
CN118505362A