A stock risk analysis method based on mean reversion
Patent Information
- Application Number
- CN202610897607.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-22
- Publication Date
- 2026-10-16
AI Technical Summary
本发明中通过获取两品种股票的同步价格、建立滚动窗口内的一元线性回归方程、计算残差值序列的标准化偏离值并输出结构化结果包,能够有效识别股票对之间的短期偏离程度,不直接给出买卖指令,而是提供客观的偏离信号和信号强度,帮助用户判断均值回归机会,降低主观情绪干扰;同时,滚动窗口机制使本方法能自适应市场变化,保持回归关系的时效性,从而提升均值回归风险分析的准确性、稳定性和实用性。
Smart Images

Figure CN122928503A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of stock risk analysis, and more specifically, to a stock risk analysis method based on mean regression. Background Technology
[0002] Mean reversion is a classic theory in financial analysis, which posits that stock prices or price differences between asset pairs tend to revert to their mean after deviating from long-term equilibrium. In stock risk analysis and pair trading strategies, establishing a linear regression relationship between two assets and utilizing the degree of deviation in residuals or price differences to capture potential regression opportunities is a common technical approach.
[0003] Several mean regression identification methods based on regression analysis already exist in existing technologies. For example, ordinary least squares (OLS) regression with a fixed time window generates signals by calculating residuals or price differences and setting a fixed threshold. However, these methods have significant drawbacks. First, the fixed window cannot dynamically adjust the regression coefficients according to changes in the market environment. When the correlation between stock pairs undergoes structural changes, the regression relationship based on historical data may become invalid, leading to deviations and misjudgments. Second, most methods only output absolute residuals or simple price differences without standardizing the deviation values (e.g., converting them to Z-scores), making the degree of deviation incomparable across different periods or stock pairs, and making it difficult for users to set a unified judgment standard. Third, some existing technologies directly output buy and sell orders, ignoring the principle that the analysis model and transaction execution should be decoupled. This not only increases the system coupling but also easily induces users to ignore the probabilistic attributes of the model itself, resulting in emotional trading decisions.
[0004] To address the aforementioned issues, some improvement schemes attempt to introduce rolling window mechanisms or standardized processing methods, but these are often limited to a single time scale and still lack objective quantification of signal strength and structured result output. Furthermore, existing methods do not strictly regulate data synchronization and minimum sample size constraints, making it easy for regression parameters to become unreliable due to data quality or insufficient samples.
[0005] Therefore, this invention provides a stock risk analysis method based on mean regression. Through rolling OLS regression, calculation of standardized residual deviation, and signal strength quantification, it outputs a structured result package containing key information such as standardized deviation, threshold, and signal strength for users to refer to and make decisions. This stock risk analysis method can dynamically adapt to market changes, provide objectively comparable deviation signals, and does not directly generate trading orders, thereby effectively improving the accuracy, stability, and practicality of mean regression risk analysis. Summary of the Invention
[0006] The technical problem this invention aims to solve is how to effectively improve the accuracy, stability, and practicality of mean reversion risk analysis. To overcome the shortcomings of the existing technology (or related technology), this invention provides a stock risk analysis method based on mean reversion.
[0007] This invention provides a stock risk analysis method based on mean regression, comprising the following steps: Step S1: Obtain the synchronous prices of the first stock and the second stock over multiple periods. The synchronous prices are determined according to a preset calculation price type and the original price or natural logarithmic price is selected for model price exchange to obtain the independent variable sequence of the first stock and the predictive variable sequence of the second stock. Step S2: Using the current period as the end point, construct a rolling window by taking multiple valid samples with the same number of OLS backtracking periods, and establish a univariate linear regression equation for the independent variable sequence and the predictor variable sequence within the rolling window, and estimate the regression coefficients and intercepts using the least squares method. Step S3: Substitute the independent variables of the first type of stock in different periods into the univariate linear regression equation to obtain the predicted value of the second type of stock, and obtain the residual value sequence based on the predicted value and the predicted variable of the corresponding period. Step S4: Calculate the mean and standard deviation of the residual value sequence within the corresponding calculation window according to the preset standardized calculation period, and calculate the standardized deviation value of the current period based on the mean and the standard deviation. Step S5: Calculate the signal strength based on the standardized deviation value, the preset upper bound of the basic threshold, and the lower bound of the basic threshold, and output a structured result package containing the standardized deviation value, the upper bound of the basic threshold, the lower bound of the basic threshold, the signal strength, the regression coefficient, the intercept, and the residual value for user reference.
[0008] Compared with existing technologies, the stock risk analysis method based on mean regression proposed in this invention has the following advantages: This invention effectively identifies the short-term deviation between stock pairs by acquiring the synchronous prices of two stocks, establishing a univariate linear regression equation within a rolling window, calculating the standardized deviation of the residual value sequence, and outputting a structured result package. Instead of directly issuing buy or sell orders, it provides objective deviation signals and signal strengths to help users judge mean reversion opportunities and reduce subjective emotional interference. At the same time, the rolling window mechanism enables this method to adapt to market changes and maintain the timeliness of the regression relationship, thereby improving the accuracy, stability, and practicality of mean reversion risk analysis.
[0009] In one possible implementation, in step S2, only the period in which both the first type of stock and the second type of stock have valid prices at the same timestamp is retained as the valid sample, and the scrolling window contains at least the valid samples that meet the preset minimum sample number.
[0010] Compared with existing technologies, the above technical solution can eliminate invalid samples caused by missing data or mismatched timestamps, ensure that the data used for regression calculation is strictly consistent in time, avoid spurious regression or erroneous residuals caused by asynchronous data, and improve the reliability of least squares calculation. At the same time, the minimum sample size constraint prevents unreliable parameter estimation caused by too few samples in the rolling window, and enhances robustness under sparse data conditions.
[0011] In one possible implementation, step S3 further includes performing a moving smoothing process on the predicted value using the following calculation formula: in, This represents the moving average of the predicted values; This indicates that a moving average calculation is being performed. This represents the predicted value; The moving average period represents the predicted value.
[0012] In one possible implementation, step S4 involves introducing a dynamic standard deviation before calculating the standardized deviation, including the following steps: Step A1: Calculate the deviation of the residual value of the current period from the residual mean, and calculate the rolling standard deviation, EWMA standard deviation and GRACH standard deviation based on the deviation, the residual mean, EWMA variance, EWMA decay factor and GRACH variance. Step A2: Calculate the dynamic standard deviation based on the rolling standard deviation, the EWMA standard deviation, and the GRACH standard deviation, and calculate the dynamic standardized deviation based on the dynamic standard deviation and the residual value of the current period; Step A3: Replace the standardized deviation value with the dynamic standardized deviation value.
[0013] Compared with existing technologies, the above-mentioned technical solution can combine three volatility parameters: rolling standard deviation, EWMA standard deviation, and GARCH standard deviation. By utilizing dynamic standard deviation, it can more sensitively capture changes in the current volatility environment, making the standardization of deviation values more reasonable. This reduces false signals and missed signals when volatility changes drastically, and improves adaptability under different market conditions.
[0014] In one possible implementation, in step A1, the rolling standard deviation, the EWMA standard deviation, and the GRACH standard deviation are obtained using the following formulas: in, This represents the rolling standard deviation; Indicates the selected first number within the calculation window Group residuals; This represents the mean of the residuals; This indicates the number of valid residual values within the calculation window; This represents the standard deviation of the EWMA; express The EWMA variance at time t; This represents the EWMA attenuation factor; express The EWMA variance at time t; express The deviation at any given time; This represents the GRACH standard deviation; express The GARCH variance at time t; This represents the long-term volatility benchmark coefficient; This represents the residual impact weighting coefficient from the previous period; express The deviation at any given time; This indicates the weighting of the fluctuations from the previous period. express The GARCH variance at time t.
[0015] Compared with existing technologies, the above-mentioned technical solution can integrate the classical volatility modeling method with the rolling window method to form a composite volatility index. The EWMA standard deviation reacts quickly to recent shocks, the GARCH standard deviation can characterize the persistence of volatility, and the rolling window provides a benchmark scale. The weighted average of the three retains the reference for long-term volatility levels and can respond to sudden fluctuations in a timely manner, making the denominator of the standardized deviation value more robust and sensitive, thereby more accurately judging whether the price spread deviation is truly beyond the reasonable range.
[0016] In one possible implementation, step S5, before calculating the signal strength, further includes: The fluctuation adjustment factor is calculated based on the ratio of the dynamic standard deviation to the normal fluctuation power benchmark coefficient. The dynamic upper threshold and dynamic lower threshold are obtained based on the fluctuation adjustment factor and the base threshold multiple, respectively. The upper limit of the base threshold is replaced with the dynamic upper threshold, and the lower limit of the base threshold is replaced with the dynamic lower threshold.
[0017] Compared with existing technologies, the above-mentioned technical solution can reduce noise interference by appropriately relaxing the dynamic upper and lower thresholds during high volatility and appropriately tightening the dynamic upper and lower thresholds during low volatility to improve sensitivity, thereby maintaining a constant false alarm rate and making the signal strength output more in line with the current market risk level, thus improving practicality and robustness.
[0018] In one possible implementation, after performing step S5, a three-layer window merging process is further included, which includes the following steps: Step B1: Repeat steps S1 to S5 for the strategic layer window, tactical layer window, and execution layer window respectively to obtain the corresponding first standardized deviation value, second standardized deviation value, and third standardized deviation value. Step B2: Calculate the integrated signal score after three-layer fusion based on the first standardized deviation value, the strategic layer weight corresponding to the strategic layer window, the second standardized deviation value, the tactical layer weight corresponding to the tactical layer window, the third standardized deviation value, and the execution layer weight corresponding to the execution layer window. Step B3: Based on the dynamic standardized deviation value, the dynamic upper threshold, the dynamic lower threshold, and the comprehensive signal pair, determine the direction and output the corresponding direction confirmation signal.
[0019] Compared with existing technologies, the above-mentioned technical solution can capture mean regression characteristics of different frequencies by using windows of different time scales. The strategic layer window reflects the long-term equilibrium relationship, the tactical layer window captures the medium-term deviation, and the execution layer window identifies short-term trading opportunities. By weighted fusion, a comprehensive signal score is obtained, and the direction is determined by combining the dynamic standardized deviation value. This can effectively filter out false signals that may appear in a single window, improve the synergy and reliability of the direction confirmation signal, and enable users to obtain more robust multi-timeframe confirmation results.
[0020] In one possible implementation, in step B3, if the dynamic standardized deviation value is not less than the dynamic upper threshold and the composite signal score is greater than zero, then an upper deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is not greater than the dynamic lower threshold and the composite signal score is less than zero, then a lower deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is between the dynamic upper threshold and the dynamic lower threshold, then an observation signal is output as the direction confirmation signal.
[0021] Compared with existing technologies, the above technical solution enables the output of a clear upward or downward confirmation signal only when the dynamic standardized deviation value reaches the dynamic threshold and the overall signal direction is consistent; otherwise, an observation signal is output. This dual confirmation mechanism significantly reduces false prompts caused by misjudgment of a single-layer window or abnormal fluctuations, making the output direction confirmation signal more reliable. This helps users reduce unnecessary trading decisions in risk analysis and improve the profit-loss ratio of the strategy.
[0022] In one possible implementation, the structured result package output in step S5 further includes an auxiliary price difference, which is equal to the predictor variable of the second stock minus the regression coefficient and multiplied by the independent variable of the first stock, and the residual value is equal to the auxiliary price difference plus the intercept.
[0023] Compared with existing technologies, the above technical solution can intuitively display the degree of deviation of the second stock price from the regression slope through auxiliary price difference, making it easier for users to quickly understand the current price difference size; at the same time, since the residual value includes intercept correction, the coexistence of the two can provide users with deviation information from different dimensions, enhance the interpretability and flexibility of the structured result package, and meet the needs of different analysis habits.
[0024] In one possible implementation, the price type calculated in step S1 is selected from one of the following: closing price, opening price, highest price, lowest price, the average of the highest price and the lowest price, the average of the opening price and the closing price, the average of the highest price, the lowest price, and the closing price, twice the average of the highest price, the lowest price, and the closing price, and six times the average of the opening price, the highest price, the lowest price, and the closing price.
[0025] Compared with existing technologies, the above technical solution takes into account that different users or different market environments may affect the stability of regression residuals by selecting different calculation price types. By providing a variety of price construction options, users can flexibly select the most suitable calculation price according to data characteristics, thereby improving the universality and customization capabilities of mean regression analysis. Attached Figure Description
[0026] Figure 1 This is a flowchart of the steps of the present invention; Figure 2 This is a flowchart illustrating the dynamic standardized deviation calculation process of the present invention. Figure 3 This is a flowchart illustrating the specific process of the three-layer window fusion method of the present invention. Detailed Implementation
[0027] First, those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention. Those skilled in the art can make adjustments as needed to adapt to specific application scenarios.
[0028] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0029] See Figure 1 This invention discloses a stock risk analysis method based on mean regression, comprising: Step S1: Obtain the synchronous prices of the first stock and the second stock over multiple periods. The synchronous prices are determined according to the preset calculation price type and the original price or natural logarithmic price is selected for model price exchange to obtain the independent variable sequence of the first stock and the predictive variable sequence of the second stock. Step S2: Using the current period as the endpoint, construct a rolling window by taking multiple valid samples with the same number of OLS backtracking periods, and establish a univariate linear regression equation for the independent variable sequence and the predictor variable sequence within the rolling window, and estimate the regression coefficients and intercepts using the least squares method. Step S3: Substitute the independent variables of the first type of stock in different periods into the univariate linear regression equation to obtain the predicted value of the second type of stock, and obtain the residual value sequence based on the predicted value and the predicted variable of the corresponding period. Step S4: Calculate the mean and standard deviation of the residual value sequence within the corresponding calculation window according to the preset standardized calculation period, and calculate the standardized deviation value of the current period based on the mean and standard deviation. Step S5: Calculate the signal strength based on the standardized deviation, the preset upper bound of the basic threshold, and the lower bound of the basic threshold, and output a structured result package containing the standardized deviation, the upper bound of the basic threshold, the lower bound of the basic threshold, the signal strength, the regression coefficient, the intercept, and the residual value for user reference.
[0030] In this embodiment of the invention, in step S1, the synchronous price needs to be selected according to the calculated price type in practical applications. This calculated price type can be selected from closing price, opening price, highest price, lowest price, the average of the highest and lowest prices (HL / 2), the average of the opening and closing prices (OC / 2), the average of the highest, lowest, and closing prices (HLC / 3), twice the average of the highest, lowest, and closing prices (HLCC / 4), and six times the average of the opening, highest, lowest, and closing prices (OHLCCC / 6). After selecting the calculated price type, it is also necessary to determine whether to perform a natural logarithmic transformation: if the original price model is selected, then the above calculated price type is directly used as the sequence of independent variables. and predictor variable sequence If the natural logarithm pricing model is selected, the natural logarithm of the calculated price type is taken first: ,in, Indicates the first type of stock. The second type of stock is used as the regression input. Once the transformation method is determined, it remains unchanged throughout the analysis process. In addition, the OLS backtracking period needs to be set in advance (e.g., an integer between 20 and 60) to determine the length of the subsequent rolling window.
[0031] In this embodiment of the invention, during step S2, when constructing the rolling window, the current period t should be taken as the endpoint, and the most recent n valid periods should be taken in the historical direction to form the rolling window. , where n is the OLS backtracking period. To ensure the reliability of the regression parameters, the rolling window must contain a sufficient number of valid samples. Specifically, if strict price-time alignment is enabled, only periods in which both the first and second stocks have valid prices at the same timestamp (i.e., no missing, no anomalies, and exact time matching) are retained as valid samples. If strict alignment is not enabled, the two stocks are allowed to match within their respective valid periods, but the correspondence of timestamps must still be guaranteed. At the same time, a minimum sample size is preset (e.g., 80% of n). If the number of valid samples in the rolling window is lower than this minimum sample size, the regression cannot be performed in this round, and an abnormal data status should be output with an explanation of the reason, and the process should wait for the next period to try again.
[0032] In this embodiment of the invention, in step S2, a window is created within the scrolling window. The univariate linear regression equation is used to minimize the sum of squared prediction errors within the rolling window using the least squares method: Therefore, the regression coefficients are calculated. and intercept : in, , , , These represent all within the scrolling window. and, all and and Sum of products The sum of squares This indicates the number of valid cycles within the scrolling window.
[0033] In this embodiment of the invention, in step S3, the independent variable of the current period is... Substituting into the univariate linear regression equation, we obtain the predicted value of the second type of stock. : The residual value of the current period Defined as: After the predicted value is calculated, the predicted value sequence can be further processed by moving average smoothing. The moving average period m can be set as needed (e.g., 5 or 10). The smoothed moving average is only used to assist in displaying or observing the changing trend of the regression line and does not participate in the calculation of subsequent residual values and signal strength, so as to avoid the lag effect interfering with the real-time deviation judgment. The formula for calculating the residual value sequence is: current residual value = actual predicted variable of the current second stock - current predicted value. This residual value sequence will serve as the basis for subsequent standardization processing.
[0034] In this embodiment of the invention, in step S3, the predicted value is subjected to moving smoothing processing using the following calculation formula: in, This represents the moving average of the predicted values; This indicates that a moving average calculation is being performed. Indicates the predicted value; This indicates the moving average period for the predicted value.
[0035] See Figure 2 In this embodiment of the invention, before calculating the standardized deviation value in step S4, a dynamic standard deviation is introduced for processing, including the following steps: Step A1: Calculate the deviation of the residual value of the current period from the residual mean, and calculate the rolling standard deviation, EWMA standard deviation and GRACH standard deviation based on the deviation, residual mean, EWMA variance, EWMA decay factor and GARCH variance. Step A2: Calculate the dynamic standard deviation based on the rolling standard deviation, EWMA standard deviation, and GRACH standard deviation, and calculate the dynamic standardized deviation based on the dynamic standard deviation and the residual value of the current period. Step A3: Replace the standardized deviation with the dynamic standardized deviation.
[0036] In this embodiment of the invention, during step S4, a preset standardized calculation period is used. Calculate the mean of the residual sequence within the corresponding calculation window. and standard deviation : Standardized deviation for the current period If the standard deviation If the value is too small, it is considered an abnormal state.
[0037] In this embodiment of the invention, in step A1, the rolling standard deviation, EWMA standard deviation, and GRACH standard deviation are obtained using the following calculation formulas: in, Indicates the rolling standard deviation; Indicates the selected number within the calculation window Group residuals; This represents the mean of the residuals; This indicates the number of valid residual values within the calculation window; Indicates the standard deviation of EWMA; express EWMA variance at time t; Indicates the EWMA attenuation factor; express EWMA variance at time t; express Deviation in time; Indicates the GRACH standard deviation; express GARCH variance at time step; This represents the long-term volatility benchmark coefficient; This represents the residual impact weighting coefficient from the previous period; express Deviation in time; This indicates the weighting of the fluctuations from the previous period. express GARCH variance at time step.
[0038] In this embodiment of the invention, in step A2, the dynamic standard deviation is calculated. If a certain item cannot be calculated, only the effective items are used to calculate the average, and the dynamic standardized deviation is calculated. .
[0039] In this embodiment of the invention, in step S5, a preset base threshold multiple is set. upper bound of the basic threshold Basic threshold lower bound Before calculating the signal strength, it also includes calculations based on the dynamic standard deviation. Compared with the normal fluctuation power benchmark coefficient ratio The volatility adjustment factor was calculated. And adjust according to volatility factor and base threshold multiple The dynamic upper threshold and dynamic lower threshold are obtained respectively. The basic threshold upper bound is replaced with the dynamic upper threshold, and the basic threshold lower bound is replaced with the dynamic lower threshold. Where, if ,but ,like ,but Dynamic upper threshold Dynamic threshold When adaptive thresholding is enabled, the upper and lower bounds of the base threshold are replaced with dynamic upper and lower thresholds.
[0040] See Figure 3 In this embodiment of the invention, after step S5, a three-layer window merging process is further included, which includes the following steps: Step B1: Repeat steps S1 to S5 for the strategic layer window, tactical layer window, and execution layer window respectively to obtain the corresponding first standardized deviation value, second standardized deviation value, and third standardized deviation value. Step B2: Calculate the integrated signal score after three-layer fusion based on the first standardized deviation value, the strategic layer weight corresponding to the strategic layer window, the second standardized deviation value, the tactical layer weight corresponding to the tactical layer window, the third standardized deviation value, and the execution layer weight corresponding to the execution layer window. Step B3: Based on the dynamic standardized deviation value, dynamic upper threshold, dynamic lower threshold, and comprehensive signal pair, determine the direction and output the corresponding direction confirmation signal.
[0041] In this embodiment of the invention, in step B3, if the dynamic standardized deviation value is not less than the dynamic upper threshold and the comprehensive signal score is greater than zero, then the upper deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is not greater than the dynamic lower threshold and the comprehensive signal score is less than zero, then the lower deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is between the dynamic upper threshold and the dynamic lower threshold, then the observation signal is output as the direction confirmation signal.
[0042] In this embodiment of the invention, the first standardized deviation value, the second standardized deviation value, and the third standardized deviation value are obtained in step B1 using the following calculation formulas: in, Indicates the first standardized deviation value. This represents the second standardized deviation. This represents the third standardized deviation. This represents the sequence of residual values from the strategy layer window. This represents the sequence of residual values from the tactical layer window. This represents the sequence of residual values from the execution layer window. This represents the mean value from the strategic layer window. This represents the mean value from the tactical layer window. This represents the mean value from the execution layer window. This represents the standard deviation from the strategic layer window. This represents the standard deviation from the tactical layer window. This represents the standard deviation from the execution layer window.
[0043] In this embodiment of the invention, the three-layer window fusion process also includes directional consistency judgment: if the number of layers in the same direction is not less than the preset number of layers to be confirmed r (usually 2 or 3), then the consistency flag C=1, otherwise C=0.
[0044] In this embodiment of the invention, the comprehensive signal score is obtained in step B2 using the following calculation formula: in, Indicates the integrated signal component, Indicates the strategic layer weight. Indicates the tactical layer weights. This indicates the execution layer weight.
[0045] In this embodiment of the invention, the structured result package output in step S5 also includes auxiliary price differences. The auxiliary price difference is equal to the predictor variable of the second stock minus the regression coefficient, multiplied by the independent variable of the first stock. The residual value is equal to the auxiliary price difference plus the intercept.
[0046] In this embodiment of the invention, the signal strength is calculated in step S5. in This indicates that the signal strength is limited to the interval [-1, 1]. If dynamic standardized deviation is used, the signal strength is calculated accordingly. If a three-layer window fusion process is further applied, the signal strength can be calculated. .
[0047] In the description of this invention, the references to "one embodiment," "some embodiments," "in this embodiment," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0048] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A stock risk analysis method based on mean reversion, characterized in that, Includes the following steps: Step S1: Obtain the synchronous prices of the first stock and the second stock over multiple periods. The synchronous prices are determined according to a preset calculation price type and the original price or natural logarithmic price is selected for model price exchange to obtain the independent variable sequence of the first stock and the predictive variable sequence of the second stock. Step S2: Using the current period as the end point, construct a rolling window by taking multiple valid samples with the same number of OLS backtracking periods, and establish a univariate linear regression equation for the independent variable sequence and the predictor variable sequence within the rolling window, and estimate the regression coefficients and intercepts using the least squares method. Step S3: Substitute the independent variables of the first type of stock in different periods into the univariate linear regression equation to obtain the predicted value of the second type of stock, and obtain the residual value sequence based on the predicted value and the predicted variable of the corresponding period. Step S4: Calculate the mean and standard deviation of the residual value sequence within the corresponding calculation window according to the preset standardized calculation period, and calculate the standardized deviation value of the current period based on the mean and the standard deviation. Step S5: Calculate the signal strength based on the standardized deviation value, the preset upper bound of the basic threshold, and the lower bound of the basic threshold, and output a structured result package containing the standardized deviation value, the upper bound of the basic threshold, the lower bound of the basic threshold, the signal strength, the regression coefficient, the intercept, and the residual value for user reference.
2. The stock risk analysis method according to claim 1, characterized in that, In step S2, only the period in which both the first type of stock and the second type of stock have valid prices at the same timestamp is retained as the valid sample, and the scrolling window contains at least the valid samples that meet the preset minimum sample number.
3. The stock risk analysis method according to claim 1, characterized in that, Step S3 further includes performing a moving smoothing process on the predicted value using the following calculation formula: in, This represents the moving average of the predicted values; This indicates that a moving average calculation is being performed. This represents the predicted value; The moving average period represents the predicted value.
4. The stock risk analysis method according to claim 1, characterized in that, In step S4, before calculating the standardized deviation value, a dynamic standard deviation is introduced for processing, including the following steps: Step A1: Calculate the deviation of the residual value of the current period from the residual mean, and calculate the rolling standard deviation, EWMA standard deviation and GRACH standard deviation based on the deviation, the residual mean, EWMA variance, EWMA decay factor and GRACH variance. Step A2: Calculate the dynamic standard deviation based on the rolling standard deviation, the EWMA standard deviation, and the GRACH standard deviation, and calculate the dynamic standardized deviation based on the dynamic standard deviation and the residual value of the current period; Step A3: Replace the standardized deviation value with the dynamic standardized deviation value.
5. The stock risk analysis method according to claim 1, characterized in that, In step A1, the rolling standard deviation, the EWMA standard deviation, and the GRACH standard deviation are obtained using the following formulas: in, This represents the rolling standard deviation; Indicates the selected first number within the calculation window Group residuals; This represents the mean of the residuals; This indicates the number of valid residual values within the calculation window; This represents the standard deviation of the EWMA; express The EWMA variance at time t; This represents the EWMA attenuation factor; express The EWMA variance at time t; express The deviation at any given time; This represents the GRACH standard deviation; express The GARCH variance at time t; This represents the long-term volatility benchmark coefficient; This represents the residual impact weighting coefficient from the previous period; express The deviation at any given time; This indicates the weighting of the fluctuations from the previous period. express The GARCH variance at time t.
6. The stock risk analysis method according to claim 4, characterized in that, In step S5, before calculating the signal strength, the following steps are also included: The fluctuation adjustment factor is calculated based on the ratio of the dynamic standard deviation to the normal fluctuation power benchmark coefficient. The dynamic upper threshold and dynamic lower threshold are obtained based on the fluctuation adjustment factor and the base threshold multiple, respectively. The upper limit of the base threshold is replaced with the dynamic upper threshold, and the lower limit of the base threshold is replaced with the dynamic lower threshold.
7. The stock risk analysis method according to claim 6, characterized in that, After performing step S5, a three-layer window merging process is further included, which includes the following steps: Step B1: Repeat steps S1 to S5 for the strategic layer window, tactical layer window, and execution layer window respectively to obtain the corresponding first standardized deviation value, second standardized deviation value, and third standardized deviation value. Step B2: Calculate the integrated signal score after three-layer fusion based on the first standardized deviation value, the strategic layer weight corresponding to the strategic layer window, the second standardized deviation value, the tactical layer weight corresponding to the tactical layer window, the third standardized deviation value, and the execution layer weight corresponding to the execution layer window. Step B3: Based on the dynamic standardized deviation value, the dynamic upper threshold, the dynamic lower threshold, and the comprehensive signal pair, determine the direction and output the corresponding direction confirmation signal.
8. The stock risk analysis method according to claim 7, characterized in that, In step B3, if the dynamic standardized deviation value is not less than the dynamic upper threshold and the comprehensive signal score is greater than zero, then an upper deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is not greater than the dynamic lower threshold and the comprehensive signal score is less than zero, then a lower deviation confirmation signal is output as the direction confirmation signal; if the dynamic standardized deviation value is between the dynamic upper threshold and the dynamic lower threshold, then an observation signal is output as the direction confirmation signal.
9. The stock risk analysis method according to claim 1, characterized in that, The structured result package output in step S5 also includes an auxiliary price difference, which is equal to the predictor variable of the second stock minus the regression coefficient and multiplied by the independent variable of the first stock. The residual value is equal to the auxiliary price difference plus the intercept.
10. The stock risk analysis method according to claim 1, characterized in that, The price type calculated in step S1 is selected from one of the following: closing price, opening price, highest price, lowest price, average of the highest price and the lowest price, average of the opening price and the closing price, average of the highest price, the lowest price, and the closing price, twice the average of the highest price, the lowest price, and the closing price, and six times the average of the opening price, the highest price, the lowest price, and the closing price.