Method for calculating minute granularity fund flow in real time based on deep market
By using Level-2 market gateway to receive transaction-by-transaction data in securities trading services, restore the original commission and distinguish different order types, and combine it with a high-performance timing database, the accuracy and real-time problems of existing capital flow calculation methods are solved. , realizes rapid, refined and accurate calculation of capital flows.
Patent Information
- Application Number
- CN202410897767.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-05
- Publication Date
- 2024-11-29
AI Technical Summary
There are deviations in the calculation methods of capital flow in existing securities trading services, especially because the characteristics of each commissioned data provided by different exchanges, the calculation results are not accurate enough, and the different types of commissioned methods are not effectively distinguished, which affects the accuracy of the algorithm. Spend.
The Level-2 market gateway receives commissions and transaction data in real time, creates relevant flow data tables that store real-time data, restores the original commissions by ordering and transaction data by ordering, and distinguishes super large orders and large orders based on the original commission. , mid-single and small orders, combined with high-performance timing databases to realize real-time calculation of capital flow.
It realizes the fast, refined and accurate capital flow calculation, abandons the limitation of single use of snapshots or transaction-by-transaction data, fully considers different delegation methods, improves the accuracy and real-timeness of the algorithm, and is suitable for high-performance timing in the financial field. database.
Smart Images

Figure CN119048231A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of securities trading services, and in particular relates to a method for calculating minute-granularity fund flows in real time based on deep market conditions. Background Art
[0002] At present, there are four mainstream real-time fund flow algorithms in the industry. The first method is based on Level-1 snapshot market calculation, that is, the market snapshot service provided by the Shanghai and Shenzhen Stock Exchanges every 3 seconds. The fund flow calculated by this algorithm has a large deviation and has been gradually eliminated by the market; the first method is improved to produce the second method based on Level-2 snapshot combined with transaction-by-transaction data calculation. This method is more accurate than the first method, but it will still produce deviations for some stocks; the third method eliminates the snapshot data and is only based on Level-2 transaction-by-transaction data, which is more accurate than the second method. For example, the patent "A method for calculating the control ability of the main stock based on fund flow analysis" (patent number: CN107798490A) is based on the analysis of each transaction data, and on the basis of distinguishing between the main funds and non-main funds, a method for quantitative calculation of the main control ability is proposed.
[0003] However, this method is still not the most accurate. The main reason is that not every order will be executed. Therefore, it is necessary to distinguish based on the original order. There are slight differences in the order data provided by the Shanghai and Shenzhen stock markets (the order data of the Shanghai stock market will not be provided to the public until 2023). Therefore, the capital flow of the Shanghai and Shenzhen stock markets needs to be calculated differently. For the Shenzhen stock market, the order is the original order; while for the Shanghai stock market, the order is usually not the original order, and the original order needs to be restored through a certain algorithm. In addition, different prices are used to participate in the calculation for different order methods (limit order, market order, and best order), which basically achieves zero defects in the accuracy of the algorithm. Therefore, combining the Level-2 order and order data, and taking into full consideration the characteristics of each order method and exchange data, a more accurate capital flow can be calculated. Summary of the invention
[0004] The purpose of the present invention is to provide a method for calculating minute-granularity capital flow in real time based on deep market conditions. Compared with traditional capital flow calculation methods, the calculation process is faster and the calculation results are more precise and accurate.
[0005] The technical solution adopted by the present invention is a method for calculating minute-granularity capital flow in real time based on deep market conditions, which specifically includes the following steps:
[0006] S1, receives real-time order and transaction data from the exchange's computer room through the Level-2 market gateway, saves it in the memory database, and creates relevant stream data tables to store real-time data;
[0007] S2, restore the original order through the order-by-order and transaction-by-transaction data, and distinguish super large orders, large orders, medium orders and small orders according to the original order;
[0008] S3, each transaction triggers the real-time calculation of the size of the capital flow and the net capital inflow at the 1-minute level.
[0009] The present invention is also characterized in that:
[0010] The relevant flow data tables in S1 include original transaction data, original order data, transaction-by-transaction responsive state engine, order-by-order responsive state engine and real-time calculation data of capital flow.
[0011] In S2, the original entrustment is restored through the entrustment and transaction data of each transaction as follows: the buy entrustment and sell entrustment are found according to the buy and sell indexes in each transaction, the type of each entrustment is determined according to the entrustment price, entrustment volume and entrustment amount in each entrustment, and the transaction volume in each transaction is added to the type of each entrustment to obtain the original entrustment.
[0012] In S2, the original entrustment is restored through the entrustment and transaction data of each transaction. Specifically, the buying and selling indexes in the transaction data are matched. If the transaction data matches the buying and selling indexes, the entrustment amount in the buying and selling indexes is referenced; if the transaction data does not match the buying and selling indexes, the transaction amount in the transaction data is used; in the matching process, the situations where the buying and selling indexes appear in the previous transaction data are traversed. If they have appeared, they are accumulated, and the accumulated result is compared with the entrustment amount in the found buying and selling indexes. The larger value is taken to get the original entrustment.
[0013] If the timestamp of the current order is equal to the timestamp of the previous order, and the indexes are equal, it is judged as a remaining order, that is, the order amount in this order is added to the transaction volume of the current transaction to get the original order.
[0014] In S2: a single order is defined as a super large order if the proportion of the single order to the circulating share capital is ≥ 0.1% or the transaction amount is greater than RMB 1 million; a single order is defined as a large order if the proportion of the single order to the circulating share capital is [0.05%-0.1%) or the transaction amount is greater than RMB 1 million; a single order is defined as a medium order if the proportion of the single order to the circulating share capital is [0.01%-0.05%) or the transaction amount is RMB 40,000-200,000; a single order is defined as a small order if the proportion of the single order to the circulating share capital is [0-0.01%) or the transaction amount is greater than RMB 40,000.
[0015] The beneficial effects of the present invention are:
[0016] Compared with the current mainstream capital flow calculation method in the market, the present invention abandons the single use of snapshots or transaction data, restores the original entrustment through entrustment and transaction data, and distinguishes super large orders, large orders, medium orders, and small orders according to the original entrustment. At the same time, the two special entrustment methods of "market entrustment" and "our best" in addition to "limited price entrustment" are fully considered. For the "our best" entrustment, the most recent transaction price is used for calculation, and for the "market entrustment", the buy price or sell price is used for calculation, basically achieving zero defects in the accuracy of the algorithm. On this basis, with the help of a high-performance time series database suitable for application in the financial field, a more refined, accurate, and real-time calculation of capital flow is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a flow chart of a method for calculating minute-granularity fund flows in real time based on deep market conditions of the present invention;
[0018] Figure 2 It is a calculation logic diagram of capital flow in the method of the present invention for calculating minute-granularity capital flow in real time based on deep market conditions. DETAILED DESCRIPTION
[0019] The present invention will be further explained below in conjunction with the accompanying drawings and specific embodiments.
[0020] Example 1
[0021] like Figure 1-Figure 2 As shown, the method disclosed in the present invention for calculating minute-granularity fund flows in real time based on deep market conditions specifically includes the following steps:
[0022] S1, receives real-time order and transaction data from the Shanghai and Shenzhen Stock Exchanges through the Level-2 market gateway, saves it in the memory database, and creates relevant stream data tables to store real-time data; the stream data table persistence is performed asynchronously, which can effectively improve the throughput of stream data table writing. It mainly includes the following shareable asynchronous persistent stream data tables: original transaction data (TradeOriginalStream), used to receive and publish real-time stock transaction data, original order data (OrderOriginalStream), used to receive and publish real-time stock order data, transaction responsive state engine (TradeProcessStream), used to receive and publish intermediate result data after the responsive state engine processes transaction data, order responsive state engine (OrderProcessStream), used to receive and publish intermediate result data after the responsive state engine processes order data, and capital flow real-time calculation data (CapitalFlowStream), used to receive and publish capital flow indicators of 1-minute rolling window processed by the time series engine.
[0023] S2, restore the original order through the order-by-order and transaction data, and distinguish super large orders, large orders, medium orders and small orders according to the original order; a single order is ≥0.1% of the circulating share capital or the transaction amount is greater than 1 million yuan for a super large order; a single order is [0.05%-0.1%) of the circulating share capital or the transaction amount is greater than 1 million yuan for a large order; a single order is [0.01%-0.05%) of the circulating share capital or the transaction amount is 40,000-200,000 yuan for a medium order; a single order is [0-0.01%) of the circulating share capital or the transaction amount is greater than 40,000 yuan for a small order.
[0024] S3, each transaction triggers the real-time calculation of the 1-minute level of capital flow, large and small orders, and net capital inflow (net capital inflow = buy super large orders + buy large orders - sell super large orders - sell large orders).
[0025] Example 2
[0026] For the Shenzhen Stock Exchange, the transaction-by-transaction entrustment is the original entrustment, and each transaction-by-transaction corresponds to a buy entrustment and a sell entrustment (note that the order cancellation entrustment is excluded. The order cancellation entrustment is issued through transaction-by-transaction. If it is a buy order cancellation, the buy index is valid and the sell index is 0; similarly, if it is a sell order cancellation, the sell index is valid and the buy index is 0). Therefore, under normal circumstances, for the Shenzhen Stock Exchange, each transaction-by-transaction data has corresponding buy and sell transaction-by-transaction entrustment data. On the basis of Example 1, the original entrustment is restored by transaction-by-transaction entrustment and transaction-by-transaction data in S2 as follows:
[0027] Find the buy and sell orders in each transaction according to the buy and sell indexes in each transaction, determine the type of each order according to the order price, order volume and order amount in each order, and then add the transaction volume in each transaction to the type of each order to get the original order.
[0028] Example 3
[0029] For the Shanghai Stock Exchange, the capital flow algorithm is more complicated than that of the Shenzhen Stock Exchange. The main reason is that the Shanghai Stock Exchange's individual entrustment is usually not the original entrustment, and the individual transaction data may precede the individual entrustment data. The size of the order in the capital flow calculation is a dynamic concept, that is, a small order may evolve into a large order after the transaction volume increases. The calculation process of the capital flow involves historical status, and a response is required for each transaction record. If incremental calculation cannot be achieved, the calculation efficiency will be relatively low. Therefore, the real-time calculation of the capital flow is under great pressure and has high latency requirements. Take an entrustment with a total entrustment volume of 4,000 as an example:
[0030] (1) If the first matchmaking fails, the message number UA5803 will publish the original order quantity of 4000.
[0031] (2) If the first match is successful with 2300, the message number UA5803 will publish the remaining order quantity of 1700, and the order will only be published once.
[0032] (3) If all orders are successfully matched for the first time, message number UA5803 will not publish the order.
[0033] If the transaction by transaction sent by Shanghai Stock Exchange is received first, the cache operation is performed first, and the real-time calculation of the capital flow driven by the transaction by transaction is performed, and the current buy order quantity, buy order amount, sell order quantity, and sell order amount for distinguishing large, medium and small orders are recorded during the calculation. On the basis of Example 1, the original order is restored by transaction by transaction and transaction by transaction data in S2 specifically as follows:
[0034] For the Shanghai Stock Exchange: Match according to the buy and sell indexes in the transaction data. If the transaction data matches the buy and sell indexes, the entrustment amount in the buy and sell indexes is referenced; if the transaction data does not match the buy and sell indexes, the transaction amount in the transaction data is used; in the matching process, traverse the situations where the buy and sell indexes appear in the previous transaction data. If they have appeared, accumulate them, and compare the accumulated results with the entrustment amount in the found buy and sell indexes. Take the larger value to get the original entrustment. The calculation process needs to correct the distinction between large and small orders in real time.
[0035] Furthermore, if the timestamp of the current order is equal to the timestamp of the previous order and the indexes are equal, it is judged as a remaining order, that is, the order amount in the order is added to the transaction volume of the current transaction to obtain the original order.
[0036] Compared with the current mainstream capital flow calculation method in the market, the present invention abandons the single use of snapshots or transaction data, restores the original entrustment through entrustment and transaction data, and distinguishes super large orders, large orders, medium orders, and small orders according to the original entrustment. At the same time, the two special entrustment methods of "market entrustment" and "our best" in addition to "limited price entrustment" are fully considered. For the "our best" entrustment, the most recent transaction price is used for calculation, and for the "market entrustment", the buy price or sell price is used for calculation, basically achieving zero defects in the accuracy of the algorithm. On this basis, with the help of a high-performance time series database suitable for application in the financial field, a more refined, accurate, and real-time calculation of capital flow is achieved.
[0037] After the downstream consumption system subscribes, downstream consumers can consume and subscribe through the playback function or Python API of the high-performance time series database, and can also push strategy trading terminals and other downstream platforms.
[0038] The present invention fully considers the characteristics and differences of the Level-2 market data launched by the Shanghai and Shenzhen Stock Exchanges respectively. The calculation of real-time capital flow at a minute granularity based on this method has significantly improved the real-time performance and accuracy compared with the previous capital flow algorithm, and has basically reached the level of accuracy. Therefore, it can be used as the basic data for the calculation of more complex indicators / factors based on real-time capital flow calculation, and has a relatively broad application prospect.
Claims
1. A method for calculating minute-level capital flows in real time based on deep market conditions, characterized in that: The specific steps include: S1, receives real-time order and transaction data from the exchange's computer room through the Level-2 market gateway, saves it in the memory database, and creates relevant stream data tables to store real-time data; S2, restore the original order through the order-by-order and transaction-by-transaction data, and distinguish super large orders, large orders, medium orders and small orders according to the original order; S3, each transaction triggers the real-time calculation of the size of the capital flow and the net capital inflow at the 1-minute level.
2. The method for calculating minute-level capital flows in real time based on deep market conditions according to claim 1, characterized in that: The relevant flow data table in S1 includes original transaction data, original entrustment data, transaction-by-transaction responsive state engine, entrustment-by-entrustment responsive state engine and real-time calculation data of capital flow.
3. The method for calculating minute-level capital flow in real time based on deep market conditions according to claim 1 is characterized in that: In S2, the original entrustment is restored through entrustment and transaction data one by one, specifically: Find the buy and sell orders in each transaction according to the buy and sell indexes in each transaction, determine the type of each order according to the order price, order volume and order amount in each order, and then add the transaction volume in each transaction to the type of each order to get the original order.
4. The method for calculating minute-level capital flows in real time based on deep market conditions according to claim 1, characterized in that: The specific method of restoring the original entrustment through the entrustment and transaction data of each transaction in S2 is as follows: matching is performed according to the buying and selling indexes in the transaction data of each transaction. If the transaction data of each transaction matches the buying and selling indexes, the entrustment amount in the buying and selling indexes is referenced; if the transaction data of each transaction does not match the buying and selling indexes, the transaction amount in the transaction data of each transaction is used; in the matching process, the situations where the buying and selling indexes appear in the previous transaction data are traversed, and if they have appeared before, they are accumulated, and the accumulated result is compared with the entrustment amount in the found buying and selling indexes, and the larger value is taken to obtain the original entrustment.
5. The method for calculating minute-level capital flows in real time based on deep market conditions according to claim 4 is characterized in that: If the timestamp of the current order is equal to the timestamp of the previous order, and the indexes are equal, it is judged as a remaining order, that is, the order amount in this order is added to the transaction volume of the current transaction to get the original order.
6. The method for calculating minute-granularity fund flows in real time based on deep market conditions according to claim 3 or 4, characterized in that: In S2: a single order accounting for ≥0.1% of the circulating share capital or a transaction amount of >1 million yuan is a super large order; a single order accounting for [0.05%-0.1%) of the circulating share capital or a transaction amount of >1 million yuan is a large order; a single order accounting for [0.01%-0.05%) of the circulating share capital or a transaction amount of 40,000-200,000 yuan is a medium order; a single order accounting for [0-0.01%) of the circulating share capital or a transaction amount of >40,000 yuan is a small order.
