Calculation method and system for order flow strategy backtest

By establishing a Tick data service cluster and user client, combining simulated matching mechanism and fund management, the accuracy of order flow strategy backtesting is solved, and more accurate strategy verification and optimization is achieved.

CN120258978APending Publication Date: 2025-07-04SHANGHAI WENHUA FINANCIAL INFORMATION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410112652.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-26
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The backtesting method of order flow strategy in the prior art cannot accurately reflect its results in actual transactions, resulting in large differences between backtesting and actual transactions, and it is impossible to effectively verify the advantages and disadvantages of the strategy.

Method used

Establish a Tick data service cluster and user client, forward and store market-related data through network connections, initialize and manage the simulated trading account, use the simulated matchmaking mechanism to backtest the order flow strategy, dynamically display positions and capital changes, and generate accurate backtest reports.

Benefits of technology

It improves the accuracy and reliability of backtesting of order flow strategy, can better simulate the actual trading environment, generate consistent backtest reports, and support policy debugging and optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120258978A_ABST
    Figure CN120258978A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of financial science and technology, and provides an order flow strategy backtest calculation method, which comprises the following steps: S1, establishing a Ti < ck > data service cluster and a plurality of user clients; s2, selecting an order flow strategy needing back testing and a back testing date needing back testing, and setting initial position information and initial fund information of a simulation transaction account; s3, after the back-test task is started, initializing a back-test module; s4, after initialization of the backtesting module is finished, starting a calculation thread, and applying for market information related data of all contracts on a backtesting date; s5, calling order flow strategy circulation to calculate the market information related data; and S6, after calculation is finished, carrying out simulated collection processing, emptying the pending orders which are not transacted in the simulated transaction account, calculating a back test report, and notifying the Tick data display interface to refresh. The operation condition of the order flow strategy can be simulated relatively accurately.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of fintech, and particularly relates to a calculation method and system for order flow strategy backtesting. Background Art

[0002] In the existing financial market, algorithmic trading has already been a very popular trading method. Algorithmic trading combines the unique speed advantage of computers with modern order flow strategies. The order flow strategy automatically completes a series of trading operations such as batching, placing orders, and canceling orders according to the order book data and the user's position status, greatly improving the trading efficiency and reducing the trading cost. However, how to verify the order flow strategy has become a very important issue.

[0003] In the prior art, the order flow strategy is usually simply backtested and verified by using a simple matching method based on the latest market price, and the fund management is also incomplete, resulting in a large difference between the results of the order flow strategy in backtesting and actual trading, and being unable to accurately reflect the advantages and disadvantages of the order flow strategy. Summary of the Invention

[0004] In view of the above problems, the purpose of the present invention is to provide a calculation method and system for order flow strategy backtesting, which can relatively accurately simulate the operation of the order flow strategy.

[0005] The above object of the present invention is achieved by the following technical solutions:

[0006] A calculation method for order flow strategy backtesting includes the following steps:

[0007] S1: Establish a Tick data service cluster and several user clients. The Tick data service cluster and the user clients are connected through a network. The Tick data service cluster is used for forwarding and storing market-related data, and the user clients are used for storing the order flow strategy and providing a Tick data display interface;

[0008] S2: Select the order flow strategy to be backtested and the backtest date in the Tick data display interface, and set the initial position information and initial fund information of the simulated trading account;

[0009] S3: After starting the backtest task, initialize the backtest module;

[0010] S4: After the initialization of the backtest module is completed, start a calculation thread, and apply for the market-related data of all contracts on the backtest date, where the contracts used for the backtest task are written through the function interfaces provided in the order flow strategy;

[0011] S5: Invoke the order flow strategy to loop and calculate the market-related data;

[0012] S6: After the calculation, perform simulated closing processing, clear the unexecuted pending orders in the simulated trading account, calculate the backtest report, and notify the Tick data display interface to refresh.

[0013] Further, in step S1, the Tick data service cluster is used for forwarding and storing the market-related data, specifically:

[0014] The Tick data service cluster provides the forwarding and storage of various market-related data including 5-level Tick data, price limits, fund flows, deposited funds, price increases, and volume ratios for each market. Among them, the 5-level Tick data includes bid price, bid volume, ask price, ask volume, trading volume, active buying and selling, and timestamp.

[0015] Further, in step S1, the user client is used for storing the order flow strategy and providing the Tick data display interface, specifically including:

[0016] The user client stores the order flow strategy required for backtesting locally;

[0017] The user client provides the Tick data display interface, which displays the list of the order flow strategy, the Tick market data line chart, and the backtest results of the order flow strategy;

[0018] Before the backtest is performed, the Tick data display interface displays: the list of the order flow strategy stored locally by the user, the Tick market data line chart of the specified contract on the current day, and the order book information;

[0019] During the backtest, the Tick data display interface displays: the market-related data of the backtest date according to the backtest progress, and the real-time information of the simulated trading account for the backtest, including the position list, the pending order list, and the equity curve;

[0020] At the end of the backtest, the Tick data display interface provides an interface to display information including the backtest report, transaction details, and trading logs.

[0021] Further, in step S3, after starting the backtest task, initialize the backtest module, specifically:

[0022] S31: Compile the order flow strategy, and parse out the contract list related to the order flow strategy from the order flow strategy, where the contract list includes a trading contract list and an extended data contract list;

[0023] S32: Initialize the Tick data cache container, register the contract list in the Tick data cache container, initialize the simulated trading account, register the initial position information and the initial fund information, initialize the data containers for the interface display information including trading logs, position information, order list, and equity curve, initialize the calculator for the backtest report, and register the data required for the backtest report calculation.

[0024] Further, in step S4, after the initialization of the backtest module is completed, start a calculation thread and apply for the market-related data of all contracts on the backtest date. Specifically:

[0025] Start the calculation thread to begin processing the backtest process and notify the Tick data display interface;

[0026] Apply for the market-related data of all contracts on the backtest date using the contract list in the Tick data cache container.

[0027] Further, in step S5, call the order flow strategy to loop and calculate the market-related data. Specifically:

[0028] Since the sampling frequencies of different contracts are different, align the market-related data in seconds, obtain all the market-related data for one second from the Tick data cache container, and process it in the order of extended data and trading data;

[0029] Before processing each piece of market-related data, first determine whether there is an order for the current contract. If there is an order generated by a trading instruction, use the current market-related data to perform a simulated matching mechanism to determine whether it can be traded. If it can be traded, generate a transaction record and update the information of the simulated trading account;

[0030] When processing each piece of market-related data, first update the latest data in the Tick data cache container with this piece of market-related data, call the order flow strategy for calculation to generate trading information, and the simulated trading account generates trading instructions including the trading instruction and the order cancellation instruction based on the trading information, position status, and fund information;

[0031] After calling the order flow strategy for calculation, process the order cancellation instruction;

[0032] Before the end of each loop, notify the Tick data display interface to refresh and cache the data required for the backtest report calculation.

[0033] Further, the calculation method for order flow strategy backtesting further includes: managing the simulated trading account, specifically:

[0034] Managing the information of the simulated trading account including the position information, order information, execution information, and the fund information, and providing an interface to support generating the trading instructions according to the trading information;

[0035] Meanwhile, before processing each piece of the market-related data, first determine whether there is an outstanding order for the current contract. If there is an outstanding order generated by the entrusted trading instruction, use the simulated matching mechanism to match according to the current market-related data, where the simulated matching mechanism simulates the matching mechanism based on the order book data, converts the trading instruction into the user's position, and updates the information including the position information, the order information, the execution information, and the fund information in real time.

[0036] An order flow strategy backtesting calculation system for the above-mentioned calculation method of order flow strategy backtesting includes:

[0037] A server module for establishing a Tick data service cluster, which is used for forwarding and storing market-related data;

[0038] A backtesting parameter setting module for selecting the order flow strategy to be backtested, the backtesting date to be backtested, and setting the initial position information and initial fund information of the simulated trading account in the Tick data display interface;

[0039] An initialization backtesting module for initializing the backtesting module after starting the backtesting task;

[0040] An application data module for starting a calculation thread and applying for the market-related data of all contracts on the backtesting date after the initialization of the backtesting module is completed, where the contracts used for the backtesting task are written through the function interface provided in the order flow strategy;

[0041] A backtesting process calculation module for calling the order flow strategy to calculate the market-related data in a loop;

[0042] A backtesting report calculation module for calculating the backtesting report after the calculation is completed and notifying the Tick data display interface to refresh.

[0043] A computer device includes a memory and one or more processors. When the computer code stored in the memory is executed by the one or more processors, the one or more processors execute the method as described above.

[0044] A computer-readable storage medium stores computer code which, when executed, causes the above-described method to be executed.

[0045] Compared with the prior art, the present invention has at least one of the following beneficial effects:

[0046] (1) By providing a calculation method for order flow strategy backtesting, including: S1: Establish a Tick data service cluster and several user clients, the Tick data service cluster and the user clients are connected through a network, the Tick data service cluster is used for forwarding and storing market-related data, and the user clients are used for storing order flow strategies and providing a Tick data display interface; S2: Select the order flow strategy to be backtested and the backtest date in the Tick data display interface, and set the initial position information and initial capital information of the simulated trading account; S3: After starting the backtest task, initialize the backtest module; S4: After initializing the backtest module, start a calculation thread, and apply for the market-related data of all contracts on the backtest date, where the contracts used for the backtest task are written through a function interface provided in the order flow strategy; S5: Call the order flow strategy to calculate the market-related data in a loop; S6: After the calculation is completed, perform simulated closing processing, clear the unexecuted orders in the simulated trading account, calculate the backtest report, and notify the Tick data display interface to refresh. The above technical solution simulates the operation of the order flow strategy, obtains the data of the contracts related to the order flow strategy, aligns the data if it contains the data of multiple contracts, and uses historical data to call the order flow strategy to generate corresponding trading signals; a simulated trading account generates trading instructions according to the trading signals; a simulated matching mechanism matches the trading instructions according to the market data and converts the trading instructions into user positions; during the calculation process, dynamically display the position list, order list, and equity curve of the simulated trading account; after the calculation is completed, display the backtest report calculated based on the change in funds. Simulate the order flow strategy for simulated trading users, imitate the processing flow of account funds in actual trading, and ensure that the user fund processing logic is consistent with that in actual trading, so that the final backtest report is more accurate.

[0047] (2) When including the data of multiple contracts, by aligning the market-related data in seconds, as long as the data is recorded in seconds, the market state of actual trading is simulated as much as possible.

[0048] (3) By performing matching according to the current market-related data using a simulated matching mechanism, a specific matching algorithm generates a more realistic trading position result based on the order book data, improving the accuracy, reliability, and applicability of the backtest. This enables users to more conveniently debug and optimize order flow strategies. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is the overall flowchart of the calculation method for the order flow strategy backtest of the present invention;

[0050] Figure 2 It is the front-end effect schematic diagram of the Tick data display interface of the present invention;

[0051] Figure 3 It is the front-end effect schematic diagram of the parameter setting interface for the order flow strategy backtest of the present invention;

[0052] Figure 4 It is the front-end effect schematic diagram at the start of the calculation task for the order flow strategy backtest of the present invention;

[0053] Figure 5 It is the front-end effect schematic diagram during the calculation task for the order flow strategy backtest of the present invention;

[0054] Figure 6 It is the front-end effect schematic diagram at the end of the calculation task for the order flow strategy backtest of the present invention;

[0055] Figure 7 It is the overall structure diagram of the calculation method for the order flow strategy backtest of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the scope of protection of the present application.

[0057] Those skilled in the art of the present technology can understand that unless specifically stated otherwise, the singular forms "a", "an", "the", and "said" used herein may also include the plural forms. It should be further understood that the term "comprising" used in the specification of the present invention means the presence of the described features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or their groups.

[0058] The present invention provides a calculation method for backtesting an order flow strategy. The backtesting speed of the order flow strategy is controllable. In combination with the dynamically output position list, order list, and equity curve, it allows users to more intuitively understand the operation of the order flow strategy; the management of the simulated account imitates the processing flow of account funds in actual trading. It makes the change of user funds consistent with actual trading, thus making the final backtesting report more accurate; simulating the matching mechanism, a specific matching algorithm generates more realistic position results based on the order book data, improving the accuracy, reliability, and practicality of the backtesting. It enables users to more conveniently debug and optimize the order flow strategy.

[0059] The following specifically illustrates the inventive points of the present invention through specific embodiments:

[0060] First Embodiment

[0061] As Figure 1 shown, this embodiment provides a calculation method for backtesting an order flow strategy, including the following steps:

[0062] S1: Establish a Tick data service cluster and several user clients. The Tick data service cluster and the user clients are connected through a network. The Tick data service cluster is used for forwarding and storing market-related data, and the user clients are used for storing the order flow strategy and providing a Tick data display interface.

[0063] Specifically, this embodiment provides a Tick data server as the Tick data service cluster. The Tick data server supports users to obtain various market-related data of a specified contract, including 5-level Tick data, price limits, fund flows, sedimented funds, price increases, and volume ratios. A better Tick data server should include the forwarding and storage of the above data for each market.

[0064] Among them, the five-level Tick data includes the bid price, bid volume, ask price, ask volume, trading volume, active buying and selling, and timestamp. The bid price is the highest price at which the buyer is willing to purchase the asset, the bid size is the quantity of the asset that the buyer is willing to purchase, the ask price is the lowest price at which the seller is willing to sell the asset, the ask size is the quantity of the asset that the seller is willing to sell, the trading volume refers to the quantity of actual transactions that occur in the market within a specific time, active buying and selling refers to the behavior of traders taking proactive orders in the market to execute their trading strategies, and the timestamp is the time when the Tick data is generated. These data are very important for traders and algorithmic trading strategies because they provide real-time information about market depth and the situation of the bid-ask spread. By monitoring these data, traders can better understand the dynamics of the market and make corresponding decisions, such as judging trends, identifying support and resistance levels, etc. The purpose of using five-level Tick data is to capture the changes in the closest price levels in the market to more accurately reflect the instantaneous state of the market. This data is commonly used in high-frequency trading and other trading strategies that are sensitive to market depth.

[0065] In step S1, the user client is used to store the order flow strategy and provide the Tick data display interface, specifically including:

[0066] The user client stores the order flow strategy required for backtesting locally. Among them, the order flow strategy is an investment strategy based on market order flow data. By analyzing the rules and trends of the order flow, it judges the market sentiment and future price trends, and thus makes investment decisions. The core principle of the order flow strategy lies in that the market order flow reflects the behaviors and emotions of market participants, and these behaviors and emotions change with the change of the market environment, thus affecting the future price trends. Therefore, by analyzing the order flow data, signals of market trends and future price trends can be obtained. The order flow strategy of the present invention is aimed at the market Tick data. The user writes a strategy script, and based on data such as the latest price, bid-ask price and quantity in the Tick data, judges the change rules, and performs operations such as entrusting and canceling orders when the conditions defined by the user are met.

[0067] The user client provides the Tick data display interface, and the Tick data display interface displays the list of the order flow strategies, the line chart of the Tick market data, and the backtesting results of the order flow strategies.

[0068] Before the backtesting is carried out, the Tick data display interface displays: the list of the order flow strategies stored locally by the user, the line chart of the Tick market data of the specified contract on the current day, and the order book information. Such as Figure 2As shown, a list of locally stored order flow strategies is displayed on the left side of the interface, a line chart of the Tick market data for the specified contract on the current day is displayed in the middle, and the current order book information is displayed on the right side.

[0069] When performing backtesting, the Tick data display interface shows: the market-related data for the backtesting date according to the backtesting progress, and real-time information including the position list, order list, and equity curve of the simulated trading account for backtesting.

[0070] When the backtesting ends, the Tick data display interface provides an interface to show information including the backtesting report, trading details, and trading logs.

[0071] S2: Select the order flow strategy to be backtested, the backtesting date, and set the initial position information and initial capital information of the simulated trading account in the Tick data display interface.

[0072] Specifically, in this embodiment, as Figure 3 shown, set the backtesting date, specify the initial capital, position quantity, and position price of the simulated trading account. In the Tick data display interface, double-click the order flow strategy to be backtested to start the backtesting task.

[0073] S3: After starting the backtesting task, initialize the backtesting module.

[0074] In this embodiment, initializing the backtesting module specifically includes:

[0075] S31: Compile the order flow strategy, and parse out the contract list related to the order flow strategy from the order flow strategy, where the contract list includes a trading contract list and an extended data contract list.

[0076] The order flow strategy is user-defined, and the user will write the required trading contract data and extended data in the order flow strategy. For example, if contracts m2305 and m2312 are needed, in addition to obtaining the latest price, trading volume, open interest, bid price, ask price, bid volume, and ask volume of contracts m2305 and m2305, extended data such as the daily increase in open interest, deposited funds, and fund flow of contract m2305 are also required.

[0077] S32: Initialize the Tick data cache container, register the contract list in the Tick data cache container, initialize the simulated trading account, register the initial position information and the initial capital information, initialize the data containers for the interface display information including trading logs, position information, order list, and equity curve, initialize the calculator for the backtesting report, and register the data required for the backtesting report calculation.

[0078] S4: After the initialization of the backtest module is completed, start a calculation thread to apply for the market-related data of all contracts on the backtest date, where the contracts used for the backtest task are written using the function interfaces provided in the order flow strategy.

[0079] In this embodiment, start the calculation thread to start processing the backtest process and notify the Tick data display interface. Apply for the market-related data of all the contracts on the backtest date using the contract list in the Tick data cache container. The interface effect is as Figure 4 shown.

[0080] S5: Call the order flow strategy to loop and calculate the market-related data.

[0081] For the order flow strategy written by the user, it is the calculation logic of the market-related data, which will specify how to use the data, how to judge the data, and how to issue trading instructions. The calculation process is actually the process of executing the order flow strategy written by the user.

[0082] In this embodiment, execute the order flow strategy to loop and calculate the market-related data. Specifically:

[0083] Since the sampling frequencies of different contracts are different, align the market-related data in seconds. Obtain all the market-related data of one second from the Tick data cache container and process it in the order of extended data and trading data.

[0084] For aligning the market-related data in seconds, the following is an example:

[0085] Suppose we need the latest price, best bid price, daily increase in open interest, settled funds, fund flow of contract m2305 and the latest price and closing price of contract m2312.

[0086] We will apply for the basic data of m2305 and m2312 and the extended data of m2312 (these are two data sources). First, we need to align the data of the same contract. The sampling frequencies of the basic data and the extended data of the same contract are the same, and they can be placed together in order. Different contracts have different sampling periods and different levels of activity. The number of Ticks in the same second is also different for each contract. When calculating, we process along the time axis. Obtain data in seconds. After retrieving the data of all contracts in this second, since non-trading contracts do not participate in indicator calculations, we sort all the data in the order of non-trading data and trading data. When traversing and calculating, we first update the buffer area using non-trading contracts and then call trading contracts for calculation.

[0087] Before processing each piece of market-related data, first determine whether there are any pending orders for the current contract. If there are pending orders generated by the entrusted trading instructions, use the simulation matching mechanism to match according to the current market-related data, and determine whether a deal can be made. If a deal can be made, generate a transaction record and update the information of the simulated trading account.

[0088] When processing each piece of market-related data, first use this piece of market-related data to update the latest data in the Tick data cache container, call the order flow strategy for calculation, generate trading information, and the simulated trading account generates trading instructions including the entrusted trading instructions and cancel order trading instructions according to the trading information, position status, and capital information.

[0089] After calling the order flow strategy for calculation, process the cancel order trading instructions.

[0090] Before the end of each loop, notify the Tick data display interface to refresh and cache the data required for calculating the backtest report.

[0091] During the loop, at the end of each loop, the interface will be notified to display the current backtest progress, and the interface effect is as Figure 5 shown.

[0092] S6: After the calculation is completed, perform a simulated closing operation, clear the unexecuted pending orders in the simulated trading account, calculate the backtest report, and notify the Tick data display interface to refresh.

[0093] Specifically, in this embodiment, the calculation of the backtest report is mainly based on the trading details generated by the user's trading instructions. Each time the user closes a position, it counts as one transaction. Calculate the final backtest report based on the profit and loss generated by each position closing.

[0094] The calculation explanations of each index of the backtest report are as follows:

[0095] (1) Leverage ratio = maximum capital utilization rate / margin rate 《Foreign exchange margin rate = margin per lot * total open lots / open turnover》

[0096] (2) Concept definition

[0097] Principal = initial capital + deposit and withdrawal

[0098] Profit and loss = realized profit and loss + floating profit and loss

[0099] Income = realized profit and loss + floating profit and loss - commission

[0100] Equity = realized profit and loss + floating profit and loss - commission + initial capital + deposit and withdrawal

[0101] Profit and loss on disposal = realized profit and loss - commission

[0102] (3) Yield = Income / Principal

[0103] (4) Equity Dispersion = Square root of (Sum of squares of single - profit - and - loss) / Number of trades

[0104] (5) Equity Dispersion Coefficient = (Equity Dispersion / Principal) * 100%

[0105] (6) Average Margin Yield = Average of (Income of each trade / Opening Margin)

[0106] (7) Maximum Equity Drawdown Ratio = Maximum of (Equity Drawdown / Equity at the time of equity drawdown)

[0107] (8) Maximum Profit - and - Loss Drawdown Ratio = Maximum of (Profit - and - Loss Drawdown / Equity at the time of profit - and - loss drawdown)

[0108] (9) Principal Risk Ratio = (Principal - Minimum Equity during backtesting period) / Principal

[0109] (10) Win Rate = (Number of winning trades + Number of even trades) / Number of trades

[0110] (11) Profit - and - Loss Ratio = Average profit per winning trade / Average loss per losing trade

[0111] (12) Ratio of Single - largest Profit to Total Profit = Single - largest Profit / Total Profit

[0112] (13) Ratio of Single - largest Loss to Total Loss = Single - largest Loss / Total Loss

[0113] After the loop ends, provide an interface to display the backtesting report, transaction details, trading logs, etc., and the interface effect is as Figure 6 shown.

[0114] Furthermore, in this embodiment, it is also necessary to manage the simulated trading account, specifically:

[0115] Manage the information including the position information, order information, execution information, and fund information of the simulated trading account, and provide an interface that supports generating the trading instructions according to the trading information.

[0116] At the same time, before processing each piece of market - related data, first determine whether there is an order hanging for the current contract. If there is an order hanging generated by the entrusted trading instruction, use the simulated matching mechanism to match according to the current market - related data. The simulated matching mechanism simulates the matching according to the order book data, converts the trading instruction into the user's position, and updates the information including the position information, order information, execution information, and fund information in real - time.

[0117] Preferably, according to the buy / sell direction of the trading order, the relationship between the latest price and the entrusted price is judged. Here, taking the buy order as an example:

[0118] (1) If the entrusted price is greater than the latest price, it is a full transaction

[0119] (2) If the entrusted price is less than the latest price, there is no transaction

[0120] (3) If the entrusted price is equal to the latest price, it is a partial transaction, and the entrusted data is processed according to the latest price, the best bid price, the best ask price and the trading volume

[0121] (31) If the latest price is equal to the best ask price, it is equivalent to a counterparty transaction, and the entrusted data = the volume of the current transaction / the order quantity at the best ask price * the entrusted quantity

[0122] (32) If the latest price is equal to the best bid price, it is equivalent to a hanging price transaction, and the entrusted data = the volume of the current transaction / the order quantity at the best bid price * the entrusted quantity

[0123] (32) In other cases, there is no transaction

[0124] Second Embodiment

[0125] As Figure 7 shown, this embodiment provides a calculation system for order flow strategy backtesting for executing the calculation method of the order flow strategy backtesting in the first embodiment, including:

[0126] Server module 1, used to establish a Tick data service cluster for forwarding and storing market-related data;

[0127] Backtesting parameter setting module 2, used to select the order flow strategy to be backtested, the backtesting date, and set the initial position information and initial capital information of the simulated trading account in the Tick data display interface;

[0128] Initialization backtesting module 3, used to initialize the backtesting module after starting the backtesting task;

[0129] Application data module 4, used to start a calculation thread and apply for the market-related data of all contracts on the backtesting date after the initialization of the backtesting module is completed, where the contracts used for the backtesting task are written through the function interfaces provided in the order flow strategy;

[0130] Backtesting process calculation module 5, used to call the order flow strategy to calculate the market-related data in a loop;

[0131] Backtesting report calculation module 6, used to calculate the backtesting report after the calculation is completed and notify the Tick data display interface to refresh.

[0132] A computer-readable storage medium stores computer code, which, when executed, performs the above-described method. Those of ordinary skill in the art will understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program, and this program can be stored in a computer-readable storage medium. The storage medium may include: read-only memory (ROM), random access memory (RAM), magnetic disks, optical discs, etc.

[0133] The above are only the preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions falling within the concept of the present invention belong to the protection scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications should also be regarded as within the protection scope of the present invention.

[0134] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as within the scope described in this specification.

[0135] It should be noted that the above embodiments can be freely combined as needed. The above are only the preferred embodiments of the present invention. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can also be made, and these improvements and modifications should also be regarded as within the protection scope of the present invention.

Claims

1. A calculation method for order flow strategy backtesting, characterized in that, It includes the following steps: S1: Establish a Tick data service cluster and several user clients. The Tick data service cluster and the user clients are connected through a network. The Tick data service cluster is used for forwarding and storing market-related data, and the user clients are used for storing order flow strategies and providing a Tick data display interface; S2: Select the order flow strategy to be backtested, the backtest date to be backtested in the Tick data display interface, and set the initial position information and initial capital information of the simulated trading account; S3: After starting the backtest task, initialize the backtest module; S4: After the initialization of the backtest module is completed, start a calculation thread and apply for the market-related data of all contracts on the backtest date, where the contracts used for the backtest task are written through the function interfaces provided in the order flow strategy; S5: Call the order flow strategy to calculate the market-related data in a loop; S6: After the calculation is completed, perform simulated closing processing, clear the unexecuted orders in the simulated trading account, calculate the backtest report, and notify the Tick data display interface to refresh.

2. The calculation method for order flow strategy backtesting according to claim 1, wherein In step S1, the Tick data service cluster is used for forwarding and storing the market-related data. Specifically: The Tick data service cluster provides the forwarding and storing of various market-related data including 5-level Tick data, price limits, fund flows, sedimented funds, price increases, and volume ratios for each market. Among them, the 5-level Tick data includes bid price, bid volume, ask price, ask volume, trading volume, active buying and selling, and timestamp.

3. The calculation method for order flow strategy backtesting according to claim 1, characterized in that In step S1, the user client is used for storing the order flow strategy and providing the Tick data display interface. Specifically, it includes: The user client stores the order flow strategy required for backtesting locally; The user client provides the Tick data display interface, which displays the list of order flow strategies, the line chart of Tick market data, and the backtest results of the order flow strategies; Before the backtest is performed, the Tick data display interface displays: the list of order flow strategies stored locally by the user, the line chart of Tick market data for the specified contract on the current day, and the order book information; During the backtest, the Tick data display interface displays: the market-related data for the backtest date according to the backtest progress, and the real-time information of the simulated trading account for the backtest, including the position list, order list, and equity curve; At the end of the backtest, the Tick data display interface provides an interface to display information including the backtest report, transaction details, and transaction logs.

4. The calculation method for order flow strategy backtesting according to claim 1, characterized in that, In step S3, after starting the backtest task, initialize the backtest module. Specifically: S31: Compile the order flow strategy and parse out the contract list related to the order flow strategy from the order flow strategy, where the contract list includes a trading contract list and an extended data contract list; S32: Initialize the Tick data cache container, register the contract list in the Tick data cache container, initialize the simulated trading account, register the initial position information and the initial capital information, initialize the data containers for the interface display information including trading logs, position information, order list, and equity curve, initialize the calculator for the backtest report, and register the data required for the backtest report calculation.

5. The calculation method of order flow strategy backtesting according to claim 4, characterized in that, In step S4, after the initialization of the backtest module is completed, start a calculation thread and apply for the market-related data of all contracts on the backtest date. Specifically: Start the calculation thread to begin processing the backtest process and notify the Tick data display interface; Apply for the market-related data of all contracts on the backtest date using the contract list in the Tick data cache container.

6. The calculation method of order flow strategy backtesting according to claim 5, wherein, In step S5, call the order flow strategy to loop and calculate the market-related data. Specifically: Since the sampling frequencies of different contracts are different, align the market-related data in seconds, obtain all the market-related data for one second from the Tick data cache container, and process it in the order of extended data and trading data; Before processing each piece of market-related data, first determine whether there are any orders for the current contract. If there are orders generated by the entrusted trading instructions, use the current market-related data to perform matching using the simulated matching mechanism, determine whether it can be traded. If it can be traded, generate a transaction record and update the information of the simulated trading account; When processing each piece of market-related data, first use this piece of market-related data to update the latest data in the Tick data cache container, call the order flow strategy for calculation, generate trading information, and the simulated trading account generates trading instructions including the entrusted trading instructions and cancel order trading instructions based on the trading information, position status, and capital information; After calling the order flow strategy for calculation, process the cancel order trading instructions; Before the end of each loop, notify the Tick data display interface to refresh and cache the data required for the backtest report calculation.

7. The calculation method of order flow strategy backtesting according to claim 6, characterized in that It further includes: Manage the simulated trading account. Specifically: Manage the information of the simulated trading account including the position information, entrustment information, transaction information, and capital information, and provide an interface to support generating the trading instructions based on the trading information; At the same time, before processing each piece of market-related data, first determine whether there are any orders for the current contract. If there are orders generated by the entrusted trading instructions, use the current market-related data to perform matching using the simulated matching mechanism, where the simulated matching mechanism is based on the order book data simulation matching mechanism, convert the trading instructions into user positions, and update the information including the position information, entrustment information, transaction information, and capital information in real time.

8. An order flow strategy backtesting calculation system for performing the calculation method of order flow strategy backtesting as described in any one of claims 1-7, characterized in that, It includes: A server module for establishing a Tick data service cluster, and the Tick data service cluster is used for forwarding and storing market-related data; The backtest parameter setting module is used to select the order flow strategy to be backtested, the backtest date to be backtested in the Tick data display interface, and set the initial position information and initial capital information of the simulated trading account; The initialization backtest module is used to initialize the backtest module after starting the backtest task; The data application module is used to start a calculation thread and apply for the market-related data of all contracts on the backtest date after the initialization of the backtest module is completed, wherein the contracts used for the backtest task are written through the function interfaces provided in the order flow strategy; The backtest process calculation module is used to call the order flow strategy to calculate the market-related data in a loop; The backtest report calculation module is used to calculate the backtest report after the calculation is completed and notify the Tick data display interface to refresh.

9. A computer device, including a memory and one or more processors, wherein computer code is stored in the memory, and when the computer code is executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, wherein the computer-readable storage medium stores computer code, and when the computer code is executed, the method according to any one of claims 1 to 7 is executed.