The increasing number of photovoltaic (PV) systems in our energy system leads to a high share of decentralized production. Households or small businesses that were previously considered consumers only now have the opportunity to become prosumers. To go beyond individual self-consumption of single prosumers, collective forms of self-consumption take advantage of load aggregation to further optimize the use of resources (Frieden et al.1). By sharing or trading self-generated electricity within a certain framework, for example in energy communities, prosumers become active participants in the energy system. There are also opportunities to form local, decentralized electricity markets. In peer-to-peer trading, participants trade electricity directly with other participants, the "peers" (Bjarghov et al.2, Sousa et al.3, and Tushar et al.4). Peer-to-peer trading allows participants to increase their consumption of locally generated clean energy and to increase flexibility. Prosumers usually seek to maximize their economic or environmental benefits; hence, a fair pricing mechanism and trust in the community are crucial in this aspect. Furthermore, peer-to-peer trading and energy communities are opportunities to create new sustainable business models (F.G. Reis et al.5). When transitioning toward a world with a high share of renewables, it can be assumed that local electricity markets, such as peer-to-peer trading or pool markets, are more established and sufficient regulatory framework exists.
The core objective of this research is to investigate and optimize energy communities, wherein prosumers trade self-generated PV electricity with one another (peer-to-peer trading), including members’ entry and exit over time. The research question is the following: How would an existing energy community collectively choose an optimal new member/prosumer to engage in peer-to-peer trading? With the model developed in this work, it is possible to (i) choose between different prosumers, and (ii) choose the desired parameters of a new prosumer.
The method applied is based on a linear optimization model for local energy communities that was previously developed by the authors in Perger et al.6. The objective of this model is to optimally allocate electricity trades between community members considering each prosumer’s individual willingness-to-pay for locally generated PV electricity. To answer the research question, the model is extended to a bi-level optimization problem.
The model developed is an operating model rather than an investment model, assuming that in the future (i) many people will already have PV modules and (ii) PV systems will be "mainstream products" and therefore installing a PV system is a low barrier for those interested in joining a local energy market. In particular, a community’s new member selection and decision-making process is the subject of interest.
The next Section 2 presents a comprehensive literature review of local energy markets, peer-to-peer trading mechanisms, and the regulatory framework. Section 2 concludes with the paper’s contributions beyond state-of-the-art. Section 3 explains the methodology and modeling approach, and presents the data and assumptions of the case study. Section 4 presents the results of the case study, followed by a sensitivity analysis in Section 5. A conclusion and the outlook for future research needs in Section 6 complete the paper.
This Section provides a review and discussion of recent, relevant scientific literature regarding energy communities and peer-to-peer trading. Section 2.1 reviews state-of-the-art peer-to-peer trading modeling approaches. Section 2.2 gives an overview of related research on policy and legislation, with focus on Europe, and on the social aspects of energy communities. Section 2.3 presents this paper’s contribution beyond state-of-the-art.
A comprehensive review of existing literature and modeling approaches in the field of peer-to-peer trading is presented in Soto et al.7. Most peer-to-peer trading models consider consumers, prosumers, an energy sharing coordinator, and an electricity supplier/retailer. There are different approaches to implementing the energy exchange and negotiation processes. In Soto et al.7, they are categorized into trading platforms, blockchain, game theory, simulation, optimization, and algorithms. Different non-cooperative game theory approaches for peer-to-peer trading of prosumers in microgrids with PV systems and battery storage are developed in Paudel et al.8 and Zhang et al.9. A canonical coalition game for peer-to-peer trading is presented in Tushar et al.10, while Fleischhacker et al.11 compares a Stackelberg game with a welfare maximization model for PV sharing in multi-apartment buildings. Using a game theory framework to analyze the impact of three-part tariff and renewable portfolio standard on electricity pricing, Tsao et al.12 found that peer-to-peer energy trading benefits both residential and industrial prosumers through more flexible and cost-effective energy options. Continuous double auctioning models for peer-to-peer trading are developed in Li and Ma13, Chen et al.14, and Lin et al.15.
To decrease aggregated peak load, Bjarghov et al.16 developed a peer-to-peer trading capacity market formulated as a mixed complementarity problem (MCP). Sharing energy in a community-based market structure including fairness indicators is proposed in Moret and Pinson17. Jiang et al.18 presents a two-stage optimization approach, including social utility maximization in the first stage and payment bargaining in the second stage. Comparing three different models, Henriquez-Auba et al.19 found that a sharing economy model in which PV generation is traded among firms in a local spot market is a plausible pathway to maintaining and accelerating investments in PV systems, considering that feed-in programs are likely to be phased-out in the near future. Peer-to-peer markets with product differentiation are introduced in Sorin et al.20. In Hashemipour et al.21, virtual local energy markets with dynamic allocation of clusters that change on a daily basis are developed. Electric vehicles are pooled into the market to further increase flexibility. Nikkhah et al.22 developed a multi-level peer-to-peer energy trading framework for residential buildings. Ghaemi et al.23 investigate how the risk behavior and flexibility options of local energy communities impact their profits from peer-to-peer energy trading, particularly in the absence of renewable energy subsidies. Using a multi-leader–multi-follower game model, the study finds that while flexibility from distributed energy resources boosts profits, risk-averse strategies reduce financial gains. Espadinha et al.24 develop a peer-to-peer energy optimization model to evaluate energy communities' contribution to Portugal's 2050 decarbonization goals, finding that collective self-consumption and trading can reduce costs by over 31% and CO2 emissions by over 26%.
Potential congestion and voltage problems in the distribution network considering the increasing penetration of Distributed Energy Resources are addressed in recent papers on peer-to-peer trading. For example, Dynge et al.25 analyze the impact of the low voltage grid on local markets. As the physical distribution network is used for trades in local electricity markets, a market clearing approach considering network fees and power losses is introduced in Paudel et al.26. Faria et al.27 examine three coordination methods to manage peer-to-peer energy trading among prosumers while addressing network constraints like voltage and congestion. It finds that a method, which incorporates a flexibility market with an AC Optimal Power Flow for managing upward and downward flexibility, delivers the highest social welfare while ensuring network stability. The Euclidean distance of the distribution network between peers is included as grid-related costs using a product differentiation method in Orlandini et al.28. Another product differentiation approach is presented in Khorasany et al.29 in which network constraints are considered using a power transfer distribution factor to represent the contribution of transactions in the line flows. Considering electrical distances between prosumers, Guerrero et al.30 include a shortest path algorithm in their peer-to-peer market design and compare stable-matching and continuous double auction allocation mechanisms. An optimization problem solving matching between peers, including least-cost energy path algorithms, is proposed by Jogunola et al.31.
A selection of real-life implementations of peer-to-peer trading examples includes Piclo (Piclo32) in the UK, The Brooklyn Microgrid (Microgrid33 and Mengelkamp et al.34) in the US, Vandebron (Vandebron35) in the Netherlands, and the sonnenCommunity (sonnenGroup36) in Austria, Germany, Italy, and Switzerland. A detailed review of existing peer-to-peer trading projects including those mentioned is found in Zhang et al.37.
A number of legal instruments are included in the European Union’s Clean Energy Package Directorate-General for Energy (European Commission)38 introducing the legal framework to establish the sharing/trading of self-generated electricity and to initiate economic incentives for its practice. EU member states are obliged to enable the entrance of these active participants into markets. Furthermore, the Clean Energy Package introduced a definition of peer-to-peer trading. Nevertheless, many regulatory aspects of peer-to-peer trading remain unclear. A review of current European policies, legislation, and possible legal issues related to peer-to-peer trading and energy communities in electricity markets is presented in de Almeida et al.39. The European guidelines of the Clean Energy Package as transposed into Austrian law is analyzed in Fina and Fechner40.
Azarova et al.41 analyze how to design a Renewable Energy Community (REC) to increase social acceptance, finding that acceptance for solar farms and power-to-gas infrastructure is high, mixed for wind farms, and low for gas power plants and power lines. To gain more knowledge regarding individuals’ willingness to participate in energy communities, using regression analysis, Koirala et al.42 conducted a survey in the Netherlands to determine the importance of factors such as environmental concerns, renewable acceptance, community trust, and resistance (among others). According to the survey, perceived barriers for participation include lack of time, financial reasons, satisfaction with the status quo of the energy system, and no trust in the neighborhood.
According to the analysis in Hackbarth and Löbbe43 focusing on intentions of private households to participate in peer-to-peer trading mechanisms in Germany, highly interested potential participants exhibit environmental rather than economic preferences, and are drawn to innovative pricing schemes. Soeiro and Ferreira Dias44 found that trust is a key component and that citizens recognize the added non-monetary values of renewable energy communities. In another work by the same authors, Soeiro and Dias45 aims to understand the motivations of members in energy communities using a survey in Spain and Portugal. In said countries, citizens are willing to participate in energy communities if it benefits their local community and the environment. This statement is further supported by the key finding in Haji Bashi et al.46, which highlights that energy community initiatives are driven primarily by the desire to meet renewable energy targets and engage in energy-related social activities, like improving energy efficiency, rather than by economic benefits. Musolino et al.47 examines the emergence of RECs in Italy, following a 2020 law enabling their creation, and explores alliances among various actors (professionals, institutions, NGOs, citizens). Using Actor-Network Theory, the study analyzes three case studies to highlight how trust and local context influence the formation and organization of RECs, while suggesting trends or models for future research.
The inclusion of vulnerable consumers in the energy transition, who are generally underrepresented in REC projects, is discussed in Hanke and Lowitzsch48. The enabling framework to support inclusion remains rather unclear and should not languish as an idea on paper; therefore, lawmakers and policymakers should develop incentives targeting both RECs and individual vulnerable consumers. How the concept of fairness is applied in local energy systems is examined in Soares et al.49 by analyzing 80 scholarly papers. The study aims to define fairness within local energy systems, explore its interpretations (e.g., equality, meritocracy), and identify gaps in the literature, providing guidelines for future research.
Regarding peer-to-peer trading concepts in particular, Reis et al.50 developed a multi-agent framework to model peer-to-peer electricity within energy communities with an emphasis on vulnerable consumers and members’ economic outcomes, considering fairness in the distribution of energy resources. Fair revenue sharing and exit clauses are examined in Fioriti et al.51, to identify the optimal sizing of energy communities. Exit clauses, where a member leaving the community has to pay a time-decreasing fee, are introduced to ensure that the remaining members of the community do not experience any economic disadvantages.
To date, there has been minimal analysis of dynamic participation (entry and exit) in energy communities over time. This is where the present paper picks up. The contribution of the following analyses beyond state-of-the-art is summarized as follows:
A method is developed based on the peer-to-peer allocation mechanism presented in 6 to optimize energy communities with peer-to-peer trading, including the annual entry of new members.
A novel peer-to-peer model is proposed that simultaneously provides (i) an allocation mechanism for electricity trades between members and (ii) a new member’s selection process. Both (i) and (ii) take the prosumers’ individual preferences into account.
The selection process, which is of particular interest, operates from the perspective of the community members, wherein community members are searching for "optimal fitting participants" as opposed to optimal technologies.
The insights gained from the results and sensitivity analyses expand the understanding of the importance of participants’ individual preferences. These insights offer practical considerations to help establish stable and prosperous local energy communities.
In this Section, the methodology and modeling approach are described. The framework of the study explained in Section 3.1 is followed by a detailed description of the optimization problem in Section 3.2. Data and assumptions are presented in Section 3.3, and Section 3.4 introduces the verification of the proposed modeling approach.
3.1.1 Modeling framework. The framework of the modeling approach is a peer-to-peer electricity trading concept in a local energy community. Prosumers (or consumers or producers) join on a voluntary basis and exchange PV electricity generated by community members with one another. Figure 1 presents the basic idea of the peer-to-peer trading concept in this paper. All members are connected to the public distribution grid to be able to cover the community’s residual load, to feed in the surplus PV electricity, and to trade with the other community members (green arrows). Participants in the community are either households or small-to-medium-sized enterprises. The technology portfolio includes PV systems and battery energy storage systems (BESSs). In addition, each prosumer has an individual willingness-to-pay for PV electricity generated by community members, which determines the allocation of the peer-to-peer trading.
The aim of this work is to optimize the dynamic participation of prosumers in an energy community; hence, changes in the set-up of members over time (i.e., exit/entry). In Figure 1, the orange parts represent a new member joining the community.
In this context, new prosumers are characterized by (i) electricity load/demand, (ii) electricity generation (PV system and BESS size), and (iii) consumer-type (household or small business). Different consumer types are considered to show a wider variety of load profile types in the analysis. Along with households, small businesses are also a key target group for RECs. Other characteristics include electrical distance from the other community members, the minimum and maximum number of new prosumers, and the length of binding contracts with the community. The latter is out of scope for this paper.
3.1.2 Flow chart. The minimum length of a contract for prosumer participation in energy communities is assumed to be one year. There is a deadline each year; until then, members can decide to leave the community in the next contract period, or decide to stay and extend the contract for another year. In the meantime, prospective new members can declare interest in joining the community until the annual deadline. The flow chart in Figure 2 shows the process that is suggested to optimize dynamic participation in energy communities over a horizon of several years.
The starting point is the "old" community, where some members leave at the end of their contract period.
The status quo of the remaining members is then captured. Previous analyses of peer-to-peer electricity trading under the consideration of prosumers’ willingness-to-pay demonstrate two important characteristics for a community and its members: Overall community welfare1, and the annual emissions and costs of each member. These indicators are obtained by solving a linear program (see the model presented in Perger et al.6) to maximize community welfare of the original community configuration. The annual costs and emissions are then used as "benchmarks" for the optimization process.
After decisions about leaving, staying, or joining the community are made by all existing and potential new members, a bi-level optimization problem is solved to determine the optimal configuration of new prosumers. The lower level problem is linear community welfare maximization that was applied to the original community in the previous step to obtain benchmarks. The upper-level problem determines which potential members are selected by the community, and subsequently, the new prosumers’ parameters (annual electricity demand and peak capacity of the installed PV systems).2
Finally, the new community is defined and the process repeats in the next year.
In this work, the implementation of the proposed method is shown for one period (year) in order to focus on the selection process of the community that is conducted using the bi-level optimization approach.
3.2.1 Willingness-to-pay of prosumers. Prosumers’ individual willingness-to-pay determines how PV generated electricity is distributed among community members. The baseline of the willingness-to-pay is the retail electricity price, , and an individual CO2-price, wj, is added on top that relates to the prosumer’s preference for reducing emissions from electricity consumption. In addition, there is also a preference, di,j ∈ [0, 1], to buy more locally (i.e., buying from a prosumer with the shortest electrical distance3). The willingness-to-pay of prosumer j at time t to buy from prosumer i, wtpi,j,t , is as follows:
The emissions from the grid, et, are represented as a time series using the greenhouse gases emitted into the wider electricity system by the marginal power plant; hence, they are also known as marginal emissions. The local energy community is assumed to be a price taker in the wider electricity system.
3.2.2 Community welfare. In this work, the aim of peer-to-peer electricity trade is to maximize community welfare, which is the objective function of the lower-level problem. Part I of community welfare measures the optimal resource allocation at the community level. In other words the community minimizes the electricity bill from the retailer. Part II optimally assigns PV generated electricity to each member in consideration of their individual willingness-to-pay; thus, part II represents peer-to-peer trading from one prosumer to another, . Community welfare (CW) is defined as following:
3.2.3 Prosumers’ cost-emission function. To evaluate the impact of new prosumers on original prosumers, the following functions are defined:
Equation (3) is the deviation of prosumer i’s annual costs within the new community set-up compared to the previous status quo. Similar to Eq. (3), Eq. (4) represents prosumer i’s annual emission increase or decrease. The cost-emission function CE, which is the objective function of the upper-level problem, is defined next.
Similar to Pareto-optimization, a weighting factor αi ∈ [0, 1] is introduced for each prosumer to choose individually. Therefore, αi determines whether more emphasis is placed on minimizing costs or emissions. By choosing an individual αi, prosumers can express either a cost-saving or an emission-saving preference. Due to the absolute values of costs and emissions in Eq. (3) and (4), each prosumer’s changes count equally. The cost-emission function CE is the objective to be minimized in the optimization problem.
The costs of each member i of the community over a certain period are calculated as following:
where 𝒯 is the respective time period. The emissions over a certain time are:
Only purchases from the grid are considered in the emissions calculations, because the production of PV electricity does not generate marginal emissions.
3.2.4 Bi-level optimization problem. This model solves two main problems: (i) selecting the optimal electricity demand and PV capacity of new prosumers to fulfill certain requirements set by original community members, and (ii) maximizing community welfare, given the new prosumers’ parameters selected in (i). Subsequently, this problem can be formulated as a bi-level problem, wherein the leader anticipates the follower’s reaction. In the upper-level problem, the leader, of the bi-level problem represents (i) and its lower level, the follower, (ii).
The leader minimizes the cost-emission function CE with the continuous decision variables loadi and PVi, and the binary decision variables bi, for all i ∈ ℐnew (see Eq. (8a)). The decision variables have lower and upper bounds to ensure a reasonable solution of the model (see Eqs. (8b) and (8c)). The set of variables
are the lower level primal decision variables. The dual variables of the lower level problem are for equality constraints, for inequalities, and for non-negativities. The objective function of the follower in Eq. (8e) maximizes community welfare. The equality constraints (8f)–(8i) ensure that prosumer i’s electricity demand and PV generation are covered at all times. The upper-level decision variables are included in Eq. (8h) and (8i) for new prosumers. The state of charge of prosumer i’s BESS is defined in Eqs. (8j) and (8k), and other battery constraints in (8l)–(8n). Non-negativity conditions are included in (8o).
subject to:
subject to:
with i, j ∈ ℐ and t ∈ 𝒯.
A very common approach to solving a bi-level optimization problem is the transformation to a mathematical program with equilibrium constraints (MPEC); see Ruiz et al.52. The lower level problem (Eqs. (8e)–(8o)) is reformulated by its corresponding Karush-Kuhn-Tucker (KKT) conditions, and can be classified as a mixed complementarity problem (MCP) or equilibrium problem, which is parameterized by the leader’s decision variables (Dempe and Kue53). The resulting optimization problem is single-level, and it is linear except for binary variables and complementarity constraints. The derivation of the KKT conditions is presented in detail in A. The resulting complementarity conditions are then transformed into a mixed integer linear program (MILP) using the Fortuny-Amat method (see A.3), also known as the "Big-M approach" (Fortuny-Amat and McCarl54, Fischetti et al.55, and Pineda et al.56).
3.3.1 Model implementation. The model is implemented using Python (version 3.7.2; see Van Rossum and Drake57) using the Pyomo package (version 5.7.3; see Hart et al.58 and 59), and Gurobi (version 9.0.0; see Gurobi Optimization, LLC60) as a solver. Gurobi is a commercial solver. Alternatively, the problem can be solved with the open-source solver GNU Linear Programming Kit (GLPK). The model is available open source on GitHub (see Software availability).
3.3.2 Input data. To generate the results of a case study, a small community needs to be defined. The electricity demand of each member is obtained from the open-source tool LoadProfileGenerator (version 10.4.0; see Pflugradt and Muntwyler61), which generates artificial data. Different household types categorized by living situation and demographics (single working person, elderly couple, family, etc.) are included in this study.
The PV generation data are obtained from a different open-source tool Renewables.ninja (version v1.3; see Pfenninger and Staffell62, and Staffell and Pfenninger63). PV systems’ irradiation data and electricity output are location-specific to Vienna, Austria. Various PV system sizes and orientations are considered in the analyses presented in this paper, with the tilt uniformly set at 35°.
While the existing community is characterized by specific input parameters, standardized profiles for the new prosumers are used as input data:
is a standardized load profile (H0 for household, G0 for standard business4)), which is normalized to 1000kWh/year. For example, a result of loadi = 5 means that the optimal prosumer has an annual demand of 5000kWh/year. The possible range is between 2000 – 8000kWh/year.
is the generation profile of a 1kWpeak PV system facing South with a tilt of 35°; hence, the decision variable PVi is a factor that upscales the PV system size. The possible range is between 0 – 5 kWpeak from no PV system to a medium sized one.
A summary of the prosumers’ input data can be found in Figure 3 and in more detail in Table 1. The willingness-to-pay wi is arbitrarily assigned between the prosumers to cover a range between 0–100EUR/tCO2. The electrical distance factors dij ∈ [0, 1] can be represented by a symmetric matrix with diagonal elements all set to 0 (see Figure 4). The values assumed here are dummy values to represent electrical distances within a distribution network because the case study is artificial. The higher the value of dij, the further the electrical distance between prosumer i and j.

The willingness-to-pay wi of the new prosumers (H0 and G0) is not optimized, but varied in a sensitivity analysis.
Input data from the grid includes the following values: = 0.2EUR/kWh (the average value of the 2019 Austrian retail electricity price; see 64) and = 0.04EUR/kWh (average Austrian spot market price of 2019; see 65). Marginal emissions et are hourly values obtained from 66 (Austrian-German spot market), and average hourly values are found in Figure 22 in the Appendix.
3.3.3 Clustering in the time domain. Because MPECs are computationally expensive, an alternative approach is used to represent peer-to-peer trading within a community over a whole year. The input data that is available in hourly resolution for a whole year is transformed to three representative days using a k-means algorithm (Teichgraeber and Brandt67) of the Python tslearn package (Tavenard et al.68). The optimization model then determines the optimum using the three representative days considering the weight (each day represents a number of days of the year, which is then used to weight each representative day in the process of upscaling back to annual values; all three days represent the whole year) of each day in both the upper and lower level objective functions.
In the bi-level optimization approach shown above, the lower level problem maximizes the welfare of the community and optimally distributes the PV generated electricity within the community. This linear problem is replaced by its corresponding KKT conditions to solve the bi-level problem. The lower level KKT formulation is validated by setting the upper-level objective function to a constant (e.g., F(x) = 1) and ℐ = ℐold. With this configuration, the results of the bi-level problem are compared to the solution of the lower level problem without upper-level function, variables, and constraints (which equals the solution of the linear optimization problem based on the model presented in Perger et al.6).
The difference of all participants’ annual results (amount of electricity bought and sold, emissions, and costs) is calculated comparing the two solution methods. The box plot in Figure 5 presents the distribution of each category of results. The differences between the two solution methods are negligibly small in the scale of 10–13 and the KKT formulation of the lower level problem sufficiently substitutes the ordinary LP, which means that the Big-M method is appropriately applied (see Kleinert et al.69).
The bi-level modeling approach and the study presented in this work contain the following limitations. Firstly, the case study and the community set-up are artificial. Next, deterministic supply and demand functions and willingness-to-pay are used to conduct the study. Lastly, grid topologies are neglected and power losses are not taken into account directly. However, the modeling approach allows network topologies to be considered using the distance factor di,j.
This section covers the results of the case study described in Section 3.3 under various scenarios, including the original community without extension in Section 4.1, extending the community by adding a new house-hold in Section 4.2.1 and Section 4.2.2, and the comparison of household and business prosumer types in Section 4.3. The different scenarios are compared using fairness indicators in Section 4.4.
It is first necessary to take a deeper look into the original community’s peer-to-peer trading. The original community consists of six households with consumers and prosumers. The annual results (kilowatt-hours of electricity bought and sold, marginal emissions, and costs) of all members are presented in Table 2. Figure 6 presents the peer-to-peer traded electricity (in kWh/year) in detail as a heat map; rows represent the amount a prosumer sells to each peer, and columns are the respective purchases. Diagonal elements indicate self-consumption of the prosumers.

Compared to all other participants, prosumer 1 buys the most from the community, with the highest share coming from prosumer 2, who is prosumer 1’s closest peer and has a 5kWpeak PV system installed. Prosumer 1 does not own a PV system and has the highest willingness-to-pay. Prosumer 3 has the second-highest willingness-to-pay; however, they also have their own PV system installed, and mostly consume their own generation. Prosumer 2 prefers to sell to prosumer 1, with a higher willingness-to-pay than prosumer 3. Prosumer 2 clearly has the highest electricity demand within the community; therefore, the highest annual (marginal) CO2 emissions of the community, despite having large PV system capacities installed.
Prosumer 5, who is a consumer only, prefers to buy from their closest peers, prosumers 4 and 6. Prosumer 6 has very low annual electricity costs due to high-self-consumption and being able to sell electricity to other members of the community. Prosumer 4 is the only participant with a BESS and is able to further minimize their electricity costs, achieving negative annual costs.
One new prosumer with a household electricity demand profile (prosumer H0) is added to the original community of six households described above. The potential new member is characterized by a willingness-to-pay of 50 EUR/tCO2 (mid-range compared to the other prosumers) and by electrical distances as defined in Figure 4. Minimizing the objective function of the upper-level problem will determine the ideal parameters of the new prosumer. Annual electricity demand might vary between 2000kWh/year to 8000kWh/year, and PV capacity between 0kWpeak to 5kWpeak. The variable n (number of new prosumers) is set to one; hence, with one potential new prosumer the binary variable bi automatically equals one (see Eq. (8d)).
4.2.1 Cost- vs. emission-saving preference of prosumers. The first set of results shows two distinct cases; (i) where all members have an emission-saving preference (αi = 0), and (ii) where all members have a cost-saving preference (αi = 1). A third case (iii) with mixed preferences will be presented in Section 4.2.2.
(i) Minimizing emissions In the first case, it is assumed that all community members care about minimizing their annual emissions, but have no preference regarding cost savings; αi = 0 is set for all prosumers i ∈ ℐold. The result of the new prosumer’s PV system size is not surprising. The PV capacity is set to its maximum PVnew = = 5kWpeak. At the same time, the optimal electricity demand of the new prosumer is at its minimum loadnew = = 2000kWh/year. The new annual peer-to-peer trading values are shown in Figure 7. The annual results (kilowatt-hours of electricity bought and sold, marginal emissions, and costs) of all members are presented in Appendix Table 7.

Cost-wise, the newly added PV capacity can be seen as a competition with other members’ PV systems. Part of the revenue from selling electricity to consumers transfers to the new prosumer instead of old members, whose earnings now decrease. Notably, the annual emissions of all prosumers involved are reduced. Due to the newly added PV capacity, prosumers are able to buy more electricity from the community. The electricity demand of the new prosumer is low, such that there is little competition in consuming PV electricity.
The Sankey diagram in Figure 8 demonstrates that members of the original community (ℐold) cover their electricity demand through self-consumption, buying from other community members or buying from the grid. The left side represents the old community without the new prosumer, and the right side shows the new community. The new prosumer’s PV generation primarily substitutes purchases from the grid, which is desirable if the common goal is to reduce emissions. Prior to adding the new prosumer, community members purchase 10 700kWh from the grid. Adding a new prosumer with a 5kWpeak PV system installed, this amount can be reduced by around 8%. Prosumer 4, who has battery storage installed, can also increase their self-consumption.
The next Figure 9 presents the annual cost and emission increase (or decrease) of each prosumer of the original community, comparing Eqs. (3) and (4). Annual costs (left axis in red) increase slightly by a few EUR for most prosumers, whereas emissions significantly decrease, as desired. The total costs of the members of the original community (ℐold) increase by 12.9 EUR. The savings for self-consumption increase by 39.3 EUR.
(ii) Minimizing costs The other distinct case is setting all αi = 1, indicating that prosumers seek to minimize annual electricity costs. The optimal result of the bi-level problem is a prosumer with the maximum possible annual electricity demand loadnew = = 8000kWh/year. At the same time, the new prosumer’s optimal PV capacity is at its minimum PVnew = = 0kWpeak; hence, the new member is a consumer, who buys PV electricity from the community, which generates additional revenue for the other members. The new annual peer-to-peer trading values are shown in Figure 10. The annual results (kilowatt-hours of electricity bought and sold, marginal emissions, and costs) of all members are presented in Appendix Table 8.

The Sankey diagram in Figure 11 demonstrates that members can increase their income by selling a significant amount of their generation to the new prosumer, which was previously sold to the grid because the new prosumer’s willingness-to-pay is higher than the remuneration for selling PV generation into the grid wtpi,new,t > .
In total, about 40% of the community’s surplus PV production is sold to the new prosumer in this scenario, resulting in cost savings for prosumers with PV systems (see Figure 12). This is especially evident for prosumer 6, who is the closest neighbor of the new prosumer. The consumers of the community, prosumers 1 and 5 do not experience major changes. Emission balances offer another interesting result; the lower the willingness-to-pay (e.g., prosumer 2 with w2 = 0EUR/tCO2), the higher the annual CO2 emissions. Prior to adding the new member with a high electricity demand, higher amounts of PV generated electricity remained available for prosumers with low willingness-to-pay, which are now sold to the new member. Therefore, the savings from self-consumption for the members of the original community (ℐold) decrease in total by 146.5 EUR. This minus is compensated by additional income from peer-to-peer trading with the new prosumer. This leads to overall cost savings of 401.6 EUR. Prosumer 6, the closest neighbor of the new prosumer, achieves the highest cost decrease.
4.2.2 Prosumers with mixed emission and cost-saving preferences. While the prosumers’ choices of αi are uniform in both cases (i) and (ii) in Section 4.2.1, this Section introduces non-uniform values of αi. There is an extremely large number of possible combinations, many of which lead to the same results as either case (i) or (ii). Other combinations lead to different results; for example, [α1, α2, α3, α4, α5, α6] = [1, 1, 0, 1, 1, 0], which is presented here as case (iii). The optimal parameters of the new prosumer are set by the model to maximum PV capacity and maximum annual electricity demand, PVnew = 5kWpeak and loadnew = 8000kWh/year, respectively. The detailed peer-to-peer trading in Figure 13 shows that the new prosumer trades electricity with the other members, but predominantly self-consumes their PV generated electricity due to their own high annual electricity demand. This differs from case (i) in the previous Section, wherein the new prosumer has a low electricity demand and sells larger volumes of electricity to the other members, comparing Figure 14 with Figure 8.

Due to the high share of self-consumption in case (iii), the new prosumer buys only small volumes of electricity from the community (see Figure 15). In general, there are less interactions/trades with the community, which is reflected in the annual cost-emission balances as well. Figure 16 shows very small deviations from the previous status quo. Annual emissions decrease for prosumers 3 and 6, which is congruent with their preferences on saving emissions (α3,6 = 0). Annual cost differences are negligible (less than 2 EUR per year). The annual results (kilowatt-hours of electricity bought and sold, marginal emissions, and costs) of all members are presented in Appendix Table 9. The total costs of the members of the original community (ℐold) increase by 1.3 EUR. The savings for self-consumption decrease by 15.8 EUR.
Next, another potential new prosumer with the electricity demand profile of a standard business (prosumer G0) is compared to prosumer H0. The results are unchanged when the case study from Section 4.2 is conducted with prosumer G0 instead of H0; therefore, the binary decision variables are actively used in this step and the model is run with two potential new prosumers ℐnew = {prosumer H0, prosumer G0} to determine which prosumer type is preferred by the community. There is only one possible choice:
We start the analyses by minimizing the individual emissions again, as in case (i). The community prefers the household profile with the same parameters as seen in Section 4.2: PVnew = 5kWpeak and loadnew = 2000kWh/year. The annual peer-to-peer trading is shown in Figure 17 (left), wherein the business (prosumer G0) is not part of the community. The other cases, (ii) and (iii), minimizing the prosumers’ costs and mixed preferences elicit a different result. The business is a better match with PV generation profiles than the household (see Figure 22 and Figure 23 in the Appendix) and is, therefore, a better opportunity to sell surplus PV generation to. In case (ii) the business is a consumer only, with an annual electricity demand of 8000kWh (see Figure 17, right). The results are summarized in Table 3.

Fairness measures are now introduced to assess the community’s results from a different perspective. Various fairness indicators are used in network technology, which are adapted for peer-to-peer trading, similar to previous work from Moret and Pinson17. The first indicator is Quality of Service (QoS) to measure allocation fairness, referencing Jain’s index (Jain et al.70):
with
The QoS indicator considers the amount of electricity traded in the community. A QoS of one (100%) indicates perfect fairness, i.e., the trades (buying plus selling) of each member within the community are equally high.
The second indicator is Quality of Experience (QoE):
where σ is the standard deviation of the perceived electricity costs of the community members (individual electricity costs per unit calculated by dividing the total annual costs by the demand). σmax is the maximum deviation of perceived electricity costs within the community. A QoE close to one means that there is little deviation in perceived electricity costs (note that the indicator is already slightly distorted by the willingness-to-pay).
The third indicator is minimum-maximum fairness (MinMax), to compare the annual electricity imports of community members from the grid. The MinMax indicator obtains the ratio between the prosumer with smallest amount of electricity imports from the grid and the prosumer with largest imports. A MinMax of one indicates a community of prosumers with similar needs for electricity imports from the grid.
with the sum of electricity imports from the grid
These fairness indicators are compared for different sets of results, including the original community (Section 4.1), case (i) with a preference for minimizing emission and case (ii) with a preference for minimizing costs (Section 4.2.1), and case (iii) with mixed preferences (Section 4.2.2). The values are shown in Figure 18.

QoS, Quality of Service; QoE, Quality of Experience; MinMax, minimum-maximum fairness.
The QoS indicator is highest in case (ii) with QoS = 0.81. In other cases, including the original community, peer-to-peer trading is 65% fair. The new prosumer with a high electricity demand (case (ii)) increases the volumes traded in the community, which are rather fairly distributed within the community, given QoS fairness of more than 80%.
The QoE indicator improves by adding a new prosumer compared to the original community. Interestingly, the indicator is best in case (i). Adding additional PV capacity to the community helps to distribute perceived electricity costs more equally among members. However, the deviation of QoE between the cases is generally rather small.
Adding a new prosumer with high electricity demand slightly decreases MinMax fairness. In general, the MinMax indicator is rather small because prosumers with high demand for electricity naturally have higher volumes of purchases from the grid, especially without BESSs involved. In a community set-up including members with low demand and/or flexibilities, the import needs are rather divergent. Therefore, MinMax fairness is small.
The three fairness measures represent different characteristics of the energy community. QoS measures how fairly electricity trading is distributed, QoE compares the relative electricity costs of members, and MinMax assesses whether there is an imbalance in the amount of electricity members purchase from external sources, such as their individual retailers, outside the community. Those measures are interesting for members of energy communities so that they can assess how equally or unequally some aspects such as costs or trading volumes are distributed in the community.
This section presents sensitivity analyses to complete the results of this study. In Section 5.1, differing levels of the new prosumer’s willingness-to-pay are applied to the case study to determine possible changes in the results. In Section 5.2, the distances of the new prosumer to the other members are altered.
The first set of sensitivity analyses observes the effect of the new prosumer’s willingness-to-pay on the community decision. First, we compare the outputs of the bi-level model for different cases of prosumer preferences αi, as seen in Section 4.2.1 and Section 4.2.2, varying the new prosumer’s willingness-to-pay. Table 4 presents the results of cases (i)-(iii), where wnew is altered from one side of the spectrum of willingness-to-pay, wnew = 0EUR/tCO2, to the other, wnew = 100EUR/tCO2. There is no noticeable influence of wnew in cases (i) and (ii) (see Table 4). With either all αi = 0 or αi = 1, the parameters of the new prosumer, 2000kWh/5kWpeak and 8000kWh/0kWpeak, respectively, are clearly specified by the upper-level cost-emission objective function (CE), regardless the new prosumer’s willingness-to-pay.
In contrast, wnew can be a decisive factor when αi are mixed. With wnew = 100EUR/tCO2, the new prosumer’s optimal annual electricity demand decreases to 2000kWh, whereas lower willingness-to-pay leads to 8000kWh. Prosumer 6 has a preference to lower emission (α6 = 0) in case (iii). When wnew > w6 = 60EUR/tCO2, the peer-to-peer allocation assigns higher volumes of PV generated electricity to the new prosumer instead of prosumer 6, negatively impacting the cost-emission function CE and lowering the optimum electricity demand of the new prosumer.
wnew is the individual CO2- price of the new prosumer, loadnew and PVnew the resulting optimal annual electricity demand and PV capacity of the new prosumer, respectively.
Next, the community decides between two potential new members (similar to Section 4.3) with opposite levels of willingness-to-pay to analyze the influence of the willingness-to-pay on the community’s choice. The first example is two household (H0) prosumers, who are identical except for the willingness-to-pay, wH0,0 = 0 vs. wH0,100 = 100. The community’s choices can be seen in Table 5, columns two and three (highlighted). In cases (i) and (iii), a prosumer with a low willingness-to-pay is preferred, whereas, in case (ii), the community opts for the prosumer with high willingness-to-pay. The two subsequent columns on the right, which compares household (H0) and business (G0) prosumers, repeat this pattern.
wnew is the individual CO2-price of the new prosumers.
| prosumer type | H0 | H0 | H0 | G0 | G0 | H0 |
|---|---|---|---|---|---|---|
| wi in EUR/tCO2 | 0 | 100 | 0 | 100 | 0 | 100 |
| (i) individual emissions | ✓ | - | ✓ | - | ✓ | - |
| (ii) individual costs | - | ✓ | - | ✓ | - | ✓ |
| (iii) mixed preferences | ✓ | - | ✓ | - | ✓ | - |
An assertion can be drawn from the first set of sensitivity analyses that while willingness-to-pay is not a decisive factor in terms of choosing a new prosumer’s optimal parameters, it is crucial when deciding between two otherwise identical or similar prosumers. This leads to the assumption that willingness-to-pay is a more significant parameter than prosumer type.
The second type of sensitivity analysis alters the geographical location of the new prosumer with respect to the old community members. The altered distance factors, , of the new prosumer are mirrored compared to the original configuration, d:
where j are the indices of prosumers in ℐold; hence, the new prosumer is (geographically) on the other side of the community. The closest community member is prosumer 1, the furthest is prosumer 6. Note that the distances within the original community remain equal. The new distance factors can be found in Figure 19.
Cases (i)–(iii) are once again analyzed and the new prosumer is a household prosumer type with a willingness-to-pay wnew = 50EUR/tCO2. Deviation from the previous distance set-up is noticeable in case (iii), where the PV capacity changes to zero, whereas the other two cases remain the same, see Table 6. In cases (i) and (ii), the location of the new prosumer does not influence the community’s decision. To analyze the community’s decision in the mixed-preference (case (iii)), Figure 20 compares the prosumer’s volumes of traded electricity in two different scenarios: (a) the optimal output of case (iii) (loadnew = 8000kWh/year and PVnew = 0kWpeak) and (b) the non-optimal parameters of the new prosumer (loadnew = 8000kWh/year and PVnew = 5kWpeak) in Section 4.2.2, both with new distance factors The optimal parameters in scenario (a) lead to an increase in purchases from the community and a decrease in sales for the new prosumer (H0) compared to (b). Therefore, the prosumers of ℐold considerably increase sales volumes, particularly prosumer 2 with a cost-saving preference (α2 = 1), which compensates for the small decrease in purchases of prosumer 3 and prosumer 6, who have an emission-saving preference (α3, α6 = 0) in case (iii).
dnew and new are the unmodified and modified distance factors, respectively; loadnew and PVnew are the the resulting optimal annual electricity demand and PV capacity of the new prosumer, respectively.
| old distances dnew | new distances dnew | |||
|---|---|---|---|---|
| loadnew | PVnew | loadnew | PVnew | |
| (kWh) | (kWpeak) | (kWh) | (kWpeak) | |
| (i) ind. emissions | 2000 | 5 | 2000 | 5 |
| (ii) ind. costs | 8000 | 0 | 8000 | 0 |
| (iii) mixed preferences | 8000 | 5 | 8000 | 0 |
This work proposes a bi-level optimization model for dynamic participation in energy communities with peer-to-peer trading. The functionality of the model is demonstrated in a small case study and sensitivity analyses.
The model is able to choose the optimal parameters of a new member. This is the first step for gaining useful information on the kind of prosumer (e.g., consumer only or prosumer, high or low PV capacity, level of annual electricity demand, including or excluding BESS (the latter aspect was not shown in this research)) that is preferred by the community. Simultaneously, the model can determine whether the participation of a new member in the community is accepted or rejected; hence, a choice between potential members can be made. In this model, the case study was limited to one new addition to the community; however, it is possible to introduce a portfolio of new members without limiting the number of new members. The model determines the prosumers who are selected and the optimal number of new members at the same time. This is possible because binary variables are bound to each new member that determine acceptance or rejection. The optimal number differs based on the portfolio of members and the needs of the old community.
The community’s choice reflects well the different needs of prosumers. Environment- and profit-oriented preferences are balanced, and there is no bias toward one aspect or the other. Geographical distance and the new prosumer’s willingness-to-pay also influence the decision. If the community members have divergent needs, it is recommended to aim for a diverse set-up of members. There is, of course, also the possibility for the community to define a common goal, such as saving the community’s total emissions. In that case, the community must ensure that new prospective members commit to the same target.
Ultimately, the energy community must be able to attract suitable potential new members to guarantee its performance over the years. If members leave the community and cannot be replaced by new members who restore or improve the status quo, the satisfaction of existing members with the community decreases. In fact, this is a limitation of this work. The selection process is made solely from the perspective of the original community, assuming the availability of potential new prosumers who fit well into the community. Another limitation is that length of the binding contract between participants and community is always one year (and can be extended for another year after expiration); therefore, variations in contract lengths are not included in the decision process.
Future research should include analyses of communities with more diverse participants, such as different settlement patterns (cities or rural areas), community sizes, and other relevant parameters. Another possible future research topic is to study an energy community over a longer period of time (e.g., many years) including members with different contract lengths. Finally, analysis of dynamic participation from the perspective of Distribution System Operators (DSO) and/or community managers should follow.
Stationarity of the Lagrangian function:
Substituting the stationarity of the Lagrangian function (17a)–(17g) can be formulated with complementarity conditions as well (see Eq.s (18a)–(18g)). Eq.s (18h)–(18n) are the complementarity conditions of the lower level problem’s constraints.
The complementarity constraints are reformulated as a mixed-integer program applying the Fortuny-Amat method. The following set of equations shows the transformation of Eq. (18a), the other complementarity constraints, Eq.s (18b)–(18n), are transformed in the same way.
The value of M are M1 = 5000 and M2 = 2000, which were determined empirically, ensure the feasibility of the model and effectively no numerical problems.
The hourly input data of the case study is presented in the form of hourly average values. The original community prosumers’ electricity demand is shown in Figure 21. The average electricity output values of a 5kWpeak PV system is shown in Figure 22 (left axis), together with the marginal emissions from the grid (right axis). Figure 23 shows the standardized load profiles of household H0 and business G0, which are used in the case study to represent the potential new members.
Table 7–Table 9 present the annual results of purchases/sales from/to the grid and the community, self-consumption, battery operation, emissions, and costs for all prosumers 1–6 and prosumer H0. The tables are split into cases (i)–(iii) from Section 4.2.1 and Section 4.2.2.
Zenodo: FRESH:COM Dynamic Participation in Local Energy Communities with Peer-to-Peer Trading. https://doi. org/10.5281/zenodo.5791940 Theresia Perger71.
This project contains the following underlying data:
Input_data_alpha.csv Alpha values (αi) of all prosumers.
Input_data_distances.csv Distances (di, j) between the prosumers.
Input_data_grid_IAMC.csv Input data of the grid: electricity prices, marginal emissions (hourly values).
Prosumer 1.csv Input data of Prosumer 1: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer 2.csv Input data of Prosumer 2: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer 3.csv Input data of Prosumer 3: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer 4.csv Input data of Prosumer 4: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer 5.csv Input data of Prosumer 5: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer 6.csv Input data of Prosumer 6: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer H0.csv Input data of Prosumer H0: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Prosumer G0.csv Input data of Prosumer G0: PV capacity, BESS parameters, willingness-to-pay, electricity demand (hourly values), PV generation (hourly values).
Data are available under the terms of the Creative Commons Attribution 4.0 International license (CC-BY 4.0).
Source code available from: https://github.com/tperger/FRESH-COM
Archived source code at time of publication: https://doi.org/10.5281/zenodo.5796210 Theresia Perger72
License: Apache-2.0