Stochastic programming approach for optimal day-ahead market bidding curves of a microgrid

The deregulation of electricity markets has driven the need to optimise market bidding strategies, e.g. when and how much electricity to buy or sell, in order to gain an economic advantage in a competitive market environment. The present work aims to determine optimal day-ahead market bidding curves for a microgrid comprised of a battery, power generator, photovoltaic (PV) system and an electricity load from a commercial building. Existing day-ahead market bidding models heuristically fix price values for each allowed bidding curve point prior to the optimisation problem or relax limitations set by market rules on the number of price– quantity points per curve. In contrast, this work integrates the optimal selection of prices for the construction of day-ahead market bidding curves into the optimisation of the energy system schedule; aiming to further enhance the bidding curve accuracy while remaining feasible under present market rules. The examined optimisation problem is formulated as a mixed integer linear programming (MILP) model, embedded in a two-stage stochastic programming approach. Uncertainty is considered in the electricity price and the PV power. First stage decisions are day-ahead market bidding curves, while the overall objective is to minimise the expected operational cost of the microgrid. The bidding strategy derived is then examined through Monte Carlo simulations by comparing it against a deterministic approach and two alternative stochastic bidding approaches from literature.


Introduction
Over the last three decades, power systems have undergone a fundamental transition from centralised, vertically integrated towards decentralised, deregulated systems [1]. Deregulated systems based on market mechanisms are complex due to their competitive nature, but offer economic incentives to those participants with the best decision making in a present market set-up. Therefore, strategies need to be developed on how to optimally participate in relevant markets of the power sector. Moreover, political support to de-carbonise the energy sector will boost the adoption of renewable resources for power production [2,3]. Uncertainty involved in renewable energy supply poses a major challenge to decision makers in the power system. Thus, system operators need to secure more grid flexibility to handle the increase of uncertain energy supply, while energy market participants can adopt bidding strategies to hedge against rising market volatilities.
Decentralised energy networks such as microgrids have generated considerable research interest both in-and outside academia for their * Corresponding author.
E-mail address: l.papageorgiou@ucl.ac.uk (L.G. Papageorgiou). potential to provide reliable, low-emission energy and their capability to add flexibility to the power sector [4]. A microgrid can be defined as a group of interconnected loads and distributed energy resources acting as a single controllable unit [5]. The definition further includes a physical network for internal energy flows, advanced control technologies as well as the technical feature to operate decoupled from the grid, known as island mode [6]. Distributed energy resources deployed in the microgrid are small-scale power units that produce, store or release energy. These units produce efficient and predominantly green energy due to its close proximity to energy consumers and a high share of renewable energy [7]. Despite these benefits, the installation of microgrid systems faces the obstacle of high investment cost [8]. Hence, more research is needed to improve the economic viability of microgrid systems.
Several microgrid models were studied under economical perspectives in literature. Deterministic microgrid models such as in Refs.  11] assume accurate knowledge of data, but may fall short if data realisations deviate [12]. In contrast, microgrid models under uncertainty, such as in stochastic programming, hedge decisions against a predicted uncertainty space of data, derived from information available at the moment of decision making. Particularly, stochastic programming aims to find best decisions under uncertainty taking into account the expected objective value after the uncertainty is revealed. The uncertainty space can be approximated by a set of discrete realisations, called scenarios, which allow the optimisation problem to be transformed into a deterministic equivalent which can be solved with standard optimisation solvers [13]. A two-stage stochastic programming problem was formulated in Ref. [14] for the optimal energy dispatch of a microgrid with uncertain wind and solar power generation. Thomas et al. [15] analysed a stochastic microgrid model comprised of a stationary battery, a PV system with uncertain power output and controllable batteries from a fleet of electric vehicles. Grover-Silva et al. [16] studied a microgrid with thermal comfort constraints modelled as a two-stage stochastic programming problem with uncertainty in energy demand, ambiguous temperature and PV power. However, in the described references the electricity price was treated as perfectly known. Naturally, this assumption dismisses the need to extend microgrid optimisation problems with decisions on how to participate in electricity markets. Only a few researchers addressed the problem of bidding in electricity markets under uncertain electricity prices explicitly for microgrids [17][18][19][20][21].
Overall, electricity markets with different time resolutions and settlement periods are facilitated to maintain the power system energy balance at any time [1]. Electricity as a physical commodity can be traded in wholesale markets; services for grid balancing can be traded in reserve or auxiliary markets [22]. The focus of this work is in shortterm wholesale electricity markets with daily or shorter time horizons. These may include a day-ahead, intra-day and a real-time or balancing market. The day-ahead market handles bulk electricity, while intraday and real-time markets allow market participants to trade electricity closer to its actual delivery [22].
In the day-ahead market, market gate closure and market clearing take place on each day, but the settlement (here: delivery of electricity) happens on the day ahead. Fig. 1 illustrates this procedure by an example for the Electric Reliability Council of Texas's (ERCOT) day-ahead market [23]. Before gate closure, and for each discrete time block of the day ahead, market participants submit a collection of price-quantity points, known as a bidding curve. Each point expresses the willingness to buy (sell) a certain amount of electricity for a market clearing price below (above) or equal to a certain price threshold. Indicative bidding curves for buying or selling electricity in the ERCOT dayahead market are given in Fig. 2. The economic importance of bidding strategies in various short term electricity markets has been established in applications such as operating stand-alone batteries [24,25], large hydros [26][27][28], industrial demand side management [29][30][31], retailers [32,33] or virtual power plants [34][35][36]. For instance, Fleten and Pettersen [32] examined a two-stage stochastic programming problem of a retailer with price responsive demand. The optimisation goal was to determine piecewise linear bidding curves for buying electricity in the Nord Pool 1 day-ahead market. The authors demonstrated that more price-quantity points per curve result in equal or higher expected profit and that the profit gain per additionally activated price-quantity point tails off for larger values. Ottesen et al. [37] considered a twostage stochastic programming problem of an aggregator of prosumers. The aggregator controlled the prosumer's flexibility and covered the exchange of electricity with prosumers through bidding in the Nord Pool day-ahead electricity market and an additional balancing market. Krishnamurthy et al. [25] considered a stochastic optimisation problem of a stand-alone battery bidding in the ERCOT day-ahead electricity market. After market clearing a subsequent real-time market problem was solved. Results indicated that a single price-quantity point with an optimised bid price threshold resulted in higher profits than so called self-scheduled bids, whose bidding quantity materialises regardless of the market clearing price. However, their approach was limited to optimise only a single price-quantity point for buying or selling instead of multiple points forming a bidding curve.
This work considers a microgrid with a commercial electricity demand and its own resources for production and storage of electrical energy. Electricity exchange between the microgrid and the main grid is assumed to be facilitated via bidding into a day-ahead electricity market and a simplified real-time market. In this context, a novel mathematical model for bidding in the day-ahead market is formulated. The proposed model addresses a gap in research, which is to optimise simultaneously bid price thresholds and bid quantities of submitted buy or sell biding curves along with the recourse microgrid energy schedule. In particular, this model results in bidding curves that are guaranteed to be feasible under a market rule limit for the number of utilised price-quantity points per curve per time period.
The remainder of this paper is organised as follows: Section 2 describes the overall problem statement together with relevant assumptions. Section 3 presents the mathematical formulation of the proposed optimisation problem. It further describes the solution approach to evaluate obtained bidding decisions. In Section 4, the examined microgrid bidding model is tested in a computational study and results are discussed in Section 5 . Finally, in Section 6 concluding remarks are given.

Fig. 2.
Stepwise bidding curves (a) for buying electricity using three price-quantity points and (b) for selling electricity using four price-quantity points. An exemplaric market clearing at a market clearing price is illustrated in red.

Problem statement
This work considers a microgrid consisting of a battery, power generator, PV system and a commercial building with electricity load. Its internal electricity network is assumed to be perfect with no power flow losses or congestions. The microgrid system and technical parameters for all resources are given and remain unchanged, i.e. the microgrid optimisation problem is purely operational. The battery has constant charge/discharge efficiencies and degeneration is assumed to be linear proportional with respect to battery flow rates. Moreover, the battery storage starts and ends each day with a prefixed initial battery storage. The generator is assumed to have linear operational costs with no start up, shut down or minimum up and down times. Additionally, the gas price is assumed to be flat and perfectly known. Both electricity demand and the PV power are inflexible. They cannot be curtailed or shifted and hence need to be served instantly in the microgrid energy balance.
Energy exchange with the main grid is assumed to be unrestricted and facilitated through trading in the day-ahead and real-time market. The microgrid is assumed to be a price-taker in both electricity markets. Day-ahead market rules are based on the ERCOT day-ahead market: Stepwise bidding curves with up to 10 price-quantity points can be submitted for buying and selling electricity for each hour of the day ahead. Electricity prices are assumed to be uniform, i.e. accepted bidding quantities settle at the market clearing price rather than at submitted bid prices. Real-time market prices are hourly averaged to match the time resolution of the optimisation problem. Furthermore, the real-time market price is assumed to follow the day-ahead market price, but is considered to be less favourable for both buying and selling energy [18,37].
Uncertainty is considered in electricity prices and the PV power over the day ahead; electricity demand is assumed to be perfectly known. Decision stages are illustrated in Fig. 3. It is worth to mention, that real-time market prices and the PV power reveal gradually over the day ahead, but are simplified to a single stage in the decision tree. The overall problem can be stated as follows: Given are (a) battery initial state of charge, minimum and maximum storage capacity, charge and discharge capacity, charge and discharge efficiency, degradation cost (b) generator capacity, heat-to-power ratio (c) gas price, (d) electricity demand, (e) scenarios for PV power, (f) scenarios for day-ahead market electricity price, (g) real-time market price, (h) market rules for bidding curves; determine (a) day-ahead market bidding curves for buying and selling electricity, (b) battery schedule, (c) generator schedule, (d) real-time market bidding; so as to minimise total microgrid operational cost.

Mathematical model
The microgrid bidding problem is formulated as a two-stage stochastic MILP model. The goal is to find optimal bidding curves as first stage decisions minimising the microgrid operational costs subject to internal energy balances, resource constraints and electricity market rules. The time horizon is the day ahead discretised into equidistant, hourly time intervals ∈ . Scenarios for day-ahead market electricity price and PV power output are jointly represented by scenario set with index ∈ . The notation of the mathematical model is given as follows:  3.2. Microgrid energy system

Battery constraints
The battery storage ( ) in scenario at time is determined by the battery storage at the previous time point adding the amount of charged electricity accumulated from charge rate , with efficiency and subtracting the amount of discharged electricity accumulated from discharge rate , with efficiency over time step length .
where 0 is the initial battery storage at the beginning of the time horizon. Moreover, the battery storage cannot exceed its capacity , and must not fall below a minimum storage , at any time of scenario .
Furthermore, the battery storage at the end of the time horizon in scenario must be greater or equal to the initial battery storage.
Charging and discharging the battery at the same time in scenario is not allowed.
where binary variable , equals one if the battery is charging at time of scenario , zero otherwise. Similarly, binary variable , equals one if the battery is discharging at time of scenario , zero otherwise. If the battery is in (dis)charge mode at time of scenario , it cannot exceed its maximum (dis)charge rate . Otherwise, its (dis)charge rate must be zero.
To reduce long-term battery degradation the battery is not allowed to charge or discharge more than a multiplier of its storage capacity over the time horizon in scenario .

Generator constraints
The generator electricity output cannot exceed its capacity at any time of scenario :

Microgrid energy balance
An internal energy balance illustrated in Fig. 4 is applied to match electricity supply and demand within the microgrid at time of scenario . The left hand side of the balance equation represents electricity supply, namely battery discharging, generator electricity output, PV power ( ) as well as electricity bought in the day-ahead market ( , ) and real-time market ( , ). The right hand side of the balance equation represents electricity consumption, namely battery charging, electricity demand ( ) as well as electricity sold in the day-ahead market ( , ) and real-time market ( , ). Note, that the battery does not actually consume or produce electricity in the microgrid, but is treated as such from the perspective of the energy balance boundary.
R. Herding et al.

Day-ahead market bidding
The day-ahead market requires particular market rules to hold for the bidding decisions determined by the stochastic optimisation. The following set of bidding constraints are inspired by the ERCOT day-ahead market.

Monotonicity constraints
Bidding curves for buying (selling) electricity have to be monotonically decreasing (increasing). Therefore, buy (sell) quantity of the bidding curve at day-ahead market price of scenario at time has to be equal or larger than the quantity of its closest but higher (lower) price of scenario ′ .
where represents the order of scenario from low to high dayahead market electricity prices at time , = max ( ) represents its maximum at time , positive slack variables , and , represent the incremental quantity increase of the bidding curve at time for buying and selling electricity at day-ahead market electricity price of scenario . Subset represents scenarios with distinct dayahead market electricity price values at time , i.e. let , ′ ∈ at time then ≠ ′ ≠ , .

Nonanticipativity constraints
To respect nonanticipativity of the uncertainty ahead when bidding curves are decided, a certain realisation of an electricity price must imply a certain accepted quantity after market clearing [13]. This guarantees that committed buy (sell) bid quantities over the scenario set at time root from a single buy (sell) bidding curve submitted for this hour as stage one decision that can be unambiguously constructed using the solution of , ( , ). Therefore, buy (sell) quantities at day-ahead market electricity prices of scenario and ′ have to be equal if prices of both scenarios are the same at time .

Price-quantity point limit constraints
If the bid quantity at day-ahead market electricity price of scenario of the bidding curve for buying (selling) at time increases incrementally by , ( , ), it represents an active price-quantity where , and , are sufficiently large values and binary variable , ( , ) equals one if the bid quantity at day-ahead market electricity price of scenario increases incrementally and forms an active price-quantity point of the bidding curve for buying (selling) at time . Conversely, we label a bid point as inactive if its bid quantity does not increase incrementally and binary variable , ( , ) equals zero. Fig. 5 illustrates the mathematical construction of an inactive and active price-quantity point for a generic buy bidding curve. Notice that inactive price-quantity points add no information to bidding curves, hence are redundant once a bidding solution has been obtained. Consequently, bidding curves as first stage decisions can be expressed in a compact form by for selling for each time .
Electricity markets often restrict the number of points per bidding curve. Thus, the sum of active price-quantity points of the bidding curve for buying (selling) electricity at time is not allowed to exceed points per curve.
where the value of is determined by market rules, for instance = 10 in the ERCOT or the California Independent System Operator (CAISO) day-ahead market. An illustrative example of a feasible solution for a buy bidding curve together with numerical values is provided in Fig. 6.

Simultaneous buy and sell bid constraints
Although both buy and sell bidding curves can be submitted together at time , only one should be activated in a certain market clearing outcome. This requirement can be violated if the price of a sell bidding curve point falls below the price of a buy bidding curve point, and the day-ahead market price clears in between both prices. Auxiliary variables , and , are introduced to represent the highest price value of active price-quantity points of the bidding curve for buying R. Herding et al.
where is a sufficiently large value. In case all price-quantity points of the buy (sell) bidding curve at time are inactive, these logical constraints are non-binding.
Due to the monotonicity property enforced in Eqs. (12)- (15), it is sufficient that the highest price value of active price-quantity points of the bidding curve for buying has to be lower than the lowest price value of active price-quantity points of the bidding curve for selling at time .
where a small positive number ensures strict inequality.

Objective function
The objective function aims to minimise the expected total cost of the microgrid over the day ahead. The total cost of each scenario with probability comprises four terms: Battery degradation cost (O1) is the product of degradation cost , with the sum of charging and discharging over the day ahead in scenario . Generator fuel cost (O2) is calculated from flat gas price charged for the generator heat input, which is its total electricity output over the day ahead in scenario multiplied with the generator heat rate . Day-ahead market net cost (O3) is calculated as the sum of the product between the net of electricity bought minus electricity sold in the day-ahead market and its day-ahead market electricity price over the day ahead in scenario .
where real-time market prices of scenario at time are calculated as: Parameter determines the extent of premium charge that is assumed to be paid for electricity traded in the real-time market. Notice that the objective function Eq. (25) can be easily transformed into a profit maximisation problem by considering max , where represents total profit and = − .

Overview of optimisation models
The proposed stochastic optimisation problem for bidding is referred as the SN-model. This shortcut expresses that price values can be selected via logical constraints out of about | ℎ | price values available in the stochastic optimisation to construct bidding curves for the microgrid. Additionally, SN10 refers to the SN-model with parameter value = 10, expressing a limit of ten bid points per bidding curve in the day-ahead market. We further investigate the SN-model with = 3 and = 5, denoted as SN3, SN5. It is benchmarked against a deterministic model denoted as Det-model, which is outlined in Appendix A. Furthermore, we compare the SN-model with two alternative stochastic bidding approaches from literature denoted as S-model and N-model outlined in Appendix B. The Det-model is scenario independent using expected values of uncertain parameters. Also, it features a simplified bidding approach using self-scheduled bids, whose bid-quantities materialise independent of the electricity price realisation. Besides, key feature of the S-model is a relaxation of constraints on the number of active price-quantity points utilised per bidding curves. Key feature of the N-model is a heuristic that preselects | | price thresholds for the construction of bidding curve points in the stochastic optimisation. We use shortcuts N3, N5, N10 to refer to the N-model with | | = 3, | | = 5 and | | = 10 prefixed bid price values per time period. Essentially, all examined stochastic bidding models share the same microgrid energy system constraints, but use different constraints for the day-ahead market bidding. Table 1 provides an overview of all considered optimisation problems.

Solution approach
A solution procedure was applied to evaluate day-ahead market bidding decisions for a particular day. The procedure is summarised in Fig. 7. Scenario sets were generated per random variable for the uncertainty of the day ahead and then combined to a scenario tree. Two scenario sets were drawn randomly without replacement from the super set: a set for the stochastic optimisation and a set for the Monte Carlo (MC) simulation denoted as ℎ and , respectively. The stochastic optimisation problem was solved and day-ahead market bidding curves as first stage decisions were obtained. In case of the deterministic benchmark, the deterministic optimisation problem was solved instead and self-scheduled bids were obtained. Bidding decisions for the day-ahead market were then locked and tested through a Monte Carlo simulation using . The Monte Carlo simulation is conducted as follows: Reveal uncertainty in form of scenario ∈ : (i) obtain realisation of random variables: ← and̂← (ii) determine day-ahead market commitments: , ← ClearBuyCurves( ,̂) , ← ClearSellCurves( ,̂) where and represent submitted bidding curves at time (iii) solve Det-model with fixed̂, and̂, , minimising total cost̂( iv) store optimal total cost as: Monte Carlo objective value ←( v) reveal next and go back to (i); stop when entire is covered Pseudocodes for ClearBuyCurves(⋅) and ClearSellCurves(⋅) are described by Algorithms C.1 and C.2 in Appendix C, respectively. The Monte Carlo mean objective value is obtained as the average of total costs over : It is worth noting that the out-of-sample test was conducted using simulated realisations of random variables rather than their actual observations over the day. By simplifying the test environment and keeping scenario generation simple, the focus of this work remained on the actual decision making process represented through different microgrid bidding models. It further allowed testing of bidding decisions under a significant number of possible realisations.

Computational study
In this section, a computational study is conducted to demonstrate the applicability of the proposed stochastic optimisation problem to generate bidding curves for a day-ahead electricity market. The solution procedure in Fig. 7 is applied for each day of two separate weeks with different time series characteristics. They are denoted as test week 1 (TW1) and test week 2 (TW2): • Test Week 1: Date range 05/03/2019 -11/03/2019 (high electricity price peaks and volatility, lower PV power, higher electricity demand) • Test Week 2: Date range 05/11/2019 -11/11/2019 (low electricity price peaks and volatility, higher PV power, lower electricity demand) Each day of the two weeks is characterised by predicted uncertainty spaces for the day-ahead electricity price and PV power as well as observed demand profiles. Furthermore, the cyclicity assumption of the battery to start each day with a fixed initial storage allows to apply the presented solution procedure for each day independently.

Input data
PV power data with a maximum power of 300 kW were simulated from global horizontal irradiance data obtained from the National Solar Radiation Data Base of the National Renewable Energy Laboratory [42]. For the sake of simplicity, temperature dependency of the PV power was neglected. Day-ahead market electricity price data were taken from the ERCOT Houston zone. Electricity demand data were received from the industrial partner. Parameter values of the battery are summarised in Table 2 and parameter values of the generator are summarised in Table 3. Real-time market prices were considered to be 20 % less favourable than day-ahead market prices, which is similar to Ref. [43] but lower than for instance in Ref. [41].

Scenario generation
Scenarios for the day-ahead market electricity price were obtained from our industrial partner, whose generation method was based on a stochastic differential equation approach. Reported scenarios with a look-back window of 30 days and a weighting approach on prior days were considered [44]. PV power scenarios were generated from a seasonal autoregressive integrated moving average (SARIMA) model. SARIMA models can be generally expressed by hyperparameters ( , , ) ( , , ) , where represents the order of autoregressive parameters, is the integration order, is the order of moving average parameters and , , are their seasonal equivalents with seasonality order [45]. SARIMA models were then identified as (0, 1, 2) (0, 1, 1) 24 for TW1 and (1, 0, 0) (0, 1, 1) 24 for TW2 based on correlation and autocorrelation plots on the training data. Model training was performed on historical PV power data from a look-back window of 35 days. Once a model had been trained, a point forecast̃for the PV power over the day ahead was generated. In addition, univariate normal distributions  ( , ) for each 'hour of the day' were retrieved from the forecast error over the training data, thus resulting in 24 individual error distributions per day. For instance,  =5 represents the forecast error distribution observed over the fifth hour of all days from the training data.
Finally, PV power scenarios were generated by the summation of point forecast at time and error values sampled for each from the forecast error distributions: In total, 1000 PV power scenarios and 1000 day-ahead market electricity price scenarios were generated for each day. From the permuted scenario tree with cardinality of 1M scenarios, 400 scenarios were randomly drawn for the stochastic optimisation and 10k scenarios for the Monte Carlo simulation.

Seasonal characteristics of test week data
Test weeks TW1 and TW2 feature different seasonal characteristics of electricity demand data, electricity price scenarios and PV power scenarios under which the microgrid bidding strategy is examined. Demand profiles displayed in Fig. 8 indicate that electricity demand was generally higher in TW1 compared to TW2. Moreover, it can be seen that demand profiles of non-working days such as weekends are characterised by a much lower, flat profile compared to regular working days. Furthermore, Fig. 9 displays hourly mean values and Fig. 10 displays hourly standard deviation of scenario sets used in the  stochastic optimisation. Key differences between both test weeks are higher mean price peaks on the majority of days in TW1 compared to TW2, with peaks occurring around 6 to 8 a.m. and 17 to 19 a.m.; significantly higher electricity price variability in TW1 around time periods of price peaks; lower mean PV power in TW1 compared to TW2 but a similar variability around its scenario mean.

Computational environment
All calculations were executed on an Intel Xeon Processor E5-1650 v3 @ 3.5 GHz with 32 GB memory. SARIMA models were implemented in Python and their training was performed through the Statsmodels package version 0.12.1 [46]. Optimisation problems were modelled in GAMS 27.1.0 and solved with CPLEX 12.9.0.0.. Termination criteria for all optimisations were set to one hour CPU time limit or global optimality.

Results and discussion
In this section, objective values are displayed as 'profit' rather than 'cost' values for a more intuitive discussion, because total cost values from the microgrid bidding were often found to be negative.

Value of stochastic solution
In general, results demonstrate that bidding curves obtained from stochastic microgrid models outperformed self-scheduled bids obtained from the deterministic microgrid model. This can be seen in Fig. 11, which compares daily average Monte Carlo mean objective values from R. Herding et al. test days in TW1 and TW2 for each microgrid bidding model. From the displayed profit values, the value of stochastic solution can be calculated as the difference between Monte Carlo mean objective values of a stochastic solution for microgrid bidding (N-, S-or SN-model) and of the deterministic solution using expected values for uncertain parameters (Det-model) [13]. The average value of stochastic solution for the SN10-model was 5.01 $ per test day in TW1, which is a profit increase well over 40 % on the deterministic solution (see Fig. Fig. 11). The average value of stochastic solution in TW2 was 3.96 $ per test day, which corresponds to a profit increase of above 20 % on the deterministic solution (see Fig. Fig. 11). Table 4 indicates that stochastic solutions generally led to higher profits in the day-ahead market compared to the deterministic solution. By contrast, the deterministic solution lead on average to small profits in the real-time market, while all stochastic solutions observed minor losses. Consequently, stochastic models most likely took advantage of information in ℎ and the flexibility of bidding curves to balance moderate real-time market cost against higher profits in the day-ahead market.

Comparison of stochastic bidding models
As stated earlier, the SN-model has been designed to optimally utilise multiple price-quantity points of constructed microgrid bidding curves without exceeding a maximum point number imposed by market rules. It is important to reiterate that the S-model is a relaxation of the proposed SN-model. Thus, it is likely to provide an upper bound for the expected profit of the SN-model solution. Therefore, the aim of the SN-model should be to perform as close as possible to the S-model in terms of profit. Fig. 11 reveals that average profits from the SN-model solutions were exceptionally close to profit values from the S-model solution.
Hence, for the examined test days of both weeks the SN-model successfully compressed the number of active price-quantity points per bidding curve per time period into a market-feasible range as well as enforced with only minor additional cost compared to the Smodel. This observation is further stressed in Figs. 12 and 13 which visualises normalised profit values for each test week on a daily resolution. The normalisation was conducted with min and max profit values per day across all microgrid bidding models, whose underlying numerical values are given in Table C.1 of Appendix C. For instance, Fig. 12 shows that on six out of seven days SNmodel solutions performed above 0.95 normalised profit, i.e. close to  Notably, only on the first day of TW1 the S-model did not lead the profit value ranking, which may partly be caused by a generally tight range of profit values between different bidding models on this particular day.
Moreover, SN-model solutions performed on average better than N-model solutions. Particularly, daily average profits from the SN10model were 2 % greater than from the N10-model in TW1 and more than 8 % greater in TW2. Also, the SN-model demonstrated a better resilience against tighter limits on the number of price-quantity pairs compared to the N-model. This can be visually observed for both test weeks in Figs. 12 and 13, in which the spread between profit values from the N3-and N10-model was larger than from the SN3-and SN10model in the majority of days. It is reasonable to argue that profit reductions from allowing fewer price-quantity points per bidding curve were damped through the optimisation of bid price values for bidding curves in the SN-model compared to the heuristical approach of fixing bid price values using the N-model. Furthermore, the squeezing effect of the three SN-models on the utilised number of price-quantity points is visualised in Fig. 14. As expected, point numbers utilised by the S-model were usually higher and repeatedly exceeded the point cap of ten points per curve that is required by ERCOT market rules. This is due to the absence of logical constraints in the S-model on the maximum number of points per bidding curve and the requirement of . For instance, buy bidding curve in the first hour of TW1 contained eleven price-quantity points (see Fig. 14), but quantity values of these points were in close range of one another, between 87.8 kW − 99.5 kW. Also, it can be seen that bidding curves from the SN10-model frequently utilised fewer R. Herding et al.    points than the present limitation of ten points per curve. This suggests that the examined microgrid usually did not need the full cardinality of ten price-quantity points to express its optimal bidding decisions. However, in as many as six out of seven days in TW2 sell bidding curves of the SN10-model solution utilised their upper limit of ten points at least once during each day (see Fig. 14). As an example, bidding curves of the SN3-and SN10-model solution from the fourth day of TW2 are shown in Fig. 15 for buying and in Fig. 16 for selling electricity.

Computational results
The SN3-, SN5-and SN10-model consisted of around 130 000 equations and 132 000 variables (32 570 were binary). They were solved on average to 1.56 %, 1.03 % and 0.95 % optimality gap, respectively. Full computational statistics including for reference bidding models are given in Table C.2 of Appendix C. Results demonstrate that near optimal solutions for the SN-models were found within an acceptable time range of up to one hour. This was achieved despite a larger model size of SN-models, which incorporates additional market rules and the optimal selection of bid prices, compared to reference bidding models for the same scenario set and microgrid energy system.

Expected microgrid energy balance
Expected electricity flows of the microgrids internal energy balance obtained from the Monte Carlo simulation of the SN10-model solution are displayed in Fig. 17. Electricity leaving the energy balance boundary is represented by a negative sign. Electricity was most likely bought from electricity markets early in the day to charge up the battery at low electricity prices, late in the day to recharge the initial battery storage, and occasionally on work-days in TW1 around noon to satisfy electricity demand. Electricity was most likely sold to the dayahead market at peak electricity prices in the morning and during late afternoon. This electricity was usually provided by battery discharge and the generator. Furthermore, electricity was sold throughout the day on weekend days due to low electricity demand or on work-days when excess PV power could not be stored in the battery (see hours 0-23 in Fig. 17) or when the generator became active (see hours 0-47 in Fig. 17). Due to higher PV power and lower demand profiles in TW2, more excess electricity was sold to electricity markets compared to TW1.
In both test weeks, the generator was occasionally activated as a back up to satisfy electricity demand at times of low PV power. Additionally, it was activated to sell electricity to markets when electricity prices exceeded the generators marginal cost. Finally, real-time market trades for the SN10-model solution were most likely for buying R. Herding et al.  electricity in the morning, but traded quantities were generally low throughout each day.

Concluding remarks
In this work, the day-ahead market bidding problem of a microgrid consisting of a battery, generator, PV system and electricity demand has been addressed. A two-stage stochastic MILP model has been developed with uncertainty considered in the electricity market price and PV power. A particular focus of the proposed microgrid bidding model is the optimal selection of price values for day-ahead market bidding curves that are optimised together with the microgrid's energy schedule. Microgrid bidding decisions have been evaluated on a large set of possible realisations through a Monte Carlo simulation. In a computational study, the evaluation procedure has been applied for each day of two separate test weeks with different seasonal characteristics of underlying time series data.
Results demonstrate a higher profitability of the proposed bidding model compared to a deterministic benchmark model that relies on self-scheduled bids. Also, it has achieved higher profits than a bidding approach from literature that relies on equidistantly fixed price values to construct bidding curves. Furthermore, the proposed bidding model has kept the number of price-quantity points per bidding curve successfully in a market-feasible range with only minor additional cost and a moderate increase of computational time. The computational time could potentially be further reduced by scenario reduction methods. Finally, the optimisation of price values to construct bidding curves has lead to a strong resilience of profit from the energy system against a compression of bidding curves towards fewer price-quantity points. These advantages offer potential to use the examined bidding approach for other energy systems that would benefit from multiple price-quantity points in their bidding curves, but would need to curb the number of utilised bid points per curve to a market feasible range. Obtained results have been subject to model assumptions that may be improved in future works. Real-time market bidding and its price uncertainty could be modelled in more detail to take advantage from profit opportunities in different markets. Also, future work could extend the presented microgrid bidding problem to a multi-objective approach, in which optimal bidding curves strike a balance between total cost and the financial risk of potentially high, undesirable losses from participating in electricity markets.

Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Data availability
The data that has been used is confidential.
This section outlines the deterministic microgrid optimisation problem, denoted as Det-model. It uses an analogue notation to the stochastic microgrid model. However, it drops the scenario index out of variable and equation domains. In addition, all variables from the deterministic model are marked with a hat decorator. For instance, battery charge rate , is expressed aŝ, in the deterministic model. The deterministic microgrid optimisation problem is used in the following two circumstances within this work: The Det-model is applied before uncertainty reveals. Here, random variables at time are considered as their expected values calculated over the set of stochastic scenarios: Particularly, in this case first stage bidding decisionŝ, and̂, are considered as self-scheduled bids which materialise unconditionally for any realisation of day-ahead market electricity price at time . Furthermore, the Det-model is applied after uncertainty revealed, and first stage bidding decisions for the day-ahead market had already been logged in. In this casêrepresent revealed realisations of the day-ahead market electricity price,̂represent revealed PV power at time , and̂, and̂, represent revealed real-time market prices for buying and selling following assumptions in Eqs. (26)- (27). Moreover,̂, and̂, represent quantities that are obligated to be served at time as a result of the market clearing of submitted bidding decisions. Because these quantities are binding, their values are fixed constants in the optimisation problem. In both described situations the following deterministic microgrid optimisation problem is solved:

B.2. N-model approach
This stochastic bidding approach assumes a discrete number of price levels ∈  , each with a fixed price value at time . Therefore, we  [26,27,32,33,37,40,41]. Price values must be fixed prior to the stochastic optimisation through a heuristic. In this work, values for were fixed equidistantly between a min and max value [26,37]. Min and max values were derived from day-ahead market electricity prices over ℎ for each time : continuous variables representing the bid quantity for buying (selling) at price value of price level at time . The market clearing logic that selects point and its attached bid quantity , from the stepwise bidding curve to be accepted in scenario can be preprocessed for given day-ahead market electricity prices and expressed as follows: The N-model for the microgrid bidding is comprised of energy system Eqs.