A Framework for O ﬀ ering Short-Term Demand-Side Flexibility to a Flexibility Marketplace

: The decarbonization of the power sector involves electriﬁcation and a massive deployment of variable renewable energy sources, leading to an increase of local transmission congestion and ramping challenges. A possible solution to secure grid stability is local ﬂexibility markets, in which prosumers can o ﬀ er demand-side ﬂexibility to the distribution system operator or other ﬂexibility buyers through an aggregator. The purpose of this study was to develop a framework for estimating and o ﬀ ering short-term demand-side ﬂexibility to a ﬂexibility marketplace, with the main focus being baseline estimation and bid generation. The baseline is estimated based on forecasts that have been corrected for e ﬀ ects from earlier ﬂexibility activations and potential planned use of internal ﬂexibility. Available ﬂexibility volumes are then estimated based on the baseline, physical properties of the ﬂexibility asset and agreed constraints for baseline deviation. The estimated available ﬂexibility is further formatted into a bid that may be o ﬀ ered to a ﬂexibility marketplace, where buyers can buy and activate the o ﬀ ered ﬂexibility, in whole or by parts. To illustrate and verify the proposed methodology, it was applied to a grocery warehouse. Based on real ﬂexibility constraints, historic meter values, and forecasts for this use-case, we simulated a process where the ﬂexibility is o ﬀ ered to a hypothetic ﬂexibility marketplace through an aggregator.


Introduction
Increasing energy consumption and greater environmental concerns have led to more focus on decarbonization of the power sector. One of the possible solutions is electrification, in which the consumption of fossil energy is replaced by electric energy from renewable sources. This applies to traditional electric power generation, as well as to the demand side. A typical example of the latter is the introduction of batteries and electric vehicles (EVs).
The electrification transition will lead to increased high-intensive decentralized demand for electricity. In addition, an increased share of variable renewable energy sources like solar PV and wind power, leads to more dynamics and less predictability. A significant part of this production comes at decentralized level.
Overall, the complexity of the future electricity system will increase rapidly, particularly at the distribution level, and this will result in more local congestion and voltage problems. The traditional way to meet such challenges is to invest in grid capacity upgrades. An alternative to grid reinforcements is the use of demand side flexibility, defined by Eurelectric as "The modification of generation injection and/or consumption patterns in reaction to an external price or activation signal in order to provide a service within the electrical system" [1]. The Universal Smart Energy Framework Foundation (USEF) defines different flexibility services to unlock the value of flexibility [2]. The framework also defines the different stakeholders in the flexibility value chain and potential benefits from flexibility for each of them. Customers of flexibility are grouped into four different types: transmission system operators (TSOs), distribution system operators (DSOs), balancing responsible parties (BRPs) and prosumers (end-users that produce and consume electricity). The prosumers are also the main source of potential flexibility. According to USEF, an aggregator role is needed to release the flexibility. The aggregator accumulates flexibility from active demand and supply from industrial, commercial and residential end users. The EU defines aggregation as "a function performed by a natural or legal person who combines multiple customer loads or generated electricity for sale, purchase or auction in any electricity market" [3]. Poplavskaya & de Vries [4] state that this definition is rather broad and leaves a lot of room for the aggregators to define their business models. In this article we confine the aggregator role according to Olivella-Rosell et al. [5] and focus on flexibility management and the process of selling flexibility.
Flexibility can be sold based on bilateral contracts between the DSO and the aggregator, for instance by the DSO issuing a flexibility request in cases where congestion or voltage problems occur [5][6][7], or it can be offered by actively trading on flexibility marketplaces [8,9]. A recent review of the literature on local flexibility markets is given by Jin & Jia [10]. They classify and organize the literature based on potential market designs (centralised optimization models, game-theory based models, auction theory based models and simulation models) and market clearing methods (centralized optimization, cecomposition methods, multi-level optimization and optimization with uncertainties). Johnston & Sioshansi [11] describe a UK case study with a marketplace delivered by Piclo (https://picloflex.com/). Other similar marketplace platforms exist, for instance Gopacs (https://gopacs.eu/) and NODES (https://nodesmarket.com/).
The market participants offering flexibility need decision support models for the active trading. In this paper we take the perspective of a demand-side flexibility provider who sells available flexibility in a flexibility marketplace on a daily basis. To be specific and ease the explanation, we have selected one given market design, proposed by NODES [12]. Figure 1 illustrates the marketplace concept where the different types of entities that need flexibility and hence buy flexibility at the marketplace are given to the left. Then the marketplace itself appears, followed by the different types of flexibility providers that sell flexibility. Finally, the prosumer with the flexible assets is presented to the right. In Figure 1, the flexibility value chain goes to the left. A prosumer, with its flexible assets, offers flexibility through an aggregator, who sells flexibility at a flexibility marketplace. The flexibility is then bought by the entity that needs the flexibility. The monetary value chain will go in the opposite direction, from the flexibility buyer on the left to the prosumer on the right. The Universal Smart Energy Framework Foundation (USEF) defines different flexibility services to unlock the value of flexibility [2]. The framework also defines the different stakeholders in the flexibility value chain and potential benefits from flexibility for each of them. Customers of flexibility are grouped into four different types: transmission system operators (TSOs), distribution system operators (DSOs), balancing responsible parties (BRPs) and prosumers (end-users that produce and consume electricity). The prosumers are also the main source of potential flexibility. According to USEF, an aggregator role is needed to release the flexibility. The aggregator accumulates flexibility from active demand and supply from industrial, commercial and residential end users. The EU defines aggregation as "a function performed by a natural or legal person who combines multiple customer loads or generated electricity for sale, purchase or auction in any electricity market" [3].
Poplavskaya & de Vries [4] state that this definition is rather broad and leaves a lot of room for the aggregators to define their business models. In this article we confine the aggregator role according to Olivella-Rosell et al. [5] and focus on flexibility management and the process of selling flexibility.
Flexibility can be sold based on bilateral contracts between the DSO and the aggregator, for instance by the DSO issuing a flexibility request in cases where congestion or voltage problems occur [5][6][7], or it can be offered by actively trading on flexibility marketplaces [8,9]. A recent review of the literature on local flexibility markets is given by Jin & Jia [10]. They classify and organize the literature based on potential market designs (centralised optimization models, game-theory based models, auction theory based models and simulation models) and market clearing methods (centralized optimization, cecomposition methods, multi-level optimization and optimization with uncertainties). Johnston & Sioshansi [11] describe a UK case study with a marketplace delivered by Piclo (https://picloflex.com/). Other similar marketplace platforms exist, for instance Gopacs (https://gopacs.eu/) and NODES (https://nodesmarket.com/).
The market participants offering flexibility need decision support models for the active trading. In this paper we take the perspective of a demand-side flexibility provider who sells available flexibility in a flexibility marketplace on a daily basis. To be specific and ease the explanation, we have selected one given market design, proposed by NODES [12]. Figure 1 illustrates the marketplace concept where the different types of entities that need flexibility and hence buy flexibility at the marketplace are given to the left. Then the marketplace itself appears, followed by the different types of flexibility providers that sell flexibility. Finally, the prosumer with the flexible assets is presented to the right. In Figure 1, the flexibility value chain goes to the left. A prosumer, with its flexible assets, offers flexibility through an aggregator, who sells flexibility at a flexibility marketplace. The flexibility is then bought by the entity that needs the flexibility. The monetary value chain will go in the opposite direction, from the flexibility buyer on the left to the prosumer on the right.  [12]. Figure 1. The NODES Flexibility Marketplace concept with the different potential stakeholders [12]. Notice that NODES define three types of flexibility providers: microgrid, aggregator, and BRP. Their tasks when selling at the marketplace will be similar, and since all of them perform some form of aggregation, we use the term aggregator in the rest of this paper.
Our focus is on the middle and right side of the figure. An aggregator offers the available flexibility from one or several prosumers by submitting bids to the marketplace. When the bid is sent, it will either automatically be matched with a buy bid, it may be accepted by a buyer or no buyer wants to use the bid. This is a continuous process that may happen around the clock or within predefined opening hours. An agreement must be entered between the prosumer and the aggregator that regulates the information flow between the two parties, technical constraints regarding the flexibility, commercial terms, and so forth.
Different types of tradeable products may be defined, but in general a bid consists of a volume and a price, possibly including timing information and other constraints. The volume defines how much the prosumer can deviate from the baseline (in kW) and can be positive flexibility (increased consumption or decreased production compared to baseline) or negative flexibility (decreased consumption or increased production) [13]. Notice that by this definition, positive flexibility corresponds to down-regulation in wholesale reserves markets, while negative flexibility corresponds to up-regulation.
Deciding the bids is a complex decision-making problem, well known from existing wholesale power markets (see for instance [14] or [15] for power producers or [16] for retailers). A methodology for flexibility aggregators participating in wholesale markets is outlined in [17]. Bidding methodology for aggregators participating in flexibility markets is covered in some recent publications. For instance, Abapour et al. [18] propose a robust optimization method for demand response aggregators, where the responsive load is based on customer benefit function and price elasticity. Iria and Soares [19] propose a hierarchical model predictive control (MPC) algorithm to support aggregators that deliver multiple market products through heterogenous flexible resources. Correa-Florez et al. [20] present an adjustable robust optimization model for residential aggregators participating in day-ahead energy and local flexibility markets. Shen et al. [21] propose a market clearing strategy based on an alternating direction method of multipliers. Their paper also formulates an optimal flexibility bidding model for the aggregators, where the objective is to maximize the revenue taking the flexibility cost into consideration. All of these works focus on optimization methods, while disregarding the bid formatting and iterative information process.
In the present paper we define a framework for the bidding process intended for practical, real-world applications. Therefore, we explicitly consider the iterative information revelation process, where new information becomes available from the flexibility marketplace, from meter values in the prosumers' energy systems or from updated predictions, and new bid decisions must be made at certain points in time. Furthermore, we describe the inter-relations between the different parts of the baseline estimation process and the market clearing process. Finally, we visualize the bid formatting and illustrate the total process through a realistic use-case. Different optimization methods will fit into our framework. We limit the scope to the process of deciding potential volumes to bid in the short term, i.e., a few hours ahead. Hence, we disregard two important issues: (1) the problem of finding the optimal price for the flexibility offer; and (2) the problem of finding the optimal time slots to allocate flexibility volumes with time limitations. We leave these issues for future research and assume in this paper that available volume is offered to the earliest possible time slot. Figure 2 shows the involved process steps necessary to handle flexibility sales. We assume that each bid is at asset level, where an asset can be • a load unit, like an EV charging point, a water heater or an air-conditioning unit • a generation unit, like a PV or a wind power generator • a storage unit, like an electric battery or a hot water tank used as thermal storage Further, we assume that the flexibility can be traded with a given time-granularity, where each period (timeslot) for instance can last for 15 min or one hour. Moreover, we assume continuous trade, similar to several Intraday markets [22]. Bids can be entered for a bid horizon, the latter consisting of a defined number of periods. For each period, bids can be entered and changed until a deadline, denoted as gate closure. To simplify, we assume that the seller places sales bids on the marketplace and that these are updated for all trading periods just before each gate closure. As Figure 2 indicates, the bid process is repeated in an iterative way. Further, we assume that the flexibility can be traded with a given time-granularity, where each period (timeslot) for instance can last for 15 min or one hour. Moreover, we assume continuous trade, similar to several Intraday markets [22]. Bids can be entered for a bid horizon, the latter consisting of a defined number of periods. For each period, bids can be entered and changed until a deadline, denoted as gate closure. To simplify, we assume that the seller places sales bids on the marketplace and that these are updated for all trading periods just before each gate closure. As Figure 2 indicates, the bid process is repeated in an iterative way. A high-level description of each of the process steps is given in the list below. In this paper, we focus on the iterative process illustrated in the figure, in particular the baseline estimation and bid generation steps. Detailed explanations about these are given after the list, followed by more in-depth illustrations in the use-case chapter.

Methodology
1. Baseline estimation. The baseline indicates what is expected to be the production/consumption for the given asset if no future flexibility is activated through trades at the flexibility marketplace. In general, the estimation consists of several parts. It starts with a forecast of the production/consumption, followed by a correction for effects from earlier flexibility activations and potential planned use of flexibility for internal purposes. 2. Bid generation. Based on baseline information, physical properties of the asset and agreed constraints for baseline deviation, available flexibility volumes are estimated, period wise. This information is further formatted into bids according to the bid rules defined by the marketplace operator. Fundamentally, the bids contain information about the prosumer's ability and willingness to provide flexibility per asset, defined by the sales price, volumes per period, and potential limitations. The bids are submitted to the flexibility marketplace. 3. Market clearing. This step is performed at the marketplace. Two possible outcomes exist. In the first, the bid is declined, which means that no market participant wants to buy the bid, and it does not end up in a trade. Then the process ends, and we move back to Baseline estimation for the next iteration. The second outcome is that the bid is accepted, which means that someone buys the bid, resulting in a trade and a commitment to deliver flexibility. 4. Flexibility activation. When a bid has resulted in a trade, the prosumer is committed to activating the flexibility, meaning that some setpoints must be changed or an asset must be disconnected or reconnected. From this process step, we move to the next iteration, again starting with baseline estimation. In addition, A high-level description of each of the process steps is given in the list below. In this paper, we focus on the iterative process illustrated in the figure, in particular the baseline estimation and bid generation steps. Detailed explanations about these are given after the list, followed by more in-depth illustrations in the use-case chapter.

1.
Baseline estimation. The baseline indicates what is expected to be the production/consumption for the given asset if no future flexibility is activated through trades at the flexibility marketplace. In general, the estimation consists of several parts. It starts with a forecast of the production/consumption, followed by a correction for effects from earlier flexibility activations and potential planned use of flexibility for internal purposes.

2.
Bid generation. Based on baseline information, physical properties of the asset and agreed constraints for baseline deviation, available flexibility volumes are estimated, period wise. This information is further formatted into bids according to the bid rules defined by the marketplace operator. Fundamentally, the bids contain information about the prosumer's ability and willingness to provide flexibility per asset, defined by the sales price, volumes per period, and potential limitations. The bids are submitted to the flexibility marketplace.

3.
Market clearing. This step is performed at the marketplace. Two possible outcomes exist. In the first, the bid is declined, which means that no market participant wants to buy the bid, and it does not end up in a trade. Then the process ends, and we move back to Baseline estimation for the next iteration. The second outcome is that the bid is accepted, which means that someone buys the bid, resulting in a trade and a commitment to deliver flexibility. 4.
Flexibility activation. When a bid has resulted in a trade, the prosumer is committed to activating the flexibility, meaning that some setpoints must be changed or an asset must be disconnected or reconnected. From this process step, we move to the next iteration, again starting with baseline estimation. In addition, a separate process starts including the steps 5 and 6 below. This process has a different timeline and happens more rarely than the iterative process.

5.
Flexibility verification. After the activation period is over, a verification process must be performed to document that the flexibility in fact was activated according to the trade. The documentation is based on meter values for the asset. Ideally, the metered value should be equal to the baseline corrected for the activated flexibility, but this equation may be broken if the forecast was inaccurate, the estimated shifting effect was wrong or the activation of flexibility for internal or market purposes was not performed according to plan. Such deviations lead to an imbalance between committed and delivered flexibility. 6.
Financial settlement. At certain points in time, economic settlement is calculated, and financial transactions between the marketplace and the seller are performed. Likewise, financial transactions between the seller and the prosumer are also performed, according to agreed contract terms (business model) between the two parties.
When the market clearing is finalized, a new iteration starts, this time with a different bid horizon, since trading for the first period now is closed. In the new iteration, effects from the activated flexibility in previous iterations are taken into account. We assume that the bid horizon has a fixed length, which means that a new bid horizon is constructed by removing the first period and adding a new period at the end of the previous horizon. This leads to a rolling horizon approach, as illustrated in Figure 3, where two iterations are shown. Notice that different approaches are possible, for instance that the bid horizon has a fixed final period, and that a new bid horizon is constructed by simply removing the first period. This is denoted as the receding horizon. Our methodology will work in any case.
Energies 2020, 13, x FOR PEER REVIEW 5 of 17 a separate process starts including the steps 5 and 6 below. This process has a different timeline and happens more rarely than the iterative process. 5. Flexibility verification. After the activation period is over, a verification process must be performed to document that the flexibility in fact was activated according to the trade. The documentation is based on meter values for the asset. Ideally, the metered value should be equal to the baseline corrected for the activated flexibility, but this equation may be broken if the forecast was inaccurate, the estimated shifting effect was wrong or the activation of flexibility for internal or market purposes was not performed according to plan. Such deviations lead to an imbalance between committed and delivered flexibility. 6. Financial settlement. At certain points in time, economic settlement is calculated, and financial transactions between the marketplace and the seller are performed. Likewise, financial transactions between the seller and the prosumer are also performed, according to agreed contract terms (business model) between the two parties.
When the market clearing is finalized, a new iteration starts, this time with a different bid horizon, since trading for the first period now is closed. In the new iteration, effects from the activated flexibility in previous iterations are taken into account. We assume that the bid horizon has a fixed length, which means that a new bid horizon is constructed by removing the first period and adding a new period at the end of the previous horizon. This leads to a rolling horizon approach, as illustrated in Figure 3, where two iterations are shown. Notice that different approaches are possible, for instance that the bid horizon has a fixed final period, and that a new bid horizon is constructed by simply removing the first period. This is denoted as the receding horizon. Our methodology will work in any case. For simplicity, we assume that the bid decisions are made just before gate closure and that market clearing happens directly after. In a real-life setting, though, this might be done continuously from market opening until gate closure.

Baseline Estimation
For load and generation assets, the baseline estimation starts out with forecasting how much the asset will consume or produce if no flexibility is utilized. Many forecast methods exist, for instance different statistical methods [23] or methods in the field of machine learning [24]. When training forecast models for controllable assets, special attention must be put on the dataset. Data for periods For simplicity, we assume that the bid decisions are made just before gate closure and that market clearing happens directly after. In a real-life setting, though, this might be done continuously from market opening until gate closure.

Baseline Estimation
For load and generation assets, the baseline estimation starts out with forecasting how much the asset will consume or produce if no flexibility is utilized. Many forecast methods exist, for instance different statistical methods [23] or methods in the field of machine learning [24]. When training forecast models for controllable assets, special attention must be put on the dataset. Data for periods where the asset has been controlled (i.e., flexibility has been activated) must be treated carefully. The same applies to data for periods just after an activation is ended in cases where activation has implied shifting effects. In our work we assume that forecasts are updated and available before each iteration starts. We further assume that the forecast is "pure", meaning that it contains the expected value given that no activation is planned, nor performed in the recent past.
To create a baseline, the forecast must be corrected for potential consequences from earlier flexibility activations. For instance, if charging power to an electric vehicle has been reduced, some volume will be shifted to later periods. Likewise, if a thermal load has been disconnected in a period, load will also be shifted to later periods. In the latter case, the shifting may also lead to an even higher power demand, which can lead to unwanted consequences, known as rebound effects [25]. We denote the consequences from earlier flexibility activations as shift effects. Finally, the use of flexibility for internal purposes (e.g., for self-consumption, time-of-use or kWmax reduction due to variation in spot market prices, network tariffs, etc.) must be corrected for. For simplicity, we assume that the decision for internal flexibility is taken before the bid generation step, but in real life there may be a link between these decisions, where the flexibility will be used where it is expected to provide the largest value. The link might for instance be through the bid price policy. Further, we assume that the prosumer is small enough to be a price taker, and therefore not affect the prices in the spot market.
This means that baseline for a given period and a given asset can be calculated as: where t ∈ T is any period in the bid horizon, f t is original (based on no flexibility activation) forecasted load or generation, s t is the expected effect from earlier activations and F internal t is the scheduled internal use of flexibility.
To illustrate how Equation (1)  First consider an EV that is connected to a charging point to recharge the battery. A charging demand forecast of 20.0 kWh exists, and it is expected that the connection time is for 7 h. The maximum charging power is 4.0 kW. The resulting charging forecast will then be 4.0 kW for 5 h (hour 0-4), then 0.0, see Table 1. The table illustrates a situation where we are going to calculate the baseline for the coming 6 h (1-6) and that current time is within hour 0. Now, assume that the charging is flexible, and that 2.5 kW negative flexibility is needed for internal purposes in hour 1 and 2. If the EV is going to receive charging according to the total demand, 5.0 kWh must be shifted to later hours. Since 4.0 kW is maximum power, 4.0 out of these 5.0 kWh are shifted to hour 5, while the remaining 1.0 is shifted to hour 6.  For a battery, the situation is slightly different, since no traditional forecast exists. On the other hand, the battery operator might plan to change the state-of-charge (SoC) of the battery, for instance discharge it to prepare it to store surplus PV electricity or to charge it to be able to reduce a consumption peak. These schedules can also be viewed as forecasts. Compared to generation and load forecasts, they can go in both directions: charging (load) and discharging (generation). We chose to view the battery as a load, hence charging will be positive and discharging will be negative.
Consider a battery that has 100.0 kWh capacity, 40.0 kW max charging and discharging power. For simplicity we assume 100% round trip efficiency. During hour 0 (current hour) the battery has charged 10.0 kWh and reached 50.0 kWh energy content (SoC = 0.5). It is scheduled to fill up the Energies 2020, 13, 3612 7 of 17 battery completely by charging 40.0 kWh in hour 1 and 10.0 in hour 2. In hour 3 and 4 the battery will be discharged at full power to limit a demand peak (internal flexibility). After hour 4, the energy content is 20 kWh. Table 2 illustrates how the baseline is calculated in this example. No shifting effect is relevant for the battery. The bottom row shows the baseline, with charging and discharging power.  In hour 3 and 4 the battery will be discharged at full power to limit a demand peak (internal flexibility). After hour 4, the energy content is 20 kWh. Table 2 illustrates how the baseline is calculated in this example. No shifting effect is relevant for the battery. The bottom row shows the baseline, with charging and discharging power.

Bid Generation
The purpose of the bid generation process is to define and submit the bids. Since the bid defines the prosumer's ability and willingness to deviate from the baseline for each asset, we must first estimate the magnitude of potential deviations, namely the available flexible power. For each asset, minimum and maximum possible production or consumption in each period are calculated, then allowed deviations to the baseline are derived. Recall that we distinguish between positive and negative flexibility, defined as follows for load and generation assets: where and are maximum and minimum possible power consumption or production in period t.
The equations will calculate available flexibility for each period in the bidding horizon. Since there are close inter-relations between the periods, and the different assets have different technical, contractual, and comfort related constraints, this is not a straightforward task. Some assets are simple to handle, like curtailing PV production or disconnecting constant loads. Others are slightly complex, for instance a battery, where the SoC-constraints must not be violated. Some are even more complex, like shifting EV charging demand without dis-satisfying the driver or shifting thermal loads without introducing discomfort due to unacceptable temperatures. To handle these constraints properly, an

Bid Generation
The purpose of the bid generation process is to define and submit the bids. Since the bid defines the prosumer's ability and willingness to deviate from the baseline for each asset, we must first estimate the magnitude of potential deviations, namely the available flexible power. For each asset, minimum and maximum possible production or consumption in each period are calculated, then allowed deviations to the baseline are derived. Recall that we distinguish between positive and negative flexibility, defined as follows for load and generation assets: where P max t and P min t are maximum and minimum possible power consumption or production in period t.
The equations will calculate available flexibility for each period in the bidding horizon. Since there are close inter-relations between the periods, and the different assets have different technical, contractual, Energies 2020, 13, 3612 8 of 17 and comfort related constraints, this is not a straightforward task. Some assets are simple to handle, like curtailing PV production or disconnecting constant loads. Others are slightly complex, for instance a battery, where the SoC-constraints must not be violated. Some are even more complex, like shifting EV charging demand without dis-satisfying the driver or shifting thermal loads without introducing discomfort due to unacceptable temperatures. To handle these constraints properly, an asset model is needed, and necessary parameters must be received from the Prosumer's asset management system. Different types of asset models can be used in our framework, for instance the model proposed in [26].
Referring to the examples outlined in the previous section, we get the following available volumes, see summary in Table 3: • The EV can be disconnected in the hours 1-2, releasing 1.5 kW in each hour and 3.0 kWh in total.
Assuming that the planning should aim for the EV getting the total charging demand delivered, these 3.0 kWh must be shifted to hour 6, and there will be no flexibility available for the hours 3-6.

•
For the battery, we can follow 2 alternative paths: Positive flexibility: The battery is scheduled to charge 40.0 kW in hour 1 and 10.0 kW in hour 2. It is not possible to increase the load in these hours; in hour 1 maximum charging power is already scheduled. In hour 2 the battery gets fully charged. Hence, no positive flexibility can be provided in these hours. In hour 3, the schedule is to discharge with 40.0 kW. By cancelling this, 40.0 kW positive flexibility can be provided. However, it is not possible to charge, since the battery is already full. The same argument is valid in hour 4. In later periods, the baseline is 0, and by following this path, the battery is still full and cannot be charged further, hence no further potential for positive flexibility exists. In the end of hour 2 the battery energy content will be 0.0, so no more negative flexibility can be provided until it is charged again.  Notice that for the battery we have outlined two extreme paths, based on the approach that we provide maximum flexibility in the earliest periods in each iteration. These are illustrated in Figure 5, where the green curve shows the maximum charging strategy and the red the maximum discharging. Between these two paths, other feasible paths exist. The blue curve shows the baseline.
When the estimated volumes for positive and negative flexibility are available, they must be put together into a bid according to the formats and other rules defined by the marketplace operator. Table 4 illustrates a principal bid for a certain asset with a given asset ID. The bid consists of two lines, one for positive flexibility and one for negative. Each line consists of one price and flexibility volumes for each of the periods. Finally, some limitations can be formulated. These might be timing constraints, information whether the volume is all-or-nothing or can be partly traded, whether an activation will give a shifting effect, and other possible limitations or additional information. When the estimated volumes for positive and negative flexibility are available, they must be put together into a bid according to the formats and other rules defined by the marketplace operator. Table 4 illustrates a principal bid for a certain asset with a given asset ID. The bid consists of two lines, one for positive flexibility and one for negative. Each line consists of one price and flexibility volumes for each of the periods. Finally, some limitations can be formulated. These might be timing constraints, information whether the volume is all-or-nothing or can be partly traded, whether an activation will give a shifting effect, and other possible limitations or additional information.  When the bids are ready, they are submitted to the marketplace, where the market clearing process is performed. For each bid, the result can be a decline and we move to the next iteration or an accept, and we activate the flexibility and then move to the next iteration.

Introduction
To illustrate and verify the baseline estimation and the bid generation parts of our framework (step 1 and 2 of the workflow given in Figure 2), we performed a case-study which was as realistic as possible. Our starting point was a real commercial building with 4 flexibility sources. We had access to relevant parameters and data, like flexibility constraints, historic meter values, and forecast information. This is accessible through the flexibility management software platform Connected Prosumer (https://www.esmartsystems.com/connected-prosumer/). Data from a specific day in February 2020 was used.
With this realistic starting point, we simulated a process where the flexibility is offered to a hypothetic flexibility marketplace through an aggregator. Furthermore, we assumed that the local DSO is a potential buyer of negative flexibility for congestion management purposes, and hence we limited the scope to negative flexibility, only.
Since this market regime is not established yet, we made some assumptions (although the methodology will work also for other assumptions):  The traded products have hourly time-resolution  Gate closure is 30 min before the start of each operation hour When the bids are ready, they are submitted to the marketplace, where the market clearing process is performed. For each bid, the result can be a decline and we move to the next iteration or an accept, and we activate the flexibility and then move to the next iteration.

Introduction
To illustrate and verify the baseline estimation and the bid generation parts of our framework (step 1 and 2 of the workflow given in Figure 2), we performed a case-study which was as realistic as possible. Our starting point was a real commercial building with 4 flexibility sources. We had access to relevant parameters and data, like flexibility constraints, historic meter values, and forecast information. This is accessible through the flexibility management software platform Connected Prosumer (https://www.esmartsystems.com/connected-prosumer/). Data from a specific day in February 2020 was used.
With this realistic starting point, we simulated a process where the flexibility is offered to a hypothetic flexibility marketplace through an aggregator. Furthermore, we assumed that the local DSO is a potential buyer of negative flexibility for congestion management purposes, and hence we limited the scope to negative flexibility, only.
Since this market regime is not established yet, we made some assumptions (although the methodology will work also for other assumptions): • The traded products have hourly time-resolution • Gate closure is 30 min before the start of each operation hour • Baseline and bid volumes are given in kWh/h as integers, while bid prices are given in €/kWh with 2 decimals

The Building and Flexibility Sources
The building is a large warehouse used for storing groceries until they are distributed to different stores. A complex heating and cooling system is installed to maintain different temperature levels in the different parts of the building. The areas for storage of frozen and chilled goods need cooling, while offices and other areas for personnel need heating most of the year. A cooling machine system, containing several compressors, pumps, fans, and so on uses a lot of electricity to provide the cooling energy to the storage areas. Waste heat from this system is used for heating purposes. In cases where the heat demand is larger than the heat production from the cooling machines, an electric boiler starts. This boiler can be substituted with a non-electric boiler fueled with bio-oil. In black-out situations, an emergency generator (fueled by biodiesel) starts up, to maintain critical loads and to prevent damage of the groceries. Finally, an electric battery is installed in the building, mainly with the purpose to avoid selling surplus electricity back to the grid in periods with much PV generation and little load, and to reduce the import peaks during the wintertime to avoid demand charges at the grid contract.
For provision of negative flexibility, 4 assets exist in the building: 1.
The battery can provide negative flexibility by discharging. The capacity is 65 kWh and maximum charging and discharging power is 30 kW. It can discharge down to 5 kWh, which means that it can provide 30 kW flexibility for 2 h (efficiency loss taken into consideration), given that it is fully charged before flexibility activation. After activation, we assume that the battery will be recharged evenly over 5 h.

2.
The electric water heater has 350 kW installed capacity and runs on different power levels according to the need for hot water not supplied by the cooling machines. Negative flexibility can be provided by disconnecting the electric boiler and switching to the fuel boiler. This can be done very fast, but the fuel boiler can only run for maximum 6 h a day. These hours can be spread over the day, there is no requirement that they must be consecutive. The flexibility volume will be the volume that the electric boiler would have used if it had been running. Since the fuel boiler delivers the heat demand, switching back to the electric boiler will have negligible shifting effect. According to the terminology defined in [26], this flexibility source is in the category curtailable disconnectable.

3.
The cooling machine system runs at different power levels according to the need for cooling energy. Negative flexibility can be provided by adjusting the temperature setpoints in the freezing area. Experiments show that the machine room can provide negative flexibility for one hour according to the following equation: where T t is the outdoor temperature in period t. It is assumed that the flexibility has an upper limit of 400 kW, which is reached when the outside temperature is 20 • C. After flexibility activation there must be a rest time for 5 h to smooth out the shifting effect. This is done by softly adjusting the setpoints back to normal operation, and experiments show that the curtailed volume is recovered by equal distribution over 5 h. After these 5 h, flexibility can again be provided. According to the terminology defined in [26], this flexibility source is in the category shiftable volume.

4.
The emergency generator has 2 MVA installed capacity and can be quickly started. In addition to emergency purposes, it can provide negative flexibility by starting without a black-out situation. In such cases, the generator is permitted to run for maximum 6 consecutive hours, but due to the startup-costs, it should run for minimum 2 h. Such a start can be done only once a day. Due to power factor and efficiency the optimal operation for active power is set to 1800 kW.
We do not have exact information about costs for providing flexibility from the different sources, nor insight in how the prosumer would strategically price the bids. We assume that the prices increase downwards the list above. To have specific numbers, we use 0.50, 1.00, 1.50 and 2.50 €/kWh, respectively. Figure 6 sums up the flexibility sources and their key parameters.
We do not have exact information about costs for providing flexibility from the different sources, nor insight in how the prosumer would strategically price the bids. We assume that the prices increase downwards the list above. To have specific numbers, we use 0.50, 1.00, 1.50 and 2.50 €/kWh, respectively. Figure 6 sums up the flexibility sources and their key parameters.

The Bidding Process
Since our approach is to bid all available flexibility to the earliest periods in the bidding horizon and the maximum duration is 6 h, we define a rolling bidding horizon of 6 h. When a new iteration starts, the horizon is rolled 1 h, meaning that the first hour is removed and a new hour is added in the end.
In our study, we start before noon for the given day. We assume that no flexibility has been activated so far. To ease the explanation of the bidding process below, we further assume that no flexibility will be used for internal purposes for the rest of the day. Finally, we assume that the battery is fully charged.
We collect relevant forecasts from Connected Prosumer for each of the remaining 12 h of the day. These are outdoor temperature forecasts, originally retrieved from an external weather forecast provider (https://darksky.net/dev) and consumption forecasts for the water boiler and cooling machines (data available through project funded by the Research Council of Norway's ENERGIX program under Grant Agreement No 282357). The two latter are estimated in Connected Prosumer by a machine learning model based on adaptive boosting techniques. Table 5 shows the forecast information, where temperatures are in °C and consumption values in kWh. Notice that the consumption forecasts are valid under the assumption that no flexibility will be used.

The Bidding Process
Since our approach is to bid all available flexibility to the earliest periods in the bidding horizon and the maximum duration is 6 h, we define a rolling bidding horizon of 6 h. When a new iteration starts, the horizon is rolled 1 h, meaning that the first hour is removed and a new hour is added in the end.
In our study, we start before noon for the given day. We assume that no flexibility has been activated so far. To ease the explanation of the bidding process below, we further assume that no flexibility will be used for internal purposes for the rest of the day. Finally, we assume that the battery is fully charged.
We collect relevant forecasts from Connected Prosumer for each of the remaining 12 h of the day. These are outdoor temperature forecasts, originally retrieved from an external weather forecast provider (https://darksky.net/dev) and consumption forecasts for the water boiler and cooling machines (data available through project funded by the Research Council of Norway's ENERGIX program under Grant Agreement No 282357). The two latter are estimated in Connected Prosumer by a machine learning model based on adaptive boosting techniques. Table 5 shows the forecast information, where temperatures are in • C and consumption values in kWh. Notice that the consumption forecasts are valid under the assumption that no flexibility will be used. In the first iteration, bids will be submitted for the bidding horizon spanning from the hour 12-13 to 17-18. First, the necessary forecasts are collected according to Table 5. Then, baselines are calculated for all the flexible assets. Since no flexibility is planned for internal use and no flexibility is activated earlier this day, the battery and the emergency generator will have 0 baseline, while the boiler and cooling machines will have baselines equal to their consumption forecasts (see Table 6). The next task is to estimate the available flexibility, which is straightforward in this iteration, since no flexibility has been activated yet.
The battery can discharge 30 kW for two hours. Since our approach is to allocate the volumes to the earliest possible periods in each bidding horizon, the battery flexibility will be set to 12-13 and 13-14. The electric boiler can be substituted with the fuel-boiler for all the hours in the bidding horizon. The cooling machines can reduce consumption for one hour according to Equation (6). Finally, the emergency generator can start and run for all the hours. Table 7 shows the resulting bids, which are submitted to the marketplace before 11:30 (gate closure). We assume that none of the bids are accepted and move on to iteration 2 without any activation.

Iteration 2
The gate closure for the next iteration is 12:30, and the bidding horizon now starts with 13-14 and ends with 18-19. Updated forecasts are downloaded, they are unchanged from the previous iteration and still according to Table 5. Baselines are calculated exactly as in iteration 1, see Table 8. Bids are also generated the same way as in iteration 1, see Table 9. Let us now assume that the DSO, due to a predicted congestion, buys the three first bids for hour 13-14, i.e., the battery (30 kW), the boiler (328 kW), and the cooling machines (208 kW). The total volume traded is 566 kWh, and the total cost is 655 €.
At 13:00 these three flexibility sources must be activated according to the trades, meaning that the battery must start discharging, the electric boiler must be switched off (and consequently the bio-boiler must be switched on), and finally, the temperature setpoints in the freezing area must be changed.

Iteration 3
The bidding horizon now goes from 14-15 to 19-20 and the gate closure is 13:30. Forecast information is still according to Table 5, but due to activations in the previous iteration, shifting effects must be taken into consideration when calculating baselines for the battery and the cooling machines.
Since we assume that the battery is recharged evenly over 5 h, it will have a baseline consumption of 6 kWh each hour from 14-15 to [18][19]. Similarly, the cooling machines will increase the consumption with 42 kWh (328/5) relative to Table 5 in the same 5 h. The resulting baselines are presented in Table 10. For the assets with time limitations, the bids must reflect the previous activations. Hence, the battery can only discharge for one more hour. Since the battery has a baseline equal to 6 kW charging, changing to 30 kW discharging represents 36 kW negative flexibility. For the hours starting at 15 and ending at 19, the baseline is also 6 kW, but since the battery now will be empty, no discharging will be possible, and negative flexibility will be only 6 kW. The maximum duration for the boiler means that it can only run for 5 more hours, and it cannot provide flexibility in hour 19-20. The cooling machines have no flexibility available until the rest time is over. This happens in hour 19-20, and since the temperature forecast is −1.74, the estimated volume is 183 kWh. The resulting bids for iteration 3 are presented in Table 11. Iteration 4 closes at 14:30 and contains the 6 h from 15-16 to 20-21. When iteration 4 starts, new weather forecasts have been received, where the outside temperature is expected to be a bit higher than in the previous forecast. As a result, the updated consumption forecasts are slightly lower for the boiler and slightly higher for the cooling machines. Table 12 shows the updated forecast information. Notice that the cooling machine consumption so far is not considering the shifting effects from activation.  Table 13 shows the baseline information. The battery, which is not affected by the updated forecasts, is now at 36 kWh and needs to charge for 4 more hours. The cooling machines will have shifting effects until the end of hour 18-19, then they are back to normal operation, and thus the consumption is reduced.  16-17 17-18 18-19 19-20 20-21   Battery  6  6  6  6  0  0  Boiler  253  253  253  249  167  110  Cooling machines  592  556  509  537  463  463  Emergency generator  0  0  0  0  0  0 Bids for iteration 4 will be according to Table 14. Similar to iteration 3, the battery can provide 36 kWh flexibility in the first hour. Notice the reduced volumes for the boiler, due to updated forecasts, and consequently, the higher volume for the cooling machines in hour 19-20, which is the first possible hour they can provide flexibility again.

Discussion
Since the market rules and products considered in this paper are not established yet, we have made several assumptions. Furthermore, to illustrate our points in a not too complicated way, we have made some simplifications.
First, our work is based on the NODES concept, where the price formation mechanism is continuous trade like stock trading or Intraday markets, and where sales and buy bids are matched continuously. Other marketplaces might have other clearing principles, like closed auction, commonly used in several day-ahead markets. Then all bids are collected first, and one, joint market clearing process is run for all the periods in the bid horizon (e.g., 24 h). All prices are published simultaneously. Such markets have different bid formats, like piece-wise linear bid curves between mandatory lower and upper price limits, block bids, or other, more complex formats. Although the framework presented in the current article is generic, the bid decision process will be influenced by the bid formats and the market clearing principle. In particular, in the case of closed auction, the timing of the volumes will be crucial. The wait-and-see strategy as proposed in the current article, where volume is bid to the earliest possible time slot and moved to the next if not accepted, will not be optimal.
Although baseline information is frequently connected with uncertainty, we have assumed that the aggregator reports the true baseline, in terms of best estimate. In cases where the marketplace has little liquidity or solves very local problems, situations can occur where the aggregator can create a demand for flexibility, by deliberately altering the baseline. By providing flexibility bids later, it might be possible for the aggregator to increase the profit. This is exercise of market power, which should be avoided. The issue illustrates one of the key challenges for flexibility marketplaces-how to build trust.
In the proposed methodology, we have assumed that the basic load and generation forecasts are made first, and that shifting effects are made in a separate process. Dependent on the forecasting methods available, these might be forecasted in an integrated approach. Further, we have assumed that the planned use of internal flexibility is given before deciding the volumes to bid to the marketplace. In a real-world setting, the overall target will probably be to use the flexibility where it maximizes the value. Hence, there will be a kind of competition between internal and external purposes, and the decision will probably be taken in an integrated approach.
We have proposed that the flexibility volumes are placed at the earliest possible time. In reality this will rarely not be the optimal strategy, and a more advanced methodology will be needed for optimal timing. This argument, in combination with problem of using flexibility for internal or external purposes, will probably mean the planning horizon must be extended.
The pricing of the bids is also disregarded in this work, since we have assumed prices determined outside our methodology. The objective will be to maximize the expected profits the flexibility assets can generate. To do so, forecast models are needed for the market prices or the demand for flexibility; see for instance [27] or [17]. Such models must be based on historic values, and since the market regime is not established yet, we selected to disregard these issues.
The flexibility volumes in the bids are based on estimations and associated with uncertainty. The level of uncertainty will vary from asset to asset. Anyway, this must be taken into consideration when deciding the volumes to bid to the marketplace. The risk is that the committed volumes cannot be delivered, which in turn may give serious consequences for the buyer. An important parameter for such considerations is the possible penalty for not delivering the traded volumes. Some sort of risk management is anyway needed.
As illustrated both in the methodology chapter and in the use-case, activation of flexibility might have rebound effects. In the worst case, this could lead to a situation where the DSO buys flexibility to solve a congestion problem, but the activation introduces a new congestion in a later period. One possible way to avoid such situations is to include potential rebound effect information as a constraint in the bid. Then the DSO knows possible consequences from buying the bid and can avoid potential negative side effects.

Conclusions
In this paper, we have proposed a framework for estimating and offering short-term demand-side flexibility to a flexibility marketplace. The framework consists of 6 steps: (1) baseline estimation; (2) bid generation; (3) market clearing; (4) flexibility activation; (5) flexibility verification; and (6) financial settlement. The main focus in this work is on the first 2 steps, but we also outline how a flexibility trade can take place. Each step of the proposed framework can be changed or improved without disturbing the overall workflow.
The baseline is estimated based on forecasted values for the production/consumption for the given flexibility asset, which is further corrected for effects from earlier flexibility activations such as shift effects/rebound effects and potential planned use of flexibility for internal purposes. The available flexibility volumes are then estimated based on the baseline information, physical properties of the asset, and agreed constraint for baseline deviation. Additionally, these are formatted into a flexibility bid that can be offered to a flexibility marketplace.
To illustrate and verify the proposed methodology, we have applied it to a use-case based on a grocery warehouse with the following flexibility sources: a battery, an electric water heater, a cooling machine system, and an emergency generator. Forecasted values for a specific day in February 2020 were used in order to make the use-case as realistic as possible, together with historic meter values and real flexibility constraints. Since the flexibility market does not exist yet, several assumptions and simplifications were made in order to simulate a process where the flexibility is offered to a hypothetic flexibility marketplace through an aggregator. However, the methodology is not restricted to these assumptions and simplifications, and it could also be applied to assets other than the examples given in this paper.