Peer-to-Peer Energy Trading for Improving Economic and Resilient Operation of Microgrids

Peer-to-peer (P2P) energy exchange is a popular market mechanism which enables the transaction of energy in local communities. The advantages of this method for different stakeholders has been demonstrated in the literature. However, the effect of P2P energy exchange on economic and resilient operation of microgrids (MGs) has not been studied yet. This paper presents a P2P energy exchange framework for improving economic and resilient operation of MGs. The proposed method considers the synergistic benefits of system operator and end-users in terms of: a) economic benefit from participation in in the market, b) system resilience improvement, c) battery lifetime improvement, and d) carbon emissions reduction. The proposed method optimizes the battery sizing and operation, while categorizing and prioritizing the end-users. In order to evaluate the effectiveness of the proposed method, it has been applied to four different geographical locations with various Time-of-Use tariff schemes, and is tested against different fault scenarios. The results show that the proposed method can improve the resilience up to 80%, while battery lifetime can be prolonged by 32% - 37%.


Nomenclature a, b, c, d, e
Degradation model coefficients Battrated (k) The battery size (rated capacity) of each battery k BBAU (k,n) The benefits gained for the BAU scenario (in £), for each user k, for each representative day n BP2P(k,n) The gained benefits from P2P for each user k, for each representative day n BP2P-CO2(k,n)) The benefits gained due to carbon emissions savings for each user k, for each representative day n BP2P-PV(k) The benefits gained for each kWh that is provided to the grid from the PV surplus, of each user k BP2P-tot (k,n) The benefits gained from P2P energy exchange process for each user k, for each representative day n Btot(k,n) The total benefits each user k gains for each representative day n Cbatt The current battery prices CBAU (k,n) The total cost paid to the grid (in £), for BAU scenario by each user k for each representative day n CCO2-saved(k,n) The tariff paid for each tone of carbon emissions that is saved Cdeg(t,k) The degradation cost for each discharging event, at time t for each battery k Cgrid-BAU (k,n) The cost paid to the grid (in £) by each user k, for each representative day n

Cgrid-P2P(k,n)
The total cost paid to the grid for P2P process by each user k (in £), for each representative day n, including battery charging cost CHT The high tariff of the existing ToU tariff scheme Cinv(k) The inverter cost of each inverter k Cinvest(k) The investment cost for each user k CLT The low tariff of the existing ToU tariff scheme CP2P(k,n) The total cost for P2P energy exchange process for each user k, for each representative day n

CP2P-tariff
The tariff paid for each kWh delivered during the P2P energy exchange process

CPV-surplus
The reward provided for each kWh fed into the grid CPV-surplus (BAU) The FIT paid for each kWh fed into the grid by the PV E1 The total energy loss (kWh) due to fault 2 Ebatt-sc(k,n) The energy needed for self-consumption , for each user k during the P2P energy exchange period for the day n Emax(k) The maximum energy that can be discharged from the inverter of user k Emax-batt (k) The maximum energy that can be discharged from the battery of user k Enet-tot (k,n) The total net energy for the BAU scenario for each user k, for each representative day n EPV (k,n) The energy produced from the PV panel of user k, for the day n

EPV-surplus(k,n)
The energy surplus produced from the PV of each user k, during P2P energy exchange for each representative day n Etot-P2P(k,n) The total energy required during the P2P energy exchange period by each user k and for each the day n I(t,k) Discharging current of battery k at time k Imax (k) Maximum discharging current of battery k lossbatt(k) The percentage of estimated battery losses for each battery k, for each representative day n PB(k) The cost of each battery k Pinv(k) The maximum power that can be discharged by the inverter of user k PL (t,k) Load demand at time t for user k Pnet(t,k) Net power at time t for user k PPV(t,k) PV generation power at time t for user k q Discount rate Qcycle loss %(t,k) The percentage of cycle loss due to the discharging event, at time t for each battery k r The reduction tariff offered to the users participating in the P2P process SoC ( The total minutes of disturbance of all users TP2P-end Time that P2P energy exchange process ends TP2P-start Time that P2P energy exchange process starts WCO2-saved (k,n) The amount of carbon emissions saved from each user k, for each representative day n y years ΔΤP2P The duration of P2P energy exchange process η The threshold of maximum cycle loss I. INTRODUCTION Microgrids (MGs) are small-scale power systems consisting of self-controllable interconnecting distributed energy resources (DERs) and load customers within clearly defined electrical boundaries [1].Microgrids can operate in grid-connected and islanded modes.In the grid-connected mode, the microgrid exchanges power with the main grid, while in the islanded one, it operates independently from the main grid, relying on its own assets for power and energy needs [2].With the increasing number of natural disasters due to climate change issues and the rise in the penetration level of renewable energy sources (RESs), the optimal control and management of MGs is becoming a challenge for system operators.The former brings about contingency conditions in the network while the latter is the reason for the challenge of low-inertia networks.MGs could be the most vulnerable to faults, as the vast majority of failures occur at this level of the grid, and security standards are less onerous [3].Therefore, improving the resilience of MGs while considering the economic perspective is an important issue of evolving energy grids.Numerous metrics have been proposed to quantify resilience, such as percentage of load loss under extreme conditions, level of disturbance, duration of disturbance, load served, and number of users disturbed [4].A novel way to control efficiently MG assets is to establish smallscale energy zones, in particularly designated areas of these systems [5].
Several methods such as network reconfiguration [6], hardening schemes [7], and battery energy storage [8] have been utilised to improve system resilience.Meanwhile, with increasing the necessity of activating the engagement of end users in the grid, the emergence of prosumers in the MG can facilitate the efficient operation of MGs in different modes, and this paradigm can be efficient in improving the economic and resilient operation of MGs.Prosumers can both produce and consume energy, while actively modifying their consumption depending on the prevailing conditions [9].These developments can also enable the introduction of local energy networks, in which each peer can trade energy.This framework is widely known as peer-to-peer (P2P) energy exchange where prosumers can share their energy with their peers, without mediation by an energy supply company [10].
A P2P scheme enables users to exchange their energy surplus (or the flexibility) of their demand with other end-users, which can benefit both energy producers and consumers [11].High diversity of generation and load demand offers great potential for P2P sharing.P2P energy exchange schemes have been implemented in different countries, including USA, New Zealand, United Kingdom, Spain, Portugal and Australia [12].
P2P energy exchange is a novel approach which enables the local energy exchange and allows the participants to cooperate or compete in a local market.Current literature on P2P energy exchange mainly focused on market design and pricing mechanisms, which can be either competitive or cooperative.
In competitive approaches, the prosumers behave independently to gain benefits.In [13], a biding strategy is developed for ancillary services, where customers' benefit has been maximised by participating in the local market.The P2P energy exchange proposed in [14] considered the different social and environmental criteria as the main objective of the participants.The authors proposed a bilateral P2P energy exchange process with energy contracts among prosumers.The impact of P2P energy trading on the penetration level of RESs is investigated in [15] where an optimal energy exchange happened between two prosumers which were aiming to minimise their operational cost.The P2P energy trading can be applied to different technologies.P2P energy trading between two sets of electric-vehicles (EVs) is analysed in [16], to reduce the impact of charging process on the system during the business hours.
P2P energy exchange schemes under a cooperative approach have been developed under different game-theory basics.In [17], a cooperative P2P energy exchange scheme is established, where the prosumers form coalitions to gain benefits as a whole.
Coalition formation is also investigated in [18] under the Blockchain concept, to establish P2P trading among different microgrids.
Reference [19] used game theory to find the ideal incentive structure, to allocate payments among peers.
The P2P energy trading approaches are considered from a centralized and decentralized perspective.A comparison between a centralized and decentralized approaches is provided in [20].Decentralized approaches based on Blockchain have been presented in the literature [21,22], either to create smart and safe contracts for prosumers or to increase the integration of renewables, by providing incentives for the users.In [23], the impact of users' preferences on line congestion and renewable energy surplus is analysed under centralised and decentralised P2P energy exchange frameworks.A centralised P2P energy exchange strategy is proposed in [24] for a community of buildings to optimise building to building and building to grid strategies under a local market mechanism.
Different intelligent metaheuristic approaches such as fuzzy multi-objective programming [25], teaching learning-based optimization [26], genetic algorithm [27], particle swarm optimisation [28], etc., are proposed in the literature for improving optimal operation of MGs.The main drawback of metaheuristic methods compared to mathematical models such as linear programming, however, is related to the optimality of the results.The latter approaches can guarantee the optimal solution.
Nevertheless, for large-scale mixed-integer non-linear problems, metaheuristics can provide a good-quality solution although they cannot guarantee the globally optimal solution, whereas classical optimization could possibly have difficulty to solve such a problem [29].
In the recent literature, P2P energy exchange has been utilised for improving different aspects of the network.In [30], the authors presented a multi-market paradigm based on P2P energy exchange, with trading among nano-grids, so as to eliminate energy imbalance and frequency regulation procurement.The dynamic network structure is investigated in the context of P2P energy exchange in [31], where the authors developed a P2P energy sharing model along with a dynamic network model to reduce power losses.
The literature review shows that a wide range of papers has been published on the P2P energy exchange and the market design approaches.Recent studies have also demonstrated the importance of P2P in improving various characteristics of the network, such as frequency regulation, grid structure and operation.Also, some studies investigated the role of batteries in the context of P2P energy exchange.One of the main concerns of lithium-ion batteries is the capacity loss, known as degradation effect [32].
Degradation effect occurs either when the battery remains idle (calendar degradation) or when the battery is operating (operation degradation).While the calendar degradation is irreversible effect, operation degradation can be mitigated by controlling specific parameters of battery operation.However, there are some critical technical aspects that are missing in the literature.System resilience and battery lifetime are two major concepts that require further exploration.Mitigation of degradation leads to the extension of battery lifetime, increasing the potential benefits for the stakeholders [33].
Considering the importance of the P2P approach, this study fills this gap by introducing a novel P2P energy exchange framework for microgrids to improve their economic and resilient operation.The main goals of the developed methodology are to: a) improve system resilience, b) increase battery lifetime, and c) provide economic benefits for the participants.The proposed model is developed based on a planning mode where the number and the size of batteries is defined in the system.A model is proposed based on the NPV, where only the users with positive investment outcomes will install a battery.Then in the operation mode, the participation of battery owners in the P2P energy exchange is categorized based on their contribution to the economic and environmental objectives.This categorization is utilised to prioritize the users in the MG.This prioritization then defines different zones of the network.After defining the boundaries of the MG, the power output of batteries is optimized using a mathematical model defining the optimal charging of batteries subject to their life cycle.The proposed methodology relies on a ToU tariff scheme, to value benefit in time-shifting demand to low-cost periods, and the main goal is to define its influence on the economic and resilient operation of the network.Two groups of stakeholders are considered: A) the local system operator and B) the microgrid users.The stakeholders agree in advance to share the cost and benefits of P2P energy trading.Energy sharing is regulated and followed by all participants according to the rules explained in each step, taking into consideration transformer and storage inverter power limits.The energy trading occurs under three principles: a) by using the storage and renewable assets of the microgrid, b) P2P energy exchange is enabled during the high-tariff period, and c) it is based on the mutual benefits to the system operator and microgrid users.The main contributions of this paper are the following: 1) Investigation of the impact of P2P energy exchange on system resilience enhancement, by using the storage assets of endusers.A range of cases is examined, achieving a resilience enhancement of up to 80%.
2) Investigating the effect of P2P energy exchange on battery lifetime.Optimization to minimise battery degradation resulted in a battery lifetime improvement of 32% -37%.
3) The proposed framework is generalised and tested for four different locations (Newcastle, New York, New Delhi, Athens) and several different Time-of-Use (ToU) tariff schemes.The model identifies the input parameters values, for which the framework is beneficial to the stakeholders, and can be applied to any microgrid.
This paper is organized as follows: Section II presents the proposed P2P methodology.Section III describes the fault scenarios and case study.Simulation results are given in Section IV.Finally, Section V concludes the paper.

A. Battery sizing
The presented methodology includes two different modes: planning and operation modes.In the planning mode, the number and the size of storage assets are not defined in advance, thus a battery sizing process is required.In operation mode the storage assets are predefined thus the sizing process is not required.
In planning mode, each MG user is willing to jointly buy a battery with the DNO so as to participate in P2P process, in case that benefits are gained.This will determine the total number of batteries and their size in the MG.The contribution of each stakeholder to the investment cost and the percentage of benefits gained, is settled in advance.The expected benefits for each potential battery owner are then estimated.Initially, it is assumed that all users have batteries.A cost-benefit analysis (CBA) is performed for each of them, seeking the optimum battery size for which their benefits (if there are any) are maximised.For this purpose, the net present value (NPV) is the metric against which different battery sizes are assessed.With a positive NPV the user gains benefits for the considered parameters, whereas for a negative NPV the user does not gain benefits after the payback period, meaning the battery purchase is not a profitable option.If the benefits are satisfactory, the user installs a battery asset.In this study, it is assumed that all the load and the power generation are known.The net power,  (,) at an individual home is: where  (,) is the load demand and  (,) is the power generated by the PV panel (in kW), for each timestep  and for each user .The duration of P2P energy exchange process in the time period ∆ 2 is: where  2− is the time when P2P ends; and  2− is the time P2P starts (in minutes).For a particular ToU tariff scheme, this parameter remains constant.It is assumed that each user has one inverter connected, both to the PV panel and the battery.The inverter first covers the power from PV panel and then from the battery of the user.The maximum energy (in kWh) that can be discharged from the inverter of each user ,  max() during the P2P period, is: where  () is the maximum power limit of each user's inverter device (in kW).The maximum energy (in kWh) that can be discharged from the battery,  −() is: where  (,) is the energy produced from the PV panel (in kWh) of each user , for each representative day  that passes through the inverter.During the P2P energy exchange period, each user uses its battery first for self-consumption and the remaining energy, for the P2P energy exchange.The energy needed for self-consumption (in kWh), for each user  during the P2P energy exchange period,  −() is: where  −2(,) is the total energy required during the P2P energy exchange period by each user  and for each representative day ; and  −2(,) is the total energy produced by the PV panel during P2P energy exchange period, for each user  and for each representative day  (in kWh).The benefits gained (in £) for each kWh that is provided to the grid from the surplus of each PV, of each user ,  2−() is: where  −(,) is the energy surplus (in kWh) produced from the PV of each user , during P2P energy exchange for each representative day ; and  − is the reward provided for each kWh (in p/kWh).The tariff paid (in £) for each kWh delivered during the P2P energy exchange,  2− is: where   and   are the high and low tariffs of the existing ToU tariff scheme, respectively (p/kWh);  is the reduction tariff (p/kWh) offered to the users participating in the P2P process, that have no batteries under their ownership; and  is the percentage of participation of each user to cost and benefits (% percentage).The gained benefits (in £) from P2P for each user , for each representative day ,  2(,) is: where  () is the percentage of estimated battery losses for each battery , for each representative day .P2P energy exchange will achieve carbon emissions reduction if the grid carbon intensity is lower during the low-tariff (LT) period and higher during the high-tariff (HT) period.This will happen as batteries are charged during the LT period and discharged during the HT period.The benefits gained due to carbon emissions savings for each user , for each representative day ,  2−2(,) is: where  2−(,) is the amount of carbon emissions saved from each user , for each representative day  in tones; and  2−(,) is the tariff paid for each tone of carbon emissions that is saved (£/tn CO2 saved).This tariff is specified by the implemented carbon emission policies.The benefits gained from P2P energy exchange process for each user , for each representative day , will be: The total cost (in £) for P2P energy exchange process for each user , for each representative day ,  2(,) is: where  −2(,) is the total cost paid to the grid for P2P process by each user  (in £), for each representative day , including battery charging cost.To compare the impact of P2P energy exchange framework, a business as usual (BAU) scenario is considered as a baseline.In this scenario, it is considered that the same users have PV panels but no batteries.The benefits gained for the BAU scenario (in £), for each user , for each representative day ,  (,) are: where  −() is the FIT paid for each kWh fed into the grid by the PV.The total cost paid to the grid (in £), for BAU scenario by each user  for each representative day ,  (,) is: where  −(,) is the cost paid to the grid (in £) by each user , for each representative day , for the same period P2P energy exchange lasts in order the results to be comparable; and  −(,) is the total net energy (in kWh) for the BAU scenario for each user , for each representative day , for the same period P2P lasts.The total benefits each user  gains for each representative day ,  (,) is: The investment cost for each user ,  () is: where  () is the battery size (rated capacity) of each battery  (in kWh);   is the current battery prices in £/kWh; and  () is the inverter cost of each inverter  (in £).The net present value (NPV) equation can be found in [34].In this study, the net present value of each for each user , after  years for each representative day ,  (,,) is: where  is the discount rate after  years.The highest NPV is selected, as it represents the maximum benefits.The NPV value is calculated on an annual base, using a certain number of representative days for each user.For each representative day, an optimum battery size is estimated, for which the NPV value is maximized.The annual benefits will be the average value of the benefits gained for each representative day.In the same way, the battery size will be the average value of the optimum sizes of each representative day.

B. Users' categorization and priority order
The methodology is applied to microgrids where users have batteries or/and PV under their ownership.The MG users who have batteries are characterized as "Battery owners" (BO), while the rest of them as "Grid-connected" (GC) users.The users' categorization is implemented regardless the PV ownership.The energy can be also shared with users outside the MG, named "users outside MG".BO charge their batteries during the low-tariff (LT) period and discharge them during the high-tariff (HT) period.During P2P process, the stored energy is sold in a price slightly lower to the existing HT, providing incentives to the users to participate in the process.The users that are not included in the P2P process continue to pay the HT as before.The amount of reduction is settled by the system operator and the BO users.The prioritization can be determined in several ways.In this study, three principles have been followed: first to minimize disruption to users with storage assets, second to align with the physical features of the network, and third to minimize the number of users interrupted.It is recognized that these principles will impact different types of users in different ways, for instance in this case, users with high consumption will be more likely to be disconnected.Other principles can be adopted to determine the prioritization order that is applied.For this study, users' prioritization is shown in Figure 1.The users are prioritized in three stages.
First, the BO users are prioritized, as they are the key players of P2P process, starting from the one with the lowest energy demand until the one with the highest one.Second, the GC users are prioritized.GC prioritization occurs based on the energy mismatch of each feeder for the P2P energy exchange period, on a day ahead basis.The mismatch is calculated by subtracting the total stored energy in the batteries of the feeder, from the total net energy demand of the feeder's user.A negative mismatch means there is surplus energy in the batteries of the feeder, while a positive value shows a deficit.The MG feeders are prioritized from the lowest mismatch value to the highest.The GC users of the first priority feeder have priority from the users of second priority feeder and so on.However, a second prioritization happens within each feeder, where the users are also prioritized from the lowest to the highest energy demand.Third, the "users outside the MG" are prioritized according to their energy demand, simply form the lowest to the highest.Finally, the model checks how many users can be served based on the availability of the available energy stored in the batteries and used for P2P process.

C. Zoning
In this study, the concept of "zone" is used, which is defined as the area where P2P energy exchange is enabled.The zone is expanded according to the users' priority order, described in the previous section.The users who participate in it gain privileges from the P2P process.
The energy sharing occurs within energy and power limits.Energy limit refers to the stored energy available in each timestep while power limit is given by the maximum transfer capacity of the inverters and transformers.Zones are dynamically defined that include users according to those that can be served within the energy and power limits (following the priority order defined in the previous step).As zone members gain benefits, all MG users have incentives to participate in it.MG users mitigate their energy consumption during HT period to reduce energy costs, and they have further incentives to reduce it due to the P2P energy exchange process.
Regarding BO users, the less energy they need for themselves, the more energy they have available in their batteries to share and gain benefits.In the same way, GC users try to reduce their energy needs as in this way, they have more chances to be part of the zone and gain a reduction tariff as reward.
An example of zoning expansion according to a particular order, is presented in Figure 2. The zone area does not always coincide with a continuous geographical area, as some batteries might be in a feeder that does not participate in the zone, yet its "Battery owners" do.
The NPV described in (16), is initially calculated, without taking into consideration the TF power limit per user, as the amount of power used within the MG and the amount exported to the grid, cannot be estimated in advance.However, after the number of batteries is determined, the zone process runs again for the  representative days, this time including TF power limits.The model calculates how much energy remains in the batteries (if any) after the zoning process.If there is unused energy this is interpreted to mean that the batteries are oversized.Thus, the battery sizes of the existing batteries are corrected, and the NPV value is recalculated as well as the users' categorization and zoning process (Figure 3).

D. Optimum battery discharging
After the zone boundaries have been defined for each timestep, the power required from the batteries of the BO users is calculated.
The required power will be equal to the total net power demand for the P2P period, with the power limits applied.The required power is used in the optimization section, where the batteries are discharged in unison, to minimize the degradation cost.According to [32] degradation cost for each discharging event  deg(,) , can be describe by the following equation: where    %(,) is the percentage of cycle loss due to the discharging event, for each timestep  and for each battery ;  () is the cost of the each battery ; and % is the threshold of maximum cycle loss, according to [32].The cycle loss will be: where   is the discharge rate (C-rate);  ℎ is the Ah-throughput; and  1 ,  2 are: where  is the absolute temperature in K; and a, b, c, d, e are the model coefficients presented in [35].Distributing the required power among all the available batteries prolongs battery lifetime compared to a one-by-one battery discharging in which each home covers its individual needs.In the joint discharge approach the power in each timestep is shared among  batteries resulting in lower discharging currents than individual batteries would see through one-by-one discharging.Lower discharging current means a lower degradation cost for each battery.The optimum battery discharging problem is formulated below. Minimize: where K is the total number of batteries of the BO users, included in the zone.
subject to: min() ≤  (,) ≤  max() (23) 0 ≤  (,) ≤  max() (24) where  ℎ(,) is the charging cost;  deg(,) ;  (,) is the SoC (in Ah);  (,) is the discharging current of each battery  for each timestep ; and  max() is the maximum current that can be discharged from each battery .The optimization problem is convex, and the relevant proof is presented in the Appendix.

A. Resilience Metrics and Fault scenarios
In this study, four resilience metrics are selected from the literature for evaluating the proposed methodology.The selected resilience metrics are presented in Table 1. 13

Resilience metrics Comments
Load connected (%) [4] Defined as the percentage of total connected load (in kW) during fault, with respect to the initial connected load before the fault.Number of customers disturbed [36] Number of customers disturbed due to fault.Duration of interruption [37] Duration of disturbance (minutes) Average level of disturbance (%) Average percentage of lost load for all users.
Also, to examine the impact the developed methodology on resilience, four fault scenarios are considered.The first two scenarios examine the faults on the physical components of batteries and the communication system respectively.The third scenario investigate the electrical fault in one of system feeders, and the fourth one is the case where TF/supply is lost.The overall methodology process is summarized in the flowchart presented in Figure 4.Each scenario is described as below:

S1: Battery fault scenario (FLTBatt)
In the FLTBatt scenario, a number of batteries is unavailable due to faults.Fault incidents could occur before or during the HT period in which the P2P process occurs.Battery faults could occur in multiple batteries during the same day.Repair time is assumed to be 1-day; so, the P2P energy exchange is reconfigured to continue without the faulted batteries.Users with a battery fault can still communicate with the MG controller, yet they are treated as simple GC users for that particular day.The zone expansion order is reconfigured with the available assets, excluding the fault batteries.After reconfiguration, the number of batteries has changed which could change the zone expansion order.P2P energy exchange continues with the remaining batteries noting that the available energy for P2P sharing will be less, resulting in shrunken zone boundaries.

S2: Communication fault scenario (FLTCOM)
Faults to the communication network.Multiple communication faults can happen during the same day, before or during the HT period.Communication faults can occur either to battery owners or to GC users or to both user categories.In this case, the faulted users are no longer visible by the MG controller, thus they are automatically excluded from zone.

S3: Feeder fault scenario (FLTFeed)
A FLTFeed considers losing whole feeder(s) due to faults in the electrical network components.One or more feeders can be disconnected from the substation leaving their users without supply.The zone is reconfigured by adjusting its boundaries to the new circumstances.The faulted feeders are automatically excluded from the zone along with their users.P2P energy exchange continues with the remaining users of the no fault feeders.The zone expansion order is changed, as the faulted feeders are excluded.

S4: TF fault-losing supply scenario (FLTTF)
The zone is automatically reconfigured so that all MG users are included.P2P energy exchange attempts to mitigate the disturbance to users until a fault is restored.For this period, the DNO is obliged to provide compensation to the users off-supply, according to the duration and the level of disturbance.If the energy available in the batteries is sufficient to cover MG users' needs, for the expected fault duration, without violating PL, the users will remain undisturbed.However, it is very likely the energy available to be insufficient, or the PL to be violated in some time steps.In this case, a load curtailment strategy is introduced to satisfy the energy and power limitations.All MG users have agreed in advance a priority list of devices to be disconnected in case of a TF/supply fault.The device priority list is shown in the table below: The load is curtailed gradually according to a load curtailment priority order.While in the zoning process there is a user priority order according to which the users are added in the zone, another priority order is defined for load curtailment process.The load curtailment priority order will be exactly the opposite of the users' priority list.In other words, the first user added in the zone will be the last curtailed.Initially, the first device in the priority list is curtailed according to the load curtailment priority order until the point that the energy limits (EL) and PL are not violated.If the EL or PL are still violated the next device is curtailed in the same way.The flowchart of load curtailment strategy is shown in Figure 5.In the first two scenarios, no compensation is provided as system operator is not responsible for these faults, while in the last two scenarios, the system operator is obliged to provide compensation as it is responsible to cover the energy needs of the end users.
The following equation is utilised for evaluating the compensation required [37,38].
where  dist is the total minutes of disturbance of all users; and  l is the total energy loss (kWh) due to fault.
In addition to fault scenarios, the efficiency of the proposed method is tested against a case study "No P2P".This case study has the same number of batteries, but P2P is not enabled, and thus batteries operate independently in the interests of the individual users.The implementation of the methodology requires a communication network to exchange information and make certain decisions according to the rules explained in this paper.The structure of this network is described in [39].

B. Input data
The proposed methodology is developed in MATLAB, and fmincon solver is used to solve the model.The input parameters are shown in Table 3.It is assumed that half of the users have 3 kW PV installations.The DNO and the BO users contribute 50% each to the investment cost and share the benefits.All microgrid users are domestic users and their load data are produced from the CREST model [40,41].It is assumed that the FIT for P2P energy exchange is increased significantly by policy makers so as to provide incentives for the users to participate in the market.Thus, for this case study, the FIT for P2P energy exchange is almost three times higher than that of BAU case (see Table 3).Figure 6 shows the microgrid topology with five parallel feeders and 16 users per feeder.

A. Battery sizing
As mentioned above, battery sizing is required for the planning mode.Therefore, the number and size of storage assets are defined in this mode.The process of battery sizing is explained in Section II-A.The NPV metric after 5 years is used in this case.In Figure 7, an indicative graph with the cost function of a specific user is presented for a particular inverter and TF power limits.The minimum cost for this case is £261.40(maximum NPV), when the battery size is 49 kW due to inverter limits.However, the final optimum battery size will be 34 kW.This gives the optimal NPV of £242.19.Note that the TF power limit affect the sizing process.This methodology can be followed for battery sizing of the rest of loads in the MG.The average NPV after 5 years for each user is presented in Figure 8.The NPV metrics are before and after the battery sizing correction process.Positive NPV indicates gaining profit after 5 years from battery installation, while negative NPV means the investing in storage costs more to hold than it returns.The value of NPV affects the user's decision on investing in battery for the P2P energy exchange.The minimum profit of £100 is considered as the limit for investing in the battery.Accordingly, a user invests in battery if the profit is more than £100.As shown in Figure 8, the initial number of batteries before correction is 27.
However, it dropped to 18 after applying the correction.The optimum battery size of the batteries after correction is shown in the

C. Optimum battery discharging
The batteries of the MG are optimally discharged in unison, according to the equations described in the optimization section.A threshold of 20% maximum capacity loss is considered (see Eq. ( 17)).A temperature of 300K is also selected, assuming for simplicity reasons that remains constant during discharging process (see Eqs. ( 19)-( 20)).When the optimization process ends, the daily cost for P2P and BAU scenarios are calculated and compared.The comparison between the cost in P2P and BAU scenarios is shown in Figure 13.It can be seen that the battery owners gained considerable benefit from participating in the P2P.It is worth mentioning that the users' benefit is different due to the load diversity.This shows the role of optimal battery charging process in the P2P energy exchange.Figure 14 compares the discharging currents for one-by-one discharging (i.e.battery owner coupled only to a specific user) and optimum discharging (i.e.sharing all batteries' energy resources across all users).The discharging is indicative for one particular battery for a representative spring day; each user's battery will have a different profile depending on the specific demand and distributed generation profiles for a given day.The optimum discharging current is smoother compared to one-by-one, only fluctuating between 0.1 -3 Amps.In contrast, in the one-by-one discharging the discharging current reaches the maximum current (i.e.4.75 Amps) multiple times.This pattern of discharging causes higher cycle loss compared to the optimum discharging, demonstrating the significance of the latter strategy.
In order to demonstrate the efficiency of the optimum discharging for a wide range of circumstances, 250 random discharging scenarios are simulated for each of the four representative days (i.e. total 1000 simulation for each battery).Each scenario couples the available batteries with the GC users and the batteries are discharged individually.Figure 15 shows the cycle loss saved for each battery for 1000 random discharging cases.The results show that the battery lifetime increases between 32% -37% when the optimum discharging strategy is applied.

D. Application of fault scenarios
For the fault scenarios described in the Section III, particular fault conditions are considered in Table 4, including the number of fault users, the time and duration of the fault.Indicative fault conditions are chosen as the model is generalized and provides results for any combination of fault parameters.The fault time and the duration are the same for the first three scenarios, so that the results are comparable.Similarly, the battery fault and communication faults are configured to occur at the same time.In feeder off (FLTFeed) and TF fault (FLTTF) scenarios, the fault duration is different as it is assumed that the DNO brings a portable generator after 3 hours.In the FLTBatt scenario, battery fault users (1, 7, 9, 79) become GC users after losing their batteries.This has been shown in Figure 16-green colour.Thus, the number of GC users is increased to 66 and the number of BO users is reduced to 14. Comparing Figure 11 and Figure 16 shows that the battery faults change the zone expansion order, from ""2-4-5-3-1" to "2-4-3-5-1".This happens, as the model re-runs the zoning process for the new conditions, without including the fault batteries.Thus, the energy mismatch for each feeder will be different, changing in the end the previous zoning expansion order.In this case, feeder 1 remains in the same (last) position as it was in the no fault scenario since it loses 3 batteries.However, feeder 5 is moved from the third priority position to the fourth one, as it loses one battery, which reduces its energy mismatch making it lower than that of feeder 3.In the FLTCOM scenario, the fault users (users 1, 2, 3, 12) are automatically excluded from the zone as they cannot communicate with the MG server.This is shown with red colour in Figure 17.In this case, the zone expansion order changes from "2-4-5-3-1" to "2-4-5-1-3", meaning that feeder 1 moves from the fifth priority position to the fourth one.The main reason for the change in the priority position is the fact that feeder 1 loses four users in the FLTCOM scenario.The fault users are one BO and three GC users, leading to an overall higher energy mismatch compared to the no fault scenario, which becomes higher than that of feeder 3.
Figure 17: GC users' priority order -FLTCOM scenario.In Figure 18, the priority order of the GC users for the FLTFeed scenario is presented, where the fault users excluded from zone are marked with red colour.As the fault feeder is feeder 3, it excluded also from the expansion order which has only four feeders in this case (Figure 18).The zoning process runs only with the assets of the remaining feeders (Figure 18 blue colour).Figure 19 compares the number of users included in the zone for the FLTBatt and no-fault scenario.In the battery fault scenario, the number of users included in the P2P zone is significantly less than the no-fault scenario.Only 20 batteries are available in the battery fault scenario instead of 24.This means that less energy is available for P2P energy exchange.However, for a few time steps, the number of users is slightly higher, due to the change to the users' priority order.Reduced energy availability and updated user priority means that different combination of users will fulfil the energy and power requirements.The relevant graphs for FLTCOM and FLTFeed scenarios are available here.
The average benefits that all BO users gain in a day are presented in Figure 20 for three of the considered scenarios.Note that benefits of FLTTF will be presented separately.Grid carbon intensity data have been obtained from [46].Since the electricity production carbon intensity is lower during night (i.e.battery charging period), the P2P contributed to the carbon emissions saving.This is valued based on carbon emissions policies, DNO and BO users share the payment of £80 per ton of CO2 saved, meaning that they gain extra benefits for decarbonizing the grid [47].The total benefits gained are also shown in Figure 20.As it is expected, the highest benefits are gained when there is no fault at the system.Benefits gained in the FLTCOM scenario are higher than the FLTBatt scenario as two batteries are off instead of four.In FLTFeed the average benefits are between the FLTBatt and FLTCOM scenarios, as three batteries are off, due to the feeder fault.Finally, the benefits gained for the different scenarios are summarized in Table 5.In this case study, the energy available in the batteries is sufficient to cover the energy needs of the MG users.However, the PL are violated for some time steps, meaning that some devices need to be curtailed.The power before and after the load curtailment along with the resilience metric for two case studies (e.g. with and without P2P) is shown in Figure 21.Resilience is expressed in terms of the percentage of power supplied in each timestep relative to the baseline demand.The power required from batteries is then used in the optimization process (yellow line).The P2P energy exchange process improves significantly system resilience, in comparison to the No P2P scenario, where the battery owners use their batteries individually.As it is shown in Figure 21, resilience in No P2P scenario does not exceed 40%, and reaches at a minimum value of 6%.In contrast, in the P2P scenario, during most of the fault period, the users are not disturbed as resilience remains 100%.However, for the time steps the PL is violated the resilience drops, due to device curtailment, but not below 60% (Figure 21).This result shows how significantly the P2P can improve the system resilience in a MG equipped with storage devices.The average level of disturbance of all users, the duration of disturbance and the number of users disturbed, with and without P2P energy exchange, are presented in Figure 22.The boxplot shows these metrics for the periods that the fault lasts (180 minutes).
The duration of disturbance is significantly lower in the P2P scenario compared to the no P2P scenario (mean value ~5minutes and ~150 minutes respectively).The average level of disturbance is around 10% with only a few users higher, at most reaching 60%.
In contrast, the average level of disturbance in the no P2P scenario fluctuates from 10 up to 100%.The results show that the P2P method applied in this paper significantly helps in reducing the number of disrupted users, as well as the level and duration of the disturbance.

E. Generalization of resilience enhancement and DNO savings
To generalize the impact of P2P energy exchange on resilience enhancement, a wide range of fault scenarios are examined.A study of 50 days with 48 different fault scenarios within each day is considered (fault could occur every 30 minutes).This corresponds to a total of 2,400 scenarios.The comparison of resilience enhancement and DNO savings between P2P and no P2P cases are presented in Figure 24.In most cases the resilience is enhanced, though the range of enhancement is wide, fluctuating between 0-80%.In a few cases the resilience enhancement drops below zero, indicating that the resilience of the system has deteriorated.This happens as in some scenarios the fault occurs when the stored energy of the batteries is depleted.
It is assumed that the faults are random and have the same probability to occur.In reality, on days with extreme weather phenomena, there is a higher probability of losing the TF or the supply.Thus, during these days, the P2P energy exchange energy management system (EMS) could be modified to operate in safe mode, reserving energy by discharging less energy during P2P process.In this way, more energy is saved in the batteries in case of fault.
Figure 24 shows a boxplot for the resilience enhancement and DNO money saved for the examined scenarios.When the resilience enhancement is positive, the outcome for the DNO is a saving in money from compensation for supply interruptions.The majority of cases show a positive result with a median value of 78% (Figure 24).Thus, in the majority of cases DNO saves money as the median is £400 (Figure 24).For the few cases that the resilience is deteriorated (negative resilience enhancement) the money than the DNO money saved could reach up to -£2000 (Figure 24).

F. Different ToU schemes and locations
To illustrate the efficiency of this methodology in determining the outcome from a series of complex interactions between demand, distributed generation resources, energy storage size selection, energy tariff structure and fault behaviours, it is applied to four different locations.As the input data vary in each case, the number of batteries and their size will be different in each location, as summarized in Table 6.The rest of the parameters such as number of users and power limits remain the same.Four representative days are also used for the sizing process, for each location.The resilience enhancement of the system is investigated comparing the P2P scenario with the No P2P scenario for the same ToU tariff scheme presented in case study section.The improvement of resilience is examined by simulating 2400 scenarios for each location.Each simulation represents a particular fault scenario, where the TF/Power supply is disabled.48 fault scenarios are examined for each day, considering that the fault occurs in each 30-minute period.50 different days are examined for each location (48 × 50 = 2400 fault scenarios).The fault duration is set to be 3-hrs, as assumed in the UK case study.To simulate the considered scenarios, load demand and PV generation data were required for each location.For PV data, CREST model was used as it permits the generation of data for different locations [40].However, there was a lack of data regarding load demand for other locations besides UK.To overcome this issue, the existing load demand data for UK were modified by using suitable multipliers to represent the different locations.The multipliers were set based on the differences in average load demand for different countries presented in [48].In this way, the required data were generated and used in the model.
The impact on resilience is dependent mainly on two factors: a) total installed battery capacity and b) total net energy consumption of the system.The total net energy consumption is calculated for the same day, for all locations.The higher the installed capacity the lower the net energy consumption, and the higher the resilience enhancement.This happens, as it is more likely the available stored energy to cover the energy needs of the users, mitigating their disturbance.
In Table 6, the total installed battery capacity and the total net energy consumption are presented for the examined locations.The differences in these values are depicted in the obtained results shown in Figure 25.New Delhi has the higher resilience enhancement, with a median value of 80%, and a minimum value of 60%, as it has the lowest total net energy consumption and considerably significant installed battery capacity (Table 6).TF fault the system can better manage the disturbance.Athens follows, as it has similar characteristics with New Delhi, with a median of 68% and the majority of cases are above 60%.There are also a few cases that the resilience enhancement drops significantly and reaches for very few cases to negative values.Negative values mean that the No P2P scenario offers higher resilience, as the energy in the batteries has been depleted in the P2P scenario.New York has the highest installed battery capacity but also the highest total net energy consumption (Table 6).This fact leads to Resilience improvement between 20% -60% for the majority of scenarios, with a median of 58%.UK has the lowest installed capacity and the highest total energy consumption.For this reason, there is a high fluctuation in the resilience enhancement, for the majority of cases with a range of -20% -80% (Figure 25).
Different ToU tariff schemes are also examined for the selected locations.The expected benefits for each case provide insights about the design of ToU tariff schemes that will be suitable for each location.The examination provides useful information to energy suppliers and DNOs in order to make decisions about the ToU tariff design.Two factors are changed in each scheme: the duration of high tariff (HT) period and the levels of high/low tariffs.Six different HT period schemes are examined, as shown in Table 7. Six low/high tariffs schemes were examined with the best three selected for presentation.In Figure 26 to Figure 29 the outcomes from these scenarios are presented, by creating the pareto front of two objectives, for four different locations.The objectives are the annual total benefits gained (in £) and the annual carbon emissions savings (in tons).For Athens and New Delhi the best solution for both objectives is the 6-30 p/kWh tariff with HT duration 1 (Figure 26-Figure 27).For NY location, the best solution for the annual benefits objective is the 6-30 p/kWh tariff with HT duration 3, while for the annual carbon emissions savings the same tariff with HT duration 1 (Figure 28).For UK location, the best solution for the annual benefits gained is the 6-30 p/kWh tariff with HT duration 3, while for the annual carbon emissions savings the 6-35 p/kWh tariff with HT duration 1 (Figure 29).For some cases, the gained benefits and carbon savings are zero meaning that the developed methodology is not a profitable option for that set of parameters (Figure 26-Figure 29).For example, in Athens location the 2-25 p/kWh tariff with HT duration 6 has no benefits for the stakeholders (Figure 26).One for the annual carbon emissions saving and the other one for annual total benefits.One for the annual carbon emissions saving and the other one for annual total benefits.
Pareto front is also examined for two more objectives: average resilience enhancement and DNO money saved (Figure 30-Figure 33).These two objectives are related to the TF fault scenario and are dominated only from the HT duration.Thus, there are only 6 cases for each location.The obtained results show that for all locations the best solution is the HT duration 3. The graphs show that the developed methodology can be applied to any location providing different results according to the characteristics of each location.The examination provides insights to the stakeholders about the desired ToU tariff scheme according to their preferences (annual benefits, carbon savings etc.).V. DISCUSSION Peer-to-peer energy trading is an efficient local energy trading that enables transaction of energy in small communities.This method has been utilized in the literature for improving different aspects of the network, such as frequency and system operation.
This study investigates the benefit of this method in improving the economic and resilient operation of the MG.
Table 8 provides a comparison on the effect of different methodologies suggested in the literature on the system resilience with the proposed framework in this paper.This table shows that the P2P framework can be a promising method in improving system resilience based on: a) load connected: 80% of the system load is connected when using the P2P, meaning that it can provide higher amount of service in the event of disruption, b) number of customers disrupted: the proposed method provided service for the majority of the loads connected to the grid, with about 10% of customer disruption, and c) duration of the interruption: the proposed method minimised the duration of time at which the customers are interrupted.The evaluation of this three metrics together shows that the proposed method can provide service for the majority of customers with least amount of interruption time.
In terms of economic evaluation, the P2P energy trading method provided considerable insights.The amount of DNO compensation cost to the end-users with and without P2P is £125 and £1,625 respectively.This means that the developed framework can benefit the system operators from economic point of view, such that they do not need to consider higher amount of budget for interrupted users.This is due to the fact that the proposed method decreases the duration of interruption and number of customers affects by disruption (see Table 8).In addition, by improving the battery lifetime (e.g., up to 37%) the proposed method proved to be beneficial for those who invest in storage units.
The proposed method also showed a considerable performance in terms of emission reduction.With a 32 -46 kg CO2 reduction, the method proposed in this paper can be beneficial in reducing the environmental impacts.This is highly valuable due to the climate change and the need for transformation of energy systems toward carbon free targets.The economic and resilient performance of the model in highly populated cities (e.g., New Delhi and New York) indicates that this framework can be beneficial in improving system performance while reducing the environmental impact.In this paper, a novel P2P energy exchange framework for improving the economic and resilient operation of MGs is developed.
The impact of P2P energy exchange on system resilience and battery lifetime is examined.The proposed framework is implemented under chosen principles in the context of an existing static ToU tariff scheme.The system users are categorized based on their available assets, while a particular priority is defined for them.The P2P energy exchange is enabled within a zone, which is expanded according to the users' priority order.The P2P energy exchange is defined based on the available assets of the microgrid (PVs, batteries), where the system batteries follow a coordinated discharging in an optimum way.The effectiveness of the method is examined for different fault scenarios, and different geographical locations while the results are compared against a no P2P case study.The simulation results show that the stakeholders gain significant benefits from the P2P energy exchange framework compared to the BAU and No P2P scenarios.These benefits were examined in the context of resilience enhancement (up to 80%) and battery lifetime improvement (32% -37%).In addition, the economic benefits (£3.6 -£4) and carbon emissions reduction (32 -46 kg CO2) for battery owners are other positive aspects of the proposed methodology.The economic benefits for the DNO range between £32 -£40.In the case of loss of supply (FLTTF scenario), the compensation expenses for the DNO are significantly reduced in the P2P scenario (from £1,625 to £125).The results show a variability on system resilience based on the characteristics of different geographical location.The results show that, the presented framework is a generalized tool that provides insights about the potential benefits stakeholders can gain for any location.
Equation (3), using ( 5) and ( 12), becomes: Functions h and h'' (i.e., Qcycle loss and its second derivative) are illustrated in Figure 34 for the above-mentioned temperature range, current range, and coefficient values.Since h'' > 0, h is convex.This means that cdeg(t,k) in ( 2) is also convex, and, finally, the objective function (f) is convex, as a sum of convex functions.

Declaration of interests
☒ The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.
☐ The authors declare the following financial interests/personal relationships which may be considered as potential competing interests:

Figure 2 :
Figure 2: Microgrid topology and zone expansion in time.

Figure 4 :
Figure 4: Flowchart of the developed methodology.

Figure 8 :
Figure 8: Average NPV before and after battery size correction.

Figure 9 .
Figure 9.It can be seen that the optimal size of battery is around 35 kWh for different number of storage devices.

Figure 12 :
Figure 12: Number of users included in zone -no fault scenario.

Figure 12
Figure 12 shows the temporal evolution of the zone.This figure demonstrates the number and the type of users included in zone over a 15-hour period.This figure indicates that the battery owners are always connected.The second group in this order is the grid connected users within the MG.The users outside the MG are considered as the last group.Meanwhile, this type of users can only be connected to the MG if energy resources are sufficient.

Figure 14 :
Figure 14: Comparison of discharging currents, between optimum and one-by-one discharging, for spring representative day.

Figure 15 :
Figure 15: Cycle loss saved for each battery for 1000 random discharging cases.

Figure 19 :
Figure 19: Number of users included in zonecomparison between FLTBatt and no-fault scenario.

Figure 20 :
Figure 20: Average benefits gained (with respect to BAU scenario) for BO users, for different scenarios including carbon emission reduction.

Figure 23 :
Figure 23: DNO compensation provided to the users for P2P and No P2P scenarios.

Figure 24 :
Figure 24: Resilience enhancement boxplot for the examined fault cases.

Figure 26 :
Figure 26: Pareto front for annual total benefits and carbon emissions savings-location, Athens.The red circle shows the best scenario for the two objectives.

Figure 27 :
Figure 27: Pareto front for annual total benefits and carbon emissions savings-location, New Delhi.The red circle shows the best scenario for the two objectives.

Figure 28 :
Figure 28: Pareto front for annual total benefits and carbon emissions savings-location, NY.The red circles show the best scenario for each objective separately.

Figure 29 :
Figure 29: Pareto front for annual total benefits and carbon emissions savings-location, UK.The red circles show the best scenario for each objective separately.

Figure 30 :
Figure 30: Pareto front for average resilience enhancement and average DNO money saved, location Athens.The red circle shows the best scenario for the two objectives.

Figure 31 :
Figure 31: Pareto front for average resilience enhancement and average DNO money saved, location Ndelhi.The red circle shows the best scenario for the two objectives.

Figure 32 :
Figure 32: Pareto front for average resilience enhancement and average DNO money saved, location New York.The red circle shows the best scenario for the two objectives.

Figure 33 :
Figure 33: Pareto front for average resilience enhancement and average DNO saving, location UK.The red circle shows the best scenario for the two objectives.

Figure 34 :
Figure 34: Qcycle loss and its second derivative for the considered temperature range, current range, and coefficient values.

Table 1 :
Resilience metrics used in this study

Table 2 :
Device priority list.

Table 3 :
Input data for the case study.

Table 4 :
Fault conditions for the considered parameters.

Table 5 :
Total daily benefits for the Battery owners and the DNO, for different scenarios.

Table 6 :
Number of batteries and average battery size for different locations (ToU tariff scheme 2-25p/kWh and HT 1).

Table 8 :
Comparison of different resilience metrics.