Futures quantification strategy back testing method, device and equipment and storage medium
By constructing the monthly futures contract data for multiple delivery years and months in the backtesting time interval, the high cost problem caused by the large amount of data in the backtesting futures quantitative strategy is solved, saving storage space and network bandwidth is achieved, and the return is improved. Test efficiency.
Patent Information
- Application Number
- CN202410928841.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-11-08
AI Technical Summary
During the backtesting process of futures quantitative strategy, the amount of data in historical futures contracts is large, resulting in high backtesting costs, and requires pre-storing historical data, occupying a large amount of storage space and network bandwidth.
By obtaining continuous contract data, including the main force, the current month and the next month contract, the monthly futures contract data of multiple delivery years and months in the backtesting time interval are constructed, and the backtesting is carried out, avoiding the need to pre-store historical data and reducing storage and network occupation.
It effectively reduces the cost of backtesting, saves storage space and network bandwidth, improves backtesting efficiency, and meets the backtesting needs.
Smart Images

Figure CN118917942A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of quantitative backtesting technology, and in particular, to a backtesting method, device, equipment and storage medium for a futures quantitative strategy. Background Art
[0002] Quantitative strategy, also known as quantitative trading strategy, refers to the simulation, analysis, judgment and trading of financial markets through computers and other tools. Quantitative strategies are generally evaluated through backtesting methods to verify the effectiveness and feasibility of quantitative strategies.
[0003] At present, when backtesting futures quantitative strategies, the contract data of historical futures contracts are often stored in advance, and then backtesting is performed based on the stored contract data. However, due to the large amount of contract data of historical futures contracts, there is a problem of high backtesting costs. Summary of the invention
[0004] The present application provides a backtesting method, apparatus, device and storage medium for a futures quantitative strategy to reduce the backtesting cost of the futures quantitative strategy.
[0005] In a first aspect, the present application provides a backtesting method for a futures quantitative strategy, comprising: obtaining a futures quantitative backtesting strategy for a target underlying asset, and determining a backtesting time interval based on the futures quantitative backtesting strategy; obtaining continuous contract data for the target underlying asset, the continuous contract data comprising at least one of the following: a main continuous contract, a continuous contract for the current month, and a continuous contract for the next month; constructing, based on the continuous contract data, contract data for monthly futures contracts of the target underlying asset under multiple delivery years and months within the backtesting time interval; and backtesting the futures quantitative backtesting strategy based on the contract data for monthly futures contracts under multiple delivery years and months.
[0006] In a second aspect, the present application provides a backtesting device for futures quantitative strategies, including: an acquisition and determination module, used to: acquire the futures quantitative backtesting strategy of the target subject, and determine the backtesting time interval based on the futures quantitative backtesting strategy; a first acquisition module, used to: acquire continuous contract data of the target subject, the continuous contract data including at least one of the following: main continuous contract, current month continuous contract, next month continuous contract; a first construction module, used to: construct the contract data of monthly futures contracts of the target subject under multiple delivery years and months within the backtesting time interval according to the continuous contract data; a backtesting module, used to: backtest the futures quantitative backtesting strategy according to the contract data of monthly futures contracts under multiple delivery years and months.
[0007] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory, the memory being used to store a computer program, the processor being used to call and run the computer program stored in the memory, and executing the method in the first aspect or its various implementations.
[0008] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program enables a computer to execute the method in the first aspect or its various implementations.
[0009] In a fifth aspect, the present application provides a computer program product, comprising computer program instructions, which enable a computer to execute the method in the first aspect or its various implementations.
[0010] In a sixth aspect, the present application provides a computer program, which enables a computer to execute the method in the first aspect or its various implementations.
[0011] In the above process, since most of the futures trading investments are basically concentrated in the continuous contracts of the current month and the continuous contracts of the next month, the contract data of the monthly futures contracts under multiple delivery years and months within the backtest time interval are constructed based on the continuous contracts including them, and backtesting is performed based on the contract data obtained by the construction. This can not only meet the backtesting needs, but also eliminate the need to pre-store the contract data of historical futures contracts, thereby saving storage space and reducing backtesting costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0013] Figure 1 An application scenario diagram provided for an embodiment of the present application;
[0014] Figure 2 A flow chart of a backtesting method for a futures quantitative strategy provided in an embodiment of the present application;
[0015] Figure 3 A schematic diagram of a backtesting method for a futures quantitative strategy provided in an embodiment of the present application;
[0016] Figure 4 A schematic diagram of another backtesting method for futures quantitative strategy provided in an embodiment of the present application;
[0017] Figure 5 A schematic diagram of another backtesting method for futures quantitative strategy provided in an embodiment of the present application;
[0018] Figure 6 A schematic diagram of a backtesting device 600 for a futures quantitative strategy provided in an embodiment of the present application;
[0019] Figure 7 A schematic block diagram of an electronic device 700 provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] As mentioned above, the prior art often stores the contract data of historical futures contracts in advance, and then performs backtesting based on the stored contract data, which results in a high backtesting cost.
[0023] In order to solve the above technical problems, the present application can construct the contract data of monthly futures contracts under multiple delivery years and months within the backtest time interval based on continuous contracts, and perform backtesting based on the contract data obtained by the construction. Among them, most of the trading investments in futures are basically concentrated in continuous contracts. Therefore, it can not only meet the backtesting needs, but also eliminate the need to pre-store the contract data of historical futures contracts, thereby saving storage space and reducing backtesting costs.
[0024] It should be understood that the technical solution of the present application can be applied to the following scenarios, but is not limited to:
[0025] In some achievable embodiments, the technical solution of the present application can be used in a futures quantitative backtesting scenario of the underlying asset. For example, it can be applied to a quantitative backtesting scenario for cotton futures, and the present application does not impose any restrictions on this.
[0026] In some possible implementations, Figure 1 An application scenario diagram provided for an embodiment of the present application, such as Figure 1As shown, the application scenario may include a terminal device 110 and an electronic device 120. The terminal device 110 and the electronic device 120 may be connected via a wired network or a wireless network.
[0027] Among them, the terminal device 110 can be installed with a client, and the user can select the target underlying asset and its futures quantitative backtesting strategy based on the client. Correspondingly, the electronic device 120 can obtain the futures quantitative backtesting strategy of the target underlying asset and determine the backtesting time interval of the futures quantitative backtesting strategy. After that, the electronic device 120 can construct the contract data of the monthly futures contracts under multiple delivery years and months within the backtesting time interval from the continuous contract data, and perform backtesting based on the constructed contract data.
[0028] Exemplarily, the terminal device 110 may be a mobile phone, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, a vehicle-mounted device, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) or virtual reality (VR) device, etc., but is not limited thereto. The electronic device 120 may be a server, a server cluster consisting of multiple servers, or a cloud platform control center, which is not limited in the embodiments of the present application.
[0029] also, Figure 1 The number of terminal devices and electronic devices shown is only exemplary, and may actually include other numbers of terminal devices and electronic devices, which is not limited in this application.
[0030] In some other possible implementations, the technical solution of the present application can be executed by the above-mentioned terminal device 110, and the present application does not impose any limitation on this.
[0031] It should be noted that in the specific implementation of this application, contract data, futures quantitative backtesting strategies, backtesting time intervals, static data and other related data are involved. When the embodiments of this application are applied to specific products or technologies, user permission, consent or authorization is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0032] After introducing the application scenarios of the embodiments of the present application, the technical solution of the present application will be described in detail below:
[0033] Figure 2A flow chart of a backtesting method for a futures quantitative strategy provided in an embodiment of the present application, the method can be performed as follows Figure 1 The electronic device 120 shown in the figure performs, but is not limited to this. Figure 2 As shown, the method may include the following steps:
[0034] S210: Obtain the futures quantitative backtesting strategy of the target underlying asset, and determine the backtesting time interval based on the futures quantitative backtesting strategy;
[0035] S220: Acquire the continuous contract data of the target underlying asset, where the continuous contract data includes at least one of the following: the main continuous contract, the current month continuous contract, and the next month continuous contract;
[0036] S230: constructing the contract data of the monthly futures contracts of the target underlying asset under multiple delivery years and months within the backtest time interval according to the continuous contract data;
[0037] S240: Backtest the futures quantitative backtesting strategy based on the contract data of monthly futures contracts under multiple delivery years and months.
[0038] The following is an explanation and description of the terms involved in this application:
[0039] Futures, a type of financial derivative, refers to a contract to buy or sell a certain amount of the underlying asset at a predetermined price at a certain time in the future. The underlying asset in the futures contract, that is, the futures product, can be a physical commodity such as metals, crude oil, agricultural products, etc., or it can be a financial asset such as foreign exchange, bonds, etc.
[0040] That is to say, the target subject matter in the present application may be any one of metals such as gold, crude oil, agricultural products, foreign exchange, and bonds, but is not limited thereto.
[0041] The futures quantitative backtesting strategy can be a backtesting strategy related to futures delivery, or a backtesting strategy related to cross-period arbitrage or cross-product arbitrage (i.e., related to delivery month change), and this application does not impose any restrictions on this.
[0042] The main contract refers to the contract with the largest trading volume or the contract with the largest open interest. Generally speaking, the contract with the largest open interest is usually also the contract with the largest trading volume. The main contract will generally change over time and with changes in market conditions. The change of the main contract refers to the change of the contract month with the most active trading (i.e. the contract with the largest trading volume or the largest open interest) in a certain futures product.
[0043] The main continuous contract is a contract sequence composed of the main contracts of the same futures products in different time periods. The K-line chart corresponding to the main continuous contract is formed by connecting the K-line charts of the main contracts of the same futures products in different time periods, which can show the market situation of a certain futures product over a longer time dimension.
[0044] The current month continuous contract is a contract sequence composed of the futures contracts of the delivery month closest to the current time. The K-line chart corresponding to the current month continuous contract is formed by connecting the K-line charts corresponding to the above-mentioned futures contracts of each delivery month, which can show the market conditions of a certain futures product over a longer time dimension.
[0045] The next month continuous contract is a contract sequence composed of the futures contracts of the second closest delivery month to the current time. The K-line chart corresponding to the next month continuous contract is formed by connecting the K-line charts corresponding to the above-mentioned futures contracts of each delivery month, which can show the market conditions of a certain futures product in a longer time dimension.
[0046] Monthly futures contracts, also known as monthly futures contracts, are standardized contracts listed on futures exchanges with a delivery date in a specific month. Monthly futures contracts can be represented by a trading code and the expiration month of the contract. For example, the SHILI2310 contract refers to a monthly futures contract with a trading code of "SHILI" and an expiration month of October 2023.
[0047] In one embodiment, the electronic device may determine the backtesting time interval based on the futures quantitative backtesting strategy in any of the following ways, but is not limited thereto:
[0048] Method 1: If the futures quantitative backtesting strategy includes a backtesting time interval, the electronic device can perform text extraction on the futures quantitative backtesting strategy to obtain the backtesting time interval.
[0049] Exemplarily, the electronic device may first read the futures quantitative backtesting strategy, and then, based on natural language processing technology or regular expressions, identify and extract keywords related to date and time in the futures quantitative backtesting strategy to obtain the backtesting time interval.
[0050] Method 2: The electronic device can first determine the target strategy type of the futures quantitative backtest strategy according to the profit target of the futures quantitative backtest strategy; then, according to the target strategy type, determine the target backtest duration corresponding to the target strategy type; finally, determine the backtest time interval according to the target backtest duration and the backtest initial time, and the futures quantitative backtest strategy includes the backtest initial time. Among them, the target strategy type can include any of the following: short-term strategy type, medium-term strategy type, and long-term strategy type, among which the futures quantitative backtest strategy of the short-term strategy type refers to a strategy with a short backtest duration and a high profit target, and its corresponding backtest duration can be 3 months; the futures quantitative backtest strategy of the medium-term strategy type refers to a strategy with a medium backtest duration and a medium profit target, and its corresponding backtest duration can be 1 year; the futures quantitative backtest strategy of the long-term strategy type refers to a strategy with a long backtest duration and a stable profit target, and its corresponding backtest duration can be 2 years.
[0051] For example, assuming that the initial backtesting time included in the futures quantitative backtesting strategy is June 2023 and the target strategy type of the futures quantitative backtesting strategy is a short-term strategy type, the electronic device can determine the backtesting time interval as [June 2023, August 2023].
[0052] The following embodiment will introduce the process of constructing the contract data of the monthly futures contracts of the target subject matter under multiple delivery years and months within the backtest time interval based on the continuous contract data:
[0053] In one embodiment, the continuous contract data includes at least one of the following: the main continuous contract, the continuous contract of the current month, and the continuous contract of the next month, but is not limited thereto.
[0054] In one embodiment, the electronic device can first determine the main contract switching date and the last trading day within the backtest time interval based on the continuous contract data; then, determine multiple delivery years and months within the backtest time interval based on the main contract switching date, and extract the contract data of the monthly futures contracts under multiple delivery years and months from the continuous contract data based on the last trading day and the multiple delivery years and months.
[0055] Among them, the contract data of the monthly futures contract may include the futures market data of the corresponding delivery year and month, and the futures market data may be historical K-line data, but is not limited thereto.
[0056] Specifically, the electronic device can determine the main contract switching date within the backtest time interval and the last trading day of the monthly futures contracts corresponding to different delivery years and months within the backtest time interval based on the market data in the continuous contract data; then, the monthly futures contracts used by the main continuous contracts in different backtest time periods within the backtest time interval can be determined based on the main contract switching date, and multiple delivery years and months within the backtest time interval are determined based on the years and months corresponding to the delivery dates of the monthly futures contracts used by the main continuous contracts in the different backtest time periods; then, based on the last trading days of the monthly futures contracts corresponding to different delivery years and months in the multiple delivery years and months within the above-mentioned backtest time interval, the contract data of the monthly futures contracts under multiple delivery years and months are extracted from the continuous contract data (specifically, the continuous contract of the current month and the continuous contract of the next month).
[0057] The following is an introduction to the process of determining the main contract switching date and the last trading day:
[0058] In one embodiment, the above-mentioned determining the main contract switching date within the backtest time interval and the last trading day of the futures contracts of the corresponding months of different delivery years and months based on the market data in the continuous contract data includes: in the same time range, in response to the market data of the main continuous contract, the market data of the continuous contract of the current month or the continuous contract of the next month is converted from the same to different, and the time corresponding to the first conversion point from the same to different is determined as the main contract switching date of the main continuous contract; in the same time range, in response to the market data of the main continuous contract, the market data of the continuous contract of the current month or the continuous contract of the next month is converted from different to the same, and the time corresponding to the second conversion point from different to the same is determined as the last trading day of the futures contracts of the corresponding months of different delivery years and months.
[0059] Combined with the above explanations of the main continuous contract, the current month continuous contract and the next month continuous contract, it can be understood that: the futures market data involved in the main continuous contract is spliced from the futures market data of the most active futures contract of a specific month, and the corresponding splicing time point is the main contract switching day; the futures market data involved in the current month continuous contract (or the next month continuous contract) is spliced from the futures market data of the specific month futures contract corresponding to the current month (or the next month), and the corresponding splicing time point is the last trading day of the specific month futures contract. Therefore, the electronic device can determine the market splicing point, i.e., the main contract switching day and the last trading day, based on the above splicing rules of the continuous contract data and the market data.
[0060] For example, Figure 3As shown in the figure, in the main continuous contracts, the futures market data before the first main switching day (i.e. time period A) is the futures market data of the most active monthly futures contract SHILI2310, and the futures market data after the first main switching day and before the second main switching day (time period B and time period C) is the futures market data of the most active monthly futures contract SHILI2311 during this period; and in the continuous contracts of the same month, the futures market data before the first last trading day (i.e. time period A and time period B) is mainly the futures market data of the monthly futures contract SHILI2310, and the first last trading day The futures market data after the last trading day of the previous month and before the second last trading day (i.e., time period C and time period D) are mainly based on the monthly futures contract SHILI2311, that is, the futures market data of the main continuous contract and the futures market data of the current month continuous contract are the same in time period A, different in time period B, and the same in time period C; that is, after the last trading day of the previous month and before the main switching day of the current month, the market data of the main continuous contract is the same as the market data of the current month continuous contract; after the main switching day of the previous month and before the last trading day of the current month, the market data of the main continuous contract is different from the market data of the current month continuous contract. Therefore, it can be determined that the conversion time point when the market data of the main continuous contract and the market data of the current month continuous contract (or the next month continuous contract) in the same time range are converted from the same to different is the main contract switching day in the main continuous contract; the conversion time point when the market data of the main continuous contract and the market data of the current month continuous contract (or the next month continuous contract) in the same time range are converted from different to the same is the last trading day of the corresponding monthly futures contracts of different delivery years and months (i.e., the monthly futures contracts involved in the current month continuous contract or the next month continuous contract).
[0061] The following is an introduction to the process of determining multiple delivery years and months within the backtest time interval:
[0062] It should be noted that the above-mentioned multiple delivery years and months are the months to which the delivery dates of the main contracts corresponding to different backtesting time periods within the backtesting time interval belong, that is, the months to which the delivery dates of the specific futures month contracts required by the futures quantitative backtesting strategy belong, and the delivery years and months involved in the continuous contract data are the time intervals of the existing futures market data. Therefore, the electronic device can determine the delivery years and months to which the main contracts corresponding to different backtesting time periods within the above-mentioned backtesting time interval belong based on the intersection of the main contract switching date involved in the continuous contract data and the time of the actual backtesting operation.
[0063] In general, the time range corresponding to the delivery year and month involved in the acquired continuous contract data is greater than the time range corresponding to the actual backtesting operation time. Therefore, the electronic device can extract multiple delivery years and months within the backtesting time interval from the continuous contract data, and construct the contract data of the monthly futures contracts under the multiple delivery years and months.
[0064] For example, Figure 3 As shown, within the backtesting interval (time period A to time period D), according to the main contract switching date (i.e., the main switching date) determined in the previous sequence, it can be determined that the backtesting interval includes three main contracts corresponding to different backtesting time periods: the main contract 1 corresponding to time period A, the main contract 2 corresponding to time period B and time period C, and the main contract 3 corresponding to time period D; among them, the main contract 1 under time period A uses the monthly futures contract SHILI 2310 with a delivery year and month of October 23, the main contract 2 under time period B and time period C uses the monthly futures contract SHILI2311 with a delivery year and month of November 23, and the main contract 3 under time period D uses the monthly futures contract SHILI2312 with a delivery year and month of October 23. Therefore, within the backtesting interval (time period A to time period D), the month and year corresponding to the delivery date of the monthly futures contracts used by the main contracts in different backtesting time periods are 2310, 2311 and 2312, that is, the delivery year and month include 2310 to 2312, and the contract data of the monthly futures contracts corresponding to the delivery year and month need to be obtained later.
[0065] It is understandable that after determining the monthly futures contract used by the main contract in different backtesting time periods according to the main contract switching date, when placing an order for the main contract during the backtesting process, the backtesting operation can be performed based on the futures market data corresponding to the monthly futures contract actually used by the main contract to improve the accuracy of the backtesting.
[0066] For example, assuming that a backtesting time point is time point b1 within time period B, the futures quantitative backtesting strategy includes placing an order for the main contract at time point b1. At this time, the main contract 2, that is, the monthly futures contract SHILI2311, is triggered at time point b1 to place an order.
[0067] Furthermore, based on the last trading day obtained above, the month futures contract used by the current month contract or the far month contract in different backtesting time periods can also be determined. When placing an order for the main contract or the far month contract during the backtesting process, the backtesting operation can be performed based on the futures market data corresponding to the month futures contract actually used by the current month contract or the far month contract to improve the backtesting accuracy.
[0068] Assume that a backtest time is time point b2 within time period B. The futures quantitative backtest strategy includes placing an order for a far-month contract at time point b2. At this time, the far-month contract at time point b2 actually uses the month futures contract SHILI2312. The month futures contract SHILI 2312 triggered at time point b2 is used as the far-month contract to place an order.
[0069] As mentioned above, in the backtesting process, it is necessary to use the contract data of the monthly futures contracts of the delivery year and month involved in the backtesting time interval. After determining the delivery year and month involved in the backtesting time interval, the contract data of the monthly futures contracts under multiple delivery years and months can be extracted from the continuous contract data according to the last trading day of the monthly futures contracts corresponding to different delivery years and months. Among them, the contract data mainly includes the futures market data of the monthly futures contracts.
[0070] The following is an introduction to the process of extracting contract data for monthly futures contracts under multiple delivery years and months:
[0071] Combined with the above explanations of the continuous contracts of the current month and the continuous contracts of the next month, it can be seen that the futures market data in the futures contract of a specific month is included in the futures market data of the continuous contracts of the current month and the futures market data of the continuous contracts of the next month. According to the last trading days of the continuous contracts of the current month and the continuous contracts of the next month, the futures market data of the futures contract of the specific month can be separated from the futures market data of the continuous contracts of the current month and the futures market data of the continuous contracts of the next month, and the (partial) futures market data of the futures contract of the specific month separated from the continuous contracts of the current month and the (partial) futures market data of the futures contract of the specific month separated from the continuous contracts of the next month are spliced to obtain the futures market data of the futures contract of the specific month, that is, the contract data of the futures contract of the month under a specific delivery year and month within the backtesting interval are obtained.
[0072] Exemplarily, the above-mentioned extracting the contract data of the monthly futures contracts under multiple delivery years and months from the continuous contract data includes: for the monthly futures contract of the first delivery year and month among the multiple delivery years and months, obtaining the first last trading day of the monthly futures contract of the first delivery year and month and the second last trading day of the monthly futures contract of the second delivery year and month, wherein the second delivery year and month is the delivery year and month previous to the first delivery year and month; extracting the first contract data before the second last trading day from the continuous contracts of the current month; extracting the second contract data before the first last trading day from the continuous contracts of the next month; and splicing the first contract data and the second contract data to obtain the contract data of the monthly futures contract of the first delivery year and month.
[0073] For example, combined with Figure 3 Based on the above content, the electronic device can splice the market data of the futures contract SHILI2311 before the last trading day of October in the next month's continuous contract with the market data of the futures contract SHILI2311 before the last trading day of November in the current month's continuous contract to obtain the contract data (specifically market data) of the futures contract SHILI2311 in November of 23 years.
[0074] After obtaining the contract data of the monthly futures contracts under each delivery year and month within the backtesting interval, the contract data of the monthly futures contracts under each delivery year and month can be stored corresponding to the specific delivery year and month respectively for use in subsequent backtesting.
[0075] It is understood that futures are a type of derivative. Underlying, also known as underlying a sset or underlying security, refers to the underlying asset or subject matter of an option, futures, stock or other derivative.
[0076] In the financial market, the prices of many derivatives change based on the price changes of their corresponding underlying assets or subject matter. For example, the subject matter of a futures contract is also an underlying asset, and the fluctuation of futures prices changes based on the price fluctuations of its underlying asset. For example, the underlying asset of a crude oil futures contract is crude oil, and the changes in contract prices are usually based on the changes in crude oil prices. Therefore, crude oil is the underlying asset or subject matter of a crude oil futures contract, also known as Underlying.
[0077] Derivatives are derived from many underlying assets with different expiration dates, that is, hundreds or even tens of thousands of underlying assets can be derived from one underlying asset, so there will be more corresponding contract data. For example, a futures contract has an expiration date every month. If the backtesting time interval is 10 years, then data for 12*10=120 contracts are required.
[0078] Therefore, if the market data of the futures contracts of the specific months required for backtesting are stored in advance before backtesting, and downloaded to the local computer for backtesting during backtesting, then due to the large amount of corresponding contract data, more computer hard disk will be occupied, resulting in a large storage cost, and when downloading contract data in subsequent backtesting, more network download bandwidth will be occupied, increasing the waiting time for backtesting.
[0079] In the technical solution of the present application, only the continuous contract data needs to be cached (specifically including the futures market data corresponding to the main continuous contract, the futures market data corresponding to the continuous contract of the current month, and the futures market data corresponding to the continuous contract of the next month). Then, when the backtest is started, the futures market data corresponding to the specific month futures contracts involved in the continuous contract (specifically the specific month futures contracts involved in the continuous contract of the current month and the continuous contract of the next month) are cut and spliced to construct the contract data of the monthly futures contracts of different delivery years and months within the backtest time interval, and the constructed contract data is used for backtesting, thereby not only ensuring that the backtesting effect meets the backtesting requirements, but also reducing storage costs, reducing the occupancy of network download bandwidth, and reducing the waiting time for backtesting preparation.
[0080] After obtaining the contract data of the monthly futures contracts in different delivery years and months, the futures quantitative backtesting strategy can be backtested according to the contract data of the monthly futures contracts under these delivery years and months. In one embodiment, different backtesting time points and futures contract trading operations at the backtesting time points can be determined according to the futures quantitative backtesting strategy; the futures market data corresponding to the backtesting time points can be obtained in the monthly futures contracts corresponding to different delivery years and months; the futures quantitative backtesting strategy can be backtested based on the futures market data corresponding to the backtesting time points and the futures contract trading operations.
[0081] Specifically, based on the futures quantitative backtesting strategy, futures contract trading operations at different backtesting time points can be triggered. In response to the futures contract trading operations at the backtesting time points, the contract type of the futures contract operated by the futures contract trading operations can be obtained, wherein the contract type includes but is not limited to the main contract type, the current month contract type, and the next month contract type, etc.; then, according to the contract type of the futures contract trading operation and the backtesting time point, the target month futures contract of the futures contract trading operation is determined from the monthly futures contracts of different delivery years and months; finally, according to the futures market data in the contract data of the target month futures contract, the futures contract trading operation is executed to obtain the backtesting result.
[0082] Specifically, after obtaining the contract type of the futures contract transaction operation, the target month futures contract used in the contract type can be determined from the month futures contracts of different delivery years and months according to the main contract switching date, the last trading day of the corresponding month futures contracts of different delivery years and months, and the backtesting time point. Figure 3 As shown, within the backtest interval (time period A to time period D), the backtest time point is a time point in time period B. If the contract type is the main contract type, the main contract at the backtest time point can be determined to use the month futures contract SHILI2311 according to the backtest time point and the main contract switching date, that is, the month futures contract SHILI2311 is determined as the target month futures contract; if the contract type is the current month contract type, the current month contract at the backtest time point can be determined to use the month futures contract SHILI2310 according to the backtest time point and the last trading day of the corresponding month futures contract of different delivery years and months, that is, the month futures contract SHILI2310 is determined to be the target month futures contract; similarly, if the contract type is the next month contract type, the next month contract at the backtest time point can be determined to use the month futures contract SHILI2311 according to the backtest time point and the last trading day of the corresponding month futures contract of different delivery years and months, that is, the month futures contract SHILI2311 is determined to be the target month futures contract.
[0083] After determining the target month futures contract used for the futures contract trading operation, the futures market data corresponding to the backtest time point is determined from the contract data corresponding to the target month futures contract according to the backtest time point, and then the futures contract trading operation is executed according to the futures market data corresponding to the backtest time point to obtain the backtest result.
[0084] Furthermore, in one embodiment, after constructing the contract data of the monthly futures contracts under multiple delivery years and months within the backtest time interval, it may also include: determining the main contract switching date corresponding to the target subject matter and the last trading day of the monthly futures contracts corresponding to different delivery years and months according to the market data in the continuous contract data; determining the market coverage time period of the futures market data of the contract data of the monthly futures contracts corresponding to different delivery years and months in the main contract corresponding to the target subject matter, the current month contract and the next month contract according to the main contract switching date and the last trading day of the monthly futures contracts corresponding to different delivery years and months; and further determining the market coverage time period of the futures market data of the contract data of the monthly futures contracts corresponding to different delivery years and months in the main contract corresponding to the target subject matter according to the futures market data of the monthly futures contracts corresponding to different delivery years and months. According to the market coverage period on the target underlying, the first market mapping relationship between the futures market data of the main contract and the futures market data of the corresponding month futures contracts of different delivery years and months is constructed; according to the market coverage period of the futures market data of the corresponding month futures contracts of different delivery years and months on the target underlying, the second market mapping relationship between the futures market data of the current month contract and the futures market data of the corresponding month futures contracts of different delivery years and months is constructed; according to the market coverage period of the futures market data of the corresponding month futures contracts of different delivery years and months on the target underlying, the third market mapping relationship between the futures market data of the next month contract and the futures market data of the corresponding month futures contracts of different delivery years and months is constructed. Among them, the corresponding month futures contracts of different delivery years and months are also the monthly futures contracts under different delivery years and months.
[0085] Accordingly, the futures quantitative backtesting strategy is backtested according to the contract data of the monthly futures contracts under multiple delivery years and months, which may specifically include: obtaining the futures contract trading operations triggered by the futures quantitative backtesting strategy at different backtesting time points, and in response to the futures contract trading operations at the backtesting time points, the contract type of the futures contract trading operations may be obtained; further, according to the contract type of the futures contract trading operations, the target market mapping relationship is determined from the first market mapping relationship, the second market mapping relationship, and the third market mapping relationship, and according to the backtesting time point, the futures market data corresponding to the futures contract trading operation is determined from the target market mapping relationship to execute the futures contract trading operation and obtain the backtesting result.
[0086] Among them, determining the futures market data of the corresponding monthly futures contracts for different delivery years and months, in the market coverage period of the main contract (or the current month contract, or the next month contract) corresponding to the target underlying, refers to determining the specific monthly futures contracts of the year and month used by the main contract (or the current month contract, or the next month contract) in different time periods; for example, combined with Figure 3 As shown, the market coverage period of the main contract for the 30-month futures contract SHILI2310 is time period A, the market coverage period of the 30-month futures contract SHILI2311 is time period B and time period C, and the market coverage period of the 30-month futures contract SHILI2312 includes time period D. It can also be understood that the main contract uses the 30-month futures contract SHILI2310 in time period A, the main contract uses the 30-month futures contract SHILI2311 in time periods B and time periods C, and the main contract uses the 30-month futures contract SHILI2312 in time period D.
[0087] After determining the futures market data of the corresponding monthly futures contracts for different delivery years and months, and the market coverage period of the main contract (or the current month contract, or the next month contract) corresponding to the target underlying asset, a mapping relationship between the futures market data of the main contract (or the current month contract, or the next month contract) at different time points and the futures market data of the corresponding monthly futures contracts for each specific year and month can be constructed based on the market coverage period; for example, the first market mapping relationship is established between the futures market data of the main contract in time period A and the futures market data of the corresponding time period in the monthly futures contract SHILI2310, and the first market mapping relationship is established between the futures market data of the main contract in time period B and time period C and the futures market data of the corresponding time period in the monthly futures contract SHILI2311, and so on. The second mapping relationship and the third mapping relationship are constructed in the same way, which will not be elaborated here.
[0088] When performing specific backtesting in the future, according to the contract type of the futures contract trading operation, the futures market data of the corresponding futures contract (such as the main contract, the current month contract or the next month contract) at the backtest time point is determined from the corresponding market mapping relationship to execute the futures contract trading operation and realize the backtesting. For example, the backtesting time point is a time point in time period B. If the contract type is the current month contract type, the target market mapping relationship is the second market mapping relationship. According to the backtesting time point and the second market mapping relationship corresponding to the main contract, the monthly futures contract SHILI2310 used by the current month contract and the futures market data at the backtesting time point in the monthly futures contract SHILI2310 can be determined, and then according to the futures market data corresponding to the backtesting time point, the futures contract trading operation is executed to obtain the backtesting result. It can be understood that if the contract type is the main contract type, the target market mapping relationship is the first market mapping relationship, and if the contract type is the next month contract type, the target market mapping relationship is the third market mapping relationship.
[0089] By storing the market mapping relationship between the futures market data of the main contract, current contract, next month contract, etc. and the futures contracts of the specific year and month (or the delivery year and month), when executing the futures contract trading operations in the backtesting process, the corresponding futures market data can be directly found according to the backtesting time point and the market mapping relationship, thereby improving the efficiency of futures backtesting.
[0090] In one embodiment, before constructing the contract data of monthly futures contracts under multiple delivery years and months within the backtest time interval based on the continuous contract data, the electronic device can first determine the main contract switching date corresponding to the target underlying asset and the last trading day of the monthly futures contracts corresponding to different delivery years and months based on the market data in the continuous contract data (this has been introduced in the above embodiment and will not be repeated in this application); then, based on the main contract switching date and the last trading day of the monthly futures contracts corresponding to different delivery years and months, determine the specific monthly futures contracts and contract time periods involved in the continuous contract data, and based on the specific monthly futures contracts and contract time periods, determine the time mapping relationship between the specific monthly futures contracts and contract time periods.
[0091] Accordingly, when constructing the contract data of monthly futures contracts under multiple delivery years and months within the backtest time interval based on the continuous contract data, the electronic device can first determine the contract time period to be matched included in the backtest time interval; then, according to the contract time period to be matched and the time mapping relationship, determine the matching specific monthly futures contract corresponding to the contract time period to be matched from the specific monthly futures contracts involved in the continuous contract data; finally, the electronic device can construct the contract data of monthly futures contracts under multiple delivery years and months within the backtest time interval based on the matching specific monthly futures contracts.
[0092] The following is an introduction to the specific monthly futures contracts and contract time periods involved in the above continuous contract data:
[0093] Specifically, taking the continuous contract for the current month as an example, combined with the above introduction to the continuous contract for the current month, it can be known that the specific month futures contract involved in the continuous contract for the current month is: the month futures contract divided by the last trading day of the continuous contract for the current month.
[0094] The contract time period involved in the continuous contract of the current month (i.e., the contract time period having a time mapping relationship with the futures contract of the specific month involved in the continuous contract of the current month) is determined by the last trading day of the expiration month of the futures contract of the specific month and the last trading day of the month before the expiration month, specifically, the time period between the last trading day of the expiration month and the last trading day of the month before the expiration month; or, it can be determined by the last trading day of the expiration month of the futures contract of the specific month, the last trading day of the month before the expiration month, and the main contract switching day of the expiration month, specifically, the time period between the last trading day of the month before the expiration month and the main contract switching day of the expiration month, and the time period between the main contract switching day of the expiration month and the last trading day of the expiration month.
[0095] For example, Figure 3 As shown, the specific month futures contracts involved in the continuous contract of the current month include: SHILI2310, SHILI2311, and SHILI2312. The contract time periods with a time mapping relationship with the specific month futures contract SHILI2311 involved in the continuous contract of the current month are time period C and time period D, wherein time period D and time period C are the time periods between the last trading day of November (i.e., the expiration month of the specific month futures contract SHILI2311) and the last trading day of October (i.e., the month before the expiration month of the specific month futures contract SHILI2311), or time period C is the time period between the last trading day of October and the main contract switching day of November, and time period D is the time period between the last trading day of November and the main contract switching day of November.
[0096] Specifically, taking the next month continuous contract as an example, combined with the above introduction to the next month continuous contract, it can be known that the specific month futures contract involved in the next month continuous contract is: the month futures contract divided by the last trading day of the next month continuous contract.
[0097] The contract time period involved in the next month continuous contract (i.e., the contract time period having a time mapping relationship with the specific month futures contract involved in the next month continuous contract) is determined by the last trading day of the month before the expiration month and the last trading day of the second month before the expiration month of the futures contract of the specific month, specifically, the time period between the last trading day of the month before the expiration month and the last trading day of the second month before the expiration month; or, it can be determined by the last trading day of the month before the expiration month, the last trading day of the second month before the expiration month and the main contract switching day of the month before the expiration month of the futures contract of the specific month, specifically, the time period between the last trading day of the second month before the expiration month and the main contract switching day of the month before the expiration month, and the time period between the main contract switching day of the month before the expiration month and the last trading day of the month before the expiration month.
[0098] For example, Figure 3 As shown, the specific month futures contracts involved in the next month continuous contract include: SHILI2311, SHILI2312, SHILI2401. The contract time periods with a time mapping relationship with the specific month futures contract SHILI2312 involved in the next month continuous contract are time period C and time period D, where time period D and time period C are the time periods between the last trading day of November (i.e., the month before the expiration month of the specific month futures contract SHILI2312) and the last trading day of October (i.e., the second month before the expiration month of the specific month futures contract SHILI2311), or time period C is the time period between the last trading day of October and the main contract switching day of November, and time period D is the time period between the last trading day of November and the main contract switching day of November.
[0099] It should be noted that the contract time period involved in the main continuous contract and the content corresponding to the specific month futures contract are similar to the above content and will not be elaborated in this application.
[0100] The following is an introduction to the process of obtaining the contract data of monthly futures contracts under multiple delivery years and months based on the time mapping relationship:
[0101] Specifically, the electronic device can determine the contract time period to be matched included in the backtesting time interval based on the backtesting time interval. For example, the time parameter of the backtesting time interval can be converted to determine the contract time period to be matched included in the backtesting time interval; then, after determining the contract time period to be matched, the electronic device can match the contract time period to be matched and the contract time period involved in the continuous contract data in the time mapping relationship, and determine the specific month futures contract corresponding to the contract time period that matches the contract time period to be matched in the mapping relationship as the matching specific month futures contract; thereafter, the electronic device can extract and splice the matching specific month futures contracts in the continuous contract data to obtain the contract data of the month futures contracts under multiple delivery years and months within the backtesting time interval.
[0102] For example, combining the above and Figure 3 Assuming that the contract time period included in the backtest time interval is time period D, it can be determined that the contract time period to be matched is time period D; time period D has a time mapping relationship with SHILI2311 in the continuous contract of the current month, it can be determined that the futures contract of the specific month to be matched is SHILI2311.
[0103] In one embodiment, the electronic device can store the above-mentioned mapping relationship in the memory. When constructing the contract data, the time mapping relationship can be directly obtained from the memory, and then the monthly futures contract can be constructed in real time according to the time mapping relationship and the continuous contract data, so that the monthly futures contract within the backtesting interval can be determined efficiently, and there is no need to strip the contract data of the monthly futures contract of each specific delivery year and month from the continuous contract data in advance, which effectively saves storage space.
[0104] In one embodiment, before backtesting the futures quantitative backtesting strategy, the electronic device may, in response to the fact that monthly futures contracts under multiple delivery years and months are expired futures, obtain futures information corresponding to the target underlying asset; construct static data of the target underlying asset based on the futures information of the target underlying asset and the monthly futures contracts under multiple delivery years and months; accordingly, backtesting the futures quantitative backtesting strategy based on the contract data of the monthly futures contracts under multiple delivery years and months may include: determining multiple backtesting time points and futures contract trading operations at the multiple backtesting time points according to the futures quantitative backtesting strategy; obtaining futures market data corresponding to multiple backtesting time points from the monthly futures contracts under multiple delivery years and months in the static data; and backtesting the futures quantitative backtesting strategy based on the futures market data corresponding to the multiple backtesting time points and the futures contract trading operations.
[0105] It is understandable that the market data of the underlying assets that can be traded at the current time point is used in the backtesting process. However, the expired futures contracts are not the underlying assets that can be traded at the current time point, that is, the futures market data of the historical futures contracts are expired, that is, the contract data of the monthly futures contracts may be the contract data of expired futures contracts. The electronic device can first construct the static data of the monthly futures contracts corresponding to the target underlying assets. During the backtesting, the contract data of the expired monthly futures contracts can be supported through the static data, so that under the premise of not modifying the backtesting logic, when the historical market data is verified to be legal during the external access, that is, during the backtesting process, the contract data used in the backtesting is determined to be legal and not expired based on the static data.
[0106] Among them, the futures information corresponding to the target subject matter may include, but is not limited to: the futures identification, listing time, and futures name of the target subject matter (i.e., the futures traded by the futures contract); the static data of the target subject matter, including the futures information of the target subject matter, the monthly futures contracts corresponding to different delivery years and months, and their specific years and months, contract names, etc. Specifically, when constructing the static data of the target subject matter, the contract name of the monthly futures contract corresponding to the target subject matter can be constructed according to the futures identification and the specific years and months corresponding to the different monthly futures contracts, and then the static data of the target subject matter can be constructed according to the futures information, contract name, and the corresponding monthly futures contract. After the static data is constructed, the static data can be stored in the local memory for use in subsequent futures quantitative backtesting strategies.
[0107] After obtaining the futures quantitative backtesting strategy, the contract names of the monthly futures contracts in the local memory and static data can be matched based on the futures information and the backtesting time interval carried in the futures quantitative backtesting strategy to ensure the validity of the target underlying in the backtesting time interval and obtain the corresponding monthly futures contracts; specifically, the contract names of the monthly futures contracts in the static data can be segmented to determine the futures identifier and the specific year and month corresponding to the monthly futures contract, and then the futures information and the backtesting time interval carried in the futures quantitative backtesting strategy can be matched with the futures identifier and the specific year and month corresponding to the monthly futures contract in the static data respectively through the following formula (1):
[0108]
[0109] Among them, val represents the futures identifier carried in the futures quantitative backtesting strategy and the matching degree between the backtesting time interval and the static data, which can be used to measure the effectiveness of the futures contract corresponding to the futures identifier carried in the futures quantitative backtesting strategy within the backtesting time interval; x i (i=1, 2, ..., n) represents the futures information and backtesting time interval carried in the futures quantitative backtesting strategy, y i(i=1, 2, ..., n) represents the futures identifier corresponding to the monthly futures contract in the static data and its specific year and month. By matching the futures identifier and the backtesting time interval carried in the futures quantitative backtesting strategy with the static data, if the matching degree val is greater than or equal to the preset matching threshold, it is determined that the futures contract corresponding to the futures identifier carried in the futures quantitative backtesting strategy is valid in the backtesting time interval, and the corresponding monthly contract data in the static data is used as the data in the subsequent futures backtesting process.
[0110] It can be understood that after obtaining the contract data of the futures contracts corresponding to the different delivery years and months corresponding to the target underlying assets from the static data, the futures market data corresponding to the backtest time point is obtained, and the specific process of backtesting the futures quantitative backtesting strategy based on the futures market data corresponding to the backtest time point and the futures contract trading operation has been described in the above embodiments and will not be repeated here.
[0111] Furthermore, static data of the target underlying asset can also be constructed based on the futures information of the target underlying asset and the time mapping relationship between the futures contract of a specific month and the contract time period; when backtesting the futures quantitative backtesting strategy, the contract data of the monthly futures contracts under multiple delivery years and months within the backtesting time interval can be spliced in real time from the continuous contract data according to the backtesting time interval and the time mapping relationship between the futures contract of a specific month and the contract time period in the static data, and then the futures market data corresponding to the backtesting time point can be obtained from the contract data of the monthly futures contracts under multiple delivery years and months within the backtesting time interval, so as to backtest the futures quantitative backtesting strategy based on the futures market data corresponding to the backtesting time point and the futures contract trading operation.
[0112] It is understandable that by plotting futures prices with different expiration dates on a graph, a forward curve can be formed. Figure 4 As shown, there are two structures of forward curves: contango structure as shown in Figure 4 As shown in (a) in the figure, under this structure, the price of the near-month contract is lower and the price of the far-month contract is higher, and the K-line chart of the futures main contract will jump upward; the backwardation structure is as follows Figure 4 As shown in (b), under this structure, the price of the near-month contract is higher and the price of the far-month contract is lower, and the K-line chart of the main futures contract will jump down. The above gap is caused by the price difference between the old main contract and the new main contract when the futures switch to the main contract.
[0113] In futures trading, if you want to hold the main contract of a certain variety all the time, you need to continuously transfer positions, that is, close the near-month contract you hold and open the far-month contract, that is, transfer positions to change months. This operation will bring actual benefits due to premium or discount. In the backtesting of related technologies, the contract data corresponding to the main continuous contract (such as the contract price data of the main continuous contract, that is, the futures market data) is directly used for backtesting. Since the gap in the forward curve corresponding to the main continuous contract affects the futures quantitative backtesting strategy, the benefits of the gap part will be ignored or the profit and loss will be miscalculated, resulting in a certain deviation between the backtesting results and the actual strategy performance. For example, for the contango structure, when long positions in futures are transferred to another month, it is necessary to sell the near-month contract and buy the far-month contract, which should have resulted in a loss. However, in the backtesting of continuous contracts such as the main continuous contracts in the related technology, the upward gap in the forward curve corresponding to the continuous contract may cause it to be miscalculated as a profit. For the backwardation structure, when long positions in futures are transferred to another month, it is necessary to sell the near-month contract and buy the far-month contract, which should have resulted in a profit. However, in the backtesting of continuous contracts such as the main continuous contracts in the related technology, the downward gap in the forward curve corresponding to the continuous contract may cause it to be miscalculated as a loss.
[0114] In the technical solution of the present application, when backtesting the cross-period arbitrage futures strategy, the month futures contract corresponding to the near-month contract and the month futures contract corresponding to the far-month contract can be determined according to the backtest time point, and then the near-month contract is closed and the far-month contract is opened. The price difference between the closing price of the near-month contract and the opening price of the far-month contract will cause the account to generate certain profits or losses in the process of transferring positions, thereby restoring the impact of the forward curve, making the backtest results closer to the actual trading results, and realizing correct backtest verification.
[0115] Specifically, in one embodiment, the electronic device can respond to the futures quantitative backtesting strategy being a cross-period arbitrage futures strategy, and determine the first month futures contract corresponding to the near month contract and the second month futures contract corresponding to the far month contract from the monthly futures contracts under multiple delivery years and months according to the backtesting time point involved in the cross-period arbitrage futures strategy; perform a near month contract closing backtesting operation based on the market data in the contract data of the first month futures contract, and perform a far month contract opening backtesting operation based on the market data in the contract data of the second month futures contract; determine the backtesting result of the backtesting based on the trading results of the near month contract closing backtesting operation and the trading results of the far month contract opening backtesting operation.
[0116] Among them, in the cross-period arbitrage futures strategy, the near-month contract closing backtesting operation and the far-month contract opening backtesting operation can be triggered at the corresponding backtesting time point; among them, the contract type corresponding to the near-month contract closing backtesting operation is the current month contract type, that is, the near-month contract can refer to the current month contract at the backtesting time point, and the contract type corresponding to the far-month contract opening backtesting operation is the next month contract type, that is, the far-month contract can refer to the next month contract at the backtesting time point.
[0117] Specifically, according to the backtesting time point and the backtesting operation of closing the near-month contract and the backtesting operation of opening the far-month contract, the first-month futures contract used by the near-month contract and the second-month futures contract used by the far-month contract can be determined from the monthly futures contracts under multiple delivery years and months. At the same time, the first futures market data corresponding to the backtesting time point is determined from the first-month futures contract used by the near-month contract, and the second futures market data corresponding to the backtesting time point is determined from the second-month futures contract used by the far-month contract. Then, based on the first futures market data, a sell operation of the near-month contract is executed to realize the backtesting operation of closing the near-month contract, and based on the second futures market data, a buy operation of the far-month contract is executed to realize the backtesting operation of opening the far-month contract, thereby realizing the cross-period arbitrage futures strategy.
[0118] For example, when backtesting the cross-period arbitrage futures strategy, assuming that November 23, 2023 is the last delivery date of the SHILI 2311 futures contract, the backtesting time point is November 23, 2023. It can be determined that when executing the cross-period arbitrage futures strategy, the near-month contract is the month futures contract HSI2311, and the far-month contract is the month futures contract HSI2312. Then, according to the market data of November 23 in the near-month contract: HSI2311 futures contract, close the position and sell HSI2311, and according to the market data of November 23 in the far-month contract: HSI2312 futures contract, open a position and buy HSI2312, so that the shifting of positions and the change of months can be accurately restored, that is, the cross-period arbitrage futures strategy can be accurately implemented.
[0119] In one embodiment, the electronic device may first determine a plurality of backtesting instances required for backtesting; then, determine a plurality of backtesting instance groups based on the plurality of backtesting instances, wherein the backtesting instances in each backtesting instance group share the contract data of the monthly futures contracts under the common delivery month among the contract data of the monthly futures contracts under the multiple delivery years and months; then, the contract data of the monthly futures contracts under the common delivery month corresponding to each backtesting instance group may be stored in the same storage unit; finally, the plurality of backtesting instances may be executed based on the contract data of the monthly futures contracts under the common delivery month in the corresponding storage unit to backtest the futures quantitative strategy.
[0120] Among them, the electronic device can first determine the delivery year and month corresponding to the monthly futures contracts that need to be used in multiple backtesting instances; then, the backtesting instances using the monthly futures contracts corresponding to the same delivery year and month are grouped together to obtain multiple backtesting instance groups.
[0121] It can be understood that, compared with each backtesting instance separately storing the contract data of the month futures contract corresponding to the backtesting instance, the above technical solution can enable multiple backtesting instances to share the market data, i.e., contract data, of the same month futures contract, thereby reducing storage space usage and data redundancy, and improving the convenience of data management.
[0122] In one embodiment, the futures quantitative backtesting strategy includes a quantitative backtesting strategy for a combination futures contract. When backtesting the quantitative backtesting strategy for the combination futures contract, the electronic device can determine the contract type corresponding to each single futures contract in the combination futures contract from the futures contract trading operation for the combination futures contract, and the contract type includes a long contract type and a short contract type; according to the contract type of the single futures contract involved in the combination futures contract, determine the margin of the futures contract trading operation, and execute the futures contract trading operation based on the margin, so as to ensure that the backtesting result is closer to the actual transaction.
[0123] Among them, margin refers to the funds that must be deposited to cover possible losses in transactions and to maintain positions.
[0124] For example, for futures contracts with different expiration months and the same underlying asset, if the contract types are different, it can be determined that margin reduction is required. For example, the combined futures contract involves two futures contracts: SHILI2311 and SHILI2312. SHILI2311 is a long contract with a position on the buyer side, and SHILI2312 is a short contract with a position on the seller side. In the backtesting process, it can be determined that the margin used is not the sum of the margins of the above two contracts, but the maximum value of the margins of the two contracts.
[0125] The following is an introduction to the calculation process of the margin required for the same underlying asset:
[0126] Exemplarily, the electronic device may first determine the size of long contract positions of the same underlying asset and the size of short contract positions of the same underlying asset; then, determine the margin by multiplying the size of long contract positions of the same underlying asset and the size of short contract positions of the same underlying asset by different margin ratios (e.g., 10%, 9%, and 8%).
[0127] For example, the initial margin Deposit1 of the same underlying asset can be determined by formula (2):
[0128] Deposit1=MAX(∑(D1*10%), abs(∑(D2*10%))) formula (2)
[0129] Among them, MAX means to find the maximum value, abs means to find the absolute value, D1 and D2 respectively represent the size of long positions and short positions of the same underlying asset.
[0130] ∑(D1*10%) is the margin required for long positions, and abs(∑(D2*10%)) is the margin required for short positions.
[0131] For example, the Margin Call Deposit t2 of the same underlying asset can be determined by formula (3):
[0132] Deposit2=MAX(∑(D1*9%),abs(∑(D2*9%))) Formula (3)
[0133] Among them, ∑(D1*9%) is the margin required for long positions, and abs(∑(D2*9%)) is the margin required for short positions. Since the Margin Call margin is usually triggered when the account value drops to a certain level, more funds are deposited to maintain the position, so the margin ratio is reduced from 10% to 9%.
[0134] For example, the maintenance margin Deposit3 of the same underlying asset can be determined by formula (4):
[0135] Deposit3=MAX(∑(D1*10%),abs(∑(D2*10%))) Formula (4)
[0136] Among them, ∑(D1*8%) is the margin required for long positions, and abs(∑(D2*10%)) is the margin required for short positions. Since the maintenance margin is to maintain the minimum margin level in the account to ensure that the position will not be forced to close due to market fluctuations, the margin ratio is reduced from 10% to 8%.
[0137] It should be noted that the electronic equipment can adjust the above margin ratio according to the market conditions and exchange regulations involved in the backtest.
[0138] In one embodiment, in combination with the above, Figure 5As shown, the electronic device may include a quantitative module and a market background service module, and the quantitative module may include: a strategy request response module, a stock list module, a data storage module and a backtester, wherein the backtester includes: a backtest market backend and a data download module. The data download module of the backtester can download the data required for backtesting from the market backend, for example, obtain continuous contract data; and store the obtained data in the data storage module; then, the module for constructing specific monthly contracts of the backtest market backend can construct monthly contract market data according to the continuous contract data stored in the data storage module, that is, the contract data of the monthly futures contracts under multiple delivery months within the backtest time interval. In addition, the module for constructing specific monthly contracts can also construct static data and store it in the stock list module. When backtesting, the strategy request response module can communicate with the strategy script according to the protocol data, determine the futures quantitative backtesting strategy, obtain static data from the stock list module, control the backtest market backend to construct contract data, and the backtest market backend can also simulate futures delivery, perform data integration and data cleaning, etc.
[0139] It should be noted that all the above technical solutions can be combined in any way to form optional embodiments of the present application, which will not be described one by one here.
[0140] Figure 6 A schematic diagram of a backtesting device 600 for a futures quantitative strategy provided in an embodiment of the present application.
[0141] like Figure 6 As shown, the backtesting device 600 for futures quantitative strategy includes: an acquisition and determination module 601, a first acquisition module 602, a first construction module 603, a backtesting module 604, a first determination module 605, a second determination module 606, and a second construction module 607.
[0142] In one embodiment, an acquisition and determination module 601 is used to: acquire a futures quantitative backtesting strategy for a target underlying asset, and determine a backtesting time interval based on the futures quantitative backtesting strategy; a first acquisition module 602 is used to: acquire continuous contract data for a target underlying asset, the continuous contract data including at least one of the following: a main continuous contract, a continuous contract for the current month, and a continuous contract for the next month; a first construction module 603 is used to: construct, based on the continuous contract data, contract data for monthly futures contracts of the target underlying asset under multiple delivery years and months within the backtesting time interval; a backtesting module 604 is used to: backtest the futures quantitative backtesting strategy based on the contract data for monthly futures contracts under multiple delivery years and months.
[0143] In one embodiment, the first construction module 603 is specifically used to: determine the main contract switching date within the backtest time interval and the last trading day of the monthly futures contracts corresponding to different delivery years and months according to the market data in the continuous contract data; determine that the delivery years and months involved in the main contracts corresponding to different backtest time periods within the backtest time interval are multiple delivery years and months according to the main contract switching date; extract the contract data of the monthly futures contracts under multiple delivery years and months from the continuous contract data according to the last trading day of the monthly futures contracts corresponding to different delivery years and months.
[0144] In one embodiment, the first construction module 603 is specifically used to: in the same time range, in response to the market data of the main continuous contract, the market data of the continuous contract of the current month or the continuous contract of the next month is converted from the same to different, and the time corresponding to the first conversion point from the same to different is determined as the main contract switching day in the main continuous contract; in the same time range, in response to the market data of the main continuous contract, the market data of the continuous contract of the current month or the continuous contract of the next month is converted from different to the same, and the time corresponding to the second conversion point from different to the same is determined as the last trading day of the futures contract of the corresponding month in different delivery years and months.
[0145] In one embodiment, the first construction module 603 is specifically used to: for the monthly futures contract of the first delivery year and month among multiple delivery years and months, obtain the first last trading day of the monthly futures contract of the first delivery year and month and the second last trading day of the monthly futures contract of the second delivery year and month, wherein the second delivery year and month is the previous delivery year and month of the first delivery year and month; extract the first contract data before the second last trading day from the continuous contracts of the current month; extract the second contract data before the first last trading day from the continuous contracts of the next month; splice the first contract data and the second contract data to obtain the contract data of the monthly futures contract of the first delivery year and month.
[0146] In one embodiment, the first determination module 605 is used to: determine the main contract switching date corresponding to the target underlying and the last trading day of the monthly futures contracts corresponding to different delivery years and months according to the market data in the continuous contract data; the second determination module 606 is used to: determine the specific monthly futures contracts and contract time periods involved in the continuous contract data according to the main contract switching date and the last trading day of the monthly futures contracts corresponding to different delivery years and months, and determine the time mapping relationship between the specific monthly futures contracts and the contract time periods according to the specific monthly futures contracts and the contract time periods; correspondingly, the first construction module 603 is specifically used to: determine the contract time periods to be matched included in the backtesting interval; determine the matching specific monthly futures contracts corresponding to the contract time periods to be matched from the specific monthly futures contracts involved in the continuous contract data according to the contract time periods to be matched and the time mapping relationship; and construct the contract data of the monthly futures contracts under multiple delivery years and months within the backtesting time interval according to the matching specific monthly futures contracts.
[0147] In one embodiment, the backtesting module 607 is specifically used to: in response to the monthly futures contracts under multiple delivery years and months being expired futures contracts, obtain the futures information corresponding to the target underlying asset; construct the static data of the target underlying asset based on the futures information of the target underlying asset and the monthly futures contracts under multiple delivery years and months; accordingly, backtest the futures quantitative backtesting strategy according to the contract data of the monthly futures contracts under multiple delivery years and months, including: determining multiple backtesting time points and futures contract trading operations at multiple backtesting time points according to the futures quantitative backtesting strategy; obtaining the futures market data corresponding to the multiple backtesting time points in the monthly futures contracts under the multiple delivery years and months in the static data; and backtesting the futures quantitative backtesting strategy based on the futures market data corresponding to the multiple backtesting time points and the futures contract trading operations.
[0148] In one embodiment, the backtesting module 607 is specifically used to: determine multiple backtesting instances required for backtesting; determine multiple backtesting instance groups based on the multiple backtesting instances, the backtesting instances in the backtesting instance groups share the contract data of the monthly futures contracts under the common delivery months among the contract data of the monthly futures contracts under multiple delivery years and months; store the contract data of the monthly futures contracts under the common delivery months corresponding to each backtesting instance group in the same storage unit; execute multiple backtesting instances based on the contract data of the monthly futures contracts under the common delivery months in the corresponding storage units to backtest the futures quantitative strategy.
[0149] In one embodiment, the backtesting module 607 is specifically used to: in response to the futures quantitative backtesting strategy being a cross-period arbitrage futures strategy, determine the first month futures contract corresponding to the near-month contract and the second month futures contract corresponding to the far-month contract from the monthly futures contracts under multiple delivery years and months according to the backtesting time point involved in the cross-period arbitrage futures strategy; perform a near-month contract closing backtesting operation according to the market data in the contract data of the first month futures contract, and perform a far-month contract opening backtesting operation according to the market data in the contract data of the second month futures contract; determine the backtesting result of the backtesting according to the trading results of the near-month contract closing backtesting operation and the trading results of the far-month contract opening backtesting operation.
[0150] It should be understood that the device embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here. Specifically, Figure 6 The device 600 shown can execute the above method embodiments, and the above and other operations and / or functions of each module in the device 600 are respectively for implementing the corresponding processes in the above methods, which will not be repeated here for the sake of brevity.
[0151] The above describes the device 600 of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above method embodiment in conjunction with its hardware.
[0152] Figure 7 A schematic block diagram of an electronic device 700 provided in an embodiment of the present application.
[0153] like Figure 7 As shown, the electronic device 700 may include:
[0154] The memory 710 and the processor 720, the memory 710 is used to store the computer program and transmit the program code to the processor 720. In other words, the processor 720 can call and run the computer program from the memory 710 to implement the method in the embodiment of the present application.
[0155] For example, the processor 720 may be configured to execute the above method embodiments according to instructions in the computer program.
[0156] In some embodiments of the present application, the processor 720 may include but is not limited to:
[0157] General-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.
[0158] In some embodiments of the present application, the memory 710 includes but is not limited to:
[0159] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory can be read-only memory (ROM), programmable ROM (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SL DRAM) and direct memory bus random access memory (DR RAM).
[0160] In some embodiments of the present application, the computer program may be divided into one or more modules, which are stored in the memory 710 and executed by the processor 720 to complete the method provided by the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.
[0161] like Figure 7 As shown, the electronic device may also include:
[0162] The transceiver 730 may be connected to the processor 720 or the memory 710 .
[0163] The processor 720 may control the transceiver 730 to communicate with other devices, specifically, to send information or data to other devices, or to receive information or data sent by other devices. The transceiver 730 may include a transmitter and a receiver. The transceiver 730 may further include an antenna, and the number of antennas may be one or more.
[0164] It should be understood that the various components in the electronic device are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.
[0165] The present application also provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a computer, the computer can perform the method of the above method embodiment. In other words, the present application embodiment also provides a computer program product containing instructions, and when the instructions are executed by a computer, the computer can perform the method of the above method embodiment.
[0166] When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instruction is loaded and executed on a computer, the computer can be made to perform the corresponding flow in each method in the embodiment of the present application in whole or in part, and generate the functions that can be realized by each method in the embodiment of the present application. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instruction can be transmitted from a website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (Digital Subscriber Line, DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integrations. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital video disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0167] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0168] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0169] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0170] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A backtesting method for futures quantitative strategy, characterized in that: include: Obtaining a futures quantitative backtesting strategy for a target underlying asset, and determining a backtesting time interval based on the futures quantitative backtesting strategy; Acquire the continuous contract data of the target underlying asset, wherein the continuous contract data includes at least one of the following: a main continuous contract, a continuous contract for the current month, and a continuous contract for the next month; According to the continuous contract data, construct the contract data of the monthly futures contracts of the target subject matter under multiple delivery years and months within the backtest time interval; The futures quantitative backtesting strategy is backtested according to the contract data of the monthly futures contracts under the multiple delivery years and months.
2. The method according to claim 1, characterized in that The step of constructing the contract data of the monthly futures contracts of the target subject matter under multiple delivery years and months within the backtest time interval according to the continuous contract data includes: Determine the main contract switching date within the backtest time interval and the last trading day of the futures contracts of the corresponding months in different delivery years and months according to the market data in the continuous contract data; According to the main contract switching date, determining the delivery years and months involved in the main contracts corresponding to different backtesting time periods within the backtesting time interval as the multiple delivery years and months; According to the last trading days of the monthly futures contracts corresponding to the different delivery years and months, the contract data of the monthly futures contracts under the multiple delivery years and months are extracted from the continuous contract data.
3. The method according to claim 2, characterized in that Determining the main contract switching date within the backtest time interval and the last trading day of the futures contracts corresponding to different delivery years and months based on the market data in the continuous contract data includes: In the same time range, in response to the market data of the main continuous contract changing from the same to different with the market data of the current month continuous contract or the next month continuous contract, the time corresponding to the first conversion point from the same to different is determined as the main contract switching date in the main continuous contract; In the same time range, in response to the market data of the main continuous contract, the market data of the continuous contract of the current month or the continuous contract of the next month is converted from different to the same, and the time corresponding to the second conversion point from different to the same is determined as the last trading day of the futures contract of the corresponding month of the different delivery year and month.
4. The method according to claim 2, characterized in that: The step of extracting the contract data of the monthly futures contracts under the multiple delivery years and months from the continuous contract data according to the last trading days of the monthly futures contracts corresponding to the different delivery years and months includes: For the monthly futures contract of the first delivery year and month among the multiple delivery years and months, obtaining the first last trading day of the monthly futures contract of the first delivery year and month and the second last trading day of the monthly futures contract of the second delivery year and month, wherein the second delivery year and month is the delivery year and month preceding the first delivery year and month; Extract the first contract data before the second last trading day from the continuous contracts of the current month; Extracting the second contract data before the first last trading day from the next month continuous contract; The first contract data and the second contract data are concatenated to obtain the contract data of the monthly futures contract of the first delivery year and month.
5. The method according to any one of claims 1 to 4, characterized in that: Before constructing the contract data of the monthly futures contracts of the target subject matter under multiple delivery years and months within the backtest time interval according to the continuous contract data, the method includes: Determine the main contract switching date corresponding to the target underlying asset and the last trading day of the corresponding month futures contract for different delivery years and months according to the market data in the continuous contract data; Determine the specific month futures contract and contract time period involved in the continuous contract data according to the main contract switching date and the last trading day of the corresponding month futures contract of the different delivery years and months, and determine the time mapping relationship between the specific month futures contract and the contract time period according to the specific month futures contract and the contract time period; Accordingly, constructing the contract data of the monthly futures contracts of the target underlying asset under multiple delivery years and months within the backtest time interval according to the continuous contract data includes: Determine the contract time period to be matched included in the backtesting interval; According to the to-be-matched contract time period and the time mapping relationship, determining a matching specific month futures contract corresponding to the to-be-matched contract time period from the specific month futures contracts involved in the continuous contract data; According to the matching specific month futures contracts, the contract data of the month futures contracts under multiple delivery years and months within the backtest time interval are constructed.
6. The method according to any one of claims 1 to 4, characterized in that: Before backtesting the futures quantitative backtesting strategy based on the contract data of the monthly futures contracts under the multiple delivery years and months, the method further includes: In response to the monthly futures contracts under the multiple delivery years and months being expired futures contracts, obtaining futures information corresponding to the target underlying asset; Based on the futures information of the target underlying and the monthly futures contracts under the multiple delivery years and months, construct static data of the target underlying; Accordingly, the backtesting of the futures quantitative backtesting strategy according to the contract data of the monthly futures contracts under the multiple delivery years and months includes: Determine multiple backtesting time points and futures contract trading operations at the multiple backtesting time points according to the futures quantitative backtesting strategy; Obtaining futures market data corresponding to the multiple backtest time points from the monthly futures contracts under the multiple delivery years and months of the static data; The futures quantitative backtesting strategy is backtested based on the futures market data corresponding to the multiple backtesting time points and the futures contract trading operations.
7. The method according to any one of claims 1 to 4, characterized in that: The backtesting of the futures quantitative strategy according to the contract data of the monthly futures contracts under the multiple delivery years and months includes: determining a number of backtesting instances required to perform the backtest; Determine a plurality of backtesting instance groups according to the plurality of backtesting instances, wherein the backtesting instances in the backtesting instance groups share the contract data of the monthly futures contracts under the common delivery months among the contract data of the monthly futures contracts under the plurality of delivery years and months; The contract data of the monthly futures contract under the common delivery month corresponding to each of the backtest instance groups is stored in the same storage unit; The multiple backtesting instances are executed according to the contract data of the monthly futures contract under the public delivery month in the corresponding storage unit to backtest the futures quantitative strategy.
8. The method according to any one of claims 1 to 4, characterized in that: The backtesting of the futures quantitative strategy according to the contract data of the monthly futures contracts under the multiple delivery years and months includes: In response to the futures quantitative backtesting strategy being a cross-period arbitrage futures strategy, according to the backtesting time point involved in the cross-period arbitrage futures strategy, determining a first month futures contract corresponding to the near month contract and a second month futures contract corresponding to the far month contract from the monthly futures contracts under the multiple delivery years and months; Based on the market data in the contract data of the first-month futures contract, a backtest operation of closing a near-month contract is performed, and based on the market data in the contract data of the second-month futures contract, a backtest operation of opening a far-month contract is performed; The backtesting result of the backtest is determined according to the trading result of the backtesting operation of closing the near-month contract and the trading result of the backtesting operation of opening the far-month contract.
9. A backtesting device for futures quantitative strategies, characterized in that: include: An acquisition and determination module is used to: acquire a futures quantitative backtesting strategy of a target subject matter, and determine a backtesting time interval based on the futures quantitative backtesting strategy; The first acquisition module is used to: acquire the continuous contract data of the target subject matter, wherein the continuous contract data includes at least one of the following: the main continuous contract, the continuous contract of the current month, and the continuous contract of the next month; The first construction module is used to: construct the contract data of the monthly futures contracts of the target subject matter under multiple delivery years and months within the backtest time interval according to the continuous contract data; The backtesting module is used to backtest the futures quantitative backtesting strategy according to the contract data of the monthly futures contracts under the multiple delivery years and months.
10. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1 to 8 by executing the executable instructions.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
