Analysis method and system for predicting stock trend based on fund flow data

Through machine learning models combining historical funds and price data, predict stock trends and formulate trading strategies, the complexity and objectivity of stock trend prediction in the existing technology are solved, and stable stock price prediction and excess returns are achieved.

CN118941387APending Publication Date: 2024-11-12NANTONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410995231.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively predict stock trends. It is affected by the complexity of macro and micro factors, and the lack of objective analytical indicators, making it difficult to widely apply trading rules.

Method used

Using machine learning methods, we establish a prediction model with the average return in the future as the dependent variable, historical capital inflow data, historical price data and historical trading volume data as independent variables, through different models (random forest, K nearest neighbor, LSTM and depth Learn) Predict stock trends and formulate trading strategies based on the prediction results.

Benefits of technology

By introducing historical funding data, a robust stock price prediction model is established, quantitative trading strategies are provided, excess returns are achieved, and stock classification and diagnosis are carried out through a systematic and modular process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118941387A_ABST
    Figure CN118941387A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data analysis, in particular to an analysis method and system for predicting stock trend based on fund flow data, and the method specifically comprises the steps: S1, carrying out the stock back-test through historical data, and calculating the excess incomes of different models; s2, predicting earnings through different models according to the real-time data; s3, stock classification is carried out according to the predicted income in S2 and the excess income in S1; the invention further discloses an analysis system for predicting the stock trend based on the fund flow direction data. The analysis system specifically comprises an individual stock back-testing module, a batch back-testing module, a stock diagnosis module and a classification module. According to the method and the system disclosed by the invention, the fund flow direction is stronger in continuity relative to the trend, so that the prediction of the stock price trend is more stable; and on the basis, a quantitative transaction strategy is established, so that the excess income is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data analysis, and in particular to an analysis method and system for predicting stock trends based on capital flow data. Background Art

[0002] Stock price trends are affected by many factors. There are macro factors, such as the current international situation, the current economic trend, whether the industry is booming, etc.; there are micro factors, such as trend characteristics, stock popularity, etc. However, these factors are subjective and difficult to quantify. At the same time, different stocks are affected differently by the above characteristics according to their industries, scales, and trends. Therefore, it is difficult to have a universal trading rule.

[0003] In comparison, the total amount of capital inflow and the proportion of capital inflow are relatively objective indicators. Because in theory, when the proportion of capital inflow exceeds a certain proportion, it represents the strength of the buyer. It means that the market is optimistic about the target. And the establishment of this view often has a certain degree of sustainability. Therefore, in theory, capital flow is a reliable analytical indicator.

[0004] Therefore, it is of great significance to develop an analysis system to predict stock trends based on capital flow data. Summary of the invention

[0005] Purpose of the invention: The technical problem to be solved by the present invention is to provide a method of using machine learning to establish a prediction model with the average return in the future as the dependent variable and the historical capital inflow data, historical price data and historical trading volume data as the independent variables in view of the deficiencies in the prior art.

[0006] In order to solve the above technical problems, the present invention discloses an analysis method for predicting stock trends based on capital flow data, the method comprising the following steps:

[0007] S1. Calculate the excess returns of different models using historical data and stock backtesting;

[0008] S2. Predict revenue through different models based on real-time data;

[0009] S3. Classify stocks based on the predicted returns in S2 and the excess returns in S1.

[0010] Among them, in S1, the specific steps of stock backtesting are:

[0011] S11. Obtain market data and capital data;

[0012] S12. Clean and merge the data, calculate the k-day moving average data and k-day rate of return;

[0013] S13. Predict the average return rate in the next k days

[0014] S14. Establish stock trading strategies;

[0015] S15. Perform backtesting based on the trading strategy in S14 and calculate the profit;

[0016] S16. Compare the returns obtained from the backtest of S15 with the actual stock performance and calculate the excess returns.

[0017] Among them, in S11, before obtaining the data, it is determined whether the target stock data is obtained for the first time. If so, all historical market data and historical capital data of the target stock are obtained; if not, the updated market data and capital data of the target stock are obtained and merged with the historical data.

[0018] Among them, in S13, the capital data and moving average data are used as independent variables, and the k-day yield is used as the supervisory variable to use the machine learning model to predict the average yield of the next k days Among them, the machine learning models are random forest, K nearest neighbor, LSTM and deep learning models.

[0019] Among them, in said S14, the specific trading strategy is: set different thresholds δ, when Execute a buy operation when , execute the sell operation.

[0020] The present invention also provides an analysis system for predicting stock trends based on capital flow data, the system comprising:

[0021] Individual stock backtesting module, used to collect data and calculate returns for a single target stock;

[0022] Batch backtesting module, used to calculate the threshold and maximum excess return of multiple stocks under different forecasting models;

[0023] The stock diagnosis module is used to predict expected returns using different forecasting models based on real-time data and compare them with the excess returns obtained by the batch backtesting module;

[0024] Classification scenario, used for classification after the diagnosis of the stock diagnosis module is completed.

[0025] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the analysis method for predicting stock trends based on capital flow data of the present invention are implemented.

[0026] The present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the analysis method for predicting stock trends based on capital flow data of the present invention are implemented.

[0027] Beneficial effects: The present invention provides an analysis method and system for predicting stock price trends based on capital flow data. By introducing historical capital data, a stock price prediction model based on machine learning is established. Since capital flow is more continuous than the trend, the prediction of stock price trends is more robust. On this basis, a quantitative trading strategy is established to obtain excess returns. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments, and the above and / or other advantages of the present invention will become more clear.

[0029] Figure 1 This is a flow chart of the individual stock backtesting module in Embodiment 1 of the present invention;

[0030] Figure 2 This is a flow chart of the batch backtesting module in Embodiment 2 of the present invention;

[0031] Figure 3 This is a flow chart of the stock diagnosis module in Example 3 of the present invention. DETAILED DESCRIPTION

[0032] In order to better understand the technical solution of the present invention, the present invention will be further described in detail below in conjunction with specific embodiments. The embodiments described below are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0033] Example 1: Individual Stock Backtesting Module

[0034] The present invention discloses an analysis method for predicting stock trends based on capital flow data, which specifically includes:

[0035] S1. Calculate the excess returns of different models through stock backtesting;

[0036] S2. Predict revenue through different models based on real-time data;

[0037] S3. Classify stocks based on the predicted returns of S2 and the excess returns of the corresponding models in S1.

[0038] The individual stock backtesting module is implemented through the following steps: (1) obtaining market data and capital data; (2) cleaning data and calculating average price data, average trading volume, average capital inflow and average inflow ratio; (3) establishing a machine learning model and calculating the expected historical rate of return based on the model; (4) formulating a trading strategy based on the predicted rate of return and calculating the rate of return of the strategy and statistical indicators such as the Sharpe ratio based on actual data.

[0039] Taking a stock with the stock code 00000X as an example, the specific implementation steps are as follows:

[0040] 1. Specify the storage location of market data File1, such as "D:\Funds\Market Data\"; the storage location of fund data File2, such as "D:\Funds\Fund Data\"; the log file of strategy backtesting File3, such as "D:\Funds\Backtesting Results.csv";

[0041] 2. Specify the file name format for storing fund data, for example, name it after the stock code, the current example is "00000X.csv";

[0042] 3. Run the data acquisition system. Use os.path.exists to determine whether the file "00000X.csv" exists in File2;

[0043] If "00000X.csv" does not exist, run data acquisition subsystem 1, that is, use selenium, request library to crawl the capital data of the current stock code; if "00000X.csv" exists, run data acquisition subsystem 2, that is, read "00000X.csv" and obtain the capital data from the last date to the current date, and merge it with the historical capital data;

[0044] 4. Read the market data and merge it with the capital data. The length of the merged data file is n;

[0045] 5. Fixed parameter k = 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 20, 60. For any j∈[1, n], when j1∈[k, n], calculate the moving average data of the k days before the j1th day (including the moving average of the closing price, the moving average of the total amount of capital inflow and the moving average of the capital inflow ratio); when j2∈[1, nk], calculate the rate of return of the k days after the j2th day;

[0046] 6. Fixed historical information data N = 200. For any given parameter k and i = N, ..., nk, the yield of the next k days is the supervisory variable, the moving average data (including the market moving average and the capital moving average) is used as the independent variable, and the historical data from iN to the i-1th row is used as the sample data. A variety of machine learning models, including random forest, K nearest neighbor, LSTM, and deep learning are used to predict the average yield of the next k days based on the data of the previous N days. The predicted value is related to the historical information length N, the short-term moving average data parameters, the later prediction length k, and the prediction method;

[0047] 7. For a fixed historical information length N, moving average and return time parameter k, and a specific prediction method, this embodiment can obtain a set of prediction values For thresholds δ = 0, 0.5, 1, 2, 3, establish strategies respectively. When When , sell; Thus, for this set of predicted values, due to the difference of δ, this embodiment can obtain multiple strategies;

[0048] 8. Use the backtrader package to perform backtesting and calculate the absolute return and average return of the strategy;

[0049] 9. Compare the performance of the stock with that of the same period and calculate the excess return of the strategy;

[0050] 10. Append the stock code, the statistical machine learning method used, the historical information length N, the moving average parameter k, the threshold δ, the absolute return, the average return and the excess return and other indicators to File3, and mark the code as the key variable.

[0051] Example 2: Batch backtesting module

[0052] For a given threshold delta, this embodiment counts the effectiveness of each machine learning prediction effect;

[0053] 1. Traverse the stock codes and obtain the transaction records of each stock code under different parameters (N, k, δ and prediction method) in Example 1;

[0054] 2. For the same prediction method, calculate the absolute returns and excess returns of the trading strategies under different thresholds;

[0055] 3. For each prediction method, select the threshold with the maximum excess return, denoted as δ best ;

[0056] 4. For each stock, summarize the prediction methods and find the value of the prediction method at the threshold δ bestThe excess return rate at that time is saved as a local file File4, for example, "D:\Funds\Backtest Result Statistics.csv;

[0057] 5. Summarize using statistical methods and evaluate the predictive value of different forecasting methods in transactions.

[0058] Example 3: Femoral Diagnosis Module

[0059] Still taking a stock with the stock code 00000X as an example, the specific implementation steps are as follows:

[0060] 1. As described in Example 1, before the market opens on the day, update the data file and use the specified multiple machine learning methods to predict the expected returns δ for the next k days. C ;

[0061] 2. For any statistical method, calculate the excess return of the method in historical simulated transactions. If the excess return is greater than 0, trade according to the signal, that is, δ c >δ best , then buy; δ c <δ best , then sell; otherwise, do not trade;

[0062] 3. Repeat the above steps for all statistical methods and use voting method to derive trading strategy.

[0063] Example 4: Classification module

[0064] 1. For each stock, use the method in Example 3 to select a trading direction;

[0065] 2. Select stocks with a trading direction of "buy" to enter the candidate buy position; select stocks with a trading direction of "sell" to enter the candidate sell position.

[0066] Embodiment 5: Computer readable storage medium

[0067] The computer-readable storage medium of this embodiment stores a computer program thereon, which, when executed by a processor, implements the steps in the analysis method for predicting stock trends based on capital flow data of Example 1.

[0068] The computer-readable storage medium of this embodiment may be an internal storage unit of the terminal, such as a hard disk or memory of the terminal; the computer-readable storage medium of this embodiment may also be an external storage device of the terminal, such as a plug-in hard disk, a smart memory card, a secure digital card, a flash memory card, etc. equipped on the terminal; further, the computer-readable storage medium may also include both an internal storage unit of the terminal and an external storage device.

[0069] The computer-readable storage medium of this embodiment is used to store computer programs and other programs and data required by the terminal. The computer-readable storage medium can also be used to temporarily store data that has been output or is to be output.

[0070] Example 6: Computer equipment

[0071] The computer device of this embodiment includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the analysis method for predicting stock trends based on capital flow data of Example 1 are implemented.

[0072] In this embodiment, the processor may be a central processing unit, or other general-purpose processors, digital signal processors, application-specific integrated circuits, readily available programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.

[0073] Those skilled in the art will appreciate that the disclosed content of the embodiments may be provided as methods, systems, or computer program products. Therefore, the present solution may adopt the form of hardware embodiments, software embodiments, or embodiments combining software and hardware. Moreover, the present solution may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program codes.

[0074] The present solution is described with reference to the flowchart and / or block diagram of the method and computer program product according to the embodiment of the present solution. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions; these computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0075] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0076] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0077] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0078] The present invention provides an analysis method and system for predicting stock trends based on capital flow data. There are many methods and ways to implement the technical solution. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the protection scope of the present invention. All components not specified in this embodiment can be implemented by existing technologies.

Claims

1. An analytical method for predicting stock trends based on capital flow data, characterized in that: The method comprises the following steps: S1. Calculate the excess returns of different models by backtesting stocks with historical data; S2. Predict revenue through different models based on real-time data; S3. Classify stocks based on the predicted returns in S2 and the excess returns in S1.

2. The analysis method according to claim 1, characterized in that In S1, the specific steps of stock backtesting are: S11. Obtain market data and capital data; S12. Clean and merge the data, calculate the k-day moving average data and k-day rate of return; S13. Predict the average return rate for the next k days S14. Establish stock trading strategies; S15. Perform backtesting based on the trading strategy in S14 and calculate the profit; S16. Compare the returns obtained from the backtest of S15 with the actual stock performance and calculate the excess returns.

3. The method according to claim 2, characterized in that In S11, before acquiring the data, it is determined whether the target stock data is acquired for the first time. If so, all historical data of the target stock are acquired; if not, the updated data of the target stock are acquired and merged with the historical data.

4. The method according to claim 2, characterized in that: In S13, the moving average data is used as the independent variable, the k-day yield is used as the supervisory variable, and the machine learning model is used to predict the average yield of the next k days. Among them, the machine learning models are random forest, K nearest neighbor, LSTM and deep learning models.

5. The method according to claim 2, characterized in that: In S14, the trading strategy is specifically as follows: different thresholds δ are set. Execute a buy operation when , execute the sell operation.

6. An analysis system for predicting stock trends based on capital flow data, characterized in that: The system comprises: Individual stock backtesting module, used to collect data and calculate returns for a single target stock; Batch backtesting module, used to calculate the threshold and maximum excess return of multiple stocks under different forecasting models; The stock diagnosis module is used to predict expected returns using different forecasting models based on real-time data and compare them with the excess returns obtained by the batch backtesting module; The classification module is used for classification after the diagnosis of the stock diagnosis module is completed.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps in the analysis method for predicting stock trends based on capital flow data as described in any one of claims 1 to 5 are implemented.

8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the analysis method for predicting stock trends based on capital flow data as described in any one of claims 1 to 5 are implemented.