## 3 Framework Implementation
### Local Energy Market
#### 3.2.2 Pricing Algorithms  
For the validation of the proposed coordination scheme between CDT and LEM, the first step is the local price clearing at which the transactions take place in the market. Regarding the pricing algorithms, two different approaches are considered. In both algorithms, the price resolution is hourly, similar to the price signals of the external day-ahead market (DAM). Therefore, there is a different arbitrage (difference between LEM price and external price) for each particular hour. The two algorithms are summarized below:  
* Peer-to-peer (P2P) pricing algorithm: The first approach is a direct P2P pricing mechanism. In a P2P transaction, the buyer and the seller transact directly with each other in terms of the delivery of the good or service and the exchange of payment. Specifically, after the initial submission of the bids from both sides, the order book of the pairs of transactions is created. Multiple price levels are initially created since different energy levels are offered at different prices. Prices are ranked for sellers from the lowest to the highest and vice versa for buyers. If the lowest price for consumers is lower than the highest price for sellers, the transaction can be executed. Otherwise, there is a case of supply deficit; in that case, the minimum of the supply-demand pair is cleared within the internal market and the rest is supplied by the grid. The clearing price \(P_{lem}\) (the average value of the two prices) creates one universal price inside the LEM. A universal (same) price is desirable since it is easier to evaluate the efficiency of the market. The clearing price results from: \[P_{lem}=\frac{P_{prod_{low}}+P_{cons_{high}}}{2}\] (1)
* CDT-LEM pricing algorithm: In this work, the price is calculated based on the LEM's production and consumption values. In other words, the participants are not directly participating in the market in the form of bids. This pricing mechanism has three main advantages. First, it minimizes the participants' involvement so that the LEM is accessible to more potential members by lowering the entry barriers. Secondly, the elimination of a bidding process strengthens the resiliency of LEM against market manipulation concerns. Finally, the solution's applicability is straightforward since all the necessary data are directly taken from smart meters or IoT devices. The process of determining the clearing price is analyzed in more detail in the following section.  
In both pricing algorithms, the internal market is cleared at a price lower than the selling price of the retail external grid and higher than the buying price of the external grid. The internal energy is practically exempt from transfer losses and any other monetary burdens (such as transfer may incur due to the transition of energy through a large-scale grid) and thus the internal price can be lower. The time horizon that transactions take place depends on the market design (Day-ahead market, Real-time market, etc.), while the granularity of the algorithm's solution is determined mainly by how often the system updates its information and control signals.