Market Design and Trading Strategies for Community Energy Markets with Storage and Renewable Supply

: Community Energy Markets (CEMs) enable trading opportunities between participants in a community to achieve savings and proﬁts. However, the market design and the behaviour of participants are key factors that determine the success of such markets. To this end, this research presents a CEM model and conducts agent-based simulations to study the beneﬁts of the CEM to consumers and prosumers. The proposed market structure is an hour-ahead periodic double auction. In particular, market rules are proposed that incentivise the provision of energy supply to the community and the investment in energy storage. Furthermore, a trading strategy is introduced that leverages energy ﬂexibility created by the storage devices. Finally, as well as the hour-ahead market, we include a minute-by-minute balancing as part of the CEM’s energy exchange mechanism. The balancing approach is introduced to account for a community budget deﬁcit caused by the time difference between supply and demand. The proposed market results in cost savings for consumers and proﬁt for prosumers similar to existing approaches, while increasing the energy suppliers’ percentage of ﬁnancial beneﬁts from 50% to a range between 60–96% depending on the community conﬁguration. Moreover, the market model accounts for uncertainties in supply and demand and suggests a methodology to overcome the community budget deﬁcit.


Introduction
The smart grid is a promising technology to transform the traditional energy industry. Nowadays, the growth of Distributed Energy Resources (DERs) such as Renewable Energy Sources (RESs), energy storage and electric vehicles (EV) is significantly impacting energy networks [1]. Furthermore, consumers in the residential sector are increasingly aware of the environmental and economic benefits of using DERs such as solar photovoltaic (PV) or wind-based energy sources. Such on-premise RES combined with storage make their energy demands more flexible. In addition, it enables consumers to also become producers, the so-called prosumers (producers and consumers), and look for energy trading opportunities. To this end, some incentives have been put in place to encourage the use of RES at the residential levels, such as the Feed-in-Tariff (FIT) schemes where prosumers sell their surplus energy to the grid [1]. However, the FIT schemes are not always appropriately designed and can be inefficient, and thus often do not provide sufficient incentive for DER investment [2]. Therefore, there is a need to design energy markets where consumers and prosumers can trade with each other. Now, Community Energy Markets (CEMs) are a way to facilitate trading between participants in a community and create better financial situations compared to dealing with the grid. However, the market mechanism and the behaviour of participants are key factors that determine their success.
Researching those factors contributes to the creation of beneficial markets that could be adopted in the future to help reduce global CO 2 emissions and promote the use of sustainable energy sources. To this end, the aim of this paper is to propose a novel market mechanism for community energy markets, and through simulations show the benefits of such a market for the various participants.
There has been extensive work on designing and evaluating energy markets in recent years [3][4][5][6][7][8], ranging from economically to environmentally focused (see also Section 2). Most research in this area usually focuses on the overall economic benefits, such as cost reductions and profits to the community as a whole, and neglects how those benefits are distributed. Some research considers the equal distribution of benefits as one reasonable objective for CEM designs [9,10]. However, bearing in mind the investments that prosumers made to supply energy, other consumers in the market who are not adding any value are exploiting this equality. Moreover, the uncertainty in energy supply and demand poses a limitation to CEMs and needs to be thoroughly evaluated [11]. Therefore, in this study, we seek to design a CEM that promotes renewable energy supply through financial motivations and storage consideration, and that incorporates uncertainty in supply and demand. Moreover, we seek to evaluate the proposed model using agent-based simulations. In more detail, our contributions are as follows. First, we design a market model which provides financial incentives for energy suppliers and suppliers with storage capabilities. Second, we introduce a mechanism to address uncertainties in supply and demand. Third, we perform simulations using real market and household data in order to investigate and validate the proposed model.
The rest of this paper is structured as follows. Section 2 summarises related work in the area of CEMs and highlights the motivational research gaps for this work. Section 3 presents the proposed market model. Section 4 discusses the considered market agents and their trading strategy. Section 5 explains the market simulations performed, and Section 6 discusses the obtained results. Lastly, Section 7 summarises the paper and suggests areas for future work.

Related Work
The issue of market design for CEMs and microgrids has been widely explored in the literature. These studies can be broadly categorised into two groups depending on the market structure considered: peer-to-peer (P2P) approaches, where energy is traded bilaterally between pairs of participants, and centralised auctions. More specifically, the first group includes the works in [10,[12][13][14][15][16][17][18], and the second group includes works in [3,5,7,9,16,19,20].
In more detail, focusing on the former category, in [12] a local energy exchange system is presented, considering both the physical and the trading infrastructures, and simulating user behaviour using game theory. Focusing on the trading aspect, the authors of [13] consider different existing P2P energy sharing mechanisms with a focus on both economic and technical indices and realistic scenarios from the UK. Moreover, a very similar setting is also studied by the authors of [10], with a focus on PV generation integration. In a slightly different vein, the authors of [14] propose a regret-matching P2P procedure, which also includes transmission costs and a game theoretic analysis of the participants. Focusing now on the integration of RES, the authors of [15] employ a random-matching P2P procedure to link households with surplus RES generation with others with excess demand; their results showing that RES utilisation is greatly improved by the proposed P2P market. Moreover, this work is subsequently extended in [16], where the authors focus on the effect of different participant strategies, including zero-intelligence and learning agents. The authors of [21] take a different perspective and focus on the storage aspect of local P2P trading, considering both decentralised household-owned batteries, and centralised community storage. Finally, the authors of [17,22] review the state-of-the-art in real-world P2P trials and discuss their relative merits. All these works present consistent results: CEMs and local P2P trading present significant improvements, including monetary savings and profits, RES utilisation and congestion mitigation.
Regarding the second category, we can find two different types of auctions in the literature: continuous [19,20] and discrete [3,5,7,9,18]. In more detail, continuous auctions match buy and sell orders instantly and keep an order book continuously open (like stock markets). In contrast, discrete auctions are open for a certain interval of time, and clear the market periodically considering all the received orders. Specifically, the authors of [19] propose using a continuous double auction for energy trading, together with a real-time balancing market to mitigate energy imbalances. Moreover, line congestion is dynamically taken into account in the pricing of the traded energy. Furthermore, trading agents are also considered, including zero-intelligence and adaptive-aggressiveness strategies. In a slightly different vein, the authors of [20] also consider a continuous double auction in a similar setting but focus on agent behaviour, presenting a prediction-integration strategy that the market participants can use in order to perform more informed trading. In a different vein, the authors of [4,18] focus on the possibilities offered by blockchain technology as a framework for implementing CEM auctions, such as increased transparency and trust-less execution.
These existing P2P-and auction-based approaches demonstrate the benefits offered by CEMs, such as reductions in energy costs and grid congestion, and better grid stability by increased accommodation of RES. However, these works do not account for the uncertainty of future supply and demand. More specifically, the realised demand or supply will differ from the amounts of energy bid in a given market, given that no forecast is perfect. In this work we address this issue by considering both an hour-ahead market and a minute-by-minute balancing market where forecast deviations can be addressed. Moreover, although often the aim is to optimise the social welfare of all agents, little attention has been devoted to who the main beneficiaries are at the individual level, e.g., whether it is prosumers with storage supply and renewable energy or regular consumers as well. To this end, we consider the effects of the proposed CEM for different types of households and, in so doing, study the use of monetary incentives for investment in RES.
In addition to the works studying the design of CEMs reviewed above, the role of energy storage in such markets has also received considerable interest in recent years [16,21,[23][24][25][26][27][28][29]. In more detail, the authors of [23] study the creation of charging and discharging schedules for storage systems, with a focus on profit maximisation for communities purchasing energy from the grid, and their results show the economic benefits associated with the addition of storage. Similarly, the authors of [16,21] study the effects of adding storage to a P2P CEM design, and their results emphasise the higher market efficiency achieved with the introduction of storage. In a slightly different vein, others study the effects of adding storage to households with RES [24,25]. In these studies, storage and RES are shown to be tightly coupled and to provide significant cost reductions together, in comparison to only either of them being present in the household. Similar scenarios, but from a business perspective, are analysed in [26,27]. In these works, both the accommodation of solar generation and the load-shifting necessary to avoid congestion and demand peaks are considered. Moreover, different battery technologies are considered, and several techno-economical indicators studied, showing that storage is able to significantly reduce the dependence on the grid. The authors of [28] consider a different perspective, focusing on the issue of planning the location and capacity of local storage systems in a micro-grid with photovoltaic generation. In more detail, the authors perform a cost-benefit analysis of such storage systems and propose a planning strategy that maximises the total net present value of the storage system for the micro-grid. Finally, the authors of [29] look at the possibilities offered by storage from a policy perspective. With the aim of improving the efficiency and operation of both large-scale grids and micro-grids, the authors propose defining storage as a new and important class of grid participants, and consider it essential for the the smart-grid paradigm. Overall, storage is seen as a key element in the transition to the smart-grid paradigm and is shown to provide ample benefits to prosumers participating in both CEMs and traditional electricity markets. However, many of these works ignore the business aspect of investment in storage. To address this issue, we study the provision of monetary incentives to households for investing in storage solutions.
Finally, another relevant area of the literature is the investigation of trading strategies for household participation in CEMs. Different types of algorithms have been proposed in previous literature, including zero-intelligence (ZI) [3,16,30], zero-intelligence plus [19] and forecasting-based agents [16,20]. Among these, the former are only valid as a proof-of-concept due to their simplicity. The second type include some degree of sophistication, usually by keeping track of margin prices that get updated with some simple rule in every sequential auction. Although these techniques have been shown to significantly outperform ZI agents, they are quite simple and do not exploit most of the information available to the agent. Finally, the third group is quite generic and may contain many different types of algorithms, characterised by exploiting the data available to the agent and using forecasts to optimise their behaviour. Examples of these include the extreme machine learning models presented in [20], the reinforcement learning approach in [31], the constraint satisfaction problem in [32] or the support vector machine forecaster in [30]. In a similar vein to these works, we propose a trading algorithm which exploits the flexibility provided by the available storage and a forecast about future supply and demand to optimise the household participation strategy.

Market Design
In this research, a residential community is considered where the physical exchange of energy is assumed possible via a microgrid network and smart grid technologies. The households are participants in the CEM. The community is assumed to be always connected to the grid. The grid is assumed to have a continuous supply of energy without interruptions and no limits on the feed-in energy from households with excess renewable supply. A household can only import or export energy at any moment and cannot do both at the same time. This constraint is referred to as the one-way flow of energy assumption. This section is structured as follows. First, a brief explanation of the two-sided auction is presented in Section 3.1, followed by definitions of the market players in Section 3.2 and the trading rules in Section 3.3. Section 3.4 explains the optimisation problem to solve for pricing and clearing. Section 3.5 presents the adopted method for allocation. Section 3.6 describes the minute-by-minute balancing approach to fulfil energy and the proposed secondary market. Finally, the accounting method to calculate the bills is presented in Section 3.7.

Two-Sided Auction
Auctions are a common trading mechanisms whereby traders submit offers for buying or selling goods. A bid is an offer to buy a good, whereas an ask is an offer to sell a good. Two-sided auctions allow both bids or asks and aims to match these resulting in an exchange. The time interval when orders can be submitted is referred to as the trading period. A discrete-time auction permits the exchange of goods only at the end of the trading period. A famous example of a discrete-time two-sided market is the clearinghouse where the offers are cleared at the end of each trading period [33]. The CEM presented in this work is modelled as a repeated clearinghouse auction with uniform pricing, which means that there is a single price for all the accepted transactions in that period.

Players
The primary players are consumers (i.e., buyers), suppliers/producers (i.e., sellers) and prosumers (who can be both buyers and sellers). These players are represented by so-called software agents, which are able to autonomously trade energy on their behalf. The fourth market player is the grid. Last, a market facilitator is introduced to perform support tasks. The remainder of this section will detail these market players.
In more detail, buyers (i.e., consumers and prosumers) can submit bids to the market to purchase energy. A bid contains a quantity in kWh and the maximum price accepted to pay for each kWh in pence. Similarly, sellers submit asks containing a quantity in kWh and the minimum price accepted to sell each kWh in pence. More importantly, buyers and sellers can submit multiple such orders. For example, a seller may be willing to sell its first 10 kWh for 20 pence, and its next 10 kWh for 50 pence. This can be achieved by simultaneously submitting two asks.
Prosumers and suppliers can produce energy through either renewables or a storage device. In practice, storage is typically sold in combination with renewable energy installations. Therefore, we assume that households with storage will also have some renewable, although we will also have households with just renewable (or no supply at all). Prosumers with energy storage devices are referred to as flexible agents.
The grid is an essential player in the market and represents a (private) energy supplier. It resolves any imbalance by providing or accepting energy that could not be fulfilled within the community market. The grid is assumed to have two fixed prices: a bid and an ask. These are varied in our experiments. The bid price is denoted by G b per kWh and represents the residential energy price when energy needs to be purchased without the CEM. The second price is effectively a feed-in-tariff, and is denoted by G s . We assume these are available at sufficient capacity to address any imbalance.
The market facilitator receives the bids and asks from the agents, determine the exchange price, allocates energy fairly and calculates the agents' bill. These issues are discussed in more detail in the subsections that follow.

Auction Rules
In this work, we consider an hour-ahead market. The trading period for exchange in the next hour opens at minute 45 of the current hour and closes at minute 55. Agents submit their bids and asks during this 10-minute interval. A trading period is referred to as a market round. The hour which agents are trading for and energy is physically exchanged in is referred to as the energy exchange period. An agent can submit multiple offers with different prices, but once an offer is submitted, it cannot be recalled. Two minutes before the energy exchange period starts, the facilitator announces the market round (auction) results, which specify the price, the winning agents and their energy allocations. At the end of each energy exchange period, the demand and supply amounts are used to calculate the agents' bill. The proposed market timeline is depicted in Figure 1.

Clearing
At the end of each trading period, the clearing price and trading quantity or volume are calculated based on market equilibrium matching using uniform pricing [34]. The market objective is to maximise the equilibrium trading volume. There are typically two different types of goals when it comes to auctions: maximising social welfare or maximising trading volume. Maximising volume would be better for a community energy market because, in our proposed market, the private values of the buyers and sellers which are required to compute social welfare are unknown. In addition, using a uniform pricing approach, as in our model, we aim to trade as much energy as possible to reduce energy exchanged with the grid. Therefore, given the set of bids N B T for market a round T, where b i and d i i ∈ N B T are the bid price and demand quantity respectively, (1) calculates the demand quantity for a price p. Moreover, given the set of asks N A T , where o i and s i i ∈ N A T are the ask price and supply quantity, respectively, (2) calculates the supply quantity. Therefore, for a price, p, (3) calculates the market trading volume Q(p).
The facilitator is responsible for finding the auction clearing price P that maximises Q. If there are two or more prices that achieve the same trading volume, this referred to as a buy-sell gap. In this case, the clearing price P is then chosen in the middle between the minimum ask and maximum bid so as to not favour suppliers in all situations, and to provide some benefits to consumers. Therefore, P is the average of the set P returned by (4) as represented by (5).
Algorithm 1 shows the steps to compute the clearing price and the trading volume given N B T and N A T . Moreover, Figure 2 shows an example clearing price alongside the corresponding supply and demand curves. The shaded area refers to social welfare, which is the total utility of the buyers minus the total cost of the sellers [35]. Although social welfare as defined in (6) assumes the knowledge of the true demand and supply curves using the private sellers' cost (c) and buyers' marginal benefit (m), in our setting, the submitted bids and asks are used to represent the supply and demand curves.  Example of computed clearing price and trading volume for a market round. The bids and asks prices are always within the grid prices. The clearing price is in the middle of the buy-sell gap. Demand/supply at any price is the aggregate bids/asks that could be fulfilled using this price. The shaded area corresponds to social welfare using the bids and asks as the traders private values.

Algorithm 1 Compute Clearing Price and Volume.
Input bids list N B T , asks list N A T Output clearing price P and trading volume V Loop over the unique set of bid prices q ← Q(p) Compute the volume for price p using (3) bidsQ ← bidsQ || (p, q) Append price p and volume q to the bids list Loop over the unique set of asks prices q ← Q(p) asksQ ← asksQ || (p, q) Append price p and volume q to the asks list maxQbid ← max(bidsQ.q) Get the bid with max volume maxQask ← max(asksQ.q) Get the ask with max volume if maxQbid.q > maxQask.q then Return null if no trade can be done return P, V Return the clearing price and the trading volume

Allocation
After the clearing price and the trading volume are computed, the facilitator needs to distribute the cleared energy among the winning agents. Sometimes demand from the winning buyers is more than supply or vice versa. Therefore, an allocation mechanism is needed to distribute the cleared energy. The adopted allocation approach is an envy-free division protocol [36]. To explain our motivation, let us consider this more detailed description of the problem. First, once a clearing price is determined, the clearing mechanism needs to determine a precise energy allocation, i.e., who supplies energy and whose demand is met. Buyers whose buy price is highest are matched with sellers whose price is lowest. However, at the border where demand meets supply, there could be multiple agents who have the same price. The problem is then choosing who should contribute and how many resources should they contribute. The algorithm is based on a proportional selection but takes into account the individual agent's constraints. For example, suppose that, at a price p = 5, there is demand of 9 units, and a supply of 2, 5 and 10 units by agents 1, 2 and 3, respectively. Therefore, there is a demand of 9, but a supply of 17. The question is: how to select who supplies energy and how many units. If we divide these proportionally, then each agent would contribute 3. However, agent 1 can supply a maximum of 2 units at that price. Therefore, we have a preliminary allocation of 2, 3, 3, which equals 8 units. Therefore, there is 1 unit left that needs to be allocated in a second round. Again we divide this proportionally between the remaining agents (2 and 3), and they contribute 0.5 each. This is within their maximum supply, so the algorithm stops, and the final allocation is 2, 3.5, 3.5. This seems a natural way of dividing the resources. We call this allocation envy-free as no agent is envious of the allocation of the other agents. In more detail, for a set of players R and an energy quantity E to be divided, this protocol guarantees at least 1 R for each player. This way, no player is envious or desires the share of another player. If a player desires less than the minimum share, he/she is allocated what he/she desires, and the leftover energy is redistributed on the remaining players who desire more. In situations where the winning demand is more than the winning supply, the set of players R becomes the winning buyers, and E becomes the wining supply. Otherwise, R becomes the set of winning suppliers, and E is the winning demand. The procedure for the division protocol is shown in Algorithm 2. Agents who did not win in the auction are implemented as if they have a desire of zero. For each round T, the demand allocation for an agent a is denoted as LD a T , and the supply allocation is denoted as LS a T .

Algorithm 2 Envy Free Division.
Input energy amount E and list of agents with their desire R Output a dictionary of agents with their shares resulting from the division Sort winning agents' desire in ascending order Return agents with their shares

Balancing
Agents are assumed to demand or supply more or less than what they were allocated in the market. The excess supply, for instance, can be caused by a surge in solar energy on a sunny day. Similarly, the excess demand can be caused by increased human activities. This behaviour is referred to as uncertainty in future supply and demand. Storage, on the other hand, can help reduce this uncertainty and preserve energy to be used when needed. Naturally, the difference between the allocated and exact energy amounts should be reflected in the agents' final bills, which will be explained in Section 3.7. However, first, an energy balancing method needs to be implemented to fulfil the community's energy needs. The proposed balancing mechanism is a minute-by-minute approach. Before we discuss how energy balancing is achieved, we need to consider the time differences between agents' allocated supply and demand, as it is not reasonable to assume that energy exchange in the hourly round will overlap perfectly. This issue is depicted in Figure 3. This condition creates an energy quantity that has to be fulfilled by the grid, and for which no agent is responsible, as agents are only accountable for their net energy at the end of each hour. This results in what is referred to as a deficit in the community net bill.
We define three sources of energy used to satisfy the agents' energy needs, which are inflexible energy, flexible energy and the grid. Inflexible energy is the energy that needs to be fulfilled no matter what, such as an appliance's demand or excess solar energy with no storage which has to be exported. The energy that is or could be charged or discharged from storage devices is referred to as flexible energy. This energy is sometimes used to fulfil inflexible energy in order to avoid dealing with the grid and to maintain the benefits within the community. The grid's energy is always considered as the last resort if any needs cannot be satisfied by the other two types of energy. Therefore, to fully utilise the energy within the community, the concept of demand and supply ability at a given minute is introduced, representing the amounts agents can demand or supply in a given minute. For agents without storage, the demand and supply abilities are the same as their exact needs in a given minute. However, for agents with storage, their abilities change every minute depending on their needs and their storage state. The formulas used to compute the demand and supply abilities will be explained in Section 4.2. The proposed balancing method uses the demand and supply abilities to facilitate the energy exchange of the allocated market amounts and resolve any imbalance. Energy can be exchanged between agents outside the allocated market amounts within what is referred to as the secondary market, which is explained next in Section 3.6. The algorithm for the balancing methodology is shown in Algorithm 3. This algorithm treats agents with no storage devices as if they have storage devices with zero capacity. This approach makes the implementation functional for agents with and without storage. The algorithm uses some functions that will be presented in Section 4.  . An example of the imperfect overlap between a consumer and a supplier each allocated 2 kWh. In the first half-hour, no supply is available, so there is a shortage of 1 kWh. The supplier's entire 2 kWh is exported in the second half of the hour, which creates a surplus of 1 kWh. Assuming both agents do not have storage, the shortage and surplus have to be fulfilled by the grid. Thus, 1 kWh is imported at G b , and 1 kWh is exported at G s . This condition creates a net bill deficit because both agents demanded and supplied exactly their allocation, but some energy was exchanged with the grid to resolve the imperfect overlap.

Secondary Market
The uncertainty in supply and demand creates secondary exchange opportunities between agents. However, to avoid strategic behaviour, inflexible energy is exchanged at grid prices. Therefore, instead of one supplier exporting his energy at G s and the consumer importing it at G b , they exchange the energy at those prices, and the community gets the profit instead of the grid. This profit is referred to as a surplus in the community net bill, which is used to compensate for the deficit resulting from the imperfect overlap between supply and demand discussed in Section 3.6. If the energy exchanged is flexible, the situation is different. The secondary market provides an opportunity for agents with storage to capitalise on the inflexibility of other agents. Flexible supply can be used or sold later, whereas the flexible demand is extra energy that can be stored. Therefore, agents with storage involved in the secondary exchanged, act as the grid. They get the benefits of fulfilling inflexible energy. Therefore, when an inflexible consumer needs energy, he pays G b , the flexible agent providing this energy receives G b instead of G s because he supplied this energy as the grid would. The flexible agent does not lose anything because if this energy is needed later, it can always be imported from the grid at G b or from the market at a lower price.

Algorithm 3 Balance Market.
Input agents list A, allocated demand dictionary for current round LD T , allocated supply dictionary for the current round LS T , minute t, current round cleared price P T and the community energy accounts accounts Output updated community accounts procedure BALANCEMARKET(agents, LD T , LS T , t, P, accounts) Now compute remaining for all agents for secondary market

Accounting
Similarly, when an inflexible supplier exports energy, he/she receives G s , the flexible agent pays G s instead of G b because he/she received this energy as the grid would. Also, the flexible agent does not lose anything because this energy can always be exported at G s , used for self-consumption or sold to the market for profit. Note that when flexible energy is used in the secondary market, it always fulfils inflexible energy. Naturally, the benefits of the secondary market apply only to the flexible energy amount provided. For example, an agent might provide 1 kWh from his storage as flexible energy, and 2 kWh that could not be stored as inflexible, so he/she only gets the benefits of the flexible quantity. Because of the positive advantage crated by the secondary market, all flexible agents are assumed to participate. The energy exchanged within the secondary market creates a division problem to distribute inflexible energy that needs to be fulfilled, which is solved using the envy-free division presented in Section 3.5. A notable limitation to consider is the direction of energy. If a flexible agent is supplying energy to fulfil his allocated market amounts, he/she cannot also demand energy from the secondary market at the same minute. The flow of energy has to be one-way. Therefore, if a flexible agent is supplying to fulfil his allocated supply, he can only supply more energy to the secondary market in the same minute. The same applies to the demand case. Section 3.7 will explain how the energy from the primary and secondary markets are reflected in the agents' bills.
The accounting function refers to the bill calculation method, which determines the cost of energy to consumers and the income from sold energy for suppliers. This accounting should be simple in order to clearly communicate to the market players how their bills are calculated. The results from the energy balancing are used in the accounting function with additional conditions. In the balancing function, energy might be fulfilled by the grid because of the imperfect overlap between agents supply and demand for which no agent is responsible. Yet, it is accounted in the community's net bill. Thus, to calculate the agents' bills, the total energy for each agent at end of each round is calculated. For a round T and an agent a, the sum of demand energy imported within the market allocation is denoted as DM a T , and the demand imported within the secondary market as D2 a T , the demand imported from the grid as GI a T , his flexible demand as DX a T and his allocated demand LD a T . We denote the supply exported within the market allocation as SM a T , the supply exported within the secondary market as S2 a T , the supply exported to the grid as GE a T , his flexible supply as SX a T and his allocated supply as LS a T . Last, Equations (7) and (8) calculate the total imported demand denoted as D a T and the total exported supply denoted as S a T .
The market facilitator maintains energy amounts from the balancing algorithm and is responsible for calculating all the bills at the end of each hour. A positive bill represents a cost, and a negative bill represents an income. The bill calculation for inflexible energy is straightforward. If an agent consumes or supplies what he was allocated in the round, he pays or receives the cleared market price P T for that energy amount. For each kWh of excess demand, he pays G b , and for each kWh of excess supply, he receives G s . When an agent consumes or supplies less than his allocation, he is penalised. The penalty is needed because the difference is still provided by other agents who trade all their allocated amounts using the cleared price. Besides, this charge is necessary to enforce the market allocations and prevent agents from exaggerating their offer with no consequences. The demand shortage fee is denoted as DF T and the supply shortage fee as SF T , which are defined in (9) and (10).
When excess inflexible demand and supply are exchanged within the secondary market, a surplus is created in the community net bill, as explained in Section 3.6. However, this unclaimed profit is needed to compensate for the deficit created from the imperfect overlap of supply and demand. Also, trading excess energy at grid prices prevents inflexible agents from misreporting in the auction to strategise over the secondary market.
Flexible energy bills are calculated slightly differently because of the secondary market. Similar to inflexible energy, for each kWh consumed or supplied within the allocated amounts, flexible agents pay or receive the cleared market price P T . If they provide any excess flexible supply or demand within the secondary market, they act as the grid. Therefore, for each kWh of excess flexible demand, they pay G s , and for each kWh of excess flexible supply, they get G b . If a flexible agent consumes less or supplies less than his allocation, he also pays the shortage fees. Thus, for an agent a and a round T, (11) and (12) compute the net demand cost denoted as C a T , and the net supply income I a T respectively. The agent net bill, denoted as B a T is defined by (13), and the grid net bill, denoted as B G T is defined by (14). Finally, a bill is defined for the community budget balance, which is the amount needed to balance all agents net bills and the grid to zero. The community budget balance is referred to as the community net bill, denoted as B C T and is represented by (15). The accounting algorithm to compute the hourly bills is shown in Algorithm 4.
The accounting algorithm maintains the hourly bills for all agents in the facilitator's accounts database. The next section will present the agents' energy prediction and their bidding strategy.

Algorithm 4 Compute Hourly Bills.
Input agents list A, accounts book accounts and round T, Output updated accounts procedure COMPUTEHOURLYBILLS(A, accounts, T) Require: A = ∅ bills ← {} Initialise empty dictionary for the bills P T ← clear price for round T start of the round T t s , end of the hour t f for a in A do Loop over all agents list Update accounts with bills

Agent Trading Strategies
This section will explain the energy profiles in Section 4.1, followed by the energy prediction method in Section 4.2, and concludes with the agents' bidding strategy in Section 4.3.

Energy Profile
A set of agents A is defined where an agent a ∈ A has an energy profile in minute resolution n a i i ∈ [0, . . . , T ] where n a i is positive for energy demand and negative for energy supply. An agent with renewable supply or a prosumer is assumed to always first self-consume this supply. Therefore, when n a i is negative, this agent has already self-satisfied its demand and has more supply.

Energy Prediction
Agents in this work predict their demand or supply based on past values using a look-back amount denoted as k. Thus, for a given time t, the predicted energy n a t = n a t−k where t ∈ [0, . . . , T ]. If k is 0 and t is in the future, this assumes the agent has complete knowledge of his future energy needs and can predict his profile with perfect foresight. Although such perfection in prediction, in reality, is highly unlikely, it is worth exploring and will be discussed in Section 5 in more details.
For an inflexible agent a ∈ A, the predicted energy demand, denoted as D a T , and the predicted energy supply, denoted as S a T , for a time interval T where the starting time in minutes is t s and the end time is t f , are represented by (16) and (17), respectively, where k is look-back amount in minutes used to compute n a t .
For a flexible agent a ∈ A, a storage device is defined with capacity a of C a , a charge power of V a − and a discharge power of V a + and a state of charge profile SC a t where t ∈ [0, . . . , T ]. A storage device can only discharge or charge at any given time and cannot do both. An energy profile w a t is defined for the estimated energy profile after storage fulfilment. The predicted energy profile using the look-back k is used alongside the current SC a t to predict a new energy profile after using the energy storage. w a t is calculated using (18).
Note that while calculating the energy profile w a t , at each t, the SC a t is updated with the fulfilled amount from n a t . Similar to inflexible agents, the predicted demand and supply are calculated via (16) and (17), but using w a t instead of n a t . These are the predicted inflexible demand and supply, which cannot be fulfilled by the storage device.
Storage devices give flexible agents the ability to supply or demand more than they need. This ability allows these agents to sell or buy more if the price is suitable and to participate in the secondary market to fulfil their inflexible energy. First, flexible agents need to estimate how much demand or supply can they offer in the market. An agent's maximum demand and supply abilities are defined as the maximum amounts the storage device can charge or discharge at time t plus the agent's estimated net n a t . The flexible agents maximum demand for a time interval T with start time t s and finish t f , and a look-back value k is defined by (19). The storage demand is reduced by the predicted excess energy that needs to be stored, or is added to the agent's demand. When n a t is positive, this means the agent has energy need that could either be fulfilled by the storage or by the market. However, if the storage fulfils this demand, then at this moment, the storage cannot charge because it is discharging to fulfil this energy need. Therefore, the storage demand ability at this moment is zero. In contrast, if the agent's need is added to the storage demand, the agent can request more from the market to cover his needs and store the rest. The second approach is implemented to maximise the potential energy stored. If n a t is negative, the agent can demand from the market the remaining in his charge power if available or zero.
Similarly, the maximum storage supply and for a time interval T is defined by (20). The storage supply is reduced by the predicted needed energy or is added to the agent's supply. When n a t is negative, this means the agent has an excess supply that could be stored or exported to the market. However, if this supply is stored, then at this moment, the storage cannot discharge because it is charging with the excess supply. Therefore, the storage supply ability at this moment is zero. In contrast, if the agent's supply is added to the storage supply, the agent can offer more to the market. If n a t is positive, the agents can offer the market the remaining in his discharge power if available or zero. Again, the second approach is implemented to maximise the potential energy offered to the market.
In computing the maximum demand ability and supply ability for a flexible agent, at each t, a temporary SC a t is updated with the maximum charge or discharge amounts to be included in the calculation of t + 1. The maximum demand and supply in (19) and (20) contains both flexible and inflexible energy. Agents need to distinguish between them for bidding reasons. Therefore, flexible energy is calculated by subtracting inflexible energy from the maximum demand and supply.
The inflexible and flexible energy is priced differently, which is explained next in Section 4.3.

Bidding Strategy
The two grid prices, G b and G s , play an important role in the trading strategy. There is no reason for an agent to exchange energy within the community market at prices worse than the grid prices. Therefore, the maximum possible market price is G b and the minimum possible price is G s . As consumers are inflexible (i.e., they need to satisfy demand), we assume they are always prepared to pay G b to buy energy, and so their bids are always G b . Similarly, suppliers and prosumers without storage with any surplus supply are always prepared to sell at G s , their asks are always at G s (as otherwise the energy is wasted). Therefore, The bid for inflexible demand D a T is G b and the ask for the inflexible supply S a T is G s . However, when prosumers have storage, they can offer different prices for both demand and supply. They can buy energy when supply is ample and sell it back when demand is higher. This is an essential element of the proposed market to create a profit opportunity for prosumers with storage. Thus, flexible agents can choose prices for SX T or DX T within the limits of the grid prices. No agent is allowed to sell energy at a lower price than G s or buy at a higher price that than G b .
Due to the complexity of the market model, a simple bidding strategy for flexible agents is implemented. The strategy is based on multiple parameters. The first one is the predicted price for the next market round denoted as P T+1 . The prediction is performed by averaging the previously announced prices for the same round from past days. Thus, given the set of announced market prices H T i i ∈ [T − 24, T − 48, . . . , 0] and a size of the set M T for a market round T, Equation (23) represents the predicted price for the next round P T+1 . If no market announcements exist for the next round, the predicted price is chosen halfway between the grid prices. To avoid having all agents adopt the same price prediction, a random noise , drawn from a standard uniform distribution with a minimum of −1 and a maximum of 1, is added to the predicted price. In summary, agents use the previously announced market prices to predict the price for the next round. is a random noise to introduce variance in the bidding strategy as all agents adopt the same strategy. The range (−1,1) is chosen because the price range between the gird prices is 5 in our simulations, and 20% of that range is 1, which is a reasonable variance.
The rationale behind predicting the price for the next market round is that agents can assume that if they do not sell their energy at the current round, they can sell it in the next round at P T+1 . Thus, P T+1 is the minimum asking price for the current round. The same applies to the demand, but instead of selling, agents assume they can buy it in the next round at P T+1 . Therefore, P T+1 is the maximum bidding price for the current round.
Another vital parameter in the bidding method is the gap between the selling and buying prices that flexible agents adopt. This gap is denoted as ∆. Agents adopt an increasing function for their flexible supply quantity SX T . They start at a price of P T+1 + ∆ 2 and increase it by an increment price z for each additional unit u that can be offered up to the maximum price of G b − y. When the maximum price is reached, all the remaining quantity of SX T is offered at this maximum price even if it exceeds u. In the case of flexible demand quantity DX T , the price function is a decreasing function where agents start with the P T+1 − ∆ 2 and decrease the price by z for each additional unit u demanded down to the minimum price of G s + y. Similarly, any remaining DX T is offered at the minimum price. Algorithm 5 shows the function used by agents to price their flexible energy using the mentioned parameters. Figure 4 provides an example quantity pricing for an agent with 5 kWh of DX T and 5 kWh of SX T . With this methodology, flexible agents participate in the market by providing their offers. The next section will present the agent-based market simulations.
Version February 11, 2020 submitted to Energies  . Asks and bids for 5 kWh of flexible energy in both supply and demand. T predicted price P T+1 at this instance is halfway between G b and G s . The price gap ∆ is the quantity u is set to 1 kWh, the price changing rate z is set to 0.5 pence and the price the grid prices y is set to 0.25 pence. This agent submitted 5 bids and 5 asks for each wi 5. Simulations 420 Figure 4. Asks and bids for 5 kWh of flexible energy in both supply and demand. The next round predicted price P T+1 at this instance is halfway between G b and G s . The price gap ∆ is set to 1 pence, the quantity u is set to 1 kWh, the price changing rate z is set to 0.5 pence and the price distance from the grid prices y is set to 0.25 pence. This agent submitted 5 bids and 5 asks for each with 1 kWh.

Algorithm 5 Quantity Pricing.
Input the estimated price for the next round P T+1 , the gap between the selling and buying prices ∆, price changing unit z quantity changing unit u, price of buying energy form the grid G b ,price of selling energy to the grid G s , flexible demand quantity DX T , flexible supply quantity SX T Output lists of bids and asks bids, asks procedure QUANTITY PRICING(P T+1 , ∆, z, u, y, G b , G s , DX T , SX T ) Require: append quantity and price to bids list append quantity and price to asks list SX T ← 0 else asks ← bids || (min(SX T , u), maxAsk − priceSpace) SX T ← max(0, SX T − u) priceSpace ← max(0, priceSpace − z) return bids, asks

Simulations
To empirically validate the market mechanisms and agents proposed in earlier sections, we performed multiple simulations using data from real household appliances, random occupant activities and real energy prices. In more detail, the rest of this section is structured as follows. Section 5.1 gives an overview of the data used for energy profiles. Section 5.2 explains the measures evaluated in the simulations. Finally, Section 5.3 states the assumptions in the simulations and the parameters varied. We then present and discuss the results obtained in Section 6.

Data
The data used in the simulations are generated using the stochastic energy model developed by the Centre of Renewable Energy Systems Technology [37] to create realistic energy profiles. The model simulates households' energy consumption using a range of electrical appliances and randomised human activities. Also, the model includes dwellings with Photovoltaic (PV) panels and models the energy generation by specifying the geographical coordinates in the UK, and using historical irradiation, temperature and cloud clearness data. The model is used to generate energy profiles for 100 agents with 50 consumers and 50 prosumers for 29 days in June, including weekends, using the geographical coordinates of Southampton. Five different solar array profiles are used with a maximum output of 2, 3, 3.5, 4 and 6 kW for 10 prosumers each to introduce variations in renewable supply among prosumers. The grid prices used in the simulations are from The Office of Gas and Electricity Markets (OFGEM), which is a UK government regulatory entity for energy markets. The selling to grid price G s is based on the latest Feed-In Tariff rates from OFGEM for 2019 [38]. The price used is 3.41 pence/kWh, which is the standard solar photovoltaic receiving the middle rate 0-10 kW as of Q1 2019. The buying from grid price G b is based on the annual average tariff prices for six large suppliers in the UK provided by OFGEM as of 28 June 2019 [39]: 8.3 pence/kWh.

Measures
Two measures of financial benefit are defined, one for consumers and one for suppliers. The saved demand cost attained from participating in the market compared to not being in the market, and buying the same energy from the grid at round T is referred to as demand savings, denoted as DS T , and represented by (24). The extra supply income received from participating in the market compared to not being in the market, and selling the same energy to the grid at round T is referred to as supply profit, denoted as SP T , and represented by (25). When DS T or SP T is negative indicates demand cost or supply income at this round is worse compared to the existence of no market.
The community net bill, B C T , defined in Section 3.7 is another measure considered. If B C T is positive, a deficit exists in the budget and cost needs to be paid by the community as a whole. If B C T is negative, a surplus exists in the budget and profit needs to be shared. The mechanism of distributing the community budget deficit or surplus is beyond the scope of this research, so only the net budget bill is reported.
In some cases, the fees from demand and supply shortage could result in agent bills that are worse than not being in the market. For example, let say an agent is allocated 5 kWh at the price of 6 pence/kWh, the agent then only uses 1 kWh. It is therefore charged a shortage fee of 4 · DF T = 4(6 − 3.41), which is 10.36. It pays this fee plus the 6 pence he pays for the 1 kWh which totals to 16.36 pence. On the other hand, importing 1 kWh from the grid with no market costs 8.3 pence. Therefore, this agent does not make any savings, and in fact, pays more for his energy compared to not participating in the market. Therefore, we introduce a notion of capped bills where the agent never pays more than the cost to import its true demand without participating in the market. Similarly, the agent never receives less than the income to export its true supply without participating in the market. The concept of the capped bill is adopted to avoid resulting in higher energy costs or profit compared to not participating in the CEM. In other words, agents are always at least as well off participating and never worse off. To this end, we compare what the cost would have been using the (fixed) grid prices. Note that we consider the caps ex-post, i.e., based on the actual consumption and/or production and so there is no uncertainty to consider here.
Equation (26) defines the capped bill B a T for agent a at round T. Moreover, the capped community net bill B C T is defined using B a T in (26). Finally, the capped demand savings and supply profit DS a T and SP a T are defined in (28) and (29). The capped measures are important to note here as they will be discussed in more details under the imperfect predictions simulations Section 6.2.
Finally, the aggregate result for a day K is the sum of all results for rounds T where T ∈ K. Equations (30)-(35) define the aggregate uncapped and capped measures. The average daily aggregate results and the aggregate results for the entire simulations period will be compared in each setting presented in Section 6.

Assumptions and Parameters
The simulations are performed over a 29 days period, which is referred to as M. The proposed market is simulated using two main settings, perfect predictions and imperfect predictions. Each setting is executed for a market without storage and varying the prosumer ratio in the community from 0% to 100%. Increasing the prosumer ratio also increases the renewable capacity of the community as prosumers have different solar profiles. Then, each setting is run for a market with 40% prosumers with storage varying the ratio of prosumers with storage from 0% to 100% with three different storage profiles. These profiles are capacities of 3, 5 and 10 kWh and charge/discharge powers of 3, 5 and 5 kW. Some parameters are fixed throughout the performed simulations (see Table 1).The fixed values provide reasonable freedom for agents to submit multiple offers given the price space between the chosen grid prices G b and G s is about 5 pence.

Results and Discussion
This section presents the results for the market simulations using the parameters discussed in Section 5.3 and the measures defined in Section 5.2. Section 6.1 presents the setting with prefect predictions, and Section 6.2 presents the setting with imperfect predictions.

Perfect Predictions
In the perfect predictions setting, agents are assumed to have absolute certainty or perfect foresight of their future supply and demand. This certainty is achieved by setting the look-back amount k to zero. Section 6.1.1 presents the simulations without storage, and Section 6.1.2 presents the simulations with storage.

Perfect Predictions Without Storage
In each simulation, the average daily community net bill, B C K , where K ∈ M, is calculated for different prosumer ratios. Also, the averages daily SP K and DS K are calculated. A simulation with 20% prosumer ratio means a community with exactly 5 prosumers and 45 consumers. The simulations show that with perfect predictions, B C K is in a deficit state. This deficit exists because no energy is traded in the secondary market to create profit that compensates for the supply-demand overlap deficit. Figure 5 shows the daily average B C K with increasing prosumer ratio. With a prosumer ratio of zero, no deficit exists as there is no market. With a prosumer ratio of 20%, the deficit is insignificant because the energy traded is small as only 10 prosumers with 2 kW solar array can supply energy, and the demand is far greater. However, as energy traded becomes large enough, the deficit becomes significant at around £0.65 per day on average. Average Daily Community Net Bill Figure 5. Daily average B C K for the simulations with perfect predictions without storage. A deficit exists a result of the imperfect overlap between supply and demand. The deficit is noticeable with a prosumer ratio of 40% and higher as more energy is traded within the market. The error bars represent 95% confidence intervals. Figure 6 shows a comparison between the average daily SP K and DS K . Both are equal because the energy price in this setting is always at the mid-price between the grid prices. The mid-price is a result of all agents being inflexible and, therefore, not able to bid or ask different prices. Table 2 compares the results for this entire period M for each prosumer ratio. This setting with perfect predictions without storage indicates that the prosumer ratios between 40% and 60% produces the most benefit to the community, which is a similar result to other reviewed literate [10].   When flexible agents are incorporated, the number of prosumers is fixed, and the storage ratio among the prosumers is varied. The prosumer ratio in this setting is selected at 40%, which means 20 agents are prosumers with an aggregate max PV power of 50 kW. Similar to the simulations in the previous setting without storage, the simulations with storage show that with perfect predictions, B C K is in a deficit state. This is expected as no energy is traded in the secondary market to compensate for the deficit. However, the deficit is reduced with the introduction of storage. Compared to the market with 40% prosumer ratio and without storage, where the average daily B C K is around £0.75 per day, introducing 20% storage ratio among the prosumers with 3 kWh storage devices reduces the average daily B C K to around £0.6 per day. Furthermore, increasing the storage ratio or the capacity also reduces the average daily B C K as seen in Figure 7. This reduction is due to the flexible agents' ability to preserve energy and discharge it when it is needed by the market, rather than having the randomised supply control when energy is exported to the market.
The distribution of financial benefits in this setting shows that the average daily SP K is more significant than DS K . This shift is because flexible agents trade their energy at high prices to maximise their profit as seen in Figure 8. Moreover, Figure 8a shows that as more prosumers become flexible, DS K is reduced because less inflexible supply is offered at the low price of G s . Also, increasing the storage capacity has the same effect of lowering the inflexible energy. Figure 8b shows that having 10 kWh storage devices with all prosumers results in the most substantial average daily SP K and the least DS K at the same time.   . Average daily DS K and SP K for the setting with perfect predictions with storage. The average SP K is more than DS K because flexible agents raise the trading price to gain more profit. That is why as storage ratio increases, SP K increases as well, because prosumers have more flexible energy to offer at higher prices, which also decreases DS K . The error bars represent 95% confidence intervals. (a) Average daily DS K . (b) Average daily SP K . Table 3 compares the results for this setting for the entire period M. It shows that introducing storage increases the sum of DS M and SP M , with SP M as the significant portion. Also, as the ratio of prosumers with storage increases, the share of SP M in the sum increases as well. In the same setting with 40% prosumers but without storage, the sum of both DS M and SP M is~£203 with 50% for SP M . Equipping 20% of the prosumers with 3 kWh storage devices results in increasing the sum to £236, which is a 16% increase with SP M , making 60% of the sum. The market with 40% of the prosumers having 10 kWh capacity storage devices, has the most significant sum of £302, which is a 48% increase from the setting without storage, with SP M making 77% of the sum. This setting with storage shows that suppliers are benefiting more compared to without storage, which is anticipated, given their flexible ability and bidding strategy. To provide a further comparison, Table 3 also shows the aggregate demand savings from only using storage with no market. It refers to the savings from the energy that is stored then discharged to fulfil the agents' demand. If no storage existed, this energy would have been exported to the grid and imported when needed. Therefore, the savings are the difference between G s and G b for every kWh. The storage only savings show that participating in the market is more profitable for prosumers with storage.

Imperfect Predictions
In the setting with imperfect predictions, uncertainty in demand and supply is introduced. A look-back time k of 60 minutes is chosen, which means agents predict their next round's demand and supply as the amounts from the past hour. The capped and uncapped measures explained in Section 5.2 are compared for each simulation in this section, for the daily averages and the entire period. Section 6.2.1 presents the settings without storage, and Section 6.2.2 presents the setting with storage.

Imperfect Predictions Without Storage
The results for this setting show the impact of the secondary market, which is evident compared to the setting with perfect predictions. The profit from the secondary market to the community overcomes any deficit and creates a surplus. However, when the bills are not capped, the shortage fees reduce DS M and SP M . Figure 9 shows a comparison between the average daily capped B C K and uncapped B C K where both are negative bills, which indicate surplus states. However, this setting shows that the average daily B C K is larger than B C K because the uncapped shortage fees result in higher demand costs and less supply income. Average Daily Community Net Bill Capped Uncapped Figure 9. Average daily B C K and B C K for the setting with imperfect predictions without storage. Both average daily B C K and B C K are negative, which indicate surplus states. However, B C K is more with all prosumer ratios due to the uncapped approach. The error bars represent 95% confidence intervals. Figure 10 shows a comparison between the average daily DS K and SP K , and the average daily DS K and SP K . Increasing the prosumer ratio reduces the average daily DS K until it becomes negative with 100% prosumers as seen in Figure 10a. This behaviour is a sign that demand in a market with 100% prosumers under the uncapped approach, is slightly more expensive compared to no market. This is because demand shortage fees become more significant, as increasing the prosumer ratio means fewer consumers, which reduces the overall market demand. Another reason is the higher uncertainty in demand predictions compared to supply predictions when using the past hour approach. That is why the uncapped approach also reduces SP K , but not the same levels. Nevertheless, the average daily DS K and SP K in Figure 10b, indicate that the capped bill approach limits the shortage fees to a certain level, and results in higher combined benefit. Table 4 compares the results for this setting for the entire period M. In both capped and uncapped approaches, B C M and B C M are negative, which indicates surplus states. However, the gain in the uncapped approach is a result of reducing DS M and SP M . This setting shows that the surplus from the secondary market is enough to overcome the deficit and adopted the capped bill approach.  Figure 10. Comparison between the average daily DS K and SP K , and the average daily DS K and SP K for the setting with imperfect predictions without storage. The error bars represent 95% confidence intervals. (a) Average daily DS K and SP K . With 100% prosumer ratio, DS K is negative because of the uncapped bills approach. (b) Average daily DS K and SP K . The capped bills approach produces higher DS K and SP K compared to the uncapped DS K and SP K . Table 3. The results for M in £ for the setting with perfect predictions with storage. At the end of the period, B C M is in a deficit state in all storage ratio variations. However, increasing the storage ratio decreases the deficit. Also, increasing the storage ratio increases SP M as more prosumers become flexible, but, it also reduces DS M . By aggregating DS M and SP M , the configuration of 40% of prosumers having 10 kWh capacity storage devices, results in the most substantial combined benefit with 77% for SP M .  By introducing flexible agents to the imperfect predictions settings, the results show the advantages of the proposed market to prosumers with storage and the effect of the secondary market. Note that flexible agents in this setting include the present state of charge in their predictions alongside the net profile from the past hour. Figure 11 shows that increasing the storage ratio reduces the surplus as more flexible agents take advantage of the secondary market, and less inflexible energy is traded there. The average daily B C K and B C K are both in surplus states in all varying storage capacities and ratios. Figure 11b shows that the capped bill approach results in less surplus while still overcoming the deficit reaching close to complete balance of zero with 100% storage ratio.  Figure 11. Comparison between the average daily B C K and B C K for the setting with imperfect predictions with storage. The error bars represent 95% confidence intervals. (a) Average daily B C K . Under the uncapped approach, increasing the storage capacity or the ratio of prosumers with storage decreases the average daily surplus, but it is still significant with around £2 per day when all prosumers have storage. (b) Average daily B C K . Under the capped approach, increasing the storage capacity or the ratio of prosumers with storage decreases the average daily surplus, but it reaches close to zero with 100% prosumers with storage. However, B C K does not enter a deficit state.

Ratio of
As more prosumers become flexible, the trading price becomes higher, and the demand shortage fees become higher as well because of the gap between the clearing price and G s widens. On the other hand, the supply shortage fees become smaller as the gap between the clearing price and G b shrinks. This effect is shown in Figure 12a, where the average daily DS K decreases as the storage ratio increases. Also, increasing the storage ratio decreases the market demand as flexible agents become more able to fulfil themselves, which reduces DS K . The uncapped approach results in negative DS K with some storage ratios and capacities, while the capped approach maintains a positive DS K in all combinations as seen in Figure 12b. This setting shows that the average daily SP K and SP K are larger with the addition of storage compared to the absence of storage. Also, increasing the capacity increases the average daily profit as well as increasing the flexible agents' ability to offer supply in the market. Figure 13 shows both average daily SP K and SP K . The differences between them are insignificant because of high trading prices, low supply shortage fees and less uncertainty as flexible agents predictions include the current state of charge. Table 5 compares the results for this setting for M. The surplus from the secondary market overcomes the deficit in all variations. The uncapped bills result in extra costs in demand because of the high shortage fees, which causes the demand to be more expensive. These cases are highlighted in red. Overall, the surplus from the secondary market is enough to support the capped bills approach, which results in a higher DS M and SP M . This setting also shows the ratio of SP M in the sum of benefits SP M + DS M increases from 54% without storage to a range between 66 and 96% with different storage ratios and capacities.  Figure 13. Comparison between average daily SP K and SP K . Increasing the storage ratio and capacity increase both profits. The reduction from the uncapped bill approach is still present. However, it is insignificant due to high supply profit and low supply shortage fees as more prosumers become flexible. The error bars represent 95% confidence intervals. (a) Average daily SP K . (b) Average daily SP K .

Conclusions
This paper develops and evaluates a new community energy market. The proposed market model is a repeated discrete-time two-sided auction. The market selects prices and clears energy using market equilibrium methodology. The participating agents predict their energy offers using past consumption and production values. Only agents with storage can submit offers different from the grid prices. Agents that do not have storage always use the grid prices because they are inflexible. Agents with storage adopt a simple bidding strategy with an increasing price function for supply and a decreasing price function for demand. The bidding strategy maximises their profit under constrains on price increments and quantities. The market cleared energy is allocated using the envy-free division protocol. The model uses a minute-by-minute energy balancing approach that fulfils energy within the allocated amounts or a secondary exchange opportunity where agents with storage can capitalise, or lastly by the grid. The proposed billing method charges the grid prices for any excess energy and enforces the auction allocations using shortage fees to discourage agents from exaggerating their offers. The billing method also rewards agents with storage for any energy exchanged within the secondary market.
Considering the minute-by-minute energy balancing, this research shows that the imperfect overlap between supply and demand creates a deficit in the community net bill. This deficit is reduced through the proposed secondary market, capitalising on uncertainty in future energy predictions. The proposed billing method also reduces the deficit by collecting portions of the shortage fees from both demand and supply at the same time when less energy is exchanged with the grid. The disadvantage of this method is that it can result in overpriced demand when uncapped. However, the market evaluations show that capping the market bills with the bills if no market exists results in more financial benefits for both consumers and suppliers, while still maintaining enough surplus to overcome the deficit. In other words, the capped bill approach penalises the benefits from the market and does not create any financial disadvantages for the market participants. Therefore, the capped bills method is recommended with the proposed market. The model assumes accurate reporting of flexible and inflexible energy by agents and access to the storage devices, which may not always be feasible. Nevertheless, the results present a positive step towards promoting community energy markets.
Evaluation of the proposed market is performed using agent-based simulations for a community with 50 agents over 29 days. The market simulated is an-hour-ahead trading market. Simulated energy profiles based on CERT model [37] are used with average grid prices from OFGEM [38,39]. Several market settings are evaluated by varying the prosumer ratio in the community without storage, and then fixing this ratio and varying the ratio of storage among the prosumers. Furthermore, all the variations for the simulations with storage or without storage are performed for settings with perfect energy predictions and imperfect energy predictions. The results of the setting with perfect energy predictions without storage show that consumers and suppliers share the benefits equally. Additionally, the number of prosumers in the community influences the benefits. The highest combined benefit for consumers and suppliers achieved in the market simulations are for communities with prosumer ratios between 40 and 60%, which results in average aggregate daily demand savings and supply profit of £3.5 each. The same prosumer ratios also result in the highest average daily community net bill deficit of~£0.75. However, the results of the setting with imperfect energy predictions also without storage show the effect of the secondary market and the billing method to overcome the deficit and create a surplus. Still, prosumer ratios between 40 and 60% result in the highest average daily community net bill surplus of £2 when bills are capped. The average aggregate daily demand savings drops to £1.9, and the average aggregate daily supply profit drops to £2.5 due to fees caused by uncertainties in supply and demand.
The results of introducing storage to the proposed market model are interesting. In the setting with perfect energy predictions with storage, flexible agents reduce the community net deficit through minimising the inflexibility of their supply and demand. With a community with 40% prosumers, the average daily community net bill deficit drops from £0.75 to £0.6 with 20% of prosumers having 3 kWh storage devices and down to £0.2 with all prosumers having 10 kWh storage devices. Furthermore, the market simulations with storage show more shares of the financial benefits go toward suppliers, which is desirable, given their investments in renewable generation or storage technology. Also, using a community with 40% prosumers with perfect predictions, the average aggregate daily supply profit increases from to £3.5 without storage, to £8.5 when all prosumers have 10 kWh storage devices. On the other hand, the average aggregate daily demand savings drops from £3.5 without storage, to £0.5 with all prosumers having 10 kWh storage devices. The setting with perfect predictions with storage show an increase in the total community benefits up to 48% compared to the same setting without storage. Moreover, the ratio of supply in the total community benefits increases from 50% to a range between 60 and 94% depending on the storage ratio and capacity.
In the setting with imperfect energy predictions with storage, the proposed secondary market and bill methods still overcome the deficit and create a surplus. However, flexible agents reduce the community net surplus because of lower uncertainty and benefits gained from the secondary market. Storage is a primary reason for reducing the uncertainty of energy predictions as the proposed model uses the current state of charge for the next round's offers. The results show that storage reduces the average daily community net bill surplus from £2 without storage, to £0.4 when all prosumers have storage. Furthermore, the setting with imperfect predictions also shows that storage shifts the financial benefits towards suppliers. The average aggregate daily supply profit increases from £2.3 without storage, to £8 when all prosumers have 10 kWh storage devices. In contrast, the average aggregate daily demand savings decreases from £1.9 without storage, to £0.4 when all prosumers have 10 kWh storage devices. Moreover, the ratio of supply in the total community benefits increases from 54% to a range between 66 and 96% depending on the storage ratio and capacity. The proposed market model provides opportunities for flexible suppliers to benefit through the auction mechanism and the secondary market. However, the results show that having all suppliers as flexible with large storage capacities tend to make the demand savings insignificant in comparison. Therefore, a combination of flexible and inflexible suppliers is suggested to maintain motivation for consumers. Variations in the fixed parameters could modify the results obtained, but it not believed to change the overall trends.
Additional simulations for the scenarios with storage were conducted with changed prosumer ratios, and similar results were achieved.
Finally, the proposed market model presents a design of a community energy market to incentivise supply and energy storage investments and account for uncertainty in supply and demand. In general, a mix of prosumers with storage, prosumers and consumers creates an ideal setting for the proposed market model where the benefits are shared in that order. Uncertainty in supply and demand is expected, but not at extreme levels where the market predictions become irrelevant, and most energy is exchanged in the secondary market. Although the net bill deficit/surplus is reduced by adding storage at the prosumers' level, the net bill is not balanced completely. Further studies are therefore necessary to determine fair mechanisms of distributing the community net bill in both deficit and surplus states. Due to the complexity of the proposed market model, this research kept the agent strategy simple. However, future work will explore more sophisticated strategic behaviour and cooperative game-theoretical approaches. Moreover, the complexity of the model will be improved through incorporating electric vehicles, which not only influence the energy needs, but can also act as storage devices and means for transporting energy.

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