## 1 Introduction
For example, VPPs in [19; 20; 21; 22; 23; 24] use the BE market to correct energy deviations to their day-ahead schedule due to the inherent uncertainties in RES and loads. In this case, VPP only expects to profit from the DA market while trying to minimize the penalty cost in the BE market. However, based on advanced information, communication technology, and control systems, VPP can now integrate many RES, ESS, and loads, so its size becomes large. In addition, due to the advantages of ESS, such as a fast response time, a high ramp rate, and the ability to adjust power output up or down flexibly [28; 29; 30], VPP can easily meet the BC market's requirements and become an active reserve provider. Thus, in VPP operations, ESS plays a considerable role. In coordinating resources and customers within VPP, ESS compensates for the difference between the predicted and actual power of RES and demand. In the DA market, ESS will store electricity during low-priced hours and discharge during high-priced hours; consequently, VPP can profit from energy arbitrage. In the balancing market, ESS is also an effective source, providing a part of VPP's upward/downward reserve. A proper optimal scheduling model can ensure that ESS performs well in the above roles. Unfortunately, in recent studies, the role of ESS has not been emphasized. In [31; 32; 33; 34; 35], VPP acts as a reserve provider (RP) that always holds a part of its capacity available to make adjustments if needed. In [36], the authors propose a trading strategy in which VPP can be both passive and active agents to get more profit based on the dual-price formation of the balancing market. However, in these studies, the VPP's upward/downward reserve provision ability is almost based on the capacity adjustment of REs and flexible demand. As in [37; 38], VPPs provide peak shaving and valley filling services for a distribution system, where providing peak regulation service is the ESS's sole role. Few studies consider the role of an ESS in both energy and reserve markets [39; 40; 41; 42]. It is easy to see that an ESS can provide upward reserve in several ways: increasing discharging power, reducing charging power, or even changing ESS status from charging to discharging. Similarly, a downward reserve can be provided by increasing charging power, reducing discharging power, or changing ESS status from discharging to charging. To the best of our knowledge, very few studies pay attention to all of these ways. In [39; 40; 41], ESSs only provide upward reserve by increasing discharging power and downward reserve by increasing charging power. Ref. [42] considers the reserve provision by switching the ESS state from charging to discharging and vice versa. However, the authors are only interested in the ability to adjust the ESS's power output without considering that providing reserves will cause the ESS's energy to change; consequently, the ESS's operating plan in the energy market will differ from the original one. In other words, this study only considers the provision of the reserve at an opportunity level without considering its realization. This paper proposes a two-stage optimal scheduling model of a VPP, including RESs, ESSs, and flexible demand. The VPP not only participates in the DA market but also plays an active role in the BE market. Assuming that VPP has a pre-signed upward reserve capacity contract in the BC market, the VPP's optimal trading strategy in the DA and BE markets is determined to maximize the VPP's profit while satisfying the BC contract's requirements. Besides the reserve energy RESs provide, the ESSs' ability to provide upward/downward reserve provision is also determined. The VPP's optimal scheduling model is formulated as a two-stage stochastic optimization problem to account for the uncertainty in RESs' available power output and demand. In addition, note that VPP's must submit a trading plan to the market operator at least one day before the actual operation date in the DA market and from one to several hours before the operating hour in the BE market.