A lightweight financial data query, quantitative strategy development and backtesting method and device

Financial data is obtained and processed through web crawlers, combined with a multi-threaded query interface and simulated transaction backtesting platform, which solves the speed and quantity limitations of existing financial data acquisition methods and achieves high-speed, unlimited financial data query and simulated transactions. Backtesting and support for real trading.

CN114564499BActive Publication Date: 2024-10-22DERKEE INFORMATION CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210121976.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-09
Publication Date
2024-10-22
Estimated Expiration
2042-02-09

AI Technical Summary

Technical Problem

Existing financial data acquisition methods have problems such as slow data query speed, limited quantity, and insufficient simulation of backtest functions, and cannot meet the needs of quantitative investment and trading.

Method used

Obtain financial data through web crawlers, perform data cross-checking and deduplication processing, use serialization and compressed storage, implement multi-threaded query interfaces, provide a high-speed simulated trading backtesting platform, integrate backtesting, custom model predictions and real offer file generation Function.

Benefits of technology

It achieves lightweight, high-speed financial data query and unlimited quantity query, significantly speeds up quantitative investment experiments and strategy verification, improves the simulated trading speed of the backtesting platform, and supports real trading.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114564499B_ABST
    Figure CN114564499B_ABST
Patent Text Reader

Abstract

The present invention discloses a lightweight financial data query, quantitative strategy development and backtesting method and device, the method includes: downloading various types of financial data through a multi-website crawler and cross-validation method; classifying, labeling, de-duplicating, and reducing the number of bits of data, serializing it into a binary file, and compressing and storing it into a local lightweight file; designing a data query interface for lightweight files, and encapsulating it with multi-threading; based on the above data query interface, realizing high-speed simulation backtesting and real-time trading platform, integrating backtesting, custom model prediction and real-time file generation functions. The present invention realizes high-speed, unlimited quantity data query by compressing and storing financial data in the local after efficient processing, occupying only a small capacity space, and based on this, realizing high-speed simulation backtesting function, greatly improving the speed of quantitative investment experiments, and realizing the real-time file generation function, and the experimental strategy can be directly connected to the real-time trading platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of finance and computer software, and in particular to a lightweight financial data query, quantitative strategy development and backtesting device. Background Art

[0002] In recent years, with the development of society and the continuous advancement of computer technology, the scale of the financial market has continued to grow and play a significant role in economic and social development. Among them, the stock and futures markets are important components of the financial market. The financial market has now become an important means for corporate financing and institutional and personal wealth appreciation. With the development of the Internet, the storage and computing costs of computers have continued to decrease, and quantitative investment methods that combine computer technology with financial investment have emerged. Nowadays, quantitative investment and automated trading have been widely used in financial markets and stock trading.

[0003] At present, quantitative investment includes AI quantitative investment, rule-based quantitative investment, quantitative investment plus manual judgment and other methods. AI quantitative investment is to apply artificial intelligence methods to quantification, explore some features, use these to make artificial intelligence predictions, and then conduct some long and short strategies for backtesting based on the training model. If the effect is good, it can be used in actual transactions. Rule-based quantification is to set some rules manually, and buy and sell when these rules are met. The buying and selling suggestions and some financial features obtained by these two methods can also be manually judged for the final transaction.

[0004] From the above quantitative investment methods, we can see that when conducting quantitative experiments and transactions, we need to use financial data, such as market data, financial data, etc. to calculate financial characteristics or buying and selling points, and backtesting is needed to verify the feasibility of the strategy. Therefore, a financial data interface and backtesting platform are needed to meet the entire process of quantitative experiments and transactions.

[0005] At present, there are data acquisition channels such as Tushare and AkShare data interfaces, which provide APIs to obtain financial data; there are also quantitative platforms such as Nuggets and Jukuan, which provide API interfaces and backtesting platforms for data acquisition; and there are also Pyramid, which only provides backtesting platforms. However, these data interface APIs and backtesting platforms have their own limitations, such as limited data query speed, especially when querying a large amount of data; the number of data queries is also limited, with a daily limit or a single query limit; the backtesting function of the backtesting platform is not simulated enough, the backtesting speed is slow, and cross-product backtesting is not possible. Summary of the invention

[0006] The purpose of the present invention is to overcome the shortcomings and deficiencies of existing financial data acquisition methods, and to provide a lightweight financial data query, quantitative strategy development and backtesting method and device. Various types of financial data can be downloaded through a web crawler method, and stored locally through serialization and compression methods, and a matching query interface can be implemented to achieve the purpose of lightweight and high-speed query without quantity restrictions, and to provide a high-speed and simulated backtesting function based on a data platform, and then a real-time transaction file can be generated to connect to a real-time trading platform.

[0007] In order to achieve the above object, the present invention adopts the following technical solutions:

[0008] On the one hand, the present invention provides a lightweight financial data query, quantitative strategy development and backtesting method, comprising the following steps:

[0009] Obtain various types of financial data and cross-check the reliability of the data;

[0010] Classify, classify, remove duplicates, and reduce the number of digits of the acquired financial data;

[0011] Serialize the data into binary files and compress them for storage locally;

[0012] Use multi-threaded encapsulation data query interface for serialized binary data to achieve high-speed and unlimited data query;

[0013] A high-speed simulation trading backtesting platform is implemented based on the above data query interface;

[0014] The platform integrates backtesting, custom model prediction and real-time file generation functions.

[0015] As a preferred technical solution, the acquisition of financial data is specifically as follows:

[0016] Through the web crawler method, data from multiple financial data websites are crawled and downloaded, and then the data downloaded from these different websites are compared and mutually verified to solve the problems of data missing and errors caused by network fluctuations during the crawling process. The final stored data is selected by comparing the data of each website one by one to ensure the reliability of the data.

[0017] As a preferred technical solution, when the acquired financial data is classified, classified, deduplicated, and the number of bits of data is reduced, different storage structures are adopted for data of different types and periods to achieve the purpose of lightweight storage, specifically:

[0018] For some data updated monthly, quarterly or annually, this method only stores the time point when the data changes and the new data value after the change. The data value between the data change time points is the data at the last change time point;

[0019] For market data, the time field is the same for all targets and the data for targets of the same type are the same. You can store it in a separate file and omit this field in the data file. For price and transaction volume data in market data, set the 32-bit or 64-bit data storage type according to the value.

[0020] By removing duplicate data and using a storage type with a smaller number of bits, local data files take up less space when stored, thereby achieving the purpose of lightweighting.

[0021] As a preferred technical solution, it is serialized into a binary file through Python and compressed and stored locally, specifically:

[0022] Use Python's pickle library to serialize data, generate binary files, compress them with gzip, and store them as local files. Compared with conventional csv and txt file storage, although the serialized files are basically unreadable, the reading speed after serialization and compression is 10 to 50 times faster than the storage of raw data such as csv. This is based on the file size. The smaller the file, the greater the speed difference.

[0023] As a preferred technical solution, when querying data, first query whether the data in this condition has been queried in the temporary file, otherwise obtain the number of files required to be used in the query condition, and use a dynamic multi-threading method to accelerate the query. The dynamic multi-threading method is as follows:

[0024] threadNum=OTN[fileNum]

[0025] Among them, threadNum indicates the number of query threads, that is, the number of multi-threads for each query is related to the query conditions; fileNum indicates the number of files required for this query condition; OTN is a hash table that records the optimal number of query threads under each fileNum. The hash table is calculated by the following formula:

[0026] OTN={OTN i |OTN i =getFast({j:spendTime(j),1≤j≤i}),1≤i≤allFileNum}

[0027] Among them, i represents the number of different query files, spendTime function is the query time for this query file number, and getFast function obtains the number of files with the minimum time in the hash table, that is, the key value; the hash table of the entire optimal number of query threads is calculated when the system is deployed. By traversing each fileNum, the number of threads ranges from 1 to the number of files to be queried, and the number of threads with the fastest query speed under each fileNum is calculated, recorded in the hash table, and serialized into a binary local file.

[0028] As a preferred technical solution, in multi-threaded parallel query, the file is decompressed in each thread, the binary file is deserialized into an instance object, the index is returned, and the query result is serialized into a binary file in the background and stored in a temporary folder;

[0029] The temporary folder has a custom upper limit according to the storage capacity of the local computer. When the storage capacity limit is reached, the earliest files are deleted according to the first-in-first-out rule to store the latest files.

[0030] As a preferred technical solution, the backtesting platform creates a new process to process order message queues. In the queue, the data of each order subject at the time of placing an order is asynchronously queried in a multi-threaded manner, and the success of the simulated transaction is calculated as follows:

[0031]

[0032] Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment.

[0033] On the other hand, the present invention provides a lightweight financial data query, quantitative strategy development and backtesting platform, which is applied to the lightweight financial data query, quantitative strategy development and backtesting method, including a trading module, a position module, a statistics module, a display module, a custom model training module, and a real disk file generation module;

[0034] The transaction module is used to provide an order placement function. The transaction module uses an asynchronous method to first obtain the user's order information, calculate the fee required for the transaction, deduct it from the account, push the order into the message queue and return a successful order.

[0035] When the backtesting system is initialized, a new process is created to handle the order message queue. In the queue, the data of each order subject at the time of placing the order is asynchronously queried through multi-threading. The success of the simulated transaction is calculated as follows:

[0036]

[0037] Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment;

[0038] When querying data asynchronously, obtain disk utilization in real time. When the disk utilization reaches 100%, reduce the number of threads and fix the upper limit of the number of threads.

[0039] The position module is used to save all transaction data, obtain all orders, and asynchronously update the order data in the position after the transaction module calculates whether the order simulation transaction is successful or not;

[0040] The statistical module is used to calculate the profit situation and various profit indicators after the backtest is completed, and supports transaction data storage and report generation functions;

[0041] The display module is used to generate the report in the statistical module in the form of a chart;

[0042] The custom model module is used to provide a custom AI stock selection strategy generation function without coding. Through custom algorithms, custom selection features, partial feature calculation time range, opening and closing time points, and high-speed local query interface, the feature data and labels required for training can be quickly calculated. In combination with the high-speed backtesting platform, the effect of this AI stock selection strategy can be obtained intuitively and comprehensively. If the effect of this custom strategy meets expectations, the real-time file generation module is directly used to generate the running files required by the corresponding real-time platform for real-time trading.

[0043] The real-time file generation module is used to convert and encapsulate the files for the experiment using the backtesting API interface to generate a series of files that can be used in the real-time market;

[0044] For trading platforms that provide real-time trading interfaces, identify the data query interface and backtest order interface used in the experimental files, and replace them with the real-time data query interface of the day and the order interface provided by the trading platform;

[0045] For those that need to be deployed in the platform's own real-time trading environment, the data query interface and order placement interface are also replaced, and the corresponding code files are generated according to the corresponding platform format;

[0046] For some platforms that do not support complex calculations or artificial intelligence model calculations, real-time order transactions are carried out in the form of generated file orders.

[0047] Another aspect of the present invention provides an electronic device, the electronic device comprising:

[0048] at least one processor; and,

[0049] a memory communicatively connected to the at least one processor; wherein,

[0050] The memory stores computer program instructions that can be executed by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute the lightweight financial data query, quantitative strategy development and backtesting method.

[0051] On the other hand, the present invention provides a computer-readable storage medium storing a program, which, when executed by a processor, implements the lightweight financial data query, quantitative strategy development and backtesting method.

[0052] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0053] (1) In the present invention, all data are stored locally, and the speed of querying data is more stable and faster than querying from a public network interface, and there is no limit on the number and it is free.

[0054] (2) The present invention adopts the method of deduplication and downsizing of data, and uses serialization and compression storage, which greatly reduces the storage space and enables large-scale data to be stored on personal computers.

[0055] (3) Based on localized data and data query interface, the backtesting speed of the transaction backtesting platform of the present invention is much faster than that of the backtesting platforms publicly available on the Internet, and can achieve backtesting of tens of thousands of transactions in 10 seconds.

[0056] (4) The query interface and backtest interface of the present invention can be embedded in Python code, making it convenient to view the trading effects of complex artificial intelligence experimental strategies.

[0057] (5) The present invention proposes a method for accessing a real-time trading platform. By identifying code files that use query and backtesting interfaces, real-time trading files that can be used by the corresponding platform are generated, thereby realizing the implementation of experiments or strategies.

[0058] (6) The present invention can greatly speed up the experiments and strategy verification of quantitative investment. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] 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.

[0060] Figure 1It is a flowchart of the lightweight financial data query, quantitative strategy development and backtesting method of the present invention;

[0061] Figure 2 It is the storage structure of the daily level data in the embodiment of the present invention.

[0062] Figure 3 It is a storage structure of tick-level data in an embodiment of the present invention.

[0063] Figure 4 It is a flow chart of the backtesting platform according to an embodiment of the present invention.

[0064] Figure 5 This is a diagram of a custom model prediction platform according to an embodiment of the present invention.

[0065] Figure 6 It is a structural diagram of the lightweight financial data query, quantitative strategy development and backtesting platform of the present invention;

[0066] Figure 7 It is a structural schematic diagram of the electronic device of the present invention. DETAILED DESCRIPTION

[0067] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0068] like Figure 1 As shown, the use of a lightweight financial data query, quantitative strategy development and backtesting platform in this embodiment includes the following steps:

[0069] (1) Obtain various types of financial data and cross-check the reliability of the data;

[0070] The financial data acquisition method specifically includes: crawling and downloading data from multiple financial data websites through a web crawler method, and then comparing the data downloaded from these different websites for mutual verification to solve the problem of data missing and errors caused by network fluctuations during the crawling process, and selecting the final stored data by comparing the data of each website one by one to ensure the reliability of the data.

[0071] Furthermore, for data updated on a monthly or even annual basis, such as the number of outstanding shares of a stock target, the price-earnings ratio, the top ten holdings of a fund, etc., it is only necessary to store the time point when the data is updated and the updated value, so that duplicate data in the middle can be omitted to achieve the purpose of lightweight storage.

[0072] Data of the same period with different target types adopt different storage structures.

[0073] like Figure 2 As shown in the figure, the data of the daily level cycle is stored in a file for each target, because the trading date is the same for stocks, futures and funds, so the trading date only needs to be stored in a separate file. Each target can use this trading date file in combination with the data offset to restore the data corresponding to each trading date, and the data when the stock is suspended is replaced by a null value. In this way, only six basic data need to be stored: opening price (open), closing price (close), highest price (high), lowest price (low), trading volume (volume), and trading amount (money).

[0074] Minute-level data is only available for stocks and futures.

[0075] The data storage at the minute level is similar to that at the daily level. A separate file for intraday trading time at the minute level is stored, and the storage format of one file per day is adopted. The time when there is no trading is filled with the data of the previous moment. Each target can use this transaction date file in combination with the data offset to restore the data corresponding to each transaction date. In this way, only six non-repetitive data are stored: opening price (open), closing price (close), highest price (high), lowest price (low), trading volume (volume), and trading amount (money).

[0076] Tick-level data is only available for stocks and futures.

[0077] like Figure 3 As shown in the figure, the tick-level data is stored in one file per trading day, with stocks and futures stored in one file each. The storage space of the underlying code is saved by using a dictionary.

[0078] The data of each time period mentioned above is set to 32-bit or 64-bit data type according to the maximum value of each field to reduce memory usage and space usage during storage to achieve lightweight purpose.

[0079] (2) Classify, classify, remove duplicates, and reduce the number of bits of the acquired financial data;

[0080] For some data updated monthly, quarterly or annually, this method only stores the time point when the data changes and the new data value after the change. The data value between the data change time points is the data at the last change time point;

[0081] For market data, the time field is the same for all targets and the data for targets of the same type are the same. You can store it in a separate file and omit this field in the data file. For price and transaction volume data in market data, set the 32-bit or 64-bit data storage type according to the value.

[0082] By removing duplicate data and using a storage type with a smaller number of bits, local data files take up less space when stored, thereby achieving the purpose of lightweighting.

[0083] (3) Serialize the data into binary files and compress and store them locally;

[0084] In this embodiment, it is serialized into a binary file through Python and compressed and stored locally, specifically:

[0085] Use Python's pickle library to serialize data, generate binary files, compress them with gzip, and store them as local files. Compared with conventional csv and txt file storage, although the serialized files are basically unreadable, the reading speed after serialization and compression is 10 to 50 times faster than the storage of raw data such as csv. This is based on the file size. The smaller the file, the greater the speed difference.

[0086] (4) Use multi-threaded encapsulation data query interface for serialized binary data to achieve high-speed and unlimited data query;

[0087] When querying data, first check whether the data in this condition has been queried in the temporary file, otherwise obtain the number of files required to be used in the query condition, and use the dynamic multi-threading method to accelerate the query. The dynamic multi-threading method is as follows:

[0088] threadNum=OTN[fileNum]

[0089] Among them, threadNum indicates the number of query threads, that is, the number of multi-threads for each query is related to the query conditions; fileNum indicates the number of files required for this query condition; OTN is a hash table that records the optimal number of query threads under each fileNum. The hash table is calculated by the following formula:

[0090] OTN={OTN i |OTN i =getFast({j:spendTime(j),1≤j≤i}),1≤i≤allFileNum}

[0091] Among them, i represents the number of different query files, spendTime function is the query time for this query file number, and getFast function obtains the number of files with the minimum time in the hash table, that is, the key value; the hash table of the entire optimal number of query threads is calculated when the system is deployed. By traversing each fileNum, the number of threads ranges from 1 to the number of files to be queried, and the number of threads with the fastest query speed under each fileNum is calculated, recorded in the hash table, and serialized into a binary local file.

[0092] In multi-threaded parallel query, each thread decompresses the file, deserializes the binary file into an instance object, indexes and returns the result, and serializes the query result into a binary file in the background and stores it in a temporary folder;

[0093] The temporary folder has a custom upper limit according to the storage capacity of the local computer. When the storage capacity limit is reached, the earliest files are deleted according to the first-in-first-out rule to store the latest files.

[0094] For example, query the daily data of 000001 (Ping An Bank) and 002594 (BYD) on December 1, 2021, the pre-adjusted minute data of 000001 (Ping An Bank) half an hour before the opening, and the tick data of 000001 (Ping An Bank) 5 minutes before the opening.

[0095] (4.1) To query the daily data, two files are needed to determine the query conditions. According to threadNum=OTN[2], threadNum threads are set to find the 000001 and 002594 files in the daily folder respectively, decompress and deserialize them into instance objects, and query the offset corresponding to 2021-12-01 in the day-level date file to directly obtain the daily data of this day through the offset in the object.

[0096] (4.2) To query minute data, first find the 000001 file in the minute-level folder, decompress it, deserialize it, and parse it into an instance object. Query the offsets corresponding to 2021-12-01 09:30:00 and 2021-12-01 10:00:00 in the minute-level date file. Slice the start and end offsets to get the data for the first half hour, then query the daily line data of that day to get the pre-adjustment factor (2.1 and 2.2 are independent queries). Use the following rules to get the pre-adjustment data:

[0097] Before (after) adjusted data = original price × before (after) adjusted factor;

[0098] The trading volume before (after) adjustment = original trading volume / the adjustment factor before (after);

[0099] Transaction amount is not processed

[0100] (4.3) To query the tick data, first find the 2021-12-01 file in the tick level folder, decompress it, deserialize it and parse it into an instance object, use the 000001 label to perform dictionary indexing to obtain Ping An Bank's tick data for 2021-12-01, and then use the characteristics of pandas to index through [20211201090000:20211201093500] to obtain the tick data 5 minutes before the opening.

[0101] (5) Implement a high-speed simulation trading backtesting platform based on the above data query interface;

[0102] The backtesting platform creates a new process to handle the order message queue. In the queue, the data of each order subject at the time of placing the order is asynchronously queried through multi-threading, and the success of the simulated transaction is calculated according to the following formula:

[0103]

[0104] Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment.

[0105] Furthermore, the process of backtesting a custom trading strategy is as follows Figure 4 As shown:

[0106] (5.1) Initialize the backtest module, set the account number, initial funds, transaction fee rate, statistical start and end time, result save path, and benchmark comparison target.

[0107] (5.2) Use the order function to place an order, including the target code, transaction time, transaction quantity, long and short and buy and sell directions, transaction price, and order account. The same account is not limited to placing orders for only one type of target. Here, an asynchronous method is used to calculate the fees required for this transaction, deduct them from the account, push the order into the message queue and position module, return the order success, and continue with subsequent order operations.

[0108] (5.3) Asynchronously query the data of the unprocessed order targets in the queue at the time of placing the order through multi-threading, and calculate whether the simulated transaction is successful according to the following formula:

[0109]

[0110] Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment.

[0111] When querying data asynchronously, obtain disk utilization in real time. When the disk utilization reaches 100%, reduce the number of threads.

[0112] In the message queue, the orders on the same day are summarized into one message and processed by one thread. This can reduce the number of queries for the data at this historical moment. The query is only done once, and the data is stored in the memory. After calculating the success or failure of all orders on this day and the closing market value of the positions on this day, the memory occupied by this part of the data is released.

[0113] This asynchronous merging processing method can speed up the data query in backtesting.

[0114] (5.4) Update the order information in the position module based on the return result of whether the order transaction is successful or not.

[0115] (5.5) When all transactions are completed, manually call the report generation function for statistics and view the result report in the preset path.

[0116] All order data and position data are stored in the position module. Based on the data in this module, various financial indicators of backtesting can be statistically calculated, including rate of return, annualized return, maximum drawdown, Sharpe ratio, etc.

[0117] (6) The custom model module provides a custom AI stock selection strategy generation function without coding. Figure 5 As shown, you can select different algorithms, features, stock pools, partial feature calculation time ranges, opening and closing time points, and use the high-speed local query interface in step S4 to quickly calculate the feature data and labels required for training; through the high-speed backtesting platform and visual operation, you can intuitively, conveniently and comprehensively obtain the effect of this artificial intelligence stock selection strategy. The specific process is as follows:

[0118] (6.1) According to Figure 5 The parameters shown are queried through the query interface to query the tick-level data. Some features are calculated according to the opening time range. The minute-level data is queried to create labels to form training data.

[0119] (6.2) Use the selected algorithm to perform rolling training forecasts, and use the order placement function of the trading module to trade at the set time point;

[0120] (6.3) Check the backtest results.

[0121] For files that use the backtesting API interface for experiments or models that have trained good results using custom model modules, you can use the real-time file generation module to convert and package them to generate a series of files that can be used in real-time.

[0122] For trading platforms that provide real-time trading interfaces, identify the data query interface and backtest order interface used in the experimental file, replace them with the real-time data query interface of the day and the order interface provided by the trading platform to generate a real-time trading file, and then package them together with the local files used in the experimental file, regenerate a folder and copy them into it. After the user sets the account password of the corresponding real-time trading platform, he can conduct real-time trading during the market opening hours.

[0123] For those that need to be deployed in the platform's own real-time trading environment, the data query interface and order placement interface are also replaced, and the corresponding code files are generated according to the corresponding platform format. They are packaged together with the local files used in the experimental files, and a new folder is generated and copied into it. The user manually moves it to the platform environment to start trading.

[0124] For some platforms that do not support complex operations or AI model calculations, we use the form of generating file orders for real-time order trading, identify the data query interface and backtest order interface used in the experimental file, and replace them with the real-time data query interface and file order generation function of the day, so that the platform can read the file order calculated by the personal local environment for trading. Through the intermediate conversion link of local files, complex AI stock selection strategies can be implemented for some platforms that do not support complex operations or AI model calculations.

[0125] It should be noted that, for the sake of convenience, the aforementioned method embodiments are all expressed as a series of action combinations, but those skilled in the art should know that the present invention is not limited to the described order of actions, because according to the present invention, certain steps can be performed in other orders or simultaneously.

[0126] Based on the same idea as the multi-party privacy-preserving machine learning method based on homomorphic encryption and trusted hardware in the above-mentioned embodiment, the present invention also provides a multi-party privacy-preserving machine learning system based on homomorphic encryption and trusted hardware, which can be used to execute the above-mentioned multi-party privacy-preserving machine learning method based on homomorphic encryption and trusted hardware. For ease of explanation, the structural diagram of the embodiment of the multi-party privacy-preserving machine learning system based on homomorphic encryption and trusted hardware only shows the parts related to the embodiment of the present invention. Those skilled in the art can understand that the illustrated structure does not constitute a limitation on the device, and may include more or fewer components than shown in the diagram, or combine certain components, or arrange the components differently.

[0127] Please refer to 6. In another embodiment of the present application, a lightweight financial data query, quantitative strategy development and backtesting platform is provided, including a trading module, a position module, a statistics module, a display module, a custom model training module, and a real disk file generation module;

[0128] The transaction module is used to provide an order placement function. The transaction module uses an asynchronous method to first obtain the user's order information, calculate the fee required for the transaction, deduct it from the account, push the order into the message queue and return a successful order.

[0129] When the backtesting system is initialized, a new process is created to handle the order message queue. In the queue, the data of each order subject at the time of placing the order is asynchronously queried through multi-threading. The success of the simulated transaction is calculated as follows:

[0130]

[0131] Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment;

[0132] When querying data asynchronously, obtain disk utilization in real time. When the disk utilization reaches 100%, reduce the number of threads and fix the upper limit of the number of threads.

[0133] The position module is used to save all transaction data, obtain all orders, and asynchronously update the order data in the position after the transaction module calculates whether the order simulation transaction is successful or not;

[0134] The statistical module is used to calculate the profit situation and various profit indicators after the backtest is completed, and supports transaction data storage and report generation functions;

[0135] The display module is used to generate the report in the statistical module in the form of a chart;

[0136] The custom model module is used to provide a custom AI stock selection strategy generation function without coding. Through custom algorithms, custom selection features, partial feature calculation time range, opening and closing time points, and high-speed local query interface, the feature data and labels required for training can be quickly calculated. In combination with the high-speed backtesting platform, the effect of this AI stock selection strategy can be obtained intuitively and comprehensively. If the effect of this custom strategy meets expectations, the real-time file generation module is directly used to generate the running files required by the corresponding real-time platform for real-time trading.

[0137] The real-time file generation module is used to convert and encapsulate the files for the experiment using the backtesting API interface to generate a series of files that can be used in the real-time market;

[0138] For trading platforms that provide real-time trading interfaces, identify the data query interface and backtest order interface used in the experimental files, and replace them with the real-time data query interface of the day and the order interface provided by the trading platform;

[0139] For those that need to be deployed in the platform's own real-time trading environment, the data query interface and order placement interface are also replaced, and the corresponding code files are generated according to the corresponding platform format;

[0140] For some platforms that do not support complex calculations or artificial intelligence model calculations, real-time order transactions are carried out in the form of generated file orders.

[0141] In the implementation of a lightweight financial data query, quantitative strategy development and backtesting platform in the above embodiment, the logical division of each program module is only an example. In actual applications, the above functions can be assigned to different program modules as needed, for example, for the convenience of corresponding hardware configuration requirements or software implementation. That is, the internal structure of the lightweight financial data query, quantitative strategy development and backtesting platform is divided into different program modules to complete all or part of the functions described above.

[0142] See also Figure 7 In one embodiment, an electronic device of a lightweight financial data query, quantitative strategy development and backtesting platform is provided. The electronic device 200 may include a first processor 201, a first memory 202 and a bus, and may also include a computer program stored in the first memory 202 and executable on the first processor 201, such as a lightweight financial data query, quantitative strategy development and backtesting program 203.

[0143] The first memory 202 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the first memory 202 may be an internal storage unit of the electronic device 200, such as a mobile hard disk of the electronic device 200. In other embodiments, the first memory 202 may also be an external storage device of the electronic device 200, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 200. Further, the first memory 202 may also include both an internal storage unit of the electronic device 200 and an external storage device. The first memory 202 can not only be used to store application software and various types of data installed in the electronic device 200, such as lightweight financial data query, quantitative strategy development and backtesting program 203 code, but also be used to temporarily store data that has been output or is to be output.

[0144] In some embodiments, the first processor 201 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The first processor 201 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules (such as federated learning defense programs, etc.) stored in the first memory 202, and calls data stored in the first memory 202 to execute various functions of the electronic device 200 and process data.

[0145] Figure 6 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the electronic device 200 , and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0146] The lightweight financial data query, quantitative strategy development and backtesting program 203 stored in the first memory 202 of the electronic device 200 is a combination of multiple instructions. When running in the first processor 201, it can achieve:

[0147] Obtain various types of financial data and cross-check the reliability of the data;

[0148] Classify, classify, remove duplicates, and reduce the number of digits of the acquired financial data;

[0149] Serialize the data into binary files and compress them for storage locally;

[0150] Use multi-threaded encapsulation data query interface for serialized binary data to achieve high-speed and unlimited data query;

[0151] A high-speed simulation trading backtesting platform is implemented based on the above data query interface;

[0152] The platform integrates backtesting, custom model prediction and real-time file generation functions.

[0153] Furthermore, if the module / unit integrated in the electronic device 200 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0154] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0155] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0156] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications made without departing from the spirit and principles of the present invention shall be equivalent replacement methods and shall be included in the protection scope of the present invention.

Claims

1. A lightweight financial data query, quantitative strategy development and backtesting method, characterized in that: The steps include: Obtain various types of financial data and cross-check the reliability of the data; Classify, classify, remove duplicates, and reduce the number of digits of the acquired financial data; Serialize the data into binary files and compress them for storage locally; Use multi-threaded encapsulation data query interface for serialized binary data to achieve high-speed and unlimited data query; A high-speed simulation trading backtesting platform is implemented based on the above data query interface; The platform integrates backtesting, custom model prediction and real-time file generation functions; A lightweight financial data query, quantitative strategy development and backtesting platform applied to the lightweight financial data query, quantitative strategy development and backtesting method, including a trading module, a position module, a statistics module, a display module, a custom model training module, and a real-time file generation module; The transaction module is used to provide an order placement function. The transaction module uses an asynchronous method to first obtain the user's order information, calculate the fee required for the transaction, deduct it from the account, push the order into the message queue and return a successful order. When the backtesting system is initialized, a new process is created to handle the order message queue. In the queue, the data of each order subject at the time of placing the order is asynchronously queried through multi-threading. The success of the simulated transaction is calculated as follows: Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment; When querying data asynchronously, obtain disk utilization in real time. When the disk utilization reaches 100%, reduce the number of threads and fix the upper limit of the number of threads. The position module is used to save all transaction data, obtain all orders, and asynchronously update the order data in the position after the transaction module calculates whether the order simulation transaction is successful or not; The statistical module is used to calculate the profit situation and various profit indicators after the backtest is completed, and supports transaction data storage and report generation functions; The display module is used to generate the report in the statistical module in the form of a chart; The custom model training module is used to provide a custom AI stock selection strategy generation function without coding. Through custom algorithms, custom selection features, partial feature calculation time ranges and opening and closing time points, combined with a high-speed local query interface, the feature data and labels required for training can be quickly calculated. Then, in conjunction with a high-speed backtesting platform, the effect of the AI ​​stock selection strategy can be obtained. If the effect of this AI stock selection strategy meets expectations, the real-time file generation module is directly used to generate the running files required by the corresponding real-time platform for real-time trading. The real disk file generation module is used to convert and encapsulate the files for the experiment using the backtesting API interface to generate a series of real disk files; For trading platforms that provide real-time trading interfaces, identify the data query interface and backtest order interface used in the experimental files, and replace them with the real-time data query interface of the day and the order interface provided by the trading platform; For platforms that do not support complex calculations or artificial intelligence model calculations, real-time order trading is carried out in the form of generated file orders.

2. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 1, characterized in that: The specific steps of obtaining various types of financial data are as follows: Through the web crawler method, data from multiple financial data websites are crawled and downloaded, and then the data downloaded from different websites are compared and mutually verified to solve the problems of data missing and errors caused by network fluctuations during the crawling process. The final stored data is selected by comparing the data of each website one by one to ensure the reliability of the data.

3. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 1, characterized in that: When the acquired financial data is classified, classified, deduplicated, and the number of bits of data is reduced, different storage structures are adopted for data of different types and periods to achieve the purpose of lightweight storage, specifically: For some data updated monthly, quarterly or annually, only the time point when the data changes and the new data value after the change are stored. The data value between the data change time points is the data at the last change time point; For market data and time fields, all targets have data of the same type and store it in a separate file. For price and transaction volume data in market data, set the 32-bit or 64-bit data storage type according to the value. By removing duplicate data and using a storage type with a smaller bit number, local data files take up less space when stored, thus achieving the purpose of lightweighting.

4. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 1, characterized in that: Serialize it into a binary file through Python and compress it and store it locally. Specifically: Use Python's pickle library to serialize the data, generate a binary file, compress it with gzip, and store it as a local file.

5. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 1, characterized in that: When querying data, first check whether the data in the query condition has been queried in the temporary file, otherwise obtain the number of files required to be used in the query condition, and use the dynamic multi-threading method to accelerate the query. The dynamic multi-threading method is as follows: threadNum = OTN[fileNum] Among them, threadNum indicates the number of query threads, that is, the number of multi-threads for each query is related to the query conditions; fileNum indicates the number of files required for this query condition; OTN is a hash table that records the optimal number of query threads under each fileNum. The hash table is calculated by the following formula: OTN={OTN i |OTN i =getFast({j:spendTime(j),1≤j≤i}),1≤i≤allFileNum} Among them, i represents the number of different query files, spendTime function is the query time for this query file number, and getFast function obtains the number of files with the minimum time in the hash table, that is, the key value; the hash table of the entire optimal number of query threads is calculated when the system is deployed. By traversing each fileNum, the number of threads ranges from 1 to the number of files to be queried, and the number of threads with the fastest query speed under each fileNum is calculated, recorded in the hash table, and serialized into a binary local file.

6. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 5, characterized in that: In multi-threaded parallel query, each thread decompresses the file, deserializes the binary file into an instance object, indexes and returns the result, and serializes the query result into a binary file in the background and stores it in a temporary folder; The temporary folder has a custom upper limit according to the storage capacity of the local computer. When the storage capacity limit is reached, the earliest files are deleted according to the first-in-first-out rule to store the latest files.

7. A lightweight financial data query, quantitative strategy development and backtesting method according to claim 1, characterized in that: The backtesting platform creates a new process to handle the order message queue. In the queue, the data of each order subject at the time of placing the order is asynchronously queried through multi-threading, and the success of the simulated transaction is calculated according to the following formula: Among them, price indicates the order price, volume indicates the order quantity, limit indicates the price limit at the historical moment, and buy_amount indicates the purchase volume at the historical moment.

8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores computer program instructions that can be executed by the at least one processor, and the computer program instructions are executed by the at least one processor so that the at least one processor can execute a lightweight financial data query, quantitative strategy development and backtesting method as described in any one of claims 1-7.

9. A computer-readable storage medium storing a program, characterized in that: When the program is executed by a processor, a lightweight financial data query, quantitative strategy development and backtesting method as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Distributed memory calculation based data deduplication method

    CN105354246A

  • Processing method of financial quotation data

    CN107748797A

  • Strategy back test method and strategy back test system

    CN110689436A