Local flexibility market framework for grid support services to distribution networks

The increasing volume of distributed resources and user-dependent loads in local networks has increased the concern for congestion and voltage management in distribution networks. To mitigate these issues, the implementation of local flexibility markets has been proposed to assist distribution system operators (DSOs) to manage their networks efficiently. This paper presents the framework of a local flexibility market, including the market participants and their roles. This framework aims to empower DSOs with a market-based instrument for the alleviation of congestion incidents by exploiting the flexibility of local resources. The proposed market aims to provide a tool for the holistic management of distribution networks by trading both reservation and activation of flexibility services, indifferent of the type and the timeline of the needed service. Three market modes are proposed, i.e., long-term, short-term and real-time market, and the interactions among those modes are shown. The operation of the market is explained in detail, including the identification of the needed services, the activation of the market as well as the proposed bidding, clearing and settlement mechanisms. The modelling of the long-term and real-time markets is also presented, along with some indicative simulation results for long-term and real-time services. Finally, the future developments as well as the major conclusions are discussed.


Introduction
The need for energy transition has led to increased penetration of distributed energy resources (DERs) in distribution networks. The increased local electricity production has many advantages such as lower operational costs, reduced transmission losses and smaller environmental footprint, since it is mostly renewable-based production. However, it is associated with increasing operational problems in distribution networks. The bi-directional power flow associated with the operation of DERs and the non-dispatchability of renewable energy sources (RES), such as solar PVs and wind turbines, are expected to cause congestions and voltage deviations in future distribution networks. This situation is deteriorated by the increased penetration of user-dependent loads, such as electric vehicles (EVs) and heat pumps (HPs) [1]. Congestion generally refers to the power flow that exceeds the network's transfer capacity, mostly regarding line and transformer ratings, while voltage deviation is linked with voltage magnitudes beyond bounded limits [2]. Currently, the forecasted and emerging congestions in distribution networks are primarily managed by DSOs through grid reinforcement. DSOs conservatively increase the capacity of the power lines, feeders and transformers existing in their networks; when a congestion or voltage problem is anticipated in an area, the capacity of the respective element is passively increased to cover the predicted scenario. However, this approach is generally expected to result in increased costs for DSOs [3]. An approach to mitigate congestion problems in distribution networks would be to mimic the methods that are traditionally used by transmission system operators (TSOs) to deal with congestions that occur in transmission systems, such as optimal power flow-based methods, price area congestion methods and transactionbased methods. However, these methods may not lead to effective congestion relief in distribution networks, as dispatching is more complex in distribution than in transmission, due to the high penetration of small-scale distributed generators with volatile output [4].
A more active way to manage congestion problems in distribution networks is by using the flexibility that is available on the end-user side. The definition of flexibility and its concept and utilization vary according to the perspective of the entity to which it is referred (power system, system operators, balance responsible parties (BRPs), aggregators, end users, etc.). From a power system perspective, the flexibility of supply is defined as the ability of a power system to maintain continuous service in the face of rapid and large swings in supply [5]. From a market perspective, the flexibility of power markets is characterized by their ability to efficiently cover fluctuating demand [5]. Finally, from an endusers' perspective, demand-side flexibility can be defined as the modification of generation and/or consumption patterns in reaction to an external signal (e.g., price signal or activation) in order to provide services to the system operator [6]. Therefore, it is important to consider all the different approaches when a framework for a flexibility exploitation mechanism is designed, so that the traded products can meet the expectations of all involved participants.
Several methods have been proposed to incentivize and utilize the available flexibility that exists in distribution systems for congestion management, such as dynamic tariffs (e.g., time of use, reduced tariffs combined with use restrictions, critical peak pricing, etc.) [7], or grid reconfiguration. However, the implementation of local markets that trade flexibility from the end users to system operators seems to be one of the most promising solutions to tackle congestion problems. Local flexibility markets (LFMs) can be defined as marketplaces that operate on geographically limited areas and in which flexibility is traded from flexibility suppliers (end users) to flexibility users (DSOs, TSOs, BRPs, etc.) [8]. It is expected that a marketplace with clearly defined rules and widely approved trading procedures will increase the awareness of all parties concerning flexibility use, leading to its more adequate utilization in future energy systems. However, there are significant regulatory and operational issues that should be addressed so that the large-scale implementation of LFMs in real-life applications is feasible (e.g., existing regulations, system operator role, end-user participation, etc.) [9]. In recent years, there have been several research [10][11][12][13][14][15] and commercial [16][17][18] approaches on LFMs. These approaches differ on the scope (i.e., avoid costly grid reinforcement, provide robust short-term and real-time management of distribution networks, provide frequency and balancing services, etc.) and the timeline of flexibility exploitation (i.e., long-term, short-term or real-time services). Even though the exploitation of locally available flexibility has gained interest recently, there are not many approaches that directly target the alleviation of congestion and voltage issues in distribution level. Some LFMs proposed in international literature target the implementation of LFM as an extra tool for the formation of local energy communities (LECs), scheduling the operation of the LFM on top of a local energy market [13,14]. Furthermore, each of the proposed LFMs focuses on a different operating timeline in order to provide different kind of services to the DSOs. For example, the LFM proposed in [4] focuses on the provision of long-term services by the flexibility providers to the DSOs in order to provide an alternative to costly grid reinforcement. The LFMs proposed in [13], and [15] focus on closer to real-time operating horizons targeting the efficient management of the distribution network and the management of imbalances, respectively. Therefore, it is important to conceptualize a LFM structure that focuses on facilitating the DSOs to manage their networks efficiently through the procurement of both activation and reservation of flexibility in different time horizons irrespective of the timeline of the needed services and the nature of the anticipated issues. In this paper, the framework and the initial model of the LFM that has been developed within the H2020 project UNITED-GRID [19] are presented, along with some illustrative results regarding the operation of the proposed structure. The operation of the market and the respective mechanisms used for opening, auctioning, clearing and settlement of the market are presented, while the interaction among the different market timelines is also explained. The proposed LFM aims to provide DSOs with a market-based instrument for the efficient management of their network, indifferent of the origin and the attributes of the congestion problems, as well as the different objectives of the participating market players. In the proposed LFM framework, the market players can trade both reservation and activation of flexibility. Based on the outcome of the market operation, DSOs can investigate the possibility of avoiding grid reinforcement through the reservation of the required flexibility via the long-term market structure. In addition, DSOs can reserve more flexibility via the short-term market (i.e., for the day ahead), in case that the forecasting mechanisms detect that more flexibility may be needed. Finally, DSOs can procure the necessary activation of flexibility to cater the congestion incidents closer to real time, while exploiting the flexibility capacity that has been reserved by the long-term market. Hence, the main novelty of the proposed LFM framework is the envision of the different market modes and the interaction among them to facilitate the reservation and activation of flexibility. This way, the proposed LFM provides a market-based instrument to the DSOs to avoid the grid reinforcement cost in the long term, while ensuring the secure operation of the distribution system closer to real time. The main contributions of this paper are: 1 3 • The development of a LFM framework that can mitigate congestion issues in different time horizons. In the proposed market framework, both reservation and activation of flexibility can be traded. More specifically, in the proposed LFM framework, a long-term market mode is envisioned that will trade the reservation of flexibility for the coming months or years to avoid grid reinforcement, while providing the rules for the activation of the reserved flexibility closer to the event, if necessary. Furthermore, a short-term market mode is proposed for the day-ahead management of distribution networks that will also trade reservation and possible activation of flexibility services. Finally, a real-time market mode is proposed that will trade the activation of flexibility to alleviate real-time congestions and emergency problems. This novel approach provides the DSOs with the necessary market-based tools to mitigate congestion incidents and effectively manage their networks in different time horizons; • The detailed explanation of the different stages of the market operation (i.e., opening, auctioning, clearing and settlement of the market) for the different market modes; • The provision of the initial models of the long-term and real-time market modes of the proposed LFM framework, along with the initial simulation results that indicate the feasibility of the proposed framework to result in flexibility exploitation and in mitigation of congestion incidents in distribution networks. For the construction of the real-time flexibility supply bids, data from smart buildings with different assets (i.e., solar PVs, batteries, HPs) located on the premises of Chalmers University of Technology in Gothenburg, Sweden have been used.
The remaining of this paper is as follows: In Sect. 2, the proposed market framework is presented, including the market participants and their roles as well as the proposed market timelines along with their objectives and interaction. In Sect. 3, the operation of the proposed market is explained, while in Sect. 4 the modelling of the different market modes is presented. In Sect. 5, the initial simulation results of the proposed market framework are included. Finally, in Sect. 6 the major conclusion of this work as well as the envisioned future developments of the proposed LFM are discussed.

Proposed LFM framework
In this section, the LFM framework is presented. The participants of the market and their roles are explained, while the different timelines and the interaction among them are illustrated. The proposed LFM is event driven; when a congestion incident emerges, or when it is forecasted, the suitable market mode is activated. Therefore, the proposed market model should be coupled with a mechanism that can forecast congestions in different horizons. Hence, the market model should be designed to mitigate as much as possible the inherent inaccuracy of the forecasting tools, especially in the longer time horizons.

Motivation
Due to the increasing penetration of RES and unpredictable loads in distribution grids, more congestion and voltagerelated issues appear with an incremental frequency and severity. Therefore, DSOs should be prepared for this future challenge, as their tasks are evolving from long-term planning to including also short-term and real-time grid operation [12]. For this reason, within the UNITED-GRID project, the framework of a LFM has been developed, targeting the efficient employment of demand-side flexibility through a dedicated marketplace, which will provide DSOs with suitable mechanisms to alleviate these phenomena.

Market participants
In the proposed LFM framework, the following entities can participate: a) The local DSO which is responsible for identifying the need for flexibility services as well as for passing the signal for the activation of the market along with the request for the necessary service to the market operator. The flexibility provided by the flexibility suppliers will be a modification in active or reactive power consumption or generation. The procured flexibility could be used to alleviate different issues, e.g., voltage limit violations, overloading of components or to reduce peaks/ losses. b) The LFM Operator (LFMO) The LFMO is the entity that manages the operation of the most important aspects of the LFM, such as bidding, clearing and settlement of the market. The LFMO could be the DSO, a DSO-oriented entity or an independent entity, according to the existing regulatory framework. In the economics literature, it is often suggested that the market operator should be an independent, neutral third party. More specifically, Eurpex directly recommends that the LFMs should be operated by independent third parties, who are not themselves active on the market, in order to avoid any risk of conflict of interest and ensure non-discriminatory access for all market participants [20]. Therefore, the LFMO should not be an aggregator that participates in the LFM. This would imply that this aggregator would have had an unfair advantage comparing to other aggregators participating in the same LFM. The LFMO is important for the efficient management and it could only be omitted 1 3 in case that the DSO directly manages the market. In the proposed framework, the LFMO is responsible for: i) activation of the market; ii) conducting the auctions (broadcast DSO's request for flexibility and gather the bids from the interested suppliers); iii) clearing of the market; iv) contracts between the DSO and the winning bidders; and v) settlement. c) Aggregators representing: i) prosumers; ii) households with flexible loads; iii) EVs; iv) building and storage owners; and v) local DER owners. The aggregators are responsible for gathering and managing their portfolios' flexibility, as well as for representing them in the LFM by bidding in response to the requests of the DSO. The participating aggregators should have good understanding of the local market mechanisms as well as the ability to adequately determine the price of the flexibility services that will be provided by their associated resources. Finally, they are also responsible for representing their portfolio in the settlement phase of the market; they will be paid by the DSO through the LFMO for the provided services, and then, they will be responsible to allocate these financial benefits among their resources according to their participation in the respective service.

Market timelines
In the proposed LFM, three different modes regarding timing are proposed, so that the DSO is equipped with a tool to mitigate congestions in different time resolutions. The different market modes and their most significant characteristics are: a) Long-term market This market mode is responsible for services forecasted long time in advance and needed for a specific period (e.g., the next year, a specific month, etc.). In this mode, the reservation of flexibility is traded so that the DSO can procure the adequate capacity of flexibility in areas with anticipated problems, while paying a reservation fee. Services can be activated, when needed, closer to real time. Then, the DSO will pay an activation fee. A maximum price cap for the activation fee could be agreed on the long-term market, while the actual fee will be determined in the real-time market. In the long-term market, the possibility of multiple activations within the specified period is included. This market is open from when a need for a long-term service is forecasted until a certain time (e.g., one or several months depending on the traded service and the risk assessment of the DSO) before the date of the first possible activation. Closer to the delivery time, the DSO could activate the reserved flexibility by sending a request to the cleared aggregators that the reserved flexibility should be available in the real-time market, with, e.g., the predefined maximum price cap. By including both the reservation and activation price in the long-term market, the DSO knows what the maximum cost for the requested flexibility needed to solve potential congestions would be. This market mode provides an alternative to grid reinforcement, while long-term contracts would encourage customer participation, hence enhancing market liquidity. The details about the proposed long-term market operation can be found in Sect. 3. b) Short-term market This market mode is responsible for services forecasted for the following day that cannot be catered by long-term contracts, due to forecasting errors related to the anticipated inaccuracy of the used congestion forecasting mechanisms on the long term, the possible underestimation of the potential congestion by the DSOs or the emerge of a congestion issue that has not been previously predicted (e.g., transformer maintenance, larger EV penetration or larger PV production than anticipated, etc.). The short-term market is open for specific hours of the previous day (e.g., until 12:00 of the previous day), where the DSO can procure flexibility reservation for the next day. In the short-term market, both reservation and activation of aggregators' flexibility will be traded in a similar way to the long-term market. c) Real-time market This market mode is responsible for the activation of the services for the following time period (e.g., 1 h), including the activation of the capacity reserved in the long-term or short-term market modes as well as the flexibility that is required to cater emergencies that have not been forecasted and cannot be catered by the reserved capacity. The time resolution of this market mode is 15 min. After the respective real-time market is cleared, the DSO can either take direct control of the resources, or utilize the accepted resources according to its needs for the next time step (15 min) by submitting dispatch signals to the respective aggregators, which will then be responsible to follow that schedule and define which resources of their portfolio will provide the required service. Since in real-time grid reinforcement is not an option, DSOs provide a price curve for the respective service, while the aggregators provide their price curves regarding the flexibility that they can offer in response to the DSOs request. Thus, in the real-time market the DSO is willing to pay more to activate as much flexibility as possible to cater the emerging incident. The interaction among different market modes is shown in Fig. 1.

3 3 Proposed market operation: how the market works
The proposed LFM is event driven according to the traffic light concept [7,21]. It is assumed that the DSO constantly forecasts its future state through a congestion forecasting mechanism, and when a problem is detected (amber phase), it sends a signal to the LFMO for the activation of the market. When no problem is detected (green phase), the market is idle. In emergency cases, and when no solution can be provided by the operation of the market (red phase), the DSO takes direct control of the resources to manage its network. When a service need is forecasted, the DSO sends a signal to the LFMO that activates the suitable market mode (i.e., long term, short term or real time). Then, the LFMO is responsible for the required auction. The request of the DSO is published in open orderbooks accessible to all aggregators participating in the respective area, where the interested aggregators can place their bids.
The request of the DSO should include information about the type, location, volume, duration and pricing of the service. The bidding and clearing procedures are slightly different in the different market modes. However, the binding characteristic is that in all situations the DSO is the only buyer of flexibility while the bidding aggregators are multiple flexibility providers. Therefore, in the proposed market framework no TSO-DSO coordination schemes are studied or proposed. However, although the TSO is not directly included in the LFM, aggregators can still decide if they want to participate in the LFM or in the respective TSO ancillary services market. Hence, the price in the LFM would partially reflect the anticipated TSO ancillary service prices. Future expansion of the LFM could include the possibility of multiple flexibility buyers on the demand side (e.g., TSO, BRPs, other aggregators, etc.). After the auctions, the feasibility of the selected bids should be verified. For example, the selected bids could be fed back to the used congestion forecasting mechanism, so that the possibility of future congestion or voltage problems ought to their employment can be checked. The general operation of the market is illustrated in Fig. 2.

Required service identification
The identification of the needed service is derived by a congestion forecasting mechanism linked to the DSO operation.
The output of such a tool can be used for the identification of the DSO need for flexibility concerning the following parameters: • Probability of a specific incident to happen; • Estimated type of the forecasted incident (i.e., congestion, voltage issue); • Estimated severity of the incident (i.e., x kW, y V, etc.); • Estimated location of the incident; • The element of the network that the incident is anticipated (i.e., line, transformer, node); • Estimated timeline of the incident (i.e., long term, short term, real time); • Estimated time and duration of the incident; • Accuracy of the forecast. Generally, the longer the forecast window is, the lower the accuracy will be, as the generation and load forecast required for the congestion forecast are not highly accurate in the long term. For this reason, in the proposed LFM framework, the long-term market mode trades the reservation of flexibility and not its activation. In this way, the DSO can ensure that the required amount of flexibility has been reserved in the long-term market, while the short-term and the real-time market modes are available to correct potential underestimation of the future conditions by the congestion forecast mechanism. In this way, the unavoidable forecast inaccuracy is mitigated. It is considered that the accuracy of the congestion forecast mechanism in real-time or close to real-time events is satisfyingly high.
Then, the DSO can assess the output of the forecasting mechanism and decide whether to initiate the procedure for the activation of the market or not. This decision should be based on the probability of the incident to happen as well as its anticipated severity. However, the final decision of the type and the requested volume of flexibility will be a function of several other parameters, such as the risk level of the DSO, the market participants that are operational on the area of the incident, the anticipated cost for the DSO etc.

DSO service request and market activation
After the identification of the need for service, the DSO passes the activation signal to the LFMO that in the next step will be responsible for broadcasting the service request to all participating aggregators by opening a specific orderbook. Before that, the DSO should evaluate the forecasted situation and decide on the volume of the required flexibility, the location in which the flexibility is needed, as well as the duration and the maximum price of the service. It is noted that the details of the operation of the short-term market mode, as well as the respective model and simulations tests, will be studied in future expansions of the proposed LFM. In the real-time market mode, the DSO provides a price curve, while the reservation of flexibility is not traded. The maximum allowable activation price of the long-term services will serve as the maximum cap for the activation of the reserved capacity closer to the incident, if necessary, through the real-time market. The market activation signal should include information about the service type (e.g., congestion relief), service timeline (e.g., long-term), price (i.e., activation and/or reservation fees), location (e.g., area and element), duration and other specifications such as the maximum times of activation and the possible activation window. A typical template regarding the DSO request that can be delivered to LFMO is shown in Table 1, while an example of a real-time service request that the DSO passes to the LFMO is presented in Table 2.
It should be noted that the volume of the DSO requests could generally be different from the forecasted congestion volume. The reasons behind that could be the different risk level of the DSO, the possible flexibility that has been already reserved as well as the accuracy and the possibility that has been predicted by the congestion forecasting mechanism. An example of a long-term service request from the DSO is presented in Table 3. It is assumed that the congestion forecasting mechanism has provided a forecast for a long-term service need (i.e., the whole August) at an area of the distribution grid (i.e., an overload of a transformer) due to the expected increased penetration of RES and/or EVs in the coming period. In such a case, the provided service request from the DSO to the LFMO will be shown in Table 3. In that case, the clearing will be performed considering both reservation and activation prices of the aggregators bids, while also considering the maximum activation and reservation prices defined by the DSO (i.e., 1.5 €/kWh and 10 €/kWh, respectively). More information about the clearing of the long-term market is cited in Sect. 3.5.
From the comparison of the real-time and long-term service request, it is evident that there are some substantial differences between the different market modes especially regarding the pricing and the activation/reservation procedure. However, the general idea remains the same, as the DSO must identify, assess and publish its need to the market operator, which is then responsible to broadcast the requests to the interested aggregators through the opening of the respective orderbook.

Service orderbook opening
After receiving the signal from the DSO, the LFMO activates the respective market mode by notifying every participating aggregator in the area of interest about the specific request of the DSO. The LFMO opens a new orderbook in which the DSO service request is placed. This orderbook should be broadcasted through a dedicated template that will clearly communicate the needed flexibility service, so that every participant understands the basic points of the request. A typical suggested orderbook template is presented in Table 4.
Comparing the request that the LFMO receives and the published orderbook the main differences are: • There is no specification regarding the type of issue in the DSO network (i.e., overload, overvoltage, etc.); • The requested volume of flexibility is not disclosed to the aggregators; • The maximum price that the DSO is willing to pay for the required service is not provided to the aggregators; • The time instant of the orderbook opening as well as the time of the market closure are broadcasted to the aggregators.
The first three alterations aim to protect the DSO as well as the LFM from malicious events such as market power incidents. Even though the phenomenon of market manipulation is not particularly studied in the current work, it is assumed that considering some sensitive information of the DSO as confidential until the clearing of the market (i.e., the type of issue in the DSO network, the volume of flexibility requested by the DSO, and the DSO pricing of the event) is the first step towards reducing the risk of gaming and malicious behavior of the market players. Furthermore,   it can generally be assumed that the possibility of market manipulation decreases when the number of the participants increases. The number of the participants that is required to avoid market power incidents will be the scope of future work. In addition, the implementation of the LFM in a larger geographical area might help towards increasing its liquidity. Having a higher liquidity can help having a more diverse set of prices offered by the flexibility providers, hence mitigating malicious and gaming opportunities. Moreover, it is important that the market design is incentive compatible (i.e., participants bid with their true cost). This can be achieved in liquid markets or through the Vickery-Clark-Groves method [22][23][24] for settlement of the market which will be the scope of future work. Furthermore, curve-bidding (multiple-bidding) in the real-time market mode can help including the preferences of the participants and reducing the chance of such situations. Nevertheless, a complete and functional market should have carefully defined rules that incentivize all participants to bid according to their actual cost and benefits in the market; the market should be designed in a way that the participants will not gain any benefit by falsely bidding in the market. The definition of the methods to achieve that in the proposed LFM will be the scope of future work. The latter difference is imposed to increase the transparency of the market. An illustrative orderbook opening that broadcasts the DSO request to the aggregators regarding the long-term example presented in Table 3 is shown in Table 5.

Aggregators bids
After the DSO request has been broadcasted to all aggregators, the interested aggregators are able to submit their bids in response to that request. For transparency reasons, all bids should be stored in the dedicated orderbook, along with all their necessary information (volume, price, time of submission, location, etc.). The individual aggregator bids will not be disclosed to the other aggregators for confidentiality reasons. A uniform template can be used for the aggregator bids as presented in Table 6. All aggregator bids referring to a specific DSO request ID are stored in the respective orderbook by the market operator. When the market is closed, the market operator is responsible for evaluating the bids and proceed to the market clearing. It is noted that in the real-time market the aggregators should submit only their activation prices.
Let's assume that for the long-term example illustrated in Table 5, there are three interested aggregators that offer their   flexibility. Then, the respective orderbook at the time instant of the market closure would be similar to the one presented in Table 7. Note that for the long-term services, the aggregators should bid both their activation and the reservation prices.
After the deadline of the market closure, the LFMO is responsible for the assessment of the bids and the clearing of the market.

Auctions and market clearing
The general approach of the market clearing is based on the fact that the DSO is the only flexibility buyer. However, there are some differences between the long term and the real time derived by the inherent differences of the DSO needs in the different time horizons. In the long term, the DSO tries to investigate the available amount of flexibility in the location of interest, so that the necessity of grid reinforcement can be evaluated, while in the real time the DSO is willing to get as much flexibility as possible up to the amount that it is still valuable for it in order to address the upcoming incident and maintain the stability of the system. Generally, when the market closes, the LFMO goes through the specific orderbook and checks the eligibility of the bids (e.g., if the bids are applicable in the area of interest, if all the fields have been adequately filled, etc.). Afterwards, the LFMO places the bids in ascending order from the cheapest to the most expensive. The distinction between the long-term and the real-time market in terms of clearing can be mostly defined in the following parameters: • In the long-term market, both activation and reservation costs should be considered, while in the real-time market there is only the cost related to the service activation. Thus, a way should be defined so that both activation and reservation prices are incorporated into the clearing mechanism. In the developed framework, the clearing of the long-term market is based on a single price. The DSO should define some weighting factors to the LFMO regarding the activation and the reservation price of the bids. Then a single price is calculated according to which the single-sided auction is performed: where p R i is the reservation price of the ith aggregator, p A i is the activation price of the ith aggregator, p Agg i is the weighted price of the ith aggregator and a , b are the reservation and activation weighting factors, respectively. For example, let's assume that a = 0.8 and b = 0.2 and that an aggregator bids with 10 €/kWh as activation price and 1 €/ kWh as reservation price; hence, the weighted price for this aggregator will be 0.8*1 + 0.2*10 = 2.8 €/kWh. Despite that the market can be cleared by using the weighted price for each aggregator, there is still the need to conclude on the reservation price and the maximum allowable activation price. In the proposed framework, a pay as bid approach is followed for the reservation price of the long-term services; the winning aggregators are reimbursed according to their submitted reservation prices. Furthermore, the submitted activation price of the winning aggregators is stored and used as an input for the real-time market, if the activation of the reserved flexibility is needed. In that case, the submitted activation price in the long term will serve as the maximum cap for the aggregators in the real-time market; the aggregators that have been cleared in the long-term market should bid in the realtime market for the activation of the reserved flexibility at a price equal or lower than the activation price that they have submitted in the long-term market. The aggregators that have won in the long-term market (meaning that their flexibility has been reserved for the possible future congestion incident) are obliged to bid in the real-time market for the same event, if it is necessary. If they do not bid in the real-time market or if the volume they bid is lower than the volume that has been reserved in the long-term market, a penalty will be imposed in the settlement phase. In this way the uncertainty regarding the availability of flexibility in the real time is mitigated.
• In the long-term market, there is no elasticity on the demand side (i.e., the DSO) as the DSO should determine whether the available flexibility capacity is adequate to securely manage the system in the long-term or reinforce it. Therefore, from the DSO side only the maximum allowable price and the required volume is necessary, and a single-sided auction can be performed, similarly to [4]. On the contrary, for real-time events the DSO is willing to pay more to buy the necessary flexibility up to the point that the congestion can be mitigated. Therefore, the DSO provides a demand curve to the market operator. In addition, the aggregators bid similar curves, which represent their available flexibility. The market is then cleared based on the intersection point of those curves. • The real-time market is cleared with a 15-min resolution. If a real-time event is larger than 15 min, the DSO should activate the market multiple times to address the event.
In the current market model, it is assumed that the DSO puts suitable requests resulting in optimal flexibility exchange for both the demand and the supply side.
The selected bids should be sent back to a congestion forecast mechanism to check the probability of causing other congestion incidents derived by their employment. After the feasibility check, the market is cleared, and the winning aggregators are informed. The winning bids are then written in the specific orderbook along with the cleared activation and/or reservation price, depending on the market mode, for transparency reasons. For confidentiality reasons, the orderbook should not be publicly accessible until the end of the service provision, so that possible malicious actions from competitors are avoided. In addition, after the settlement phase, details about the aggregators that bided to the specific DSO request will not be revealed. Nevertheless, the clearing status of the specific DSO request (cleared/not cleared), the cleared volume as well as the cleared reservation and/ or activation prices of each aggregator along with the possible penalties of undelivered activation should be included in the published orderbook. Table 8 presents an example of a typical orderbook containing the information related to market clearing, while Table 9 presents a possible specific  closed orderbook based on the market example presented in Table 7.

Market settlement
After the finalization of the service provision, the necessary settlement of the service is implemented, for which the LFMO is responsible. The settlement phase of the market and the related penalties for possible non-deliveries or deliveries of lower volume of flexibility mitigate the uncertainty about the responsiveness of the aggregators; the aggregators are aware that since they participate in the market they are obliged to deliver the cleared volume of flexibility, otherwise they must pay the respective penalty which is determined by the market rules. Therefore, the reliability of the proposed LFM framework increases; the DSOs can consider that the agreed flexibility will be available when they need it, according to the clearing of the market. The settlement is similar for all market modes and it should combine both reservation and activation reimbursement, where applicable. Since a pay as bid approach is followed for the flexibility reservation, the settlement will be customized for each aggregator according to their submitted reservation and their cleared activation price. For the long-term and short-term market, the part of the reservation settlement will be decided according to the respective auction and it will be calculated by: where c res i is the reservation settlement price for the ith aggregator, p Ri is the submitted reservation price of the ith aggregator and P res i is the reserved volume of the ith aggregator.
The activation settlement should consider the actual activation of resources' flexibility, e.g., the deviation of their operation from a predefined schedule. Since the activation is decided closer to real time, the settlement of the activation should be done according to a schedule of aggregator's portfolio that should be submitted to the DSO the previous day (e.g., 12:00 the day before the service). This should be the procedure for all aggregators that are willing to participate in the short-term and real-time market modes, even if the respective incident has not been auctioned yet, e.g., to be able to participate in the real-time market, a schedule of the planned resources must be submitted. In addition, all aggregators that have been cleared in long-term services that may be activated through the real-time market, should also submit this baseline schedule. Then, the activation settlement should be assessed based on the scheduled baseline and the deviations from that for service provision purposes. This approach implies that adequate measurement devices are installed on the resources, so that their power profile is accurately measured. In case that the measured flexibility (2) c res i = p Ri * P res i volume (i.e., deviation from the baseline) is different from the one cleared, the aggregator will have to pay a predefined penalty. Therefore, the activation settlement will be calculated by: where c act i is the activation settlement price for the ith aggregator, p A is the activation price of the real-time market, p pen is the penalty price, P cleared i is the flexibility volume of the ith aggregator that has been cleared in the real-time market and P meas i is the measured flexibility provided by the ith aggregator.
Thus, the total settlement price in which the ith aggregator will be reimbursed for its service would be given by:

Market modelling
In this section the modelling of the proposed LFM is presented. Two different market modes have been designed: i) long-term; and ii) real-time market. The modelling of the short-term market mode will be the scope of future work.

Long-term market
For the long-term market, both reservation and activation prices have been considered. The market clearing is performed based on the weighted price of the activation and reservation prices of the aggregators' bids according to (1).
To explain the mathematical formulation of the market clearing, the location and time-related attributes of the bids are excluded, as they are not involved in the mathematical calculations of the market clearing. In other words, the clearing is explained for a specific time window and a location, and this formulation is applicable in the clearing of each bid set with similar location and time window. Excluding the abovementioned attributes, the supply bids ( B s ) and the demand bids ( B d ) consist of a reservation price ( R ), an activation price ( A ) and a quantity ( q ). Since the market is a single-sided auction, the bids on the demand side consist of only one set (Eq. (5)) while the supply side consists of a set of bids from the supplier set S (Eq. (6)).
From the reservation and activation price, a total price is formed according to (7).
The market is solved by maximizing the social welfare which is the consumers' benefit minus the sum of the value for the cleared supply bids (i.e., suppliers' cost) (Eq. (8)). It should be noted that practically in such LFM structure, a tradeoff between the benefits of all stakeholders (i.e., the DSOs and the aggregators) should be considered. However, the proposed LFM has been built as closely as possible to strict market terms. In addition, the optimization of the social welfare implies that there is a trade-off among the benefits of all stakeholders. The optimization problem can be reformulated in (9) where the minimization variable is y which is the amount of cleared power for each bid. The cleared power quantity should be positive and less than the maximum quantity of the bid (Eq. (10)).
Moreover, the optimization is subjected to (11) in which the sum of the cleared bids needs to be more than or equal to the required power by the quantity demanded by the DSO. The uncleared bids have a value equal to 0. Therefore, the sum of all cleared quantities will represent the quantity of the total cleared power.
The cleared reservation price for each aggregator is determined by a pay as bid concept. Furthermore, the cleared reservation price must be checked to be less than or equal to the price of the DSO bid, while the activation price submitted by the aggregators should be checked that is not higher than the maximum allowable activation price of the DSO, even though the activation will be traded in the real-time market. This is because the submitted activation price of the aggregators will serve as the maximum price that they will be allowed to bid in the real-time market for the activation of the reserved flexibility.

Real-time market
As mentioned before, in the real-time market only the activation of flexibility is traded. In the real-time market, each participant can submit a set of bids in order to make it possible to have a more realistic representation of their cost curves. Since the real-time markets are very close to the event, and the availability of the flexible resources might be limited due to being very close to the event, it is important to facilitate higher flexibility exploitation to reduce the damage from emergency events as much as possible. The idea is that a closer representation of the cost curve might help to increase the quantity of the cleared power in the market by avoiding the requirement to bid one single price for the whole available quantity. As the prices from the supply and demand bids show (see Fig. 8), the value of the first kWs is quite high for lowering the overloading of the transformer, while the first few kWs of power from the batteries have lower cost for the supplier. Therefore, the possibility of a higher flexibility exploitation can be increased in this case. For example, in Fig. 3, an extreme case comparison is made for single price bidding and multiple price Fig. 3 Example for single price bidding versus cost curve bidding bidding. As it can be seen in the single price bids, the supplier and the demander can bid with their marginal price for flexibility which has resulted into no flexibility exploitation while bidding with multiple bids to represent the cost curve has resulted to the clearance of the market.
The participants are assumed to bid with their real costs and do not practice any manipulation in the market. In the current version of the proposed LFM the malicious behavior of the aggregators and/or the DSO has not been studied. Hence, no mechanisms about the prevention of market power have been studied or proposed except for the basic rules about the confidentiality of some sensitive information (i.e., the type of issue in the DSO network, the volume of flexibility requested by the DSO, and the DSO pricing of the event) that are not disclosed until after the clearing of the market, as mentioned in Sect. 3.3. Furthermore, it can generally be assumed that the possibility of market manipulation decreases when the number of the participants increases and the geographical area covered by the LFM increases, facilitating its liquidity. However, since the prevention of market manipulation is important for the reliability and the acceptance of the LFM, the ways to avoid market power will be the scope of future study. In addition, the participants of which the reservation has been cleared in the long market are not allowed to bid higher than the activation price that they submitted in the long-term market. Similarly to the long-term market formulation, the time term and locational attributes are excluded from the mathematical representation. The bids from supplier s and demander d consist of a set of multiple bids { , q} (Eq. (14) and (15)). is the price of the bid (SEK/ kW) and q is the quantity of the bid (kW). It is worth noting that the suppliers of flexibility are the aggregators (or end users of electricity) and the demand for flexibility is requested by the system operators (i.e., DSOs in this case). The prices of the aggregators in the real-time market are bounded by their bids in the long-term market (Eq. (17)), while the total provided quantity should not be less than what they were cleared for in the long-term market (Eq. (18)).
∑ i∈s q s i ≥ y LT s , ∀s ∈ S, s.t.y LT s > 0 The size of each bid is limited to 0.1 kW to reach a closer representation of a continuous function for marginal values of flexibility or the cost function (Eq. (19)). This value to discretize the cost curve should originally reflect the size of the minimum flexibility supply that is possible to be provided by the flexibility technology as well as the minimum size of the bids allowed in the actual flexibility markets. In this study, the flexibility is supplied by battery resources which can be assumed to have a continuous operational power range and no limitation on the minimum quantity for supplying flexibility. The flexibility could also be provided by other resources, such as solar PVs, EVs, HPs and ventilation systems, it has however not been considered in the simulations in this paper in order to keep the focus on the market framework, but it will be included in future versions of the proposed LFM. Therefore, the value is chosen small enough (0.1 kW) to provide an acceptable resolution of the cost curve while not causing high computational burden by high discretization of the cost curves.
Similarly to the long-term market, the real-time market is solved by maximizing the social welfare which is the sum of the value of the demand (i.e., consumers' benefit) minus the sum of the value for the cleared supply bids (i.e., suppliers' cost) (Eq. (20)). Similarly to the long-term market mode, in practical applications of such LFM structures, a tradeoff between the benefits of all stakeholders (i.e., the DSOs and the aggregators) should be considered. However, the proposed LFM has been built as closely as possible to strict market terms. In addition, the optimization of the social welfare implies that there is a trade-off among the benefits of all the stakeholders. The maximization variable is y that is the amount of cleared power for each bid. The cleared value should be positive and less the than maximum provided quantity of the bid (Eq. (21) and (22)).
The total cleared quantity ( Y ) for the supplier s and demand d is the sum of all the cleared capacities of its subbids (Eqs. (23) and (24)).
Finally, the cleared supply capacity must be equal to the total cleared demand capacity according to (25).
The cleared activation price is based on a pay as cleared concept which is equal to the maximum price among the cleared bids. The cleared bids are the bids that have a nonzero cleared quantities. Therefore, the cleared price, if there is an intersection between the demand and supply curves, will be calculated by: In cases that there is no intersection between the demand and supply curves, but all the flexibility supply bids are below the flexibility demand bids, the real-time market will be cleared, as the DSO tries to procure as much flexibility as possible to address the emerging issue in its network. In such cases, the cleared price will be calculated as the average of the highest accepted supply bid and the lowest accepted demand bit, as described by (27):

Simulation results and discussions
The market model has been coded in Python. The simulated test cases include both long-term and real-time services exchange. Real data from two smart buildings on Chalmers campus (Gothenburg, Sweden) premises with different assets such as solar PVs, batteries, and HPs have been used for the formation of aggregator's bids. Regarding the DSO bids, the simulations are based on fictitious data that are similar to the output data of a congestion forecasting mechanism [25]. In all simulated plots for both long-term and real-time services the price axis (y-axis) denotes the price of the flexibility exchange and not the total energy price. Therefore, the total resource reimbursement should consider the possible energy exchange as well. For example, if the flexibility refers to the discharge of a storage unit (i.e., a battery) then, since the battery provides energy to the system along with the required flexibility, the resource should be paid for both deliveries. Thus, the total reimbursement will be the sum of the flexibility and the energy exchange prices.

Long-term market operation
For the simulations of the long-term market, it is considered that the aggregators bid their marginal cost and that the DSO is the only flexibility buyer. Hence, a single-sided auction is used to clear the market, where the DSO defines the volume and maximum acceptable price. Figure 4 depicts a situation of overload in a given transformer on Chalmers campus one typical winter day, extracted by the mean values anticipated for a whole winter month (i.e., February), as the situation is expected to be generally more intense during winter due to heavier load. The transformer is expected to be overloaded between 10:00-16:00. The dashed area represents the amount of flexibility that should be reserved by the DSO in the given location at the specific time period to address this congestion. The flexibility that is traded (i.e., the given example of transformer overloading, but generally in any case) is a trade-off between overloading the transformer and procuring flexibility to avoid the potential congestion. In the long-term market mode, not only the overloading, but also the reinforcement costs can be considered. However, in this paper, the focus is on illustrating the market clearing and the modelling of the DSOs' bidding strategy is not investigated. The trade-off is reflected in the pricing of the DSO's bid and the required volume of the flexibility. More specifically in the long-term market mode, the trade-off is reflected in the maximum allowable price and the flexibility volume that is requested by the DSO in the respective bid. After the identification of the service, the DSO request is sent to Fig. 4 Example of long-term transformer overload the aggregators through the LFMO by opening a long-term orderbook, while the aggregators (i.e., the storage units), which are active in that specific area, bid in response to that request. When the time of the market closure is reached, the clearing procedure is initiated. The followed steps are:

Studied long-term service scenario
1. The weighted prices for the bids of the DSO and the aggregators are calculated, based on the weighted factors provided by the DSO; 2. The bids of the aggregators are put in ascending order according to their weighted price; 3. It is checked if the total power of the bids is enough to satisfy the respective DSO request; 4. The weighted, activation and reservation prices that correspond to the required DSO power volume are compared with the respective maximum acceptable prices provided by the DSO.
If the requested flexibility volume can be catered by the aggregators' bids, the market is cleared and the corresponding reservation prices are determined in a pay as bid concept. When the required volume and/or the maximum acceptable price is not satisfied, the market is not cleared, and the DSO should follow some alternative methods to mitigate the expected congestion, e.g., grid reinforcement or mobile energy storage.

Simulation results for long-term market services
For the case depicted in Fig. 4, three different scenarios are illustrated, as shown in Fig. 5a-5c.
In the first case (Fig. 5a,) the market is not cleared due to high prices in aggregators' bids. As it can be seen in Fig. 5a, the accumulated weighted price of the aggregators (red line) meets the DSO requested volume for flexibility (dashed blue line) at a larger price point than the DSO maximum weighted price (yellow dotted line). This means that the DSO pricing of the incident (i.e., the given transformer overloading), along with the DSO's risk assessment of the event results in a lower price than the one available in the local flexibility market. Therefore, the market is not cleared, as it is more financially beneficial for the DSO to reinforce the system (i.e., by replacing the transformer) than to reserve the available flexibility. In the second case (Fig. 5b) the market is not cleared, as the available flexibility of the aggregators is not enough to cover the volume requested by the DSO. As it can be seen in Fig. 5b, the accumulated weighted price of the aggregators (red line) does not meet the volume of the DSO request for flexibility (dashed blue line). This means that the available flexibility in the market is not enough to satisfy the respective DSO request. Therefore, the market is not cleared, and the DSO must reinforce the system (i.e., by replacing the transformer) to ensure stable future operation under the studied scenario. In the third case (Fig. 5c), the market is cleared, and some bids are accepted. As it can be seen in Fig. 5c, the accumulated weighted price of the aggregators (red line) meets the volume of the DSO request for flexibility (dashed blue line) at a point which is below Fig. 5 a Not cleared long-term market due to high flexibility price, b Not cleared long-term market due to low flexibility availability, c Cleared long-term market the maximum DSO weighted price. Thus, the market is cleared, and the reservation price of each aggregator is determined with a pay as bid concept. The submitted activation price of each aggregator is stored to be fed in the real-time market to serve as the maximum price cap for the activation price of the aggregators.

Real-time market operation
This studied scenario is about a real-time service need regarding a forecasted real-time overload in the same transformer as in the long-term service scenario. In the real-time market mode, the flexibility that is traded is a trade-off between overloading the transformer and procuring flexibility to avoid the congestion. This trade-off is reflected in the pricing of the DSO's bid and the required volume of the flexibility. In the real-time market, the trade-off is reflected in the price curve provided by the DSO in the respective bid. However, in this scenario no long-term or short-term capacities were cleared. In the real-time market, only the activation of flexibility is traded.

Real-time studied scenario
The DSO provides a price curve for the flexibility that is required to address the given transformer overloading. The respective DSO price curves are produced based on the calculation of overloading cost of a typical 250 MVA transformer (overheat, loss of life, degradation, etc.). To calculate the demand curve, the loss of life of the transformer is calculated based on the IEEE C5791-2011Clause 7 [26]. Afterwards, in an iterative procedure, the loss of life is recalculated by reducing the overloading. The benefit from the flexibility is calculated by the reduction in transformer's loss of life caused by the purchased flexibility. The DSO's demand bid for the studied transformer overloading is presented in Fig. 6.
Four different aggregators are active in this area, which represent storage units located in the area. The price curves for the aggregators are calculated based on the storage units installed in two residential buildings located near Chalmers campus. The respective data that have been used to construct the flexibility supply bids can be found in [27]. The small amount of the available flexibility of the studied storage units, comparing to the large capacity of the transformer used for the definition of the DSO price curves, result in linear DSO price curves with low slope. However, the generality of the results and the adequacy of the proposed framework are not compromised. For the construction of the aggregated price curve the cheaper bids are prioritized over the more expensive ones. The cleared flexibility price and volume are defined by the intersection of the DSO price curve and the aggregated price curve of the bidding aggregators. Figure 7 depicts an example of a real-time overload of a transformer and the clearing of the market in three different timesteps. Three different cases can be defined in Fig. 7: a) Overload at timestep No.1. As can be seen in Fig. 7, there is a small overload at timestep 1. The market for the procurement of flexibility to alleviate this congestion is cleared one timestep (i.e., 15 min) before the forecasted overload. Therefore, at timestep 0, the DSO requests flexibility by submitting a demand bid and the respective aggregators respond by submitting their bids. Figure 8a illustrates the described situation, where the DSO requests flexibility and the different aggregators bid in response to that request. Since the anticipated overload at timestep 1 is not severe (0.04 pu), the aggregators bids and the demand bid from the DSO are intersecting at a low price/volume, resulting in partially cleared flexibility bids with low cleared price and volume (0.01SEK/ kW and 4 kW, respectively); b) Overload at timestep No.4. As the forecasted overload is increasing, the demand for flexibility increases i.e., at timestep 4 the forecasted overload has increased to about 1.2 pu. As previously, the market is cleared one time-step (i.e., 15 min) before the forecasted overload, i.e., at timestep 3. Hence, the DSO request and the respective aggregator bids are submitted at step 3. Figure 8b illustrates the described situation, where the DSO requests flexibility and the different aggregators bid in response to that request. Since the anticipated overload at timestep 4 is more severe than the one at timestep 1, the demand and supply curves intersect at a higher price level compared to the previous case at timestep 1. As a result, the market is cleared, but the cleared price and the cleared flexibility  Figure 8c illustrates the described situation, where the DSO requests flexibility and the different aggregators bid in response to that request. Since the anticipated overload at timestep 5 is more severe than in the previous cases, the price curve of the DSO is higher than in the previous cases. As a result, all the bids of the aggregators are accepted and the cleared flexibility price and volume is higher than both the previous cases (0.17 SEK/kW and 65 kW, respectively). It should be mentioned that in strict market rules this market should not be cleared as there is no intersection between the demand and the supply price curves. However, since flexibility is traded in this market, the DSO can procure all the flexibility provided by the aggregators to alleviate the transformer overloading as much as possible. The cleared price was selected in the middle of the maximum of the supply price curve and the minimum of the demand price curve at the given volume as a trade-off between these price levels.

Conclusions
This paper presents the operation of a LFM for the holistic management of distribution grids, through the trade of both reservation and activation of flexibility, indifferent of the type and the timeline of the required services. The framework and the initial model of the market have been explained, while the ability of the proposed market to trade both reservation and activation of flexibility in long-term and real-time horizons has been verified through simulations. The modelling of the proposed short-term market will be the scope of future work. The proposed LFM framework provides DSOs with a market-based instrument to actively manage congestion and voltage issues in their networks. The different timelines provide solutions for DSOs to defer grid reinforcement in the long term, while allowing active management of the distribution grid in the short-term and real-time horizon. The suggested framework has been tested through long-term and real-time simulation-based test cases. The simulation of the operation of the short-term market mode will be the scope of future work. The outcome of the Fig. 8 a Partially cleared real-time market for transformer overloading with low cleared flexibility price and volume, b partially cleared real-time market for transformer overloading with higher cleared flexibility price and volume, c partially cleared real-time market for transformer overloading with all aggregators' bids accepted Furthermore, the proposed market framework has been designed to be simple and fair, so that increased participation of aggregators is facilitated. The simplifications assumed in the current market model do not affect the generality of the extracted conclusions. The future developments of the proposed LFM include the modelling of the short-term market as well the simulations of both active and reactive power trade. In addition, the study of the rebound effect will be investigated. One way to mitigate the rebound effect is through market rules that clearly specify the duration and the maximum volume of the rebound for the resources, similarly to [28]. Finally, different approaches for the long-term market clearing will be evaluated considering the possibility of three-dimensional clearing of reservation, activation and flexibility volume in the long term.
Funding Open access funding provided by Chalmers University of Technology. The work leading to this paper was part of the UNITED-GRID project which has received funding from the European Union's Horizon 2020 Framework Programme under Grant Agreement No 773717.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creat iveco mmons .org/licen ses/by/4.0/.