A method, system, device and medium for evaluating profit and loss of power medium and long-term transaction based on spot rule

By constructing a directed acyclic computational graph and performing forward propagation and backward differentiation, the accuracy problem of power trading profit and loss attribution in existing technologies is solved, enabling refined analysis and decision support for power trading profits and losses.

CN122415151APending Publication Date: 2026-07-17GD POWER JIUQUAN GENERATION CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GD POWER JIUQUAN GENERATION CO LTD
Filing Date
2026-04-16
Publication Date
2026-07-17

AI Technical Summary

Technical Problem

Existing methods for attributing profits and losses in electricity trading cannot accurately quantify the marginal contribution of each factor. In particular, in complex multi-market, multi-time-series, and multi-entity settlement systems, they are difficult to penetrate nonlinear coupling rules and cannot provide interpretable quantitative decision-making basis.

Method used

By parsing the settlement rules of the electricity spot market to generate a structured computational task sequence, constructing a directed acyclic computational graph, performing forward propagation to calculate the total profit and loss value, and automatically generating a gradient table through reverse mode differentiation to achieve multi-level profit and loss attribution.

Benefits of technology

It can accurately quantify the marginal impact of minute changes in any input variable or intermediate rule parameter on profit and loss, provide interpretable quantitative decision-making basis, and support trading strategy optimization and risk warning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122415151A_ABST
    Figure CN122415151A_ABST
Patent Text Reader

Abstract

This application relates to a method, system, device, and medium for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules. The method generates a structured sequence of computational tasks by parsing the electricity spot market settlement rules and constructing a directed acyclic computational graph, transforming complex settlement rules into a differentiable dependency network. It performs forward propagation, calculating and storing intermediate values ​​node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost. Based on the stored intermediate values, it performs automatic differential backward propagation in a reverse mode, calculating gradients node by node to form a gradient table. Based on the gradient table, it generates multi-level attribution results at the input variable level and intermediate rule level. This method combines automatic differentiation with rule graph modeling, penetrating deviation assessments of nonlinear coupled rules such as tiered pricing and ancillary service allocation, accurately quantifying the marginal contribution of any variable or parameter change to profit and loss, and providing a refined and interpretable quantitative basis for trading decisions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of power market transaction management technology, and in particular relates to a method, system, equipment and medium for evaluating the profit and loss of medium and long-term power transactions based on spot market rules. Background Technology

[0002] Since the market-oriented reform of the power sector, the settlement system, which combines medium- and long-term transactions with the spot market, has become increasingly complex. According to the current power market rules, medium- and long-term contract electricity volumes are settled using a "take-or-pay, deviation-based" differential settlement method. Actual deviations are settled separately at deviation prices, while ancillary service fees are shared by market participants according to the principle of "whoever benefits, bears the cost." This multi-market, multi-time-series, and multi-participant settlement structure makes profit and loss analysis exceptionally difficult. In actual settlement, deviation assessment typically employs a tiered pricing system, with different settlement prices applied to positive and negative deviations within the allowable range and those exceeding the range. The allocation of ancillary service fees is simultaneously related to both the deviation volume and the spot price. These various settlement rules are coupled together through piecewise functions, conditional branches, and other nonlinear operators, resulting in the profit and loss function's partial derivatives with respect to various input variables not being constant. Therefore, the sources of profit and loss cannot be accurately identified using the traditional volume-price dichotomy method.

[0003] Existing methods for attributing profits and losses in electricity trading are mainly divided into statistical regression-based methods and analytical decomposition-based methods. Statistical regression-based methods rely heavily on the choice of regression model and sample quality, have limited ability to fit nonlinear terms, and the attribution results are essentially statistical approximations. The economic meaning of the regression coefficients is ambiguous and difficult to correlate with specific market rule parameters. Analytical decomposition-based methods are effective when the profit and loss function has a linearly additive structure, but when the settlement rules contain piecewise functions and conditional branches, analytical expansion becomes extremely difficult or even infeasible. Furthermore, hard-coded analytical formulas are difficult to adapt to the differentiated and frequently revised settlement rules across provinces. From the perspective of attribution granularity, existing methods can usually only attribute profits and losses to a few macroeconomic factors, failing to answer refined attribution questions such as whether losses are triggered by positive or negative deviation assessments, which specific period's deviation in electricity volume triggered punitive pricing, the contribution of each service type to ancillary service fees, and the marginal impact of changes in deviation assessment threshold parameters on profits and losses.

[0004] Therefore, there is an urgent need for a profit and loss assessment method that can penetrate complex settlement rules and accurately quantify the marginal contribution of each factor. This method should be able to adapt to the differentiated rules of various provinces and the dynamic changes in those rules, and provide an interpretable quantitative basis for trading strategy optimization and risk warning. Summary of the Invention

[0005] Therefore, it is necessary to provide a method, system, equipment, and medium for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules, in response to the above-mentioned technical problems.

[0006] Firstly, this application provides a method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules, including:

[0007] S1. By parsing the settlement rules of the electricity spot market, generate a structured sequence of calculation tasks describing the process from raw settlement data to total profit and loss calculation;

[0008] S2. Based on the structured computing task sequence, construct a directed acyclic computation graph that starts with the original input data and ends with the total profit and loss value; where the nodes of the directed acyclic computation graph represent computing variables, and the directed edges of the directed acyclic computation graph represent the computing dependencies between variables.

[0009] S3. By performing forward propagation on the directed acyclic computation graph, the values ​​of each node are calculated along the directed edges node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the values ​​of each intermediate node in the directed acyclic computation graph.

[0010] S4. Based on the values ​​of each intermediate node in the directed acyclic computation graph, the gradient value of each node relative to the total profit and loss value is calculated node by node along the reverse direction of the directed edge by performing backward propagation of the reverse mode automatic differentiation on the directed acyclic computation graph, and the gradient table is obtained.

[0011] S5. Based on the gradient values ​​of each node in the gradient table, generate multi-level profit and loss attribution results, and use the multi-level profit and loss attribution results as the profit and loss assessment results for medium and long-term power transactions; wherein, the multi-level profit and loss attribution results include input variable level attribution results and intermediate rule level attribution results.

[0012] Secondly, this application also provides a profit and loss assessment system for medium- and long-term electricity transactions oriented towards spot market rules, used to implement the method described in the first aspect, the system comprising:

[0013] The rule parsing and task generation module is used to generate a structured sequence of calculation tasks that describe the process from raw settlement data to total profit and loss calculation by parsing the settlement rules of the electricity spot market.

[0014] The computation graph construction module is used to construct a directed acyclic computation graph based on the structured computation task sequence, starting from the original input data and ending at the total profit and loss value. In this graph, the nodes represent computation variables, and the directed edges represent the computational dependencies between variables.

[0015] The forward propagation calculation module is used to perform forward propagation on the directed acyclic computation graph, calculate the value of each node along the directed edge node by node, and obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the value of each intermediate node in the directed acyclic computation graph.

[0016] The reverse gradient calculation module is used to calculate the gradient value of each node relative to the total profit and loss value in the reverse direction of the directed acyclic computation graph by performing backward propagation of automatic differentiation in the reverse mode on the directed acyclic computation graph, based on the values ​​of each intermediate node in the directed acyclic computation graph, and obtain the gradient table.

[0017] The profit and loss attribution analysis module is used to generate multi-level profit and loss attribution results based on the gradient values ​​of each node in the gradient table. These multi-level profit and loss attribution results are used as the profit and loss assessment results for medium- and long-term power transactions. The multi-level profit and loss attribution results include input variable-level attribution results and intermediate rule-level attribution results.

[0018] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement a method for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules as described in the first aspect.

[0019] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules as described in the first aspect.

[0020] The aforementioned method, system, equipment, and medium for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules generate a structured sequence of computational tasks describing the process from raw data to profit and loss calculation by parsing the settlement rules of the electricity spot market. Based on this, a directed acyclic computational graph is constructed, starting from the raw input and ending with the total profit and loss value, transforming the complex settlement rules into a computable directed dependency network. On this basis, forward propagation is performed on the computational graph, calculating and storing the specific values ​​of each intermediate variable node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost. Subsequently, based on the values ​​of each intermediate node stored in the forward propagation, backward propagation with automatic differentiation in the reverse mode is performed on the same computational graph, accurately calculating the gradient of each variable relative to the total profit and loss value node by node along the reverse direction of the directed edges, forming a gradient table containing marginal contribution information of all nodes. Finally, based on the gradient values ​​of each node in the gradient table, multiple levels of attribution results covering the input variable level and the intermediate rule level are generated, which serve as the profit and loss evaluation result for medium- and long-term electricity transactions. By organically combining automatic differentiation technology with the graphical modeling of electricity settlement rules, this method elevates the traditional coarse-grained price-volume dichotomy attribution to a refined marginal contribution analysis at the rule and variable levels. It can penetrate the superposition effect of multiple nonlinear coupled rules such as deviation assessment tiered pricing and ancillary service cost allocation, and accurately quantify the marginal impact of small changes in any input variable or intermediate rule parameter on the final profit and loss. This provides an interpretable quantitative decision-making basis for trading strategy optimization, risk warning, and rule sensitivity assessment. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 A flowchart illustrating a method for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules, provided by this invention;

[0023] Figure 2 This is a schematic diagram of the process for generating input variable-level attribution results in one optional embodiment of the present invention;

[0024] Figure 3 This is a schematic diagram of the process for generating intermediate rule-level attribution results in one optional embodiment of the present invention.

[0025] Figure 4 This is a schematic diagram of the structure of a profit and loss assessment system for medium- and long-term electricity transactions based on spot market rules, provided by the present invention. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0027] This invention provides a method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules. This method can be deployed on the data server of an electricity trading center, the local computing server of market participants, or a cloud-based virtual computing instance. The server or computing instance communicates with the electricity trading platform, the spot market clearing system, and the ancillary services market system via data interfaces to obtain settlement rule configuration files, market participant contract data, time-of-use actual electricity consumption data, spot market time-of-use clearing price data, and ancillary services market total cost data. The processor of the server or computing instance loads and executes the instructions for each step of this method, transmitting the generated profit and loss assessment results and multi-level attribution data via network to the terminal devices of traders or administrators for display.

[0028] Example 1: Reference Figure 1 The application presents a flowchart illustrating a method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules. This method includes the following steps:

[0029] S1. By parsing the settlement rules of the electricity spot market, a structured calculation task sequence describing the process from raw settlement data to total profit and loss calculation is generated.

[0030] Specifically, before the monthly settlement cycle begins, the rule engine deployed on the server retrieves a settlement rule configuration file stored in Extensible Markup Language (EXPLAIN) format from the power trading center. This configuration file follows a predefined subset of power settlement rule syntax, which includes syntax for electricity variable declarations, price variable declarations, arithmetic expression syntax, conditional expression syntax, and piecewise function definition syntax. Internally, the rule engine maintains an industry terminology mapping table, mapping specific terms in the rule texts of various provinces to unified variable identifiers; for example, mapping "contractual electricity volume" to... Mapping "day-ahead clearing electricity price" to Mapping the "scope of assessment without deviation" to .

[0031] The rule engine performs lexical analysis on the rule file, breaking down the text stream into a sequence of lexical units consisting of identifiers, keywords, operators, and numerical literals. It then performs syntactic analysis, constructing an abstract syntax tree (Abstract Syntax Tree) from the sequence of lexical units based on the grammar rules defined in the grammar subset. In the Abstract Syntax Tree, each leaf node corresponds to a primitive input variable or constant parameter, and each internal node corresponds to an operation or conditional judgment. The rule engine traverses the Abstract Syntax Tree, using a post-order traversal to transform each internal node into an independent computation instruction. For rule nodes containing nested conditional branches, the rule engine expands the conditional branches into computation instructions for conditional selection operators; for multi-level piecewise function nodes, the rule engine breaks them down into combined computation instructions for multiple maximum value operators and multiplication operators. When the execution of one rule depends on the computation result of another rule, the rule engine automatically determines the order of computation instructions by analyzing the parent-child dependencies of nodes in the Abstract Syntax Tree and arranges all instructions in topological order.

[0032] The rule engine arranges all the transformed computation instructions according to the causal order of the settlement process, forming a structured computation task sequence. When a settlement rule is partially modified, the rule engine only re-parses the affected abstract syntax tree subtree, marks and replaces the changed computation instructions in the original structured computation task sequence, and leaves the computation instructions unaffected by the modified rules unchanged. This achieves incremental updates to the computation task sequence and the directed acyclic computation graph without having to rebuild the entire graph.

[0033] Each calculation instruction's data structure includes an instruction type field, identifying whether the instruction is an arithmetic operation, comparison operation, or conditional branch operation; an input variable list field, recording the names of upstream variables to be read when executing the instruction; an output variable field, recording the name of the variable storing the instruction's calculation result; and an operator identifier field, indicating the specific operator type used by the instruction, such as addition, multiplication, division, maximum value, minimum value, or conditional selection operator. This structured calculation task sequence declaratively and completely describes the entire calculation process from the original input variables, through layers of calculation, to finally converge into the total profit and loss value, thus completely decoupling the settlement rules from the underlying execution code.

[0034] S2. Based on the structured computing task sequence, construct a directed acyclic computation graph that starts with the original input data and ends with the total profit and loss value. In this graph, the nodes represent computational variables, and the directed edges represent the computational dependencies between variables.

[0035] Specifically, the power trading profit and loss assessment system (hereinafter referred to as the "system") deployed on the server or computing instance traverses each calculation instruction in the structured computing task sequence and creates a corresponding node object for the output variable of that instruction. Taking a simplified assessment period containing three consecutive time periods as an example, the system first creates an input node group corresponding to the original input data, including the contract electricity node for the first time period. Contract price nodes for the first period Actual electricity consumption nodes in the first time period The first period's spot price node The first phase of the ancillary services market total cost node The system also includes a second-time period input node group and a third-time period input node group with the same structure. In addition, the system creates global rule parameter nodes, including a positive deviation exemption ratio parameter node. Negative deviation exemption from assessment parameter node Positive deviation over-limit penalty coefficient node and negative deviation over-limit penalty coefficient node .

[0036] For each computation instruction, the system creates a computation node with the same name as the output variable, and adds a directed edge from the upstream node corresponding to each variable in the input variable list of that instruction to the newly created computation node. For example, for a time period... The command for calculating positive deviation electricity usage takes time period as its input variable. Deviation in electricity quantity With a constant of zero, and the operator type being the maximum value operator, the system creates a positive deviation energy calculation node. From the deviation power calculation node and constant zero node Draw a directed edge pointing to each of them. And associate the execution logic reference of the maximum value operator in the standardized operator library with this node.

[0037] After processing in this manner, the computational graph contains four types of nodes: input nodes with an in-degree of zero, corresponding to the original settlement data and global rule parameters for each time period; computational nodes with both in-edges and out-edges, corresponding to the intermediate variables generated by each computational instruction; aggregation nodes that sum up similar nodes from multiple time periods, such as the monthly total contract electricity fee node that adds up the contract electricity fees for three time periods; and the root node with an out-degree of zero, corresponding to the final total profit or loss value relative to the benchmark electricity purchase cost. Directed edges strictly point from the upstream variable to the downstream computational node that depends on that variable.

[0038] After the graph is constructed, the system uses the Karn algorithm to perform a topological sort on all nodes, generating a linear computational order for each node. Simultaneously, it verifies that no directed loops exist in the graph, ensuring that both forward and backward propagation can be executed completely within linear time complexity. The technical advantage of constructing a directed acyclic computational graph lies in explicitly expressing the complex computational dependencies implicit in the settlement rule text as a computable directed graph structure, providing a standardized data foundation for subsequent automatic differentiation operations.

[0039] S3. By performing forward propagation on the directed acyclic computation graph, the values ​​of each node are calculated along the directed edges node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the values ​​of each intermediate node in the directed acyclic computation graph.

[0040] Specifically, the system executes the forward computation logic of its association operator for each node sequentially according to the node order determined by the topological sorting. First, each input node loads the actual data for the evaluation period from the external data source: for each time period... Contracted electricity volume nodes The assigned value is the medium- and long-term contract electricity volume held by market participants during that period, and the contract price node. The value assigned is the price agreed upon in the corresponding contract, and the actual electricity consumption node. The value assigned is the actual electricity consumption during that period collected by the metering system, and the spot price node. The value assigned is the marginal electricity price at that time period published by the spot market clearing system, and the total ancillary service cost at that node. The value is assigned to the total cost of ancillary services across the entire network for that period, as published by the power trading center. The global rule parameter node is assigned the parameter value applicable to the current settlement cycle. Subsequently, the system processes the computing nodes layer by layer: for each computing node, the system reads the values ​​that have been calculated and stored by all its predecessor nodes in the current forward propagation, calls the operator library associated with that node to execute the logic to perform the calculation, and stores the calculation result inside that node.

[0041] In the deviation electricity charge calculation subgraph, the system first calculates the deviation electricity node. The value is ; and then calculate the positive deviation electrical node. The value is Calculate the negative deviation electrical node The value is ; Calculate the threshold node for exemption from assessment for positive deviation The value is Negative deviation exemption threshold node The value is ; Calculate the positive deviation assessment electricity node The value is For multi-tiered deviation assessment rules containing three or more tiers, the rule engine decomposes them into a combination of multiple two-tiered piecewise functions when generating the structured computation task sequence. For example, for "deviation rates between 0% and 2% are exempt from assessment, 2% to 5% are assessed..." Settlement at multiples of 5%, or more than 5%. The system breaks down the "double settlement" three-tier rule into the first stage of assessment electricity consumption. The second stage assesses the amount of electricity consumed. The corresponding assessment electricity fees are calculated separately and then summed up. This represents the proportion of the first-tier threshold. This represents the second-order threshold ratio. When the input variable falls exactly at the boundary between the two orders of magnitude, the selection of the subgradient follows the half-allocation strategy of the maximum value operator in the equal case in Example 3 below, to ensure the continuity of gradient propagation. When the contracted electricity volume for a certain period... When the threshold is zero, both the positive deviation exemption threshold and the negative deviation exemption threshold are zero, and all deviation electricity consumption during this period will be settled according to the corresponding over-limit penalty coefficient. Positive deviation electricity billing node. The value, as defined by the rules, consists of two parts: the electricity fee exempt from assessment and the electricity fee for exceeding the limit as a penalty. Its forward propagation calculation formula is as follows:

[0042]

[0043] in, Indicates time period The positive deviation in electricity bill settlement amount, Indicates time period The positive deviation threshold for exemption from assessment is the amount of electricity. Indicates time period The spot market clearing price, Indicates time period The portion of electricity exceeding the exemption threshold for assessment. This is the penalty coefficient for positive deviation exceeding limits. Similarly, the calculation of negative deviation electricity bill nodes also follows the logic of exemption from assessment and segmented pricing for exceeding limits under the corresponding rules.

[0044] In the ancillary service cost allocation subgraph, the system calculates the network-wide allocation base node. The value is the sum of the actual electricity consumption of all market participants during that period plus the sum of the on-grid electricity that did not participate in the electricity market transaction; the allocation ratio node is calculated. The value is When the total network share base When the value of approaches zero, the result of the division operation mathematically approaches infinity. The system performs gradient clipping for this boundary case: if If the absolute value is less than the preset minimum positive threshold, the apportionment ratio will be adjusted. The gradient is forcibly set to zero, and its upstream gradient is truncated during subsequent backpropagation, preventing it from propagating to the input node and thus avoiding computational distortion caused by gradient explosion. Under normal circumstances, the auxiliary service cost-sharing node is computed. The value is .

[0045] Benchmark electricity purchase cost nodes for each time period The value is based on Calculation. After the calculation results for each time period are aggregated to the aggregation node, the root node subtracts the total monthly contract electricity cost, the total monthly deviation electricity cost, and the total monthly ancillary service allocation cost from the total monthly benchmark electricity purchase cost to obtain the total profit or loss value relative to the benchmark electricity purchase cost for the assessment period. The total profit and loss is expressed by the following formula:

[0046]

[0047] in, This represents the total profit or loss relative to the benchmark electricity purchase cost for the assessment period. To determine the total number of time periods within the assessment period, For time period The benchmark electricity purchase cost, For time period Electricity expenses under medium- and long-term contracts For time period Deviation in electricity expenses, For time period The cost of ancillary services is allocated. A positive value indicates that the actual electricity purchase cost is lower than the benchmark cost of spot electricity purchase for the entire amount of electricity, achieving cost savings; a negative value indicates that the actual cost is higher than the benchmark. At this point, the forward propagation is complete, and each computation node, aggregation node, and root node in the computational graph stores its specific value for this evaluation period. The values ​​of each intermediate node are stored; these stored values ​​are necessary input data for calculating local partial derivatives in the subsequent backward propagation stage.

[0048] S4. Based on the values ​​of each intermediate node in the directed acyclic computation graph, the gradient value of each node relative to the total profit and loss value is calculated node by node along the reverse direction of the directed edge by performing backward propagation of the reverse mode automatic differentiation on the directed acyclic computation graph, thus obtaining the gradient table.

[0049] Specifically, the system initializes a gradient table indexed by node identifiers, and sets the root node... The gradient values ​​in this table are set to The gradient values ​​of the remaining nodes are initialized to zero. Subsequently, the system processes each node sequentially in reverse topological sort order. For large-scale computational graphs containing tens of thousands of nodes, the system employs a batch node parallel scheduling strategy: the reverse topological sort list is divided into multiple independent batches of nodes. Nodes within the same batch can perform backpropagation computations in parallel on multiple processor cores. After computation, the gradient components calculated by each core are aggregated into the gradient table. To reduce the memory footprint of the gradient table, the system uses a sparse gradient storage format, allocating storage space only for nodes with non-zero gradient values. For the currently processed node... The system reads the accumulated upstream gradient values ​​of the node from the gradient table. The system retrieves the operator library execution logic associated with the node in step S2 and calls the backpropagation function defined by that operator. The backpropagation function uses the values ​​of each input node stored during the forward propagation phase and the upstream gradient values ​​to calculate the gradient components to be passed to each input node according to the chain rule. Taking the multiplication operator as an example, let... Then the gradient component transmitted to the first input node is: The gradient component transmitted to the second input node is ,in and These are the values ​​stored by the two input nodes during forward propagation. The system accumulates the calculated gradient components into the corresponding entry for the input node in the gradient table. When the same node serves as the input to multiple downstream nodes, it will receive one gradient component from each downstream node, and the final gradient value for that node in the gradient table is the algebraic sum of all components. For constant nodes, the system automatically discards their gradient values ​​after gradient propagation is complete, and they are not included in subsequent attribution analysis.

[0050] The gradient propagation process proceeds layer by layer in the reverse direction of the directed edges, propagating downwards from the root node to all input nodes. Once the reverse processing is complete, the gradient table stores the total profit / loss value of each node in the computational graph relative to the total profit / loss. The precise gradient value. For any node. Its gradient value The economic meaning of this is that, under the assumption that all other input variables remain constant, the node For every unit increase in the value, the total profit / loss value... The marginal changes that occur. The technical advantage of performing backpropagation for automatic differentiation in the reverse mode is that it can obtain the gradients of all input variables and intermediate variables with respect to the total profit and loss with only one back traversal. Its computational complexity is independent of the number of input variables, thus efficiently supporting large-scale, high-dimensional, refined attribution analysis.

[0051] S5. Based on the gradient values ​​of each node in the gradient table, generate multi-level profit and loss attribution results, and use the multi-level profit and loss attribution results as the profit and loss assessment results for medium and long-term power transactions; wherein, the multi-level profit and loss attribution results include input variable level attribution results and intermediate rule level attribution results.

[0052] Specifically, the system extracts the gradient values ​​corresponding to all input nodes from the gradient table. Contract electricity quantities for each time period... gradient value The marginal contribution vector constituting the contracted electricity volume dimension, with its positive or negative value indicating the direction of the marginal impact of increasing the contracted electricity volume for that period on the savings in electricity purchase costs. Actual electricity consumption nodes for each period. gradient value The marginal contribution vector constituting the electricity consumption deviation dimension, and the spot price nodes for each time period. gradient value This constitutes the marginal contribution vector in the spot price dimension.

[0053] The system organizes the gradient values ​​by time period and dimension, generating input variable-level attribution results. Simultaneously, the system extracts the gradient values ​​of intermediate rule nodes from the gradient table, including deviation assessment fee nodes for each time period. gradient Ancillary service cost allocation nodes for each time period gradient And rule parameter nodes such as the proportion of positive deviation exempt from assessment gradient Positive deviation over-limit penalty coefficient gradient The system combines the actual amounts calculated by each intermediate rule node during forward propagation to generate intermediate rule-level attribution results. The input variable-level attribution results are then combined with the intermediate rule-level attribution results to form a complete profit and loss assessment result for medium- and long-term electricity transactions, which is presented to traders through the terminal interface. The technical advantage of generating multi-level profit and loss attribution results including input variable and intermediate rule levels lies in its ability to penetrate from macro-level dimensions such as contracted electricity volume, electricity consumption deviation, and spot prices to specific deviation assessment rules, ancillary service allocation rules, and their parameter dimensions. This accurately answers the quantitative contribution of each variable and rule to the final profit and loss, providing decision-making basis for refined adjustments to trading strategies that traditional methods cannot offer.

[0054] The aforementioned method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules generates a structured sequence of computational tasks describing the process from raw data to profit and loss calculation by parsing the settlement rules of the electricity spot market. Based on this, a directed acyclic computational graph is constructed, starting from the raw input and ending with the total profit and loss value, transforming the complex settlement rules into a computable directed dependency network. On this basis, forward propagation is performed on the computational graph, calculating and storing the specific values ​​of each intermediate variable node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost. Subsequently, based on the values ​​of each intermediate node stored in the forward propagation, backward propagation with automatic differentiation in the reverse mode is performed on the same computational graph, precisely calculating the gradient of each variable relative to the total profit and loss value node by node along the reverse direction of the directed edges, forming a gradient table containing marginal contribution information of all nodes. Finally, based on the gradient values ​​of each node in the gradient table, multiple levels of attribution results covering the input variable level and the intermediate rule level are generated, which serve as the profit and loss assessment result for medium- and long-term electricity transactions. By organically combining automatic differentiation technology with the graphical modeling of electricity settlement rules, this method elevates the traditional coarse-grained price-volume dichotomy attribution to a refined marginal contribution analysis at the rule and variable levels. It can penetrate the superposition effect of multiple nonlinear coupled rules such as deviation assessment tiered pricing and ancillary service cost allocation, and accurately quantify the marginal impact of small changes in any input variable or intermediate rule parameter on the final profit and loss. This provides an interpretable quantitative decision-making basis for trading strategy optimization, risk warning, and rule sensitivity assessment.

[0055] Example 2: Based on the structured computing task sequence, construct a directed acyclic computation graph starting from the original input data and ending at the total profit / loss value, including the following steps:

[0056] S11. For each computation instruction in the structured computation task sequence, determine the operator type corresponding to the computation instruction by identifying the input and output variables of the computation instruction.

[0057] Specifically, the system reads the computation instructions from the structured computing task sequence one by one, by time period. Taking the positive deviation electricity calculation instruction as an example, the system parses the input variable list field of the instruction and obtains the input variable identifier as the time period. Deviation in electricity quantity A constant variable with a sum of zero; parse its output variable fields to obtain the output variable identifier as a time period. Positive deviation of electricity variable ; Parse its operator identifier field to determine that the operator type corresponding to the instruction is the maximum value operator.

[0058] By time period Taking the instruction for calculating the positive deviation exemption threshold as an example, the system identifies its input variable as the positive deviation exemption ratio parameter. and time period Contracted electricity volume variable The output variable is the threshold variable for exemption from assessment due to positive deviation. The operator type is a multiplication operator.

[0059] By time period Taking the instruction for calculating the ancillary service cost sharing as an example, the system identifies the input variable as the time period. The sharing ratio variable and time period Ancillary service total cost variable The output variable is the time period. Ancillary service cost allocation variable The operator type is a multiplication operator.

[0060] Taking the instruction for calculating the sharing ratio as an example, the system recognizes that its input variable is the time period. Actual electricity consumption variables and the total network share base variable The output variable is the sharing ratio variable. The operator type is division operator.

[0061] By identifying each instruction in the structured computing task sequence, the system obtains all the node metadata and inter-node dependencies required to construct the computing graph.

[0062] S12. By creating computation nodes corresponding to the output variables, adding directed edges from the nodes corresponding to the input variables to the computation nodes, and associating the operator type with the corresponding computation node, an initial computation graph including input nodes, computation nodes, aggregation nodes, and root nodes is constructed.

[0063] Specifically, the system pre-builds a standardized operator library, which contains all the basic operator types required for electricity settlement rules, including addition, subtraction, multiplication, division, maximum value, minimum value, conditional selection, and summation operators. Each operator in the library corresponds to a unique operator identifier, and standard forward computation functions and backward gradient propagation functions are predefined.

[0064] The system maintains a mapping table with variable identifiers as keys and node objects as values. For each calculation instruction, the system first looks up or creates the node objects corresponding to each input variable of the instruction in the mapping table, then creates a new calculation node object for the output variable of the instruction, and adds the new node to the mapping table. (By time period) Taking the positive deviation power calculation instruction as an example, the system finds the deviation power calculation node. and constant zero node Create a new positive deviation electricity calculation node ,from Towards Add a directed edge from Towards Add a directed edge and associate the execution logic reference of the maximum value operator in the normalized operator library with it. node.

[0065] In this way, the system sequentially constructs a complete set of nodes and directed edges. Based on the position and function of each node in the graph, they can be divided into four categories: The first category is input nodes, which are pre-created and added to the mapping table before the computational graph is constructed. These nodes have an in-degree of zero and include nodes for contracted electricity volume, contracted price, actual electricity consumption, spot price, total ancillary service cost, and global rule parameter nodes for each time period. The second category is computational nodes, consisting of nodes corresponding to the output variables of each computational instruction. Each computational node is associated with a specific operator library execution logic and has both in-edges and out-edges. The third category is aggregation nodes, used to sum the results of similar calculations across multiple time periods, such as the monthly total deviation electricity fee node. Electricity billing nodes based on time period deviations The input is used to perform a summation operator; the fourth type is the root node, i.e., the total profit and loss value node, whose incoming edges come from the monthly total benchmark electricity purchase cost node, the monthly total contract electricity fee node, the monthly total deviation electricity fee node, and the monthly total ancillary service allocation cost node, and its out-degree is zero. All nodes and directed edges together constitute the initial computational graph.

[0066] S13. By performing topological sorting verification on the initial computation graph, it is ensured that there are no directed cycles in the initial computation graph, thus obtaining a directed acyclic computation graph.

[0067] Specifically, the system uses the Karn algorithm to perform topological sorting verification on the initial computational graph. The algorithm maintains a queue of nodes with an in-degree of zero, initially adding all input nodes to the queue. The system retrieves a node from the head of the queue and adds it to the topological sorting result list. It then iterates through all outgoing edges of that node, decrementing the in-degree of each downstream node pointed to by an outgoing edge. If the in-degree of a downstream node reaches zero, it adds that downstream node to the queue. This process is repeated until the queue is empty. If the number of nodes in the topological sorting result list equals the total number of nodes in the initial computational graph, the verification passes, the initial computational graph is confirmed as a directed acyclic computational graph, and the topological sorting result list represents the valid execution order for subsequent forward propagation. If the number of nodes in the result list is less than the total number of nodes, it indicates the presence of directed cycles in the graph, such as a situation where node A depends on node B, and node B depends on node A, due to an incorrect settlement rule configuration. In this case, the system outputs the list of nodes with cycles to the management interface, prompting the administrator to correct the rule file and rebuild the graph until the topological sorting verification passes. The technical advantage of performing topological sorting verification is that it can automatically detect possible circular dependency errors in the settlement rules, ensure the computability of the computation graph, and prevent forward and backward propagation from entering infinite loops.

[0068] Example 3: Operator types include maximum value operator, minimum value operator, and conditional selection operator.

[0069] Forward propagation is performed on the directed acyclic computation graph, including: executing the defined forward computation logic for the maximum value operator, minimum value operator, and conditional selection operator respectively, and storing the computation results in the corresponding computation nodes; wherein, for the conditional selection operator, the forward propagation selects the true value branch node value or the false value branch node value as the output based on the Boolean value of the condition node, and stores the Boolean result of the condition judgment in the condition node.

[0070] Based on the values ​​of each intermediate node in the directed acyclic computation graph, backward propagation of automatic differentiation in reverse mode is performed on the directed acyclic computation graph. This includes: for the maximum value operator, minimum value operator, and conditional selection operator, the defined backward gradient propagation logic is executed respectively using the values ​​stored in the forward propagation of the corresponding computation nodes; when the same node is used as the input of multiple downstream nodes, the gradient of the node is the sum of the gradient components received from each downstream node.

[0071] For the maximum operator, the expression for the gradient assignment rule during backpropagation is:

[0072]

[0073]

[0074] in, Represents total profit and loss. This represents the input variable of the first input node of the maximum value operator. This represents the input variable of the second input node of the maximum value operator. This represents the output value of the output node of the maximum value operator. This represents the accumulated upstream gradient at the output node of the maximum value operator. and These represent the gradients passed to the first and second input nodes of the maximum value operator, respectively. The first indicator function takes the value of 1 when the stored value of the first input node of the maximum value operator is greater than the stored value of the second input node, and takes the value of 0 otherwise. When the stored value of the first input node of the maximum value operator is equal to the stored value of the second input node, the first input node and the second input node of the maximum value operator each obtain half of the upstream gradient.

[0075] For the minimum operator, the expression for the gradient assignment rule during backpropagation is:

[0076]

[0077]

[0078] in, This represents the input variable of the first input node of the minimum value operator. This represents the input variable of the second input node of the minimum value operator. This represents the output value of the output node of the minimum value operator. This represents the accumulated upstream gradient at the output node of the minimum operator. and These represent the gradients passed to the first and second input nodes of the minimum operator, respectively. The second indicator function takes the value of 1 when the stored value of the first input node of the minimum operator is less than the stored value of the second input node, and takes the value of 0 otherwise. When the stored value of the first input node of the minimum operator is equal to the stored value of the second input node, the first input node and the second input node of the minimum operator each obtain half of the upstream gradient.

[0079] For the conditional selection operator, the backpropagation passes the upstream gradient to the selected true or false branch node in the forward propagation based on the Boolean result stored in the condition node. The condition node does not receive gradients.

[0080] Specifically, during the forward propagation of the directed acyclic computation graph, the system performs the following forward computation logic on the computation nodes of the associated maximum value operator: read the value stored in the first input node of the node. The second input node stores the values Compare the two values ​​and take the larger value as the output value of that node. Stored on this node. Organized by time period. Taking the positive deviation energy calculation as an example, the first input node is the deviation energy calculation node. Its stored value is the algebraic value of the actual electricity consumption and the contracted electricity consumption, and the second input node is a constant zero node. .like If the value is positive, then the positive deviation electricity node Store the positive number; if If the value is negative or zero, then The system stores the value zero. For computation nodes associated with the minimum value operator, the system reads the stored values ​​of the two input nodes and stores the smaller value as the output value. For computation nodes associated with the division operator, the system reads the stored value of the first input node. The second input node stores the values The quotient of the two is calculated and stored as the output value in this node. For the calculation node of the association condition selection operator, the system first reads the condition node. Stored Boolean values; if the Boolean value is true, select the true branch node. The value is used as the output; if the Boolean value is false, then the false branch node is selected. The value is output; at the same time, the system stores the Boolean result inside the condition node for use in the subsequent backpropagation stage.

[0081] During the backward propagation of the directed acyclic computation graph based on the intermediate node values ​​stored in the forward propagation, the system performs the following backward gradient propagation logic on the computation nodes of the associated maximum operator: read the accumulated upstream gradient values ​​of that node. And obtain the value of the first input node stored in the node during forward propagation. Second input node value The gradient assignment rule is given by the following formula:

[0082]

[0083]

[0084] in, This represents the total profit or loss calculated from the root node. This represents the input variable of the first input node of the maximum value operator. This represents the input variable of the second input node of the maximum value operator. This represents the output value of the output node of the maximum value operator. This indicates the accumulated upstream gradient value of the output node of the maximum value operator. This represents the gradient components passed to the first input node. This represents the gradient component passed to the second input node. For the first indicator function, when the stored value of the first input node... The stored value is greater than the second input node. When, the indicator function takes the value Otherwise, the value is .when and When the stored values ​​are equal, the system adopts a subgradient approximation strategy to pass the value to the first input node. The gradient components are also transmitted to the second input node. The gradient components. For a combination of multiple maximum operators obtained by decomposing a multi-step piecewise function, the backpropagation sequentially applies the above gradient allocation rule at each maximum operator node, and the gradient signal is transmitted layer by layer from top to bottom, eventually being correctly allocated to the original input variable. The effect of using subgradient approximation to handle non-differentiable points is that it ensures the continuity of the gradient propagation path at the breakpoints of the piecewise function, enabling automatic differentiation to be stably executed in the settlement rule graph containing a large number of non-smooth operators. Taking positive deviation charge nodes as an example. Taking the backward propagation as an example, if the deviation power value stored in the forward direction is greater than zero, then all upstream gradients are passed to the deviation power calculation node; if the deviation power value is less than zero, then all upstream gradients are passed to the constant zero node. Since the gradient of the constant zero node has no practical economic meaning, the gradient propagation path is actually terminated; if the deviation power value is exactly zero, then the upstream gradients are evenly distributed to the two input nodes.

[0085] For nodes that compute the associated minimum operator, the backward gradient propagation logic is given by the following formula:

[0086]

[0087]

[0088] in, This represents the input variable of the first input node of the minimum value operator. This represents the input variable of the second input node of the minimum value operator. This represents the output value of the output node of the minimum value operator. This indicates the accumulated upstream gradient value of the output node of the minimum value operator. This represents the gradient components passed to the first input node. This represents the gradient component passed to the second input node. The second indicator function is used when the stored value of the first input node... The stored value is less than the second input node. The time value is Otherwise, the value is When the stored values ​​are equal, each receives half of the upstream gradient.

[0089] In addition, the operator type also includes the division operator. For the computation node associated with the division operator, the backward gradient propagation logic is as follows: read the accumulated upstream gradient value of the node. And obtain the value of the first input node stored in the node during forward propagation. Second input node value The system first determines the value of the second input node. If the absolute value is less than a preset numerical stability threshold, gradient truncation is triggered, and no gradient components are propagated to the first and second input nodes. If the absolute value is greater than or equal to the threshold, gradient allocation is calculated according to the following rules:

[0090]

[0091]

[0092] in, This represents the value of the first input node of the division operator, i.e., the dividend. This represents the value of the second input node of the division operator, i.e., the divisor. This represents the output value of the output node of the division operator. This represents the accumulated upstream gradient value at the output node of the division operator. This represents the gradient components passed to the first input node. This represents the gradient component passed to the second input node. In actual electricity settlement scenarios, the dividend is usually the electricity consumption of market participants, and the divisor is the base for the entire network's allocation. This gradient allocation rule and the accompanying numerical stability check can accurately reflect the marginal impact of changes in the allocation ratio on the total profit and loss, while avoiding numerical anomalies caused by a divisor of zero.

[0093] For the computation node of the association conditional selection operator, the backpropagation reads the Boolean result stored inside the conditional node during the forward propagation phase: if the Boolean result is true, then all upstream gradients are passed to the truth branch node. If the Boolean result is false, then all upstream gradients are passed to the false value branch node. Condition nodes, because they correspond to non-differentiable discrete decision operations, do not receive any gradients during backpropagation. The technical reason why condition nodes do not receive gradients is that condition decisions are discrete operations, and the derivative of their output with respect to the input is mathematically non-existent or zero. Forcing gradient propagation would distort the attribution results.

[0094] Furthermore, in the entire directed acyclic computation graph, a node may simultaneously serve as the input to multiple downstream computation nodes. For example, during a time period... Contracted electricity nodes It also provides input data for the contract electricity cost calculation node, the deviation electricity calculation node, and the exemption threshold calculation node. During the backpropagation process, Each node will receive its respective gradient components from the three downstream nodes. The system maintains the cumulative gradient value of each node in the gradient table. Whenever a new gradient component propagates from a downstream node to this node, the system algebraically adds this gradient component to the existing cumulative value in the gradient table and updates it. Ultimately, The total gradient value of a node is the sum of the gradient components propagated from the three paths: the contract electricity fee path, the deviation electricity path, and the exemption threshold path. While accumulating gradients, the system records the gradient component values ​​contributed by each propagation path, forming a path gradient component table. This gradient accumulation mechanism strictly conforms to the chain rule of multivariable function differentiation, ensuring the accuracy and completeness of gradient calculation under multi-dependency paths.

[0095] Example 4: Reference Figure 2 The steps for generating input variable-level attribution results include:

[0096] S21. Extract the gradient values ​​corresponding to all input nodes from the gradient table, and use the gradient values ​​as the marginal contribution of each input variable to the total profit and loss value.

[0097] Specifically, after the backpropagation is completed, the gradient table stores the gradient values ​​of all nodes in the computational graph. The system then filters out the node entries marked as input nodes in step S2. (By time period) For example, extract the contract electricity input node. gradient value This gradient value represents the marginal contribution of the contracted electricity volume variable to the total profit and loss. Its economic interpretation is: when the contracted electricity volume increases by one unit during a given period while all other input variables remain constant, the total profit and loss... The amount indicated by this gradient value will be varied. A positive gradient value indicates that increasing the contracted electricity volume will increase savings in electricity purchase costs; a negative value indicates that reducing the contracted electricity volume is more advantageous. Similarly, the actual electricity consumption input node will be extracted. gradient value Its positive or negative sign reflects the direction of the marginal impact of changes in actual electricity consumption on savings in electricity purchase costs. Extracting the spot price input node. gradient value Its value reflects the strength of the marginal impact of spot price fluctuations on total profit and loss.

[0098] S22. For each input variable, multiply the marginal contribution by the deviation of the input variable from the preset benchmark value to obtain the actual contribution estimate of the input variable to the total profit and loss; wherein, the formula for calculating the actual contribution estimate is:

[0099]

[0100] in, Indicates input variables Estimate the actual contribution of total profit and loss. Represents total profit and loss. This represents the input variables extracted from the gradient table. gradient value, Indicates input variables The deviation from the preset reference value.

[0101] Specifically, the system pre-sets benchmark values ​​for each input variable. The selection of benchmark values ​​follows these rules: when assessing the profit and loss contribution of the contract signing strategy, the benchmark value is the contract electricity volume for each time period preset in the trading plan; when assessing the profit and loss impact caused by load forecast deviations, the benchmark value is the forecasted electricity consumption output by the load forecasting system; when assessing the impact of spot market price fluctuations, the benchmark value is the forward price referenced at the time of signing medium- and long-term contracts or the average spot price for the same period in the previous trading cycle. For time periods... The contracted electricity volume variable, let its actual value be... The baseline value is The deviation is The actual contribution of this variable to the total profit and loss is estimated using the following formula:

[0102]

[0103] in, Indicates input variables The estimated actual contribution to total profit and loss. This represents the total profit or loss calculated from the root node. This represents the input variables extracted from the gradient table. gradient value, Indicates input variables The deviation of the actual value from the preset benchmark value. When the deviation of the input variable is large, the system can divide the deviation interval into several smaller intervals, calculate the gradient value at the midpoint of each smaller interval, and multiply the gradient value by the interval length to obtain the contribution estimate for that interval. Finally, the contribution estimates of all intervals are summed to obtain the total contribution estimate, thereby achieving piecewise linear approximation to correct the error caused by nonlinear effects. The system also estimates the truncation error of the piecewise linear approximation. The error estimate is equal to the remainder of the second-order Taylor expansion of the nonlinear contribution of the variable. When the error estimate exceeds the preset proportion threshold of the actual contribution estimate, the system adds an error warning label to the attribution result, prompting the user that the attribution value of the variable may have significant uncertainty.

[0104] S23. The actual contribution estimates of each input variable are aggregated and summarized according to the category dimension of the input variables to obtain the input variable-level attribution results; among which, the category dimension of the input variables includes the contracted electricity volume dimension, the electricity consumption deviation dimension, and the spot price dimension.

[0105] Specifically, the system iterates through all time periods within the evaluation period and estimates the actual contribution of the contracted electricity volume variable for each time period. Algebraic calculations and summations are performed to obtain the total contribution of contracted electricity consumption to the total profit and loss. The estimated actual contribution of the deviation of actual electricity consumption from the benchmark value for each time period is then calculated. By summing these values, we obtain the total contribution of the electricity consumption deviation dimension to the total profit and loss. This is used to estimate the actual contribution of the deviation of the spot price variable from the benchmark value in each time period. The summation yields the total contribution of the spot price dimension to the total profit and loss. The sum of the contributions from the three dimensions is numerically approximately equal to the change in the actual total profit and loss relative to the total profit and loss calculated under the benchmark scenario. The system integrates the total contribution of each dimension and the detailed contribution of each time period into an input variable-level attribution result. The technical advantage of generating input variable-level attribution results is that it can break down the change in total profit and loss into three dimensions with clear economic significance: contracted electricity volume, electricity consumption deviation, and spot price, helping traders grasp the main drivers of profit and loss from a macro perspective.

[0106] Example 5: Reference Figure 3 The steps for generating intermediate rule-level attribution results include:

[0107] S31. Extract the gradient values ​​of intermediate rule nodes from the gradient table; wherein, the intermediate rule nodes include deviation assessment cost nodes and auxiliary service apportionment cost nodes.

[0108] Specifically, the system iterates through the gradient table and filters out entries whose node type is marked as an intermediate rule node. This is done by time period. For example, extract the deviation assessment cost node. gradient value This gradient value represents the impact of each unit increase in the deviation assessment fee on the total profit or loss during that period. The resulting marginal impact. Extracting the ancillary service cost allocation node. gradient value This gradient value represents the marginal profit / loss impact of changes in ancillary service cost allocation during that period. Since the total profit / loss is defined as the savings relative to the baseline electricity purchase cost, the gradient values ​​at the above cost nodes are typically negative, indicating that an increase in costs will lead to a decrease in the electricity purchase cost savings.

[0109] S32. Extract the gradient values ​​of the regular parameter nodes from the gradient table; wherein, the regular parameter nodes include the deviation assessment threshold parameter node and the tiered price coefficient parameter node; the regular parameter nodes are the input nodes of the directed acyclic computation graph.

[0110] Specifically, rule parameter nodes are explicitly created as input nodes during computational graph construction, thus the backpropagation process naturally computes the gradients of these parameter nodes relative to the total profit and loss value. The system extracts the positive deviation exemption ratio parameter nodes. gradient value This gradient value represents the marginal impact of each absolute unit increase in the exemption ratio parameter on the total profit and loss. Extract the node for the positive deviation over-limit penalty coefficient. gradient value The gradient value represents the marginal impact of each unit increase in the penalty coefficient on the total profit and loss. The technical advantage of incorporating the rule parameters as differentiable input nodes into the computational graph is that it enables the system to quantitatively evaluate the sensitivity analysis of the rule parameters, a function that traditional profit and loss analysis methods cannot achieve.

[0111] S33. Trace the gradient propagation path of each intermediate rule node and identify the specific input variables and corresponding time periods that cause the changes in the values ​​of the intermediate rule nodes.

[0112] Specifically, by time period Positive deviation assessment cost node For example, starting from this node, the system traces its gradient propagation path backward along the directed edges of the computational graph. First, it locates the positive deviation electricity fee calculation node, whose input includes the electricity fee item corresponding to the positive deviation exemption threshold and the electricity fee item corresponding to the positive deviation assessment electricity volume. Continuing to trace backward along the source of the positive deviation assessment electricity volume, passing through the positive deviation assessment electricity volume calculation node, the positive deviation electricity volume calculation node, and the deviation electricity volume calculation node, it finally locates the original input variable: the time period. Actual electricity consumption nodes and time period Contracted electricity nodes .

[0113] When an intermediate rule node has multiple upstream propagation paths, the system iterates through the reverse directions of all incoming edges, tracing the source input variable and corresponding time period for each path. For each complete path obtained through tracing, the system calculates the contribution of that path to the total gradient of the intermediate rule node based on the gradient distribution ratio of each node on the path. For example, the time period... Contracted electricity nodes Simultaneously, the system influences the positive deviation assessment fee nodes through the deviation power path and the exemption threshold path. It calculates the gradient components propagating along both paths and allocates contribution percentages according to their proportion to the total gradient. The system also records the values ​​of each node along the path: the positive or negative direction of the deviation power, the positive or negative deviation power value, whether it exceeds the exemption threshold, and the power value exceeding the threshold.

[0114] Through this path tracing and contribution breakdown, the system accurately identifies the triggering period. The root cause of the positive deviation assessment fee is that the actual electricity consumption during the period exceeds the contracted electricity consumption, and the excess portion is greater than the exemption threshold. The system can determine the price range of the excess portion in the tiered assessment and quantify the contribution of the contracted electricity consumption variable to the assessment fee through the deviation electricity consumption path and the exemption threshold path. The system records the identified specific input variable identifiers, corresponding time period information, contribution ratio of each path, and key values ​​along the path in the attribution traceability data structure. The combined technical effect of tracing the gradient propagation path and performing path-level contribution decomposition is that it can further decompose the marginal contribution of intermediate rule nodes to the lowest level of original input variables and specific time periods, and clearly show the relative importance of the impact of the same input variable through different rule paths, achieving true "penetrating" attribution.

[0115] S34. Based on the gradient values ​​of intermediate rule nodes, the gradient values ​​of rule parameter nodes, the gradient propagation path, and the specific input variables and corresponding time periods, generate intermediate rule-level attribution results; wherein, the intermediate rule-level attribution results are used to quantify the marginal contribution of each specific settlement rule and its parameters to the total profit and loss value in different time periods, and identify the specific input variables that trigger the assessment of each rule and their period of action.

[0116] Specifically, the intermediate rule-level attribution results include a summary of marginal contributions categorized by rule: listing the cumulative marginal contribution amount of each settlement rule—positive deviation tiered assessment rule, negative deviation tiered assessment rule, FM ancillary service cost allocation rule, and standby ancillary service cost allocation rule—to the total profit and loss value within the assessment period. The conversion of the gradient value of the intermediate rule node to the actual contribution amount is accomplished using the following formula: [Formula omitted for brevity]. gradient value Multiply by the actual value calculated by the rule node during forward propagation. We obtain an estimate of the marginal contribution elasticity of the rule to the total profit and loss, and then determine the contribution amount by combining it with the actual triggering degree of the rule.

[0117] Intermediate rule-level attribution results can also include time-segmented contribution distribution data for each rule.

[0118] Intermediate rule-level attribution results can also include a detailed list of rule triggers, which clearly lists the specific time period number that triggered the punitive assessment, the deviation in electricity consumption during that time period, the amount of electricity consumption exceeding the exemption threshold, the corresponding penalty price coefficient, and the contribution percentage of the triggering event through each upstream path.

[0119] Intermediate rule-level attribution results also include a rule parameter sensitivity analysis table, showing the percentage impact of each percentage change in the deviation assessment threshold parameter and the tiered price coefficient parameter on the total profit and loss value. This percentage impact can be expressed through elasticity coefficients. The calculation shows that, among which Indicates input variables or rule parameters The elastic modulus, Total profit and loss. The gradient value, The actual value of the variable or parameter.

[0120] Intermediate rule-level attribution results can accurately answer penetrating attribution questions such as which rule caused the loss this month at which time, how much improvement would a relaxation of the deviation assessment threshold have on profitability, which type of ancillary service fee contributed the most, and which rule path the contract electricity volume change had the main impact on profit and loss.

[0121] Example 6: The profit and loss assessment method for medium- and long-term electricity transactions based on spot market rules proposed in this application also includes the following steps:

[0122] S41. For each historical settlement period, multiply the gradient value of each input variable by the deviation of the corresponding input variable from the preset benchmark value to obtain the contribution estimate of each input variable, and sum all the contribution estimates of the input variables to obtain the sum value of the contribution estimates of each input variable.

[0123] Specifically, taking a three-month monthly settlement cycle as historical backtesting data as an example, the system executes the complete processes described in Examples 1 to 5 for the first, second, and third months, respectively. For the... The system obtains the gradient values ​​of each input node for each month. and the deviation of each input variable from the preset baseline value for that month. The system calculates the contribution estimate of each input variable according to the formula described in S22 of Example 4, and then algebraically sums the contribution estimates of all input variables for all time periods in that month to obtain the first... The cumulative sum of the contributions of each input variable over the months is denoted as . .

[0124] S42. Based on the cumulative estimated contribution values ​​of each input variable and the actual total profit and loss value, calculate the attribution explanatory power (AEP) used to assess the reliability of the multi-level profit and loss attribution results; wherein, the formula for calculating the AEP is:

[0125]

[0126] in, This represents the total number of historical cycles. Indicates the degree of attribution explanation. Indicates the first The actual total profit and loss over a historical period express The average of the total actual profit and loss over a historical period Indicates the first Input variables in historical periods The deviation relative to the preset reference value Indicates the first Input variables in each historical settlement period gradient value, This represents the cumulative value of the estimated contributions of each input variable.

[0127] Specifically, This represents the total number of historical periods involved in the calculation, and in this embodiment, it is taken as a value of . This represents the attribution explanatory power, and its value typically ranges from... and Between them, the closer the values ​​are The stronger the explanatory power of the attribution model based on the gradient linear approximation, the better it can explain the actual fluctuations in historical profits and losses. When the denominator is zero, meaning the actual total profits and losses are exactly the same across all historical periods, the attribution explanatory power is directly defined as... This indicates that the attribution model can fully explain all profit and loss variations. Indicates the first The total profit and loss for each historical period is confirmed by the settlement documents of the power trading center. express The arithmetic mean of the total actual profit and loss over a historical period is calculated using the following formula: When different historical periods differ significantly in distance from the current time point, the system can use the exponentially weighted moving average method to calculate the weighted average, assigning a higher weight coefficient to recent periods to better reflect the attribution characteristics under current market conditions. Indicates the first Input variables in historical periods The deviation of the actual value from the preset reference value for that period. Indicates the first Input variables calculated during the backpropagation process of each historical settlement cycle The gradient value. Indicates the first The cumulative value of the contribution estimates of each input variable in the period, i.e., the attribution model's contribution to the period. The predicted value of the total change in profit and loss over a period of time. The numerator of the formula is the sum of squares of the residuals predicted by the attribution model, which reflects the profit and loss fluctuations that the attribution model fails to explain; the denominator is the sum of squares of the total fluctuations of the actual total profit and loss around its mean, which reflects the overall degree of variability in profit and loss itself.

[0128] S43. Add the attribution explanation to the profit and loss assessment results of medium- and long-term power transactions to update the profit and loss assessment results of medium- and long-term power transactions.

[0129] Specifically, the system will calculate the attribution explanatory power. As metadata, it is added to the multi-level profit and loss attribution results to form the updated profit and loss assessment results for medium- and long-term power transactions. On the terminal interface, the attribution explanatory power is presented numerically. The system presets a reference threshold of 0.8 for the attribution explanatory power. When the explanatory power value is greater than or equal to 0.8, it indicates that most of the profit and loss changes can be explained by the linear changes in the input variables, and the current attribution results have high reliability. Traders can directly adjust subsequent trading strategies accordingly. When the explanatory power value is between 0.6 and 0.8, it indicates that the nonlinear coupling effect of the settlement rules has a certain impact on profit and loss. The attribution results can be used as an important reference, but it is recommended to combine them with the trigger details and path tracing information in the intermediate rule-level attribution results for comprehensive judgment. Simultaneously, the piecewise linear approximation method described in Example 4 can be used to correct the contribution estimation of some large-deviation variables. When the explanatory power value is below 0.6, it indicates that nonlinear effects dominate. The system automatically prompts traders to reduce their reliance on macroscopic attribution values, focus on specific rule triggering situations and parameter sensitivity analysis, and suggests shortening the period granularity of attribution analysis to obtain a more accurate local linear approximation. By introducing attribution explanatory power indices and their associated threshold criteria and application guidelines, the reliability of profit and loss assessment results can be quantified, helping users to reasonably grasp the applicable boundaries of attribution analysis conclusions and adopt analysis strategies with appropriate precision based on the level of explanatory power.

[0130] The aforementioned method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules generates a structured sequence of computational tasks describing the process from raw data to profit and loss calculation by parsing the settlement rules of the electricity spot market. Based on this, a directed acyclic computational graph is constructed, starting from the raw input and ending with the total profit and loss value, transforming the complex settlement rules into a computable directed dependency network. On this basis, forward propagation is performed on the computational graph, calculating and storing the specific values ​​of each intermediate variable node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost. Subsequently, based on the values ​​of each intermediate node stored in the forward propagation, backward propagation with automatic differentiation in the reverse mode is performed on the same computational graph, precisely calculating the gradient of each variable relative to the total profit and loss value node by node along the reverse direction of the directed edges, forming a gradient table containing marginal contribution information of all nodes. Finally, based on the gradient values ​​of each node in the gradient table, multiple levels of attribution results covering the input variable level and the intermediate rule level are generated, which serve as the profit and loss assessment result for medium- and long-term electricity transactions. By organically combining automatic differentiation technology with the graphical modeling of electricity settlement rules, this method elevates the traditional coarse-grained price-volume dichotomy attribution to a refined marginal contribution analysis at the rule and variable levels. It can penetrate the superposition effect of multiple nonlinear coupled rules such as deviation assessment tiered pricing and ancillary service cost allocation, and accurately quantify the marginal impact of small changes in any input variable or intermediate rule parameter on the final profit and loss. This provides an interpretable quantitative decision-making basis for trading strategy optimization, risk warning, and rule sensitivity assessment.

[0131] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0132] Based on the same inventive concept, this application also provides a system for implementing the above-mentioned method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules. The solution provided by this system is similar to the solution described in the above method. Therefore, the specific limitations of one or more embodiments of the system for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules provided below can be found in the limitations of the method for assessing the profit and loss of medium- and long-term electricity transactions based on spot market rules described above, and will not be repeated here.

[0133] In one exemplary embodiment, such as Figure 4 As shown, a profit and loss assessment system 40 for medium- and long-term electricity transactions based on spot market rules is provided to implement the methods in the above-described method embodiments. The system includes:

[0134] The rule parsing and task generation module 41 is used to generate a structured calculation task sequence that describes the process from raw settlement data to total profit and loss calculation by parsing the settlement rules of the electricity spot market.

[0135] The computational graph construction module 42 is used to construct a directed acyclic computational graph that starts with the original input data and ends with the total profit and loss value, based on the structured computational task sequence. In this graph, the nodes represent computational variables, and the directed edges represent the computational dependencies between variables.

[0136] The forward propagation calculation module 43 is used to perform forward propagation on the directed acyclic computation graph, calculate the value of each node along the directed edge node by node, and obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the value of each intermediate node in the directed acyclic computation graph.

[0137] The reverse gradient calculation module 44 is used to calculate the gradient value of each node relative to the total profit and loss value in the reverse direction of the directed acyclic computation graph by performing backward propagation of automatic differentiation in the reverse mode on the directed acyclic computation graph based on the values ​​of each intermediate node in the directed acyclic computation graph, and obtain the gradient table.

[0138] The profit and loss attribution analysis module 45 is used to generate multi-level profit and loss attribution results based on the gradient values ​​of each node in the gradient table, and to use the multi-level profit and loss attribution results as the profit and loss assessment results for medium and long-term power transactions; wherein, the multi-level profit and loss attribution results include input variable level attribution results and intermediate rule level attribution results.

[0139] Embodiments of this application also provide a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the aforementioned method embodiments.

[0140] Embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps in the above-described method embodiments.

[0141] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The components described as separate parts may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this disclosure according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0142] The above-described embodiments are merely illustrative of several implementation methods of the embodiments of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the embodiments of this application, and these modifications and improvements all fall within the protection scope of the embodiments of this application.

Claims

1. A method for evaluating the profit and loss of medium- and long-term electricity transactions based on spot market rules, characterized in that, The method includes: S1. By parsing the settlement rules of the electricity spot market, generate a structured sequence of calculation tasks describing the process from raw settlement data to total profit and loss calculation; S2. Based on the structured computation task sequence, construct a directed acyclic computation graph that starts with the original input data and ends with the total profit and loss value; wherein, the nodes of the directed acyclic computation graph represent computation variables, and the directed edges of the directed acyclic computation graph represent computational dependencies between variables; S3. By performing forward propagation on the directed acyclic computation graph, the value of each node is calculated along the directed edge node by node to obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the value of each intermediate node in the directed acyclic computation graph. S4. Based on the values ​​of each intermediate node in the directed acyclic computation graph, by performing backward propagation of automatic differentiation in reverse mode on the directed acyclic computation graph, the gradient value of each node relative to the total profit and loss value is calculated node by node along the reverse direction of the directed edge to obtain the gradient table. S5. Based on the gradient values ​​of each node in the gradient table, generate multi-level profit and loss attribution results, and use the multi-level profit and loss attribution results as the profit and loss assessment results for medium- and long-term power transactions; wherein, the multi-level profit and loss attribution results include input variable-level attribution results and intermediate rule-level attribution results.

2. The method according to claim 1, characterized in that, The step of constructing a directed acyclic computation graph based on the structured computation task sequence, starting with the original input data and ending with the total profit / loss value, includes: S11. For each computation instruction in the structured computation task sequence, determine the operator type corresponding to the computation instruction by identifying the input and output variables of the computation instruction; S12. By creating computation nodes corresponding to the output variables, adding directed edges from the nodes corresponding to the input variables to the computation nodes, and associating the operator type with the corresponding computation nodes, an initial computation graph including input nodes, computation nodes, aggregation nodes and root nodes is constructed. S13. By performing topological sorting verification on the initial computation graph, the directed acyclic computation graph is obtained, ensuring that there are no directed cycles in the initial computation graph.

3. The method according to claim 2, characterized in that, The operator types include maximum value operator, minimum value operator, and conditional selection operator; The forward propagation of the directed acyclic computation graph includes: executing the defined forward computation logic on the maximum value operator, the minimum value operator, and the conditional selection operator respectively, and storing the computation results in the corresponding computation nodes; wherein, for the conditional selection operator, the forward propagation selects the true value branch node value or the false value branch node value as the output based on the Boolean value of the condition node, and stores the Boolean result of the condition judgment in the condition node; The backpropagation of automatic differentiation in reverse mode based on the values ​​of each intermediate node in the directed acyclic computation graph includes: executing defined backpropagation gradient propagation logic on the maximum value operator, the minimum value operator, and the conditional selection operator using the values ​​stored in the forward propagation of the corresponding computation nodes; when the same node is used as the input of multiple downstream nodes, the gradient of the node is the sum of the gradient components received from each downstream node; For the maximum value operator, the expression for the gradient assignment rule during backpropagation is: in, This represents the total profit or loss. This represents the input variable of the first input node of the maximum value operator. The input variable represents the second input node of the maximum value operator. This represents the output quantity of the output node of the maximum value operator. This represents the accumulated upstream gradient at the output node of the maximum value operator. and These represent the gradients passed to the first and second input nodes of the maximum value operator, respectively. The first indicator function takes the value of 1 when the stored value of the first input node of the maximum value operator is greater than the stored value of the second input node, and takes the value of 0 otherwise; when the stored value of the first input node of the maximum value operator is equal to the stored value of the second input node, the first input node and the second input node of the maximum value operator each obtain half of the upstream gradient; For the minimum operator, the expression for the gradient assignment rule during backpropagation is: in, This represents the input variable of the first input node of the minimum value operator. The input variable represents the second input node of the minimum value operator. This represents the output quantity of the output node of the minimum value operator. This represents the accumulated upstream gradient at the output node of the minimum operator. and These represent the gradients passed to the first and second input nodes of the minimum operator, respectively. The second indicator function takes the value of 1 when the stored value of the first input node of the minimum value operator is less than the stored value of the second input node, and takes the value of 0 otherwise; when the stored value of the first input node of the minimum value operator is equal to the stored value of the second input node, the first input node and the second input node of the minimum value operator each obtain half of the upstream gradient; For the conditional selection operator, the backpropagation passes the upstream gradient to the selected truth branch node or false branch node in the forward propagation based on the Boolean result stored in the conditional node, and the conditional node does not receive gradients.

4. The method according to claim 2, characterized in that, The steps for generating the input variable-level attribution results include: S21. Extract the gradient values ​​corresponding to all input nodes from the gradient table, and use the gradient values ​​as the marginal contribution of each input variable to the total profit and loss value. S22. For each input variable, multiply the marginal contribution by the deviation of the input variable from a preset benchmark value to obtain an estimate of the actual contribution of the input variable to the total profit and loss; wherein, the formula for calculating the actual contribution estimate is: in, Indicates input variables The estimated actual contribution to the total profit and loss. This represents the total profit or loss. This represents the input variables extracted from the gradient table. gradient value, Represents the input variable Deviation from the preset reference value; S23. The actual contribution estimates of each input variable are aggregated and summarized according to the category dimension of the input variables to obtain the input variable-level attribution results; wherein, the category dimension of the input variables includes the contracted electricity volume dimension, the electricity consumption deviation dimension, and the spot price dimension.

5. The method according to claim 1, characterized in that, The steps for generating the intermediate rule-level attribution results include: S31. Extract the gradient values ​​of intermediate rule nodes from the gradient table; wherein, the intermediate rule nodes include deviation assessment cost nodes and auxiliary service apportionment cost nodes; S32. Extract the gradient values ​​of the rule parameter nodes from the gradient table; wherein, the rule parameter nodes include deviation assessment threshold parameter nodes and tiered price coefficient parameter nodes; the rule parameter nodes are the input nodes of the directed acyclic computation graph; S33. Trace the gradient propagation path of each intermediate rule node and identify the specific input variables and corresponding time periods that cause the value changes of the intermediate rule nodes; S34. Based on the gradient values ​​of the intermediate rule nodes, the gradient values ​​of the rule parameter nodes, the gradient propagation path, and the specific input variables and corresponding time periods, generate the intermediate rule-level attribution results; wherein, the intermediate rule-level attribution results are used to quantify the marginal contribution of each specific settlement rule and its parameters to the total profit and loss value in different time periods, and to identify the specific input variables that trigger the assessment of each rule and their period of action.

6. The method according to claim 2, characterized in that, The method further includes: S41. For each historical settlement period, the gradient value of each input variable is multiplied by the deviation of the corresponding input variable relative to the preset benchmark value to obtain the contribution estimate of each input variable, and all the contribution estimates of the input variables are accumulated to obtain the accumulated value of the contribution estimates of each input variable. S42. Based on the cumulative value of the estimated contributions of each input variable and the actual total profit and loss, calculate the attribution explanatory power used to evaluate the credibility of the multi-level profit and loss attribution results; wherein, the formula for calculating the attribution explanatory power is: in, This represents the total number of historical cycles. This indicates the attribution explanatory power. Indicates the first The actual total profit and loss for each historical period. express The average of the total actual profit and loss over a historical period. Indicates the first Input variables in historical periods The deviation relative to the preset reference value Indicates the first Input variables in each historical settlement period gradient value, This represents the cumulative value of the contribution estimates of each of the input variables; S43. Add the attribution explanatory power to the profit and loss assessment results of the medium- and long-term power transactions to update the profit and loss assessment results of the medium- and long-term power transactions.

7. A profit and loss assessment system for medium- and long-term electricity transactions oriented towards spot market rules, used to implement the method according to any one of claims 1 to 6, characterized in that, The system includes: The rule parsing and task generation module is used to generate a structured sequence of calculation tasks that describe the process from raw settlement data to total profit and loss calculation by parsing the settlement rules of the electricity spot market. The computational graph construction module is used to construct a directed acyclic computational graph starting from the original input data and ending at the total profit and loss value, based on the structured computational task sequence; wherein, the nodes of the directed acyclic computational graph represent computational variables, and the directed edges of the computational graph represent computational dependencies between variables; The forward propagation calculation module is used to perform forward propagation on the directed acyclic computation graph, calculate the value of each node along the directed edge node by node, and obtain the total profit and loss value relative to the benchmark electricity purchase cost for the evaluation period and the value of each intermediate node in the directed acyclic computation graph. The reverse gradient calculation module is used to calculate the gradient value of each node relative to the total profit and loss value along the reverse direction of the directed edge by performing backward propagation of automatic differentiation in the reverse mode on the directed acyclic computation graph based on the values ​​of each intermediate node in the directed acyclic computation graph, thereby obtaining a gradient table. The profit and loss attribution analysis module is used to generate multi-level profit and loss attribution results based on the gradient values ​​of each node in the gradient table, and to use the multi-level profit and loss attribution results as the profit and loss assessment results for medium and long-term power transactions; wherein, the multi-level profit and loss attribution results include input variable level attribution results and intermediate rule level attribution results.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 6.