Optimized Operation of Local Energy Community Providing Frequency Restoration Reserve

In order to unlock the maximum flexibility potential of all levels in the power system, distribution-network-located flexible energy resources (FERs) should play an important role in providing system-wide ancillary services. Frequency reserves are an example of system-wide ancillary services. In this regard, this article deals with the optimal operation of a local energy community (LEC) located in the distribution network. The LEC is proposed to participate in providing manual frequency restoration reserves (mFRR) or tertiary reserves. In addition, the community is supposed to have a number of electric vehicles (EVs) and a battery energy storage system (BESS) as FERs. The scheduling of the community, which is fully compliant with the existing balancing market structure, comprises two stages. The first stage is performed in day-ahead, in which the energy community management center (ECMC) estimates the amount of available flexible capacities for mFRR provision. In this stage, control parameters are deployed by the ECMC in order to control the offered flexibility of the BESS. In the second stage, the real-time scheduling of the community is performed for each hour, taking into account the assigned and activated amount of reserve power. The target of the real-time stage is to maximize the community’s profit. Finally, the model is implemented utilizing a case study considering different day-ahead control parameters of the BESS. The results demonstrate that the proposed control parameters adopted in the day-ahead stage considerably affect the real-time profitability of the LEC. Moreover, according to the simulation results, participating in the mFRR market can bring additional profits for the LEC.

Actual updated state-of-charge of EV i in 4 th quarter of hour t-1 based on activated reserve data SOC B,act i,t −1,4 Actual updated state-of-charge of the BESS in 4 th quarter of hour t-1 based on activated reserve data I cap t The income of the LEC obtained from provision of reserve capacity at hour t [  Increasing the penetration of intermittent-based distributed energy resources (DERs) has led power system operators to deploy more flexibility services. In this way, system operators need to maintain the stability of the system at a specific threshold and increase the flexibility of the system using FERs. The flexibility of electrical systems could be defined as the continuous adjustability of the operating point of the network to accommodate the variations in predicted/unpredicted fluctuations of demand/generation [1]. Flexibility services can be provided by different FERs located in the transmission network and/or the distribution network. Exploiting the maximum flexibility potential of the power system requires the active utilization of FERs in all levels of the system [2]. Currently, transmission-network-connected FERs such as conventional generators are the only resources being deployed to satisfy system-wide (TSO-level) flexibility needs [3], [4]. In other words, flexibility needs of transmission networks are mostly met by transmission-networkconnected FERs. However, the utilization of maximum flexible capacity of the whole system requires the contribution of FERs connected to different levels of the network. These levels include DSO-and TSO-levels [5]. Electric vehicles (EV), different types of energy storage such as batteries as well as household controllable appliances can be regarded as examples of distribution-network-located FERs [5].
System operators, including transmission system operators (TSO) as well as distribution system operators (DSO), deploy various types of flexibility services so as to fulfil their operational responsibilities. The flexibility services utilized by TSOs are commonly known as ancillary services [4]. These services are normally used to satisfy system-wide flexibility needs. This means that they are deployed mostly to maintain the system frequency at its predefined limit.
The services include reserves, both spinning and non-spinning, which assist with the efficient operation of transmission networks. The ancillary services can be different depending on the characteristics and types of disturbances occurring in the power system [5], [6]. Currently in Nordic countries, frequency reserve services are categorized into primary reserves named frequency containment reserve (FCR), secondary reserves named automatic frequency restoration reserve (aFRR) and tertiary reserves named manual frequency restoration reserve (mFRR), which are deployed based on the system flexibility requirements. The FCR is a kind of reserve required to automatically respond to the real-time frequency deviation. This type of reserve is itself divided into two categories, namely frequency containment reserve for normal condition (FCR-N), which is utilized all the time, and frequency containment reserve for disturbance conditions (FCR-D). On the other hand, the aFRR is applied to automatically restore the balance, while the mFRR is used manually in case of outages, power-constrained occurrence related to cross-border connections as well as unexpected sustained activation of the aFRR [6], [7]. Moreover, a new kind of reserve market in the Nordic countries has been introduced in 2020, entitled fast frequency reserve (FFR), which can handle rapid frequency fluctuations during extremely low inertia situations (e.g. during summertime) [8].
As mentioned earlier, the main resources providing reserve services are currently conventional generators located in the TSO-level of networks. However, in the near future, the prevailing penetration of renewable energy resources would reduce the system's inertia significantly. For this reason, the participation of distribution-network-located FERs is needed as well as in order to efficiently operate future power systems.

B. LITERATURE REVIEW AND COMPARISON
There exist previous studies that have assessed the participation of distribution-network-located FERs in providing TSO-level flexibility by taking part in reserve markets. In terms of storage-based resources, several studies analyzed the profitability and feasibility of the participation of different types of energy storage in reserve markets. For example, the authors of [9] propose a control policy for batteries so as to achieve near-optimal performance considering an offline controller which has complete information about the expected future status of the grid. Reference [10] analyzed the contribution of energy storage for better management of the variability of demand and generation. The provision of aFRR services by a battery energy storage system (BESS) is evaluated in [11], in which the authors aim to estimate the potential revenue of the battery storage system in the balancing market. In [12], a price-maker storage system is proposed, to participate in pool-based markets including joint energy, reserve markets and balancing settlement. In this reference, the authors did not specify the exact type of balancing services as well as the reserve that the storage was proposed to provide. Finally, the participation of pumped hydro energy storage in day-ahead energy and performance-based regulation was examined in [13]. This service was designed for North American regulation markets.
An electric vehicle (EV) aggregator has also been introduced as another reserve resource in the literature. For example, [14] proposes a novel bidding strategy for an EV aggregator aiming to provide TSO-level flexibility, by participating in reserve markets. The authors did not specify the type of reserves procured from EVs. The authors of [15] developed a deterministic optimization problem in order to minimize the costs of purchasing energy and selling secondary reserves (spinning or regulation reserves in the United States [16], [17]). The study tries to schedule EVs based on the North American reserve markets formed for secondary reserve procurement. The provision of FCR services through an EV charging station is also presented by the authors of [18], where the study calculates the potential flexibility that can be procured by each charging cycle of EVs.
In addition, some studies address the roles of distribution network aggregators in providing reserves. For instance, an aggregator of prosumers is proposed to take part in a joint day-ahead and reserve markets in [19]. This reference utilized a two-stage stochastic optimization model so as to support prosumers' participation in the reserve market. In [20]- [22], various models are presented for a virtual power plant so as to maximize its profit by participating in energy and ancillary service markets. Furthermore, the aggregator introduced in [23] is capable of taking part in spinning reserve markets as well as peak-hours load reduction. The authors of [24] proposed a coordination scheme for aggregating consumers for the purpose of providing FCR services. Similarly, [25] developed a model for the utilization of grid-connected PV panels combined with a BESS, aiming to follow the regulation signals sent by the operator. Finally, a microgrid is regarded as a provider of reserve services and flexible ramping products in [26], seeking to maximize its total profits.
Considering the existing literature, previous studies assessing the potential of distribution-network-located aggregated FERs have some shortcomings which need to be addressed in the future. For instance, in most of the above-mentioned studies, scheduling of FERs was not fully conducted based on the structure of real-world two-stage reserve markets in terms of market timing and technical aspects. In this light, for example, they do not consider whether the studied small-scale reserve unit is allowed to participate solely or whether it requires an aggregator as a broker. In addition, in most of the studies the authors do not differentiate between assigned reserve and activated reserve power, which can considerably affect the scheduling of FERs and thus affect the profitability of the reserve resource. TABLE 1 highlights the difference between the proposed method and the existing literature. It should be noted that the table includes those references which deal with the provision of TSO-level flexibility services through distributionnetwork-located resources. The first column of the table introduces the references. The second column states which kind of flexibility services are provided by the FERs. The third column assesses whether the research considers both day-ahead and real-time scheduling to include both capacity and energy of reserves. The fourth column analyzes whether the study takes into account the technical aspects and details of the existing reserve markets and whether the model is developed based on the existing reserve market models. Additionally, it assesses whether the relevant considerations related to the assigned and activated reserve are taken into account in the study. The fifth and sixth columns indicate whether they utilized the two important FERs in their models.
According to TABLE 1, this article offers the existing research some advantages, described below: 1. The distribution-network-located resource is considered to provide a type of ancillary service, which has not been regarded before. It offers mFRR services to the TSO. 2. It schedules its FERs in two stages (day-ahead and realtime) so as to take into account both reserve capacity and reserve power. 3. The model is in total compliance with the existing balancing market models in Nordic countries for providing mFRR services. The technical aspects and the difference between assigned and activated reserves are fully taken into account when scheduling the FERs. 4. The paper considers scheduling of two popular FERs, including BESS and EVs, at the same time.

C. CONTRIBUTION
In general, this article presents a two-stage model for the participation of a PV-equipped LEC with EVs and a shared BESS for providing mFRR services. The first-stage scheduling is run in day-ahead. In this stage, the LEC aims to estimate its flexible capacities and the offers which should be submitted for the provision of mFRR. In the real-time stage, the LEC is scheduled based on the assigned and activated reserve power determined in real-time. The main contribution of the paper is summarized as follows: VOLUME 8, 2020 1) To the best of the authors' knowledge, there exists no research assessing the participation of distributionnetwork-located resources in providing mFRR (tertiary reserve) services. Since each type of TSO-level reserve has a specific trading structure, along with specific technical considerations and activation time, the participation of reserve resources in each reserve market needs to be specifically analyzed.
2) The participation of a local energy community in reserve markets is not regarded in the existing studies. However, an LEC can be considered as one of the potent reserve providers by exploiting different-type distributionnetwork-located FERs and motivating members to manage their consumption. They can also share FERs so as to increase their profits. In this manner, the expenses of resources' capital costs are shared between members while they can all benefit from the monetary income. For this purpose, this article considers an LEC as a reserve provider whose members share a PV system as well as a BESS. There exists a number of EVs in the community, which can also contribute to the LEC's flexibility provision. In this regard, the EV owners' charging satisfaction is considered as well. 3) This article considers control parameters related to the SOC of the BESS so as to manage the flexible capacity offered by the LEC in the day-ahead stage. Accordingly, different control parameters are calculated for the case study, and their impact on the community's real-time operation and profitability are discussed.

D. PAPER ORGANIZATION
The rest of the paper is organized as follows. The model description is provided in Section II. Section III focuses on the problem formulation for both stages of this study. The case study and simulation results are discussed in Section IV. Finally, this study's conclusion and possible future works is presented in Section V.

II. MODEL DESCRIPTION
Before describing the proposed two-stage model, the concept of an energy community should be defined and the markets' considerations need to be introduced.

A. ENERGY COMMUNITY
A general definition of energy communities has been proposed by the literature, which refers to a group of members who voluntarily join a community. These members might appear in different forms, e.g. prosumers (proactive consumer) or/and consumers. Energy communities might also have a bulk energy storage system, wind turbine(s) and/or a PV system as shared assets between members. The aim of energy communities (i.e. its members' aim) is to minimize energy costs along with maximizing the community's revenue through trading energy with the grid as well as providing flexibility services to the networks [27].
There might be various types of energy communities in terms of members' categories (e.g. residential, industrial, rural, etc.) or based on the physical distance between the members (e.g. local energy communities or distributed energy communities). Local energy communities are communities in which the members as well as the community's assets are geographically close. In such communities, the energy produced locally is supposed to be consumed locally. In other words, there should be local proximity between prosumers and consumers [28]. Additionally, anyone from the local area can become a member of this community and can trade with other members within the community. Furthermore, the total cost and benefit of such trading must be shared between the members of the community [29]. Thus, the members will benefit from the synergy and cost-efficient outcomes of joining the community.
There are various methods for the management of energy communities. Regarding this, a non-profit manager from amongst the community members should be nominated to be in charge of community management for monetary and technical considerations [30].
This article considers a number of households as consumers who form a residential LEC. The community shares a BESS and there are also some EVs within the community, which contribute to increasing the LEC's flexibility. In addition to these resources, the community is considered to have a shared PV system as a renewable energy resource. A non-profit community manager, through an energy community management center (ECMC), is in charge of the scheduling and operation of these resources in the community. The ECMC's main goal is to increase the LEC's profit by providing TSO-level flexibility to the grid and also to schedule the community's flexible resources including EVs and the BESS.

B. FLEXIBILITY SERVICES AND MARKET STRUCTURE
The focus of this article is on providing mFRR services. With regard to the Nordic balancing markets [31], [32], a balancing service provider (BSP) aggregates several reserve resources so as to provide suitable capacities for participation in balancing energy and capacity markets. In Finland, as an example of a Nordic country, the minimum capacity required for participation in mFRR service markets is 5 MW, which needs to consist of bids with a resolution of 1 MW [31].
The studied flexibility service, i.e. mFRR, is split into upward flexibility and downward flexibility services. In circumstances wherein systems require upward flexibility, the TSO purchases power from the BSPs, whilst during time slots requiring downward flexibility, the TSO sells power to the BSPs [7]. The type of flexibility services required in each time slot depends on the TSO's flexibility needs.
Manual FRR services are traded in the balancing capacity market (BCM) and the balancing energy market (BEM).
In the BCM, participants should submit their flexibility capacities before 11:00 a.m. of the day before delivery [31]. The TSO deploys the amount of capacity required and pays a capacity fee to the corresponding BSPs. However, participants can submit and modify their balancing energy bids in the BEM 45 minutes prior to delivery [31]. The BSP submits its bids for upward/downward regulation, the prices as well as other information regarding its reserve units to the BEM. Afterwards, the TSO decides on the assigned flexibility that should be provided by the BSPs, based on their offered prices, the type of required flexibility (upward or downward) and the amount of required flexibility in each time slot.
As already mentioned, this article considers a difference between the assigned flexibility and activated flexibility. Regarding this, the TSO determines the assigned flexibility of each BSP through the settlement of the BEM, while the activated amount of flexibility is specified at the exact moment of delivery based on the TSO's real-time balancing requirements [31]. In other words, the TSO decides how much flexibility must be activated according to its instantaneous flexibility need.

C. PROPOSED MODEL
The proposed LEC, as a reserve unit, contributes to the provision of mFRR services. In order to enable participation of a small-scale LEC, the LEC's flexibility offer should be sent to the BSP to be aggregated with those of the other reserve units and be submitted to the balancing markets. Fig. 1 depicts the main structure of the proposed LEC and its interaction with the grid and the BSP. As the figure illustrates, the LEC sells TSO-level flexibility through the BSP, and also trades energy with the upstream grid so as to fulfil its energy balance constraints. Regarding the structure of the balancing markets introduced in the previous section, the LEC as a reserve unit is supposed to be scheduled in two stages, each with different time horizons and granularity.
In the first stage, the ECMC runs day-ahead 24-hour scheduling in order to estimate the flexible capacity of the LEC, which can be determined for each hour of the next day. The results should be submitted to the BSP before 11:00 a.m. of the day prior to delivery so that the BSP could be able to participate in the BCM and BEM with complete knowledge of its reserve units.
The second-stage scheduling, however, runs in real-time for the coming hour. Before this stage, the BSP participated in both BCM and BEM on behalf of its reserve units. Afterwards, the flexibility power that should be provided by the corresponding BSP was assigned by the TSO. Subsequently, the BSP determines the flexibility that needs to be provided by its reserve units. In this regard, the ECMC seeks to schedule the shared FERs to provide the assigned flexibility as well as maximizing the community's real-time profit. Fig. 2 summarizes the proposed two-stage scheduling framework for the studied LEC and its interaction with the upstream entities. According to Fig. 2, the main interaction of the LEC is with the BSP in day-ahead and real-time horizons. The BSP is in charge of creating bidding strategies in order to participate in balancing markets (BCM and BEM) on behalf of its reserve units and assign the reserve power to each reserve unit. The main responsibility of the TSO regarding mFRR services is clearing the balancing markets, assigning the reserve power to each BSP according to its required frequency-based flexibility and activating the reserved power when needed. However, the main focus of this article is on the optimized operation and scheduling of the LEC. Therefore, other issues such as the bidding strategy, reserve assignment, aggregation methods applied by the corresponding BSP and reserve market clearing performed by the TSO, as well as the calculation of the related flexibility need is not within the scope of this article (see the grey blocks in Fig. 2).  The proposed two-stage operation will be fully explained in Section III.

III. PROBLEM FORMULATION
The problem formulation of this article includes two stages, which are explained in detail as follows.

A. STAGE I: DAY-AHEAD FLEXIBILITY OFFER
In this stage, the ECMC runs day-ahead scheduling aimed at estimating the LEC's utmost capability to provide flexibility services for the 24 hours of the next day. The following factors are taken into account in the day-ahead stage: 1. EV owners in the LEC arrange their next-day exact plugged-in and plugged-out hours and submit it to the ECMC. Thus, the ECMC has the next-day temporal charging information of EVs. Note that it is assumed that EV charging is centrally controlled by the ECMC. In addition, for the sake of simplicity, they are assumed to be charged with constant power [33]. 2. The BESS can be monitored and controlled directly by the ECMC. Therefore, the ECMC has precise information regarding the BESS's capacity and estimates the BESS's next-day SOC based on its schedule. 3. The net-load of the LEC's members is predicted hourly for the 24 hours of the next day. In order to capture the stochasticity of consumption load as well as the PV generation, the error of the forecasted net-load is here taken into consideration, which can be modelled a Gaussian distribution [34]. Note that the net-load of the LEC is defined as the difference between its aggregated consumers' load and the LEC's PV generation. Regarding the probability distribution model of the net-load's forecasting error, different scenarios are considered for the first-stage schedule to consider the related uncertainties of the net-load originating from households' stochastic behavior. 4. Finally, flexibility is estimated in a time horizon of 24 hours with one-hour time granularity. Hence, each time slot refers to one hour in the first-stage scheduling. For each time slot, the community offers its upward flexibility or/and downward flexibility power based on the community's production surplus and the capability of its FERs (i.e. BESS and EVs) to change their consumption. In time slots during which the community's surplus is positive it can submit its entire surplus as upward flexibility capacity. In contrast to this, the maximum capability of the community to increase its consumption can be considered as its downward flexible capacity. It is worth mentioning that according to the proposed strategy, the LEC may offer both downward and upward flexibility at one hour in the day-ahead stage if it simultaneously has a positive surplus and some available FERs that can increase their consumption. However, one type of offer (downward or upward) will be accepted and assigned in real-time.

1) FLEXIBILITY ESTIMATION
As stated before, in the first stage the ECMC seeks to estimate the maximum upward and downward flexibility that can be offered for the 24 hours of the next day in order to submit this to the BSP for the provision of flexibility services. It is obvious that a requirement for participation in reserve markets like the mFRR is to declare capacity as reserve in previous day. Moreover, providing flexibility services is always much more profitable for the community, since the prices of balancing services is substantially higher than energy. Hence, the community should estimate the available flexibility that can be provided in the following day. The ECMC runs a stochastic optimization problem with the following objective function: Equation (1) shows that the ECMC's objective is to find the maximum upward and downward available flexibility which can be offered to the BSP for all of the considered scenarios and for all 24 hours of the following day.
According to [7], regarding balancing energy markets (BEM), the price of selling upward flexibility is always greater than the price of selling power to the upstream grid or energy markets. In addition, the price of buying downward balancing flexibility is always lower than buying power from the upstream grid or energy markets. Hence, it can be concluded that participating in balancing markets is always beneficial to the LEC. Thus, in the day-ahead stage, the energy community is merely aiming to find the maximum flexible capacities which can be offered in balancing markets.
The variable that helps to calculate the maximum upward flexible capacities of the LEC is defined by (2).
According to (2), the upward flexibility of the LEC should be obtained from the LEC's production surplus. The production surplus of the LEC is equal to the difference between the discharging power of the BESS and the aggregated values of net-load and EVs' charging power. The net-load of the LEC at hour t could be obtained from (3). Equation (4) The downward flexible capacity is known as the ability of the LEC's FERs to increase their consumption. Since EVs and BESS are considered as the existing FERs in this study, charging these resources can be taken into account as LEC's flexible consumption. Hence, the charging power of the mentioned resources can be considered as the LEC's available downward flexibility for scenario s and time slot t as stated in (4).
Equations (5) and (6) indicate that the charging and discharging power of the BESS cannot exceed their maximum rate, respectively. The binary variable u B,est t,s in (5) and (6) is employed in order to prevent the BESS from being charged and discharged simultaneously. This variable is considered to be 1 when the BESS is in a charging state, otherwise it is equal to 0.
Moreover, the net-load error is assumed to be represented by a Gaussian distribution denoted by E t (µ t , σ t ), where µ t is the mean value for error of forecast and σ t is the related standard deviation. These are obtained as follows [34]: Equation (7) shows that the standard deviation of the net-load is obtained from consumption demand and is related to the PV located in the LEC. The standard deviation of PV production is defined in (8) while the standard deviation of the total consumption load of the community is shown in (9). In (9), k is a function of the accuracy of load prediction [34].
The community can offer upward flexibility when it has a positive upward flexible capacity (i.e. the LEC's production surplus). Similarly, downward flexibility can be ascertained when the downward flexible capacity experiences a positive value, as stated by (10) and (11), respectively.
Since EVs are supposed to submit their plugged-in and plugged-out charging hours beforehand, the number of EVs being charged during each hour can be obtained simply by using (12).
Equation (12) states that the number of charging EVs at hour t is equal to the number of EVs charged in the previous hour plus the number of those beginning to charge at hour t minus the number of EVs which are supposed to be unplugged at hour t.
There exist constraints related to the operation of the BESS, which are indicated by (13) and (14). Equation (13) relates the estimated SOC of the BESS to its charging and discharging power. This constraint can also indicate the variation regarding the state of energy of the BESS. Equation (14) restricts the maximum and minimum permissible values of the estimated SOC, which implicitly limits the energy stored in the BESS as well.
The ECMC is proposed to adopt two control parameters, i.e. S OC min t and S OC max t , to control the amount of BESS's capacity deployed for provision of flexibility services. In day-ahead scheduling, there might exist some uncertainties related to the activation of balancing services, its direction (i.e. upward or downward) and those associated with forecasting PV production and demand. Therefore, the ECMC may decide to save some part of its BESS's capacity and deploy it in real-time schedules so as to avoid the risk of penalty costs related to not providing the assigned flexibility in real-time. For this purpose, the mentioned control parameters are employed to limit the day-ahead utilization of the BESS's capacity in providing TSO-level flexibility services. These parameters should be determined within a range introduced as follows: In (15) and (16), the value of SOC B,min and SOC B,max indicate the lower and upper limits of state-of-charge, where their values depend on the type of BESS. Equation (17) shows that the selected value for the lower controller of state-ofcharge, i.e. S OC min t , must be smaller than the upper controller of state-of-charge, i.e. S OC max t , at all times. Taking these constraints into account, if the gap between the adopted S OC min t and S OC max t decreases, it means that the ECMC prefers to offer a lower amount of its BESS's flexible capacity for reserve services and save a portion of its flexibility for the real-time scheduling (see Fig. 3). Fig. 3 indicates the amount of BESS's capacity deployed for flexibility offers in day-ahead. Accordingly, the expected amount of upward and downward flexibility in each time slot, which is supposed to be VOLUME 8, 2020 offered to the BSP, is obtained from (18) and (19).
After offering the total downward and upward flexible capacity by the ECMC, the BSP will then participate in balancing markets (BCM and BEM) by aggregating the flexibility offers of its reserve units.

B. STAGE II: REAL-TIME OPERATION AND SCHEDULING
Before the real-time stage, the TSO determines the power that should be provided by the BSP. In fact, the BSP has already participated in balancing markets and the results of the market settlement are specified in real-time. Afterwards, the BSP determines the amount of flexibility that should be provided by the LEC based on its day-ahead offer. Regarding this information, the manager of the community needs to schedule its FERs so as to achieve the following targets: 1. Fulfil the assigned power for mFRR provision 2. Maximize the total real-time monetary profits of the LEC In this manner, this article considers that the ECMC schedules the community's FERs for the next hour regarding four temporal quarters (15-minute timeslots), based on the assigned values of flexibility. Therefore, the time horizon and time granularity of the scheduling would be one hour and 15-minutes, respectively. The following factors are also considered in this stage: a. EV owners are assumed to adhere to their day-ahead plan. They plug in and unplug their vehicles at the exact hours they have stipulated beforehand, since they have accepted the content of the intra-community rules and must not violate their predetermined agreement signed with the community manager. In this regard, based on EV owners' desires and needs, the ECMC can schedule the vehicles for the next four quarters. b. EV owners are supposed to submit the minimum number of hours that they want their vehicles to be charged. This constraint is applied in order to take into account the EV owners' charging satisfaction. c. It is assumed that the ECMC monitors the real-time state of the FERs. Indeed, the ECMC updates the information regarding the SOC of the BESS and EVs at the end of each hour, based on the activated reserve. This information will be deployed for scheduling FERs for the next hour. d. PV power generation as well as demand forecasts are updated hourly. Since predictions with very short-time horizons (i.e. one hour) are relatively more accurate than, e.g. day-ahead forecasting, the results of PV/demand predictions are considered deterministic and not to be subjected to any uncertainties. e. After fulfilling the assigned value of TSO-level flexibility services, the ECMC trades the surplus power with the upstream grid through a DSO or a retailer.

1) LEC SCHEDULING
According to the assumptions above, the ECMC runs an optimization problem with the objective of maximizing the community's real-time profit, denoted by (20). Profit is defined by (21). In addition, (22) denotes the income or cost obtained from the LEC's participation in reserve provision. By using the objective function indicated by (20), the optimization problem seeks to find a compromise between flexibility obtained from its FERs and profits of the LEC.
On the left side of (21), Profit real−time t,m indicates the total profit of the LEC in real-time. On the right side of this equation, X represents the income or cost due to the provision of capacity and energy related to mFRR services.
According to (22), the LEC receives a fixed monetary amount which is paid for offering flexibility capacities (both upward and downward), denoted by I cap t . In fact, this income is obtained by the participation of the BSP in the BCM. In addition, the LEC receives the income for selling upward energy (I en,up t ) and incurs the cost for purchasing downward energy (C en,dn t ) from the BEM. In this manner, the BSP plays the role of an intermediary by participating in the BCM and BEM.
The remaining terms of (21) are as follows. The term Income II denoted the revenue resulting from selling energy to the upstream grid through the DSO or the retailer. The term CostII denotes the cost of purchasing energy from the grid. The last term, CostIII , refers to the operating cost of charging and discharging the BESS. It has to be mentioned that C B is the operating costs of charging/discharging the BESS, which are considered constant over the studied time and obtained as follows [35].
where DOD B indicates depth of discharge of the BESS. The rated lifetime and the replacement cost of the BESS are denoted by RL B and RC B , respectively. The main priority of the LEC's real-time scheduling is to provide the assigned flexibility services, i.e. F up,as t and F dn,as t . However, to satisfy power balance constraint within the LEC, the ECMC should trade surplus power with the upstream grid. Accordingly, (24) In (24), u up t,m and u dn t,m are binary parameters which have been determined by the BSP according to the market settlement results of the BEM. In other words, these parameters provide information on whether the TSO requires downward or upward flexibility services. According to (24), in the case of providing downward flexibility, u up t,m is equal to 0 and the consumption power of the net-load and the charging power of the BESS and EVs is supplied by the imported power from the upstream grid, as well as the downward flexibility power bought from the BEM. Similarly, in the case of providing upward flexibility, the positive power surplus of the LEC is sold to the upstream grid after fulfilling the assigned upward flexibility. It should be noted that F dn,as t and F up,as t are parameters whose values have been specified by the BSP.
Ifp in t,m , which is obtained from (24), has a positive value, this means that the LEC is not self-sufficient and the required energy should be supplied by the grid. The imported power then would be equal to P in t,m . Similarly, ifp out t,m has a positive value, this means that there exists some production surplus that should be sold to the grid. Thus, the exported power equals P out t,m , as denoted by (25) and (26).
In the proposed real-time scheduling, each EV is being scheduled to maximize the community's profit. Equation (27) - (31) are constraints related to charging the community's EVs. It should be highlighted that all EVs are supposed to be charged with a constant power rate, denoted by P EV .  (31) In (27), (29) and (30), u EV i,t,m is a binary decision variable which determines the charging status of EV i during quarter m of hour t. This variable is equal to 1 if EV i is being charged during quarter m of hour t. Otherwise, it equals 0. Accordingly, (27) expresses that the total number of EVs that are being charged during time slot m of hour t is obtained through the summation of the binary variables related to the charging status of all EVs within the LEC. Equation (28) determines the number of quarters that an EV needs to be charged during a given hour. As previously stated, in the real-time stage, the scheduling time granularity is 15 minutes (one quarter) and the scheduling time horizon is one hour. Therefore, considering the one-hour time horizon, if an EV needs to be charged for one hour (four quarters). To elaborate this constraint, consider that EV i requests to be charged for at least one hour (i.e. req i = 1). This EV, for instance, was plugged in at 8:00 and unplugged at 12:00, so it was plugged in for four hours (i.e. t plugged i = 4). Therefore, according to constraint (28), this EV should be charged at least one quarter in each hour during for which the vehicle is plugged. Through the ECMC, the community manager decides how the EVs should be charged in the plugged in periods. In order to keep all parties satisfied, it is feasible to spread the charging quarters over the plugging time, rather than charging them in a limited period. This could reduce possible peak loads during some hours.
The constraints related to EVs' battery SOC are presented by (29) and (30). It should be mentioned that the 4 th quarter of hour (t-1) is followed by the 1 st quarter of hour t, as explained in (29). Regarding the first equation of (29), the EVs' SOC in the 1 st quarter of each hour should be determined based on its actual value in the 4 th quarter of the previous hour, because the actual value of EVs' SOC may not be equal to that scheduled in the previous hour. Since the activated and assigned values of reserve power may not be equal, the scheduled values of EVs' SOC need to be replaced with the actual values. However, for the 2 nd to 4 th quarters of each hour, the values of EVs' SOC could be obtained based on their scheduled values in the previous quarter, as explained in the second equation of (29).
Equation (30) restricts the maximum value of the SOC of EVs' batteries. Finally, (31) ensures that the EVs will only be charged during the hours in which they are plugged in, meaning that they should be charged in a range which is part of the EV's plugged-in/plugged-out time window. Otherwise, the optimization solver should assign a zero value to the charging status of the EV.
In the following, the constraints related to the BESS are presented. Equation (32) and (33) elaborate the constraints associated with the SOC of the BESS. In (32) and (33), if we multiply both sides of the BESS's capacity, we will have the related constraints of the BESS's state-of-energy. Again, the scheduled value of the SOC for the previous hour (t-1) should be replaced with the actual SOC of the BESS. This value is utilized to schedule the BESS at hour t. The BESS will be charged/discharged only when needed. This need is the amount of energy required for balancing purposes, which is announced by the BSP/TSO. However, the BSP/TSO always asks for flexibility within the LEC's capability. The TSO would not ask for more than the LEC can offer.
Finally, (34) and (35) restrict the charging and discharging power of the BESS, respectively [36], along with the fact that the BESS is not allowed to be charged and discharged simultaneously, with the help of binary variable u B t,m .
The ECMC runs this optimization problem considering (20)- (35) for each hour, to schedule its FERs including the BESS and EVs as well as its trading power with the upstream grid, aiming to maximize the community's real-time profit. Before starting the next-hour scheduling, the SOC of the BESS and EVs for the previous hour, i.e. SOC B,act t−1,4 and SOC EV ,act i,t−1,4 , are updated based on the real data resulted from the activated mFRR. Thereafter, the realtime scheduling is run for the next hour (next four quarters), accordingly.
It should be mentioned that decreasing the charging rate of the BESS as flexibility-up, or increasing the discharging rate of the BESS as flexibility-down, could be considered as flexibility, which actually happen in real-time operation of the BESS in the process of flexibility provision. However, counting on them as the capacity for participation in the mFRR market would not be a wise choice. For instance, in a case where we are dealing with the constant BESS's power rates, counting on the above-mentioned strategy for flexibility provision would not be generally applicable. Moreover, the change in the power rate of the BESS might not satisfy the offered flexibility.

IV. NUMERICAL STUDIES A. CASE STUDY
The case study consists of a hypothetical LEC with 50 households. This community has a 100kW PV system as well as FERs, including a 50kW/200kWh (Vanadium Redox Flow) BESS and 10 EVs. The information on EVs' pluggedin/plugged-out status and the EVs' battery capacity can be found in TABLE 2. It is also assumed that EVs request to be charged at least for two 15-minute quarters. Moreover, the information related to the characteristics of the BESS in the simulation studies is given in TABLE 3 [37]. The forecasted day-ahead as well as actual values of demand and solar generation are depicted in Fig. 4. The pattern of solar irradiation is based on the historical data for July 7, 2019 in Finland [8]. The forecasting error of PV generation in the day-ahead study is represented by an independent normal distribution with a zero mean value and a 10% standard deviation. Similarly, the forecasting error of the demand load is also modelled with a zero mean value and a 2% standard deviation.

B. SIMULATION RESULTS
The simulation in this article was executed on a laptop with an Intel Core-i5 6200U 2.3GHz CPU and 16GB of RAM. The optimization algorithms were implemented by using the well-known GAMS programming software.

1) DAY-AHEAD FLEXIBILITY OFFER
In order to conduct the introduced stochastic study, 1000 scenarios were produced by utilizing Monte Carlo simulation for PV generation and load demand of each hour. Afterwards, the optimization problem defined in (1)- (19) was solved for the LEC introduced in this section. It is noticeable that a linearization technique was utilized, similar to the one deployed  in [38], so as to linearize constraints (10) and (11) (see APPENDIX). The total daily values of upward and downward flexibility offered to the BSP are calculated based on different SOC-based control parameters and the results are illustrated in TABLE 4. It should be noted that the control parameters are given as constant for 24 hours. In addition, the degree of BESS utilization (DBU) for offering flexibility is calculated for each case using the following equation (36): Regarding TABLE 4, all of the considered cases lead to three pairs of total upward and downward flexibility offers, i.e. ( t F up t t F dn t ), which are (583.9 780.5), (133.9 180.5) and (83.9 80.5). In light of this conclusion, we narrowed down all considered cases into three groups based on the values of available flexibility, namely G1, G2 and G3. These groups are illustrated by three different colors in TABLE 4.
The hourly upward and downward flexibility of these groups have been calculated and the results are depicted in Fig. 5 and Fig. 6, respectively.
According to TABLE 4, in general, the amount of upward flexibility and downward flexibility offered to the BSP decreases when S OC min t increases. However, this effect does not seem to be significant when the other control parameter, i.e. S OC max t , has a lower value. Although the higher value of S OC min t leads to a lower amount of offered flexibility for cases 1, 2, 3 and 4, this trend does not strongly continue for  Since the community's production surplus is negative in the early hours of the next day, discharging the BESS can provide upward flexibility during these time slots. As a result, the lower values of S OC min t enables the LEC to provide more upward flexibility through BESS discharging. In comparison, higher values of S OC max t do not necessarily lead to a higher amount of flexibility. Case 4 is an example with a high value of S OC max t while having the lowest values for the total flexibility offer. Fig. 5 shows that the LEC is able to provide upward flexibility during 09:00-14:00, even in the cases with low DBU (i.e. G3). Considering Fig. 4, the production surplus is positive during 09:00-14:00, which enables the LEC to provide upward flexibility even without the help of the BESS. As Fig. 5 shows, for G1, the LEC can offer upward flexibility in most of time slots. In addition, the only difference between G2 and G3 is that G2 is able to offer additional flexibility during hour 05:00 by utilizing the BESS. Fig. 6 demonstrates that the LEC of G1, G2 and G3 is able to provide downward flexibility during time slots when EVs (see TABLE 1) are being charged in all of the considered cases. As mentioned before, the only resources for the provision of downward flexibility are regarded to be EVs and the BESS. Since in G3 the LEC utilizes less than 50% of its BESS's capacity, the downward flexibility of this case is mostly provided by charging the EVs. However, G1, which deploys greater BESS capacity, is able to offer downward flexibility in most of the time slots. Although the downward flexibility offered by G2 is approximately similar to the amount offered by G3, the community of G2 utilized its BESS at 07:00 to provide more downward flexibility. Note that EVs are plugged in after 08:00, meaning that the downward flexibility offered at 07:00 was provided solely from the BESS.

2) REAL-TIME SCHEDULING
In real-time, the BSP specifies the amount of flexibility that should be provided by the LEC. In order to obtain the assigned amount of flexibility, we extracted information on the type of flexibility activation during the specific day (i.e. July 7, 2019) from the Finnish TSO's open data [8]. Subsequently, based on these data, the BSP accepts either the upward or the downward flexibility. In a few time slots there exist no need for mFRR deployment, which implies that no flexibility offers are accepted. Note that it is assumed that the total amount of offered flexible capacity by the LEC, which are compliant with the flexibility needs, were fully accepted and assigned by the BSP. Fig. 7 and Fig. 8 illustrate the respective assigned and activated values of upward flexibility required to be provided by the LEC. Fig. 9 and Fig. 10 depict the respective assigned and activated values of downward flexibility required to be provided by the community. The activated amount of   flexibility is also deployed based on the data of activated balancing power obtained for July 7, 2019 [8], and depicted in Fig. 7 to Fig. 10. The amount of assigned and activated flexibility is calculated for the three groups considered in the previous section, G1, G2 and G3.
The flexibility prices for provision of upward and downward balancing services are considered to be known in real-time and are presented in Fig. 11 [8]. These prices are extracted from the information on the prices of balancing energy markets on July 7, 2019, which are determined by the Finnish TSO, Fingrid. Moreover, the dynamic prices of trading energy with the grid is also shown in Fig. 11, based on one of the Finnish DSOs' open data [39]. As can be seen in the figure, the price of selling upward flexibility are always  equal to or greater than the price of selling power to the grid. Additionally, the price of buying downward flexibility is always equal to or lower than the price of buying power from the grid.
The optimization problem introduced through (20)-(35) has been solved for the proposed LEC. A linearization technique (see APPENDIX) is exploited to handle the non-linearity caused by (25) and (26), with the purpose of obtaining a mixed-integer linear programming (MILP) formulation. The input data on the SOC of the EVs and the BESS were considered to be updated based on the actual activated reserve, and the results of 24 hours are obtained. Fig. 12 illustrates the hourly real-time profits of the community for one day, considering four different cases. These cases consist of three groups introduced in the previous section (i.e. G1, G2 and G3), which consider the LEC adopting different BESS control parameters in its day-ahead schedule, along with a case that suggests the LEC's operation with no contribution to reserve provision (i.e. the LEC trades only with the upstream grid and does not tend to participate in reserve provision). Fig. 13 denotes the total net-costs of the LEC on the considered day. The share of daily income and costs stemming from different resources are also illustrated in Fig. 14.   By comparing Fig. 12 with Fig. 4, it can be concluded that the profit of the LEC leads to positive values in time slots when the LEC has production surplus. However, in the rest of the time slots, the profits mostly exhibit negative values, meaning that the community is required to purchase power either from the upstream grid or by providing downward flexibility services in order to meet its demand. After solving the optimization problem for different cases, it was concluded that the LEC of G1 and G2 was not able to provide the assigned reserve during some time slots. Consequently, in these cases, the LEC is assumed to buy energy from the upstream network (through the DSO or retailer) so as to fulfil its assigned flexibility. Hence, in a few hours of the day, the profit curves related to G1 and G2 experience a considerable decrease. By comparing G1 with G3, it could be realized that G1's curve fluctuates more than G3's. Although in a limited number of hours G1's curve experiences higher profits (e.g. during time slots 02:45 and 11:15 to 11:45), it incurs more costs early in the morning (e.g. during time slots 02:00-02:15, 03:15, 05:15 and 15:00-15:45). Fig. 13 indicates the correlation between the day-ahead selection of control parameters and the real-time net-cost of the LEC. It shows that the total net-cost of G1 is higher than that of G3 for the studied day. The same situation with a lower degree happens for G2, resulting in a higher total net-cost compared to G3 (see Fig. 13). In comparison, the case in which the LEC does not participate in reserve provision leads to the total cost which stands in the second rank, compared to the three studied cases. This means that the total net-cost of the case in which the LEC decides not to participate in reserve provision is higher than the net-costs of G3 and G2, but lower than that of G1. By comparing cases with different control parameters, i.e. G1, G2 and G3, it can be concluded that it is more profitable when the LEC deploys less BESS capacity in its day-ahead flexibility offer. In other words, according to fig. 13, the LEC made more profits when it chose a high value for S OC min t and a low value for S OC max t . Fig. 14 illustrates the sources of costs and incomes of the LEC, taking into account different cases. According to the community's day-ahead schedule, the income obtained from trading TSO-level flexibility is greater for G1, followed by G2 and G3 respectively, in terms of obtaining reserve-related income. The LEC is not able to benefit from flexibility provision if it does not claim its flexibility capacity in day-ahead, as stated in the bar chart of this case in Fig. 14.
However, the costs of real-time energy trading for G1 and G2 increase, as they need to compensate for hours during which they were not able to provide the assigned flexibility. In addition, in these cases the LEC sold a considerable amount of its production capacities through their day-ahead schedules in order to provide TSO-level flexibility. As a consequence, the community is not able to sell this part of their capacity to the upstream network, which leads to a decline in energy-trading income. Moreover, Fig. 14 implies that the higher participation of the LEC in reserve provision leads to more utilization of BESS capacity in real-time. Therefore, the operating costs of the BESS increase if the LEC provides more flexible capacity. Fig. 15 visualizes the power sold/purchased to/from the upstream network. Positive values are related to the input power while negative values show the output power exported from the community. It expresses that the LEC of G1, G2 and G3 sells a negligible amount of its capacity to its upstream network, whereas in the case with no reserve provision, the community is able to sell all of its production surplus to the upstream grid. This is due to the fact that in G1, G2 and G3, the LEC sold most of its production capacities for reserve provision. When it comes to the amount of energy imported to the community, a short-term fluctuation for the LEC of G1 can be seen, owing to fulfilling its assigned upward flexibility offers. These fluctuations occur in few time slots during the early morning as well as from 21:00 to 23:00. Similar fluctuations could be seen for the LEC of G2 in some quarters during 22:00.
The SOC variation of the BESS for different cases is illustrated in Fig. 16. This figure explains that the participation of the BESS in reserve provision leads to greater utilization of the BESS. Comparing the SOC of the BESS for the LEC of G1 and G2 with that of G3 points out that the higher participation in reserve provision results in more variation in the SOC and thus more deployment of BESS capacity. In other words, the LEC of G1utilized a higher amount of its BESS capacities and therefore experienced more fluctuations in terms of its BESS' SOC. In comparison, these fluctuations decrease for the LEC of G2 and G3. In this manner, the case with no reserve participation deploys the BESS's capacity only from 22:00 to 24:00. In the ''No reserve participation'' case, the LEC does not take advantage of the charging capacity of the BESS at all. Note that the minimum allowed values of the BESS's SOC and of its initial SOC were assumed to be 0.2 and 0.5, respectively. Moreover, Fig. 16 shows that the LEC utilizes the discharging capacity more frequently than the charging capacity.
Finally, the number of EVs being charged in different time slots is illustrated in Fig. 17, considering the studied cases. The daily number of charging quarters for all of the EVs in the considered day (i.e. i t m u EV i,t,m ) is shown in TABLE 5. This table explains how much the LEC utilized the charging capacity of EVs. The results discuss the fact that the number of charging EVs is greater in the case when the LEC does not tend to provide reserve, and it decreases for the other cases. The total number of charging EVs reaches its minimum value for G1, since it had to provide higher upward flexibility in most of the time slots, which leads to less utilization of charging EVs' (i.e. downward flexible capacity). In this manner, LECs of G2 and G3 place in the middle rank in terms of charging their EVs.

V. CONCLUSION AND FUTURE WORKS
This article deals with the optimal scheduling of an LEC participating in the provision of mFRR services. The LEC is considered to have shared assets, enabling it to contribute to the reserve provision. The scheduling comprises two stages. In the first stage, the ECMC seeks to determine the offered flexibility which should be submitted to the BSP in the day-ahead stage. In this stage, control parameters are deployed so as to manage the degree of the BESS utilization for offering the flexible capacity. In the second stage, the ECMC aims to maximize the community's real-time profit for each hour. The real-time stage also takes into account the assigned flexibility that should be provided in the following four quarters and the activated flexibility during the previous hour.
The proposed scheduling method was applied to a case study, comprised of a hypothetical LEC with a PV system, a BESS, EVs and several households as residential consumers. The paper utilized the structure of Finnish balancing energy and capacity markets related to mFRR procurement for the simulation. Hence, the data regarding reserve market prices, dynamic tariffs and solar power were fully extracted from the related Finnish utilities (Finnish TSO and DSO) and markets. The results demonstrate that the control parameters chosen in the day-ahead schedule can strongly affect the real-time profitability of the LEC. It was also concluded that the cases in which the LEC utilized a low capacity of the BESS in its day-ahead schedule were more profitable compared to those cases in which the BESS capacity was highly utilized. Moreover, the cases which deploy lower capacity of the BESS were more profitable in comparison with the cases where the LEC did not participate in mFRR provision. According to the simulation results, which were based on input data extracted from the real-world reserve markets, the participation in mFRR provision can be profitable for the LEC as a distribution-network-located energy resource. Hence, participating in providing mFRR ancillary services not only helps the TSO, but also increases profits for the LEC. However, the careful utilization of the BESS in estimating the LEC's day-ahead available flexibility is vitally important in real-time profitability and the LEC's optimal real-time operation. Finally, this article could be expanded in the future by analyzing the following directions: a) LECs providing other types of flexibility services such as FCR-N or FCR-D to the TSO. b) The provision of flexibility from LECs in the most recently introduced FFR market could also be considered as another important study. c) Different kinds of FERs in energy communities such as thermostatically controllable loads and thermal storages could be analyzed for flexibility provision. d) The TSO's responsibilities related to calculating flexibility needs and clearing each flexibility market (FFR, FCR, FRRs) according to the calculated requirements.

APPENDIX
As mentioned in the simulation section, we utilized the same approach as [37] to linearize (10), (11), (25) and (26). All of these constraints are in the form of the following equation.
In (37), A and B are two variables. In this case, an auxiliary binary variable V is adopted and constraint (37) will be replaced with the following constraints: where M is a large number, which was chosen to be 10000 in our problem. In this manner, if B becomes negative, V and A equal 0. Otherwise, V is equal to 1 and A is equal to B, accordingly. He has previously worked as a Principal Engineer at ABB Ltd., Vaasa. He is currently a Professor of Electrical Engineering with the University of Vaasa. He is also the Manager of the Smart Energy Master's Program. His research interests include the protection of low-inertia power systems (including microgrids), active management of distributed and flexible energy resources in future smart energy systems and future-proof technology, and market concepts for smart grids. VOLUME 8, 2020