Financial transaction backtest breach detection method, device, and storage medium
Patent Information
- Application Number
- CN202611296006.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-25
- Publication Date
- 2026-10-27
AI Technical Summary
[0003]本申请的主要目的在于提供一种金融交易回测穿越检测方法、设备及存储介质,旨在解决现有回测缺乏自动检测数据穿越能力,无法准确识别风险的技术问题
[0016]本申请提出的一个或多个技术方案,至少具有以下技术效果:获取待检测策略回测产生的回测数据,回测数据包括原始信号序列、收益率序列、仓位序列以及逐笔交易记录。基于回测数据,执行包括信号滞后检测、首尾回报检测、数据镜像检测、相似度检测和信息熵检测的多维统计检测,从不同统计视角自动挖掘数据穿越带来的统计异常特征,得到各项统计检测对应的统计检测结果。同时,对回测数据执行至少一项专项检测,计算对应的金融统计指标,生成各专项检测对应的专项检测结果,避免仅凭统计检测单方面下结论,减少误判,金融统计指标包括在市时间占比、修正索提诺比率、回报成本比率、尾部比率、异常胜率和异常负率。最后,将统计检测结果与专项检测结果进行交叉验证,综合判定风险等级,输出包含定位信息的结构化检测报告,解决现有回测缺少自动检测数据穿越能力、风险识别不准确的技术问题,整体实现自动化、准确识别回测数据穿越风险。
Smart Images

Figure CN122989304A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of algorithmic trading technology, and in particular to a method, device and storage medium for backtesting and crossover detection in financial trading. Background Technology
[0002] In the fields of quantitative investment and algorithmic trading, backtesting is a core means of evaluating the effectiveness of trading strategies. Data leakage, or future information leakage, is a highly concealed defect in the backtesting process. It can cause backtesting returns to be inflated, easily misleading developers into identifying strategies with timing flaws as effective strategies with live trading value. Existing mainstream backtesting tools only focus on strategy logic simulation execution and basic return performance calculation, lacking comprehensive automated detection methods. Currently, identifying backtesting data leakage mainly relies on researchers manually reviewing code and verifying data timing, and can only rely on a few performance indicators such as the Sharpe ratio for ex-post evaluation. There is no automated detection scheme that combines multiple multidimensional statistical detections with specialized detections including self-developed unique indicators. Manual review is not only inefficient but also easily affected by subjective experience and human negligence, making it difficult to achieve multi-dimensional cross-validation, automatically output structured reports containing risk level and problem location information, and automatically distinguish whether inflated returns originate from data leakage, making it difficult to efficiently and systematically identify backtesting data leakage risks. Summary of the Invention
[0003] The main purpose of this application is to provide a method, device and storage medium for backtesting and cross-traffic detection in financial transactions, which aims to solve the technical problem that existing backtesting lacks the ability to automatically detect data cross-traffic and cannot accurately identify risks.
[0004] To achieve the above objectives, this application proposes a financial transaction backtesting crossover detection method, which includes: Acquire backtesting data generated by the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence, and transaction records. Based on the backtest data, multi-dimensional statistical detection is performed, including signal lag detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection, to obtain the statistical detection results corresponding to each statistical detection. At least one specific test is performed on the backtest data, the corresponding financial statistical indicators are calculated, and the specific test results corresponding to each specific test are generated. The financial statistical indicators include market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. The statistical detection results are cross-validated with the specific detection results to generate a structured detection report, which includes data traversal risk level and problem location information.
[0005] In one embodiment, the step of performing multidimensional statistical detection based on the backtesting data, including signal hysteresis detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection, includes: Based on the original signal sequence and the yield sequence, signal hysteresis detection is performed to obtain the hysteresis detection result; Based on the yield sequence and each transaction record, a closing return detection is performed to obtain the closing return detection result. Based on the original signal sequence and the yield sequence, perform data mirroring detection to obtain the mirroring detection result; Based on the original signal sequence and the yield sequence, a similarity detection is performed to obtain the similarity detection result; Based on the position sequence and the return sequence, information entropy detection is performed to obtain the information entropy detection result; The lag detection result, the closing reward detection result, the mirror detection result, the similarity detection result, and the information entropy detection result are determined as the statistical detection result.
[0006] In one embodiment, the step of performing signal hysteresis detection based on the original signal sequence and the yield sequence to obtain the hysteresis detection result includes: Read the original signal sequence, the return sequence, and the first preset threshold, wherein the original signal sequence is the signal value for each trading day, and the return sequence is the return for each trading day; Based on the original signal sequence and the return sequence, the signal value of each trading day is multiplied by the return of the corresponding trading day and then summed to obtain the first total return corresponding to the original signal. Based on the original signal sequence, a hysteresis signal sequence is constructed, wherein the hysteresis signal sequence takes the value of the previous position in the original signal sequence, except for the first position which takes the value of zero. Calculate the second total return corresponding to the lag signal based on the lag signal sequence and the return sequence; The difference between the first total revenue and the second total revenue is divided by the absolute value of the first total revenue to obtain the signal lag suspicion score. If the signal lag suspicion score is greater than the first preset threshold and the second total revenue is less than the product of the first total revenue and the preset attenuation coefficient, the strategy to be detected is suspected of data crossing, and a suspicion mark is generated. The signal hysteresis suspicion score and the suspicion marker are used as the hysteresis detection result.
[0007] In one embodiment, the step of performing closing return detection based on the yield sequence and transaction records to obtain the closing return detection result includes: Read the transaction records one by one, and extract the first day return sequence and the last day return sequence corresponding to all transactions from the transaction records one by one, wherein the first day return sequence is the return rate of each transaction on the first trading day, and the last day return sequence is the return rate of each transaction on the last trading day. Remove the first day's return sequence and the last day's return sequence from the return sequence, and aggregate the returns of the remaining trading days to form a normal return sequence; Calculate the first mean and first variance of the first day's return sequence, the second mean and second variance of the last day's return sequence, and the third mean and third variance of the normal return sequence, respectively. Using the first day's return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the first mean, the first variance, the third mean, and the third variance to obtain the first day's test statistic and the corresponding first probability value. Using the last day return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the second mean, the second variance, the third mean, and the third variance to obtain the last day test statistic and the corresponding second probability value. The number of suspected crossing days is determined, wherein the number of suspected crossing days is the square of the difference between the second mean and the third mean, divided by the third mean; Based on the first probability value and the second probability value, the corresponding risk level is determined through a pre-set mapping relationship between the probability value and the suspicion level; The suspected number of days of travel and the risk level are used as the results of the final reward detection.
[0008] In one embodiment, the step of performing data mirroring detection based on the original signal sequence and the return sequence to obtain the mirroring detection result includes: Based on the original signal sequence and the return sequence, backtesting of the strategy to be detected is performed to obtain the cumulative return value of the strategy to be detected on the original data. To generate a mirrored return sequence, take the inverse of each return in the return sequence. Calculate the mirror revenue boundary corresponding to the strategy to be detected, where the mirror revenue boundary value is the negative of the cumulative revenue value; Based on the original signal sequence and the mirrored return rate sequence, backtesting of the strategy to be detected is performed to obtain the actual return value of the strategy to be detected on the mirrored data. Based on the mirrored profit boundary and the actual profit value, the strategy deviation index of the strategy to be detected is obtained. The strategy deviation index is the difference between the mirrored profit boundary and the actual profit value for each trading day, divided by the absolute value of the mirrored profit boundary, and then summed over all trading days and divided by the total number of trading days. If the policy deviation index is greater than a preset second threshold, the policy to be detected is suspected of data crossing, and a suspicion label is generated. The strategy deviation index and the suspected marker are used as the mirror detection result.
[0009] In one embodiment, the step of performing similarity detection based on the original signal sequence and the yield sequence to obtain a similarity detection result includes: Obtain the number of similar market data groups and noise levels; For each set of similar market trends, random noise is superimposed on each return value of the return value sequence to generate a corresponding similar market trend return value sequence. The random noise follows a normal distribution with a mean of 0 and a variance equal to the square of the noise level. Run the strategy to be detected on each group of similar market return sequences and calculate the total return of each group of similar market sequences. Calculate the mean and standard deviation of the total returns for each group, and calculate the corresponding coefficient of variation based on the mean and standard deviation of the total returns. The coefficient of variation is the absolute value of the standard deviation of the total returns for all groups divided by the mean of the total returns for all groups. If the coefficient of variation is greater than a third preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The coefficient of variation and the suspected marker are used as the similarity detection result.
[0010] In one embodiment, the step of performing information entropy detection based on the position sequence and the return sequence to obtain the information entropy detection result includes: Based on the position sequence, the return sequence is split to obtain the signal return sequence under signal conditions and the no-signal return sequence under no-signal conditions; Binning statistical processing is performed on the signal-positive gain sequence and the signal-negative gain sequence respectively to obtain the signal-positive frequency distribution and the signal-negative frequency distribution. After multiplying the proportion of each interval in the signal frequency distribution by the corresponding position weight, the weighted information entropy under the signal condition is calculated. After multiplying the proportion of each interval in the no-signal frequency distribution by the corresponding position weight, the weighted information entropy under the no-signal condition is calculated. The weighted information entropy under the signal condition is divided by the no-signal information entropy to obtain the information entropy ratio. If the information entropy ratio is less than the fourth preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The information entropy ratio and the suspected marker are used as the information entropy detection result.
[0011] In one embodiment, the step of performing at least one specific test on the backtesting data, calculating the corresponding financial statistical indicators, and generating specific test results for each specific test includes: Traverse the position sequence, count the number of trading days with non-zero position values, divide by the total number of trading days to obtain the percentage of time spent in the market; Extract the negative return sequence from the return sequence and calculate the standard deviation of the negative return sequence to obtain the downside bias; Obtain the annualized return of the strategy and the risk-free rate. Subtract the risk-free rate from the annualized return of the strategy to obtain the excess return. Divide the excess return by twice the downside deviation and multiply the resulting quotient by the annualized adjustment factor to obtain the modified Sortino ratio. Extract the profit sequence of all profitable transactions and the loss sequence of all losing transactions from the transaction records, as well as the total number of transactions and the number of profitable transactions. Based on the profit and loss sequence, the loss and gain sequence, the total number of transactions, and the number of profitable transactions, respectively calculate the total profit of all profitable transactions, the absolute value of the total loss of all losing transactions, the average profit of profitable transactions, and the absolute value of the average loss of losing transactions. Dividing the number of profitable trades by the total number of trades yields the win rate; dividing the total profit by the absolute value of the total loss yields the profit-risk factor; and dividing the average profit of profitable trades by the absolute value of the average loss of losing trades yields the average profit-loss ratio. The return-to-cost ratio is obtained by multiplying the risk-reward factor, the win rate, and the average profit-loss ratio. The return series is arranged in ascending order. The average value of the returns above the first preset percentile is extracted to obtain the upper tail mean, and the average value of the returns below the second preset percentile is extracted to obtain the lower tail mean. The absolute value of the upper tail mean is divided by the absolute value of the lower tail mean to obtain the tail ratio. Divide the upper tail mean by the average profit of the profitable trades to obtain the abnormal win rate; The abnormal negative rate is obtained by dividing the lower tail mean by the absolute value of the average loss of the losing transactions.
[0012] Furthermore, to achieve the above objectives, this application also proposes a financial transaction backtesting and crossover detection device, which includes: The front-end data acquisition module is used to acquire backtesting data generated by the backtesting of the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence, and transaction records. The multidimensional statistical detection module is used to perform multidimensional statistical detection based on the backtest data, including signal lag detection, first and last report detection, data mirror detection, similarity detection and information entropy detection, and obtain the statistical detection results corresponding to each statistical detection. The special detection module is used to perform at least one special detection on the backtest data, calculate the corresponding financial statistical indicators, and generate special detection results for each of the special detections. The financial statistical indicators include market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. The fusion judgment and result generation module is used to cross-validate the statistical detection results with the special detection results and generate a structured detection report, which includes data crossing risk level and problem location information.
[0013] In addition, to achieve the above objectives, this application also proposes a financial transaction backtesting and cross-traffic detection device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the financial transaction backtesting and cross-traffic detection method described above.
[0014] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the financial transaction backtesting and cross-pass detection method described above.
[0015] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the financial transaction backtesting and cross-traffic detection method described above.
[0016] The proposed technical solutions (one or more) have at least the following technical effects: First, they acquire backtesting data generated by the strategy to be tested, including original signal sequences, return sequences, position sequences, and individual transaction records. Second, based on the backtesting data, they perform multi-dimensional statistical tests, including signal lag detection, first and last return detection, data mirroring detection, similarity detection, and information entropy detection. This automatically mines statistical anomalies caused by data crossing from different statistical perspectives, obtaining the statistical test results corresponding to each test. Third, they perform at least one specialized test on the backtesting data, calculate the corresponding financial statistical indicators, and generate specialized test results for each test. This avoids drawing conclusions solely based on statistical tests, reducing misjudgments. The financial statistical indicators include market time percentage, corrected Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. Finally, they cross-validate the statistical test results with the specialized test results, comprehensively determine the risk level, and output a structured test report containing location information. This solves the technical problems of existing backtesting methods lacking automatic data crossing detection capabilities and inaccurate risk identification, achieving overall automated and accurate identification of backtesting data crossing risks. Attached Figure Description
[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating an embodiment of the financial transaction backtesting and crossover detection method of this application. Figure 2 This is a schematic diagram of the module structure of the financial transaction backtesting and crossover detection device according to an embodiment of this application; Figure 3 This is a schematic diagram of the device structure of the hardware operating environment involved in the financial transaction backtesting and cross-pass detection method in this application embodiment. Detailed Implementation
[0020] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0021] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0022] The main solution of this application embodiment is as follows: First, acquire backtesting data generated by the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence, and transaction records. Second, based on the backtesting data, perform multi-dimensional statistical tests, including signal lag detection, first and last return detection, data mirroring detection, similarity detection, and information entropy detection, to obtain the statistical test results corresponding to each statistical test. Third, perform at least one specific test on the backtesting data, calculate the corresponding financial statistical indicators, and generate specific test results corresponding to each specific test. The financial statistical indicators include market time percentage, corrected Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. Fourth, cross-validate the statistical test results with the specific test results to generate a structured test report. The structured test report includes data crossing risk level and problem location information.
[0023] In this embodiment, for ease of description, the following description uses the financial transaction backtesting and crossover detection system as the execution subject.
[0024] In the fields of quantitative investment and algorithmic trading, backtesting is a core means of evaluating the effectiveness of trading strategies. Data leakage, or future information leakage, is a highly concealed defect in the backtesting process. It can cause backtesting returns to be inflated, easily misleading developers into identifying strategies with timing flaws as effective strategies with live trading value. Existing mainstream backtesting tools only focus on strategy logic simulation execution and basic return performance calculation, lacking comprehensive automated detection methods. Currently, identifying backtesting data leakage mainly relies on researchers manually reviewing code and verifying data timing, and can only rely on a few performance indicators such as the Sharpe ratio for ex-post evaluation. There is no automated detection scheme that combines multiple multidimensional statistical detections with specialized detections including self-developed unique indicators. Manual review is not only inefficient but also easily affected by subjective experience and human negligence, making it difficult to achieve multi-dimensional cross-validation, automatically output structured reports containing risk level and problem location information, and automatically distinguish whether inflated returns originate from data leakage, making it difficult to efficiently and systematically identify backtesting data leakage risks.
[0025] This application provides a solution to acquire backtesting data, including the original signal sequence, return sequence, position sequence, and transaction records of the strategy to be tested, providing a complete foundation for risk identification and eliminating the need for manual code analysis to understand time-series relationships, as required by traditional methods. Based on this, multi-dimensional statistical detection is performed, including signal lag detection, first and last return detection, data mirroring detection, similarity detection, and information entropy detection. This automatically mines statistical anomalies caused by data crossings from multiple perspectives, such as signal time-series offset, distribution of first and last trade returns, mirrored market performance, strategy perturbation robustness, and uncertainty of return information, outputting corresponding statistical detection results. This achieves automated extraction of clues to potential future information leaks, compensating for the lack of automatic statistical screening methods in existing backtesting frameworks. Subsequently, specialized detection is conducted on the backtesting data, calculating financial statistical indicators such as market time percentage, corrected Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate to obtain specialized detection results. These provide corroborating information on strategy anomalies from the perspectives of holding behavior, risk-return matching, and extreme profit and loss characteristics, avoiding misjudgments based solely on a single statistical feature. Finally, the statistical test results are cross-validated with the special test results, and the results are weighed and judged in a comprehensive manner based on multiple clues. A structured test report carrying the risk level and problem location information of data crossing is generated, thereby solving the technical problems of the lack of automatic detection of data crossing and insufficient accuracy of risk identification in the existing backtesting.
[0026] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or a financial transaction backtesting and bypass detection device capable of performing the above functions. The following description uses a financial transaction backtesting and bypass detection system as an example to illustrate this embodiment and the subsequent embodiments.
[0027] Based on this, embodiments of this application provide a method for detecting backtesting crossovers in financial transactions, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the financial transaction backtesting and crossover detection method of this application.
[0028] In this embodiment, the financial transaction backtesting and crossover detection method includes steps 101-104: Step 101: Obtain backtesting data generated by the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence, and transaction records.
[0029] Specifically, the strategy to be tested is a quantitative trading strategy that has completed backtesting and needs to undergo data cross-validation. This strategy typically exists in the form of programmatic code, including stock selection logic, market timing logic, position management rules, and profit-taking and stop-loss conditions. Backtesting uses historical market data to simulate the strategy's trading performance over a past period, generating virtual trading records and performance results. Backtesting data is the complete set of structured data generated during the strategy backtesting process that can fully describe the strategy's behavior and the market environment. The original signal sequence refers to the time series data composed of the buy and sell signals output by the strategy to be tested on each trading day during the backtesting process. The return sequence refers to the time series data composed of the returns on each trading day within the backtesting period. The position sequence refers to the time series data composed of the actual position size of the strategy to be tested on each trading day during the backtesting process. A transaction record refers to a detailed list of all transactions (buy and sell operations) executed by the strategy during backtesting. Each transaction record typically includes the following information: opening date, opening price, opening quantity (or amount), closing date, closing price, closing quantity (or amount), holding days, profit / loss amount and percentage of profit / loss for that transaction, etc.
[0030] In some embodiments, the output of the strategy under test after backtesting simulation is read to provide a complete and aligned basic data source for subsequent multidimensional statistical detection and specialized detection. First, the strategy under test that has completed historical backtesting simulation is located. This strategy has completed its logic calculations within the backtesting framework, and the backtesting results are either stored locally or output through an external interface. Next, the backtesting results are read from the storage location or data output interface of the backtesting framework, extracting four core data types: original signal sequence, return sequence, position sequence, and transaction records. Then, data integrity and temporal consistency checks are performed. This verifies whether all four data types (original signal sequence, return sequence, position sequence, and transaction records) have been completely acquired, checks the timestamp indices of each sequence to ensure that the time dimensions of the original signal sequence, return sequence, and position sequence match one-to-one, and verifies that the opening and closing timestamps in the transaction records correspond to the times of the aforementioned sequences. When the detection finds any anomalies such as missing data or misaligned time indices, a data anomaly message is output, and subsequent detection processes are stopped. After all verifications pass, the verified original signal sequences, return sequences, position sequences, and transaction records are packaged into backtesting data and output to subsequent processing stages for multidimensional statistical testing and specialized testing. This avoids misjudgments or inability to execute subsequent tests due to input data defects. Through structured collection and standardized processing, scattered and fragmented data are integrated into a unified testing data source, providing a reliable data foundation for subsequent automated testing.
[0031] Step 102: Based on the backtest data, perform multi-dimensional statistical detection including signal lag detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection to obtain the statistical detection results corresponding to each statistical detection.
[0032] Specifically, signal lag detection involves lag-processing the original signal (usually by one period) and comparing the returns of the original and lagged signals. If the returns of the lagged signal decrease significantly, it indicates that the original signal may have utilized future data. First and last day returns refer to the first and last day returns in each transaction. Generally, if no data crossing occurs, the distribution of first and last day returns should be the same as the distribution of daily returns. Data mirroring detection involves mirroring the original market data, making the original and mirrored data sets completely negatively correlated. Data mirroring detection is specifically used to detect situations where data processing and factor calculations are correct, but data misuse occurs during strategy development. Similarity detection involves generating similar market data from the original data in descending order of similarity and observing the strategy's return performance on these similar market data. If a significant monotonic change occurs as similarity decreases, it indicates that the strategy is not stable enough and reacts strongly to small random changes, suggesting the existence of data crossing. Information entropy detection is made by comparing the information entropy of returns under signal conditions with that under no signal conditions. If the information entropy of returns under signal conditions is much smaller than that under no signal conditions, it indicates that the signal "only picked out market conditions with very consistent direction", which may contain future information, and it is judged that data crossing has occurred.
[0033] In some embodiments, multiple statistical tests are performed sequentially based on the acquired structured backtesting data. In signal lag detection, the original signal sequence is shifted back by one time unit, the strategy return is recalculated, and the lagged return is compared with the original return. If the return shows a sharp drop, it is determined that the signal has an abnormal dependence on current information. In first and last return detection, the returns of the first and last days of each transaction are extracted based on each transaction record, and statistical tests such as t-tests are performed with the returns of normal holding days in between to identify whether there are abnormally high returns at the opening and closing boundaries. In data mirroring detection, the entire return sequence is inverted, and the strategy's return performance under completely opposite market conditions is recalculated to examine whether the returns exhibit theoretically symmetrical characteristics. If there is a significant deviation, it indicates that the strategy's additional logic may reference future information. In similarity detection, multiple sets of small random perturbations are superimposed on the return sequence, and the strategy's return under each perturbation market condition is calculated. The magnitude of return fluctuations is used to determine whether the strategy has an excessive dependence on a specific data path. In information entropy detection, the distribution of returns is statistically analyzed during periods with and without signals, and conditional information entropy is calculated to measure the degree to which the signal eliminates uncertainty in returns. If the elimination degree is abnormally close to complete, it suggests that the signal may predict future returns. The above multiple detections are executed in parallel and are independent of each other, each outputting statistical detection results containing judgment conclusions and quantitative indicators. This systematically screens for data traversal risks from multiple dimensions, including signal lag, abnormal distribution at the beginning and end, mirror symmetry, robustness, and changes in information entropy.
[0034] Optionally, based on backtesting data, the steps of performing multidimensional statistical detection, including signal hysteresis detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection, include: Based on the original signal sequence and the yield sequence, signal hysteresis detection is performed to obtain the hysteresis detection results; Based on the yield series and transaction records, a closing return detection is performed to obtain the closing return detection results. Based on the original signal sequence and the yield sequence, data mirroring detection is performed to obtain the mirroring detection results; Based on the original signal sequence and the yield sequence, similarity detection is performed to obtain the similarity detection results; Based on the position sequence and return sequence, information entropy detection is performed to obtain the information entropy detection results; The results of lag detection, closing report detection, mirror detection, similarity detection, and information entropy detection are defined as statistical detection results.
[0035] Specifically, firstly, the original signal sequence and return sequence are obtained. The original signal sequence is shifted forward by one trading day to generate a lagged signal sequence. The total return of the original signal and the total return of the lagged signal are calculated separately, and then a signal lag suspicion score is calculated. By comparing the signal lag suspicion score with a first preset threshold, it is determined whether the strategy signal referenced future information that was not available on the current day when making decisions, and the lag detection result is output. Secondly, the start and end positions of each transaction are identified based on the signal sequence, and the first-day return sequence and the last-day return sequence are extracted. A normal return sequence is also extracted. Statistical tests are performed on the first-day return and normal return, and the last-day return and normal return to calculate probability values. At the same time, the number of suspected crossover days is calculated. Based on the probability values, the risk level is determined as high-risk, medium-risk, or low-risk, and the first- and last-day return detection results are obtained. Thirdly, a mirrored return sequence is generated based on the original signal sequence and return sequence. The strategy to be tested is run on the original data and the mirrored data respectively, and the strategy deviation index is calculated. By comparing the strategy deviation index with a second preset threshold, it is determined whether the condition judgment, profit-taking and stop-loss rules in the strategy excessively dominate the returns, and the mirror detection result is output. Simultaneously, multiple sets of similar market return sequences with superimposed random noise are generated. The strategy to be tested is run on each set of similar market return sequences, and the coefficient of variation of the total return for each set is calculated. By comparing the coefficient of variation with a third preset threshold, it is determined whether the strategy is overly sensitive to small random disturbances, and the similarity detection result is output. Finally, based on the position sequence and return sequence, return sequences under signal conditions and no signal conditions are extracted, and the weighted information entropy under the two conditions is calculated. The information entropy ratio is calculated, and by comparing the information entropy ratio with a fourth preset threshold, it is determined whether the signal over-filters market trends in a specific direction, leading to an abnormally reduced uncertainty in returns, and the information entropy detection result is output. The above lag detection results, first and last return detection results, mirror detection results, similarity detection results, and information entropy detection results are integrated and encapsulated to form a complete statistical detection result, which is output for subsequent cross-validation steps.
[0036] Step 103: Perform at least one special test on the backtest data, calculate the corresponding financial statistics, and generate the special test results for each special test. The financial statistics include market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate.
[0037] Specifically, specialized testing refers to the process of generating a series of financial statistical indicators and comparing and judging these indicators in conjunction with the design intent of the strategy under test (such as strategy type, expected return source, risk preference, etc.). Financial statistical indicators are various statistical quantities used to quantify and evaluate strategy performance, covering multiple dimensions such as return level, risk level, risk-adjusted return, extreme performance, and fund management. This application provides 46 financial statistical indicators, of which 40 are standard indicators (such as Sharpe ratio, Sortino ratio, maximum drawdown, Kalman ratio, skewness, kurtosis, and value at risk), and 6 are self-developed indicators of this application, namely, market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. Standard indicators are used to provide industry-standard evaluation benchmarks, while self-developed indicators are used to compensate for the shortcomings of standard indicators in data cross-cutting detection. Table 1 below is a list of financial statistical indicators of this application.
[0038] Table 1 List of Financial Statistical Indicators
[0039] The time spent in the market (or holding a position) refers to the proportion of trading time during the entire backtesting period, denoted as Time_in_Market. The formula for Time_in_Market is: Time_in_Market = (1 / n) × ΣI (position_i ≠ 0), where n is the total number of trading days, and I is an indicator function. I takes a value of 1 when the position value on the i-th trading day is not equal to 0 (indicating that the strategy is in a holding position) and 0 when it is equal to 0 (indicating that the strategy is out of the market). The Time_in_Market percentage reflects the strategy's market exposure. A higher percentage indicates a strategy that is more likely to participate in the market continuously; a lower percentage indicates a strategy that is more likely to engage in market timing. The Time_in_Market percentage can be used to adjust traditional risk-return indicators such as annualized volatility and Sharpe ratio for position weighting, making strategies with different position levels comparable.
[0040] The modified Sortino ratio is an improvement upon the traditional Sortino ratio. This application modifies the Sortino ratio, and the formula for calculating the modified Sortino ratio is: Sortino_adj=(R-Rf) / (2×σ_down)× Where R is the annualized return of the strategy, Rf is the risk-free rate, and σ_down is the downside deviation (only the standard deviation of the return on days with negative returns is counted). This is an annualized adjustment factor. The adjusted Sortino ratio is comparable to the Sharpe ratio, facilitating a comprehensive assessment of the strategy's risk-adjusted returns.
[0041] The cost-return ratio (CPC) is a comprehensive strategy evaluation metric used to describe the return per unit of cost, examining three dimensions: profitability, stability, and risk control. The formula for calculating the CPC is: CPC_Index = Profit_Factor × Win_Rate × Win_Loss_Ratio. Where: Profit_Factor (return-risk factor) = Σ(gains) / |Σ(losses)|, which is the absolute value of the total profit of all winning trades divided by the absolute value of the total loss of all losing trades, reflecting the overall profit-loss ratio of the strategy; Win_Rate (win rate) = N_wins / N_total, which is the proportion of winning trades to the total number of trades, reflecting the strategy's win rate; Win_Loss_Ratio (average profit-loss ratio) = μ_wins / |μ_losses|, which is the absolute value of the average profit of all winning trades divided by the absolute value of the average loss of all losing trades. Multiplying the return-risk factor, win rate, and average profit-loss ratio yields the cost-return ratio.
[0042] The tail ratio is used to evaluate a strategy's performance in extreme situations, describing the return ratio between extreme values. The formula for the tail ratio (Tail_Ratio) is: Tail_Ratio = |μ_upper_quantile| / |μ_lower_quantile|, where μ_upper_quantile is the mean of the upper quantile (default 95%) returns, i.e., the average return of the top 5% of trading days; and μ_lower_quantile is the mean of the lower quantile (default 5%) returns, i.e., the average return of the bottom 5% of trading days. The tail ratio reflects the symmetry of returns in extreme situations.
[0043] Outlier win rate is used to identify whether a strategy has abnormally high winning trades, i.e., whether a few "super-profitable" trades dominate all profits. The outlier win rate (Outlier_Win_Ratio) is calculated as: Outlier_Win_Ratio = μ_upper_quantile / μ_wins, where μ_upper_quantile is the average of the upper quantile (default 95%) returns, and μ_wins is the average of the returns of all winning trades. If the outlier win rate is significantly greater than 1, it indicates that the strategy has abnormally high returns, with a few extremely profitable trades contributing the majority of profits. This may be due to lucky trades caused by data slippage and requires close investigation.
[0044] The Outlier Loss Ratio is used to identify whether a strategy has abnormally high losses. The Outlier Loss Ratio is calculated as: Outlier Loss Ratio = μ_lower_quantile / μ_losses, where μ_lower_quantile is the mean of the lower quantile (default 5%) returns, and μ_losses is the mean of the returns of all losing trades. If the Outlier Loss Ratio deviates significantly from 1, it indicates that the strategy has abnormally high losses, which may be a signal of risk control failure.
[0045] In some embodiments, at least one specific test is performed according to the configuration, and the financial statistical indicators to be calculated are selected. The indicator set includes market time percentage, adjusted Sortino ratio, cost-return ratio, tail ratio, abnormal win rate, and abnormal loss rate. When calculating the market time percentage, based on the position sequence, the number of trading days when the strategy is not in a cash position is counted, and the result is divided by the total number of trading days to obtain the market time percentage indicator value. When calculating the adjusted Sortino ratio, the excess return is converted based on strategy return, risk-free rate, and downside bias to obtain an adjusted Sortino ratio comparable to the Sharpe ratio. When calculating the cost-return ratio, the return-risk factor, win rate, and average profit-loss ratio are calculated separately for each transaction record, and the three are multiplied to obtain the cost-return ratio. When calculating the tail ratio, the mean of high quantile returns and the mean of low quantile returns are extracted, and their absolute values are divided. When calculating the abnormal win rate, the mean of high quantile returns is divided by the average profit of all profitable trades. When calculating the abnormal loss rate, the mean of low quantile returns is divided by the average loss of all losing trades. After calculation, anomaly detection can be performed on various self-developed indicators based on preset thresholds, generating corresponding anomaly tags. All calculated financial statistical indicator values and corresponding anomaly tags are integrated and packaged to generate specialized detection results. These results are then used for cross-validation of subsequent statistical detection results, distinguishing between anomalies caused by data crossing and those resulting from the strategy's risk control or tail returns. Specialized detection results are obtained by calculating multiple self-developed financial statistical indicators from the perspectives of strategy performance, holding behavior, and extreme profit and loss characteristics. At least one indicator can be calculated individually, or all six indicators can be calculated to corroborate suspicious clues in the statistical detection output, differentiating between different scenarios such as inflated returns from data crossing, extreme tail risks, and risk control failures. This overcomes the shortcomings of traditional strategies that rely solely on general indicators such as the Sharpe ratio for evaluation.
[0046] Step 104: Cross-validate the statistical test results with the special test results to generate a structured test report. The structured test report includes the data crossing risk level and problem location information.
[0047] Specifically, cross-validation refers to comprehensively comparing multiple suspicious markers and scores from statistical testing, combined with performance indicators from specific testing, according to pre-set judgment rules. It does not rely solely on the conclusions of any single test; multiple pieces of evidence corroborate each other to comprehensively determine the risk. The data crossing risk level is a comprehensive quantitative assessment of the possibility of data crossing in the strategy being tested. The risk level can be divided into four levels: high risk (the strategy has an extremely high probability of data crossing, rejection is recommended), medium risk (the strategy is suspected of having data crossing, item-by-item investigation is recommended), low risk (no obvious signs of crossing are found, proceed to the next stage of evaluation), and no risk (all tests pass, no abnormalities are found). Problem location information is used to precisely identify the specific links and locations where data crossing may occur. For example, if the risk level of the first day in the initial and final return detection is high risk, the problem location information would be "Abnormal first-day return, suspected of introducing future information in the data preprocessing or factor construction stage; it is recommended to investigate the pre-adjusted price calculation logic." If the risk level of the last day is high risk and the suspected crossover period is 3.2 days, the problem location information would be "Abnormal last-day return, suspected of referencing future price data in the closing logic; it is recommended to investigate whether the closing conditions reference the price N days after the closing date." This problem location information provides precise guidance for developers' subsequent code investigation.
[0048] In some embodiments, firstly, all output results of multiple statistical tests (statistical test results) are summarized, including the suspicion score and suspicion mark of signal lag detection, the suspected number of crossing days and the risk level of the first / last day of the first and last ...
[0049] Secondly, the aggregated statistical and specialized detection results are used as input. Using a rule matrix, a preset cross-validation rule matching is executed. The rule matrix defines the combination conditions of multiple sets of detection results and their corresponding cross-crossing suspicion weights. For example, if the information entropy detection alarm is triggered (entropy ratio less than 0.5) and the abnormal win rate is greater than the first abnormal threshold (default 2.0) and the tail ratio is greater than the second abnormal threshold (default 1.5), it indicates that the overly precise screening of signals at the statistical level and the concentration of extreme returns at the specialized level mutually confirm each other, both pointing to data cross-crossing. This rule triggers a high-weight bonus. If the signal lag detection alarm is triggered and the risk level of the last day in the first and last return detection is high risk, it indicates that the time axis logic and the abnormal returns at the transaction boundary mutually confirm each other. This rule triggers a high-weight bonus. If the similarity detection alarm is triggered but all specialized indicators are normal, it indicates that the strategy is sensitive to random disturbances but the return structure has no obvious abnormalities. Only a low-weight bonus is triggered, and manual review is recommended.
[0050] Next, a comprehensive score is calculated by summing the weights of all hit rules. Based on the mapping relationship between the preset score range and the risk level, the final data crossing risk level is determined: a comprehensive score higher than the first score threshold is considered high risk, a score between the first and second score thresholds is considered medium risk, a score lower than the second score threshold but greater than zero is considered low risk, and no rule is considered no risk.
[0051] Simultaneously, based on the specific rules and corresponding detection results, problem location information is generated. If the risk level of the first day of the first and last day's return detection is high risk, the problem location information can be marked as "abnormal first day return, suspected data preprocessing or factor construction stage introduces future information, it is recommended to check the pre-adjusted price calculation logic"; if the risk level of the last day is high risk and the suspected number of days of crossing is greater than the threshold of the first day, it can be marked as "abnormal last day return, suspected the closing logic references future price data, it is recommended to check the data reference in the closing conditions"; if the information entropy detection alarm is triggered and the abnormal win rate is extremely high, it can be marked as "the return distribution is too concentrated, it is recommended to check whether future information is referenced in the factor construction".
[0052] Finally, the basic information of the strategy, the summary table of various test results, the data crossing risk level, the problem location information, and the handling suggestions are assembled according to the preset format to generate a complete structured test report and output it. By integrating and analyzing the scattered test results through cross-verification rules, a structured test report is generated from the perspective of multi-dimensional evidence cross-verification, realizing the automatic identification and precise location of data crossing risks. This provides R&D personnel with a clear direction for investigation and effectively solves the problems of relying on manual comprehensive judgment and inconsistent standards in existing technologies.
[0053] Based on the financial transaction backtesting crossover detection method provided in this application, backtesting data generated by the strategy to be tested is obtained. This backtesting data includes the original signal sequence, return sequence, position sequence, and individual transaction records. Based on the backtesting data, multi-dimensional statistical detection is performed, including signal lag detection, first and last return detection, data mirroring detection, similarity detection, and information entropy detection. This automatically mines statistical anomalies caused by data crossover from different statistical perspectives, obtaining the statistical detection results corresponding to each detection. Simultaneously, at least one specific detection is performed on the backtesting data, calculating the corresponding financial statistical indicators and generating specific detection results for each detection. This avoids drawing conclusions solely based on statistical detection, reducing misjudgments. Financial statistical indicators include market time percentage, corrected Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. Finally, the statistical detection results are cross-validated with the specific detection results to comprehensively determine the risk level and output a structured detection report containing location information. This solves the technical problems of existing backtesting methods lacking automatic data crossover detection capabilities and inaccurate risk identification, achieving overall automated and accurate identification of backtesting data crossover risks.
[0054] In some embodiments, the step of performing signal hysteresis detection based on the original signal sequence and the yield sequence to obtain the hysteresis detection result includes: Read the original signal sequence, the return sequence, and the first preset threshold, where the original signal sequence is the signal value for each trading day, and the return sequence is the return for each trading day; Based on the original signal sequence and the return sequence, the signal value of each trading day is multiplied by the return of the corresponding trading day and then summed to obtain the first total return corresponding to the original signal. Based on the original signal sequence, a delayed signal sequence is constructed, wherein the delayed signal sequence takes the value of the previous position in the original signal sequence, except for the first position which takes the value of zero. Calculate the second total return corresponding to the lagged signal based on the lagged signal sequence and the return sequence; The difference between the first total return and the second total return is divided by the absolute value of the first total return to obtain the signal lag suspicion score. If the signal lag suspicion score is greater than the first preset threshold and the second total revenue is less than the product of the first total revenue and the preset attenuation coefficient, the strategy to be detected is suspected of data crossing, and a suspicion label is generated. The signal hysteresis suspicion score and suspicion marker are used as the hysteresis detection results.
[0055] Specifically, the lagged signal sequence is a new sequence obtained by shifting the original signal sequence over time. The specific construction method is as follows: the entire sequence is shifted forward by one trading day; that is, the signal value of the i-th trading day in the original sequence is moved to the (i+1)-th trading day position in the new sequence. The first position of the new sequence is padded with 0, and the signal value of the last position is removed from the sequence. The lagged signal sequence simulates the scenario of "the strategy delaying the execution of trading instructions by one day," serving as the basis for calculating lagged returns. The signal lag suspicion score is a quantitative indicator measuring the strategy's dependence on the "immediacy of the signal." The calculation formula is: first total return minus second total return, then divided by the absolute value of the first total return. The range of the signal lag suspicion score is unrestricted; the higher the score, the stronger the strategy's dependence on the immediate execution of the signal on the same day (i.e., execution on the day the signal is generated), and the greater the suspicion of using future information. The first preset threshold (default value is 0.5) is used to determine whether the signal lag suspicion score exceeds a reasonable range; the preset attenuation coefficient (default value is 0.5) is used to determine whether the lagged return is significantly inferior to the original return. The suspicion flag is the judgment conclusion of the signal lag detection, and the value is "suspicious" or "not suspicious". When the signal lag suspicion score is greater than the first preset threshold and the second total revenue is less than the product of the first total revenue and the preset attenuation coefficient, the suspicion flag is set to "suspicious", indicating that the strategy has a data crossing risk and needs to be focused on in subsequent detection; otherwise, it is "not suspicious".
[0056] As an example, first, read the original signal sequence S={s1,s2,...,s...} i ,...,s n The return sequence R = {r1, r2, ..., r} i ,...,r n The original signal sequence records the strategy signal value for each trading day within the backtesting period, typically represented by 1 for holding a position and 0 for being out of the market. The return sequence records the market return for each corresponding trading day. Both the original signal sequence and the return sequence are based on the exchange's trading calendar, ensuring strict time alignment. Next, the first total return corresponding to the original signal is calculated based on the original signal sequence and the return sequence. Specifically, for each trading day within the backtesting period, the signal value for that day is multiplied by the return for that day, and the products for all trading days are summed to obtain the first total return. The formula is: TotalReturn_original=Σ(r i ×s i ), where s i Let r be the signal value for the i-th trading day. iis the rate of return on the i-th trading day, and TotalReturn_original is the first total return. Next, a lagged signal sequence is constructed based on the original signal sequence, and the specific construction method is to generate a new sequence of the same length as the original signal sequence, set the first position of the new sequence to 0, and move the value at the (i-1)-th position in the original signal sequence to the i-th position of the new sequence (i>1), that is, s' i =s i -1 (i>1), s'₁=0, which is equivalent to shifting the entire original signal sequence backward by one trading day, and the last value of the original signal sequence is moved out of the sequence. The physical meaning of the lagged signal sequence is that the strategy only uses the signal of the previous trading day to guide the trading of the current day, which is a legal control version closest to the original signal without introducing future information. Then, the lagged signal sequence and the rate of return sequence are multiplied day by day and then summed up to obtain the second total return corresponding to the lagged signal, where TotalReturn_lagged=Σ(r i ×s' i ), and the second total return TotalReturn_lagged represents the theoretical return of the strategy under legal timing constraints, reflecting the return performance when all signals of the strategy are executed with a delay of one trading day. After that, the difference between the first total return and the second total return is divided by the absolute value of the first total return, and the calculation formula of the signal lag suspicion score is obtained as: SuspicionScore=(TotalReturn_original-TotalReturn_lagged) / |TotalReturn_original|. The signal lag suspicion score SuspicionScore is used to measure the degree of dependence of the strategy return on the immediate execution of the signal. Finally, a dual condition judgment is performed: if the SuspicionScore is greater than a first preset threshold (default 0.5), and the second total return is less than the product of the first total return and a preset attenuation coefficient (default 0.5), that is, TotalReturn_lagged<TotalReturn_original×0.5, it is determined that the to-be-detected strategy has a suspicion of data peeking, and a suspicion mark is generated; otherwise, it is determined that there is no suspicion. The suspicion score and the suspicion mark are jointly output as the lag detection result for subsequent cross-validation. The signal lag detection quantifies the degree of return attenuation before and after the delayed execution of the signal, and directly tests whether the strategy signal depends on the current day or future return information by constructing a time-shifted control experiment, converting the qualitative judgment of data peeking into a quantifiable statistical score and a clear binary conclusion, so as to provide independent and reusable time dimension evidence for subsequent multi-dimensional cross-validation.
[0057] In some embodiments, the step of performing tail return detection based on the rate of return sequence and transaction-by-transaction records to obtain a tail return detection result comprises: Read each transaction record and extract the first-day return sequence and the last-day return sequence for all transactions from the transaction records. The first-day return sequence is the return rate of each transaction on the first trading day, and the last-day return sequence is the return rate of each transaction on the last trading day. Remove the first day's return sequence and the last day's return sequence from the return sequence, and aggregate the returns of the remaining trading days to form a normal return sequence; Calculate the first mean and first variance of the first day's return sequence, the second mean and second variance of the last day's return sequence, and the third mean and third variance of the normal return sequence, respectively; Using the first day's return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the first mean, first variance, third mean, and third variance to obtain the first day's test statistic and the corresponding first probability value. Using the last day's return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the second mean, second variance, third mean, and third variance to obtain the last day test statistic and the corresponding second probability value. The suspected number of days of crossing is determined by dividing the difference between the second mean and the third mean by the square of the third mean. Based on the first probability value and the second probability value, the corresponding risk level is determined through the pre-set mapping relationship between the probability value and the suspicion level; The suspected number of days traversed and the risk level will be used as the final report detection results.
[0058] Specifically, the two-sample mean difference test (i.e., the t-test) is a statistical hypothesis testing method used to determine whether there is a significant difference between the means of two independent samples. In this application, the first-day return sequence and the normal return sequence are used as one pair of comparison groups, and the last-day return sequence and the normal return sequence are used as another pair of comparison groups, and the tests are performed separately. The null hypothesis of the test is that "there is no significant difference between the means of the two groups of samples," that is, the first-day return or the last-day return and the normal return come from the same distribution. If the test result rejects the null hypothesis, it indicates that there is a significant difference between the boundary day return and the normal day return, suggesting that there may be data crossing. The mapping relationship between the probability value and the suspicion level is a preset rule used to determine the risk level during the execution of the closing return detection process. The specific rule is as follows: if the probability value is less than the first probability threshold (default 0.01), it is judged as "high risk," indicating that there is extremely strong evidence that the boundary day return distribution is abnormal; if the probability value is less than the second probability threshold (default 0.05) and greater than or equal to the first probability threshold, it is judged as "medium risk"; if the probability value is greater than or equal to the second probability threshold, it is judged as "low risk." The risk level can be set to "high risk", "medium risk" or "low risk".
[0059] As an example, we read each transaction record and the complete return series, iterate through each transaction record, extract the return corresponding to the opening day of each transaction to form the first-day return series, and extract the return corresponding to the closing day of each transaction to form the last-day return series. The first-day return series reflects the strategy's performance on the opening day of each transaction, and the last-day return series reflects the strategy's performance on the closing day of each transaction. Then, we remove all returns marked as first and last days from the complete return series, and aggregate the returns of the remaining trading days in chronological order to form the normal return series. This normal return series represents the return distribution of ordinary trading days without special selection by the strategy, serving as an unbiased control benchmark for subsequent statistical tests. Next, we calculate the first mean and first variance of the first-day return series, the second mean and second variance of the last-day return series, and the third mean and third variance of the normal return series, providing the necessary statistics for subsequent hypothesis testing. Using the first day's return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test (i.e., a t-test) is performed based on the first mean, first variance, third mean, and third variance. The test statistic is t = (μ_test - μ_common) / √(σ²_test / n_test + σ²_common / n_common), where μ_test, σ²_test, and n_test are the mean, variance, and sample size of the first day's return sequence, respectively, and μ_common, σ²_common, and n_common are the mean, variance, and sample size of the normal return sequence, respectively. This yields the first-day test statistic and its corresponding first probability value (i.e., the p-value). Similarly, using the last day's return sequence as the sample to be tested and the normal return sequence as the control sample, the same two-sample mean difference test is performed based on the second mean, second variance, third mean, and third variance, yielding the last day's test statistic and its corresponding second probability value. Next, the suspected crossover days are calculated using the formula Days_of_Lookahead=((μ_last-μ_common) / μ_common)², where μ_last is the second mean of the last day's return sequence and μ_common is the third mean of the normal return sequence. This indicator quantifies the severity of the crossover by measuring the deviation of the last day's return from the normal return. The squaring operation eliminates the influence of positive and negative directions, so that regardless of whether the last day's return is high or low, the greater the deviation, the greater the suspected crossover days. Finally, the first and second probability values are converted into corresponding discrete risk levels through a preset mapping relationship between probability values and suspicion levels. This mapping relationship divides the continuous p-value range into several levels; for example, a p-value less than 0.01 is mapped to high risk, a p-value between 0.01 and 0.05 is mapped to medium risk, and a p-value greater than 0.05 is mapped to low risk. The higher level between the first and last day is taken as the final risk level.The suspected crossover days and risk level are combined as the output of the opening and closing return detection results for subsequent cross-validation and report generation. This closing return detection, by analyzing the statistical difference between the daily return at the trading boundary and the normal daily return, can accurately pinpoint whether the data crossover occurred during the opening or closing phase, and estimate the time range of the data crossover, providing precise guidance for subsequent code investigation.
[0060] In some embodiments, the step of performing data mirroring detection based on the original signal sequence and the yield sequence to obtain the mirroring detection result includes: Based on the original signal sequence and return sequence, backtesting is performed on the strategy to be tested to obtain the cumulative return value of the strategy to be tested on the original data. By taking the inverse of each return in the return series, a mirrored return series is generated. Calculate the mirror revenue boundary corresponding to the policy to be detected. The mirror revenue boundary value is the negative of the cumulative revenue value. Based on the original signal sequence and the mirrored return sequence, backtesting is performed on the strategy to be tested to obtain the actual return value of the strategy to be tested on the mirrored data. Based on the mirrored profit boundary and the actual profit value, the strategy deviation index of the strategy to be tested is obtained. The strategy deviation index is the difference between the mirrored profit boundary and the actual profit value for each trading day, divided by the absolute value of the mirrored profit boundary, and then summed over all trading days and divided by the total number of trading days. If the strategy deviation index is greater than the preset second threshold, the strategy to be detected is suspected of data crossing and a suspected flag is generated. The strategy deviation index and the suspected marker are used as the mirror detection results.
[0061] Specifically, the rules for profit taking, stop loss, and condition filtering in a normal strategy are designed to capture positive returns. In a completely reversed mirror market, the actual return of the strategy should fall between the negative value of the original accumulated return (the mirror return boundary) and the original accumulated return. If the strategy deviation index is too high, it means that the strategy's trading logic is overly adapted to the certain future market conditions, and there is a high probability of data crossing.
[0062] The mirror return boundary refers to the negative of the original cumulative return value. If a strategy relies entirely on market direction to generate returns (i.e., profiting when the market rises and profiting when the market falls), then in a mirror market, the strategy's return should be exactly equal to the negative of the original cumulative return. The mirror return boundary is this theoretical expected value. The actual return value is the cumulative return value obtained by backtesting the same strategy on a mirror return sequence. This actual return value reflects the strategy's true performance in a completely reversing market environment. The strategy deviation index is a quantitative indicator that measures the degree to which the strategy's conditional logic (such as profit-taking, stop-loss, weighted smoothing, etc.) affects the return. Its calculation formula is: for each trading day, subtract the actual return value of that trading day from the mirror return boundary of that trading day, divide the difference by the absolute value of the mirror return boundary, sum over all trading days, and then divide by the total number of trading days. The practical meaning of the strategy deviation index is the average relative degree to which the strategy's return deviates from the theoretical mirror boundary. If the strategy relies entirely on market direction, the strategy deviation index is close to 0; if the strategy's conditional rules generate abnormal returns in the mirror market, the strategy deviation index increases. When the strategy deviation index exceeds the preset second threshold, it indicates that the influence of factors such as conditional judgments in the strategy logic has exceeded the factors themselves, and there is a suspicion of data crossing.
[0063] As an example, firstly, the original signal sequence and the original return sequence are read, aligned along the time axis, and then a backtesting operation is performed on the strategy to be tested. That is, the original signal value is used as the strategy's position indicator, and the strategy is simulated on the original return sequence, with the returns accumulated daily to obtain the cumulative return value of the strategy on the original data, denoted as raw_gain. This value serves as the benchmark for all subsequent comparative calculations. Secondly, the inverse of each return value in the original return sequence is taken to generate a mirrored return sequence, i.e., r_mirror_i = -r_original_i. This mirrored return sequence simulates a market environment completely opposite to the original market; that is, when the original market rises, the mirrored market falls, and vice versa. Simultaneously, the inverse of the cumulative return value raw_gain is taken to calculate the mirrored return boundary value mirror_gain = -raw_gain. This mirrored return boundary value represents the theoretical expected return; that is, if the strategy's return comes entirely from correct judgment of market direction, then the strategy should incur exactly the same loss in the mirrored market. Next, using the original signal sequence as the position indicator and the mirrored return sequence as the market input, the backtesting calculation of the strategy under test is re-executed to obtain the actual return value of the strategy on the mirrored data, real_gain. This actual return value reflects the true performance of the strategy in a completely reversing market environment. Then, based on the mirrored return boundary value and the actual return value, the strategy deviation index StrategyPct is calculated. The specific calculation formula is as follows: StrategyPct=(1 / n)×Σ((mirror_gain_i-real_gain_i) / |mirror_gain_i|) Where n is the total number of trading days, mirror_gain_i is the mirrored profit boundary on the i-th trading day, and real_gain_i is the actual profit value on the i-th trading day. The strategy deviation index, StrategyPct, quantifies the impact of strategy condition rules (such as profit-taking, stop-loss, and weighted smoothing) on profits by calculating the relative deviation between the mirrored profit boundary and the actual profit for each trading day and taking the average. Finally, the strategy deviation index is compared with a preset second threshold (default 0.5). If StrategyPct is greater than 0.5, the strategy under test is judged to have data crossing suspicion, and a "suspicious" suspicion label is generated; otherwise, a "not suspicious" suspicion label is generated. The strategy deviation index and the suspicion label are used together as the mirror detection result output for subsequent cross-validation and report generation. Data mirror detection can effectively identify whether the impact of condition judgments, profit-taking, stop-loss, and other rules in the strategy exceeds the factors themselves, screening for data crossing risks from the logical structure dimension, and providing an important basis for evaluating the reliability of the strategy. By performing data mirroring detection, a directionally symmetrical virtual market environment is constructed. From the perspective of "directional symmetry breaking", it is examined whether the strategy signal has an asymmetric dependence on the direction of the original data. This forms a positive interaction with the time shift perspective of signal lag detection and the transaction boundary perspective of closing return detection, providing independent directional dimension evidence for subsequent multi-dimensional cross-validation.
[0064] In some embodiments, the step of performing similarity detection based on the original signal sequence and the yield sequence to obtain the similarity detection result includes: Obtain the number of similar market data groups and noise levels; For each set of similar market trends, random noise is superimposed on each return value of the return value sequence to generate the corresponding similar market return value sequence. The random noise follows a normal distribution with a mean of 0 and a variance equal to the square of the noise level. Run the strategy to be tested on each group of similar market return sequences and calculate the total return of each group of similar market sequences. Calculate the mean and standard deviation of the total returns for each group, and based on the mean and standard deviation of the total returns, calculate the corresponding coefficient of variation. The coefficient of variation is the absolute value of the standard deviation of the total returns for all groups divided by the mean of the total returns for all groups. If the coefficient of variation is greater than the third preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The coefficient of variation and the suspected marker are used as the similarity detection results.
[0065] Specifically, the core logic of similarity detection is that for a compliant strategy with no future information leakage, its trading decisions should be based on robust market rules, rather than certain noise patterns in the original data. Therefore, when a small random perturbation (additional noise) is applied to the return sequence, the total return of the strategy should not fluctuate drastically, and the total return under multiple perturbation scenarios should show high consistency. The noise level is a parameter controlling the degree of difference between similar scenarios and the original scenarios, denoted as σ (default value is 0.01). This parameter represents the standard deviation of the random noise added to the return of each trading day. When σ=0.01, it indicates that a random perturbation with a standard deviation of 1% is added to the original return of each trading day. The similar scenario return sequence refers to the new return sequence obtained by adding random noise to each return value of the original return sequence, denoted as R_similar_j (j=1,2,...,N). Its construction method is as follows: for the j-th group of similar scenarios, the similar return of each trading day is equal to the original return plus the random noise corresponding to that day. The j-th group of similar market data is highly similar to the original market data but exhibits random differences, simulating a market environment that is "similar to history but not exactly the same." The coefficient of variation (CV) measures the relative dispersion of the data distribution. The CV is calculated as: CV = σ_similar / |μ_similar|, where CV equals the absolute value of the standard deviation of the total returns of all groups divided by the mean of the total returns of all groups. When the CV exceeds the third preset threshold (default 1.0), it indicates that the strategy's uncertainty exceeds its average return level, the strategy is extremely unstable, and there is a risk of overfitting.
[0066] As an example, firstly, the preset detection parameters are read, including the number of similar market data groups N (default value is 10) and the noise level σ (default value is 0.01). The number of similar market data groups N represents the number of similar market data sequences to be generated from the original return series; the more groups, the higher the stability of the statistical estimate. The noise level σ represents the standard deviation of the random noise added to the return of each trading day. Secondly, for the j-th similar market data group (j from 1 to N), each trading day in the original return series is traversed, and an independently generated random noise value ε is superimposed on the original return r_original_i of that day. This random noise follows a normal distribution with a mean of 0 and a variance of σ², i.e., ε ~ N(0,σ²). The superimposed value is used as the return of that day in the j-th similar market data group, i.e., r_similar = r_original + N(0,σ²). The superimposed results of all trading days are arranged in the original time order to form the return series of the j-th similar market data group. Repeat the above process N times to generate N sets of similar market return sequences that are highly similar to the original market conditions but have random differences. These similar market return sequences simulate market environments that are similar to but not exactly the same as historical ones, and are used to test the robustness of the strategy under small market fluctuations. Next, for each set of similar market return sequences, the original signal sequence is used as the holding indicator, and the strategy is simulated to run on that set of similar market return sequences, with the returns accumulated daily to obtain the total return Return_j for that set of similar market conditions. This calculation is performed for all N sets of similar market conditions, resulting in N total return values. Then, based on the N total return values, their arithmetic mean μ_similar_returns and sample standard deviation σ_similar_returns are calculated. The mean μ_similar_returns reflects the average return level of the strategy on the N sets of similar market conditions, and the standard deviation σ_similar_returns reflects the dispersion of the strategy's return performance across different similar market conditions. Next, following the formula CV = σ_similar_returns / |μ_similar_returns|, the standard deviation is divided by the absolute value of the mean to obtain the coefficient of variation (CV). The CV measures the relative dispersion of strategy returns under different similar market conditions, eliminating the influence of the mean magnitude and making the stability of strategies with different return levels comparable. Finally, the CV is compared with a third preset threshold (default value is 1.0): if the CV is greater than 1.0, the strategy under test is suspected of data crossing, and a "suspected" label is generated; otherwise, a "not suspected" label is generated. The CV and the suspected label are output together as the similarity detection result for subsequent cross-validation and report generation. Similarity detection introduces random perturbation to test the robustness of the strategy. If the strategy reacts violently to small perturbations, it indicates that the strategy may overfit a specific data pattern, posing a risk of data crossing.By performing similarity detection, future information leakage can be detected from the perspective of perturbation robustness. The compliance strategy captures the real market rules. Under small noise perturbations, the change in returns is limited and the coefficient of variation is close to zero. In contrast, the signal of the traversal strategy overfits the specific noise of the original path, is extremely sensitive to small perturbations, and has a significantly larger coefficient of variation. Thus, it forms a multi-dimensional complementary cross-validation system with signal lag detection, data mirror detection, and end-of-line reward detection.
[0067] In some embodiments, the step of performing information entropy detection based on the position sequence and return sequence to obtain the information entropy detection result includes: Based on the position sequence, the return sequence is split to obtain the signal return sequence under signal conditions and the no-signal return sequence under no-signal conditions; Binning statistical processing was performed on the gain sequences with and without signals respectively to obtain the frequency distributions with and without signals. After multiplying the proportion of each interval in the frequency distribution with signal by the corresponding position weight, the weighted information entropy under the signal condition is calculated. After multiplying the proportion of each interval in the frequency distribution without signal by the corresponding position weight, the weighted information entropy under the no-signal condition is calculated. The weighted information entropy under the signal condition is divided by the no-signal information entropy to obtain the information entropy ratio. If the information entropy ratio is less than the fourth preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The information entropy ratio and the suspect marker are used as the information entropy detection results.
[0068] Specifically, information entropy is an indicator that measures the uncertainty (randomness) of a probability distribution. The more uniform and random the distribution, the higher the entropy value; the more concentrated and ordered the distribution, the lower the entropy value. For a compliant strategy without future information leakage, the return distribution when holding positions (after adjusting for position direction) should not differ significantly in randomness from the return distribution when holding no positions, meaning their information entropies should be roughly equivalent. However, if the strategy involves data crossing, its signals essentially predict future price movements before determining the position direction, resulting in highly concentrated positive returns when there are signals, extremely uneven distribution, and a significant decrease in information entropy; while returns when there are no signals still approach the random distribution of the market, and information entropy remains at a normal level. Therefore, the information entropy ratio (entropy with signals / entropy without signals) will be significantly less than 1.
[0069] Position sequence refers to the time series data consisting of the actual position size of the strategy under test on each trading day during the backtesting process, denoted as P={p1,p2,...,p...} i ,...,p n}, each position value p iThe value is a continuous numerical value representing the proportion of invested funds to total funds on that day. A value of 0 indicates no position, a positive value indicates a long position, and a negative value indicates a short position. The signaled return series is a time series formed by extracting the returns of all trading days with non-zero position values based on the position sequence and arranging them in chronological order. The no-signal return series is a time series formed by extracting the returns of all trading days with zero position values. Binning statistical processing involves dividing the continuous return values in the return series into several discrete intervals ("boxes") according to their numerical magnitude and calculating the proportion of samples in each box. The weighted probability is a corrected probability obtained by introducing position weights into the ordinary frequency distribution. For each box, its weighted probability is equal to the proportion of samples in that box to the total number of samples multiplied by the average position value of all trading days in that box. The weighted information entropy is calculated by multiplying the proportion of each interval in the frequency distribution by the corresponding position weight for directional adjustment, and then calculating the information entropy of the adjusted distribution.
[0070] As an example, firstly, the position sequence and return sequence are read. The return sequence is then split based on the position sequence. Each trading day is iterated over. If the position value for that trading day is not equal to 0, the corresponding return value is assigned to the signaled return sequence; if the position value is equal to 0, the corresponding return value is assigned to the unsigned return sequence. After this iteration, the signaled return sequence and the unsigned return sequence are obtained. Secondly, binning is performed on both the signaled and unsigned return sequences. The range from the minimum to the maximum return value is divided into M sub-intervals (M=10 by default, resulting in 10 categories). Each return value in the signaled return sequence is iterated over, determining which sub-interval it falls into. The proportion of samples in each sub-interval to the total number of samples in the sequence is calculated to obtain the signaled frequency distribution. The same binning operation is performed on the unsigned return sequence to obtain the unsigned frequency distribution. Thirdly, for each bin in the signaled frequency distribution, the frequency proportion of that bin is multiplied by the average position value of all trading days within that bin to obtain the weighted probability p(x). i According to the weighted information entropy formula H(X)=-Σp(x) i )×log2(p(x iThe weighted information entropy H_signal is calculated by multiplying the position (H_signal) by position, where position is the average position weight across all trading days under signal conditions. This weighting is applied to the sum of all boxes and then negated to obtain the weighted information entropy H_no_signal under signal conditions. Similarly, the same weighting is applied to each box in the no-signal frequency distribution to calculate the weighted information entropy H_no_signal under no-signal conditions. Since the strategy may hold different positions on different trading days, the returns on heavily weighted trading days have a greater impact on the overall strategy performance; therefore, they should be given higher weight when calculating information entropy. Next, the information entropy ratio is calculated by dividing H_signal by H_no_signal, resulting in EntropyRatio = H_signal / H_no_signal. This EntropyRatio reflects the degree to which the signal compresses market uncertainty. A ratio much less than 1 indicates that the uncertainty of returns is much lower when there is a signal than when there is no signal. The signal filters out overly certain market combinations, potentially containing future information. Finally, the information entropy ratio is compared with the fourth preset threshold (default value is 0.5). If the entropy ratio is less than 0.5, the strategy to be detected is suspected of data leakage, and a "suspected" label is generated; otherwise, a "not suspected" label is generated. The information entropy ratio and the suspected label are output together as the information entropy detection result for subsequent cross-validation and report generation. This information entropy detection analyzes the signal filtering effect from an information theory perspective. If the signal over-filters market trends in a specific direction, resulting in a significant decrease in information entropy, it indicates that the signal may be using future information to accurately select market trends. By performing information entropy detection, future information leakage is detected from the perspective of the orderliness of the return distribution. This complements the time-shift perspective of signal lag detection, the directional symmetry perspective of data mirroring detection, the perturbation robustness perspective of similarity detection, and the transaction boundary perspective of closing return detection, providing independent information theory dimension evidence for the multi-dimensional cross-validation system.
[0071] In some embodiments, the steps of performing at least one specific test on the backtesting data, calculating the corresponding financial statistical indicators, and generating specific test results for each specific test include: Traverse the position sequence, count the number of trading days with non-zero position values, divide by the total number of trading days to obtain the percentage of time spent in the market; Extract the negative return series from the return series and calculate the standard deviation of the negative return series to obtain the downside bias; Obtain the annualized return of the strategy and the risk-free rate. Subtract the risk-free rate from the annualized return of the strategy to obtain the excess return. Divide the excess return by twice the downward deviation and adjust the annualized factor of the resulting quotient to obtain the modified Sortino ratio. Extract the profit sequence of all profitable transactions and the loss sequence of all losing transactions from each transaction record, as well as the total number of transactions and the number of profitable transactions. Based on the profit and loss sequence, the total number of transactions, and the number of profitable transactions, calculate the total profit of all profitable transactions, the absolute value of the total loss of all losing transactions, the average profit of profitable transactions, and the absolute value of the average loss of losing transactions. Divide the number of winning trades by the total number of trades to get the win rate; divide the total profit by the absolute value of the total loss to get the profit-risk factor; and divide the average profit of winning trades by the absolute value of the average loss of losing trades to get the average profit-loss ratio. Multiply the risk-reward factor, win rate, and average profit / loss ratio to obtain the cost-return ratio; Arrange the return series in ascending order, extract the average value of the returns above the first preset percentile to obtain the upper tail mean, and extract the average value of the returns below the second preset percentile to obtain the lower tail mean. Divide the absolute value of the upper tail mean by the absolute value of the lower tail mean to obtain the tail ratio. Divide the upper tail mean by the average profit of profitable trades to obtain the abnormal win rate. Dividing the lower tail mean by the absolute value of the average loss of losing trades yields the abnormal negative rate.
[0072] As an example, firstly, read the position sequence, iterate through each trading day, and count the number of trading days with a position value that is not equal to zero. Divide the number of trading days by the total number of trading days in the backtesting period to obtain the market exposure percentage. The market exposure percentage can reflect the degree of market exposure of the strategy throughout the backtesting period. The higher the percentage, the more the strategy tends to participate in the market continuously. The lower the percentage, the more the strategy tends to time the market. This indicator can be used to adjust traditional risk-return indicators such as annualized volatility and Sharpe ratio by position weighting, so that strategies with different position levels are comparable.
[0073] Secondly, the adjusted Sortino ratio is calculated. All returns less than zero are extracted from the return series to form a negative return series. The standard deviation of this series is calculated as the downside deviation σ_down. The downside deviation reflects the volatility of the strategy under loss conditions and serves as a core variable for measuring downside risk. The annualized return R and the risk-free rate Rf of the strategy are obtained. The excess return is obtained by subtracting the risk-free rate from the annualized return. The excess return is then divided by twice the downside deviation and multiplied by the annualized adjustment factor. The corrected Sortino ratio, Sortino_adj, is obtained as: Sortino_adj = (R - Rf) / (2 × σ_down) × This modification aligns the Sortino ratio with the Sharpe ratio in terms of dimensions, making it easier to comprehensively assess the risk-adjusted returns of a strategy.
[0074] Next, calculate the return-to-cost ratio. Extract the profit sequence Gains of all profitable trades and the loss sequence Losses of all losing trades from each transaction record, and calculate the total number of trades N_total and the number of profitable trades N_wins. Based on the above data, calculate three sub-indicators: Profit_Factor = Σ(Gains) / |Σ(Losses)|, which is the absolute value of the sum of the profits of all profitable trades divided by the absolute value of the sum of the losses of all losing trades, reflecting the overall profit-loss ratio of the strategy; Win_Rate = N_wins / N_total, which is the proportion of profitable trades to the total number of trades; and Win_Loss_Ratio = μ_wins / |μ_losses|, which is the absolute value of the average profit of profitable trades divided by the average loss of losing trades. Multiply the return-to-cost ratio, win_Rate, and win_Loss_Ratio to obtain the return-to-cost ratio CPC_Index = Profit_Factor × Win_Rate × Win_Loss_Ratio. The return-cost ratio can comprehensively reflect the profitability, stability, and risk control capabilities of a strategy; the higher the value, the better the overall performance of the strategy.
[0075] Next, the tail ratio is calculated. The return series is sorted in ascending order, and all returns above the first preset quantile (default 95%) are extracted, and their mean is calculated as the upper tail mean μ_upper_quantile. All returns below the second preset quantile (default 5%) are extracted, and their mean is calculated as the lower tail mean μ_lower_quantile. The absolute value of the upper tail mean is divided by the absolute value of the lower tail mean to obtain the tail ratio Tail_Ratio = |μ_upper_quantile| / |μ_lower_quantile|. This tail ratio reflects the symmetry of the strategy's returns in extreme situations. A tail ratio that deviates significantly from 1 indicates that the strategy performs asymmetrically in extreme market conditions, which may pose a risk.
[0076] Finally, the outlier win rate and outlier loss rate are calculated. The outlier win rate (Outlier_Win_Ratio) is calculated by dividing the upper tail mean (μ_upper_quantile) by the average profit of winning trades (μ_wins), i.e., Outlier_Win_Ratio = μ_upper_quantile / μ_wins. If this outlier win rate is significantly greater than 1, it indicates that a few abnormally high-profit trades dominate all the returns, which may be due to lucky trades caused by data crossing. The outlier loss rate (Outlier_Loss_Ratio) is calculated by dividing the lower tail mean (μ_lower_quantile) by the absolute value of the average loss of losing trades (|μ_losses|), i.e., Outlier_Loss_Ratio = μ_lower_quantile / μ_losses. If the outlier loss rate deviates significantly from 1, it indicates that the strategy has abnormally high losses, which may be a signal of risk control failure. Abnormal win rates and abnormal loss rates need to be interpreted in pairs. If the abnormal win rate is extremely high while the abnormal loss rate is normal, it suggests data crossing suspicion; if both are high, it indicates high volatility and gambling risk; if the abnormal loss rate is extremely low (i.e., much less than 1), it indicates effective risk control and timely prevention of large losses. After all six indicators are calculated, the values of each indicator are summarized and compared with their respective preset thresholds to generate anomaly markers. The specific values of each indicator and the anomaly markers are packaged into a specialized detection result and output to the subsequent cross-validation module. This result, along with the statistical detection results, is used to comprehensively determine the level of data crossing risk.
[0077] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the financial transaction backtesting and crossover detection method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0078] This application also provides a financial transaction backtesting and crossover detection device; please refer to [reference needed]. Figure 2 The financial transaction backtesting and crossover detection device includes: The front-end data acquisition module 201 is used to acquire backtesting data generated by the backtesting of the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence and transaction records. The multidimensional statistical detection module 202 is used to perform multidimensional statistical detection based on backtesting data, including signal lag detection, first and last report detection, data mirror detection, similarity detection and information entropy detection, and obtain the statistical detection results corresponding to each statistical detection. Specialized testing module 203 is used to perform at least one specialized test on the backtesting data, calculate the corresponding financial statistical indicators, and generate specialized test results for each specialized test. The financial statistical indicators include market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. The fusion judgment and result generation module 204 is used to cross-validate statistical test results with special test results and generate a structured test report. The structured test report includes data crossing risk level and problem location information.
[0079] The financial transaction backtesting crossover detection device provided in this application, employing the financial transaction backtesting crossover detection method in the above embodiments, can solve the technical problem that existing backtesting lacks the ability to automatically detect data crossover and cannot accurately identify risks. Compared with the prior art, the beneficial effects of the financial transaction backtesting crossover detection device provided in this application are the same as those of the financial transaction backtesting crossover detection method provided in the above embodiments, and other technical features in the financial transaction backtesting crossover detection device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0080] This application provides a financial transaction backtesting and cross-traffic detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the financial transaction backtesting and cross-traffic detection method in the first embodiment described above.
[0081] The following is for reference. Figure 3 The diagram illustrates a structural schematic of a financial transaction backtesting and cross-travel detection device suitable for implementing embodiments of this application. The financial transaction backtesting and cross-travel detection device in this application may include, but is not limited to, mobile terminals such as laptops, tablets (Portable Application Description, PADs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 3 The financial transaction backtesting and crossover detection device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0082] like Figure 3As shown, the financial transaction backtesting and cross-traffic detection device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the financial transaction backtesting and cross-traffic detection device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows the financial transaction backtesting and cross-pass detection equipment to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows a financial transaction backtesting and cross-pass detection equipment with various systems, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems can be implemented alternatively.
[0083] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0084] The financial transaction backtesting crossover detection device provided in this application, employing the financial transaction backtesting crossover detection method described in the above embodiments, can solve the technical problem that existing backtesting methods lack automatic data crossover detection capabilities and cannot accurately identify risks. Compared with the prior art, the beneficial effects of the financial transaction backtesting crossover detection device provided in this application are the same as those of the financial transaction backtesting crossover detection method provided in the above embodiments, and other technical features in this financial transaction backtesting crossover detection device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0085] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0086] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0087] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the financial transaction backtesting and cross-traffic detection method in the above embodiments.
[0088] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0089] The aforementioned computer-readable storage medium may be included in the financial transaction backtesting and cross-pass detection device; or it may exist independently and not be assembled into the financial transaction backtesting and cross-pass detection device.
[0090] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by the financial trading backtesting and cross-trading detection device, the device performs the following actions: acquires backtesting data generated by the strategy to be tested, including the original signal sequence, return sequence, position sequence, and transaction records; based on the backtesting data, performs multi-dimensional statistical tests including signal lag detection, first and last return detection, data mirroring detection, similarity detection, and information entropy detection, obtaining statistical test results corresponding to each statistical test; performs at least one specific test on the backtesting data, calculates the corresponding financial statistical indicators, and generates specific test results corresponding to each specific test, including market time percentage, corrected Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate; cross-validates the statistical test results with the specific test results, and generates a structured test report, which includes data cross-trading risk level and problem location information.
[0091] Computer program products for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0092] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation that may be implemented in systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0093] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0094] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned financial transaction backtesting and cross-cutting detection method. This solves the technical problem that existing backtesting methods lack the ability to automatically detect data cross-cutting and cannot accurately identify risks. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the financial transaction backtesting and cross-cutting detection method provided in the above embodiments, and will not be repeated here.
[0095] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the financial transaction backtesting and cross-traffic detection method described above.
[0096] The computer program product provided in this application can solve the technical problem that existing backtesting lacks the ability to automatically detect data crossing and cannot accurately identify risks. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the financial transaction backtesting crossing detection method provided in the above embodiments, and will not be repeated here.
[0097] The above are only some embodiments of this application and do not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for detecting backtesting and crossover in financial transactions, characterized in that, The financial transaction backtesting and crossover detection method includes: Acquire backtesting data generated by the strategy to be tested. The backtesting data includes the original signal sequence, return sequence, position sequence, and transaction records. Based on the backtest data, multi-dimensional statistical detection is performed, including signal lag detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection, to obtain the statistical detection results corresponding to each statistical detection. At least one specific test is performed on the backtest data, the corresponding financial statistical indicators are calculated, and the specific test results corresponding to each specific test are generated. The financial statistical indicators include market time percentage, adjusted Sortino ratio, return-cost ratio, tail ratio, abnormal win rate, and abnormal loss rate. The statistical detection results are cross-validated with the specific detection results to generate a structured detection report, which includes data traversal risk level and problem location information.
2. The financial transaction backtesting and crossover detection method as described in claim 1, characterized in that, The steps of performing multidimensional statistical detection based on the backtesting data, including signal hysteresis detection, first and last report detection, data mirroring detection, similarity detection, and information entropy detection, include: Based on the original signal sequence and the yield sequence, signal hysteresis detection is performed to obtain the hysteresis detection result; Based on the yield sequence and each transaction record, a closing return detection is performed to obtain the closing return detection result. Based on the original signal sequence and the yield sequence, perform data mirroring detection to obtain the mirroring detection result; Based on the original signal sequence and the yield sequence, a similarity detection is performed to obtain the similarity detection result; Based on the position sequence and the return sequence, information entropy detection is performed to obtain the information entropy detection result; The lag detection result, the closing reward detection result, the mirror detection result, the similarity detection result, and the information entropy detection result are determined as the statistical detection result.
3. The financial transaction backtesting and crossover detection method as described in claim 2, characterized in that, The step of performing signal hysteresis detection based on the original signal sequence and the return sequence to obtain the hysteresis detection result includes: Read the original signal sequence, the return sequence, and the first preset threshold, wherein the original signal sequence is the signal value for each trading day, and the return sequence is the return for each trading day; Based on the original signal sequence and the return sequence, the signal value of each trading day is multiplied by the return of the corresponding trading day and then summed to obtain the first total return corresponding to the original signal. Based on the original signal sequence, a hysteresis signal sequence is constructed, wherein the hysteresis signal sequence takes the value of the previous position in the original signal sequence, except for the first position which takes the value of zero. Calculate the second total return corresponding to the lag signal based on the lag signal sequence and the return sequence; The difference between the first total revenue and the second total revenue is divided by the absolute value of the first total revenue to obtain the signal lag suspicion score. If the signal lag suspicion score is greater than the first preset threshold and the second total revenue is less than the product of the first total revenue and the preset attenuation coefficient, the strategy to be detected is suspected of data crossing, and a suspicion mark is generated. The signal hysteresis suspicion score and the suspicion marker are used as the hysteresis detection result.
4. The financial transaction backtesting and crossover detection method as described in claim 2, characterized in that, The step of performing closing return detection based on the yield series and transaction records to obtain the closing return detection result includes: Read the transaction records one by one, and extract the first day return sequence and the last day return sequence corresponding to all transactions from the transaction records one by one, wherein the first day return sequence is the return rate of each transaction on the first trading day, and the last day return sequence is the return rate of each transaction on the last trading day. Remove the first day's return sequence and the last day's return sequence from the return sequence, and aggregate the returns of the remaining trading days to form a normal return sequence; Calculate the first mean and first variance of the first day's return sequence, the second mean and second variance of the last day's return sequence, and the third mean and third variance of the normal return sequence, respectively. Using the first day's return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the first mean, the first variance, the third mean, and the third variance to obtain the first day's test statistic and the corresponding first probability value. Using the last day return sequence as the sample to be tested and the normal return sequence as the control sample, a two-sample mean difference test is performed based on the second mean, the second variance, the third mean, and the third variance to obtain the last day test statistic and the corresponding second probability value. The number of suspected crossing days is determined, wherein the number of suspected crossing days is the square of the difference between the second mean and the third mean, divided by the third mean; Based on the first probability value and the second probability value, the corresponding risk level is determined through a pre-set mapping relationship between the probability value and the suspicion level; The suspected number of days of travel and the risk level are used as the results of the final reward detection.
5. The financial transaction backtesting and crossover detection method as described in claim 2, characterized in that, The step of performing data mirroring detection based on the original signal sequence and the return sequence to obtain the mirroring detection result includes: Based on the original signal sequence and the return sequence, backtesting of the strategy to be detected is performed to obtain the cumulative return value of the strategy to be detected on the original data. To generate a mirrored return sequence, take the inverse of each return in the return sequence. Calculate the mirror revenue boundary corresponding to the strategy to be detected, where the mirror revenue boundary value is the negative of the cumulative revenue value; Based on the original signal sequence and the mirrored return rate sequence, backtesting of the strategy to be detected is performed to obtain the actual return value of the strategy to be detected on the mirrored data. Based on the mirrored profit boundary and the actual profit value, the strategy deviation index of the strategy to be detected is obtained. The strategy deviation index is the difference between the mirrored profit boundary and the actual profit value for each trading day, divided by the absolute value of the mirrored profit boundary, and then summed over all trading days and divided by the total number of trading days. If the policy deviation index is greater than a preset second threshold, the policy to be detected is suspected of data crossing, and a suspicion label is generated. The strategy deviation index and the suspected marker are used as the mirror detection result.
6. The financial transaction backtesting and crossover detection method as described in claim 2, characterized in that, The step of performing similarity detection based on the original signal sequence and the return sequence to obtain the similarity detection result includes: Obtain the number of similar market data groups and noise levels; For each set of similar market trends, random noise is superimposed on each return value of the return value sequence to generate a corresponding similar market trend return value sequence. The random noise follows a normal distribution with a mean of 0 and a variance equal to the square of the noise level. Run the strategy to be detected on each group of similar market return sequences and calculate the total return of each group of similar market sequences. Calculate the mean and standard deviation of the total returns for each group, and calculate the corresponding coefficient of variation based on the mean and standard deviation of the total returns. The coefficient of variation is the absolute value of the standard deviation of the total returns for all groups divided by the mean of the total returns for all groups. If the coefficient of variation is greater than a third preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The coefficient of variation and the suspected marker are used as the similarity detection result.
7. The financial transaction backtesting and crossover detection method as described in claim 2, characterized in that, The step of performing information entropy detection based on the position sequence and the return sequence to obtain the information entropy detection result includes: Based on the position sequence, the return sequence is split to obtain the signal return sequence under signal conditions and the no-signal return sequence under no-signal conditions; Binning statistical processing is performed on the signal-positive gain sequence and the signal-negative gain sequence respectively to obtain the signal-positive frequency distribution and the signal-negative frequency distribution. After multiplying the proportion of each interval in the signal frequency distribution by the corresponding position weight, the weighted information entropy under the signal condition is calculated. After multiplying the proportion of each interval in the no-signal frequency distribution by the corresponding position weight, the weighted information entropy under the no-signal condition is calculated. The weighted information entropy under the signal condition is divided by the no-signal information entropy to obtain the information entropy ratio. If the information entropy ratio is less than the fourth preset threshold, the strategy to be detected is suspected of data crossing, and a suspected marker is generated. The information entropy ratio and the suspected marker are used as the information entropy detection result.
8. The financial transaction backtesting and crossover detection method as described in claim 1, characterized in that, The steps of performing at least one specific test on the backtesting data, calculating the corresponding financial statistical indicators, and generating specific test results for each specific test include: Traverse the position sequence, count the number of trading days with non-zero position values, divide by the total number of trading days to obtain the percentage of time spent in the market; Extract the negative return sequence from the return sequence and calculate the standard deviation of the negative return sequence to obtain the downside bias; Obtain the annualized return of the strategy and the risk-free rate. Subtract the risk-free rate from the annualized return of the strategy to obtain the excess return. Divide the excess return by twice the downside deviation and multiply the resulting quotient by the annualized adjustment factor to obtain the modified Sortino ratio. Extract the profit sequence of all profitable transactions and the loss sequence of all losing transactions from the transaction records, as well as the total number of transactions and the number of profitable transactions. Based on the profit and loss sequence, the loss and gain sequence, the total number of transactions, and the number of profitable transactions, respectively calculate the total profit of all profitable transactions, the absolute value of the total loss of all losing transactions, the average profit of profitable transactions, and the absolute value of the average loss of losing transactions. Dividing the number of profitable trades by the total number of trades yields the win rate; dividing the total profit by the absolute value of the total loss yields the profit-risk factor; and dividing the average profit of profitable trades by the absolute value of the average loss of losing trades yields the average profit-loss ratio. The return-to-cost ratio is obtained by multiplying the risk-reward factor, the win rate, and the average profit-loss ratio. The return series is arranged in ascending order. The average value of the returns above the first preset percentile is extracted to obtain the upper tail mean, and the average value of the returns below the second preset percentile is extracted to obtain the lower tail mean. The absolute value of the upper tail mean is divided by the absolute value of the lower tail mean to obtain the tail ratio. Divide the upper tail mean by the average profit of the profitable trades to obtain the abnormal win rate; The abnormal negative rate is obtained by dividing the lower tail mean by the absolute value of the average loss of the losing transactions.
9. A financial transaction backtesting and cross-pass detection device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the financial transaction backtesting and cross-traffic detection method as described in any one of claims 1 to 8.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the financial transaction backtesting and cross-traffic detection method as described in any one of claims 1 to 8.