Hêmin Golpîra

P Sheikhahmadi

Salah Bahramara
email: s_bahramara@yahoo.com

Bruno Francois

Risk Management Model for Simultaneous participation of a Distribution Company in Day-ahead and Real-time Markets

Keywords: Active distribution networks, Bi-level approach, Day-ahead and Real-time markets, Karush-Kuhn-Tucker, Risk management

In Active Distribution Networks (ADNs), Distribution Company (Disco) follows two main strategies of dispatching of Distributed Energy Resources (DERs) and trading energy with wholesale energy markets, including Day-Ahead (DA) and Real-Time (RT) markets, to meet the demand. An attempt is made in this paper to model the strategic behavior of the Disco, in the wholesale DA and RT energy markets, through a bi-level optimization approach. While the objective of the upper-level problem is to minimize the expected cost of the Disco, the lower-level problem (with two optimization problems) formulates to simultaneously maximize the socialwelfare of the DA market and minimize the cost of the RT market. Furthermore, uncertain behavior of renewable energy sources as well as demand is tackled into the problem formulation. To this end, Disco decision-making represents as a risk-based two-stage stochastic problem where the Disco's risk aversion is modeled using conditional value at risk (CVaR) method. Generally stated, the proposed model is a non-linear bi-level problem which may be transformed into a non-linear but single-level problem through Karush-Kuhn-Tucker (KKT) conditions and dual theory. Detailed numerical results on a 6-bus and RTS 24-bus power systems are used to demonstrate efficiency of the proposed model. Moreover, sensitivity analysis is carried out to investigate the effect of riskaversion parameter on the decision making of the Disco and the offers/bids in both the DA and RT markets.

Introduction

A. Motivation and aim

Low energy efficiency of conventional generation and transmission systems besides environmental issues cause many power system industries to set an ambitious target of Distributed Energy Resources (DERs) [START_REF] Lasseter | Smart Distribution: Coupled Microgrids[END_REF]. DERs can be managed by aggregators or be operated by Distribution Companies (Discos). Therefore, decision making procedure, in Active Distribution Networks (ADNs), faces restructuring in such a way that the Disco may trade energy with DERs aggregators and participate in the wholesale markets [START_REF] Bahramara | Modelling hierarchical decision making framework for operation of active distribution grids[END_REF]. In this way, Independent System Operator (ISO) clears the market based on the accrued energy transactions in the Day-Ahead (DA) market, where there are various decision-makers including Discos, generation companies (Gencos) [START_REF] Soleymani | New approach to bidding strategies of generating companies in day ahead energy market[END_REF], wind power producers (WPPs) [START_REF] Sharma | Strategic bidding for wind power producers in electricity markets[END_REF], large consumers, and aggregators. On the other hand, the aforementioned decision-makers need to participate in realtime (RT) market to serve demand with minimum cost.

The players' operation problems involve uncertainties due to uncertain behavior of the power resources and demands. Therefore, some considerations should be made regarding energy balance in both the DA and RT markets.

Not only Disco needs to participate in the DA market, but also should participate in the RT market to deal with the uncertain behavior of Renewable Energy Sources (RESs) and demand.

Therefore, development of a comprehensive framework of energy management process seems necessary to facilitate modelling of the Disco behavior in both the DA and RT markets. In such framework, uncertain behavior of the RESs and demand should be modelled using an appropriate risk management index. In this paper an attempt is made to model the decisionmaking problem of a Disco, considering uncertain behavior of RESs and demand, in both DA and RT energy markets. SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION

B. Literature review and contributions

The decision-making framework of a Disco, as a price-taker player in wholesale market, has been modeled from different points of view. Interaction between the Disco and microgrids (MGs) is modeled using the system of system approach in [START_REF] Marvasti | Optimal Operation of Active Distribution Grids: A System of Systems Framework[END_REF]. The model is deterministic and thus does not take account of demand uncertainty. In [START_REF] Palma-Behnke | A distribution company energy acquisition market model with integration of distributed generation and load curtailment options[END_REF], operation problem of a Disco in DA market is formulated to determine the decision variables of interest including, power exchange with the DA market, the output power of Distributed Generators (DGs), and the amount of interruptible loads (ILs). A bi-level approach, which considers the profit of a Disco and the operation cost of MGs as the Upper Level (UL) and Lower Level (LL) problems, is introduced in [START_REF] Bahramara | A bi-level optimization model for operation of distribution networks with micro-grids[END_REF]. In [START_REF] Rider | Bilevel approach for optimal location and contract pricing of distributed generation in radial distribution systems using mixed-integer linear programming[END_REF], interactions between a Disco and DERs are modeled through a bi-level optimization approach in which the contract prices of the DERs are determined in the UL problem and the operation cost of the Disco is minimized in the LL problem. In [START_REF] Bagher Sadati | Risk-Based Bi-Level Model for Simultaneous Profit Maximization of a Smart Distribution Company and Electric Vehicle Parking Lot Owner[END_REF], the operation problem of a Disco in presence of Electric Vehicles (EVs) aggregators is modeled as a risk-based bi-level optimization problem in which the profits of the Disco and EVs aggregators are maximized in the UL and LL problems, respectively. In [START_REF] Xiang | Optimal active distribution system management considering aggregated plug-in electric vehicles[END_REF], a metaheuristicbased approach is proposed to deal with the probabilistic operation of a Disco in presence of EVs aggregators and RESs. In [START_REF] Iria | Optimal bidding strategy for an aggregator of prosumers in energy and secondary reserve markets[END_REF], bidding strategy of an aggregator of prosumers in the DA and secondary reserve markets is modeled using a stochastic optimization approach. The aggregator tries to optimize the prosumers' flexibility with the aim of minimizing/maximizing the cost of purchased/sold energy. The authors of [START_REF] Doostizadeh | Day-ahead scheduling of an active distribution network considering energy and reserve markets[END_REF] introduce a model for operation of a Disco in DA and reserve markets. In [START_REF] Moghaddam | Distribution company and microgrids behaviour in energy and reserve equilibirum[END_REF], operation problem of a Disco, in cooperation with MGs, in local energy and reserve markets is modeled as a bi-level approach in which the Disco and MGs are considered as the UL and LL problems, respectively. A two-stage model for a Disco is presented in [START_REF] Mashhour | Extending market activities for a distribution company in hourlyahead energy and reserve markets -Part I: Problem formulation[END_REF] in which the Disco participates in the energy and reserve markets. A bi-level optimization approach is developed in [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF][START_REF] Zhang | Strategy-making for a proactive distribution company in the realtime market with demand response[END_REF] to achieve the optimal decisions of the SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292

DRAFT VERSION 6 Disco in the presence of DER aggregators. A two-stage optimization approach is introduced in [START_REF] Algarni | A Generic Operations Framework for Discos in Retail Electricity Markets[END_REF][START_REF] Algarni | A comprehensive short-term operations framework for a Disco in competitive electricity markets[END_REF] to formulate the behavior of a Disco, as a price-taker player, in the DA and RT markets.

In [START_REF] Safdarian | A Stochastic Framework for Short-Term Operation of a Distribution Company[END_REF], operation problem of a Disco in the DA and RT markets is formulated as a stochastic problem which in turn controls the uncertainties of RT energy prices and demand. A stochastic approach to derive optimal bidding strategies for a wind power producer and energy storage in the Spanish multi-stage market, consisting of DA, intraday, and RT markets, is proposed in [START_REF] Díaz | Optimal operation value of combined wind power and energy storage in multi-stage electricity markets[END_REF]. Generally stated, in [START_REF] Palma-Behnke | A distribution company energy acquisition market model with integration of distributed generation and load curtailment options[END_REF][START_REF] Bahramara | A bi-level optimization model for operation of distribution networks with micro-grids[END_REF][START_REF] Rider | Bilevel approach for optimal location and contract pricing of distributed generation in radial distribution systems using mixed-integer linear programming[END_REF][START_REF] Bagher Sadati | Risk-Based Bi-Level Model for Simultaneous Profit Maximization of a Smart Distribution Company and Electric Vehicle Parking Lot Owner[END_REF][START_REF] Xiang | Optimal active distribution system management considering aggregated plug-in electric vehicles[END_REF][START_REF] Iria | Optimal bidding strategy for an aggregator of prosumers in energy and secondary reserve markets[END_REF][START_REF] Doostizadeh | Day-ahead scheduling of an active distribution network considering energy and reserve markets[END_REF][START_REF] Moghaddam | Distribution company and microgrids behaviour in energy and reserve equilibirum[END_REF][START_REF] Mashhour | Extending market activities for a distribution company in hourlyahead energy and reserve markets -Part I: Problem formulation[END_REF][START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF][START_REF] Zhang | Strategy-making for a proactive distribution company in the realtime market with demand response[END_REF][START_REF] Algarni | A Generic Operations Framework for Discos in Retail Electricity Markets[END_REF][START_REF] Algarni | A comprehensive short-term operations framework for a Disco in competitive electricity markets[END_REF][START_REF] Safdarian | A Stochastic Framework for Short-Term Operation of a Distribution Company[END_REF][START_REF] Díaz | Optimal operation value of combined wind power and energy storage in multi-stage electricity markets[END_REF], Disco is considered as a price-taker player in the DA and RT markets.

In presence of DERs, Discos further contribute in markets and thus the markets' outcomes may change. Operation problem of a Disco, as a price-maker player in wholesale market, in presence of DERs has been investigated in few studies. The bidding strategy of the Disco in the DA market is formulated as a bi-level optimization model in [START_REF] Li | A multiperiod energy acquisition model for a distribution company with distributed generation and interruptible load[END_REF]. In [START_REF] Sheikhahmadi | A risk-based approach for modeling the strategic behavior of a distribution company in wholesale energy market[END_REF], a bi-level approach is introduced to model Disco's behavior in the DA wholesale market. The decisionmaking problem of a price-maker Disco in the DA energy and reserve markets is formulated using a bi-level approach in [START_REF] Bahramara | Modeling the Strategic Behavior of a Distribution Company in Wholesale Energy and Reserve Markets[END_REF]. Accordingly, the operation cost of the Disco and the wholesale energy and reserve markets are modeled as the UL and LL problems, respectively.

In [START_REF] Zhang | Strategy-making for a proactive distribution company in the realtime market with demand response[END_REF], Disco's profit in the RT market is formulated as a bi-level optimization in which the Disco problem, including DR program, is considered as a one-stage deterministic model. The bidding strategy of the Disco in the DA and RT energy markets is modeled as a bi-level optimization in [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF] in which the problem of the Disco and the clearing process of the markets are modeled in the upper-and lower-level problems. Table 1 reviews the decision-making frameworks of the so far researches in the field of operation problem formulation of the Disco.

A fast review of the reported models reveals that the models consider Disco as price-taker player in the DA market or as the price-maker player in the both DA and RT markets. Although

Ref. [START_REF] Gabriel | Complementarity Modeling in Energy Markets[END_REF] mathematically formulated the participation of Disco in the DA and the RT markets, SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan. 2019.100292 DRAFT VERSION it fails to model important issues in dealing with the uncertainties as well as the technical constraints of the decision-makers in the markets, including:

• The main advantage of the co-optimization of the Disco's operation problem in the DA and RT markets is to make optimal decisions in the DA, aiming to control the effect of uncertainties, including risk-level of the Disco, on the RT operation. Indeed, the risk-level of the Disco has effects on Disco decisions to participate in the markets and optimally schedule the DERs. However, what is missed is appropriate modeling of the risk-level of Disco through a risk management method.

• Although the Disco is responsible to meet the demand of network, the uncertainty of the demand is not modeled in operation problem of the Disco in the DA and RT markets.

• The ramp-up/down limitations of Gencos -refers as to a single generation sites connected to a single transmission network node -have major impact on the DA and RT market outcomes. However, these constraints are not modeled in the problem of the DA and RT markets. In this way, power generation of Gencos in the DA and the RT markets may be higher than their ramp-rate limitations which in turn leads to unreal market output results.

8

• Modeling the simultaneous participation of Disco in the DA and RT markets using a risk-based approach. This allows to formulate the uncertainties of RESs and demand as well as the risk-level of the Disco in the bidding strategies.

• Modeling ramp-rate limitations of Gencos in both the DA and RT market clearing problems.

Table 1

Comparison between the proposed model in this paper with the previous studies

C. Paper Organization

The rest of this paper is organized as follows. Section 2 presents the problem description.

The problem mathematical formulation is explained in section 3. The numerical results are investigated in section 4 and finally, section 5 concludes the paper. In the real markets, the market players, including Gencos and Discos, submit their bids/offers to the DA market. Afterwards, ISO clears the market according to the received bids/offers and technical concepts, aiming to maximize the social welfare. Meanwhile, the market players need to participate in the RT market to control the uncertainties of the power resources/demand. In this paper, the clearing process of the DA and RT markets is modeled as the LL problem as shown in Fig. 2. Of note that, as the behavior of Gencos and TNLs in the markets are not strategic, their offers and bids are only considered in the LL problems. Decision variables of risk management:

Problem Description

_ _ _ _ _ _ _ , , , , , , , , , , , _ _ _ , , , , , , , , , , , , , ,
_ _ _ _ _ _ _ , , , , , , , , , , , , _ _ , , , , , , , , , ,
_ _ _ _ , , , , , , , , , , , , , , , ,
_ _ _ _ , , , , , , , , , , , , ,

Mathematical Modeling

Operation problem of Disco, as a price-maker player in the markets, is formulated as a bilevel optimization problem in this section.

A. Operation problem of the Disco: UL problem

The Disco decision making process, as the UL problem, is formulated as:

B.1. Objective function

The expected total and total costs of the Disco, including DA and RT markets costs, are formulated using Eqs. ( 1) and (2), respectively.

= = = = = = = =   + + +     =   + - -   -           T t ( 3
)
Subject to:

2) DA power balance constraint: The power balance constraints are modeled as:

_ _ _ , , , , , _ _ _ _ _ _ , , , , , ( , )
0.5( : , 1 )

DG IL i i DNL i RES ES ES i i i RES DA DG IL ESdch DA ESch DA f t k t a t e t e t f M e M e M D F K A E E k M a M L J j Conec i j is DA DNL DA Flow DN DA Loss DN DA t l t i j t t M i j l p p p p p P p p p t i ∈ ∈ ∈ ∈ ∈ ∈ ∈ + + + - + + = - = ∀        (4.a) _ _ _ , , , , , _ _
_ _ _ , , , ( ) , , , 0.5( : , 1 )
DG IL i i RES ES ES i i DNL i i RES DA DG IL ESdch DA ESch D F K A E E k M a M A f t k t a t e t e t f M e M e M DNL DA Flow DN DA Loss DN DA l t i j t i j t L J j Conec i j l M p p p p p p P p t i ∈ ∈ ∈ ∈ ∈ ∈ ∈ - - = + + + ≠ + ∀        (4.b)
3) RESA constraint: Eq. ( 5) stands to limit the purchased power from RESA (9 ', _ ! ). _ , 0 : ,

RES DA RES f t f p P f t ≤ ≤ ∀ (5)
4) DGA constraints: Eqs. ( 6) and ( 7) impose the lower and upper bounds and ramp-rate limitations ((* # / (+ # ) on the power generation of DGs (9 #, $ ), respectively. , , , : ,

DG DG DG DG DG k k t k t k k t k u P u p P t ≤ ≤ ∀ (6) , , 1 , , : , 1 , : , 1
DG DG DG DG k k t k t k k k t k ini k RD p p RU k t RD p p RU k t - ≤ - ≤ ∀ > ≤ - ≤ ∀ = (7)
5) DRA constraint: Eq. ( 8) is developed to tackle the upper bound of the load interruption (9 =, . ), provided by DRA, into problem formulation. power to 0 for the battery. However, if 0 %& < 0 %& for a typical time-step, the Disco can charge the ES with a high price and, at the same time, discharge it with low price to earn the profit. Since occurring such case is not possible in the real operation, these binary variables are used in equation 9. Eq. ( 10) limits the stored energy (34 , _ ! ) in ESs. Eqs. ( 11) and ( 12) explain the dynamic behavior of stored energy in ESs.

_ _ , , , , , , 0 , 0 , 1 :
η η = + - ∀ = (12)
6) DN technical constraints: Technical constraints of distribution network are presented in Eqs.

(13)-( 16). Feeder's current and the associated upper and lower bounds are defined by ( 13) and ( 14), respectively. Moreover, the limitations of bus voltages are represented in [START_REF] Mashhour | Extending market activities for a distribution company in hourlyahead energy and reserve markets -Part I: Problem formulation[END_REF]. Eqs. [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF] and ( 16) are used to model active power flow in DN feeders (9 ,6, L MN_ _ ! ) and active power losses (9 ,6, M _ _ ! ) of the network. In ( 15) and ( 16), 9 ,6, LP_ ! refers to as the active power flows from bus i to bus j and 9 ,6, M_ ! refers to as the active power flows from bus j to bus i. Eq. ( 16) calculates the power losses in each feeder (if: 5 ,6, _ ! or 5 6, , _ ! ≥0; otherwise returns 0).

Of note that the non-linear terms of (RF , _ ! S T and R5 ,6, _ ! S T ) are linearized using the piecewise liner technique of [START_REF] Rider | Bilevel approach for optimal location and contract pricing of distributed generation in radial distribution systems using mixed-integer linear programming[END_REF].

_ _ , , _ , , ,
, ,

DN DA DN DA i t j t DN DA i j t DN i j v v i i j t Z - = ∀ (13) _ _ , , , , , , , , ,
DN DN DN DN DN DA DN DA i j i j i i i j t i t I i I i j t V v V i t - ≤ ≤ ∀ ≤ ≤ ∀ (14) ( ) ( ) ( ) ( ) 2 2 , _ _ _ _ , , , , , , 2 , ( ) ,
,

DN i j Fm DA T o DA DN DA DN DA i j t i j t i t j t DN i j R p p v v i j t Z - = - ∀ (15)
( ) ( )

2 _ _ _ , , , , , , , , , Fm DA
_ _ _ _ _ , , , , , , , , 1 1 1
_ _ _ , , , , , 1 1 ( )
ω ω ω ω ω ω ω λ λ λ λ λ = = = = =   + - +     =   - - -          (17)
Subject to:

2) RT power balance constraint: Eq. ( 18) refers to as RT power balance constraint of DN buses.

( )

_ _ _ _ _ , , , , , , , , _ _ _
_ _ _ _ _ , , , , , , , , , , ( ) , , + ( ) 0.5( ) (
)

RES ES ES i i i L i RES RT RES DA ESdch RT ESch RT Dis RT f t f t e t e t t f M e M e M DNL RT DNL DA Flow DN RT Loss DN RT Loss DN DA l t l t i j t i j t i j t l M F E E L J j Conec i j p p p p P p P p p P ω ω ω ω ω ω ω ∈ ∈ ∈ ∈ ∈ - - - - + + - =      : , , 1 t i ω ∀ = (18.a) ( ) _ _ _ _ , , , , , , , _ _
_ _ _ _ _ _ , , , , ( , ) , , , , , , , ( ) 0.5
ω ω ω ω ω ω ω ∈ ∈ ∈ ∈ ∈ - + - = ∀ - - -      1 ≠ (18.b)
3) Exchanged power of Disco with the markets: Eq. ( 19) imposes the upper and lower bounds on the summation of exchanged power between the Disco and the DA and RT markets. , , ,

DN RT DN RT i t j t DN RT i j t DN i j v v i i j t Z ω ω ω ω - = ∀ (24) _ _ , , , , , , , , , , , , ,
DN DN DN DN DN RT DN RT i j i j i i i j t i t I i I i j t V v V i t ω ω ω ω - ≤ ≤ ∀ ≤ ≤ ∀ (25) ( ) ( ) ( ) ( ) 2 2 , _ _ _ _ _ _ , , , , , , , , , , , , 2 , ( ) , ,
,

DN i j Fm RT To RT DN RT DN DA DN RT DN DA i j t i j t i t i t j t j t DN i j R p p v v v v i j t Z ω ω ω ω ω - = - - - ∀ (26)
( )

2 _ _ _ , , , , , , , , , , , , ,
Fm RT To RT DN DN RT i j t i j t i j i j t p p R i i j t ω ω ω ω + = ∀ (27)
The decision variables of the UL problem is described as

X WX YZ[ = ]2 _ ! , 2 ," _ , 9 ', _ ! , 9

B.4. Risk management

CVaR approach of [START_REF] Safdarian | A Stochastic Framework for Short-Term Operation of a Distribution Company[END_REF] is used to manage risk of Disco. The value of CVaR at the confidence level of α can be defined as the expected cost in the (1 -α)× 100 percent of the worst scenarios, as [START_REF] Conejo | Decision making under uncertainty in electricity markets[END_REF]:

, 1 1 Minimize 1 W CV aR ω ω η ω ξ ω ξ τ η α = = + - (28) 0 TC ω ω ξ η --≤ (29) 0 ω η ≥ (30)
Therefore, the final objective function of the UL problem is formulated as:

Minimize ETC CVaR β + (31)
whererepresents the risk-aversion parameter. Whenis zero, the Disco is a risk-neutral decision maker. The Disco becomes more risk-averse asincreases.

B. DA market problem formulation: LL problem

The DA market problem, as the LL problem, formulates as: ( )

_ _ _ , , , , , , , , 1 1 1 1 1
_ _ _ _ _ _ , , , , , , 1 1 ( ) ( )
= = = = = = =              - -  + + +      (32)
Subject to:

2) Power balance constraints: Eqs. ( 33) and ( 34) stand to satisfy the power balance constraint in DN and TN buses, respectively.

( )

_ _ _ _ , , , , :
,

G TN n n TN Dis DA TN DA TN DA TN DA g t t n r n t r t n t g M r p p B n m t θ θ λ - ∈ ∈Λ - = - ∀ =   (33) ( ) _ _ _ _ , , , , , : ,
G D TN n n n TN TN DA TN DA TN DA TN DA g t d t n r n t r t n t g M d M r p l B n m t θ θ λ - ∈ ∈ ∈Λ - = - ∀ ≠    (34)
3) Constraint of power trading with DA market: Eq. ( 35) limits the transferred power (9 ! ) between the Disco and the market.

- ≤ ∀ > - ≤ ∀ = (38) 11_ 12 _ , , 1 , , , : , 1 , : , 1
TN TN DA DA b d t b d t b d t b d t lb LB b d t µ µ ≤ ≤ ∀ (45) _ 2 _ , , , (44) 14_ 14 _ , , , , , , , , 0 : , , ,
, ( )

B
_ _ 15_ 15_ , , , , , , : , ,

C. RT market problem formulation: LL problem

The RT market problem formulation is described as: (

( ) _ _ _ _ , , )
_ _ _ _ _ , , , , , , 1 1 _
ω ω ω ω ω ω = = =   - +       - -        (52)
Subject to:

2) Power balance constraint in RT market: Eqs. ( 53) and (54) satisfy the power balance constraints in DN and TN buses for each scenario, respectively.

( ) ( )

_ _ _ _ _ _ _ _ , , , , , , , , , , , , : , ,
ω ω ω ω ω θ θ θ θ λ ω - ∈ ∈Λ - - = - - + ∀ =   (53) ( ) ( ) ( ) _ _ _ _ _ _ _ _ _ , , , , , , , , , , , , , , , : , , G
ω ω ω ω ω ω θ θ θ θ λ ω - ∈ ∈ ∈Λ - - - = - - + ∀ ≠    (54)
3) Traded power of the Disco with RT market constraint: Eq. (55) limits the exchanged power (9 ," _ ) between the Disco and RT market. 4) Gencos constraints: Eq. (56) reveals that RT up/down regulation power of each Genco (B9 , ," _ /B9 , ," _ ) should not exceed the associated DA maximum up/down regulation power.

Eqs. (57)-(60) limit the power generation of Gencos in RT market considering the ramp-rate limitations ((* /(+ ). ( ) Eqs. (32)-( 51) and ( 52)-( 65) are developed to model the DA and RT market problems, respectively. Of note that, the dual variables of the aforementioned constraints are represented at the right hand side of the equations. The decision variables of the DA and RT problems are

_ _ 2 _ 2 _ _ _ 3 _ 3 _ , , , , , , , , , , , , , , 0 : , , 0 : , ,
_ _ _ _ 4 _ , 1 , 1, , 1, , , , , , , , : , 1
µ - - - + - - + - ≤ ∀ > (57) ( ) _ _ 5_ , , , , , , , , : , 1
ω ω ω µ - + - ≤ ∀ = (58) ( ) ( ) _ _ _ _ 6 _ , , , , , , 1 , 1, , 1, , , : , 1
( ) _ _ 7 _ , , , , , , , , : , 1
_ _ 10 _ 10 _ , , , , , , , , , , : , , ,
X XX Yc = ]9 , , 7 , _ ! , 98 , , , 78 , , , B9 , _ ! , B9 , _ ! , B7 , _ ! 9 _ ! , G , _ ! ^ and
X XX de =
]B9 , ," _ , B9 , ," _ , B7 , ," _ , 7 , ," _ , 9 ," _ , G , ," _ ^, respectively. In the proposed two-stage stochastic problem, the decisions of the Disco are divided into two parts: 1) before, and 2) after occurring of the scenarios [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF][START_REF] Conejo | Decision making under uncertainty in electricity markets[END_REF]. In this way, the first part decisions are considered as the parameters in the second-stage problem. This means that the first-stage decision variables of

D. Mathematical program with equilibrium constraints

The proposed model is a non-linear bi-level problem. One of the appropriate and common solution to deal with the bi-level problem is to replace the LL problem with the KKT conditions [START_REF] Gabriel | Complementarity Modeling in Energy Markets[END_REF][START_REF] Talbi | Metaheuristics for Bi-level Optimization[END_REF]. In the bi-level problems, the decision variables of the UL problem, i.e. bids/offers of the Disco to the DA and RT markets, are considered as the parameters of the LL problems.

Therefore, the LL problems are linear continuous and convex, and thus could be replaced by the KKT conditions, as described in Appendix B.

Cost of the exchanged power between the Disco and DA market (0 P, _ ! 9 _ ! ) is linearized using the approach of Appendix C. Also of interest, cost/revenue of exchanged power between the Disco and RT market (0 P, ," _ 9 ," _ ) is linearized using McCormick's relaxation method of Appendix D. Accordingly, the final model of Disco operation in DA and RT markets is formulated as:

( ) _ , , , , , , , , 1 1 1 1
1_ _ 1_ _ _ _ _ _ _ _ , , , , , , 1 1 1 ( ) ( ) Minimiz ] e
= = = = = = =       -+ - +         - + + +      ( ) _ _ , , , , 1 1 _
_ , , 1 1 _
_ _ , , , , , , , 1 1 ( ( )
= = = = = =   + + -     +   -     -+ -+ - +       1 1 _ , , , 1 ( ) W
β λ λ = = - - =                                     +                                         - - -                   (66)
Subject to:

Eqs. ( 4)-( 16), ( 18)- [START_REF] Alharbi | Probabilistic coordination of microgrid energy resources operation considering uncertainties[END_REF], and ( 28)- [START_REF] Kazempour | Strategic generation investment using a complementarity approach[END_REF].

Numerical results

The IEEE 6-bus test system is used to investigate the optimal behavior of the Disco as well as the associated impacts on the DA and RT markets. Furthermore, effectiveness of the proposed model is verified on the RTS 24-bus test system. In both the case studies, the Disco is responsible to operate the 33-bus distribution network.

The system data are taken from [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF]. The forecasted output power of wind turbines (WTs)

and photovoltaic (PV) arrays are taken from [START_REF] Sheikhahmadi | A risk-based approach for modeling the strategic behavior of a distribution company in wholesale energy market[END_REF]. Maximum traded power between the Disco and the market is 80MW. Technical characteristics of RESs, ESs, and DGs are taken from [START_REF] Sheikhahmadi | A risk-based approach for modeling the strategic behavior of a distribution company in wholesale energy market[END_REF].

Moreover, the maximum purchased power from DRA is 7MW. The aggregators' offers are taken from [START_REF] Zhang | Trading strategies for distribution company with stochastic distributed energy resources[END_REF][START_REF] Zhang | Strategy-making for a proactive distribution company in the realtime market with demand response[END_REF][START_REF] Alharbi | Probabilistic coordination of microgrid energy resources operation considering uncertainties[END_REF] and reported in Table 2. Also, the occurrence probabilities of the scenarios, as calculated in Appendix A, are given in Table 3.

Table 2

The offers of aggregators to the Disco and selling energy price to the DNL ($/MWh)

I. Input data

Structure of the distribution and transmission networks, the input data, and location of DERs in the DN are shown in Fig. 3 and Tables 4-8 [START_REF] Hajibandeh | The Impacts of Demand Response on the Efficiency of Energy Markets in the Presence of Wind Farms[END_REF][START_REF] Fu | AC contingency dispatch based on security-constrained unit commitment[END_REF][START_REF] Kazempour | Strategic generation investment using a complementarity approach[END_REF]. While TNL #3, locates at bus 5, is replaced with DN, bus #1 is considered as the reference bus. Moreover, the maximum up/down regulation capacity assumed to be 30MW. As shown in Table 6, two blocks are considered to represent the offers of each Genco. The total energy in DA market is reported for each TNL in Table 7. For simplicity, the total energy consumption is divided into three blocks with equal sizes. Core i-5 with a CPU speed of 2.60GHz, 64bits operating system is used to solve the model.

Using this system, the computational time to solve the proposed model for the 6-bus system is 314.06 sec.

II. Results

The Disco total cost and the mean and standard deviations of RT market clearing prices (MCPs) for each scenario are given in Table 9 and Fig. 4, respectively. Fig. 4 reveals that according to the different strategic behaviors of the Disco to manage the uncertainties, the mean and standard deviations of RT prices change.

Table 9

The total cost of Disco in each scenario

DRAFT VERSION

For instance, the operation results of the Disco, for the fourth scenario (ω = 4) with risk aversion parameter of 0 are presented in Figs. 5-10. Fig. 5 reveals that the changes in MCP for the RT market is greater than the DA market. This could be justified by:

• The purchased/sold power in the RT market is less than the DA market.

• Modeling of the responsive TNLs in the RT market besides providing RT down regulation power increase the submitted offers to the RT market.

• The Disco participates as a prosumer player in the RT market in order to face with the power deviation from RESA and DNL.

To this end, the Disco decreases the DA MCP from 18.81$/MWh and 19. According to Fig. 8, responsive TNLs 1 and 2 provide the main part of maximum up regulation power.

As shown in Fig. 9, in hours 10-18 and 21-23, the TNL of the RT market is provided by the Disco and the Genco # 3. In hours 2-8 and 24, the TNL is zero and thus, the purchased power by the Disco is provided by the Genco # 3 and responsive TNL 1. In hours 9, 19, and 20, the Genco # 3 supplies the required energy of the TNL and Disco. In hour 1, the Genco # 1 reschedules the power generation according to the maximum down regulation power, which would be determined in the DA market. Thus, the Disco sells energy to the market to compensate for the down regulation power. For instance, at hour 19, the differences between stochastic and deterministic DNL, and stochastic power of RESs and the purchased power from RESA are positive. Therefore, the Disco reduces the bid, aimed to decrease the purchased power which in turn causes the realtime MCP decreases from 23$/MWh to 22$/MWh.

III. Comparing different modeling of the ES in Disco problem

In this sub-section, the different operation modes of the ES aggregators in the Disco problem are investigated. For this purpose, three cases are considered: I) modeling the ES in the DA market, II) modelling the ES in the RT market, and III) modeling the ES in the both markets.

The results of the cases are shown in Table 10 and Figs. 11 and 12. It could be seen that, the ETC of the Disco decreases for cases II and III. This is because of the optimal decisions of the Disco to trade energy with the market, considering optimal operation of ES. Indeed, when ES is modeled in the second stage, the Disco may charge ES in the case of low prices, and sells the stored energy to the RT market in the case of high prices. For instance, as shown in Fig. 11, for hours 12 and 13, the Disco sells power to the RT market with price of 18$/MWh. On the other hand, for the case I, the Disco sells extra energy to the RT market.

Table 10

The amount of ETC regarding different interacting with the ESs aggregator

IV. Risk analysis

In this sub-section, the impact of risk-aversion parameter on the decisions of the Disco are investigated. In what follows, α sets to 0.8. It means that the Disco trusts to 80 percent of scenarios and tries to manage 20 percent of worst case scenarios, scenarios number 6, 11, and 15 in Table 8. The ETC variations of the Disco, for different values of -, are shown in Fig. 13 in which scenarios are sorted from the worst scenario to the best one. In this way, the worst scenarios, i.e. scenarios # 6, 11, and 15 in Table 9, are renamed as scenarios # 1, 2, and 3, respectively. According to Fig. 13, it is observed that as the risk-aversion parameter increases, the ETC in the worst scenario decreases and difference between the ETCs in the best and worst

DRAFT VERSION

and RESA may change difference between stochastic power of RESs and purchased power from RESA and the second-stage decision-variables. As shown in Table 11, power purchased/sold from/to the RT market increases/decreases and bids/offers related to the exchanged power increases from 18.00$/MWh to 22.00$/MWh at hours 7 and 13, respectively.

The purchased power from RESA increases from 81.259MW to 102.077MW when the riskaversion parameter increases from 0 to 100. Generally stated, the risk parameter has significant impacts on the first-stage decisions of the Disco which in turn, changes bids/offers of the Disco in the DA and RT markets.

Table 11

Sensitivity of the Disco DA and RT bids/offers to risk-aversion parameter As shown in Fig. 15, the risk-averse Disco attempts to control the uncertainties of RESs and DNL to improve the expected cost of (1 -α) × 100% of the worst scenarios (CVaR). For this reason, the risk-averse Disco trusts to the first-stage decisions to increases the total purchased power from the RESA and change the purchased power from the DA market. Therefore, the difference between stochastic power of RESs and purchased power from RESA ∑ ( ', ," -', ! g

) decreases in each scenario. This in turn decreases the ability of the riskaverse Disco to act as a producer in the RT market. The data of the system are taken from [START_REF] Sheikhahmadi | A risk-based approach for modeling the strategic behavior of a distribution company in wholesale energy market[END_REF][START_REF] Conejo | Decision making under uncertainty in electricity markets[END_REF]. The developed model, consisting of 927560 single equations, 622635 single variables, and 116110 discrete variables, is solved by CPLEX solver. Using the same personal computer as that of part A, the computational time to solve the model is 1178.18 sec.

II. Results

The numerical results, including power balance of the distribution and transmission networks and MCPs for both DA and RT markets, are presented in Figs. 16-20. As shown in

Conclusion

The decision making problem of the Disco to provide the demand through optimal trading with the DER aggregators and participating in the day-ahead and real-time markets is addressed

Power (MW) Time (hour)

Power sold to ESA Purchased power from ESA Deviation between stochastic power of RESs and purchased power from RESA Disco power exchange with RT market Power deviation between stochastic and deterministic DNL in this paper. To model such problem, a risk-based two-stage stochastic bi-level optimization approach is developed. The derived model is a nonlinear bi-level problem which may be transformed into the single-level problem using Karush-Kuhn-Tucker conditions. Moreover, the non-linear terms are linearized using the dual theory and McCormick's relaxation methods.

To investigate the effectiveness of the proposed model, the distribution network is connected to two test systems. The main conclusions from the results are as follows:

• Interactions with distributed energy resources aggregators besides low level of transactions in the market cause the Disco acts as a prosumer in the real-time market.

This in turn has significant effect on the market clearing prices. On the other hand, the Disco can compensate for the power imbalance through participating in the real-time market and interacting with the energy storage aggregators.

• Simultaneous modeling of the Disco in the day-ahead and real-time markets causes the Disco makes the best decisions to interact with the distributed energy resources aggregators, control the renewable energy sources and load uncertainties, and trade energy with the markets. Indeed, these goals are achieved using the proposed two-stage stochastic programming approach.

• The decisions of the Disco in the day-ahead and real-time markets, including bids/offers and purchased/sold power from/to the markets, depend on the associated risk parameter.

So, the decisions of the risk-averse Disco can affect the market clearing prices of the dayahead and real-time markets.

amount of these parameters in each time step is considered as the mean value of the related PDFs. The probability of each interval is obtained through the integration of the mentioned PDFs regarding the lower and the upper limitations of each interval. For each parameter, 24000 samples are generated regarding the probability of the intervals. The average value of each interval is multiplied with the forecast value of the parameter to show the value of that parameter in each sample. Then, the scenario tree construction is used to generate different scenarios in the operation time as described in [32,33]. In this approach, the time steps defined in the problem (i.e. 24 hours in this paper) and the generated samples are used as the scenario tree stages and the nodes, respectively, where a scenario is defined as the path among the nodes.

Using the scenario tree method, 1000 scenarios are generated to model the uncertain parameters in the time-period of the operation. To decrease the tractability of the computational problem of the model [START_REF] Sheikhahmadi | A risk-based approach for modeling the strategic behavior of a distribution company in wholesale energy market[END_REF], the generated scenarios are reduced to 15 scenarios using the General Algebraic Modeling System/Scenario Reduction (GAMS/SCENRED) package and fastforward scenario reduction technique. Each scenario is consisting of wind speed (" ," ), solar radiation (: ," ! ), and demand data for the time-period of the operation problem, i.e. 24 hours.

Then, the output power of WT and PV arrays is calculated as follows:

• The output power of WT is calculated using (A.1) [START_REF] Alharbi | Probabilistic coordination of microgrid energy resources operation considering uncertainties[END_REF][START_REF] Tenfen | A mixed integer linear programming model for the energy management problem of microgrids[END_REF]:

, , 3 2 , , , , , , , , , , , , 0 0 0
f t ci f t f t f t ci f t r WT f t r r f t co v V av bv cv d V v V p P V v V ω ω ω ω ω ω ω ≤ < + + + ≤ < = ≤ ≤ , , f t co v V ω       >  (A.1)
Where is the rated WT output power; F ', ," , " % , " , and " %M are the forecast wind speed, the cut-in, the rated, and the cut-out wind speeds, respectively; and a, b, c, and d are the parameters of the WT power curve.

• Equation (A.2) is used to model the output power of PV array [START_REF] Logenthiran | Multi-agent system for energy resource scheduling of integrated microgrids in a distributed system[END_REF]

π π µ θ µ θ         ≤ ⊥ -- ≥ ≤ ⊥ - ≥                 (B.25) _ 1_ 2_ 3_ 4_ 5_ , , , , , , , , , , Unrestricted

B.2. MPEC of the RT market problem

• Stationarity: The lagrangian function for the RT market problem is modeled as (B.28) in which ‰ (ˆ) = 0 , i = 1, 2,3 describes the equality constraints including (41), (42), and

(53), ) 6 (ˆ) ≥ 0 , j =

P                                 (C.1)
The parameter S is used to model all the equations in the bracket represented in (C.1).

Based on the strong duality theory 98 , , , 78 , , , 9 Eq. (C.2) can be reformulated as follows:

( ) _ _ _ , , , , , , , , 1 1 1 1
1 1 _ _ _ _ _ _ , , , , , , 1 1 ( ) ( ) [
( )

_ , , , , , , , , 1 1 1 1
_ _ 1 1 1 _ _ _ _ _ _ , , , , , , 1 1 ( ) ( ) [
= = = = = = = = =       = -    - +       + +           (C.3)
The equation (B.

  decisions of the Disco to purchase power from the DGs change the traded power with the DA market. This decreases the operation cost. clearing mechanisms, i.e., pay-as-bid and uniform, for local energy market are compared where the Disco and the MGs earn more profit in pay-as-bid and uniform mechanisms, respectively. Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292

Figs. 1

 1 Figs. 1 and 2 show the proposed decision-making framework of the Disco in the DA and

  ω

Fig. 1 .

 1 Fig. 1. Proposed decision-making framework of the Disco in the DA and RT markets

B. 2 . 1 )

 21 First-stage decisions of the Disco: Total cost of the Disco in DA market: The Disco operation cost in the first-stage decision making process (?D ! ) is modeled by Eq. (3

6 )

 6 TN power flow constraint: Eq. (47) shows the capacity limitation ( ) of TN line, specifies with sending end of 4 and receiving end of B.

1 )

 1 Objective function of RT market problem: Objective function of the problem, i.e. Eq. (52), is to minimize the total operation cost in each scenario. The objective function consists of the regulation costs of Gencos and responsive TNLs, the revenue from selling energy to RT TNLs, and the cost/revenue from trading energy with the Disco (non-negative 9 ," _ refers to bid and negative one stands for offer).

Fig. 3 .

 3 Fig. 3. Structure of the 33-bus distribution network connected to 6-bus power system

  2$/MWh to 18.6$/MWh and 18.81$/MWh at hours 8 and 9, respectively by decreasing the purchased power from the DA market. In this way the Disco decides to purchase the required energy from RESA and DGA, as shown in Fig. 7. Moreover, the Disco decreases the purchased power from the DA market by interacting with DGA and DRA at hour 23, as shown in Fig. 7. This in turn leads to decreasing the MCP of the DA market from 19.2$/MWh to 18.81$/MWh.

Fig. 5 .Fig. 6 .Fig. 7 .Fig. 8 .

 5678 Fig. 5. MCPs in the DA and RT markets

Fig. 9 .Fig. 10 . 29 Fig. 10

 9102910 Fig. 9. Share of the Disco, Gencos, and responsive TNLs to supply real-time TNL

Fig 11 .Fig. 12 .

 1112 Fig 11. Sensitivity of the Disco DA and RT bids/offers and power trading to the different modeling of ESs

  Power trading with DA Market (ES modeling in the first-stage) Power trading with DA Market (ES modeling in the second-stage) Power trading with RT Market (ES modeling in the first-stage) Power trading with RT Market (ES modeling in the second-stage) ES aggregator in the first-stage ES aggregator in the second-stage ES aggregator in the both stages SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION 31 scenarios decreases from 1499.16$ to 1248.83$. Indeed, ability of the Disco to control the uncertain behavior of the RESs and DNL increases in the risk-aversion of 100.

Fig. 13 .

 13 Fig. 13. Sensitivity of the minus ?D " to risk-aversion parameter in each scenario Fig. 14 represents the relationships between the ETC/CVaR and the risk-aversion parameter.

Fig. 14 .

 14 Fig. 14. Sensitivity of the minus ETC and CVaR to risk-aversion parameter

Fig. 15 .

 15 Fig. 15. The total amount of power deviation between the stochastic power of RESs and the purchased power from RESA in each scenario

Figs. 16 -

 16 Figs.[START_REF] Zhang | Strategy-making for a proactive distribution company in the realtime market with demand response[END_REF][START_REF] Algarni | A Generic Operations Framework for Discos in Retail Electricity Markets[END_REF][START_REF] Algarni | A comprehensive short-term operations framework for a Disco in competitive electricity markets[END_REF], the Disco decreases the MCP of DA market from 10.66$/MWh and 10.66$/MWh

Fig. 16 .Fig. 17 .Fig. 18 .Fig. 19 .Fig. 20 .

 1617181920 Fig. 16. MCPs of the DA and RT markets

  purchased/sold power by Disco DN regulation power of Genco 9 DN regulation power of Genco 8 UP regulation power of Genco 9 UP regulation power of Genco 1

  ,

	p	RES DA f t	p	DG k t	IL a t p p	ESdch DA e t	p	ESch DA e t	en	ES DA e t	ch e t v v	dch e t	p	Flow DN DA i j t	p	Loss DN DA i j t	v	DN DA i t	i	DN DA i j t

  ,

	p	ESdch RT e t ω	p	ESch RT e t ω	p	Flow DN RT i j t ω	p	Loss DN RT i t j ω	en	ES RT e t ω	i	DN RT i j t ω	v	DN RT i t ω
							, ω ξ η
										Day-ahead wholesale market
								Objective function: Maximization of the social welfare
												Decision variables:

  ,

	Real-time wholesale market
	Objective function: Minimization of the total cost in each scenario
	Decision variables:
	TN g t p pb TN b g t d t TN DA l	TN b d t b l	UP DA g t rp	r p	DN DA g t	l r	DN DA d t	TN DA n t θ -

  ,

	Upper-level problem
				_ , , TN RT m t ω λ	,	p	_ Dis RT , t ω		_ Dis RT , t c ω	_ TN DA , m t λ	,	p	_ Dis DA t	c	_ Dis DA t
	rp	UP RT g t ω	rp	DN RT g t ω	rl	DN RT d t ω	l	TN RT d t ω	TN RT n t ω θ -
	Lower-level problem
			Fig. 2. Risk-based two-stage stochastic bi-level optimization problem

  ,

		≤	ESch DA e t p	≤	ch ch e t e P v	≤	ESdch DA e t p	≤	dch dch e t e P v	ch e t v v +	dch e t	≤	e t ∀	(9)
	E	E e S	≤	_ ES DA , e t en	≤	E	ES e	: , , e t ∀	(10)
	_ ES DA , e t n e	=	_ , 1 ES DA e t n e -	+	(	_ ESch DA , e t p η ch	) ( -	_ ESdch DA , e t p	h dc η	)	, 1 t ∀ > e	(11)
	_ ES DA , e t n e		E	, ES e ini		(	_ ESch DA , e t p	c h	) (	_ ESdch DA , e t p	dch	)	, 1 e t

  SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION 1) Objective function: DA market clearing problem formulates based on the offer of Gencos, the bid of the transmission network load (TNL), the bid/offer of the Disco, the regulation reserve offer of Gencos and responsive TNLs, as:

  Eq. (42) limits the TNLs consumption (7 , _ ! ) in the DA. Eq. (44) imposes the limitation on the DA maximum down regulation power (B7 , _ ! ) for each responsive TNL. Eq. (43) stands to link Eqs. (42) to (44). It reveals that if the purchased power by the TNLs becomes zero in response to price elasticity, DA maximum down regulation of the responsive TNLs should be zero. Eq. (45) imposes the upper bound on number of energy blocks related to TNLs consumption (78 , , ). Eq. (46) indicates that summation of energy blocks, related to the TNL, is equal to the total TNL consumption.

				SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi :
	10.1016/j.segan.2019.100292	DRAFT VERSION
	p	, TN g t			=	1 = B b 	, , TN b g t pb		:	λ	1_ , g t	DA					, g t ∀	(41)
	5) TNLs constraints: _ 6 _ , , , 0 : TN DA TN DA d t d t d t l L µ ≤ ≤	,	µ	6 _ , d t	DA	, d t ∀	(42)
	0	≤		l	_ TN DA , d t	-	rl	, DN d t			:	µ	7 _ , d t	DA	∀	, d t	(43)
	0	≤	rl	_ DN DA , d t	≤	RL	DN d	:		8 _ , d t µ	DA	,	8_ , d t µ	DA	, d t ∀
	p	TN g t			-	p	TN g t	-	≤	RU	g				µ	g t	DA	g t ∀	>	p	TN gt	-	TN g ini P	≤	RU	g	µ	g t	DA	g t ∀	=	(39)
	0	≤	, , TN b g t pb	≤	PB	, , TN b g t		:	13_ , , DA b g t µ	,	13_ , b gt µ	DA	, , b g t ∀	(40)

  ,

		SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi :
	10.1016/j.segan.2019.100292	DRAFT VERSION
	1 rp  G g =	_ DN DA , g t	=	t P	_ R T C DN		:	t λ	4 _	DA	∀	t	(51)
	-	F	TN n r -	≤	B	n r -		θ	TN DA n t	-	θ	TN DA r t	≤	F	TN n r -	µ	DA n r t	µ	DA n r t	n r ∀	TN n ∈ Λ	t	(47)
	7) TN voltage angle constraints: While Eq. (49) defines TN bus as the reference, Eq. (48)
	imposes the bound on DA TN voltage angle (G ,	! ).
	π -	/ 2	≤	θ	_ TN DA , n t	≤	π	/ 2 :	µ	16 _ , n t	DA	,	µ	16 _ , n t	DA	, n t ∀	(48)
	θ	_ T N D A , n t n slack =		=	0 :	λ	5 _ , n t n slack D A =	∀	t	(49)
	8) Maximum up/down regulation power constraints: Eqs. (50) and (51) show that summation
	of the DA maximum up/down regulation power, provided by each Genco and responsive TNL,
	1 rp = G g 	_ UP DA , g t		+	1 rl = D d 	_ DN DA , d t		=	t P	_ RTC UP	:	3 _ t λ	DA	∀	t	(50)

is equal to the total up/down regulation power capacity ( _ / _ ).

  ,

	SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi :
	10.1016/j.segan.2019.100292				DRAFT VERSION
	(							) (							)
	≤	rp	UP RT g t ω	≤	rp	UP DA g t	µ	g t	RT ω	µ	g t	RT ω	≤	rp	DN RT g t ω	≤	rp	DN DA g t	µ	g t	RT ω	µ	g t	RT ω	g t ∀	ω	(56)
															20

  ,

	-	F	TN n r -	≤	B	n r -	θ	TN RT n t ω	-	θ	TN RT r t ω	≤	F	TN n r -	RT n r t ω µ	RT n r t ω µ	n r ∀	TN n ∈Λ	t	ω	(63)
	7) TN voltage angle constraints: Eqs. (64) and (65) impose bounds on RT TN voltage angle
	(G , ," _ ) in bus n.
	2 π -≤	θ	_ TN RT , , n t ω	≤	2 π	:	µ	11_ , , n t ω RT	,	µ	11_ , , n t ω RT	, , n t ∀	ω	(64)
	θ	_ TN RT , , n t ω	=	0 :	1_ , , RT n t ω λ		, , n slack t ∀ =	ω	(65)

  SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION 21 the Disco, including the DA maximum up/down regulation power, power generation of Gencos, DA TNL consumption, and DA TN voltage angle, are considered as the parameters in the second-stage problem, i.e. RT market problem.

  Table 8 reports the respective bids of the blocks. The up/down regulation offers of

	Gencos/responsive	TNLs	in	the	RT	(D ,	_ , D ,	_ , D ,	_ )	and	DA
	(D ,	_ ! , D ,	_ ! , D ,	_ ! ) markets are assumed to be equal. The model, consists of 220344
	single equations, 148714 single variables, and 28008 discrete variables, is solved by CPLEX
	solver with GAMS 24.1.2 software. A personal computer with 6GB RAM running on Intel

Table 4

 4 Technical data of generator units, TNLs, and Disco SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION

	# Genco	P s	P s	RD s /RU s	P s,ZtZ eo	Node location	# TNL	% of system load	l q,m,g eo	Node location

Table 5

 5 Location of DERs in the DN

	Type of DERs	WT	PV	DG	ES	IL
	DN Bus	12, 18, 21, 33	3, 8, 22, 25	18, 24, 29, 33	10, 11, 12, 13	8, 24, 25, 30, 31, 32

Table 6

 6 Size of energy blocks, maximum up/down regulation reserve, and offer costs ($/MWh) submitted by generator units

	# Genco	PB q,s,g eo	(Block1)	PB q,s,g eo	(Block2)	C q,s,g eo (Block1)	C q,s,g eo (Block2)	RG s Wy	RG s Yo	C s,g Wy_z{	C s,g Yo_Yc
		($/MW)	($/MW)	($/MW)	($/MW)	(MW)	(MW)	($/MWh)	($/MWh)
	1	132		88	18.60	20.03	55	55	24	16
	2		60		40	19.20	20.32	25	25	25	17

Table 7

 7 Hourly summation of TNL 1 and 2

	Time	1	2	3	4	5	6
	(MW) 111.84	105.6	102	99	99	102
	Time	7	8	9	10	11	12
	(MW)	111.6	130.2	147.6	160.2	166.2	168
	Time	13	14	15	16	17	18
	(MW)	166.2	168	168	163.2	161.4	161.4
	Time	19	20	21	22	23	24
	(MW)	156.6	155.4	155.4	156.6	147.6	124.2

Table 8

 8 Bids and maximum down regulation reserve submitted by TNL

	# TNL	eo Yc (Block1) C q,m,g	C q,m,g eo Yc (Block2)	C q,m,g eo Yc (Block3)	RL m Yo	C m,g Yo_Yc	C m,g eo_de
		($/MW)	($/MW)	($/MW)	(MW)	($/MW)	($/MW)
	1	21.58	19.80	18.81	15	23	22
	2	23.55	22.37	21.33	15	24	24

  The mean and deviation values of RT MCPs in the operation period in all scenarios

	SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi :
	10.1016/j.segan.2019.100292
	# scenario		1		2			3	4	5
	Total Cost ($)	-16150		-15380.12		-15731	-15332.24	-16010.4
	# scenario		6		7			8	9	10
	Total Cost ($)	-14900.84	-15632.36		-16220.52	-15460.19	-15813.42
	# scenario		11		12		13	14	15
	Total Cost ($)	-14970.73	-15441.28		-15473.1	-16400	-15182.71
							Average	Standard deviation
			20
		Price (S/MWh)	10 15
			5
	Fig 4. 0	1	2	3	5	6	7 Number of scenarios 8 9 10 11 12 13 14 15

:

  SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292

								DRAFT VERSION
	≤		⊥	-	-	--	-	≥	≤	µ	⊥	-	-	-	θ	θ -	≥ (B.24)
	0	16 _ , n t	DA	_ TN DA , n t	2	0 , 0	16 _ , n t	DA	2	_ TN DA , n t		0

  1, 2, … , 11 describes the inequality constraints including (43)-(52), and ˆ is variable set of the RT problem. The stationary equations are obtained as (B.30)-(B.35).

	RT L	=	( ) ( ) T RT RT f x λ +		H	RT i	( ) ( ) T RT RT x µ +	G	R j	T	( ) R T x	(B.28)
	∇	x	( ) ( ) T RT RT f x λ +	∇	x	h	RT	( ) ( ) T RT RT x µ +	∇	x	g	RT	( ) 0 RT x =	(B.29)
				_				_	2 _	2 _					4 _	4 _	5 _	6 _
				,			, ,

  : Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 Where each equation is linearized as Eq. (B.48) in which ; ' and ; T are large enough values and * is a binary variable.

																																								DRAFT VERSION
		≤						⊥								-										-						--	-	≥	≤	µ	⊥	-	-	-	θ	-	θ	≥ (B.45)
		0	≤		µ	11_ , , n t ω RT	⊥	  	θ	_ TN RT , , n t ω	 -- 	2 π	  		  	≥	0 , 0	≤	µ	11_ , , n t ω RT	⊥	  	  	2 π	-	θ	_ TN RT , , n t ω	  	  	≥	0	(B.46)
		λ	_ T N R T , , n t ω	,	λ	1 _ , , R T n t ω	n S lack =				, Unrestricted	(B.47)
	0	≤	a	R T	⊥	b	RT	≥		0			a	RT		≥	0,		b	RT	≥	0,	a	RT	≤	1 RT RT M U	,	b	RT	≤	M	2 RT	(1	-	U	R T	)	(B.48)
		rp ∂	DN RT g t L ω ∂		= -	C	DN RT g t		+	TN RT n t ω λ	-	µ	g t	RT ω	+	µ	g t	RT ω	+	µ	g t	RT ω	t	>	-	µ	g t	RT +	ω	+	µ	g t	RT ω	t	=	-	µ	g t	RT ω	t	>	(B.31)
												+	µ	g		, 1, RT t ω +	-	µ	g	, t	R ω T	t	=		=	0
		rl ∂	_ DN RT , , t d L ω ∂	=	C	, DN d t	_			-	_ TN RT , , n t ω λ		n	≠	m	-	8_ , , RT d t ω µ	+	8_ , , RT d t ω µ	=	0	(B.32)
		l ∂	_ TN RT , , d t L ω ∂	C = -	_ TN RT , d t	+	_ TN RT , , n t ω λ		n m ≠	-	9_ , , RT d t ω µ	+	9_ , , RT d t ω µ	=	0	(B.33)
		_ Dis RT , t L p ω ∂ ∂		= -	c	_ Dis RT , t ω		+	_ , , TN RT m t ω λ	-	1_ , t ω RT µ  +	1_ , t ω RT µ	=	0		(B.34)
		θ ∂	_ L , , TN RT n t ω ∂		=		r	_ 10 _ , , , , , TN RT n t RT r n t ω ω λ ( ( n r n r B B TN Λ Λ TN µ -∈ r -∈   	--	_ 10 _ , , , , , TN RT r t RT n r t ω ω λ µ  ) ) + -_ DA RTC DN Λ 11_ , , TN r n t µ ∈ 	RT B ω	n r -+	10 _ , , , 11_ , , RT n r t RT n t ω ω µ µ ( + -λ n t 10 _ , , , 1_ , , RT r n t RT n slac ) ω ω µ = + k 	=	0	(B.35)
		• Primal, dual, and complementary constraints: These equations are defined as follows:
		0 0 0	≤ ≤ ≤	1_ , t ω RT µ 2_ , , RT g t ω µ 3_ , , RT g t ω µ	( ( p t Dis RT _ , ω _ , , UP RT -) g t rp ω ⊥ ⊥ ( ) P ≥ Dis TN _ 0 , 0 ) ≥ ≤ 0 , 0 2_ , , RT g t ω µ _ 3_ , , , , 0 , 0 DN RT RT g t g t rp ω ω µ ⊥ ≥ ≤	( UP DA RT ω 1_ , t µ ⊥ ( _ , g t rp ⊥ ≤ ( _ , DN DA P -Dis TN _ , , _ UP RT p t Dis RT _ , ω -0 g t rp ω ≥ ) ) _ , , 0 DN RT g t g t rp rp ω ⊥ -≥	)	≥	0	(B.36) (B.37) (B.38)

SEGAN

  Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292 DRAFT VERSION 43 solutions of the primal problem and " 6_ ! , ∀j = 1, … , 26 and 0 •_ ! , 0 -_ ! are optimal solutions of the dual problem if and only if:

	SEGAN:
	_ ! , B9 ,	_ ! , B9 ,	_ ! , B7 ,	_ ! are optimal

  ]

		G B			D B
			TN	TN			TN DA	TN	Dis DA Dis DA
	T	g b	b g t	b g t	d b	b d t	b d t	t	t	T
	t	G						D			t
	t	UP DA	UP DA	DN DA	DN DA	DN DA	DN DA	t
		g t		g t	g t		g t		d t	d t
		g						d

  ]

						G B			D B
	T	t D	Dis DA Dis DA t t c p	T	t D	g b G	TN b g t C	TN b g t pb	d b	TN DA TN b d t b d t C lb	D	T	t D S
	t			t		C	UP DA UP DA g t g t rp	C	DN DA g t	rp	DN DA g t	DN DA DN DA d t d t rl C	t
						g								d

  [START_REF] Marvasti | Optimal Operation of Active Distribution Grids: A System of Systems Framework[END_REF]) is transformed into (C.4) and (C.5) to obtain the expression of0 P, _ ! 9 _ ! from 2 _ ! 9 _ ! .

		_	_		1_		1_
		,
					G B				D B
	T	TN DA Dis DA m t t p	T	t D	g b G	TN b g t C	TN b g t pb	)	d b	( C TN DA TN b d t b d t lb	)	D	[ ] S	t	DA Dis TN P	t	D
	t		t		UP DA UP DA g t g t rp C	DN DA DN DA g t g t rp C		DN DA DN DA d t d t rl C
					g						d

Appendix Appendix A: Modeling uncertainties

To model the uncertainties of demand, wind speed, and solar radiation, the normal, weibull, and irradiance distribution models as their probability distribution functions (PDFs), respectively, are discretized into seven and five-intervals as described in [START_REF] Wang | Spinning reserve estimation in microgrids[END_REF]. The forecast SEGAN: Sustainable Energy, Grids and Networks, vol. [START_REF] Li | A multiperiod energy acquisition model for a distribution company with distributed generation and interruptible load[END_REF] Where 9 ," … is the output power of PV array; and :

which are used to model the maximum output power and the irradiance are calculated in the standard test conditions; ? and ? ', ," describe the standard temperature and cell temperature, respectively; and † is a temperature coefficient. The equation (A.3) is used to consider the sum of the output power of WT and PV arrays in the RT power balance constraint as follows:

Appendix B: MPEC

In this Appendix the KKT conditions of the LL problems are described. The KKT conditions consist of four sets of equations which are presented as follows:

B.1. MPEC of the DA market problem

• Stationarity: To obtain the stationarity constraints, the lagrangian function is modeled using

‰ ! (ˆ) = 0 , i = 1, 2, . . . , 7 describes the equality constraints including ( 22), ( 23), (33), [START_REF] Tenfen | A mixed integer linear programming model for the energy management problem of microgrids[END_REF], and ( 37)-(39), and ) 6 ! (ˆ) ≥ 0 , j = 1, 2, … , 26 describes the inequality constraints including ( 24)-( 32) and ( 35)- [START_REF] Luenberger | Linear and nonlinear programming[END_REF]. By deriving from the proposed function related to each variable, the stationarity constraints are obtained as (B.3)-(B.11).

( ) ( ) ( ) ( ) ( )

, 0 0

, 0 0

Appendix C: Linearization of the cost of power exchange with the DA market

The non-linear term of equation (1) (0 P, _ ! 9 _ ! ) is linearized using the dual theory in this appendix. For this purpose, the dual of the DA problem is modeled as follows:

( ) Finally, the linear form of 0 P, _ ! 9 _ ! is obtained as (C.9).

( )

Appendix D: Linearization of the cost/revenue of power trading with the RT market

The cost/revenue of traded power with the RT market (0 P, ," _ 9 ," _ ) is a non-linear term and it cannot be linearized by dual theory. In other words, applying the approach utilized in SEGAN: Sustainable Energy, Grids and Networks, vol. 21, March 2020, Elsevier, doi : 10.1016/j.segan.2019.100292

DRAFT VERSION

Appendix C makes the objective function of the dual of the RT problem (it is similar to Eq.

C.1 with respective RT variables and parameters) non-linear. This is because of the DA maximum up/down regulation power of the Gencos and responsive TNLs in the RT market problem as variables in the single-level model. Therefore, an approximate approach is presented to linearize the mentioned non-linear term for comparing the results and models' attributes. The non-linear term 0 P, ," _ 9 ," _ can be replaced by F ," and F ," M as auxiliary variables and under some following constraints regarding [36, 37]. Also, ; -% is considered as a big value and the upper limit of the dual variable 0 P, ," _ .