Multi P2P Energy Trading Market, Integrating Energy Storage Systems and Used for Optimal Scheduling

The increasing use of renewable energy and storage systems by end users has changed the paradigm of electricity markets, with consumers changing their role from passive to active players, the so-called prosumers. Different countries have encouraged the aggregation of these prosumers in energy communities. In these communities, it is essential to create a market to manage energy exchanges between neighbors, who can sell surpluses or buy energy to reduce their bills. This paper presents the framework definition of a multi-peer-to-peer market. As contributions, it defines how storage systems can participate in the market and multiple exchanges between prosumers are possible. This market can be integrated in an optimization process to perform optimal scheduling in the community by setting an objective. All this has been tested in a community with 5 prosumers with generation and storage, where the effect of multiple exchanges and valuation of assets is observed, achieving as a result higher bill reductions.

INDEX TERMS Local electricity market, local energy community, optimization, peer-to-peer transactions, prosumers, energy storage systems, renewable energies

Sets
T Set of T periods, t ∈ T . Variables and parameters π Units of money.  Price set by prosumer i to buy energy to store it in the battery on the market. π bat,dis i,t Price set by prosumer i to sell energy stored in interval t. π agreed m,k,t Price agreed between supplier m and demander k for energy exchanged in the interval t.

I. INTRODUCTION
Different directives [1], [2] from official organizations lead the way towards the use of clean, sustainable and efficient renewable energies. This, along with the significant reduction in the costs of renewable generation technologies and storage [3], has enabled a large growth in small-scale distributed energy resources (DERs). This is particularly evident in the growth of domestic photovoltaic panels, together with the inclusion of residential storage systems.
The energy from these self-consumption installations is cheaper than energy purchased from the grid, due to the elimination of transmission fees, commercial margins and other taxes. This has resulted in more and more consumers opting for these installations, helped by the regulation of selfconsumption in many territories [4], [5]. This also implies a paradigm change in the electricity system and markets, with consumers becoming an active part of the system, becoming prosumers. Prosumers can buy energy they need from the grid, and sell surplus energy to the grid or to other consumers in their community. Everyone involved would also benefit from access to clean, cheaper and more efficient energy, due to more localized energy where consumption is produced.
These prosumers can be grouped into energy communities [6], which will become increasingly important and a key element of the energy system in the coming years. Thus, part of the energy generated can be traded between neighbours in the community, through peer-to-peer (P2P) exchanges [7]. P2P trading is a recent technology of the energy management mechanism for smart grids, in which prosumers exchange energy among themselves, maximizing their resources.
There are several techniques for addressing P2P exchanges, introducing new markets and the optimization of these energy exchanges. Some studies [8], [9] have reviewed the state of the art of P2P energy exchange methods.
For example, there are techniques, such as stage-based techniques [10], where a two-stage aggregate control is proposed to carry out the energy allocations, where realtime deviations are handled by rules, which, if not precise and well-defined, can affect performance. Other work [11] also uses a hierarchical stepwise model, where an energy trading framework is proposed to solve exchanges at different levels. The work developed in [12] proposes an energy sharing model with price-based demand response (DR) for P2P prosumer microgrids. This has the disadvantage that, in the absence of a market where bids are submitted, a consensus must be reached to decide prices during energy sharing. Local marginal price (LMP) to set trade prices and P2P transaction fees are used in [13]. LMPs are invariant to the type of technology, so they may not fully represent the value of resources such as batteries. In [14], a peer-to-peer market is proposed, it is based on the concept of multiclass energy, used to coordinate trading between prosumers. This concept can be difficult to apply because each prosumer may perceive the non-economic value of the resources in a totally different way. Prospect theory (PT), which is based on individual differences of market members, is used to resolve power exchanges in [15], with the handicap that the price is set by a program and not by the prosumer, who cannot value his assets according to his own criteria.
Game theory [16] is frequently used to address P2P exchanges. This approach is used to provide a solution based on an understanding of the behavior of the other participants. In [17], a motivational framework is used with the objective of improving the participation of the prosumers. The same approach is developed in [18]. These studies do not include storage systems in P2P exchanges. The work developed in [19] solves direct interactions between buyers and sellers, taking into account the DR capacity and privacy of prosumers. This paper also does not address the market integration of storage systems in the exchanges: batteries are only used to reduce own consumption. In [20], the Stackelberg game is formulated with producers as leaders and consumers as followers to optimize social welfare. In the same way, in [21], a P2P trading algorithm, based on the Stackelberg game, is proposed. In this approach, the question arises as to why consumers are not the leaders, since it is the demand that conditions the energy exchanged, and how it is resolved that a battery can act as a producer or consumer, depending on the case. A coalition game is selected in [22] to build a model where the trading price is set according to different priorities. Priorities are used for the management of exchanges, but it has the handicap of not addressing individual batteries, only one community battery for all. In [23], an economic dispatch is defined as non-cooperative game. In some cases, there is the disadvantage that the solution of these problems leads to highly complex algorithms. In this case, the issue of battery participation in exchanges and the flexibility they offer is not addressed.
Another of the most established techniques for dealing with P2P exchanges on the network is the use of linear programming techniques to optimize exchanges, where the method for obtaining the transactions is included in the optimization. A Mixed Integer Linear Programming (MILP) method is proposed in [24] to optimize the decision-making of P2P electricity transactions from the operator's point of view.
Another work, as [25], formulates another MILP problem by minimizing network costs in addition to the operating costs of the storage systems, to solve the exchanges. In these works, storage is not given a prominent role, it is only used to reduce the bill, but without seeking its integration. The work developed in [26] formulates the Generalised Nash Bargaining Problem (GNB), which is decomposed into two MILP subproblems, seeking to maximize the social welfare and the net benefit of participants but again the inclusion of storage systems in the problem is not addressed. In [27], an MILP optimization is modeled by minimizing the cost of energy purchase, as well as taking into account the cost of the assets (generation and batteries). In this work a key role of storage is not achieved, because to make a profit the battery owner must have generation. Another work, such as [28], also uses MILP, seeking to reduce the total community bill, allowing energy transactions with the retailer or with other consumers in the community. This work has the disadvantage that only the exchange between two prosumers is allowed, not being able to exchange one of them with several.
These approaches have several drawbacks. The first one is that no clear market structure is defined, which allows incorporating storage and offers for sale and purchase, including the handling of batteries. Another drawback is the need for an optimization approach to solve the P2P exchanges, which are decisively influenced by the objective function to be defined.
Another disadvantage is the modeling in linear programming, which is rigid and sometimes not all interactions can be modeled. An example of this is how to model multiple exchanges between several prosumers, which is a significant limitation. An alternative to linear programming for optimization are evolutionary algorithms, which allow including the definition of markets in a specific way and their subsequent optimization. In [29], the genetic algorithm is used to minimize the energy cost of the community. Evolutionary algorithms allow complex models to be included without the need for simplifications.
The work presented in this paper attempts to overcome some disadvantages of the existing methods. A real market structure is proposed to solve P2P exchanges, completely scalable, where producers and consumers present their offers, and the exchange occurs at a fair price between each producer and consumer for each energy block. This market has the advantage that it can be run in real time resolving with the orders submitted, and be integrated into an optimization for optimal scheduling in the community.
The main contributions of this work can be summarized in the following points: • A market structure that can be executed in any period of time is proposed, obtaining the P2P exchanges between the participants without requiring optimization. In this market, multiple exchanges are allowed. • The direct incorporation of the price in the orders at the market allows finding the right price between sup-plier and demander, eliminating the unique price of the marginalist market. This also enables the incorporation of demand side management (DSM) strategies. • Incorporation of storage systems into the market in a specific way, taking advantage of all the flexibility they offer. A bidding method is provided to decide charging and discharging based on price without the need to optimize. • It allows for a better valuation of the assets because, as a result, it is possible to identify which prosumer's asset sells energy to the other assets. Each prosumer asset can be priced independently of the other. • Opportunity to integrate the market into an optimization (possible with evolutionary algorithms). Due to the optimization process, all P2P market participants will benefit (No one is negatively affected). This paper is divided into four further sections: Section 2 presents the basics of the proposed P2P exchange method. In Section 3 it is shown how the market can be integrated in an optimization and which variables are involved. Section 4 shows the data that will be used to test the method. Section 5 depicts the results of applying the proposed market together with the optimization for the case presented in Section 4. Finally, Section 6 presents the conclusions of the developed work.

II. PROPOSED P2P MARKET
This section presents the proposed P2P methodology, including the theoretical background and conceptualization behind the method, the architecture and the operation of the power exchanges.

A. CONCEPTUALIZATION
Most of the existing methods in the literature solve peer-topeer exchanges by an optimization, seeking to maximize or minimize a specific objective, but without really defining a market. In this paper, the definition of a market in which participants can solve their buy and sell offers is presented, with the additional advantage that it can also be included in VOLUME 4, 2016 an optimization seeking a given objective as the previously mentioned methods.
The proposed market is based on two key concepts, which in combination allow defining a robust and versatile method for managing energy exchanges in each market execution. The first concept is that of aggregated curves, taken from Euphemia [30], the bid matching algorithm used to manage the daily market in Europe. The supply or demand orders of all participants in the same zone are aggregated in the supply or demand curves for each period of the day. Supply orders are ordered from lowest to highest price, while demand orders are ordered from highest to lowest price.
With these aggregated curves, Euphemia matches energy demand and supply for all periods of a single day, where a single market price and the total energy exchanged are obtained for each period. This concept can also be applied to P2P exchanges because the procedure is the same, since the aim is to match the cheapest supply and demand offers with the highest prices.
The result of Euphemia has a disadvantage that clashes with the P2P philosophy: it is a marginalist system. All producers sell their energy at the market price, despite having submitted different prices in their bids. The same occurs with the purchase bids, they pay the market price despite having set a higher price.
For a P2P market, a non-marginalist system is necessary to solve the exchanges between participants: whoever was willing to pay more, pays more; and whoever was willing to sell at a cheaper price, sells at a lower price. To solve energy exchanges and the pricing of these, the second key concept is incorporated. It is matter of managing trades based on priorities or price signals. That is, to allocate energy among prosumers according to the energy requests and prices set. Because of this, the methodology of the priority-based auction algorithm E-Broker [31], [32] is used as the resolution core. E-Broker uses price signals to allocate energy from generation sources to loads. Suppliers and demanders are ordered according to priority. For suppliers, the priorities are ordered from lowest to highest, while demanders are ordered in reverse order. For example, in the management of a microgrid, the generation with the lowest priority would be used first, feeding the load with the highest priority. This process continues with the next bidders until no more energy can be exchanged.
Thus, the way to proceed for the allocations and to fix the prices. First, the lowest priced bidders will exchange their energy with the highest purchase bids, fixing an average price between them. Then the following bidders and demanders will be chosen in order of priority to assign the energy offered, until the limit of the matched power is reached.

B. METHODOLOGY
To solve the P2P power exchanges, the proposed market method is developed in five steps, which will be described below. The data shown in Fig. 2 will be used to illustrate the description of the steps of the proposed method (as a P2P market execution.

1) Step 1: Definition of orders in the market
The first stage consists of defining the supply and demand orders, which are presented in the P2P market. Similar to Euphemia, these buy and sell bids are used to form the aggregate curves once the submission of bids is closed. Each supplier must define in its offer the amount of energy it is willing to supply and the price at which it values the energy. Similarly, purchase offers indicate the energy demanded and the purchase price.
M arket To be matched, these orders must comply: where matched sell bids must have a price equal to or lower than the equilibrium price Π eq t , while matched demand orders must have a price equal to or higher than this market equilibrium price.
The appearance of prosumers in communities and the increased use of storage systems makes it essential to specifically define how these systems participate in the market. To take advantage of the flexibility of storage systems and make them as profitable as possible, it is proposed that each storage system submits two orders, one as a supplier and the other as a demander.
Depending on the price at which the market closes, it may be interesting to charge or discharge the stored energy. If in one hour the price is low enough, the battery can be charged with cheap energy to use it later. On the other hand, if the market closing price is very high and there is stored energy, it may be interesting to discharge part of the stored energy to maximize profits.
Energy orders that are related to the charge and discharge of the battery (as bidder or demander) are conditioned by: The prices at which storage systems participate in the market must comply: which is the result of the combination of equations (2a) and (2b). Note that the battery charge price (demander) is lower than the discharge price (seller). This prevents that the battery can buy energy from itself in the market run and produce errors. The behavior of the battery depending on the price can be summarized in the following cases: , do nothing. (5) This approach allows for a better integration of prosumer storage systems. Thanks to price signals, it is possible to manage the charging and discharging behavior, maximizing the profit obtained by the owner. This strategy adds flexibility to the decision, either in the execution of the market or in the optimization of the operation. It reduces the uncertainty of how to participate in the market, being able to behave as producer or demander depending on the price at which the market closes.

2) Step 2: identification of matched supply and demand
Once the orders presented in the market have been described, in this step, the total energy exchanged is calculated based on the intersection of the aggregate curves formed by the supply and demand orders. This intersection determines the volume of energy exchanged (E eq ) and the price at which the market closes, Π eq . The balance of matched energy must be maintained between suppliers (M) and matched demanders (K): Once the participants that have been matched are identified, they are ordered according to the aggregate curves. Table 1 shows the sell offers ordered from lowest to highest price, and the purchase offers ordered from highest to lowest price.

Supplier
Demander For all matched orders (shown in the Table 1), the prices must satisfy that: The lower priced sale bids will have a greater chance of selling all the energy offered, and the higher priced purchase bids will have a greater chance of obtaining all the desired energy. As closer to the equilibrium price Π eq t , it may happen that not all the energy presented in the offer is sold or bought.

3) Step 3: Participants energy contribution
In this step, with the information of the matched participants, the objective is to identify who composes each step of the matched aggregate curve piece. To illustrate the theoretical description of the steps, the case shown in Fig. 2 will be taken as an example.
In the suppliers a first step of two kWh (supplier 1) and another step of 3.5 kWh, formed by the contribution of supplier 1 plus that of supplier 2, are identified. For the demand, there is a step of one kWh from demander 3, and another step of 3.5 kWh, with the contribution of demander 3 and 2.5 kWh from demander 2. Table 2 shows the contributions in the matched blocks of all market participants (also unmatched participants). The information collected in the supplier and demander tables is organized in a single table, with all the values of the identified energy blocks, ordered from lowest to highest. This allows to know who can offer energy in a step and who can VOLUME 4, 2016 5 This article has been accepted for publication in IEEE Access. This is the author's version which has not been fully edited and content may change prior to final publication.  Table 3 shows the unified contributions for each step.

4) Step 4: Energy blocks calculation
The identification of who makes up the steps and how much energy they contribute, allows the calculation of energy increments. These increments are defined as the difference between one energy block and another in the table of unified contributions for each participant. This helps to value each energy exchange that occurs. As each step was characterized by a different price, each increment will be valued at a different price with respect to the others. For the first block a price is paid, and for the successive increases in energy, with respect to this, different prices will be paid as they come from different agreements between participants.
To calculate the increments, the method described in the algorithm 1 is used. The input is the information contained in the unified contribution Table 3 (where J is the total number of contributions, it is, the number of columns), and the output is the energy increments.
Applying this algorithm to the information shown in Table  3, the increments of the Table 4 are obtained as output. It can be seen how two kWh that supplier 1 had matched, are divided into two different increments of 1 kWh. As the two increments are different, the supplier will receive a different amount of money for each of them, as each increment is valued with a different price.
Similarly, demander 2, who had matched 2.5 kWh, will pay a different price for a first increment of 1 kWh, and another different price for the other increment of 1.5 kWh. Thus, this demander will complete its energy demand, but will not pay the same price for all the energy, since it will buy it from different producers. This is the philosophy of P2P market, not being a marginalist market.
Algorithm 1 Algorithm for calculating increments. Input: Table 3

5) Step 5: Allocation of energy blocks and prices
With the identified energy increments of each bidder and demander, the energy allocationis carry out between them. In this allocation, the same supplier is allowed to exchange energy with several demanders in the same increment, as well as a demander can obtain energy from several suppliers. The price at which the agreements between participants are closed is defined as the average price between what a supplier set for its energy and what a demander was willing to pay for the energy required in the market: The allocation process starts with the first energy increment identified. Each supplier provides energy to each demander until completing the energy identified in the increment table, receiving for each energy exchange the agreed price.
The energy of the participant is updated in each increment. When a supplier exchanges all the energy in the increment, the next supplier is chosen to continue exchanging in the increment if is necessary. In the same way, that happens with the demanders, when their energy request is satisfied, the next demander is chosen. Once the exchanges in one increment have been resolved, it moves on to the next one. Fig. 3 shows the scheme followed for energy distribution for each block identified in the increments.
Equations (9a) and (9b) define the total amount that a supplier receives and that a demander pays for the energy exchanged in a market execution.
For the case used in the description of the market, allocation result, supplier 1 is analyzed. It offered 2 kWh to the market at a price of π, which have been divided into two increments of 1 kWh each. One is sold to demander 3 (demand price of 4π) at an agreed average price of 2.5π. The other unit of energy is sold to demander 2 (demand price of 3π) in another increment at an average price of 2π.
In a marginalist market it would have obtained 7π, while in P2P market it receives 4.5π, so there is a fairer distribution in which demanders pay less, and suppliers are paid according to their bids submitted and not at the market closing price.

III. PROPOSED OPTIMIZATION METHOD FOR THE P2P MARKET MODEL
The proposed P2P market model can be integrated into an optimisation to realise, as in other methods, optimal scheduling in a prosumer community.
Different objectives can be defined to optimize exchanges in the community and perform an optimal scheduling: reduction of grid dependency, reduction of operating costs or use of clean energy. One of the most common options is to minimize the electricity bill of the community. The aim is to seek the social welfare of all members of the community. This approach is defined by the objective function: where the objective is to reduce the costs of purchasing energy from the grid. In this case, the assets are managed not only to reduce the individual prosumer's bill, also to help reduce the bill of other prosumers, if possible. Fig. 4 shows a flowchart of the optimization process, including the proposed market for this case.  This optimization process integrating the proposed P2P market to obtain the optimal scheduling is divided into three stages: 1) Internal balance of each prosumer: the objective is first to satisfy the consumption of each prosumer with its own resources.Excess generation available, if any, is calculated to be offered to the market or stored in the battery. If, after balancing, a prosumer needs energy, it will submit a purchase offer to the market. 2) Market execution: Once the internal balancing is done, the P2P market is executed with the purchase and sale offers submitted by prosumers. 3) Evaluation of the objective function: the defined objective function is evaluated, which will use the market results. The optimization variables will change their value and how they behave in the internal balance and the market in order to minimize the set objective. Thanks to including the internal balance and separating it from the market, it is guaranteed that no prosumer will be adversely affected by participating in the P2P market, since the priority will always be to reduce its own bill.
Optimization should focus on managing the controllable assets that exists in the community: controllable generation, manageable load and mainly storage systems. Thus, the optimization variables must be related to the flexible systems in the community, which are the ones that allow the bill to be reduced through their management. Non-controllable gener- VOLUME 4, 2016 ation and loads are defined as parameters. The optimization variables that are defined to control storage systems (other manageable assets are defined in the same way) are: • E dis i,t : variable to control battery discharge, for internal consumption and participating in market. • π dis i,t : variable to control the price at which energy from the battery is offered on the market. • E ch i,t : variable to control the battery charge, storing own excesses and participating in market. • π ch i,t : variable to control the price at which energy is purchased on the market to be stored in the battery. where, by managing these variables, it is possible to order the charge or discharge of the battery, to reduce own consumption, to store surplus generation or to buy or sell in the market. Prices will adjust their value so that the sale or purchase is realized.The energy setpoints contemplate the energy to reduce internal consumption (or charge) and sell to the market (buy to the market). This is because it is satisfied: This total energy charged or discharged is the value used to update the energy in the battery:

IV. CASE STUDY
This section presents the case study on which the proposed market model will be tested along with its optimization. It is a scenario with five prosumers connected to the same node. Each of them has photovoltaic generation and storage. The evolution of the consumption of each prosumer for the day to be analyzed is shown in Fig. 5. The maximum value of the consumption of each prosumer will determine the installed PV power and storage size. Installed photovoltaic power will be around 50% of the maximum peak value of its consumption. The generation profile is shown in Fig. 6. The size of the storage will also be determined by the peak value, with the maximum battery capacity being half of the peak consumption value. This is a day-ahead market scheduling problem, so the prices of a day on the OMIE market [33] are considered as a reference, where, for each hour there is a different price. The use of different hourly prices allows prosumers to value their resources according to the time and generation available, consumption, and when to sell to the grid or store surpluses. The characteristics of the prosumer storage systems are shown in Table 5. There is no maximum amount of energy to sell to the grid or to other prosumers in this community.

V. RESULTS
In this section, the results of the optimal scheduling using the proposed market are presented. The objective is to minimize the total energy cost of the community. The optimization will be implemented in Python, using Genetic Algorithm (GA) for its resolution. In addition, a comparison with a MILP method presented in the literature [28] is included.

A. OPTIMAL SCHEDULING
The proposed market and its optimization have been tested for steps with numerous prosumers with their respective assets, as well as 15-minute time intervals. To simplify the visualization of the results, the optimization is performed for an interval of 24 periods (one day) with a community of 5 prosumers.
The evolution of the consumption of each prosumer after optimal scheduling is shown in Fig. 7.
It is observed that in the early hours of the day, when the price is lower, the consumption of the community is fed with energy from the grid. At central hours of the day, consumption from the grid decreases, and excess generation is sold to the grid.
The highest volume of P2P exchanges in the community occurs during the central hours of the day, as well as during one of the most expensive hours (20h). Batteries are discharged at night hours (19-23h) at the highest prices, in order to reduce the consumption of the grid. At the community's peak consumption hour, 20h, thanks to the batteries, consumption is reduced by 25.78%. Fig. 8 shows the total energy volume exchanged among the prosumers in the community. Prosumer 4 is the largest seller, with 7.88 kWh. This is because its maximum peak consumption occurs at 20h, having a large excess of photovoltaic generation in the central hours of the day, where it has a small consumption. The average energy exchanged in the P2P market is 3.21 kWh per prosumer. Table 6 shows the comparison of the bills of each prosumer and the community for two cases: when the assets are managed individually (through individual optimization) without allowing exchange between neighbors (without P2P), and when exchange between prosumers is allowed in addition to exchange with the grid (with P2P). It can be seen that by allowing multiple exchanges between neighbors, the overall bill is reduced by 7.22%. As can be seen, all of them reduce their bill by participating in P2P exchanges (reduction between 2.13%-15.15%), and none of them is negatively affected by participating in the P2P market. This is due to the optimization approach (Fig. 4), which first performs an internal balancing, prioritizing the reduction of own consumption, and then participate in the market with possible excesses of generation or energy in the battery.
A summary of community exchanges is shown in Table  7. Thanks to the definition of a P2P market, it is possible to identify the exchanges between the community assets: loads, batteries and generation. Batteries are not used to sell energy to the grid, only to reduce consumption, since the grid purchase price is not advantageous for selling stored energy that can be used in expensive hours. In contrast, the excess of photovoltaic generation is sold. +RXU   This article has been accepted for publication in IEEE Access. This is the author's version which has not been fully edited and content may change prior to final publication.  It is shown how the objective of reducing the overall bill is achieved. A greater volume of excess photovoltaic generation is sold to the community with respect to the grid, as the objective is also to reduce for the other prosumers (15.08 kWh versus 10.02 kWh). Regarding the behavior of batteries in the P2P market, there is a tendency to buy excess generation from other prosumers to store it and then to use this energy to reduce their own consumption. This can be seen in the volume of energy bought versus sold by batteries: 2.31 kWh when buying versus 0.97 kWh when selling.
It can be concluded that batteries are used almost exclusively to reduce self-consumption and excess generation is sold mainly to the P2P market and not to the grid, which is in the best interest of the community. Therefore, due to the definition of the market, it is possible to analyze the behavior of the assets, identifying the amount of energy exchanged by each asset. Fig. 9 shows the distribution of energy purchased from the grid by each prosumer, as well as that purchased in the P2P market.
Prosumers 3 and 4 are the biggest purchasers from the grid, with high energy peaks (4.64 kWh and 5.69 kWh respectively). This is due to their consumption profiles, where in the central hours of the day, the consumption of prosumer 4 is small (0.68 kWh consumption at 12h); while prosumer 3 is the one with the highest and most uniform consumption.
This can be seen in the distribution of the violin graph (Fig.  9). Prosumers 1 and 2 are those who buy the least amount of energy from the grid; however, they are those who buy the most in the P2P market, buying excess generation to feed consumption or to store in the battery.
KRXU D  Thus, taking into account this information and the consumption profiles, it can be seen that the first step is to try to buy on the P2P market if possible to feed consumption and reduce peaks, as is the case of prosumers 1 and 2. On the other hand, due to their consumption profile, prosumers 3, 4 and 5 are more dependent on the grid to feed their consumption, but they can reduce their bill by selling a larger amount of excess energy on the P2P market.
From a technical point of view, it is also worth analyzing the performance of prosumer batteries on the market for the day under analysis. For this purpose, the evolution of consumption, generation and P2P market together with prices and SOC of prosumer 1 is shown in Fig. 10. At 11h the consumption peak occurs (5 kWh), which is satisfied with own generation (2.73 kWh), energy from the P2P market (3.41 kWh) provided by neighbors' surpluses at a lower price than the grid. This energy from community surpluses is also used to charge the battery at low cost. Subsequently, the battery is charged with excess own generation at 13h. At 20 and 21 hours, the battery is discharged by selling on the P2P market, to reduce the own bill and the bill of neighbors, because it is the hour with the most expensive price and there isn't generation. Similarly, at 15h, there is an excess of generation that is more profitable to sell to a member of the community to reduce his consumption or charge its battery. This article has been accepted for publication in IEEE Access. This is the author's version which has not been fully edited and content may change prior to final publication. Citation information: DOI 10.1109/ACCESS.2022 It is also observed in the behavior of the battery that one of the constraints is complied with: a complete charge and discharge cycle is performed.
Thanks to the definition of the market (with multiple exchanges) and how the energy and price offers are presented, which can be optimized, the community is managed to achieve the objective. This can be observed in how excess generation is sold mainly to the community to help neighbors, to reduce individual bills, and therefore overall, instead of selling individually to the grid. By including this market in the optimization, community resources are better utilized and assets are valued more accurately (optimizing bids), which implies better overall management.

B. STATE OF ART COMPARISON
The proposed market and its optimization have been compared with an existing method in the literature to observe the improvements it provides. For this purpose, the case described has been compared with a method based on linear programming (MILP) as described in [28], from now on SoA method. This method is chosen because it is also representative and analogous to the cooperative mode in game theory, because prosumers' assets are managed cooperatively for common benefit.
The bills obtained with both methods are compared for six cases based on the case study. The first case is in which all prosumers have their own generation and storage system. In the other five cases, one of the prosumers does not have its own storage system. The results of this comparison are shown in Table 8. The objective of these cases is to show the differences between SoA method and the proposed method, such as the inclusion of batteries, asset valuation and multiple exchanges.
Taking into account the 6 cases, an average reduction of 1.92% is obtained by the proposed method. This reduction increases when one of the prosumers has no storage. This improvement in results is due to two points of improvement provided by the method proposed in this paper mentioned above. The first difference between both methods comes from allowing a prosumer to exchange energy with more than one member of the community. One prosumer can help more than one neighbor to reduce their bill or their dependence on the grid, while in the SoA method, a prosumer is not allowed to transact electricity with two or more prosumers.  The difference in the number of hourly exchanges between prosumers is shown in Fig. 11.
For example, in hour 12, one of the highest grid price in solar production hours, there is a higher number of exchanges in the proposed method compared to the comparison method. Thanks to the proposed method, prosumers can give cheap (surplus) energy to more members of the community for use or storage, and not only to a single prosumer or the grid. The same occurs in hours 20 and 21, where prices are the highest, when prosumers 1 and 2 exchange with more than one neighbor to reduce their bill.
Another contribution of the proposed method is the incorporation and definition of the participation of storage systems in the P2P market explained in Section 2, taking advantage of its flexibility. In Fig. 12 shows the comparison of the prosumer 1 battery behavior for the base case with the management of SoA method.
In this Fig. 12, despite a similar behavior of the battery some hours like 8 and 13, it can be observed the differences in the battery management between the methods. First, with the proposed method, the battery is used for fewer hours, only when necessary (6 hours versus 9 hours), because it is valued individually and differently from the other generation, thanks to the P2P market implemented different technologies with different prices. In several methods, such as the SoA method, a price is fixed previously for exchanges between prosumers, without distinguishing between the type of generation from which the energy is produced. This is not a realistic approach, in which energy from a battery has the same price as photovoltaic, because its assets are not made profitable and are not used correctly to reduce the bill. This article has been accepted for publication in IEEE Access. This is the author's version which has not been fully edited and content may change prior to final publication.  At 11th hour, when the grid price is expensive and there is surplus generation in the community, the proposed method charges the battery around 50% (1.15 kWh). In the proposed method, P2P market it uses to sell surplus PV generation at low prices between prosumers, instead of selling to the grid, to feed consumption and charge the batteries. Thus, prosumer 1 takes the opportunity to buy cheap energy from his neighbors in the P2P market. In the SoA method, since the price is pre-fixed between prosumers and not as the market closes, surplus is only sold to prosumers when the price is low. This is a handicap, since expensive network prices are not compensated with the P2P market to reduce the bill.
Another difference between the methods is observed in hour 20, where the proposed method discharges more energy. In addition to feeding its own consumption, prosumer 1 helps prosumers 3, 4 and 5 (0.76 kWh vs 0.05 kWh with SoA method). This fact is specially relevant in prosumer 4, which has its peak consumption in that hour. In hour 21, although it is the most expensive hour, with the proposed method less energy is sold between prosumers. Instead, the battery is discharged to feed its own consumption: 0.53 kWh. This is because the use of batteries is managed in order to ensure that storage energy is purchased in the market in the most expensive hour to reduce the bill, instead of buying expensive energy in the market, as with the SoA method. With the proposed method, between hours 20 and 21, a total reduction of 5.3% (the same as economic) of energy purchase from the grid is achieved.
+RXU D  With the market definition, prosumers buy little quantity of energy in expensive hours if there is no cheap energy (photovoltaic), in such a way that storage energy is managed to be used to feed their own consumption and not having to buy in any market. In the case of the SoA method, more energy is sold in expensive hours, which further increases the bill, because the batteries have not been managed to reduce own consumption as much as possible.
A summary of the transactions in the P2P market and energy sale to the grid is shown in Fig.13. It is observed that when there is solar surplus at 11 hours, the proposed method sells it in the P2P market to the neighbors to reduce the bill or store energy, while with the SoA method, it is preferred to sell to the grid, without considering the possibility that this energy can be used later. The proposed method sells solar surplus to the grid at 13 hours, because in those hours, despite being the lowest price, the consumption in the community is lower than in the previous hours.
Therefore, by defining a market in a specific way, with multiple exchanges, where prices are defined independently according to how the market closes and not fixed in advance, being parameters that can be decided in an optimization process, the community assets can be better managed to achieve the proposed objective.
12 VOLUME 4, 2016 This article has been accepted for publication in IEEE Access. This is the author's version which has not been fully edited and content may change prior to final publication. Citation information: DOI 10.1109/ACCESS.2022.3182698

VI. CONCLUSIONS
In this paper, a market to solve P2P exchanges is proposed, with a clear definition of its structure and scalable to numerous participants. It allows multiple exchanges of one participant with several, agreeing on different prices among them.
In this market, storage systems are treated specifically to take advantage of the flexibility they offer to owners. Depending on the price at which the market it is closed, batteries can be charged or discharged. This is an improvement that helps to integrate storage into the markets. Another improvement is that each prosumer can submit individual orders for its assets, making it possible to identify which asset it exchanges with the others. This allows for better valuation and profitability.
In addition, it is illustrated how this P2P market can be implemented with an optimization algorithm for optimal scheduling in the community. The results show how the proposed method fills the gaps with existing methods, such as allowing multiple exchanges and the identifying how much each asset exchanges. This helps to improve results and producing greater savings in the prosumers' bill.
Future work will focus on extending the use and application of this market in a community with a network model, taking into account the constraints associated with the lines. Another line of research is the use of this market together with Blockchain technology to achieve privacy and fast payment settlement in P2P energy trading.