New Methods for Improved Prosumer Trading and Energy Poverty Mitigation in Microgrids using Crowdsourcing Concepts and Blockchain Technologies

The deregulated markets have replaced the traditional way of trading electricity from the producers to the consumer, via government-owned organizations and regulated tariffs. Nowadays, electricity prices are determined by the offer-demand mechanism and consumers can negotiate tariffs with their supplier of choice. For classic wholesale suppliers, the tariffs are a result of the transactions performed on the wholesale market and the energy mix available in certain geographical regions. In parallel with becoming eligible and participating in retail electricity markets, the consumers use increasingly local generation sources based mostly on renewable energy technologies such as 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 benefits from their initial investment. Currently, several trading mechanisms for prosumers are available, ranging from the simplest, selling back the surplus to an aggregator at fixed tariffs, to more complex market schemes. This paper proposed a two-tier local market model for prosumers and consumers connected in microgrids, based on the blockchain technologies and other technologies and concepts such as remote sensing, smart grids, crowdsourcing and energy poverty.


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 estimated 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].
The blockchain technology was created as a solution to the problem of mistrust and data security. The first steps in the development of technology were taken in 1991, when Stuart Haber and W. Scott Stornetta first spoke about a cryptographically secure blockchain [3]. In 1993, together with Dave Bayer, they integrated optimal Merkel type trees in the concept [4]. Following the financial crisis of 2008, the concept of blockchain as a distributed database was developed, proposing a solution to change the way monetary transactions are carried out through various financial institutions. With the help of a peer-to-peer network and a distributed data server, a blockchain database can be autonomous [5].
In the recent years, billions of dollars have been invested in research on the blockchain technology in an attempt to make the most of its potential and understand how appropriate it is in the different economic domains [6]. But not all domains are fully ready to assimilate the blockchain technology. In each particular case, the current technological opportunities must be analyzed, as well as the challenges that the end-users face and how a new decentralized architecture could create value for them. The electricity industry is an extremely suitable candidate for blockchain technology-based innovation, with its complex supply chain with a need for increased transparency and improved data management and its highly transactional trading market that would benefit from fast settlement. The transparency and immutability of the blockchain can empower end-users of this industry and consumers.
A blockchain represents a decentralized ledger of transactions that take place in a network. This network consists of nodes owned by independent entities that use a cryptographic protocol to validate the transactions that are entered in the ledger and to ensure that the entered data cannot be altered or changed. It is immutable, secure, and completely transparent. Fully decentralized and replicated to node level, blockchain networks are harder to penetrate and manipulate by dangerous entities.
The blockchain system, coupled with other innovative technologies such as smart grids, big data mining and remote sensing, has the potential to provide solutions to various challenges in the energy sector and to contribute to the achievement of energy efficiency objectives, including to compensate for the funding gap for various projects in the field [7]. The technologies regarding blockchain-based platforms will lead to fundamental changes that will require the involvement of the distribution and supply companies, manufacturers of equipment, regulators, and last but not least end-users.
A review of renewable and sustainable energy published in [6] provides a systematic analysis of more than 140 blockchain research projects and startups in the energy sector, which span countries around the world. The electricity sector has a high potential to implement the blockchain technology as part of addressing several challenges [7], [8], [11], [12]: • The climate change. The need to integrate renewable energy sources has led to the development of technologies such as photovoltaic panels and wind turbines, whose costs are constantly decreasing. The consumers that choose to install such generation sources become prosumers, which present 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, being 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, REScoop cooperatives have explicitly set social goals, such as reducing energy poverty. They meet those objectives by developing solidarity schemes aimed at lowering the energy bills 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 a 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 policymakers to create a fair, useful, and cost-effective P2P energy 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 an 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 the power outages amount to about 20 minutes per year, but in other cases the average power outages range from 450 to 500 minutes [47]. Prosumers' micro-installations 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 small and fast changes in meteorological conditions can cause significant variability in power generation at different time and space scales. Methodologies based on the remote sensing of the atmospheric conditions are the primary source of information for the development of numerical models that aim at supporting the planning and operation of an electric system with a substantial contribution 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].
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.  [33,34], [36,37], [43], [45] No Our vision is to enable an overlay social network of smart devices that facilitates communication and trading process between players from LEM, prosumers, consumers and microgrid. Indubitably in microgrid communities the peers might be from different geographical locations (and bounded by, for example, the DSO). However, 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) too expensive [53,54], 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 in order 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, will sell the surplus back to the grid. As described in the introduction section, the simplest method of surplus trading is to sell back 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 [55], 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 [40] proposed an algorithm for electricity transactions at microgrid level between prosumers and consumers, using P2P contracts and the blockchain technology. The market mechanism considers trading priorities set at central level and based by consumer or prosumer prices, or custom priorities determined by the prosumerconsumer 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 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 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 would be less than the demand, the consumers would buy the rest at higher prices, from the national grid, and the generators are 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.

of 39
The newly proposed algorithm provides market mechanisms designed to alleviate these problems.
The following general assumptions are used: • 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 based on the blockchain technology, for ensuring the anonymity and security of 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 the 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 which otherwise would 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 considered fixed for all trading intervals of a day. 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 generation exceeds the local 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. The basic flowchart of the algorithm is shown in Figure 1, followed by the description of each of its main elements.

Input data for the local market
The input data required for trading refers to the quantities and prices associated to the consumption and local generation existing in the market. This information is provided in six matrices: C = C (h, i) ∈ ℝ nhxNCM , CO = CO (h, i) ∈ ℝ nhxNCM and PCO = PCO (h, i) ∈ ℝ nh× NCM for consumption quantity, offers and price offers, and G = G (h, j) ∈ ℝ nh×NPM , GO = GO (h, j) ∈ ℝ nh×NPM , PGO = PGO (h, j) ∈ ℝ 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 100W 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 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 or less than the offer placed in 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 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 the 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 in 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, al tower prices, rather than the main grid, at higher prices.

•
Consumers place in the market buy offers determined by forecast techniques using big data analysis or remote sensing techniques. The first type of offers 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 trading order and price is determined by the standard merit order method, provided in Figure 3, where the trading price is determined as the market clearing price (MCP). The flowchart of this trading method is given in Figure 4.
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 multiple 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 a important value over longer time periods. If they are not traded in the local market, the prosumers would sell surplus 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, which can better benefit for the energy cost reduction obtained from the price difference between the grid tariffs and the price offers 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 lowincome 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 that 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 with their consumption in the trading hours interval and the market price. On the other hand, the prosumers with remaining generation surplus and the consumers which 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 occasionally 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 presented 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, which 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 a real low voltage (LV) electricity 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 meters. The network supplies only single-phase residential consumers, some of which 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-hourly load profiles for the network buses are presented in Table A1 from 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 type of offers regarding the traded quantity: the entire hourly demand and forecasted values, multiple 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 from Appendix A, and in Figure 11, only for the hour intervals where prosumer generation exists.
The sellers that 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 from 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, where the offers with the highest prices are prioritized. Also, both the prosumers' and consumers' price offers were set higher than the regulated tariff, to incentivize the trading in the local market.
In the absence of the local market, 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 [56,57], 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 in achieving this goal.  The data from Tables 3-6 shows 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 lead to surplus at 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 its entire surplus because of lack of demand. Also, 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) 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-8 for the buyers and Figure 15 and Tables 9-10     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 with 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, which 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 Preprints (www.preprints.org) | NOT PEER-REVIEWED | Posted: 14 August 2020 doi:10.20944/preprints202008.0326.v1 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 3). 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, C26). The hours in which the sellers are having surplus after the primary market are presented in Appendix B, Table B1 and B2.
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, Table B3 17 and 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-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 it was seen previously, the vendors can remain after the settlement of the primary market with surplus available for selling back to the grid or to other local consumers. Both prosumers and consumers can become sellers on the secondary market. The energy poverty mitigation tier can help to reduce the surplus quantities, but, if the vulnerable consumers have low demand and are in low numbers, the surplus still remaining after the settlement of this market segment 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 proposed in the paper 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 fulfillment priority for the buy and sell offers is determined using the MO strategy from Figure 3, 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, 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 C1-C5.
The results show that the use of the MO trading priority in the primary market leads to higher quantities traded in the tariff access market tier, while if the FCFS trading priority is chosen, prosumer surplus is lower. The hourly results for the market and the daily quantities traded by the prosumers and the consumers care summarized, in the same manner as for the previous market tiers, in  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 C2).
The costs of the buyers and the revenues of the vendors in this market tier are summarized in       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 of 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 FCSF 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 at 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, B2 and C4, 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 on the tariff access market 4.844 kWh.
On the other hand, if the prosumer has a P2P contract with consumer C22 which did not participate in the primary market, and the tariff access option is not activated, then it would be able 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, win which case prosumer P21 would be able to sell its entire surplus in the local market. Thus, if the local 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 and 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% from 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 remote sensing techniques for improving the demand forecasts could reduce the costs for the consumers participating in the market. Table 29 also shows that the quantities traded in the primary market (PM) by the consumers are higher than in the secondary market. Also, The FCFS trading priority results in lower quantities sold back to the grid, because consumer surplus is absent. Table 30 shows that the secondary market has a significant contribution for reducing the prosumer surplus, from 11.58/13.88 kWh to 3.18/4.17 kWh.
On the other hand, 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 most 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 market 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 should be noted that the results presented in the paper are highly dependent on the input data used for the case study (consumption and generation profiles, buy and sell price offers). Also, 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. In the primary market, two trading priorities can be used: 'first-come-first-served' and the merit order mechanism specific to wholesale electricity markets. The secondary market has an energy poverty mitigation tier, designed to include in the market low-income or socially vulnerable consumers, and a commercial tier with two access options: fee-based and invite (P2P agreement)-based. The case study shows that the secondary market can help the prosumers to sell more surplus to the local consumers, increasing their profitability. However, the merit-order prioritization method reveals that precise remote sensing technologies are required for obtaining accurate demand forecasts for the consumers and reducing their monthly electricity costs. 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 will extend its capabilities for social inclusions and moreover, the reduction of the greenhouse gases by using these small-scale renewable energy sources.

Patents
National Patent Application "Innovative method of decision-making assistance aimed at streamlining the management of prosumer activity", Romania, 2020, in press. Appendix A -Input data for the primary market