Stochastic Bilevel Program for Optimal Coordinated Energy Trading of an EV Aggregator

Gradually replacing fossil-fueled vehicles in the transport sector with Electric Vehicles (EVs) may help ensure a sustainable future. With regard to the charging electric load of EVs, optimal scheduling of EV batteries, controlled by an aggregating agent, may provide flexibility and increase system efficiency. This work proposes a stochastic bilevel optimization problem based on the Stackelberg game to create price incentives that generate optimal trading plans for an EV aggregator in day-ahead, intra-day and real-time markets. The upper level represents the profit maximizer EV aggregator who participates in three sequential markets and is called a Stackelberg leader, while the second level represents the EV owner who aims at minimizing the EV charging cost, and who is called a Stackelberg follower. This formulation determines endogenously the profit-maximizing price levels constraint by cost-minimizing EV charging plans. To solve the proposed stochastic bilevel program, the second level is replaced by its optimality conditions. The strong duality theorem is deployed to substitute the complementary slackness condition. The final model is a stochastic convex problem which can be solved efficiently to determine the global optimality. Illustrative results are reported based on a small case with two vehicles. The numerical results rely on applying the proposed methodology to a large scale fleet of 100, 500, 1000 vehicles, which provides insights into the computational tractability of the current formulation.


Introduction
To ensure a sustainable and decarbonized future, the number of electric vehicles (EVs) is increasing steadily in the transport sector. Global EV penetration is estimated to grow up to 20 million units by 2020 [1]. This increase is expected to continue since several countries are developing supporting regulatory schemes that make EVs more attractive for potential buyers.
On the other hand, the EU is setting targets to significantly reduce greenhouse gas emissions by 2050 [2]. To accomplish this goals, the share of renewable energy sources must increase significantly. Challenges related to maintaining a high security of supply have increased with the increasing share of intermittent renewable electricity generation.
Distributed Energy Resources (DER), such as automic loads (AL), electric vehicles (EVs), thermostatically controlled loads (TCLs) could assist cost-optimal integration of renewable energy sources (RES) that offer flexibility. The possible gain from the DER integration on the whole system is investigated in detail in [3][4][5]. The potential benefits are also acknowledged by the European Commission, which in turn updates the legislation that encourages market operators to open electricity markets for DER units.
In particular, depending on their charging plans, EVs can potentially assist efficient and secure functioning of the power system. To enable the access of this type of small-scale flexibility to a large Even though in an EV aggregation context, where a stochastic bilevel optimization approach is taken in which different players act strategically to reach equilibrium was proposed in [21], the application of this kind of approach to trade energy in three sequential day-ahead, intra-day and real-time markets has not been explored. This paper proposes a stochastic bi-level optimization framework based on the Stackelberg game for an EV aggregator to prepare profit optimal retail price incentives to attract more end users to support the secure operation of the power grid relying on EVs optimal charging plans. The aggregator trades in day-ahead, intra-day and real-time markets. This formulation determines endogenously the profit-maximizing retail price levels constraint by cost-minimizing EV charging plans.
The contributions of the paper are threefold: • The development of a stochastic bi-level optimization framework based on the Stackelberg game for an aggregator who operates many batteries (stationary and EVs) and trades electric power in three markets. The model addresses carefully the lack of certainty in market prices and fleet characteristics as well as accounts for the existing market rules. This model enables market trading regardless of (1) generation or consumption technology and (2) mobile or immobile battery unit.

•
The extraction of optimal trading quantities for three-settlement markets with reasonable calculation time by employing a proper scenario-reduction technique.

•
The uncertainty modeling in all three market prices as well as EV mobility parameters.
The next sections of the paper are organized in the following manner: Section 2 outlines the problem statement, describes the proposed stochastic bilevel formulation of an aggregator based on the Stackelberg game and derives a stochastic one-level problem by replacing the lower level problem with its optimality conditions. Section 3 discusses the results from the studied cases and Section 4 concludes the paper.

Problem Statement and Methodology
First, a short description of the underlying market places is provided. Then, the decision process framework is presented. Finally, the involved uncertainties are characterized.

Market Places
Liberalized electricity markets, irrespective of geographic location, are multi-settlement structured and usually include a day-ahead market, an intra-day market and a real-time market. Unpredictable events can be balanced in the intra-day or the real-time markets. In a day-ahead market, players trade electric power with hourly increments the day before, for energy delivery of the following day. In this market, hourly demand and supply bids for the next 24 hours are submitted at once before the gate closure. In the Nordic power system, the day-ahead market gate closes at noon the day before the delivery day (see Figure 1). For day-ahead markets, gate-closure time might vary slightly in different markets. After the closure of the day-ahead market, for every hour aggregated demand and supply curves are built. The intersection point of those curves defines the day-ahead market prices and traded volumes; in other words the day-ahead market clearing takes place. In the Nordic power system, the day-ahead market clears at 3 p.m. Again, the market clearing time might vary a little in different power systems.
Intra-day markets are open directly after the clearing process of the day-ahead market. In contrast, intra-day markets are continuous and the gate closure takes place shortly before the actual delivery of that hour (in the Nordic system this is one hour before the delivery).
Similar to an intra-day market, in a real-time market the gate closes very close to the actual delivery time step (in the Nordic market the real-time market closes 45 min before the delivery). However, the real-time market is open two weeks before the delivery hour. Both producers and consumers submit upwards and downwards bids for a specific hour indicating prices and volumes. Then, system operator clears the real-time market based on the received information.  As an aggregator of a flexible power source, the EV aggregator faces the need for making optimal decisions based on uncertain data. Thus, the multilevel stochastic programming tool is appropriate in this circumstance.

Decision Process Framework
The decision making process is expressed by providing a brief description of the involved actors (an EV aggregator and end users) together with their aims, as well as the interaction between the actors through the well-known Stackelberg game.

End Users: Consumers
An EV owner aims at recharging their vehicle at the lowest possible cost. This means that EV owners are motivated to choose the most competitive aggregator from whom to buy the energy volume they need.

Aggregators
The usual decision-making mechanism of an EV aggregator shares some of the common characteristics of the decision-making skeleton of a typical consumer/retailer. On the one hand, the EV aggregator competes with other market players for electricity purchase at the least possible cost and for ancillary service provision in a profit-optimal way. On the other hand, the aggregator competes against other aggregators or retailers who provide similar services in an attempt to attract more end users.
The aggregator aims at maximizing its operating profit. In this context, such an agent determines its optimal involvement in different sequentially cleared market floors like day-ahead, intra-day and real-time markets, while offering competitive incentive prices for the end users. The aggregator's revenue is based on the consumption volume of the EV owners and the offered retail price. However, the aggregator's cost depends on the cleared prices of the day-ahead, intra-day and real-time markets. These prices are uncertain and are determined exogenously. Thus, it is assumed that the EV aggregator is a price taker and does not have marker power when participating in the above-mentioned markets.

Interaction between the Agents: Stackelberg Game
A bilevel optimization framework is suggested for an EV aggregator to construct retail price incentives for its EV owners. The aggregator (the Stackelberg game leader) determines its position in day-ahead, intra-day and real-time markets and defines non-flat price incentives for EV owners (the Stackelberg game followers) taking into consideration expected market outcomes and EV charging patterns.
A bilevel decision making mechanism of an EV aggregator in interaction with EV owners is illustrated in Figure 2. The upper level (UL) formulates the EV aggregator's challenge of maximizing revenues from retail, while the lower level (LL) develops the end users (EV owner) problem, where the EV owner aims at minimizing the charging cost subject to the technical constraints as well as EV availability patterns. In addition, Figure 2 shows the information exchange between UL and LL problems. Accordingly, the UL sends retail price signals to the LL. Consequently, based on the price signals it receives, the LL determines the cost optimal charging plans, which are then submitted to the UL problem.
The uncertainties related to the aggregator's expectations for day-ahead, intra-day, real-time market price outcomes as well as EV availability patterns are represented through a scenario-based stochastic programming tool.

Methodology for Generation and Reduction of Market Price Scenarios
Modeling and prediction of electricity market prices are complicated due to its complex structure. There is a dynamic dependency among three sequential markets, which complexifies the forecasting process even further. A huge amount of work has been done in the field of modeling and forecasting of day-ahead market prices [23,24]. Despite this, the existent literature on intra-day and real-time price modeling and forecasting is very sparse [25][26][27]. The Markov-based HW model for modeling and predicting the day-ahead, intra-day and real-time prices is presented below. According to reference [28], the Markov-based HW model is one of the best performing predicting tool for electricity market prices. The suggested model is described in the following steps.
Step I: The HW Model Parameters' Estimation The references [29,30] present the general description of the HW model for a time series with a unique seasonal pattern. The HW model is employed to predict the electricity load and imbalance cost in [31,32]. The typical HW model for a time series of prices {λ t } T t=1 is as follows [33]: whereγ t is the exponential element, T t is the trend and I t is the seasonal element with period Ξ. α, β, and σ ∈ [0,1] are smoothing parameters.λ t (h) is the h-hour forward prediction.
Step II: The transition probability matrix estimation of the Markov model for different states of real-time market prices The forecasting process of the day-ahead market prices includes the estimation of the price magnitude for the entire prediction period. In contrast to day-ahead market prices, both intra-day and real-time market prices, in addition to the price magnitude, also have a discrete mode. This implies that the price states for the intra-day and real-time markets need to be forecasted as well. The magnitude of day-ahead, intra-day and real-time electricity prices can be estimated using the HW forecasting tool. We describe the forecasting process of the price states for the real-time market. Because the forecasting process for intra-day market price states is very similar to that of real-time market, we do not include a detailed description here.
The real-time market prices may have one of the following four states in each bidding interval t:  o t is a parameter, which defines the state of the real-time price at period t as in (6).
As stated above, the state of intra-day market prices can also be modeled using a four-state Markov process. The intra-day market price series can be used for that purpose.
Step III: The scenario generation and reduction procedures for day-ahead, intra-day and real-time market prices The day-ahead market price magnitude is predicted using the historical prices with the hourly resolution reported in [34] and applying the prediction technique explained in step I. Afterwards, the day-ahead market price scenarios are produced (1) using the expected values and the variances of day-ahead market prices and (2) assuming normal distribution.
As explained in step II, both price magnitude and market state have to be predicted for intra-day and real-time markets. Historical price time series are needed for this purpose. Analogous to day-ahead market prices, the real-time market hourly price series is available from the Nord Pool website [34]. In contrast, intra-day market prices are not available on the Nord Pool website. Therefore, we contacted Nord Pool to obtain the intra-day market .csv excel files containing intra-day market trading activities. The preprocessing of the intra-day market .csv excel data resulted in the desired hourly price series. More precisely, this data was preprocessed in the following way: (1) the data was grouped as buying and selling trading within each hour, (2) then a buying and selling price series with an hourly resolution was designed taking the average of all buying and all selling trading prices within each hour correspondingly.
To predict intra-day and real-time price magnitude, the forecasting tool in step I is employed. The price direction for both intra-day and real-time markets was grasped applying the Markov model provided in step II. The intra-day and real-time market price scenarios were produced based on the forecasted price magnitude, direction and assuming normal distribution. Several scenarios have been generated to capture accurately the probabilistic information on random prices. Then the initial number of scenarios was diminished carefully, while preserving the probability information at most. The optimal scenario reduction problem can be expressed as in (8) and (9), [35].

Availability Simulation
To address the uncertain driving behavior, we need to produce mobility scenarios. A Monte Carlo simulation tool is used in that regard. The following probability measures are considered to derive discrete cumulative distribution functions (cdf), which is employed to generate mobility scenarios; • the probability of travel on a specific day, • the probability that a trip starts in a specific hour, • the probability that a trip covers a certain distance.
Mutually independent distributions are assumed as in [7].

Upper-Level: EV Aggregator as a Stackelberg Game Leader
The stochastic optimization problem stated in (10) maximizes the scenario-weighted expected profits from day-ahead energy trading, intra-day and real-time power exchange. Hourly resolution is assumed for all three market places.
Max. z UL = φ UL (γ RT s,t , p da t , p buy s,t , p sell s,t , p dn s,t , p up s,t ) = where the expected profit of the aggregator E[Π(s, can be calculated as in (11). The first term in (11) The objective function in (10) is subject to the power balance constraint expressed in (12). Equation (12) ensures that power bought in day-ahead, intra-day and real-time markets fulfill the need for all individual charging.
In addition, the EV aggregator defines hourly price incentives for EV owners as in (13), where λ s,t is calculated as the average of day-ahead, intra-day and real-time market prices and n[e/kWh] is a constant margin.

Lower-Level: EV Owners as Stackelberg Game Followers
On the lower level the potential customers aim at optimizing their charging schedule at the lowest cost possible (14).
The state of charge balance constraint can be modeled as: ∀s, k, t : h 1 = SoC s,k,t − SoC s,k,t−1 − p RTch s,k,t η ch k A s,k,t + D s,k,t η dr The new battery content for each trading period is calculated considering its previous content, energy inflow and energy outflow. This thought is stated in (15). Both mobile and immobile batteries can be modeled using Equation (15). This implies that, for immobile batteries, A s,k,t availability matrix is always 1. For EVs, the availability matrix is either 0 or 1 depending on whether the EV is available or on a trip. The battery level is bounded by its minimum and maximum levels (16) and (17). ∀s, k, t : g 1 = SoC s,k,t ≤ E k ; [µ g 1 s,k,t ] (16) ∀s, k, t : Charging activities in the periods of unavailability is prevented by the constraints (18) and (19). Finally, the constraint (20) and (21) The dual variables for equalities h and inequalities g are denoted ψ h and µ g correspondingly and are written next to the respective constraint.
The stochastic bi-level problem for developing profit-maximizing price levels while trading in day-ahead, intra-day and real-time markets for an EV aggregator is defined by: γ RT s,t = λ s,t + n; ∀s, t ∀s, k, t : ∀s, k, t : ∀s, k, t : where φ UL = {γ RT s,t , p da t , p buy s,t , p sell s,t , p dn s,t , p up s,t } is the set of decision variables for the upper level problem and φ UL = {p RTch s,k,t , SoC s,k,t , e NS s,k } is the set of decision variables for the lower level problem.

The Stochastic Convex Reformulation of the Bilevel Program
The LL optimization problem stated in (25)-(32) is a linear program, thus convex. Therefore, it can be replaced by its KKT optimality conditions, which are both necessary and sufficient. To this end, the LL problem KKT conditions can be directly included as constraints for the UL problem stated in (22)- (24). The bilevel problem is thus presented by its MPEC formulation: UL problem (22)-(24), LL constraints (26)-(32), KKT stationary equations and complementary slackness constraints (the complementary slackness constraints are derived in Appendix A.2).
The first order stationary conditions are derived by building the Lagrangian function of the LL problem and taking partial derivative of it with respect to the primal variables (33). The Lagrange function is derived in Appendix A.1.
The complementary slackness constraints {g 1 . . . g 6 } ⊥ {µ s,k,t } cause non-linearity. To avoid non-linearity resulting from the complementary slackness constraints, this formulation uses the strong duality condition [36] as derived in (34). With this last transformation equivalent one-level convex formulation is achieved. Hence, a global optimal solution can be reached.

Illustrative Small Study
Day-ahead, intra-day and real-time market price scenarios were generated following the methodology described in Section 2.3. Accordingly, the day-ahead and real-time hourly price series were taken from the Nordic electricity market website [34]. The .csv excel files, that hold the information about intra-day market trading activities were obtained from Nord Pool. The EV driving patterns were based on the reference [37]. Table 1 summarizes the input parameters used for the small-scale study.  20 28 kWh

Solution Tractability
To ensure the computational tractability of the stochastic models (1) the underlying probability distribution was approximated by a discrete probability measure and (2)the number of scenarios were reduced as accurately as possible.
Market price scenarios were generated with the proposed Markov-based HW model. Then, the number of price scenarios were reduced using a backward reduction algorithm [35] aiming to maintain the statistical information in prices to the extent possible. EV driving patterns were produced employing a Monte Carlo simulation tool. All mentioned proposed models (Markov-based HW model, scenario backward reduction technique and the Monte Carlo simulation tool) were coded in Matlab.
The preserved price scenarios together with the average for day-ahead market places are depicted in Figure 3. Price scenarios for intra-day market and real-time market are drawn in Figures 4 and 5,  Figures 6 and 7 respectively.     In addition to the 30 preserved market price scenarios, 30 equally probable mobility scenarios were produced using the Monte Carlo simulation tool. These preserved price scenarios together with mobility scenarios were used to estimate the optimal trading volumes of the EV aggregator and optimal charging schedules for the EV owners.

Results with a Variable Retail Price Margin
Solving the problem with the input data provided in Table 2, price scenarios illustrated in Figures 3-7 and mobility scenarios mentioned above, results in (for selected scenarios) EV hourly charging plans and state of charge levels depicted in Figure 8. For this simulation the constant retail price margin is selected n = e2/MWh and γ NS s,t = e 55. With this retail price margin, the LL for both EVs and scenario 1 cost-optimally consumes at hour 4 and 24. The LL consumers for scenario 3 and EV1 consumes at hours 1-3, hour 5, hour 21 and 24. However, for scenario 3 and EV2 consumes at hours 3, hour 5, hour 21 and 24. It is obvious from Figure 8 that state of charge level for each car changes depending on whether the car is available or on a trip. The UL and LL problems' economics for different retail price margin are summarized in Table 2. According to Table 2 it is profit-optimal for the aggregator to set the retail price margin of n = e4/MWh. With this retail price margin the EV owners are still satisfied and the profit of UL problem (the aggregator's profit) is the highest. A slight increase in the retail price margin leads some of the end customers to shift to another energy source (see Table 2). The volatility of market prices in day-ahead, intra-day and real-time markets is increasing due to the significant rise of varying renewable energy sources in the power system. The developed methodology of this paper allows us to investigate the impact of increased volatility of market prices on the aggregator's decisions while trading energy in those market places. In that respect, the developed model is simulated with more volatile electricity market prices. More volatile market price scenarios are obtained keeping the same market price mean and doubling the standard deviation. Table 3 sets out resulted energy tradings under base and volatile market prices. Table 3 illustrates that a significant share of intermittent wind and solar power sources in the power system leads to market prices with higher volatility, resulting in increased energy trading in intra-day and real-time markets. In addition, with a flexible energy source, an EV aggregator can sharply increase its profit using intra-day and real-time markets for correcting actions. To investigate the economic gain the aggragator receives from coordinated trading, the UL problem economics under the four different cases were observed: case (1) trading considered only day-ahead market, case (2) coordinated trading under two day-ahead and intra-day markets, case (3) coordinated trading under two day-ahead and real-time markets, case (4) coordinated trading under three day-ahead, intra-day and real-time markets. The simulation results of all four cases are presented in Table 4. Table 4 clearly shows that under coordinated trading, the EV aggregator has more generous strategies to maximize its profit. The EV aggregator's economic gain is the highest in case 4, where all three markets are considered for the energy trading.

Numerical Study Using Large Fleet of EVs
For the large-scale cases the following parameters for EV batteries are considered. The EV driving patterns follows [37]. The maximum capacity of the battery is 50 KWh like in [37]. The battery level should be at least 20 % and at most 100 % of the maximum capacity [38]. The charging power rate is assumed to be 6 kW. Finally, as in [39], the charging efficiency is stated to 90 %. Both stating and targeting state of charge battery levels are fixed at 60 % of the maximum capacity.

Computational Characteristics
To check the computational burden the suggested stochastic bilevel model was simulated while increasing the number of EVs. The model statistics with the computation time are reported in Table 5. In addition, the solution time as a function of the number of EVs engaged in the simulation is drawn in Figure 9. Figure 9 shows that the model solution time increases exponentially, when the number of EVs increases. Moreover, the simulation of the stochastic bilevel model with 1000 EVs (nearly 5 million variables and constraints, 14 million non-zero elements) requires about 843,594 iterations and 98,371 s, which is >24 h Table 5. This clearly shows that a decomposition technique is required to make the suggested model applicable for big cases, like aggregating 1000 s of EVs or more. Benders decomposition could be a good choice.

Conclusions
This paper studies the interaction between EV aggregator and EV owner, aiming to maximize the aggregator's profit and to provide EV owners with the most cost-optimal charging method. We develop a stochastic bilevel program based on the Stackelberg game to optimize the EV aggregator's decisions. The model allows us to determine endogenously the profit-optimal price incentives, which in turn generates the cost-optimal charging schedules of the final customers. By incorporating strong duality theorem the bilevel model is transformed to a single level convex mathematical program.
The work creates solid ground to analyze the strategic interaction in a leader-follower game highlighting that aggregators with solid knowledge of the physical features of local EVs' can behave strategically to increase their profit. Using the developed formulation, the optimal energy economics are achieved for both aggregator on the upper level and EV owners on the lower level in both small and large case studies. The study results show how uncertainties related to market prices and fleet characteristics influence the EV charging plans. In addition, we show how the aggregator selects the optimal retail price margin to keep its customers satisfied. Moreover, the results indicate an economic gain is achieved from coordinated planning when the aggregator trades energy in three day-ahead, intra-day and real-time markets. Large-scale study simulation results indicate that, in order to make the model computationally tractable and applicable for big cases (more than 1000 EVs), a decomposition is required. The developed methodology may be directly included in the everyday scheduling activities of the EV aggregators or retailers. Alternatively, the model might be useful for stakeholders and policy makers to assess the overall added value by coupling the power and transport sectors. This work can be extended by applying a suitable decomposition technique. The complementary slackness constraints of problem (25)-(32) are : s,k,t ⊥ (A s,k,t P k − p RTch s,k,t ) ≥ 0 (A4) s,k,t ⊥ p RTch s,k,t ≥ 0 (A5) 0 ≤ µ g 5 s,k ⊥ (SoC s,k,T + e NS s,k − SoC end k ) ≥ 0 (A6) 0 ≤ µ g 6 s,k ⊥ e NS s,k ≥ 0 (A7)