New Market Model with Social and Commercial Tiers for Improved Prosumer Trading in Microgrids

: In the deregulated electricity markets, trading prices are determined by the o ﬀ er-demand mechanism, and retail consumers can negotiate tari ﬀ s with their supplier of choice. For classic wholesale suppliers, the tari ﬀ s are determined by the prices of transactions performed on the wholesale market. In parallel with becoming eligible for participating in the market, the consumers use increasingly local generation sources based mostly on renewable electricity generation equipment such as Photovoltaic (PV) panels, and become prosumers. They want to be able to sell back to the market the generation surplus, in order to obtain the maximum beneﬁts from their initial investment. This paper proposes a two-tier local market model oriented for prosumers and consumers connected in microgrids, based on the blockchain technologies and other technologies and concepts such as smart grids, crowdsourcing and energy poverty. Its goals are to improve the possibilities of local prosumers to sell electricity to local consumers and to increase their proﬁtability, compared to the trading model often used in developing markets, of selling the surplus back to the grid via aggregators. The research aims to contribute to the sustainable development of the electricity sector using new and renewable sources of energy, state-of the art technologies and smart contracts, leading to prosumer proliferation and electricity cost reduction for consumers. two-tier prosumer electricity cost mitigating energy for remaining prosumer surplus not bilateral contracts with certain prosumers, allowing occasional access market in exchange for a tari ﬀ , and reducing the e ﬀ ect of erroneous consumer buy o ﬀ ers caused by inaccurate forecasts or temporary unusual consumption patterns. The primary market model o ﬀ ers two trading alternatives: ‘ﬁrst-come-ﬁrst-served’ (FCFS), and merit-order (MO). The secondary market proposes two tiers with three trading methodologies, which can be optionally used, in number and order, according to the speciﬁc needs of particular microgrids: energy poverty mitigation, tari ﬀ access and invite access. The proposed alternatives are tested in a case study, on an existing low voltage (LV) electricity distribution network from which has microgrid characteristics, in order to assess the e ﬀ ects of the chosen trading methods on the proﬁts achieved by prosumers and consumers. The proposed market model provides ﬂexible tools for incentivizing the sustainable development of local communities based on environment protection and economic and social inequality mitigation through the use of modern technology tools, by encouraging local trading of electricity generated from renewable, clean primary sources. case study local trading


Introduction
The European Commission's strategic framework envisages an improved and modernized European energy market, aimed at creating secure, sustainable, accessible and decentralized energy networks in response to the global challenge of greenhouse gas emissions [1]. In the context of the next generation of digital energy networks, and in the presence of multiple decentralized microgrids, managing the energy generation from various and complementary sources will result in gaining more flexibility in meeting demand and lowering costs for the community. The adoption of a decentralized electricity distribution network, in which ordinary consumers can also be energy producers, named 'prosumers', and can sell their surplus generation to the network, thus getting involved in market transactions inside a community represents an alternative to current traditional networks. It is expected that an increasing number of end-users will want to become active in the electricity sector, which will lead to a large number of transactions. A possible tool for enabling the creation of such microgrid-level markets is the blockchain technology which could provide secure and reliable means of communication and data management between the end-users [2].
Blockchain technology was created as a solution to the problem of mistrust and data security. The first steps in the development of the technology were taken in 1991, when Stuart Haber and

•
Climate change. The need to integrate in existing electricity distribution systems renewable energy sources (RES) has led to the development of technologies such as PV panels and wind turbines, whose costs are constantly decreasing. The consumers who choose to install such generation sources become prosumers, which presents a challenge for the current structure of electricity networks. They can create technical difficulties for the Distribution Network Operators (DNOs) in ensuring the energy balance. However, electricity generation at the household level (classically with PV panels on the roof) is a great opportunity for the development of blockchain technology-based architectures, because it capitalizes on the distributed nature of electricity generation with unprecedented efficiency.

•
The development of technologies that allow the transition to active distribution networks. The technological solutions refer to the communications and networking components, inverters, bidirectional smart metering systems, energy storage solutions. This evolution allows greater control at network level. Electricity becomes a controllable, storable and easily quantifiable product, suitable for trading through smart contracts.

•
The creation of energy communities managed by local energy production cooperatives formed by community members. The microgrids which integrate the blockchain technology can represent a solution for connecting the poorest consumers to cleaner and cheaper energy, but also for energy savings and more responsible and accessible consumption. In some EU member states, European Federation of Renewable Energy Cooperatives (REScoop) have explicitly set social goals, such as

Literature Review
Recent studies have considered combining the operation of small-scale renewable energy sources (SSRES) in distribution networks and deregulated electricity markets. The range of these studies is covering unit commitment [19] and economic dispatch problems [20], in addition to scheduling of SSRES [21], and the uncertainty of renewable generation [22]. The main trends and approaches currently described in the literature are briefly summarized in the following paragraphs.
As it was presented in the introduction section, in Europe there are currently over 3400 green energy cooperatives (REScoop). In accordance with [23][24][25][26], the REScoop notion is defined in EU directives as "local energy communities", according to data from the Federation of Green Energy Cooperatives in Europe. More than one million European citizens are participating in REScoops to invest together in the transition from fossil fuels to clean primary energy resources and energy efficiency. In Romania, starting in 2020, the first established REScoop proposes that future members who generate energy (prosumers) will be able to sell the surplus to other members, rather than to an aggregator, following the concept of 'prosumer-friendly' [27].
In another perspective, paper [28] considers a P2P electricity trading method using a private Ethereum blockchain ledger where all bids are encrypted for anonymity and peer matching is done by a functional encryption-based contract.
Regarding the energy crowdsourcing in prosumer-enabled electrical networks, a small number of published papers is available in the literature [16,29]. The existing studies consider a two-stage algorithm for minimizing the cost of generation and the energy losses by prior rescheduling of user loads and SSRES.
In other work, a particular local energy market model was considered in [30], which integrates different P2P energy trading platforms based on unidirectional market clearing price (MCP) for a microgrid. Moreover, the settlement considers an MCP or P2P mechanism.
The future active distribution network (ADN) is a P2P community based on active energy agent (AEA) users [31]. The maximization of social welfare in local prosumer generation trading with an auction-based mechanism is used in [32]. The same first author considers that in a microgrid the energy flows in a transactive way and the transactions are based on bilateral contracts between peers [33]. Another concept of prosumer surplus trading based on the transactive energy concept is proposed in the literature [34][35][36][37]. Paper [34] uses a Stackelberg game-based method for solving the transactive energy problem, in which the DNO and the SSRES aggregators are participating simultaneously in the Local Electricity Market (LEM) and Wholesale Electricity Market (WEM). A comprehensive cost-benefit model for prosumer load sharing was proposed in [35], using game theory and considering non-cooperative game models of the microgrids for prosumers energy surplus. In the same context, a particular social welfare-based concept on transactive energy or demand response (DR) is applied in [36,37] using negotiated prices.
Another way to trade surplus are DR programs, whereby the LEM operators play a vital role in managing the exchange of data, to ensure the notification flow between balancing authorities, service companies and end-users. First, the microgrid operator assesses the electricity consumption patterns based on the structure of variable electricity tariffs and prices to establish trading plans. They also sign bilateral P2P contracts with end-users to take direct control of specific energy assets [38]. This information is aggregated to create commitment portfolios-load reduction schedules that are provided to network operators in exchange for compensation commensurate with the size of the capacity involved [39]. In the event of a system emergency or demand, the DSO shall request the aggregator to reduce or increase a portion of the contracted portfolio. For this reason, the aggregator receives additional compensation which can take the form of tariff reductions, incentive payments and invoice credits.
Using online platforms [40][41][42][43][44][45][46], the consumers can become prosumers who create and distribute their own information about the energy generation. Some authors proposed a demurrage mechanism (DM) and Home Energy Management (HEM) for prosumers' energy surplus in an LEM based on blockchain [41]. A particular P2P business model for 48 residential prosumers with PV panels installed in a Swedish village is proposed in [42]. This article identifies some new potential opportunities for optimizing the LEM and its variables for the best gain, taking into account that a significant influence is represented by the integration of energy demand, generation supply, and LEM rules. The aforementioned study can be used to provide information for regulatory bodies to create a fair, useful and cost-effective P2P electricity trading framework for prosumers. Another comprehensive platform for prosumers' digitalization was recommended in [43], and market simulations are developed in [44,45] for consumers integration in microgrids. In the same manner, a virtual platform was proposed in [46] for efficient management of multiple energy prosumers (MEP).
The presence of decentralized energy sources demands the analysis of the problem of continuity of energy supply to operators whose activities significantly depend on electricity. There are EU countries where power outages amount to about 20 min per year, but in other cases the average power outages range from 450 to 500 min [47]. Prosumers' microinstallations ensure the business continuity for producers in such countries and negotiated surplus trading increases social welfare [48]. Because the SSRES efficiency depends on atmospheric conditions and regional climate, even minor temporary changes in weather conditions can cause significant variability in power generation at different time and space scales. Methodologies based on the remote sensing of atmospheric conditions are the primary source of information for the development of numerical forecasting models that support the planning and operation of power systems in the presence of intermittent energy sources [49]. For local trading of such electricity surplus, the LEM operators consider the blockchain concept [11,12,16,28,29,40,41,48] or direct bilateral contracts [50,51]. These market models aim to provide secure and affordable energy supply for the end user, which is essential for the functioning of an economy in which energy poverty is reduced and the needs of vulnerable social groups are taken into account [52][53][54]. Social welfare is obtained by the authors in [53], where the smart P2P contracts are considered as a distributed optimization problem, solved with a virtual aggregator based on the Alternating Direction Method of Multipliers (ADMM). All the LEM actions can be completed by the peers who do not necessarily trust each other through an agreement algorithm which defines the speed of the transactions. One of the most used algorithms is the Proof-of-Work (PoW) [55]. Nonetheless, previous articles about energy sustainability have paid limited attention to prosumer engagement, management and administration. For example, according to [56,57] each of the providers can have a proper trading platform with specific architecture for sustainable planning of the local microgrid or region.
From other perspectives, the prosumer surplus trading process based on the specific transactive energy microgrids are examined by the researchers in [58][59][60]. The prosumers' aggregation to one group with the same interest based on virtual microgrids is analyzed by the authors in [61] for bill cost reduction as a particular energy poverty mitigation or social welfare. The aforementioned problem can be solved in smart buildings by using ADMM for energy sharing between the players, as is shown in [62,63].
In [64] remarkable directions for cost-effective use of digital cryptocurrencies in smart grid dynamic management are thoroughly explained to cover the challenging viewpoints of blockchain technology. The LEM is favorable for prosumers because the participation of the before-mentioned players is concrete in the purchase of energy surplus, but the revenues from the surplus traded are proportional between sellers [65]. Common consumers do not produce electricity and are only active in the purchasing process [66]. The load flexibility can change the trading offers. Other perspectives consider peak loads in the prosumer's vicinity with smart P2P subscribed capacity prices in [67], or the crowdsourcing concept for surplus energy planning or sharing, as is used in [68], or considering the indispensable local energy storage systems [69].
The main concepts taken from the literature and discussed above are compared with the market model proposed in the paper, in Table 1. In addition, the last column considers the type of settlement used in the market.
The objective of the local market is to enable an overlay social network of smart devices that facilitates the communication and trading process between players from LEM, prosumers, consumers and microgrid. They should share a common goal, such as optimal energy management, taking into account that the solution with local energy storage systems (as is battery banks) is too expensive [70,71], and without technical possibility for energy poverty mitigation.

Materials and Methods
In LV electricity distribution networks or local microgrids, there is an increasingly larger number of residential consumers who are opting to install local generation resources to gain independence from the grid. The predominant choice is the use of PV panels systems that are easier to install at household residences and provide energy by converting the solar irradiation into electricity. This trend is incentivized by the subsidies offered by governments worldwide. As the number of individual houses adopting this technology increases, new opportunities arise regarding the trading models used for selling the excess generation. Residences become prosumers, entities capable of consuming, producing and selling electricity. The prosumers will use their own generated electricity mainly to cover their individual consumption and when the generation exceeds this amount, they will sell the surplus to the grid. The simplest method of surplus trading is to sell the entire available quantity back to the supplier, though an aggregator entity, at a regulated price. However, this is the least profitable approach, as the regulated prices are usually low [72], and the benefits can be seen only by the suppliers/network operators, and the prosumers. New trading methods for microgrids are currently envisioned in the literature, aiming to create local electricity markets that would provide benefits for all the players involved (aggregators, prosumers and consumers). A main requirement for implementing such initiatives is the conversion of the classic electricity distribution infrastructures into intelligent or smart grids, capable of real-time communication between the supply and consumer buses, and centralized operation management and data processing at microgrid level.
In line with these trends, previous research efforts by the authors, published in [40], proposed an algorithm for prosumer surplus transactions at the microgrid level, using P2P contracts and blockchain technology. The market mechanism considers trading priorities set at central level and based on consumer or prosumer prices, or custom priorities determined by the prosumer-consumer geographical distances and the 'first-come-first-served' (FCFS) principle. This paper extends the previous research considering an improved and extended market model, with two trading phases (primary and secondary). The basic flowchart of the proposed market model is depicted in Figure 1.
The primary market includes the blockchain approach from [40] and adds a supplementary trading method based on the merit order used in wholesale markets. These methods can be used as alternatives for trading.
A second market segment, with two tiers, is proposed to help the prosumers and consumers to better manage the sell and buy offers that can be affected by errors. Crowdsourcing and energy poverty mitigation are used for this purpose. The newly proposed algorithm provides market mechanisms designed to alleviate these problems.
The following general assumptions are made:


The prosumer and consumer selling and buying offers are managed by the local non-profit aggregator using two possible market mechanisms integrated in a blockchain trading system: o A primary market built on the blockchain technology, ensuring anonymity and security for the placed orders. o A secondary market with a two-tier trading mechanism for minimizing the imbalance between the offers placed in the blockchain system and the actual traded quantities.


The primary market can use two alternative price-setting methods based on blockchain technology: the 'first-come-first-served' (FCFS) method or the merit-order method used in traditional day-ahead markets.  The secondary market provides two optional trading tiers: o The energy poverty mitigation tier, aimed at low-income consumers who otherwise could not afford to participate in the market. o The commercial tier, with two options, aimed for expanding the market through crowdsourcing, with two types of consumers: those participating occasionally, in exchange for a fee, and consumers who do not participate directly with offers but are represented (invited) in the market by other consumers.


For the invite option of the commercial tier, any consumer Ci can acquire electricity from the second market layer only if has signed previously a P2P contract with a specific prosumer Pj.  The selling price of a prosumer or consumer can vary hourly, but in the paper is set constant for all trading intervals. This approach is modelling the practice used for traditional differentiated tariffs where the peak and night prices are outside the hours when PV panels can generate electricity, and the case where no storage capabilities are installed in the network. Electricity is The sell offers are the result of the surplus that the prosumers can generate but cannot use locally. The buy offers placed by the consumers in the local market are usually the result of forecasts made with variable precision. In the case of trading electricity obtained from PV panels, the forecasts must consider weather data obtained with technologies such as remote sensing and big data mining. Thus, the offers placed by the consumers in the market can be affected by errors which will result in mismatches between the needed and traded quantities.
In the Romanian market model, when the electricity acquired from the local market is less than the demand, the consumers would buy the rest at higher prices from the national grid, and the generators would be forced to sell any surplus to the aggregator, at a lower price.
On the other hand, if trading is performed in a local market, when the consumers forecasts are higher than the actual demand, the buyers would be forced to sell the excess quantities to the aggregator if sufficient and cheap storage facilities are not available.
The newly proposed algorithm provides market mechanisms designed to alleviate these problems.
The following general assumptions are made: • The prosumer and consumer selling and buying offers are managed by the local non-profit aggregator using two possible market mechanisms integrated in a blockchain trading system: A primary market built on the blockchain technology, ensuring anonymity and security for the placed orders. A secondary market with a two-tier trading mechanism for minimizing the imbalance between the offers placed in the blockchain system and the actual traded quantities.
• The primary market can use two alternative price-setting methods based on blockchain technology: the 'first-come-first-served' (FCFS) method or the merit-order method used in traditional day-ahead markets.

•
The secondary market provides two optional trading tiers: The energy poverty mitigation tier, aimed at low-income consumers who otherwise could not afford to participate in the market. The commercial tier, with two options, aimed for expanding the market through crowdsourcing, with two types of consumers: those participating occasionally, in exchange for a fee, and consumers who do not participate directly with offers but are represented (invited) in the market by other consumers.
• For the invite option of the commercial tier, any consumer Ci can acquire electricity from the second market layer only if has signed previously a P2P contract with a specific prosumer Pj.

•
The selling price of a prosumer or consumer can vary hourly, but in the paper is set constant for all trading intervals. This approach is modelling the practice used for traditional differentiated tariffs where the peak and night prices are outside the hours when PV panels can generate electricity, and the case where no storage capabilities are installed in the network. Electricity is sold on the market for the surplus intervals, and settlement is performed at the end of each trading interval.

•
If the local surplus exceeds the demand traded in the market, the surplus will be sold to the aggregator/market administrator, at regulated tariffs.

•
The secondary two-tier market components are optional, but the case study considers all the available options, in order to better demonstrate the advantages of the proposed trading algorithm.

Input Data for the Local Market
The input data required for trading consist of the quantities and prices associated with the consumption and local generation measured in the market. This information is provided in six matrices: for consumption quantity, offers and price offers, and G = G (h, j) ∈ R nh×NPM , GO = GO (h, j) ∈ R nh×NPM , PGO = PGO (h, j) ∈ R nh×NPM for generation quantity, offers and price offers, where NCM and NPM are the number of consumers and prosumers participating at hour h in the market. It is considered that generally NCM < NC and NPM < NP, NC and NP being the number of consumers and prosumers connected in the microgrid.
Trading in the primary market can occur at any hour h when there are consumer buying offers placed in the blockchain system (1), and there is generation surplus offered for selling (2).
Surplus occurs when the local generation of a prosumer exceeds its individual consumption (3) and the surplus is traded in the market (4).
The consumer quantity offers for the primary market use two types of representation: • as actual consumption value measured in [W], when the price is set according to the blockchain priority model, as in [40]; • as a multiple of 100 W for the price setting according to the day-ahead merit order model used in wholesale markets. The prosumers can choose to sell their surplus directly to the aggregator for a fixed regulated tariff, or in the primary local market. In the paper, it is considered that all the available surplus is traded through sell offers placed in the market blockchain system.
The secondary market is activated at any hour h when at least one of the following conditions is fulfilled: • The sum of the buy offers is lower than the aggregated offers placed by the prosumers, i.e., the prosumers need to sell the remaining surplus: • The buy offer of a consumer i is greater than the actual consumption because of the forecast error or representation model used in the market (multiple of 100 kW).
where TCO(h,i) is the quantity of electricity actually traded by the consumer i at hour h, which can be equal to or less than the offer placed on the market.

The Primary Market
This market segment is the main trading tool for the prosumers and consumers in the microgrid. As outlined previously, two alternatives are provided for determining the consumer and prosumer trading priority: 'first-come-first-served' and merit order. Both methods use the consumer (buy) and prosumer (sell) offers placed in a centralized secure and anonymous blockchain system established at the microgrid or market level. The blockchain system is preferred because it guarantees trading fairness, all players being unaware of the offers placed by others, thus minimizing the risk of market manipulation.
Another assumption used in the paper is that, by means of an automated system comprising smart metering, two-way communication and continuous monitoring at the microgrid level, the algorithm has immediate access to measured and forecasted data at consumer and prosumer buses. For examining the possible effects on trading, two consumer offer mechanisms are considered:

•
Consumers place on the market buy offers for the entire consumption at hour h, in order to minimize their electricity bill by attempting to buy the maximum quantity of electricity from the local market, at lower prices, rather than from the main grid, at higher prices.

•
Consumers place on the market buy offers determined by forecast techniques using big data analysis or remote sensing techniques.
The first type of offer is used in the FCFS trading method, where a generic consumer i places fixed-price-per-kWh and variable quantity offers, the trading order being determined by the time tag of the offer. The quantities for these offers are determined in the settlement phase, based on consumption measurements taken from the microgrid. The flowchart of this trading method is given in Figure 2. where TCO(h,i) is the quantity of electricity actually traded by the consumer i at hour h, which can be equal to or less than the offer placed on the market.

The Primary Market
This market segment is the main trading tool for the prosumers and consumers in the microgrid. As outlined previously, two alternatives are provided for determining the consumer and prosumer trading priority: 'first-come-first-served' and merit order. Both methods use the consumer (buy) and prosumer (sell) offers placed in a centralized secure and anonymous blockchain system established at the microgrid or market level. The blockchain system is preferred because it guarantees trading fairness, all players being unaware of the offers placed by others, thus minimizing the risk of market manipulation.
Another assumption used in the paper is that, by means of an automated system comprising smart metering, two-way communication and continuous monitoring at the microgrid level, the algorithm has immediate access to measured and forecasted data at consumer and prosumer buses. For examining the possible effects on trading, two consumer offer mechanisms are considered:


Consumers place on the market buy offers for the entire consumption at hour h, in order to minimize their electricity bill by attempting to buy the maximum quantity of electricity from the local market, at lower prices, rather than from the main grid, at higher prices.  Consumers place on the market buy offers determined by forecast techniques using big data analysis or remote sensing techniques.
The first type of offer is used in the FCFS trading method, where a generic consumer i places fixed-price-per-kWh and variable quantity offers, the trading order being determined by the time tag of the offer. The quantities for these offers are determined in the settlement phase, based on consumption measurements taken from the microgrid. The flowchart of this trading method is given in Figure 2. The second type of offer is used in the merit-order trading mechanism. The buy offer prices and quantities are placed in the blockchain system by the consumers before the trading interval. Quantities are given as multiples of 100 W and prices are given for each kWh. The flowchart of this trading method is given in Figure 3. The trading order and price are determined by the standard merit-order method, provided in Figure 4, where the trading price is determined as the market clearing price (MCP).
For both methods, the prosumer sell offers are given as the full available surplus S(i,h), in kWh. The second type of offer is used in the merit-order trading mechanism. The buy offer prices and quantities are placed in the blockchain system by the consumers before the trading interval. Quantities are given as multiples of 100 W and prices are given for each kWh. The flowchart of this trading method is given in Figure 3. The trading order and price are determined by the standard merit-order method, provided in Figure 4, where the trading price is determined as the market clearing price (MCP).
Quantities are given as multiples of 100 W and prices are given for each kWh. The flowchart of this trading method is given in Figure 3. The trading order and price are determined by the standard merit-order method, provided in Figure 4, where the trading price is determined as the market clearing price (MCP).
For both methods, the prosumer sell offers are given as the full available surplus S(i,h), in kWh. The maximum amount of traded electricity TC is determined by the minimum between the aggregated buy and sell offers:   The settlement price of a transaction t made by a prosumer j or consumer i is given by the amount of traded electricity C(h,t) and its price P(h,t), determined by each transaction, TP(h,t), which can be different from the sell or buy offer price submitted by the players in the market, PCO(h,i), PGO(h,j).
The basic flowchart of the primary market algorithm uses the steps presented in Figure 5. The trading mechanisms used in the primary market can lead to electricity quantities that cannot be traded locally. Three scenarios can lead to this situation:


At given hours, the total local generation available in the market (sell offers) exceed the total consumption (buy offers).  If the merit-order method is used, the buy offers are given as multiples of 100 W, while the sell offers are the S(h,i) quantities. This leads to S(h,i) fractions that cannot be fulfilled.  The consumers place in the market buy offers that exceed their real consumption, following forecast errors or significant accidental deviations from the daily demand pattern.
All these quantities can amount to an important value over longer time periods. If they are not traded in the local market, the prosumers would sell at minimum price to the aggregator, while the consumers would buy electricity at standard, high tariffs.
The algorithm proposed in the paper offers the possibility of extending the primary market with a two-tier secondary market, in order to make prosumer and consumer surplus quantities available for trading in the local network. For both methods, the prosumer sell offers are given as the full available surplus S(i,h), in kWh. The maximum amount of traded electricity TC is determined by the minimum between the aggregated buy and sell offers: The settlement price of a transaction t made by a prosumer j or consumer i is given by the amount of traded electricity C(h,t) and its price P(h,t), determined by each transaction, TP(h,t), which can be different from the sell or buy offer price submitted by the players in the market, PCO(h,i), PGO(h,j).
The basic flowchart of the primary market algorithm uses the steps presented in Figure 5.  The settlement price of a transaction t made by a prosumer j or consumer i is given by the amount of traded electricity C(h,t) and its price P(h,t), determined by each transaction, TP(h,t), which can be different from the sell or buy offer price submitted by the players in the market, PCO(h,i), PGO(h,j).
The basic flowchart of the primary market algorithm uses the steps presented in Figure 5. The trading mechanisms used in the primary market can lead to electricity quantities that cannot be traded locally. Three scenarios can lead to this situation:


At given hours, the total local generation available in the market (sell offers) exceed the total consumption (buy offers).  If the merit-order method is used, the buy offers are given as multiples of 100 W, while the sell offers are the S(h,i) quantities. This leads to S(h,i) fractions that cannot be fulfilled.  The consumers place in the market buy offers that exceed their real consumption, following The trading mechanisms used in the primary market can lead to electricity quantities that cannot be traded locally. Three scenarios can lead to this situation: • At given hours, the total local generation available in the market (sell offers) exceed the total consumption (buy offers).

•
If the merit-order method is used, the buy offers are given as multiples of 100 W, while the sell offers are the S(h,i) quantities. This leads to S(h,i) fractions that cannot be fulfilled.

•
The consumers place in the market buy offers that exceed their real consumption, following forecast errors or significant accidental deviations from the daily demand pattern.
All these quantities can amount to an important value over longer time periods. If they are not traded in the local market, the prosumers would sell at minimum price to the aggregator, while the consumers would buy electricity at standard, high tariffs.
The algorithm proposed in the paper offers the possibility of extending the primary market with a two-tier secondary market, in order to make prosumer and consumer surplus quantities available for trading in the local network.

The Secondary Market-The Energy Poverty Tier
The local market is profitable mostly to consumers with high demand, who can better benefit from the energy cost reduction obtained from the difference between the grid tariffs and the price per kWh offered by the local producers. These consumers are also usually those who have the financial resources to install the physical and software infrastructure required to access the market.
On the other hand, amongst the consumers connected in a microgrid can exist a number of low-income consumers, who in traditional networks would be classified as belonging to vulnerable categories and suffer from energy poverty. The paper proposes an optional secondary market tier in which the surplus that cannot be traded in the primary market would be automatically allocated in the initial settlement phase (see Figure 1) to such vulnerable consumers who, in normal conditions, would not be able to access the local market.
The surplus can come from both prosumers and consumers, as summarized in the previous subsection. In all the cases, the electricity quantities will result from the mismatch between the quantities offered for trading (higher)-CO(h,i) or GO(h,j)-and actual traded quantity, determined by the existing (lower) generation availability TC(h,j) or realized consumption TC(h,i): Thus, consumers who were buyers in the primary market can act as sellers in the secondary market, together with the prosumers.
The quantities sold to vulnerable consumers in the secondary market are determined using the merit-order method where the buyers' prices are set as 0 mu/kWh (mu is the monetary units) and the quantities are ranked in descending order. The cost for traded kWh can be set using as reference the price obtained by the seller in the primary market, the original price offer placed by the seller in the primary market or an agreed fixed tariff, according to the policy agreed in the local market.
This trading scheme offers two benefits. The vulnerable consumers from the microgrid will see social welfare increase by the reduction of their electricity bill, which will be proportional to their consumption in the trading hours interval and the market price. On the other hand, the prosumers with remaining generation surplus and the consumers who have surplus to sell after the initial settlement of the primary market can sell electricity at higher prices than the tariff used by the aggregator.
The flowchart of the first tier of the secondary market is presented in Figure 6.
Since the demand of the vulnerable consumers selected for the energy poverty tier is expected to be low, the remaining surplus after the settlement of the first tier can be further traded in a second tier reserved for commercial trading. social welfare increase by the reduction of their electricity bill, which will be proportional to their consumption in the trading hours interval and the market price. On the other hand, the prosumers with remaining generation surplus and the consumers who have surplus to sell after the initial settlement of the primary market can sell electricity at higher prices than the tariff used by the aggregator.
The flowchart of the first tier of the secondary market is presented in Figure 6. Since the demand of the vulnerable consumers selected for the energy poverty tier is expected to be low, the remaining surplus after the settlement of the first tier can be further traded in a second tier reserved for commercial trading.

The Secondary Market-The Commercial Tier
The commercial tier of the secondary market is designed to incentivize market diversity by allowing other consumers to participate in trading. Several consumer categories are envisioned. Some consumers would not trade continuously and would seek only occasional access to the market, buying the local generation surplus to supply automated receptors such as greenhouse irrigation systems in given hours of preset days. Other types of occasional consumers could benefit from the price difference when trading on the local market, but the initial investment for the infrastructure required to get access to the market would be prohibitive.
Two options are available in the algorithm for this trading segment:  Option 1: Fee access.  Option 2: Invite access.
In the fee-access model, the consumers who need only occasional access to the market can submit offers in the secondary market to gain priority access for the surplus remaining after the settlement of the primary market offers. The trading model considers the merit-order priority method described

The Secondary Market-The Commercial Tier
The commercial tier of the secondary market is designed to incentivize market diversity by allowing other consumers to participate in trading. Several consumer categories are envisioned. Some consumers would not trade continuously and would seek only occasional access to the market, buying the local generation surplus to supply automated receptors such as greenhouse irrigation systems in given hours of preset days. Other types of occasional consumers could benefit from the price difference when trading on the local market, but the initial investment for the infrastructure required to get access to the market would be prohibitive.
Two options are available in the algorithm for this trading segment: • Option 1: Fee access. • Option 2: Invite access.
In the fee-access model, the consumers who need only occasional access to the market can submit offers in the secondary market to gain priority access for the surplus remaining after the settlement of the primary market offers. The trading model considers the merit-order priority method described in Figure 5 for the primary market, but where the consumers offer to buy from the market their entire consumption measured in the trading interval, at the lowest price plus a fixed percent fee from the value of the transaction. The merit order is used to determine the succession in which the offers are fulfilled. The financial settlement is made using the MCP, the consumer or the prosumer price offers for all transactions, according to the market policy, and then a fee f% is added to the price resulting from the trading mechanism.
The basic flowchart of the fee-access secondary market model is given in Figure 7.
Sustainability 2020, 12, x FOR PEER REVIEW 13 of 43 in Figure 5 for the primary market, but where the consumers offer to buy from the market their entire consumption measured in the trading interval, at the lowest price plus a fixed percent fee from the value of the transaction. The merit order is used to determine the succession in which the offers are fulfilled. The financial settlement is made using the MCP, the consumer or the prosumer price offers for all transactions, according to the market policy, and then a fee f% is added to the price resulting from the trading mechanism.
The basic flowchart of the fee-access secondary market model is given in Figure 7. In the invite-access model, existing market players can act as subcontractors for other consumers from the microgrid. Certain prosumers or consumers can still have surplus quantities unsold after the previous settlement sessions have been completed. In order to avoid getting the lowest price per kWh from the market aggregator, they can optionally choose a partner from the microgrid to which the remaining quantities will be sold. The transactions are based on P2P contracts existing between the two entities and notified to the market administrator, who is responsible for the final settlement at market level. The settlement price is agreed between the parties, chosen from the vendor and buyer offers.
The flowchart of the secondary market invite-access model is provided in Figure 8.  In the invite-access model, existing market players can act as subcontractors for other consumers from the microgrid. Certain prosumers or consumers can still have surplus quantities unsold after the previous settlement sessions have been completed. In order to avoid getting the lowest price per kWh from the market aggregator, they can optionally choose a partner from the microgrid to which the remaining quantities will be sold. The transactions are based on P2P contracts existing between the two entities and notified to the market administrator, who is responsible for the final settlement at market level. The settlement price is agreed between the parties, chosen from the vendor and buyer offers.
The flowchart of the secondary market invite-access model is provided in Figure 8.
kWh from the market aggregator, they can optionally choose a partner from the microgrid to which the remaining quantities will be sold. The transactions are based on P2P contracts existing between the two entities and notified to the market administrator, who is responsible for the final settlement at market level. The settlement price is agreed between the parties, chosen from the vendor and buyer offers. The flowchart of the secondary market invite-access model is provided in Figure 8. It should be noted that the secondary market models are optional, and their order of activation can be changed according to the priorities of a specific microgrid. Instances can exist where the energy poverty mitigation tier is absent or one or both segments of the secondary commercial tier are used.

Results
The new market was tested on an LV distribution network from Romania, with 28 buses and two four-wire three-phase bundled feeders, with an average distance between the connection points of 40 m. The network supplies only single-phase residential consumers, some of whom also have PV generation capabilities. The load and generation profiles used in the study are considered as daily 24-hour measured values, as provided from the smart metering infrastructure existing in the LV microgrid. The 24-hour load profiles for the network buses are presented in Table A1 in Appendix A.
Each bus, except bus 1, which is a branching point, has one residence connected. The prosumers are located at buses 3, 6, 7, 10, 15, 25 and 27, as shown in the one-line diagram from Figure 9. Their 24-hour generation profiles were modeled using representative data for this type of generation and are provided in Appendix A, Table A2. The prosumers will use the generated electricity primarily for supplying their own hourly demand, and wish to sell the remaining surplus to the consumers participating in the local market set up at microgrid level and managed by a non-profit aggregator. From Table 2 and Figure 10, it is seen that generation occurs only in the 06:00-18.00 interval, when solar energy is available. The surplus is maximized in the 10:00-13:00 interval and minimized towards the evening time, when the peak load hours are near. It should be noted that the secondary market models are optional, and their order of activation can be changed according to the priorities of a specific microgrid. Instances can exist where the energy poverty mitigation tier is absent or one or both segments of the secondary commercial tier are used.

Results
The new market was tested on an LV distribution network from Romania, with 28 buses and two four-wire three-phase bundled feeders, with an average distance between the connection points of 40 m. The network supplies only single-phase residential consumers, some of whom also have PV generation capabilities. The load and generation profiles used in the study are considered as daily 24-hour measured values, as provided from the smart metering infrastructure existing in the LV microgrid. The 24-hour load profiles for the network buses are presented in Table A1 in Appendix A.
Each bus, except bus 1, which is a branching point, has one residence connected. The prosumers are located at buses 3, 6, 7, 10, 15, 25 and 27, as shown in the one-line diagram from Figure 9. Their 24-hour generation profiles were modeled using representative data for this type of generation and are provided in Appendix A, Table A2. The prosumers will use the generated electricity primarily for supplying their own hourly demand, and wish to sell the remaining surplus to the consumers participating in the local market set up at microgrid level and managed by a non-profit aggregator. From Table 2 and Figure 10, it is seen that generation occurs only in the 06:00-18.00 interval, when solar energy is available. The surplus is maximized in the 10:00-13:00 interval and minimized towards the evening time, when the peak load hours are near.

The Primary Market
From the 27 consumers existing in the microgrid, the case study considers that only 11 are participating in the primary market as buyers (from buses 5,8,9,11,12,14,16,19,20,24,26), chosen mainly between the residences with high daily electricity demand. For each hour h, they can submit to the market two types of offers according to the traded quantity: the entire hourly demand and forecasted values, in multiples of 100 kW, as discussed in Section 3.2. For the forecasted offers, the values used in the case study are given in Table A3 in Appendix A, and in Figure 11, only for the hour intervals in which prosumer generation exists.

The Primary Market
From the 27 consumers existing in the microgrid, the case study considers that only 11 are participating in the primary market as buyers (from buses 5,8,9,11,12,14,16,19,20,24,26), chosen mainly between the residences with high daily electricity demand. For each hour h, they can submit to the market two types of offers according to the traded quantity: the entire hourly demand and forecasted values, in multiples of 100 kW, as discussed in Section 3.2. For the forecasted offers, the values used in the case study are given in Table A3 in Appendix A, and in Figure 11, only for the hour intervals in which prosumer generation exists.
The sellers who place offers in the primary market are the prosumers with generation surplus. It is considered that they wish to sell the entire surplus on the market to maximize their revenue. The quantities offered, derived from Tables A1 and A2, are presented in Table 2 and Figure 10, where it can be seen that surplus exists for trading in all hourly intervals from 06:00 to 18:00, but there are prosumers who cannot trade electricity at some hours (for example, P27 or P6).
For all quantity offers, the consumers and the prosumers must also provide in the blockchain system of the primary market the desired price offers, which are given in Tables A4 and A5 in Appendix A. These values were set between 0.39 and 0.6 mu/kWh for consumers, and in the 0.4-0.55 mu/kWh range for prosumers. The higher maximum prices for consumers were chosen taking into account the merit-order method, in which the offers with the highest prices are prioritized. Furthermore, both the prosumers' and consumers' price offers were set higher than the regulated tariff to incentivize the trading in the local market.
If the market would not be present, the total electricity surplus quantity (167.97 kWh) would be traded by the aggregator back in the grid, at a regulated tariff. Using the reference value of 0.251 mu/kWh applied in Romania [73,74], the total revenue of the prosumers would be of 42.16 mu/day.
For demonstrating the advantages and disadvantages of each trading priority method used in the market, FCFS and MO, the case study results are be provided as comparisons between these alternatives.
As it can be seen from Figure 11, there are hours when the MO offers differ from the total demand used in the FCFS offers. This can happen because of two reasons: the forecast error and the standardized offer type (multiple of 100 W) used by the MO method. On the other hand, the offers placed by the consumers in the market are identical for both trading methods, and equal to the available surplus ( Figure 10), because one of the main objectives of the local market is to enable prosumers to sell the entire surplus locally, and offers given as multiples of 100 W would impede the achievement of this goal. The traded quantities and revenues/costs for each prosumer/consumer and hourly interval are given in Figures 12 and 13 and Tables 3-6.
The data from Tables 3-6 show some interesting results regarding the hourly and daily offers and traded quantities for the consumers and prosumers. The sellers who place offers in the primary market are the prosumers with generation surplus. It is considered that they wish to sell the entire surplus on the market to maximize their revenue. The quantities offered, derived from Tables A1 and A2, are presented in Table 2 and Figure 10, where it can be seen that surplus exists for trading in all hourly intervals from 06:00 to 18:00, but there are prosumers who cannot trade electricity at some hours (for example, P27 or P6).
For all quantity offers, the consumers and the prosumers must also provide in the blockchain system of the primary market the desired price offers, which are given in Tables A4 and A5 in Appendix A. These values were set between 0.39 and 0.6 mu/kWh for consumers, and in the 0.4-0.55 mu/kWh range for prosumers. The higher maximum prices for consumers were chosen taking into account the merit-order method, in which the offers with the highest prices are prioritized. Furthermore, both the prosumers' and consumers' price offers were set higher than the regulated tariff to incentivize the trading in the local market.
If the market would not be present, the total electricity surplus quantity (167.97 kWh) would be traded by the aggregator back in the grid, at a regulated tariff. Using the reference value of 0.251 mu/kWh applied in Romania [73,74], the total revenue of the prosumers would be of 42.16 mu/day.
For demonstrating the advantages and disadvantages of each trading priority method used in the market, FCFS and MO, the case study results are be provided as comparisons between these alternatives.
As it can be seen from Figure 11, there are hours when the MO offers differ from the total demand used in the FCFS offers. This can happen because of two reasons: the forecast error and the standardized offer type (multiple of 100 W) used by the MO method. On the other hand, the offers placed by the consumers in the market are identical for both trading methods, and equal to the available surplus ( Figure 10), because one of the main objectives of the local market is to enable prosumers to sell the entire surplus locally, and offers given as multiples of 100 W would impede the achievement of this goal.
The traded quantities and revenues/costs for each prosumer/consumer and hourly interval are given in Figures 12 and 13 and Tables 3-6.  Table 3. The daily offer, traded and remaining quantities for each buyer in the primary market, kWh.    The data from Tables 3-6 show some interesting results regarding the hourly and daily offers and traded quantities for the consumers and prosumers.
The local generation surplus (167.97 kW) is insufficient to supply all the consumer needs (203.43 kWh). From Table 3, it is seen that, for the chosen consumption, local generation and primary market offers, when using the FCFS trading priority, the consumers can trade quantities lower than their consumption, and will need to buy the rest from the grid, at higher tariffs. If the MO trading priority is used, Table 4 shows that the hourly buy offers placed by the consumers are usually not fully fulfilled, but the traded quantities exceed the consumption. This leads to a surplus with the consumers, which will be traded to the grid, at regulated tariffs, or sold in the secondary market.
For prosumers, there are trading intervals where the surplus exceeds the traded prosumer offer and traded consumer quantities which are equal (for example, at h11, as seen from Tables 4 and 6). This suggests that the prosumer will not be able to sell their entire surplus because of lack of demand. Additionally, applying the FCFS and MO trading priorities in fulfilling the market offers has different effects on the traded quantities, both hourly and for individual prosumers or consumers. If the FCFS trading priority is used, the total quantity traded by the prosumers is larger (Table 5) because the prosumer surplus offers can be matched more closely by the consumer offers. This means that if the MO trading priority is used, it is expected to have more surplus unsold to the local consumers, thus reducing the profitability of the prosumers. In this case, they would have to sell extra surplus to the grid in exchange for the regulated tariff, which is lower than the local consumer offers. As it can be seen from Table 6, the generation surplus remaining after the primary market is concentrated in the 09:00-14:00 interval, while the evening and morning intervals see the highest deficit in local generation (Table 4).   The profitability of the FCFS and MO trading priorities can be assessed from Figure 14 and Tables 7  and 8 for the buyers and Figure 15 and Tables 9 and 10 for the sellers. The market model offers the possibility of performing financial settlement in three assumptions for the prices: using the market clearing price (MCP), the consumer offers (COP) and the prosumer offers (POP), because different microgrids can pursue different objectives when establishing the local market. For example, using POP coupled with MO in the primary market can be an advantage for the buying consumers, who will buy electricity at lower prices from the local prosumers instead of paying the standard residential tariff. Using the MCP favors the prosumers with lower prices. In generation surplus scenarios, they can sell electricity at a higher clearing price. Using the COP will be an advantage for the prosumers, who will be able to obtain settlement prices larger than their initial offers.
The sellers/vendors with the highest cost/revenue can be considered as making the most profit because quantities are bought by consumers at a price lower than the standard LV residential tariff, while the sell offers are settled by the vendors at a price higher than the resell tariff to the grid.      For the scenario considered in the case study, Figures 14 and 15 show that the highest revenues are obtained by prosumers when the consumer offer prices (COP) are used for settlement. If the FCFS trading priority is used, the MCP and POP settlements give the same results, because the For the scenario considered in the case study, Figures 14 and 15 show that the highest revenues are obtained by prosumers when the consumer offer prices (COP) are used for settlement. If the FCFS trading priority is used, the MCP and POP settlements give the same results, because the methodology from [40] uses as settlement price the prosumer offers, and the MCP and POP trading priorities would result the same, as the buy offer price is not relevant and thus considered 0 um/kWh for all buyers. For the MO trading priority, the MCP settlement results in higher trading prices than POP, because the trading price for all sellers and buyers is determined by the price unrestricted merit order used in wholesale markets ( Figure 4).
As it can be seen from Tables 7-10, the players who get the most advantage from the local market are C8, C9, C24, the consumers without generation capability that have the highest demand, and P15, P3, P25, the prosumers with the largest daily surplus.

The Secondary Market-The Energy Poverty Mitigation Tier
The proposed local market model uses in the secondary market an optional energy poverty mitigation tier, designed to include a category of consumers that can usually will not be able to trade on the market because of their low income or other social vulnerabilities. The microgrid community can decide to assist these consumers by supporting the reduction of their electricity bill. The simplest way to achieve this goal is to automatically allocate the prosumer surplus available after the settlement of the primary market to cover the demand of such consumers. In the data used for the case study, a single consumer, C28, fulfills the requirements of a vulnerable consumer. As seen in Table A1, its total daily consumption amounts to 3.31 kWh, with 1.79 kWh in the 06:00-18:00 interval.
Since the two trading priority methods (FCFS and MO) give in the primary market different results regarding the trading participants and quantities at each hour, a similar behavior is propagated in the secondary market. Thus, the trading results will be presented in the same manner as for the primary market, as a comparison between the cases in which the primary market uses the FCFS or the MO in determining the priorities of the traded quantities. It is considered that the secondary market uses the same price offers entered in the blockchain system for the primary market.
According to the data from Tables 3 and 5, after the settlement of the primary market, prosumers P21, P7, P15, P6, P3, P25 have unsold surplus if the FCFS trading priority is used. No consumers can participate in the secondary market, because they cannot have surplus after trading. If the MO priority is used, the prosumers with available surplus are P21, P15, P3, and also there are consumers which have placed in the primary market offers exceeding their real consumption, and can become sellers on the secondary market (C5, C9, C11, C12, C16, C19, C20, C24, and C26). The hours in which the sellers are having surplus after the primary market are presented in Appendix B, Tables A6 and A7.
The only entity buying in this market is C28, and its hourly buy offer match its entire consumption (See Table A1). However, these are total quantities, and each seller can trade different surplus quantities in each hour. This will lead to the necessity of prioritization of the sell offers, and subsequent settlement between C28 and possibly multiple sellers. The quantities traded hourly are presented in Appendix B, Tables A8 and A9. The sell offers and traded quantities are given in Figures 16 and 17. Tables 11-14 summarize the daily and hourly offers and quantities traded by buyers and sellers. participate in the secondary market, because they cannot have surplus after trading. If the MO priority is used, the prosumers with available surplus are P21, P15, P3, and also there are consumers which have placed in the primary market offers exceeding their real consumption, and can become sellers on the secondary market (C5, C9, C11, C12, C16, C19, C20, C24, and C26). The hours in which the sellers are having surplus after the primary market are presented in Appendix B, Tables A6 and A7. The only entity buying in this market is C28, and its hourly buy offer match its entire consumption (See Table A1). However, these are total quantities, and each seller can trade different surplus quantities in each hour. This will lead to the necessity of prioritization of the sell offers, and subsequent settlement between C28 and possibly multiple sellers. The quantities traded hourly are presented in Appendix B, Tables A8 and A9. The sell offers and traded quantities are given in Figures  16 and 17. Tables 11-14 summarize the daily and hourly offers and quantities traded by buyers and sellers.         Tables 11-14 reveal significantly different trading scenarios on the energy poverty mitigation market when the two trading priority methods (FCFS and MO) are used in the primary market. For FCFS, 3 out of 5 prosumers will trade electricity with C28, while if MO were to be used, only P15 and P3 will sell electricity, the rest of the buying offer being fulfilled by just one consumer, C19. Also, if the secondary market is activated, the available surplus rises when MO is used from 13.88 kWh in the primary market to 63.18 kWh, due to the presence of the consumers who need to sell the surplus generated by the forecast error or offer quantity rounding. In the absence of the secondary market, these two quantities would be sold back to the grid at minimal price. Thus, in addition to allowing prosumer to sell more surplus, the secondary market offers a mechanism for minimizing the effect of consumption forecast errors at the consumer side when the MO trading priority method is used. However, the prosumer and consumer surplus to be sold back to the grid remain high, at 13.27 kWh and 48.12 kWh respectively (Table 13).
The costs of the consumer C28 and revenues of the vendors in the energy poverty market tier are given in Tables 15-18 and Figures 18 and 19. The financial settlement is performed in this case using as reference only the vendor price offer, similar to POP from Tables 7-10, because with just one vulnerable consumer trading in the market, the COP is viable only if the consumer would buy at a fixed tariff, and MCP results are the same as POP when COP is not specified.
The results show that the vendor revenues are lower than in the primary market, because of the smaller traded quantities, but they can become significant if they are averaged over longer periods (months, years). The consumer C28 will pay less in the local market than when buying electricity from the grid, and the MO trading priority maximizes its earnings and the number of hourly intervals in which trading can be made. A more profitability analysis will follow in the Discussions section, for all the trading segments considered in the market algorithm.
The costs of the consumer C28 and revenues of the vendors in the energy poverty market tier are given in Tables 15-18 and Figures 18 and 19. The financial settlement is performed in this case using as reference only the vendor price offer, similar to POP from Tables 7-10, because with just one vulnerable consumer trading in the market, the COP is viable only if the consumer would buy at a fixed tariff, and MCP results are the same as POP when COP is not specified. The results show that the vendor revenues are lower than in the primary market, because of the smaller traded quantities, but they can become significant if they are averaged over longer periods (months, years). The consumer C28 will pay less in the local market than when buying electricity from the grid, and the MO trading priority maximizes its earnings and the number of hourly intervals in which trading can be made. A more profitability analysis will follow in the Discussions section, for all the trading segments considered in the market algorithm.

The Secondary Market-The Commercial Tariff Access Tier
As seen previously, the vendors can remain after the primary market with surplus available for selling. Both prosumers and consumers can become sellers on the secondary market. The energy poverty mitigation tier can help to reduce the surplus, but, if the vulnerable consumers have low demand and are in low numbers, the quantities still remaining after the settlement can be significant. For the demand-generation balance and the set of offers used in the case study, the total primary market surplus is of 63.18 kWh and reduces only to 61.39 kWh after the energy poverty mitigation market, if the MO trading method is used. For the FCFS method, the remaining surplus decreases from to 11.58 kWh to 10.86 kW. For further reducing the quantity sold to the grid, the local market model uses the second tier of the secondary market, operated according to the MO trading priority method used in the primary market, but with different market participants.
The sellers that can enter this market segment are the same as for the energy poverty mitigation market: prosumers with remaining surplus and consumers whose offers placed in the blockchain system of the primary market exceed their actual demand, thus becoming surplus. The buyers are consumers from the same microgrid who did not participate in the primary market, but are ready to occasionally buy surplus from the secondary market when it is available, at market prices. In exchange for this facility, they pay an extra fee, according to the formula from Equation (10). The quantities are determined automatically in the settlement phase of the energy poverty market or at the end of the primary market, if the EP tier is not used. The sell price offers are the offer prices entered by prosumers in the blockchain system of the primary market. For consumers the buy prices are: C13-0.47 mu/kWh, C17-0.30 mu/kWh, C18-0.42 mu/kWh, lower than the average offers from the primary market, in order to minimize the effect of the added tariffs. The fulfilment priority for the buy and sell offers is determined using the MO strategy from Figure 4, and the actual quantities and financial exchanges between sellers and buyers are settled as in the primary market.
Using as reference the trading data from Table 13, the sellers participating in the market are P21, P15, P6 and P3, if the FCFS method is used in the primary market, and P21, P15, P3, C5, C9, C11, C12, C16, C19, C20, C24, and C26. The buyers are three consumers that did not participate in the primary market, namely C13, C17 and C18. The fee applied for all the consumers is a 10% increase of the final buy price, and it is charged by the market administrator. For evaluating all the possibilities regarding the financial settlement, all three price alternatives will be considered: MCP, COP and POP, similar to the primary market. The quantities offered and actually traded by each vendor and buyer in the two primary market methodologies (FCFS and MO) are given in Appendix C, Tables A10-A14.
The results show that the use of the MO in the primary market leads to higher quantities traded in the tariff-access market tier, while if the FCFS priority is chosen, prosumer surplus is lower. The hourly results for the market and the daily quantities traded by the prosumers and the consumers are summarized, as for the previous market tiers, in Figures 20-23 and Tables 19-22. The results from Tables 19-22 show that the tariff-access consumers are able to acquire 7.67 kWh for the FCFS primary market trading priority, exclusively from prosumer surplus. 21.28 kWh are bought for the MO trading priority method, mainly from consumer surplus, as it can be seen in Table 21. When the MO method is used, the consumer buy offers are fulfilled from the most part from the local market (Table 20), only 1.2 kWh remaining to be bought from the grid. After the settlement of the two commercial market tiers, the prosumers lower their unsold surplus to only 3.19 kWh (FCFS) or 4.7 kWh (MO), while the consumer surplus remains high, at 35.94 kWh. The prosumer surplus is available mainly in the 09:00-14:00 interval, while the consumer surplus can be accessed outside this interval, between 06:00-8:00 and 15:00-18:00 (see Table A11).
Because of the larger quantities bought by the three consumers, the fee-access tier is more profitable for the surplus vendors, compared to the energy poverty mitigation market. In addition, considering the lower price offers used for the tariff-access consumers, the COP settlement option is the best choice for the consumers, incurring the lowest costs (see Table 25). For the FCFS trading priority method, MCP and POP give the same results, which suggests that the merit order clearing price is determined by higher vendor price offers (Table 26). market, if the MO trading method is used. For the FCFS method, the remaining surplus decreases from to 11.58 kWh to 10.86 kW. For further reducing the quantity sold to the grid, the local market model uses the second tier of the secondary market, operated according to the MO trading priority method used in the primary market, but with different market participants.
The sellers that can enter this market segment are the same as for the energy poverty mitigation market: prosumers with remaining surplus and consumers whose offers placed in the blockchain system of the primary market exceed their actual demand, thus becoming surplus. The buyers are consumers from the same microgrid who did not participate in the primary market, but are ready to occasionally buy surplus from the secondary market when it is available, at market prices. In exchange for this facility, they pay an extra fee, according to the formula from Equation (10). The quantities are determined automatically in the settlement phase of the energy poverty market or at the end of the primary market, if the EP tier is not used. The sell price offers are the offer prices entered by prosumers in the blockchain system of the primary market. For consumers the buy prices are: C13-0.47 mu/kWh, C17-0.30 mu/kWh, C18-0.42 mu/kWh, lower than the average offers from the primary market, in order to minimize the effect of the added tariffs. The fulfilment priority for the buy and sell offers is determined using the MO strategy from Figure 4, and the actual quantities and financial exchanges between sellers and buyers are settled as in the primary market.
Using as reference the trading data from Table 13, the sellers participating in the market are P21, P15, P6 and P3, if the FCFS method is used in the primary market, and P21, P15, P3, C5, C9, C11, C12, C16, C19, C20, C24, and C26. The buyers are three consumers that did not participate in the primary market, namely C13, C17 and C18. The fee applied for all the consumers is a 10% increase of the final buy price, and it is charged by the market administrator. For evaluating all the possibilities regarding the financial settlement, all three price alternatives will be considered: MCP, COP and POP, similar to the primary market. The quantities offered and actually traded by each vendor and buyer in the two primary market methodologies (FCFS and MO) are given in Appendix C, Tables A10-A14.
The results show that the use of the MO in the primary market leads to higher quantities traded in the tariff-access market tier, while if the FCFS priority is chosen, prosumer surplus is lower. The hourly results for the market and the daily quantities traded by the prosumers and the consumers are summarized, as for the previous market tiers, in Figures 20-23 and Tables 19-22.           The results from Tables 19-22 show that the tariff-access consumers are able to acquire 7.67 kWh for the FCFS primary market trading priority, exclusively from prosumer surplus. 21.28 kWh are bought for the MO trading priority method, mainly from consumer surplus, as it can be seen in Table  21. When the MO method is used, the consumer buy offers are fulfilled from the most part from the local market (Table 20), only 1.2 kWh remaining to be bought from the grid. After the settlement of the two commercial market tiers, the prosumers lower their unsold surplus to only 3.19 kWh (FCFS) or 4.7 kWh (MO), while the consumer surplus remains high, at 35.94 kWh. The prosumer surplus is available mainly in the 09:00-14:00 interval, while the consumer surplus can be accessed outside this interval, between 06:00-8:00 and 15:00-18:00 (see Table A11).
The costs of the buyers and the revenues of the vendors in this market tier are summarized in Figures 24 and 25 and Tables 23-26, for all three available settlement policies (MCP, COP, POP).    The costs of the buyers and the revenues of the vendors in this market tier are summarized in Figures 24 and 25 and Tables 23-26, for all three available settlement policies (MCP, COP, POP).      Because of the larger quantities bought by the three consumers, the fee-access tier is more profitable for the surplus vendors, compared to the energy poverty mitigation market. In addition, considering the lower price offers used for the tariff-access consumers, the COP settlement option is the best choice for the consumers, incurring the lowest costs (see Table 25). For the FCFS trading priority method, MCP and POP give the same results, which suggests that the merit order clearing price is determined by higher vendor price offers (Table 26).

The Secondary Market-The Commercial Invite Access Tier
An alternative proposed in the local market model for the tariff-access secondary market is an invite-access market tier. This solution, while it has lower impact on the surplus reduction at market level, is viable for individual prosumers and consumers which are in the situation of frequently having unsold surplus after the final settlement. The invite-access strategy proposes that long-term P2P contracts can be established between seller-buyer pairs, stipulating that the buyer can automatically access the unsold surplus of the seller when it is available. In this case, the settlement is not performed at market level, but only for the two parties involved, and it can be considered that the buyer is an 'invited guest' in the local market.
The market diagram from Figure 1 considers the invite-access market as an alternative to the tariff-access market, but this approach is not mandatory, as the energy mitigation market, the tariffaccess market and the invite-access market can be used in any desired order or number in the architecture of the local market.
Considering the layout from Figure 1 and the data from Tables 2, A2, A7 and A13, the evolution of the surplus of prosumer P21 in the MO primary market priority case is the one seen in Table 27. The prosumer is able to sell 4.844 kWh on the tariff-access market.
On the other hand, if the prosumer has a P2P contract with consumer C22 who did not participate in the primary market, and the tariff access option is not activated, then it would be possible to sell in the invite-access market almost the same quantity, as can be seen in Table 28.

The Secondary Market-The Commercial Invite Access Tier
An alternative proposed in the local market model for the tariff-access secondary market is an invite-access market tier. This solution, while it has lower impact on the surplus reduction at market level, is viable for individual prosumers and consumers which are in the situation of frequently having unsold surplus after the final settlement. The invite-access strategy proposes that long-term P2P contracts can be established between seller-buyer pairs, stipulating that the buyer can automatically access the unsold surplus of the seller when it is available. In this case, the settlement is not performed at market level, but only for the two parties involved, and it can be considered that the buyer is an 'invited guest' in the local market.
The market diagram from Figure 1 considers the invite-access market as an alternative to the tariff-access market, but this approach is not mandatory, as the energy mitigation market, the tariff-access market and the invite-access market can be used in any desired order or number in the architecture of the local market.
Considering the layout from Figure 1 and the data from Tables 2, A2, A7 and A13, the evolution of the surplus of prosumer P21 in the MO primary market priority case is the one seen in Table 27. The prosumer is able to sell 4.844 kWh on the tariff-access market. On the other hand, if the prosumer has a P2P contract with consumer C22 who did not participate in the primary market, and the tariff access option is not activated, then it would be possible to sell in the invite-access market almost the same quantity, as can be seen in Table 28. Furthermore, a scenario can be imagined in which the invite market is activated first, followed by the tariff-access market, in which case prosumer P21 would be able to sell their entire surplus in the local blockchain market.
Thus, if the market model is optimally configured, it can lead to the maximization of the local trading, thus minimizing the surplus sold to the grid at regulated tariffs.

Discussion
The results presented in the case study show that the secondary market has a positive effect regarding the surplus quantities sold by the prosumers in the local market. A key aspect that still needs to be discussed is the profitability of the local market, with its two components. Using Tables 3,  5, 11, 13, 19 and 21 for quantities, the influence of the primary and secondary markets on the quantities sold by the prosumers and consumers back to the grid is determined in Tables 29 and 30.   Table 29 shows that the offer quantities used in the MO trading priority determine a 49.3 kWh surplus at the consumers, which represents electricity traded but not consumed. This represents a high value, at 25% of the total consumption, and is mainly determined by hourly demand forecast errors. In the absence of the secondary market, the entire quantity would be sold to the grid, and the price mismatch between the buy price on the market (high) and sell price to the grid (low) would represent a cost increase for the consumers. Thus, accurate demand forecasts could reduce the costs for the consumers participating in the market. Additionally, it can be seen that the FCFS trading priority results in lower quantities sold back to the grid, as consumer surplus is absent. Table 30 shows that the secondary market makes a significant contribution to reducing the prosumer surplus from 11.58/13.88 kWh to 3.18/4.17 kWh. Here, it can be seen that while the bulk of the surplus is sold on the primary market, the secondary market allows an important increase of local generation sold locally. The primary market helps prosumers to sell the majority of their surplus in the local market, and the supplementary market tiers allow consumers to mitigate forecast errors by acting as sellers, and also reduce the share of surplus prosumer generation sold back to the grid. These trading options can have, depending on local conditions, positive effects in increasing the number of prosumers in the microgrid and reducing the electricity acquired by the consumers from the grid, at higher prices and taxes. In other words, social and environmental sustainability can be improved.
The reduction of local generation quantities sold back to the grid has positive financial effects for both prosumers and consumers. In the absence of the local market, the prosumers would sell any surplus to the grid at the regulated price. The market allows them to obtain better prices, which are still attractive for consumers as long as they do not exceed the tariff paid for the electricity imported from the grid. On the other hand, by participating in the local market, the consumers have the chance of paying less for electricity. From Tables 7,9,15,17,23 and 25, the costs and revenues for the sellers and vendors on each market segment can be summarized in Tables 31 and 32, for the 06:00-18:00 interval of the analyzed day.  Table 31 shows that the highest costs for the consumers occur when the COP settlement is used, while the POP settlement offers the best buy prices from the market. In Table 32, it can be seen that the prosumer revenues can double when the primary and secondary markets are used, with the highest profits being achieved on the primary market. The secondary market is, however, useful for the consumers who need to sell surplus remaining from the primary market, increasing their daily revenue by up to 200% (14.89 mu, compared to 12.38 mu).
Using the traded quantities and factoring the costs and revenues presented above, a comparison can be made between the daily electricity costs for the aggregated network demand in the 06:00-18:00 interval. Table 33 shows that the combined effect of the primary and secondary markets can decrease the cost by up to 26% when the FCFS trading prioritization is used. For MO prioritization, because of the significant consumer surplus in the primary market, the cost increases when MCP or COP settlement is used, but the effect of the secondary market is to compensate a fraction of the increase. It is important to note that the results presented in the paper are highly dependent on the input data used for the case study. The profits of the prosumers and the cost reductions for the consumers are affected by the quantities and prices offered in the market by both parties and can vary significantly from the results presented in the paper. Also, depending on local constraints, the trading tiers of the secondary market can be used only partially and in a different order. The case study presents a scenario of a complete market trading sequence to show the capabilities of the proposed model.
The results presented in Tables 29-33 use for the commercial tier of the secondary market only the tariff-access option.

Conclusions
The paper proposes a new local market for active microgrids, designed to maximize the surplus sold by the prosumers to the local consumers. The local market requires smart grid features in the microgrid and a blockchain ledger for submitting buy and sell offers. Trading is performed in two phases, first on a primary marked, followed by a two-tier secondary market. The case study shows that the secondary market can help the prosumers to sell more surplus to the local consumers, increasing their profitability. The advantages of the local market can be discussed from several perspectives:

•
The reduction of electricity quantities traded back to the grid (at lower prices) for prosumers; • The reduction of electricity costs for consumers, brought by acquiring cheaper electricity from the local prosumers; • The increase of profits for prosumers, by selling larger quantities to local consumers, at higher prices than the regulated tariff used to sell back to the grid. This can also be seen as an incentive for increasing sustainable electricity generation from renewable resources; • The energy poverty mitigation for some consumers, an aspect regarding economic and social sustainability.
However, as main disadvantages, accurate demand forecasts are necessary for the consumers if the MO trading method is used, for optimal market benefits. Furthermore, the implementation of the proposed market model is dependent on several prerequisites: the implementation of smart grid capabilities in the microgrid, the creation of adequate regulations by regional or national authorities, and the development of residential renewable electricity generation, all these being in incipient development stages across the world.
The proposed algorithm is a comprehensive tool of the trading process for consumers and prosumers in microgrids, considering the current regulation framework regarding prosumer activity in the Romanian electricity market, and future research directions considered by the authors aim to extend its capabilities for social inclusion, analyzing the influence of storage capabilities on local market trading dynamics and profitability, and considering new trading options, by comparison with similar real local market models, as they become available in the literature.

Patents
National Patent Application "Innovative method of decision-making assistance aimed at streamlining the management of prosumer activity", Romania, 2020, in press.

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