A backtesting system for power spot day-ahead trading

By using a backtesting system for electricity spot trading, the problems of limited functionality and cumbersome algorithm adjustments in existing backtesting architectures have been solved. This enables flexible data processing and strategy analysis, improving research efficiency and prediction accuracy.

CN115860519BActive Publication Date: 2026-07-10BEIJING LANMUDA TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING LANMUDA TECH CO LTD
Filing Date
2022-11-15
Publication Date
2026-07-10

Smart Images

  • Figure CN115860519B_ABST
    Figure CN115860519B_ABST
Patent Text Reader

Abstract

The application discloses a back test system for power spot and a quantitative method for day-ahead transaction, and gives a unified technical architecture to realize the back test system, wherein the back test system comprises database table design, data auxiliary configuration and a back test engine, parameters used by the back test engine comprise mode type, model class name, parameters required for constructing a model object, a decision time point list and a decision date list; the mode type comprises a back test mode and a prediction mode; an algorithm engineer can conveniently realize own algorithm on the back test system and obtain effect display of the algorithm; and the quantitative research method for the day-ahead transaction in the power spot can be combined into the back test system, so that the yield index and the risk index of the day-ahead strategy can be conveniently and quickly calculated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electricity spot trading technology, and more specifically to a backtesting system for day-ahead electricity spot trading. Background Technology

[0002] In electricity spot trading, the core of day-ahead trading is predicting day-ahead and real-time prices. To predict prices, it's necessary to forecast supply and demand factors, including but not limited to wind power, solar power, hydropower, provincial dispatch load, and tie-line load. Besides these forecasting requirements, it's also necessary to analyze certain trading strategies with defined logic. The most direct analytical method is to assume our trading strategy doesn't affect the market and use historical data to simulate the strategy's returns—this is called backtesting. However, existing backtesting architectures are relatively simple and algorithm adjustments are very cumbersome, necessitating a new technical architecture for implementing backtesting. Summary of the Invention

[0003] The purpose of this invention is to provide a backtesting system for day-ahead trading in the electricity spot market, and to provide a unified technical architecture for implementing the backtesting system. Algorithm engineers can easily implement their algorithms on the backtesting system and obtain the algorithm's performance. Furthermore, a quantitative research method for day-ahead trading in the electricity spot market is proposed, which can be integrated into the backtesting system to conveniently and quickly calculate the return and risk indicators of the day-ahead strategy.

[0004] To solve the above technical problems, the present invention adopts the following technical solution: a backtesting system for day-ahead spot trading of electricity, including database table design, data-assisted configuration and backtesting engine, wherein the parameters used by the backtesting engine include mode type, model class name and parameters required to construct model objects, decision time point list and decision date list; the mode type includes backtesting mode and prediction mode;

[0005] The backtesting engine execution steps include:

[0006] S1. Determine the pattern type and obtain a list of query_datetime and date pairs from the data engine;

[0007] S2. Create a model object based on the parameters required to construct the model object and import it into the backtesting system;

[0008] S3. Substitute query_datetime and date into the run method of the model to find the true target and the predicted target;

[0009] S4. Store the real target and the predicted target in memory;

[0010] S5. Call the model's analyze method to obtain the results, and provide a visual representation and analysis of the results.

[0011] The aforementioned backtesting system for day-ahead spot trading of electricity, wherein the database table design mainly considers fields including data acquisition date and time, data update date and time, whether to delete, data publication date, and data business time. Data acquisition date and time, data update date and time, and whether to delete are mandatory fields, data publication date is an optional field, and data business time can be flexibly defined.

[0012] The aforementioned backtesting system for day-ahead spot trading of electricity, wherein the data auxiliary configuration file is of type YAML, and the data auxiliary configuration is logically divided into upper-layer data configuration and lower-layer data configuration; data interfaces can be automatically generated from the data auxiliary configuration file.

[0013] The aforementioned backtesting system for day-ahead spot trading of electricity uses the underlying data name as the key for configuration. The specific configuration includes data connection configuration, table name, and time column. The time column can also be generalized as an index column, representing the business time, data type, and data filtering conditions of the data.

[0014] The aforementioned backtesting system for day-ahead spot trading of electricity requires underlying data name and data time configuration for its upper-layer data configuration. The data time configuration is a pair, specifically (n, m), where n represents the time distance from the time column in days, and m represents the hour of the day the data is available. The automatically generated data interface for the upper-layer data configuration has two usage modes: one is to add additional development to shield the details of the underlying data, and the other is to directly use the automatically generated data interface, which preserves the details of the database.

[0015] The aforementioned backtesting system for day-ahead electricity spot trading, wherein the calculation process of run in step S3 is as follows:

[0016] S31. Obtain the training feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Training objectives ;

[0017] S32, Utilization , The model was trained using quantitative research methods for day-ahead trading in the electricity spot market;

[0018] S33. Obtain the test feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Obtain the actual label using the underlying data interface. ;

[0019] S34. Using the trained model and the test feature matrix, make a prediction to obtain a prediction of the true label. and return ( , ).

[0020] The aforementioned backtesting system for day-ahead spot trading of electricity, wherein the automatically generated data has a low-level data interface and an upper-level data interface, and the generation process of the low-level data interface is as follows:

[0021] S41. Read the underlying data configuration file to obtain the interface dictionary, where the key of the dictionary is a string representing the name of the underlying configuration and the name of the interface generated by the configuration, and the value is the underlying configuration.

[0022] S42. Determine the data source type recorded in the underlying configuration, and use the data generalization algorithm and partial function method to obtain the configuration interface by substituting the specific configuration parameters.

[0023] S43. Generate data interfaces according to similar logic based on the data source type;

[0024] S44. Store the generated data interface in memory for other programs, such as upper-level interfaces, to call;

[0025] The generation process of the upper-layer data interface is as follows:

[0026] S51. Calculate the available time dt of the queried data based on the input date and the upper-level data configuration;

[0027] S52. Compare the size of dt and query_datetime. If dt is greater than query_datetime, return None.

[0028] S53. Call the underlying interface to obtain data and return the data.

[0029] The aforementioned backtesting system for day-ahead electricity spot trading, wherein the quantitative research method for day-ahead trading in the electricity spot market decomposes the target profit and loss on day j into a portion dependent on the day-ahead winning bid volume and a portion independent of the day-ahead winning bid volume, specifically as follows:

[0030] =

[0031] =

[0032] in This refers to the electricity volume won in the recent bid. Let $\mathbf{j}$ be the daily winning bid amount at time $i$ on day $j$, which means the objective function is split into two terms.f It depends on the portion that relies on the electricity volume won in the previous day. g This refers to the portion of electricity volume that is not dependent on day-ahead winning bids, and does not consider the impact of day-ahead transactions on market prices and actual electricity consumption. g In day-to-day trading, this is a constant; all day-to-day trading in the spot market is aimed at optimizing the target. f The calculation formula is:

[0033] =

[0034] in The price at the i-th time point on day j. The price is the real-time price at time i on day j, taking into account that the assessment and recovery depend on different provinces. / This ratio, of which To ensure real-time bidding for electricity volume, we will provide... f Adding a constant relative to the previous day's transaction yields a new optimization objective. The calculation formula is:

[0035] =

[0036] in There are two ways to obtain the value. The first method is to obtain... =1, which we call the original profit and loss. Another possible value is... / No intermediate value is generated within the scope of the assessment and recovery;

[0037] Two metrics are defined to characterize the return and risk of a day-ahead strategy. The metric for the return of a day-ahead strategy is called the average electricity gain / loss R, and its calculation formula is as follows:

[0038] R=

[0039] The current strategy risk indicator is called the cumulative maximum drawdown per kilowatt-hour (D). First, the average daily profit or loss per kilowatt-hour is calculated. The sequence is calculated using the following formula:

[0040] =

[0041] Then calculate the cumulative maximum drawdown D, the specific steps are as follows:

[0042] S61, Average electricity loss / gain Substitute the sequence into array A;

[0043] S62. Determine the length of A. If the length of A is 0, return 0.

[0044] S163. Define the cumulative maximum drawdown D=0, parameter last_max = A[0], parameter cur_cum = A[0], parameter i=1;

[0045] S64. Execute cur_cum = cur_cum + A[i];

[0046] S65. Determine if cur_cum > last_max. If true, then last_max = cur_cum and execute step S17; otherwise, execute step S16.

[0047] S66. Determine if cur_cum - last_max < D. If true, then D = cur_cum - last_max.

[0048] S67. Execute i = i + 1;

[0049] S68. Determine if i is equal to the length of A minus 1. If they are not equal, continue to execute step S14. If they are equal, then D is the cumulative maximum drawdown at this time.

[0050] Compared with existing technologies, the advantages of this invention are that the backtesting system provides two modes: backtesting mode and prediction mode. The core uses a single codebase, ensuring that the methods used in actual predictions are validated by historical data. The invented backtesting architecture retains the flexibility of data processing and algorithm models while providing a basic framework, avoiding the use of future data in the research and data acquisition phases. It can also automatically generate data interfaces based on configuration files, greatly improving research efficiency and lowering the threshold for time series research. Furthermore, it proposes a quantitative research method for day-ahead trading in the electricity spot market, which can be integrated into the backtesting system for convenient and rapid calculation of day-ahead strategy return and risk indicators. Attached Figure Description

[0051] Figure 1 This is a schematic diagram showing the visualization results of one embodiment of the present invention.

[0052] The present invention will be further described below with reference to the accompanying drawings and specific embodiments. Detailed Implementation

[0053] Embodiment 1 of the present invention: A backtesting system for day-ahead spot trading of electricity includes database table design, data-assisted configuration and backtesting engine. The parameters used by the backtesting engine include mode type, model class name and parameters required to construct model objects, decision time point list and decision date list; the mode type includes backtesting mode and prediction mode.

[0054] The backtesting engine execution steps include:

[0055] S1. Determine the pattern type and obtain a list of query_datetime and date pairs from the data engine;

[0056] S2. Create a model object based on the parameters required to construct the model object and import it into the backtesting system;

[0057] S3. Substitute query_datetime and date into the run method of the model to find the true target and the predicted target;

[0058] S4. Store the real target and the predicted target in memory;

[0059] S5. Call the model's analyze method to obtain the results, and provide a visual representation and analysis of the results.

[0060] The main fields to consider in database table design include data acquisition date and time, data update date and time, whether to delete, data publication date, and data business time. Data acquisition date and time, data update date and time, and whether to delete are required fields, data publication date is an optional field, and data business time can be flexibly defined.

[0061] The data-assisted configuration file is of type YAML and is logically divided into upper-level data configuration and lower-level data configuration. Data interfaces can be automatically generated from the data-assisted configuration file. The automatically generated data interfaces include both lower-level and upper-level data interfaces. The generation process of the lower-level data interfaces is as follows:

[0062] S41. Read the underlying data configuration file to obtain the interface dictionary, where the key of the dictionary is a string representing the name of the underlying configuration and the name of the interface generated by the configuration, and the value is the underlying configuration.

[0063] S42. Determine the data source type recorded in the underlying configuration, and use the data generalization algorithm and partial function method to obtain the configuration interface by substituting the specific configuration parameters.

[0064] S43. Generate data interfaces according to similar logic based on the data source type;

[0065] S44. Store the generated data interface in memory for other programs, such as upper-level interfaces, to call;

[0066] The generation process of the upper-layer data interface is as follows:

[0067] S51. Calculate the available time dt of the queried data based on the input date and the upper-level data configuration;

[0068] S52. Compare the size of dt and query_datetime. If dt is greater than query_datetime, return None.

[0069] S53. Call the underlying interface to obtain data and return the data.

[0070] The underlying data configuration uses the underlying data name as the key. The specific configuration includes data connection configuration, table name, and time column. The time column can also be generalized as an index column, representing the business time, data type, and data filtering conditions of the data.

[0071] The upper-level data configuration requires the underlying data name and data time configuration; the data time configuration is a pair, specifically (n, m), where n represents the time distance from the time column in days, and m represents the hour of the day the data is available; the data interface automatically generated by the upper-level data configuration has two usage modes: one is to add additional development to shield the underlying data details, and the other is to directly use the automatically generated data interface, which will preserve the database details.

[0072] The calculation process for run in step S3 is as follows:

[0073] S31. Obtain the training feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Training objectives ;

[0074] S32, Utilization , The model was trained using quantitative research methods for day-ahead trading in the electricity spot market;

[0075] S33. Obtain the test feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Obtain the actual label using the underlying data interface. ;

[0076] S34. Using the trained model and the test feature matrix, make a prediction to obtain a prediction of the true label. and return ( , ).

[0077] A quantitative research method for day-ahead trading in the electricity spot market decomposes the target profit and loss on day j into a portion dependent on the day-ahead winning bid volume and a portion independent of the day-ahead winning bid volume, specifically:

[0078] =

[0079] =

[0080] in This refers to the electricity volume won in the recent bid. Let $\mathbf{j}$ be the daily winning bid amount at time $i$ on day $j$, which means the objective function is split into two terms. f It depends on the portion that relies on the electricity volume won in the previous day. g This refers to the portion of electricity volume that is not dependent on day-ahead winning bids, and does not consider the impact of day-ahead transactions on market prices and actual electricity consumption. g In day-to-day trading, this is a constant; all day-to-day trading in the spot market is aimed at optimizing the target. f The calculation formula is:

[0081] =

[0082] in The price at the i-th time point on day j. The price is the real-time price at time i on day j, taking into account that the assessment and recovery depend on different provinces. / This ratio, of which To ensure real-time bidding for electricity volume, we will provide... f Adding a constant relative to the previous day's transaction yields a new optimization objective. The calculation formula is:

[0083] =

[0084] in There are two ways to obtain the value. The first method is to obtain... =1, which we call the original profit and loss. Another possible value is... / No intermediate value is generated within the scope of the assessment and recovery;

[0085] Two metrics are defined to characterize the return and risk of a day-ahead strategy. The metric for the return of a day-ahead strategy is called the average electricity gain / loss R, and its calculation formula is as follows:

[0086] R=

[0087] The current strategy risk indicator is called the cumulative maximum drawdown per kilowatt-hour (D). First, the average daily profit or loss per kilowatt-hour is calculated. The sequence is calculated using the following formula:

[0088] =

[0089] Then calculate the cumulative maximum drawdown D, the specific steps are as follows:

[0090] S61, Average electricity loss / gain Substitute the sequence into array A;

[0091] S62. Determine the length of A. If the length of A is 0, return 0.

[0092] S63. Define the cumulative maximum drawdown D=0, parameter last_max = A[0], parameter cur_cum = A[0], parameter i=1;

[0093] S64. Execute cur_cum = cur_cum + A[i];

[0094] S65. Determine if cur_cum > last_max. If true, then last_max = cur_cum and execute step S17; otherwise, execute step S16.

[0095] S66. Determine if cur_cum - last_max < D. If true, then D = cur_cum - last_max.

[0096] S67. Execute i = i + 1;

[0097] S68. Determine if i is equal to the length of A minus 1. If they are not equal, continue to execute step S14. If they are equal, then D is the cumulative maximum drawdown at this time.

[0098] Embodiment 2 of the present invention: A backtesting system for day-ahead spot trading of electricity includes database table design, data-assisted configuration and backtesting engine. The parameters used by the backtesting engine include schema type, model class name and parameters required to construct model objects, decision time point list and decision date list.

[0099] The model types include backtesting models and prediction models;

[0100] The decision time point (query_datetime) and the decision date (date) are important parameters for the backtesting engine;

[0101] `query_datetime_list` and `pred_date_list` are used for backtesting the effectiveness of a day-ahead trading strategy from July 1st to July 3rd, 2022. `query_datetime_list` represents the list of time points for making decisions, and `pred_date_list` represents the list of dates on which decisions are made. If we want to backtest the effectiveness of a day-ahead trading strategy for the three days from July 1st to July 3rd, 2022, the input `query_datetime_list` would be ["2022-06-30 10", "2022-07-01 10", "2022-07-02 10"], and the input `pred_date_list` would be ["2022-07-01", "2022-07-02", "2022-07-03"]. These represent the day-ahead strategy executed on "2022-07-01" at "2022-06-30 10", and the strategy executed on "2022-07-03" at "2022-07-01 10". Make a daytime strategy for "2022-07-02", and make a daytime strategy for "2022-07-03" on "2022-07-0210";

[0102] The backtesting engine execution steps include:

[0103] S1. Determine the mode type. Obtain the query_datetime and date pair list through the data engine. There are two modes: backtesting mode and prediction mode. These two modes will also be passed to the specific model. The backtesting mode will get the label from the data interface and is suitable for the research stage, while the prediction mode is for prediction and is used in the production stage.

[0104] S2. Create model objects based on the parameters required for constructing model objects and import them into the backtesting system. Utilizing object-oriented inheritance techniques, rich models can be obtained to meet the business needs of different predictions or strategies. Prediction and strategy each have their own base classes.

[0105] S3. Substitute query_datetime and date into the run method of the model to obtain the true target and the predicted target;

[0106] S4. Store the real target and the predicted target in memory;

[0107] S5. Call the model's analyze method to obtain the results: MAE, r2, explained variance, electricity gain / loss, and cumulative electricity drawdown. Provide a visual representation and analysis of the results.

[0108] A regression problem requires predicting a variable, which we call the dependent variable. For simplicity, there is usually only one dependent variable. To make a prediction, we need a series of data as input, which we call the explanatory variables. In backtesting mode, the data in the dependent variable list is obtained through the underlying data interface, and the other variables are obtained through the upper-level data interface using the prediction time point as query_datetime. In prediction mode, we only need to obtain the variable data from the explanatory variable list (i.e., the data configuration list excluding the data entries in the dependent variable list) through the upper-level data interface.

[0109] The main fields to consider in database table design include data acquisition date and time, data update date and time, whether to delete, data publication date, and data business time. Data acquisition date and time, data update date and time, and whether to delete are required fields, data publication date is an optional field, and data business time can be flexibly defined.

[0110] The MySQL syntax for specifying whether to delete a field is as follows:

[0111] `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Whether to delete 0 No 1 Yes',

[0112] The MySQL syntax for retrieving date and time fields is as follows:

[0113] `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,

[0114] The MySQL syntax for updating date and time fields is as follows:

[0115] `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATECURRENT_TIMESTAMP;

[0116] The data-assisted configuration file is of type YAML. Logically, the data-assisted configuration is divided into upper-layer data configuration and lower-layer data configuration. Data interfaces can be automatically generated from the data-assisted configuration file. The lower-layer data configuration does not consider the data's publication time or availability time, but only focuses on the data's business time, and can automatically generate lower-layer data interfaces. The upper-layer data configuration takes into account the data's publication time or availability time, and generates upper-layer data interfaces from the upper-layer data configuration.

[0117] The MySQL data source is the most important. In this example, the data source is MySQL, so the process of automatically generating the data interface is as follows:

[0118] S11. The parameter set for reading the data configuration is {config_name, table_name, date, field, date_name, dtype, condition, order_by};

[0119] S12. Using Python's string template statement, define sql = f"select {field} from `{table_name}` where {date_name}='{date}'", where f"" is Python's string template statement;

[0120] S13. Check if the condition is empty. If the condition is not empty, assign the value sql = f"{sql} and({condition})".

[0121] S14. Check if order_by is empty. If order_by is not empty, assign the value sql = f"{sql} orderby {order_by}".

[0122] S15. Use config_name to obtain the MySQL connection and cursor, and use SQL to obtain the data result (result).

[0123] S16. Determine if field is a single column. If field has more than one column, the corresponding dtype is a dictionary. Split field by English commas. Based on field and corresponding dtype, convert the data types of different columns of result to numpy.ndarray type and store them in a list by column. Return the list. Otherwise, proceed to step S17.

[0124] S17. Based directly on the field type, convert the data in the result to the numpy.ndarray type and return this array.

[0125] The automatically generated data interface allows you to specify the date field, query field, order by, additional filtering conditions, and data type conversion. It features a two-layer caching system: a memory cache and a disk cache. Both the memory cache and the disk cache can be flexibly enabled and disabled, providing higher-performance data support for data and algorithm research while reducing database pressure.

[0126] The data interface generated by the upper-layer data configuration and the manually implemented data interface are collectively referred to as the data engine. All interfaces of the data engine only need to satisfy the existence of a string parameter named query_datetime. When the query_datetime does not meet the data availability requirement, the data engine interface returns None; otherwise, it returns the corresponding data. Generally, if the data is successfully retrieved, the returned data format is a numpy.ndarray array.

[0127] The data-assisted configuration automatically generated data interface has two usage modes: one is to add additional development to shield the underlying data details, and the other is to directly use the automatically generated data interface. This method retains the database details and shields the underlying details, which requires further encapsulation of the generated data interface. This is generally used for projects with frequently changing underlying data structures or large projects. The module for automatically generating data interfaces combines SQL statement syntax, including date fields, query fields, order by, additional condition filtering, and data type conversion.

[0128] Most of the data related to power trading is time-series data. For power trading scenarios, each data point is assigned a name as the underlying data name. The underlying data configuration is configured using the underlying data name as the key. The specific configuration includes data connection configuration, table name, time column, data type, and data filtering conditions. The time column can also be generalized as an index column, representing the business time of the data. The data source for the data connection configuration includes databases, Excel spreadsheets, and some meteorological data stored on the hard drive in nc format. The data connection configuration is abstracted to automatically generate data interfaces.

[0129] The upper-level data configuration requires the lower-level data name and data time configuration. The data time configuration is a pair, specifically (n, m), where n represents the time distance from the time column in days, and m represents the hour on the day the data is obtained when it becomes available. A configuration of (-1, 9) means that the data is available at 9:00 AM the day before the business time, and a configuration of (8, 0) means that the data is available at 0:00 AM the next 8 days after the business time. The first number of the predicted data is negative, while the first number of the actual data configuration is positive, and the specific number depends on the actual situation.

[0130] The calculation process for run in step S3 is as follows:

[0131] S31. Obtain the training feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Training objectives ;

[0132] S32, Utilization , The model was trained using quantitative research methods for day-ahead trading in the electricity spot market;

[0133] S33. Obtain the test feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Obtain the actual label using the underlying data interface. ;

[0134] S34. Using the trained model and the test feature matrix, make a prediction to obtain a prediction of the true label. and return ( , ).

[0135] A quantitative research method for day-ahead trading in the electricity spot market decomposes the target profit and loss on day j into a portion dependent on the day-ahead winning bid volume and a portion independent of the day-ahead winning bid volume, specifically as follows:

[0136] =

[0137] =

[0138] in This refers to the electricity volume won in the recent bid. Let $\mathbf{j}$ be the daily winning bid amount at time $i$ on day $j$, which means the objective function is split into two terms. f It depends on the portion of the electricity volume won in the previous day. g This refers to the portion of electricity volume that is not dependent on day-ahead winning bids, and does not consider the impact of day-ahead transactions on market prices and actual electricity consumption. g In day-to-day trading, this is a constant; all day-to-day trading in the spot market is aimed at optimizing the target. f The calculation formula is:

[0139] =

[0140] in The price at the i-th time point on day j. The price is the real-time price at time i on day j, taking into account that the assessment and recovery depend on different provinces. / This ratio, of which To ensure real-time bidding for electricity volume, we will provide... f Adding a constant relative to the previous day's transaction yields a new optimization objective. The calculation formula is:

[0141] =

[0142] in There are two ways to obtain the value. The first method is to obtain... =1, which we call the original profit and loss. Another possible value is... / No intermediate value is generated within the scope of the assessment and recovery;

[0143] Two metrics are defined to characterize the return and risk of a day-ahead strategy. The metric for the return of a day-ahead strategy is called the average electricity gain / loss R, and its calculation formula is as follows:

[0144] R=

[0145] The current strategy risk indicator is called the cumulative maximum drawdown per kilowatt-hour (D). First, the average daily profit or loss per kilowatt-hour is calculated. The sequence is calculated using the following formula:

[0146] =

[0147] Then calculate the cumulative maximum drawdown D, the specific steps are as follows:

[0148] S61, Average electricity loss Substitute the sequence into array A;

[0149] S62. Determine the length of A. If the length of A is 0, return 0.

[0150] S63. Define the cumulative maximum drawdown D=0, parameter last_max = A[0], parameter cur_cum = A[0], parameter i=1;

[0151] S64. Execute cur_cum = cur_cum + A[i];

[0152] S65. Determine if cur_cum > last_max. If true, then last_max = cur_cum and execute step S17; otherwise, execute step S16.

[0153] S66. Determine if cur_cum - last_max < D. If true, then D = cur_cum - last_max.

[0154] S67. Execute i = i + 1;

[0155] S68. Determine if i is equal to the length of A minus 1. If they are not equal, continue to execute step S14. If they are equal, then D is the cumulative maximum drawdown at this time.

[0156] Using the research method of this invention, we obtained a day-ahead strategy for a power sales company in Gansu. We can see that from February 1, 2022 to August 8, 2022, the strategy generated an average profit of RMB 23.67 per MWh (negative numbers represent cost reduction, i.e., profit). The maximum cumulative drawdown was RMB 128 per MWh. Therefore, the maximum drawdown for this virtual user was RMB 128 * 96 = RMB 12,288. Compared to the cumulative profit of approximately RMB 400,000, the risk is relatively small, indicating that this strategy is quite effective.

[0157] The working principle of one embodiment of the present invention is as follows: The backtesting system provides basic functions. Users can carry out secondary development of the backtesting system according to their own needs, such as bringing the quantitative research method of day-ahead trading in the power spot market into step S32 in embodiment 1, to obtain their own backtesting program. Then, according to the user's own needs, quantitative research on day-ahead trading is carried out to obtain the corresponding parameters, which are then brought into the backtesting program. Finally, the backtesting results of the strategy can be obtained, which represent the strategy's effectiveness on historical data. The backtesting program provides some indicators such as the cumulative maximum drawdown.

Claims

1. A backtesting system for day-ahead spot trading of electricity, characterized in that, This includes database table design, data-assisted configuration, and a backtesting engine. The parameters used by the backtesting engine include schema type, model class name, parameters required to construct model objects, decision time point, and decision date. The model types include backtesting models and prediction models; The backtesting engine execution steps include: S1. Determine the pattern type and obtain a list of query_datetime and date pairs from the data engine; S2. Create a model object based on the parameters required to construct the model object and import it into the backtesting system; S3. Substitute query_datetime and date into the run method of the model to obtain the true target and the predicted target; S4. Store the real target and the predicted target in memory; S5. Call the model's analyze method to obtain the results, and provide a visual representation and analysis of the results; The database table design fields include data acquisition date and time, data update date and time, whether it is deleted, data publication date, and data business time. The data auxiliary configuration file is of type YAML. Logically, the data auxiliary configuration is divided into upper-level data configuration and lower-level data configuration. Data interfaces can be automatically generated from the data auxiliary configuration file. The automatically generated data interfaces include upper-level data interfaces, and the generation process of the upper-level data interfaces is as follows: S51, calculate the available time dt of the queried data based on the input date and the upper-level data configuration; S52, compare the size of dt and query_datetime. If dt is greater than query_datetime, return None; S53, call the lower-level interface to obtain the data and return the data. The underlying data configuration is configured using the underlying data name as the key. The specific configuration includes data connection configuration, table name, and time column. The time column can also be generalized as an index column, representing the business time, data type, and data filtering conditions of the data. The upper-layer data configuration requires the configuration of the lower-layer data name and data time. The data time is configured as a pair, specifically (n, m), where n represents the time distance from the time column in days, and m represents the hour on the day the data is retrieved when the data becomes available. The automatically generated data interface for upper-layer data configuration has two usage modes: one is to add additional development to shield the underlying data details, and the other is to directly use the automatically generated data interface, which preserves the database details.

2. The backtesting system for day-ahead spot trading of electricity according to claim 1, characterized in that, The calculation process of run in step S3 is as follows: S31. Obtain the training feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Training objectives ; S32, Utilization , The model was trained using quantitative research methods for day-ahead trading in the electricity spot market; S33. Obtain the test feature matrix through data-assisted configuration and data interfaces automatically generated from upper-layer data. Obtain the real target using the underlying data interface. ; S34. Using the trained model and the test feature matrix, make a prediction to obtain a predicted target of the true label. and return ( , ).

3. The backtesting system for day-ahead spot trading of electricity according to claim 1, characterized in that, The automatically generated data interface includes a low-level data interface, wherein the generation process of the low-level data interface is as follows: S41. Read the underlying data configuration file to obtain the interface dictionary, where the key of the dictionary is a string representing the name of the underlying configuration and the name of the interface generated by the configuration, and the value is the underlying configuration. S42. Read the underlying configuration to obtain the parameter set; S43. Obtain the query statement using Python's string template based on the parameter set; S44. Obtain the data interface based on the query statement and store the data interface in memory for other programs, such as the upper-level data interface, to call.

4. The backtesting system for day-ahead spot trading of electricity according to claim 2, characterized in that, The quantitative research method for day-ahead trading in the aforementioned electricity spot market decomposes the target profit and loss on day j into a portion dependent on the day-ahead winning bid volume and a portion independent of the day-ahead winning bid volume, specifically as follows: = = in This refers to the electricity volume won in the recent bid. Let $\mathbf{j}$ be the daily winning bid amount at time $i$ on day $j$, which means the objective function is split into two terms. f It depends on the portion that relies on the electricity volume won in the previous day. g This refers to the portion of electricity volume that is not dependent on day-ahead winning bids, and does not consider the impact of day-ahead transactions on market prices and actual electricity consumption. g In day-to-day trading, this is a constant; all day-to-day trading in the spot market is aimed at optimizing the target. f The calculation formula is: = in The price at the i-th time point on day j. The price is the real-time price at time i on day j, taking into account that the assessment and recovery depend on different provinces. / This proportion, of which To ensure real-time bidding for electricity volume, we will provide... f Adding a constant relative to the previous day's transaction yields a new optimization objective. The calculation formula is: = in There are two ways to obtain the value. The first method is to obtain... =1, which we call the original profit and loss. Another possible value is... / No intermediate value is generated within the scope of the assessment and recovery; Two metrics are defined to characterize the return and risk of a day-ahead strategy. The metric for the return of a day-ahead strategy is called the average electricity gain / loss R, and its calculation formula is as follows: R= The current strategy risk indicator is called the cumulative maximum drawdown per kilowatt-hour (D). First, the average daily profit or loss per kilowatt-hour is calculated. The sequence is calculated using the following formula: = Then calculate the cumulative maximum drawdown D, the specific steps are as follows: S61, Average electricity loss Substitute the sequence into array A; S62. Determine the length of A. If the length of A is 0, return 0. S63. Define the cumulative maximum drawdown D=0, parameter last_max = A[0], parameter cur_cum = A[0], parameter i=1; S64. Execute cur_cum = cur_cum + A[i]; S65. Determine if cur_cum > last_max. If true, then last_max = cur_cum and execute step S17; otherwise, execute step S16. S66. Determine if cur_cum - last_max < D. If true, then D = cur_cum - last_max. S67. Execute i = i + 1; S68. Determine if i is equal to the length of A minus 1. If they are not equal, continue to execute step S14. If they are equal, then D is the cumulative maximum drawdown at this time.