A Stochastic MPC Based Energy Management System for Simultaneous Participation in Continuous and Discrete Prosumer-to-Prosumer Energy Markets

: This article studies the exchange of self-produced renewable energy between prosumers (and with pure end consumers), through the discrete trading of energy packages and proposes a framework for optimizing this exchange. In order to mitigate the imbalances derived from discrepancies between production and consumption and their respective forecasts, the simultaneous continuous trading of instantaneous power quotas is proposed, giving rise to a time-ahead market running in parallel with a real-time one. An energy management system (EMS) based on stochastic model predictive control (SMPC) simultaneously determines the optimal bidding strategies for both markets, as well as the optimal utilisation of any energy storage system (ESS). Simulations carried out for a heterogeneous group of agents show that those with SMPC-EMS achieve savings of between 3% and 15% in their energy operation economic result. The proposed structures allows the peer-to-peer (P2P) energy trading between end users without ESS and constitute a viable alternative to avoid deviation penalties in secondary regulation markets. writing–original draft preparation, P.B.-G.; writing–review and editing, F.G.-T., M.A.R. and C.B.; visualization, P.B.-G. and F.G.-T.; supervision, M.A.R. and C.B.; project administration, M.A.R. and C.B.; funding acquisition, M.A.R. and C.B. All


Introduction
The growing presence of distributed energy resources (DER) makes more and more necessary a change in the classical conception of energy markets. By giving end users the possibility of producing their own energy, the figure of the prosumer appears as an additional role to the traditional ones of pure producer and consumer. According to the latest annual forecast report [1] of the International Energy Agency (IEA), energy from renewable sources will increase its penetration in the coming years, from 26% share of global generation in 2019 to 30% in 2024. To do so, the agency estimates that the renewable power installed worldwide will increase by 50% in that period. Moreover, it is expected that almost 30% of this increase will be covered by distributed solar photovoltaic (PV) generation, which implies the installation of between 300 and 400 GW (+250%) of additional power in the aforementioned five-year period. PV installations owned by individuals, communities or industries will represent an increasing percentage of the total installed distributed PV power. The availability of ownership data varies greatly between countries, but taking the example of Germany, which has one of the most developed renewable sectors in the world, it can be seen how in 2016 more than 42.5% of PV generation capacity was owned by private individuals or farmers, while only 15.7% was owned by standard power providers (the remaining being owned by industries, project planners or the business sector) [2].
While the primary objective of end users when installing DER is self-consumption, energy surpluses might become common as the efficiency of the consumption equipment and the productivity uncertainty. Furthermore, the existence of ESS on the seller's and buyer's side allows the transfer of energy ahead of consumption, extending market time, monetisation possibilities and the rate of renewable energy used.
Therefore, this paper proposes the coexistence of two parallel markets for residential eP2P trading. In the first one, already stored energy packages are matched with available storage capacity ahead of time, so that transfer breaches can not occur. In the second one, power quotas are negotiated in real time, tackling uncertainty through real time adaptation of transferred power. Those agents who do not have an ESS can still benefit from the time-ahead market and use the real-time market as a regulation mechanism in case of imbalances.
The remaining of the paper is organised as follows. The structures of the two markets are introduced in (Section 2). An energy management system (EMS) allowing simultaneous participation in both markets is presented in (Sections 3 and 5). Section 4 derives two control formulations that simultaneously optimize participation in each market, one being stochastic and the other deterministic. The two control structures are simulated on an example case (Section 6) to analyze their different effect on the operating result of the peers, which are discussed in Section 7.

Integrated Energy Packages and Power Quotas Markets
A double auction (DA) based market [21] is a trading institution in which both buyers and sellers can raise and modify their respective offers to buy (bids) and offers to sell (asks). In a discrete-time double auction (DDA), the change in allocation of goods or market clearing occurs at one or more fixed time instants between the start of the auction and the end of the trading period. Traders must place their bids and asks before each clearing instant, and both set of offers are used to determine the supply and demand staircases for commodities. The equilibrium point sets the (uniform) trading price, and thus the surpluses, for all the trades within that trading period.
In a continuous double auction (CDA), in contrast, buyers and sellers can individually choose to accept a bid or ask at any particular price (discriminatory price) at any point in time, and then update their allocation immediately.
In general, various forms of energy trading can coexist, associated with both continuous and discrete double auction structures. In our specific case, we propose the coexistence of a market for the trading of energy packages, based on a DDA, with another market for the trading of power quotas, based on a CDA.
The discrete market acts as a futures market. According to the Investopedia, a futures market is an auction market in which participants buy and sell commodity and futures contracts for delivery on a specified future date. Futures are exchange-traded derivatives contracts that lock in future delivery of a commodity or security at a price set at present time. Those agents who expect to have more consumption than generation, try to balance this expected deficit through the purchase of energy packages of adequate size in advance. Those agents who have a certain amount of stored energy, and who expect to have more generation than consumption, try to make the surplus profitable through the sale of energy packages. The EMS uses the power quota market as an alternative for continuous time compensation for possible errors in operational predictions. Even if energy packages have been purchased in advance to compensate for an expected deficit, an agent may find itself in an energy deficit situation if predictions fail (i.e., if its actual consumption is higher than expected, or if actual generation is lower than expected). Alternatively, those agents who did not expect to have a surplus can effectively experience it if their consumption is lower than expected or their production is higher than expected. In these cases, they can choose to store the surplus in their ESS, or sell it on the continuous market. In any case, it is assumed that all agents are individually rational (IR): deficit agents only buy in the P2P continuous market if the purchase price is lower than that offered by the energy retailer company; surplus agents only sell in the P2P continuous market if the sale price is higher than the utility they expect to obtain for the consumption of that energy in the future.

An EMS for Simultaneous Participation in Both Markets
The architecture of the proposed EMS is depicted in Figure 1. To enable simultaneous participation in both markets, while performing optimal power dispatch, the EMS needs to track the state of the entity. At any given time t, the entity's state, x(t) = {SOC(t) , BC(t) , SC(t)}, is defined by the state of charge of its ESS, SOC(t), and the buy commitment, BC(t), and sell commitment SC(t), previously acquired and not yet completely satisfied. An agent's state implicitly determines the amount of energy it can bid or ask for in the market.  The EMS might or not include an Strategy Advisor (SA), explained in Section 4, that performs optimisation at each t opt = τ k = k · ∆T DDA immediately prior to each discrete market session. Before such session opens for offers submission, the agent's EMS is assumed to have the following information:

•
The following N opening instants of the discrete market, {τ k+1 , . . . , τ k+N }, which are assumed to be evenly spaced over time according to a certain period of time, where N is the length of the prediction horizon, measured in number of intervals of the discrete market. In the case of agents whose permanence in the market is dynamic this implies that they know therefore the number of remaining sessions they have to negotiate, and the corresponding time period they would have to effectively inject/absorb the energy they manage to trade.

•
The market history up to a certain past horizon N h . This includes, for each past trading period k − i, i ∈ Z + , 1 ≤ i ≤ N h , the set of all individual bids and asks, Ω(τ k−i ) = {ϕ(τ k−i ) , ϑ(τ k−i } (each offer Ω is defined by a bid/asked quantity ϕ at a price ϑ) and their market result, M(τ k−i ) = {q(τ k−i ) , p(τ k−i )} (being q the quantity actually traded and p the price actually paid/received).

•
Forecasts of consumption profile ( P load (t)) and generation profile ( P gen (t)) along certain forecasting horizon (t ∈ Z : τ k ≤ t ≤ τ k + N f ). Generally, N f ≥ N h , i.e., the EMS uses a wider time range for calculating the foreseeable energy balance than the time range it uses to optimize its future actions in the markets.

•
The time profile of the price offered by the utility company (ϑ util (t)) along the prediction horizon (t ∈ Z : τ k ≤ t ≤ τ k + N · ∆T DDA ).

Energy Balance Forecasting
Since the time resolution of the consumption and generation forecasts is generally greater than the length of the interval between sessions, the EMS is in charge of carrying out the time aggregation to calculate the interval-wise energy gross result vector GR = {gr[i]}, where (please note that parentheses are used to refer to continuous time variables, while brackets denote discrete variables): Obviously, it must hold that N f ≥ N · ∆T DDA . The cumulative gross result, GR c , vector shows the same dimensions as GR, its elements being given by: Three additional forecast variables can be calculated using the cumulative gross result: where · + denotes max{0, ·} and · − denotes min{0, ·}. PD[τ k ] ∈ (−∞, 0] is the predicted deficit, which equals zero unless the sum of the buy commitments not yet received, (BC(τ k )), plus the aggregation of the gross result over the prediction horizon is negative. PS[τ k ] ∈ [0, ∞) is the predicted surplus, which equals zero unless the sum of the current level of energy stock, (B r (τ k ) − B min ), plus the aggregation of the gross result over the prediction horizon, minus the sell commitments not yet satisfied, (SC(τ k )), is positive. Finally, ES[τ k ] ∈ [0, 1) is the excess surplus which represents the portion of the expected surplus that exceeds the maximum energy stock storage capacity, (B max − B min ), and which therefore cannot be stored and would be unused if not sold.

Private Valuation
The trading agents of all entities have the same way of valuing power in the PQ-Market and energy in the EP-Market. However, the valuation is different for each of the two possible roles (buyer or seller). For the PQ-Market, the private valuation of the buyers is equivalent to the instantaneous price at which the distributor is pricing the energy at each moment, i.e., λ b p (t) = ϑ(t). This implies that (rational) buyers never buy P2P power above the distributor's price. On the other hand, sellers value power at 35% of the value offered by the distributor (this is an arbitrarily chosen percentage and can be replaced by any other. Different percentages could even be selected for each of the traders). This implies that the unit price of the sellers is, at most, 65% lower than the instantaneous price offered by the distributor.
For the EP-Market, each trader values the energy as the average cost of its future energy needs, predicted over a future horizon of duration N p .
whereq i (t + k) is the forecast electrical consumption of the i-th prosumer during the k-th future instant, andp i (t + k) is the utility electricity price for i-th prosumer during the same k-th future instant. However, valuation here also varies depending on the role adopted by the trader. Traders which forecast deficit (buyers) directly use the aforementioned value, which implies that a buyer will try to buy energy packages with unitary price below its average energy unit cost within the prediction horizon. Sellers, for their part, adjust their valuation depending on the excess surplus (5) they forecast, considering that rather than discarding the excess of generation over consumption that exceeds the storage capacity of the battery, it is better to lower its value to sell it albeit at a lower price: where ∈ (0, 1) is an arbitrary ratio indicating at what percentage of the average energy cost the surplus portion is valued. Table 1 summarises the private valuation for both markets and both roles. Table 1. Summary of private valuation of power (energy).

PQ-Market EP-Market
Buyer

Markets Forecasting
Knowing the historical of submitted offers and their corresponding market results, the EMS can compute the following statistical terms that constitute the model (see Figure 2) for the discrete double auction-based energy packages market: • The sequence of average buying and selling prices (or the average price for uniform pricing) for each past markets session, As each session corresponds to a specific time instant t = (k − i)∆T DDA , this is equivalent to calculating the time evolution of the average market spot price during the period covered by the previous N h sessions.
• Liquidity vectors, for both demand,

A Strategy Advisor Based on Model Predictive Control
The main objective of the Strategy Advisor is to meet the projected energy demand along the prediction horizon and to do so at the lowest possible cost. To this end, taking into account the existence and availability of the two markets, it generates an optimal dispatch plan that controls the energy flows for each of the sources that the entity has available. The vector of controllable variables Its components correspond to the following energy quantities: E util [i] is the amount of energy to be consumed from the utility during the i-th period; E ch [i] and E dis [i] respectively correspond to the amount of energy to be charged or discharged from the ESS during i-th period; ϕ b [i] is the amount of energy that the entity intends to buy at the i-th period, which will be bid in the market session held in t = τ i ; finally, ϕ a [i] is the amount of energy that the entity attempts to sell in the i-th period, which will be asked in the market session held in t = τ i . Therefore, the function corresponding to the cost of energy operation of the entity along a certain prediction horizon, N is: (8) where the tilde (˜) over a variable indicates it is a random variable. By multiplying the pricep EP by the buying liquidity complement (1 −˜ b ), the expected purchase prices of those market instants with low liquidity are artificially increased. Thus, during optimisation, agents acting as buyers will be more reluctant to plan their purchases at such market sessions. Alternatively, by multiplying the pricep EP by the selling liquidity˜ a , the expected selling prices of those market instants with low liquidity are artificially lowered. Thus, during optimisation, agents acting as sellers will be more reluctant to plan their sales at such market sessions.

The Expected Value Problem
The economic objective function in (8) extends over a prediction horizon. Therefore, its elements refer to the future values of its inputs, which are the controllable variables, and to the future values of the state of the system and its outputs, which would result from the application of those inputs. Optimisation also depends on the forecast profiles of consumption, generation and prices for the two existing markets. These values, as already mentioned, are stochastic and therefore subject to uncertainty. A possible simplification consists in disregarding information on the uncertainty, taking a nominal scenario, and optimizing actions on the nominal scenario. As the common practice for defining a nominal scenario is to replace random variables by their expectation, the resulting problem is called the expected value problem, the solution of which constitutes a nominal plan [22]. At the next decision stage, the Strategy Advisor will recompute the plan by solving an updated expected value problem on a new nominal scenario that incorporates the observations of the current stage.
In this sense, the following formulation is deterministic, as it is based on nominal consumption, production and price profiles, without taking into account the aforementioned uncertainties. Specifically, within the optimisation, the market-related random variablesp Since there is no a priori statistical information available on market uncertainty, the expectation of variables in future instants is replaced by the average value of those variables in past isotemporal sessions (market sessions held at the same time period of the day but in previous days).
Thus, the optimisation problem to be solved in each t = τ k is the cost minimisation of the energy operation of the entity, which is defined by the formulation (9)-(23): where κ e is the energy transfer capacity of the entity's converters (i.e., the maximum amount of energy that can be injected into/drained from the grid during a single period, and DOD max is the maximum allowable depth of discharge of the ESS. Please note that all variables are normalised with respect to the maximum storage capacity of the entity's ESS, so that both states and control inputs are expressed in units of batteries. Constraints (10) and (12) determine how the system evolves over time, while constraint (13) imposes that the expected load must be always meet, no matter which sources are used. The following assumptions has been considered in the controller as design criteria, which affect several constraints: A.1. Following the prudence concept, quantities sold on the market are immediately deducted from the SOC, even though the physical transfer has not even begun. This avoids the possibility of selling already committed energy. On the contrary, the acquired energy is not assumed as immediately incorporated, but is added over time. This prevents the optimiser from allocating energy that is expected to be acquired in a future instant but will not be available until a later future instant (constraint (10)). A.2. Once a purchase or sale agreement has been reached, the physical transfer of the energy associated with that transaction begins immediately and continues uninterruptedly until it is completed (constraints (11) and (12). In other words, transfers cannot be postponed. A.3. Own production is dedicated primarily to self-consumption. Therefore, } is not a controllable variable but a parameter computed on the basis of the forecast generation and consumption. A.4. Purchasing energy from the utility for later consumption is forbidden (constraint (18)). In other words, during periods of low tariff prices, the entity cannot acquire more energy than it needs from the utility in order to store it and consume it during periods of high tariffs. A.5. In the same market session, each entity can only play one role, either buyer or seller (constraint (20)). Given that transfers must be started immediately after they are settled, an entity with unsatisfied sales commitments cannot go to the market as a buyer (constraint (21)); conversely, as long as it has unsatisfied buy commitments, an entity cannot go to the market as a seller (constraint (22)). A.6. In the optimisation process, the strategic advisor assumes that future offers will be fully matched in the market (i.e., the optimiser assumes that q a . Immediately after the clearing of the k-th market session, the advisor already knows the real result of the offers shouted in that period. If the offers have not been matched, the available energy differs from that assumed in the optimal strategy profile, so it may be necessary to re-run the optimiser to adjust the values of E util [k], E ch [k] and E dis [k]. In any case, given that the optimiser is run before the next market session (for which the results of the immediately previous session are already available), the quantities actually offered, ϕ a * [k] and ϕ b * [k], are always the optimal ones based on the actual state at any given time.

Multiple Scenarios SMPC Approach (MS-SMPC)
From the point of view of each agent, both P2P markets are considered stochastic systems, since the outputs (m = (q, p)) for each one of the agent's offers might be different for the same inputs (ω = ϕ, ϑ)), depending on the offers made by the other participant agents, which are considered an unknown disturbance. Scenario-based optimisation provides an intuitive way to approach the solution to the problem of stochastic optimisation. The idea behind this approach is to compute an optimal finite-horizon input sequence that is feasible under N s sampled 'scenarios' of the uncertainty, thus obtaining a certain level of robustness [23]. One of the advantages of this approach is that it does not assume a prior knowledge of the statistical properties that characterise uncertainty (e.g., a certain probability distribution function) as is generally required in stochastic optimisation. Each scenario consists of values for some or all of the stochastic processes that affect the system. Furthermore, it has been widely used for performing optimal power dispatch (e.g., [24]) and for optimal participation in energy markets [25]. In our case, only the stochasticity of the P2P markets' prices is proposed to be addressed. Therefore, each scenario is a full horizon sample of the prices for the two markets, The offers that determine actual market parameters depend directly on the energy result expected by the different agents, which is given in turn by their consumption and generation forecasts. These predictions depend fundamentally on the climatology, and therefore present a significant level of correlation between consecutive days, as well as between identical days of previous years, provided that the typology of day (workable or weekend) is the same. Therefore, the approach proposed here to build the set of scenarios is to use the set of time series representing market realisations in past days (i.e., the evolution of the average prices and liquidities over similar periods of previous days). The Multiple Scenarios Stochastic MPC (MS-SMPC) problem then reads as follows:

The Power Dispatcher
After solving the MS-SMPC formulated by Equations (25)-(39), since a receding-horizon strategy is used, only the first member of the optimal finite-horizon policy is kept and applied to the system, i.e., the SMPC control law is

Role Selection
Role Selection for the PQ-Market is performed based on the balance between generated power (if available) and consumed power. Peers with surplus go to the PQ-Market as sellers trying to trade that surplus whenever the SOC of their storage system is greater than a certain level SOC min Mkt . If the SOC is lower than this level, the surplus is used to charge that storage. Deficit peers go to the market as buyers trying to wipe out that deficit. As for the EP-Market, two possibilities arise, depending on whether the trading agent of the entity's EMS implements an SA or not: Role selection in trading agents who have a strategic advisor is an inherent result of the strategic optimisation itself. If ϕ b * [1|τ k ] > 0 the entity will play buyer in the immediate market session. Conversely, if ϕ a * [1|τ k ] > 0 the entity will play seller in the immediate market session. As mentioned before, the amounts ϕ a * [k] or ϕ b * [k] implicitly determine the role that the entity will adopt in the imminent market session (remember that only one of them can be non-zero). If the offers are matched, the optimal plan is still valid; otherwise, the optimiser must be run again to resolve the MS-SMPC replacing ϕ a * [k] by q a * [k] and ϕ b * [k] by q b * [k].

Demand Satisfaction
In either case, the optimal control variables {E * util [k + ], E * ch [k + ], E * dis [k + ]} are sent as inputs to the power dispatcher (see Figure 1). The functions performed by this block are threefold: (i) to control the power flows to ensure that demand is met at all times, (ii) to maintain the state of charge of the Energy Storage System(s) within predefined safety levels, and (iii) to maximise, as far as possible, the profits obtained through the participation in the P2P market. Furthermore, those entities with Strategy Advisor use the continuous eP2P power quota market as a disturbance absorption mechanism, i.e., they go to this market only when the difference between the forecast consumption and generation profiles and the actual ones makes it impossible to operate following the optimal plan defined by the strategic advisor. Meanwhile, those entities whose EMS does not have the Strategy Advisor go to both the EP and the PQ Markets at any given time. In any case, the power demand satisfaction is driven at all times by Algorithm 1.

Algorithm 1 Demand Satisfaction Algorithm with Integrated
Maximum ESS charge/discharge power 9: Auxiliary 10: 11: 12: if Υ(t) > 0 ∧ SOC(t) < SOC max then 22: P sc (t) = P load (t) 23: 24: The optimal value of energy injected into the ESS has not yet been reached. Charge. 25: The optimal value of energy injected into the ESS has already been exceeded. Try to sell the surplus. 28: There is still room for discharge in this period. Drain the battery. 35: The ESS has already supplied all the energy planned for this period. Try to buy the deficit. Go to P2P PQ Market. q b PQ (t) and q a PQ (t) affect P P2P (t)

Description
In this case example the entities are a group H of 100 houses within the same neighbourhood in the city of Córdoba (Spain). Some of these houses (PV pen = 45%) are supposed to have photovoltaic (PV) generation systems. There are three possible installed PV powers, P phv ∈ {1, 3, 5} kWp, and each of them has an associated ESS of adequate capacity, B max ∈ {2.5, 5, 7} kWh respectively. Houses with no PV-installation still have an ESS of B max = 10 kWh to be able to participate in the EP-Market. Among the 100 houses, SA pen = 10% (10 Houses) are randomly selected which form the control set, H c . These houses are replicated twice, giving rise to three sets: The H ns and H s resulting sets (20 houses) are simulated together with the remaining H houses of the original population, which already include H c , giving rise to a total population of n H = 120 houses. All houses simultaneously participate in the two different markets. The first one is a PQ-Market similar to the one introduced in [20]. The second one is an hourly EP-Market. The main parameters of both markets are displayed in Table 2. The EMS of all houses incorporates two trading agents, one per each market. Table 2. Main parameters of integrated markets.

PQ-Market EP-Market
Type CDA DDA ∆T 1 min a 60 min q min 0.1 (kWmin) 0.25 (kWh) q max 3.3 (kWmin) 1 (kWh) a Equal to the temporal resolution of the energy operation simulation, thus mimicking a continuous market.

Scenario Generation
To generate the scenarios (price evolution and market liquidity profiles), a full month (30 days) of operation of 100 houses (all without Strategy Advisor) was simulated. These simulations assumed that each agent perfectly knows its generation and consumption profiles, obtained from [26], so that offers (and thus prices) reflect the real energy needs/excess of the traders within the simulated days. The results are shown in Figure 3. In a real application case, the equivalent of these scenarios obtained by simulation would be the historical data profiles obtained either from similar days in previous years or from the days immediately preceding the current operation day, or from a combination of both.

Operation Costs and Final Stock Valuation
In this case study, the net cost of energy for the i-th house over a certain period of time (T = [t i , t f ]) can be calculated as: being A i ω e (T) the amount of money corresponding to each energy package transaction ω e in the set Ω ep i of all eP2P transactions dealt by house i at the EP-Market within T, and A i ω p (T) the amount of money corresponding to each power quota transaction ω p in the set Ω pq i of all eP2P transactions dealt by house i at the PQ-Market within T: where q ω is the traded quantity and p ω is the unit price of the agreed transaction. Equation (41) is the sum of the cost of energy purchased from the utility (42), plus the revenue of energy compensated by the utility at a price equal to the Voluntary Price for the Small Consumer (VPSC), ϑ c , (43), plus the result of trading in the EP-Market (44), plus the result of trading in the PQ-Market (45). A Net Purchase and Sell Scheme (NPSS) is followed here to calculate the amount of compensated energy. Under this arrangement, two uni-directional meters are installed: one records electricity drawn from the grid, and the other records excess electricity generated and fed back into the grid. Prosumers pay retail rate for the electricity they use, and the DSO purchases their excess generation at its avoided cost (wholesale rate), up to the amount of consumed energy, so that prosumers may have zero energy cost with respect to the utility, but no positive balance. By convention, costs have a negative sign, while revenues have a positive sign. In addition, and although it is not directly part of the operating result, a way of computing the value of the energy stored at the end of the operating period in the ESS of each house is necessary: where t f is the final instant of the period of comparison and λ i (t f ) is the private valuation of energy for house i in t = t f according to (6).

Comparative Indicators
The comparison is then made between the energy operation results of H c and those of H ns and H s . The following indicators can be computed to compare the operation performance of two sets of houses (H a and H b ) (Energy Result Comparator, EP-Market Result Comparator, PQ-Market Result Comparator, Renewable Energy Use Comparator and Battery Usage Comparator) and are defined below:

Tests and Results
Testing the effects of the MS-SMPC-based Strategy Advisor is a complicated task. First, because the number of optimisation variables grows very fast as the length of the prediction horizon is increased. In turn, the more optimisation variables the problem has, the number N S of different scenarios needed to reach a certain level of confidence also increases [27].
Additionally, since the experiments are basically agent-based simulations, it is difficult to guarantee common conditions for entities with/without (non-)stochastic Strategy Advisor. For each element h c ∈ H c , two identical reproductions are created, h ns ∈ H ns and h s ∈ H s . These three elements have exactly the same consumption and generation profiles, and in addition, the parameters of their respective agents are also identical, including those that drive price adaptation and private valuation determination. Therefore, the price evolution of bids and asks is the same for the three entities. What changes between them, and in fact is the origin of the performance variability, is the sequence of roles adopted in the market. Entities in H c adopt one or another role in an obtuse manner, without considering the plausible evolution of the market. In contrast, the objective of the Strategy Advisor is to steer the role selection and the temporal allocation of offered energy quantities so that the entity takes advantage of those hourly sessions with the highest expected revenue.
Each simulation covers a whole week of energy operation during the month of September. To check whether in the presence of uncertainty the stochastic strategy advisor is capable of obtaining better results than the one based on the nominal scenario, it is necessary to simulate prediction errors. For this, the agents are simulated using the real generation profile, while their forecast profile is randomly picked among the pool of daily generation profiles corresponding to the 30 days of September. Figure 4 shows the forecast and actual PhV power generation profiles for each week, in which it can be seen how both accurate and imprecise forecasting are artificially simulated.   Tables 3-9 show the results of the simulations for each of the addends that allow to compute the economic result derived from the energy operation (Equations (41) and (47)) of the three replicated sets.           )util Finally, Table 10 shows the comparative indicators with respect to the performance of the set of houses without SA (H c )) for the set of houses with Nominal MPC-based SA (H ns ) and for the set of houses with MS-SMPC-based SA (H s ).

Discussion
This article proposes the simultaneous participation of energy traders in two energy markets which run in parallel while being executed simultaneously. The discrete EP-Market acts as a futures market, allowing traders to purchase/sell energy packages in advance of the occurrence of a forecast deficit. The continuous PQ-Market acts as a spot market, in which power quotas are negotiated to balance deficits and excesses instantly. To allow this simultaneous participation, a specifically designed EMS is required to allow the automation of the procedures for determining private valuation, price adaptation and role selection for each of the two markets. Entities with an excess of energy generation act as sellers, and have the option of either selling as much as they can as soon as possible (in the immediately following market moments) or offering the aforementioned excess at certain future market moments where the price obtained is historically more advantageous. They must also decide on the quantities to be offered in the discrete market, taking into account that the stock sold in the time-ahead market is no longer available for sale in the real-time market. On the other hand, entities that foresee having an energy deficit (those whose expected consumption is greater than their foreseen generation) have to decide whether to try to anticipating it by obtaining energy packages in the discrete market, which is generally more expensive but less volatile, or to risk trying to cancel their deficit in the continuous market of power quotas, which is generally cheaper but less liquid. In this sense, the proposed EMS can incorporate the strategy advice functionality, consisting on the determination of the optimal energy operation profile and encompasses the storage utilisation, the energy acquisition from the power grid and the interactions foreseen in the two eP2P markets. This article proposes a possible implementation of this Strategy Advisor, based on MPC, including two variants, one based on a single nominal scenario, and the other based on SMPC, which optimises contemplating multiple scenarios. Simulations carried out on the case study show that both variants offer an improvement in economic performance of between 10% and 30% compared to the case of not using a SA. Furthermore, the MS-SMPC-based variant generally performs slightly better than the nominal variant, as it contemplates more possible market price evolution profiles (derived from different PV generation scenarios), although to state this conclusively it would be necessary to make a deeper statistical analysis which is beyond the scope of this article. These savings are mainly achieved by buying less energy from the grid and replacing it with cheaper energy, either previously bought and stored or bought instantaneously; and by selling a greater portion of the surplus energy in market sessions where the price is higher. But it's not all advantages. This improvement is also achieved through an intensification of the use of storage systems, which could lead to a reduction in their lifespan. The translation of depreciation costs into the calculation of energy operating costs is an open issue, both in terms of the selection of the usage level indicator and in terms of the monetisation of such usage.

Conflicts of Interest:
The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript, or in the decision to publish the results.

Abbreviations
The following abbreviations are used in this manuscript: