Decentralized Prosumer-Centric P2P Electricity Market Coordination with Grid Security

The increasing number of prosumers and the accompanying greater use of decentralised energy resources (DERs) bring new opportunities and challenges for the traditional electricity systems and the electricity markets. Microgrids, virtual power plants (VPPs), peer-to-peer (P2P) trading and federated power plants (FPPs) propose different schemes for prosumer coordination and have the potential of becoming the new paradigm of electricity market and power system operation. This paper proposes a P2P trading scheme for energy communities that negotiates power flows between participating prosumers with insufficient renewable power supply and prosumers with surplus supply in such a way that the community welfare is maximized while avoiding critical grid conditions. For this purpose, the proposed scheme is based on an Optimal Power Flow (OPF) problem with a Multi-Bilateral Economic Dispatch (MBED) formulation as an objective function. The solution is realized in a fully decentralized manner on the basis of the Relaxed Consensus + Innovations (RCI) algorithm. Network security is ensured by a tariff-based system organized by a network agent that makes use of product differentiation capabilities of the RCI algorithm. It is found that the proposed mechanism accurately finds and prevents hazardous network operations, such as over-voltage in grid buses, while successfully providing economic value to prosumers’ renewable generation within the scope of a P2P, free market.


Introduction
Advances in technology for electricity generation, storage and smart meters as well as the declines in cost of access to these technologies pose a paradigm shift in the electricity sector as the number of consumers who are becoming active participants in the electricity market is rapidly increasing [1]. This opens the door for possibilities on how to envision the new electricity market design while facing the energy trilemma: Transitioning to zerocarbon emissions in energy generation while providing universal and secure access to energy and granting that access in an affordable manner [2]. One key element of such market design involving prosumers is the inclusion of a central coordination for energy management purposes that aggregates the demand response potential of a community of prosumers as suggested by authors in [3].
Individually, prosumers have little impact at a transmission level and the complexity of communication and transactional costs may outweigh the potential benefits of prosumers directly participating in the wholesale market [4]. In this scenario, if prosumers do not see benefits in being part of the retail market, they will see an incentive in going off-grid [5]. As prosumers migrate offline, the costs of the network will be shared among the rest of participants, increasing the value of the service provided by the network [6]. Peer-to-Peer (P2P) coordination comes with the benefits of building sufficient aggregated Distributed Energy Resources (DERs) as to influence the wholesale market and to extract value from trading at a prosumer level. P2P energy trading allows prosumers to directly sell and buy electricity to one another without the need for a central coordinator. However, in the shift toward a more decentralised energy supply, there is also an increasing demand for prosumers to play a greater role in ensuring grid stability, thus, coordination mechanisms should also include this functionality. This paper, therefore, proposes a P2P coordination for energy communities that maximises the community welfare while avoiding critical grid conditions. It is especially intended for prosumers with their own renewable generation and the possibility of intermediate energy storage, who want to cover temporary energy shortages at low cost and to share surpluses profitably as part of an energy community. The community approach for peer-to-peer power exchange is modeled in form of a Multi-Bilateral Economic Dispatch (MBED) optimization problem [7].
In order to take into account physical constraints of the network such as voltage or thermal loading of network elements, this approach could now be combined with an optimal power flow (OPF) problem. P2P approaches including the network security as constraints for the OPF problem are, for instance, investigated in [8][9][10][11][12][13]. This paper takes a different approach by rather building the network requirements directly into the negotiation mechanism of the economic dispatch: Sorin et al. show in [7] how the the Relaxed Consensus + Innovations (RCI) method can be used to solve the MBED problem in a fully decentralized manner by means of agents. They also show how to implement a product differentiation into the negotiation scheme that can take additional trade characteristics of the exchanged power into account. The P2P scheme presented in this paper makes use of this product differentiation in order to iteratively increase the price penalty of harmful power exchanges until they are prevented. This approach renders the load flow and the underlying network topology itself to not directly be part of the optimization problem. In each iteration, only a normal load flow calculation has to be performed to provide input parameters for the price penalty terms. This calculation could be realized by a single designated agent controlled by the grid operator or community coordinator that then shares price signals with the peers.
Key aspects are found throughout this work. On the one hand, the possibility to establish an electricity market where participating agents can express preference and freely offer and demand power from sources at will, given the fact that the market mechanism is formed in a renewable energy-only local distribution grid of prosumers. On the other hand, the inclusion of a somewhat central grid operator at a local grid level has the rights to penalize or reward certain trades or to establish a P2P market where participating agents can freely express preference. Such agent is modeled with limited rights. Namely, its role is restricted to check for congestion problems at certain components of the network and to apply tariffs to the participating prosumers whose trades are found to cause those congestions.
The remaining part of this paper is structured as follows. Section 2 describes the methodology of the proposed P2P scheme which is based on a iterative process combining P2P negotiations and load flow calculations. For this, the modeling of the prosumers and their control strategies, the formulation of the P2P power exchange, the MBED formulation of the addressed optimization problem, the RCI method and the consideration of network constraints within the negotiation scheme are presented. Section 3 shows numerical results of an implementation of the proposed P2P scheme for a 12-bus-meshed network of prosumers. The agent-based P2P mechanism is realized in python, the network topology is built with the python open-source library pandapower [14], which is also used for load flow calculations. The results show the successful prevention of network problems and provides insight into the conversion behavior of the iterative trading scheme. Finally, in Section 4 key findings and future work are discussed.

Prosumer Simulation
A prosumer it is thought of as wanting to maximize the consumption of its own energy production. For that, photovoltaic (PV) generation is consumed first. Subsequently, the battery energy storage system (BESS) is charged until a desired state of charge (SOC) is reached. Finally, the prosumer feeds the surplus generation into the community grid, should there be any. Similarly, a prosumer's default behavior at the time of no PV generation is to demand power from its BESS and then to buy from the grid as the BESS's SOC falls below a desired limit. Figure 1 shows a conceptual diagram of the basic prosumer components and the allowed power flow. The black arrows denote the power flow whereas the grey arrows denote data flow. Data are here referred to the historical data of PV generation and a load profile in kWh for a given time step length, ∆t. Naturally, the power flows in both directions for the exchange with both the BESS and the grid. That is, it does not account for any physical phenomena with regards to its internal components and, thus, it does not account for non-linear behavior of the SOC. The power balance equation that governs the prosumer's interaction with the power system is stated as follows: where P PV is the power generated by the PV generator, P BESS is the power exchange with the BESS, P Load is the power requirements of the prosumer and P Grid is the power exchange with the grid point of connection.

Peer-to-Peer Market Coordination Model
An OPF calculation needs to account for congestion events in the power system and to access a solution in which they are tackled as effectively as possible. As such, to act and correct hazardous network operation by means of PV curtailment, load demand reduction or shifting and similar strategies by order of a central processing unit at a grid level through direct intervention might result in satisfactory grid management. However, the management of the OPF conditions by direct intervention and by controlling a grid coordination agent is not here believed to be a satisfactory enough solution for the prosumers involved. It is, instead, the intention of this work to provide an automatized solution that does not rely on such a direct intervention from a grid coordination agent on private prosumer installations and demand needs. It is believed that a free-market trading scheme provides a more satisfactory coordination than that of direct obligation, regulation and control.
A P2P market mechanism is applied in order to create an environment where prosumers can trade and exchange the power generation of their PV installations with other prosumers as agents of a market. This differs from a pool-based market, where all power generation is offered in a centralized exchange, where agents can then ask for the needed energy at the negotiated price. P2P markets are based on simultaneous negotiation of bilateral-trades where prosumers directly agree among each other on the energy and price traded. This offers a transparent clearing mechanism that involves all prosumers equally.
In this work, the role of a central coordinator is reduced to monitoring possible grid congestion occurrences. This market is built such that the valuation of certain trades is penalized in the case that the prosumer biding a power quantity is subsequently responsible for an over-voltage occurrence at its bus or thermal overload on the line through which its power is delivered. Therefore, the natural willingness of prosumers to trade among each other given the cost of certain trades is ultimately assuring an optimal network use. The proposed methodology allows for a simultaneous negotiation over the price and energy of multi-bilateral trades along a predefined trading scheme built directly in the negotiation mechanism itself. A full P2P market with a complete communication graph is considered, where every agent, n, in the grid is able to trade with the rest of neighboring agents, m, on the local grid without the need to be physically connected to them. In order to model a full P2P trading scheme, the net power injection of any agent n ∈ Ω is considered as the sum of the bilaterally traded power quantities with neighboring agents m ∈ ω n . A neighbor here might not necessarily only be physically connected agents m to agent n, but rather any other agent able to trade with the latter. A power quantity P n injected by agent n can be defined as follows.
The generator reference system is used, meaning that power injection takes positive values for those agents behaving as generators and negative values for consumers. The set of variables {P nm |n ∈ Ω, m ∈ ω n } is the set of decision variables. An agent's limitation on the quantity of power to be injected is defined by the agent power boundaries that must satisfy the following.
A prosumer's boundary power injection is P n , P n ≥ 0 at times when a prosumer behaves as a generator and P n , P n ≤ 0, otherwise. Similarly, the decision variables assume the same criteria and are, therefore, P nm ≥ 0 for when prosumer n is a generator and P nm ≤ 0, otherwise. The production cost or willingness to pay of a prosumer n is modeled as in [15] by the quadratic function of the power set-point with positive parameters a n , b n and d n , C n (P n ) = 1 2 a n P 2 n + b n P n + d n , a n , b n , d n ≥ 0 The cost of the generator or willingness to pay of the consumer is complemented with the cost of the bilaterally traded quantity towards each neighboring prosumer and has the following form:Ĉ n (p) n = ∑ m∈ω n c nm P nm (5) where p = (P nm ) m∈ω n is the vector of decision variables of prosumer n and c nm is the bilateral trading coefficient imposed by prosumer n on the trades with the rest of neighbors m ∈ ω n . The bilateral trading coefficient c nm is defined for the purpose of product differentiation. This coefficient encapsulates the information about what cost is applied to certain trades given the nature of the trading under the criterion g ∈ G being G the set of possible criteria of prosumer n applied to its trades with prosumer m. The bilateral trading coefficient has the following form.
The bilateral trading coefficient indicates the objective value of a trade under the perspective of prosumer n through the parameter γ g nm ≥ 0, called the trade characteristic under criterion g. This allows for flexibility in the nature of the bilateral trading cost as to what value is given to what trading characteristic. For instance, the criteria g could refer to the origin of the power traded, whether it comes from renewable sources or not or the distance between the producer and the consumer. The relative cost that prosumer n applies on the trade is denoted by the parameter c g n , called the criterion value. The nature of the bilateral trading coefficient allows for expressing a variety of strategies for the conformation of a market mechanism. For instance, the trade criterion could be subjected to the decision of a centralized coordinator entity in order to express taxation or it could be set as a completely decentralized notion in order to express prosumer preference over certain trades.

The MBED Formulation
The objective of the MBED problem is to maximize the social welfare of the neighborhood of prosumers at every time step of the simulation, while satisfying the demand and allocating the power generation. The problem formulation as applied in this work for a time step t takes the following form: with D = (p t n ∈ R |ω n | ) n∈Ω ; and Ω p and Ω c denoting the sets of producers and consumers, respectively. A prosumer is subject to inject a power quantity within its capabilities as stated in Equation (8). The role of consumer and producer is enforced by the sign of the power injected and that is reflected by constraints (10) and (11), respectively.
Since the MBED is a convex optimization problem, there is a single optimal solution. From here on, the followed methodology is described for solution through the RCI approach as in [7]. The approach followed in this work does not extend for the multi-time step formulation, in which ramping constraints and time-dependent behavior such as BESS charge/discharge can be considered. Here, BESS charge and discharge are performed within the prosumers' premises prior to the application of the P2P market mechanism. For such exemplary multi-time step formulation and solution of the C + I approach, the reader is referred to [15].
The stated problem is separated into subproblems subject to be solved locally by each prosumer. The cost function's parameters a n and b n as well as the bilateral trading coefficient c g nm are private to every prosumer. Indeed, every market participant is bound by the trading reciprocity constraint only, formulated in Equation (9), as to what information is shared among prosumers in the market. The proposed convex optimization problem verifies the sufficient condition for strong duality called Slater's condition. The implications are that it is possible to solve this problem in a decentralized manner, where all prosumers focus only on solving their own local welfare maximization problem and it is only by construction that, by doing so, the maximum social welfare is achieved at convergence.

The Relaxed Consensus and Innovations Algorithm
At every time step, t, of the formulation at which a market is formed, each prosumer has to solve the following problem at iteration i: where the Lagrangian dual variable λ i,t n = (λ i,t nm ) m∈ω n denotes the vector of price estimates of prosumer n at iteration i in time step t and (p t n ) is the transposed vector. Here, in order to solve this problem, a gradient step approach is taken and power boundary constraints are enforced through Lagrangian relaxation as in [16]. The dual variables for the complementary slackness of the power boundaries are denoted as µ n and µ n . An iteration of the RCI algorithm as solved by prosumer n is shown in Figure 2. The RCI algorithm can be split into three main steps. The first and second steps are the updates for the dual variables λ i,t n of the trading reciprocity constraint and the power boundary constraints µ n i,t and µ n i,t . The third step is the update of the decision variables by using the gradient step method. The update of the price estimates is carried out by each prosumer, who comes up with a solution for each bilateral trade with the rest of prosumers. Although the calculation is performed locally, a consensus has to be accomplished on the price estimates for each pair of prosumers involved in a trade (i.e., λ nm = λ mn ) after convergence. Similarly, the power reciprocity constraint in Equation (9) is enforced during the dual variable update such that the power quantity observed by the prosumers involved in the trade is equal (P nm = P mn ). This is given by the following λ-update: where α i and β i are sequences of positive factors according to [17]. These parameters are subject to tuning and constitute a trade-off between convergence speed and resilience to change. The dual variable update of the power boundary constraints is given by the following: where η i is a persistent sequence positive tuning parameter similar to α i and β i . The power set point for a negotiated trade between any two agents n and m, ifλ t nm = λ t nm − c t nm , can be written as Equation (19) and the decision variable is updated as in Equation (20): where f i,t nm is an asymptotically proportional parameter with the form as in Equation (21). This is the primal update in the case of a prosumer acting as a generator. The max operator in (17), (18) and (20) is to be substituted for a min operator in the case of a prosumer acting as a load: where δ i,t is a positive persistent sequence for which its value is taken from [7]. The iterative process is finished when the stopping criterion is met. Three parameters are defined in order to check for convergence of the primal and dual updated. Namely, P , λ and µ , as follows.
The criterion in Equation (24) is optional but can provide better monitoring of the convergence. Here, only the dual price estimates and primal updates are inspected further and their implementation is recommended by [7], where more insights on the iterative process are found and from which the values of parameters α, β, δ and η are taken. Further details on these parameters are found in the Appendix.
The amount of information exchange per iteration is very low and restricted to the power and price estimates. Cost function parameters and power injection boundaries (a n , b n , P n , P n ) as well as criterion parameter (c g n , γ g nm ) are kept private for each prosumer involved in a multi-bilateral trade, rendering this P2P market structure very secure and robust against an agent gaming the market.
A central coordinator is simulated, who checks for possible congestions, identifies the location of hazardous operation, stores the results of the network power flow, the information about the overall simulation process outside prosumer premises and shares relevant information with the prosumers. It is also another agent of the micro-grid and a P2P market participant capable of buying and selling energy. It represents the slack bus at the transformer with the external grid at the higher voltage level, which can absorb the surplus local power generation or deliver the needed power at moments where the demand exceeds the generation within the micro-grid.
For the purpose of information exchange, a broker entity is created to manage the information exchange and it is responsible for receiving all sent messages of all agents. Those messages (i.e., P nm and λ nm ) are sent to the exchange from where the broker forwards them to the rest of the peers. The events are ordered as follows: (i) The broker sends the common estimates at iteration i to all agents in the market, (ii) all agents run an iteration of the RCI algorithm with the new information and yield their local updates at iteration i + 1, (iii) agents send the information back to the broker and (iv) the stopping criterion is evaluated in order to break the iteration or to continue it.

Safety Operation of the Grid
The central coordinator has the permissions to apply an external cost to the prosumers in the grid. In this work, criterion parameters {c g n , γ g nm } under criterion g ∈ G are pushed to the central coordinator. Congestion is here defined as over-voltage at buses with a per-unit voltage V[p.u.] ≥ 1.03 and thermal overload at lines with loading percent ≥ 80 %.
In this work, three criteria, g 1 , g 2 and g 3 are chosen to be over-voltage, thermal overload and the distance from a bus with over-voltage to the rest of buses where agents are connected to, respectively. Distance is referred to as the length of the cable that connects one bus to the other. For the sake of simplicity, it is assumed that the grid topology is a strongly connected graph where a vertex is representative of a bus. This holds true for networks in which every market participant is able to trade with every other participant who is not directly and physically connected to the former. However, the power traded should be always able to reach the respective trading peer. Referring to buses is similar to referring to agents connected to them as for the set notation in the coming lines.
Penalty tariff under criterion g 1 is always applied in conjunction with that under criterion g 3 . That is because the intention is to shift the provision of power from prosumer n causing bus over-voltage to the rest of prosumers demanding its power. However, in order for the algorithm to find an alternative, the cost should be differentiable. Therefore, the differentiating criterion is chosen to be the distance in km. The respective criterion values for criteria g 1 to g 3 are in this work chosen to be c g 1 n = c g 1 = 0.5 c€/kWh, c g 2 n = c g 2 = 0.5 c€/kWh and c g 3 n = c g 3 = 0.5 c€(km · kWh). The central coordinator holds the information of what tariffs are to be applied to what prosumers as penalizations for a behavior that results in grid congestion. The penalties take the following form. ρ t = c g 1 · γ g 1 ,t + c g 2 · γ g 2 ,t + c g 3 · γ g 3 .t (25) γ g 1 ,t = (γ g 1 ,t nm ) n∈Ω g 1 ,m∈Ωn,g 1 (26) γ g 2 ,t = (γ g 2 ,t nm ) n∈Ω g 2 ,m∈Ωn,g 2 = (γ g 2 ,t mn ) n∈Ω g 2 ,m∈Ωn,g 2 (27) Once the algorithm converges and the market is cleared, the results of the power trades are passed to a power flow calculation instance in order to acknowledge the new state of the buses and lines, given the new power trades. Should the penalties not be great enough to shift the market trades towards a safety network operation, the penalization is updated in order to increase the magnitude of the tariffs imposed over problematic behavior. At a time step t for an iteration k in the global iteration, penalty updates are performed iteratively as suggested in [18] with the following form: where ∆ up is an incremental coefficient to increase the tariff ρ over iterations k, only activated after the second global iteration. If the grid state after the market clearance is proved to not incur in congestion at any point, the optimal power flow has been found, the global iteration is exited and the simulation can continue to the next time step t + 1. The overall process runs by (i) checking whether the network power flows at time step t incurs in grid congestion, (ii) identifying prosumers causing congestion, (iii) applying penalization to the respective prosumers at iteration k, (iv) running the RCI algorithm and obtaining a market clearing with traded power quantities, (v) running a power flow to check the new state of the grid and (vi) updating the penalties in iteration k + 1 if congestions are not fixed or updating exit processes if the network is safely used and continued with t + 1. Figure 3 illustrates the described process.

Limitations and Validation
Current methods for the solution of this optimization problem make use of the generator quadratic cost function model as the objective function and renewable energy sources such as PV are treated as must-take generation [17][18][19][20][21] and are accounted for as a system constraint or not accounted for at all [9,22,23]. Here, the quadratic generator cost function will be used as a virtual cost function to model prosumers' involvement in a P2P market and not necessarily to represent the cost of generation. This function serves the purpose of guiding the RCI algorithm towards an optimal solution that satisfies all demands while allocating the generated PV power production. The meaning of the linear and quadratic parameters a n and b n for prosumer n is of key importance for allocating the production of that prosumer and whose magnitude directly influences the overall prices of electricity within the market. Should prosumers' have different cost functions, competition would drive variance on who sells or buys first from whom, as generation from cheaper installations is sold first (conversely, prosumers with lowest willingness to pay are first supplied).
The de facto implications of the prosumer's PV quadratic cost function parameters and the clearing prices that arise from them is subject to a variety of strategies for market configuration. Benefits of this approach are that it is possible to adjust parameters a n and b n for a number of prosumers in a micro-grid in order to obtain a clearing price matching the average wholesale price of electricity within a variation range. Moreover, setting these parameters as equal for all prosumers produces a scenario where prosumers with surplus PV generation are equally perceived by the RCI algorithm as for the incurred overall cost they introduce into the system.
Given the nature of renewable energy sources, the establishment of such P2P market is likely to fall into local power shortage or surplus due to PV power generation intermittency. In order to overcome this shortcoming, the external grid is modelled by the central coordinator as an additional P2P market participant representing the slack bus that acquires all prosumers' surplus power generation that could not be allocated locally in the micro-grid. Conversely, it delivers the needed power provided that the local prosumers' PV generation falls short to meet the local load demand. This behavior is represented by the following equation: Here, the generator system applies, being P k,t n > 0 for prosumers' PV power generation and P k,t n ≤ 0 for prosumer demand. Therefore, the external grid agent buys surplus PV generation power when P k,t ExtGrid ≤ 0 and sells power when P k,t ExtGrid > 0. This allows for the possibility to maintain a continuous P2P market mechanism throughout day and night. The external grid's cost function parameters are tuned to give preference to trading with renewable energies first and serve as a reserve that only ensures power balance. At the time of tariff imposition, the quantity absorbed by the external grid, P k,t ExtGrid , is also shortened through the external grid penalty incremental coefficient ∆ up ExtGrid and follows the following form: where ∆ up ExtGrid takes negative values when the purpose is to reduce the external grid supply and positive values for when the aim is to reduce the external grid demand. The effect is that whenever there is a congestion occurrence and the corresponding tariff is applied, the external grid also reduces the absolute power injection in order to produce an actual shift in the demand.

Results
For the purpose of showing how the proposed methodology manages the interaction of different prosumers and solves congestion events during an optimal power-flow, a 12-Bus meshed network has been created. The topology of the network is shown in Figure 4. All prosumers count with PV installations and BESS. Moreover, they have the same cost function parameters which are smaller in magnitude than the cost function parameters chosen to represent external grid agents. The parameters for prosumers in the networks are provided in Table 1. The parameters chosen for the RCI are set to have dual variables convergence stopping criteria as provided in Table 2. The election of a high power convergence criterion comes with the trade-off of lower power allocation accuracy but a faster execution time and reduction in the average number of iterations needed to converge at every RCI process. The external grid penalty incremental ∆ up ExtGrid is set to 10 kW. It is expected that the higher ∆ up ExtGrid is, the less surplus generation the grid accepts to buy and the higher the curtailment is in those moments where over-voltage at certain buses occur. Thermal overload is not found at any line as the power flow is not big enough at this low voltage level line for the given load demand and PV generation. For that reason, only over-voltage occurrence is used for the demonstration of the model capabilities.

RCI Model Parameter Value
The simulation is performed in a minute interval throughout the day and it is required to choose a demonstrative time step to show the effects of the applied methodology. Therefore, the time step 09:31 a.m. is chosen as the representative time step, where an overvoltage occurs in Bus LV2.2.2 corresponding to prosumer 12, which is shown in Figure 5. The vertical axis shows how much the per-unit voltage at each bus surpasses 1.0 p.u. From the figure, it is clear that before the application of RCI, the voltage at bus where prosumer 12 is connected is 1.033 p.u., which is reduced to 1.009 p.u. after the application of the RCI algorithm. Figure 6 shows the power quantities traded by the prosumers and external grid agent at time step 09:31 a.m. Prosumer 12 sees its trades with the rest of the agents penalized with higher cost, shifting the external grid's demand preferably towards the rest of the prosumers first, as the demand is progressively satisfied. The demand of power from the external grid is shortened after the application of RCI algorithm by the application of the penalty tariff. This implies that external grid's demand is fully satisfied with less power purchase, leaving prosumer 12 completely out of the trading. The market condition permitted prosumer 12 to curtail full power quantity, which was available to sell.
Since all prosumers account for the same cost function parameters, they are all observed by the RCI algorithm as equally eligible peers to trade with. That is why all prosumers have progressively sold the same amount of power to the external grid agent, having a flat picture as drawn by the blue bars in Figure 6. As the RCI runs for the first time and a congestion is found, it is re-run with the mentioned penalties and external grid demands an update. The λ-convergence and the power convergence for non-zero trades are shown in Figure 7 from the perspective of external grid.   Each prosumer tried selling its full surplus power produced from PV and RCI algorithm yielded a power cost of approximately 25.25 c€/kWh. However, after the recognition of over-voltage occurrence and the respective penalty updates, the implemented RCI algorithm generates a new solution respecting the security of the network, which is shown at the right-hand side of Figure 7. An overview of the evolution of the voltage levels at the prosumer buses during the simulation horizon of 24 h is shown in Figure 8. The left hand side shows the voltages before the application RCI algorithm, where we can observe that the voltage levels increase beyond the allowed limits at mid-day, which is a time with high PV production. However such violations are removed after the application of the algorithm, as observed on the right-hand side.  Table 3 shows the performance of the algorithm when run throughout an entire day. Since the data are sampled in minute intervals, the nº of RCI problems solved is likely to be 1440. In other words, one RCI solution each minute in order to find a market clearing. However, as some minutes where found to incur in network congestion at some point, penalties are applied and the RCI needs to run again finding a new optimal market clearing. Hence, more iterations than amount of sample points in the data are needed. The load profiles vary little during some periods of the night and day. Therefore, the RCI algorithm requires no extra effort to find a solution from minute to minute when the state of the network is fairly stable, needing only 1 iteration to find the optimal allocation. Conversely, times with load or PV production variation need more RCI iterations to converge. Table 3 shows how many minutes of the day needed more than 1 RCI iteration, meaning higher power requirement variation. Average and median of the nº of RCI iterations show some minutes required a higher effort in order to find the optimal solution. Figure 9 shows the a histogram of the number of iterations needed for each RCI Algorithm to converge, given that the RCI algorithm needed more than one iteration to find the solution. Linear scale on the left-hand side versus logarithmic scale on the right-hand side. Specifications on the equipment used in this work are found in the Table A1 in the Appendix B.

Conclusions
A power flow calculation model has been developed in order to simulate a prosumer's behavior. The prosumer is expected to first satisfy its demand via its own PV installation to then charge the BESS with its eventual surplus power production and, finally, to feed the BESS rejected power into the local grid in exchange for monetary payment. Similarly, had the prosumer been unable to fully satisfy its demand throughout the PV installation and the BESS discharge, the prosumer is supplied via the local grid, in that order.
A P2P market coordination is established where prosumers are considered agents in the market along with the micro-grid operator, modelled as the EGrid agent, that also participates in the trade mechanism. The P2P market coordination is constructed via the RCI algorithm that solves the MBED problem at every time step of the simulation. The problem is solved in a decentralized manner and locally at each agent's premises. All agents focus only on solving their own local welfare maximization problem and it is only by construction that, by doing so, the maximum social welfare is achieved at convergence. Information exchange is finally limited to the exchange of the power quantities willing to be traded plus the price at which they ought to be sold or bought. This allows for a high-quality data protection trading scheme. A grid operator agent in the market is placed in charge of supervising the optimal and non-hazardous use of the network, continuously checking for congestion occurrence defined as over-voltages at certain buses and/or thermal overload at certain power transmission lines. This agent is allowed to impose a penalty tariff on each trade found to be incurring in congestion. Hence, the market is re-established with updated trading prices and the offers and demands are shifted to find the new optimal trades that simultaneously prevent congestion again.

Findings
The RCI model parameters allow for enormous possibilities as it accounts for several key parameters that incur in trade-offs between performance speed and convergence error. There is a wealth of trading schemes that can be constructed by tuning the parameters for the cost of power production and purchase that allows for great variation of the clearing prices, allowing for the simulation of different markets. Parameters related to the cost of generation/consumption per agent produce an immense amount of markets by selecting which agents ought to sell/buy first from which agents.
This work focuses in a renewable-only market, where penalties and rewards for participants can be based on a wealth of criteria such as tariff on congestion, energy origin preference, distance to source of power, etc. Furthermore, the criteria onto which penalties or rewards are settled can be pushed centrally or completely decentralize in order to allow agents to decide what they consider more costly or what reward's they are more prone to, enabling a complete product differentiation scheme in the latter scenario.
The communication graph that drives the P2P trading scheme is chosen here to be a strongly connected graph, i.e., every vertex of the graph is reachable from every other vertex of the same graph. Vertex is here referred to agents' points of connection. The graph can differ from the physical connection of agents through direct cable.

Future Work
Deeper investigation should be performed with dedicated computational characteristics and a real-world distributed system in order to better assess the algorithm speed. Moreover, the proposed algorithm can be itself implemented more optimally in terms of run-time by re-structuring the imperative flow. Further improvement should be conducted by testing asynchronous programming or parallelization in this regard. Real-world implementation should come with the need to asses possible lengthy response times after optimization from the part of the algorithm as well as the study of smaller simulation time steps.
Further work should be conducted where the proprietary BESS plays an active role in the OPF problem at a grid-level, optimizing the charge and discharge and making use of inter-temporal constraints and multi-time step market simulation. Insights on the possible application of such multi-step optimization are found, for instance, in [15].
An important tool that could be integrated with our proposed methodology to mitigate the grid stability issues with prosumers is the forecast of their stochastic power generation, especially at the distribution grid level. In this regard, several works such as [24,25] provide forecasting methodology for PV generation profiles, which could provide useful integration into the developed methodology here presented. This would in turn prove helpful in more accurate power flows, price convergence and improved grid stability.
Further investigations should be made on the asynchrony of the communication scheme as well as the intermittency of the connections among agents as performed in [26]. Moreover, the communication graph is supposed to be strongly connected. Further studies should be conducted on how to easily and quickly define changing environments as lines undergo failure, maintenance or any other event that affects the graph's characteristics.
Model parameters such as positive tuning parameters α i , β i , δ i and η i for the RCI should themselves be subject to further optimization and ought to be studied in more detail. This numerical optimization lies beyond the scope of this work. Furthermore, the magnitude of the cost criterion for the bilateral trading coefficient, c g nm , can produce different market outcomes. The election of these magnitudes can be further explored as to what criterion is of most interest given different market scenarios. The optimization problem of finding the right amount of penalization required in order to prevent a congestion occurrence is, in and of itself, a problem subject to deeper investigations.  Data Availability Statement: The data used for this work is discussed further down in the Appendix B. The source data is https://data.open-power-system-data.org (accessed on 24 April 2020).

Conflicts of Interest:
The authors declare no conflict of interest.

Abbreviations
The following abbreviations are used in this manuscript:

Appendix A
The values of the tuning parameters of The RCI algorithm discussed in Section 2 are as follows.

Appendix B
The same data profile is used for all prosumers in order to represent that all belong to the same neighborhood where solar irradiation variance is negligible. PV generator data are given in kWh/min. Data are normalized to per-unit hour and are scaled up by multiplying the series times the prosumer's installed PV capacity. Figure A1 shows the PV profile as well as the load profiles used for prosumers, which are also taken from the same source.

Appendix C
The following Table A1 shows the specifications of the equipment that run the simulation here presented.