## 3 P2P Trading Platform
### Trading Strategies and Determination of Optimal Quantities
#### 3.1.2 Strategy II: Preference-Based GT Approach  
In the preference-based GT approach, the first step follows the rule-based determination, i.e., it determines the winners (matched orders) of the market using the EM approach. Consider a particular P2P order \(X(p_{ij},t_{ij})\); then, using the EM, the winners will be determined as follows:  
\[X(p_{ij},t_{ij})= \begin{cases}X_{m}(p_{ij},t_{ij})&\text{if }B_{i,\Delta t_{i}} \geq A_{j,\Delta t_{i}}\\ X_{m}^{\prime}(p_{ij},t_{ij})&\text{if }B_{i,\Delta t_{i}}<A_{j,\Delta t_{i}}, \end{cases}  \tag{12}\]  
where \(X_{m}(p_{ij},t_{ij})\) are the matched P2P contracts, and \(X_{m}^{\prime}(p_{ij},t_{ij})\) refer to the unmatched orders such that \(X_{m}(p_{ij},t_{ij})\cap X_{m}^{\prime}(p_{ij},t_{ij})=\emptyset\). \(X_{m}(p_{ij},t_{ij})\cup X_{m}^{\prime}(p_{ij},t_{ij})=X_{T}(p_{ij},t_{ij})\) refer to the total P2P contracts for a given market interval \(\Delta t_{i}\). For order \(X(p_{ij},t_{ij})\in X_{m}^{\prime}(p_{ij},t_{ij})\), the quantities \(p_{ij},t_{ij}\) are given as follows:  
\[p_{ij},t_{ij}=0\quad\forall X(p_{ij},t_{ij})\in X_{m}^{\prime}(p_{ij},t_{ij}) \tag{13}\]  
The next step is to determine the optimal quantities \((p_{ij}^{*},t_{ij}^{*})\) for the matched contracts \(X_{m}(p_{ij},t_{ij})\) while considering the preference of the individuals. _Determination of \(p_{ij}^{*}\) and \(t_{ij}^{*}\)_: For the orders \(X(p_{ij},t_{ij})\in X_{m}(p_{ij},t_{ij})\), the quantities to find are the trading price \(p_{ij}\) and the trading quantity \(t_{ij}\). This research uses a single-leader-, multiple-follower-based Stackelberg game (SLMFSG) approach to find the optimal quantities for the matched orders, as suggested in [33]. In our proposed framework, the market operator acts as a leader, and the market participants are the followers of the game that make their decisions based on the actions of the leader. For each \(X(p_{ij},t_{ij})\in X_{m}(p_{ij},t_{ij})\), prosumer \(j\) computes the amount of power shared \(x_{j}\) based on the utility function \(U(x_{j})\) as follows:  
\[U(x_{j})=(p_{t}-A_{j})x_{j}-\alpha_{j}x_{j}^{2},\quad x_{j}\leq G_{j} \tag{14}\]  
where \(p_{t}\) is the market trading price, \(G_{j}\) is the excess renewable power, and \(\alpha_{j}\) is the reluctance parameter for the \(j\)th prosumer, respectively. The first part \((p_{t}-A_{j})x_{j}\) of the function \(U(x_{j})\) is the revenue that the prosumer receives from sharing \(x_{j}\) energy in the market. The reluctance term, \(\alpha_{j}x_{j}^{2}\), represents the negative impact on the utility of the prosumer \(j\), which measures the unwillingness of the prosumer \(j\) to share its power in the P2P market [33]. For the given market price \(p_{t}\) and the reluctance parameter \(\alpha_{j}\), the objective of the prosumer is to maximize its utility function as follows:  
\[\max_{x_{j}}\quad[(p_{t}-A_{j})x_{j}-\alpha_{j}x_{j}^{2}],\quad x_{j}\leq G_{j} \tag{15}\]  
In the SLMFSG approach, the leader (market operator) has no control over the decisions of the prosumers in solving its utility function. However, the operator sets the market price \(p_{t}\) to consider the savings of the customers participating with the prosumers in P2P trading. The aim of the market operator is to choose the \(p_{t}\) in such a way that it maximizes the cost savings of the customers, which are given as follows:  
\[Z_{i}=(B_{i}-p_{t})x_{j} \tag{16}\]  
where \(Z_{i}\) represents the savings of the \(i\)th customer. This forms an iterative process in which, at each iteration, the leader determines the market price \(p_{t}\) while considering the savings of the customer based on the amount of energy shared \(x_{j}\). The prosumer will compute \(x_{j}^{*}\) based on the \(p_{t}\) to maximize its utility function (note that the solution to the objective function given in Equation (15) can be found using \(x_{j}^{*}=\frac{p_{t}-A_{j}}{2\alpha_{j}}\)[33]) and sends the updated \(x_{j}\) to the operator for the next iteration. This process continues until Stackelberg equilibrium is achieved.