Stochastic nonlinear modelling and application of price-based energy ﬂ exibility

(cid:129) A generic method for characterising energy ﬂ exibility is developed. (cid:129) It is applied to characterise the energy ﬂ exibility of water towers and buildings. (cid:129) The resulting model is used to do price-based control of the two systems. (cid:129) It is shown to achieve between 62% and 98% of the potential energy ﬂ exibility. energy exibility with the increased of renewable energy. Utilising it necessitates mathematical models of the operational response of energy ﬂ exible consumers. In this paper we present an accurate and general dynamic model of energy ﬂ exibility based on stochastic di ﬀ erential equations. The intuitive interpretation of the parameters is explained, to show the generality of the proposed model. To validate the approach, the parameters are estimated for three water towers and three buildings controlled by economic model predictive controllers. The model is then used to o ﬀ er the energy ﬂ exibility on the current electricity market of Scandinavia, Nord Pool, using the so called “ ﬂ exi orders ” . Finally, the energy ﬂ exibility is used by controlling the demand of the water towers indirectly, through price signals designed based on the proposed model. Compared to having perfect foresight of electricity prices and future demand, between 63% and 98% of the potential savings were obtained in for these case studies. This shows that even without direct control of energy ﬂ exible systems, most of the potential can be reached under the current market conditions.


Introduction
Accompanying the ever increasing share of Renewable Energy Source(RESs) is the challenge of controlling energy generation and matching it to energy demand [1]. Historically, demand has been the main source of uncertainty for energy grid operators [2], but now the challenge gets steeper with the uncertainty of RESs added to the equation [3]. Furthermore, for electricity grids, the amount of synchronous generators is decreasing, limiting the available sources of control [4]. All in all, energy grids are faced with the challenge of increasing uncertainty and decreasing controllability. To counteract this, new ways of controlling either energy generation or demand have to be designed. On the generation side, it is possible to control RESs to some extent [5]. Unfortunately, while generation coming from energy sources such as wind and solar can be turned down, it cannot be turned up, as it is limited by the given wind and radiation conditions. Thus, on the generation side, the only solution for providing electricity when sun and wind are insufficient is to produce it using other energy sources.
https://doi.org/10.1016/j.apenergy.2020.115096 Received 15 November 2019; Received in revised form 4 April 2020; Accepted 26 April 2020 Therefore, the controllability ought to be found on the demand side [6]. Part of this controllability will come from storage solutions [7], but the potential from regular demand should be utilised as well [8].
Here, reducing demand has the same effect as increasing supply. Of course, the total amount of energy use is not expected to decrease, so reducing demand at one point in time translates into an increased demand during other periods. Furthermore, while it is easy to predict how much power a generator can supply [9], it is less straightforward to know how flexible energy demand can be. For instance, if the heating of a smart home is done in a flexible way, then the amount of flexibility varies depending on how it is being used [10]. If, for example, a home owner is having a party, then the range of allowed temperatures is probably smaller than if the owner was at work. This implies that the trouble resides not only in estimating how much flexibility is available, but also in agreeing on who is in charge of using it. The compensation required to persuade a home owner to have his heating being performed in a flexible way is highly dependent on the usage of the home [11]. Likewise, a system such as a wastewater treatment plant can provide a lot of energy flexibility most of the time, but during heavy rain it will be able to provide almost none [12], since it is more important to avoid waste water in the streets. For this reason, the owners of many energy flexible systems will not be willing to give up control to energy grid operators such as Dis-tribution System Operators (DSOs) and Transmission System Operators (TSOs), since they cannot trust the grid operators to know how to control the systems adequately. For this reason, most energy flexibility is expected to be made available through indirect price-based control [13]. In this case, instead of controlling the energy flexibility directly, grid operators or aggregators will send varying prices, based on some contractual agreements [14], to the energy flexible systems that they then react to as they please [15]. It is still expected that energy flexible systems will be automatically controlled [16], but in the end the owner has full autonomy. This approach comes with its own challenges, such as what to do when no one wants to be flexible and the uncertainty of the response to changing prices. The challenge is to understand energy flexibility. This have been investigated using a bottom-up approach for domestic households [17], with focus on thermal loads in [18] and activity patterns in [2]. However, while this gives insights into the physical capabilities of particular appliances, it does not address the fundamental challenge, namely to estimate the expected response for a given sequence of prices. This requires a top-down approach, where energy flexibility is estimated from data. One such approach was presented in [19] where reliability and potential was estimated from data. However, in order to combine the different aspects, system identification is needed to estimate the full dynamics of the energy flexibility. In [20] this topic was explored, where the relation between prices and change in demand was assumed to be linear and time-invariant. This allows for easy interpretation of the energy flexibility through the step-response, termed the Flexibility Function. It was also suggested that the only objective metric, with which to judge energy flexibility is in economic terms. The present paper sticks with this suggestion, and ultimately values the quality of the developed model in terms of economic value.
However, the linearity assumption limits the possibility for applications significantly, and so, in this paper, a nonlinear, and more realistic, model of energy flexibility is developed, preserving the intuitive flexibility characteristics noted in [20]. The goal is the same; to characterise energy flexibility, but the method and resulting model are both completely different, taking an idea and turning it into a useful tool. A first taste of this was given already in [21], where a nonlinear flexibility function was made, based on physical characteristics of a district heating system. In this paper it is shown how a nonlinear flexibility function can be estimated from data, coming from two very different kinds of systems, building heating systems and water towers. Given that the resulting model describes both kinds of systems accurately, it is expected to be useful for a wide range of systems.
The paper starts by presenting the developed model in Section 2, where the justification and interpretation of all parts are included as well. Next, a case study is presented in Section 3, consisting of three economically controlled water towers located within the Scandinavian power market. In Section 4 the parameters of the developed model are estimated for both the water towers and the buildings and subsequently the energy flexibility is bid into the day-ahead market of Nord Pool in 4.2. Finally, the findings are summarised in Section 5 and perspectives for future work are discussed in Section 6. Secondary mathematical details can be found in the Appendix.

Energy flexibility model
This section presents the complete model for characterising energy flexibility. Given the extent of this section, first the whole model structure is presented, and afterwards, each part is explained thoroughly. The model is based on a combination of physical and mathematical considerations. This means that some parameters have direct physical interpretations, while others have to be interpreted more carefully.
The model is based on the variables presented in Table 1, where they have all been normalised to be between 0 and 1, to ease notation. The general formulation of the proposed model is given by (1)-(4): where W is a Wiener process [22,23] and ∊ ∀ ∈ i i d k (0, 1 ) . . . . is the indicator function, which is equal to 1 when the input is true and equal to 0 when the input is false e.g.: , , X and σ Y are parameters, that, together with the functions l f , and g characterise the energy flexibility of a price-controlled system. As summarised by Table 1, the model consists of 1 state, X, governed by the stochastic differential Eq. (1); B and u are inputs; Y represents the observations governed by Eq. (4); finally, two algebraic equations, (2) and (3), that link the value of the state and inputs to the output for each time step. An overview of the parameters and their interpretation can be seen in Table 2.

The state equation
The interpretation of the state at time t X , t , is the state of charge of the energy flexible system, where = X 0 t means that it has no stored energy and thus cannot reduce its energy consumption. Likewise, = X 1 t means that it currently holds the maximum amount of energy possible, and thus cannot increase its consumption. For a temperaturecontrolled building this could be translated into the temperature having reached the lowest or highest allowed comfort levels respectively. Even Demand Observation Power more straight forward, as shown in this paper, X t could be proportional to the amount of water in a water tower, with = X 0 t meaning that it is empty and = X 1 t that it is full. This assumption is motivated by physics, and holds true for single-fuel systems with efficiency independent of its operation. In practice efficiency depends on operation, but for many systems this can be ignored. The underlying assumption of the model is that, at a certain point in time, the energy demand of a priceresponsive energy system is described by the price and state of charge at that time. Thus, (1)-(4) are simply predicting future values of the state of charge and the demand.
Assume that constant average prices would lead to a demand of B t at time t, then this can be considered the baseline demand. If energy efficiency is unaffected by the energy consumption, then the state of charge increases whenever demand surpasses the baseline demand and decreases whenever the demand is lower than the baseline. This is described by the first term of (1), where the parameter C determines how fast the change in state of charge happens. As already mentioned it will be ensured that , and since changing X t from 0 to 1, in T time units, requires that ∫ , the total amount of flexible energy is equal to C. Naturally, any energy consuming system will have an upper bound on how much power it can consume at any given time, which is usually obtained by turning on everything at maximum capacity. Similarly there is a natural minimum consumption, which is usually when everything is turned off, or at least when all flexible components are turned off. For convenience Y t can be assumed to be normalised such that = Y 1 t means that the maximum demand is observed at time t and, similarly, the minimum when = Y 0 t . Now, the second term describes the process noise, which can stem from unexpected behaviour of the system, model deficiencies and errors in the assumed baseline demand; where, the latter is expected to be the main contributor in the system noise. These inaccuracies of the estimated baseline demand stem from the fact that it is not possible to know exactly what the baseline is. Notice that the exact same problem is experienced for today's energy systems, where the task of predicting demand is exactly the same as predicting baseline demand in this case. The noise intensity is proportional to the parameter σ X , which is estimated, but also to the term The latter term is there to reflect that it is not possible for the state of charge to leave the interval [0, 1], and thus the noise has to go to zero when the system approaches the edges of the interval, so that it cannot push the state of charge out of bounds. This is a realistic assumption, since it is expected that prolonged high prices will push the state of charge close to the minimum and similarly prolonged low prices will push it close to the maximum with high certainty. On the other hand, with medium-sized prices, the exact state of charge is expected to be somewhere close to the middle, but it is very difficult to estimate the exact value in this case.

Linking demand to state of charge and price
Moving on to (2), δ t can be interpreted as the change in demand from the baseline, due to energy flexibility. This part of the model is based on the following three assumptions: 1. High prices tend to reduce demand, and vice versa for low prices.
2. A lot of stored energy tends to reduce demand and vice versa for low amounts of stored energy. 3. Only a finite amount of energy can be stored in the system. While these three assumptions are very natural, it is difficult to guess exactly how prices and stored energy affect demand. For that reason the exact relation is estimated by nonlinear functions from data, f and g, but requiring that they are monotonously decreasing, as a result of the first two assumptions.
The effect of state of charge is modelled by f while the effect of energy price is modelled by g. To satisfy the third assumption, X t is required to stay between 0 and 1 for all t. This is enforced by ensuring that Recall that g u ( ) is largest for = u 0 and smallest for = u 1; then, the boundary conditions are guaranteed by letting (1). This means that the desire to decrease demand due to having the largest possible state of charge is exactly equal to the desire to increase it due to the lowest possible price, and vice versa for lowest possible state of charge and largest possible price.
The numerical magnitude of f and g is irrelevant, so without loss of generality it can be assumed that (0) 1. Now the modelling task has been reduced to finding suitable functions that decrease monotonously from 1 to − 1 for inputs between 0 and 1. This is a strictly mathematical consideration, and the approach used in this paper is described in Appendix A.
Finally, to allow the model to estimate how aggressively the energy flexibility is being used, + f g is passed through the function l, which is a scaled logistic function: This way it is continuous and monotonously increasing while mapping all inputs to the interval (0, 1). Then, = − δ 1 t indicates that demand at time t is being limited as much as possible while = δ 1 t indicates that the demand is increased as much as possible. Also, = l k (0; ) 0, so that means that at time t demand is expected to equal the baseline. (1 ) t , that is, the difference between the maximum demand and the baseline demand. This reflects how much demand that could potentially be switched on. If e.g. the baseline is close to 1, then the demand can only be increased a little, since it is not possible to increase demand more than having everything switched on at maximum capacity. The opposite is true when < δ 0. In this case the change is proportional to B t , reflecting that the potential maximum negative adjustment of demand is by switching off all demand. If again the baseline is close to 1, then it makes sense that there is potential to turn down the demand a lot.

Demand and observation equation
Finally, (4) is the observation equation, describing that the observed demand will differ from the expected demand, due to both measurement errors and unexpected behaviour from the energy flexible system. Demand

Case studies
To test the approach, four case studies are used, the primary one consists of three water towers delivering water to three smaller cites. The remaining three case studies are based on the electrical heating requirements of a household, an office building and a commercial building. The essential commonality between the case studies is that demand is controlled according to price, and so, the response to price can be learned. In all cases, the response to the price is obtained via (E-MPC), where a forecasted price is used to schedule predicted demand, so that comfort (enough water and high enough temperature) is obtained in the cheapest possible way.

Case Study 1: Control of water tower
A simulation model is developed using the pipe layout and reservoir size information from the water utility in Bjerringbro, Denmark. A small city with around 8000 inhabitants and one large industry (Grundfos). The structure of the system is shown in Fig. 1.
The consumption profiles for the two pressure zones are measured over a 2 month period in Bjerringbro and the obtained time series are used as input to a simulation of the network. The pipe networks in the pressure zones are obtained by simplifying the network layout of Bjerringbro by only considering what are expected to be the main water ways. The networks are simulated by solving the pipe pressures and flows for steady state conditions, meaning that the only energy storing element is the elevated reservoir.
The control of pumping station 1, which delivers water to the water tower in Fig. 1, is the concern of this case study. The local control is done using E-MPC minimising the operational cost still taking network constraints in the form of reservoir constraints and water quality constraints into account as described in [24].
To simulate the case where several utilities are controlled by the same energy price, two additional networks are included in the simulation. These networks are derived by perturbation of main parameters in the Bjerringbro network model, that is, reservoir size and pipe resistances. Beside that, the consumer load profiles are differentiated between the networks by shifting the time series from Bjerringbro one and two weeks respectively for the two additional systems.

Case Study 2, 3 and 4: Electrical heating of buildings
These three case studies are based on the E-MPC developed in [25]. In this study, dynamic grey box models of three different kinds of buildings, namely a household, an office building and a commercial building are developed based on a combination of data-driven parameter estimation and design parameters from the literature. Each of the buildings are equipped with a heat pump, and has to keep the temperature within pre-specified temperature ranges.

Flexi orders on Nord Pool
In this study it was decided to utilise the energy flexibility on the day-ahead market, since this allows the calculation of price signals 24 h in advance. Thus the E-MPCs of the energy flexible systems can be provided with the exact future prices. If the energy flexibility was used to provide ancillary services, then future prices would never be known, and thus they would have to be forecasted instead. This would make the quality of the forecasts dominate the performance, and thus take away from the focus of this paper, namely the modelling of the energy flexibility.
On the Scandinavian power market Nord Pool, the so called "flexi orders" are the most appropriate product for utilising energy flexibility on the day-ahead market. Flexi orders are submitted by indicating three things (1) a time interval, a b [ , ], (2) an amount of hours, n and (3) an amount of energy P. The flexi order are then accepted by finding the cheapest n hours within the time interval a b [ , ]. For each of these hours P energy is bought at the corresponding spot prices. This means, that, by using flexi orders one can buy electricity for the cheapest price within some interval at the cost of not deciding exactly what hours it will be [26].
Depending on how flexible the energy flexible system is, the length of the time intervals and amount of hours within them where electricity is needed can be adjusted. The most flexible case would be to have the time interval equal all 24 h of the given day, and only purchase electricity in 1 h. If the energy flexible system can handle this, then all demand can be bought during the cheapest hour of each day. Probably, for most systems it is more appropriate to split each day into several time intervals and request energy in some amount of the hours in these intervals. The longer the time intervals and the fewer hours of requested energy, the lower the price that the systems can expect to receive. Also, it is possible to buy some of the energy in a non-flexible way using regular hour-bids, and some of it using flexi orders. This can be used to cover non-flexible parts of the energy demand. The exact bidding strategy used for these case studies in this paper is explained in Appendix C.
Once the spot market has been settled, all participants know how much energy they have bought for each hour, and the model can be used to design a price signal, which gives an expected demand equal or close to the amount of energy bought for each hour. This price signal is then sent to the energy flexible system, and the local controller acts upon it. However, the real demand is bound to deviate from the expected value, and thus there will be a difference between how much energy was bought and how much was consumed. This difference is paid for on the balance market, according to the regulation price [27]. The overall cost of running the energy flexible system is then the cost of the energy bought on the spot market and the balance market: Here, Cost is the cost of electricity consumption during one day, in which the spot and regulation price in hour k was λ k Spot and λ k Regulation respectively, and where p k energy was bought in hour k while the real demand in hour k was Y k .

Designing price signals for control
Once energy has been bought, a price signal to make the consumption of the water towers and buildings follow the amount bought, has to be designed, as explained by Fig. 2. In this figure the aggregator first bids into the market using flexi orders and then receives the amount of energy bought for each hour. This is sent to the energy flexibility model, which is then used to find prices that makes the expected demand follow the amount of bought energy. Next, this price signal is sent to the energy flexible system, which then finds the optimal consumption schedule based on its own optimisation framework (E-MPC in these case studies). However, this is an inverse problem where it is easy to compute the expected demand given the price signal, but difficult to compute a price signal given the demand. Consider the expected demand at time t D , t , from (3). This is a function of the baseline, B, and the price signal, u. The squared difference between the expected demand and a reference demand, D ref can be minimised according to the price signal: Doing so yields a price signal resulting in an expected demand as close as possible to the reference demand.

Results
In this section the parameters of the model defined by (1)-(4) are estimated and discussed in Section 4.1. Afterwards, in Section 4.2, the results of bidding energy flexibility into the spot market and simulating the operation of the water towers and buildings correspondingly are presented.

Parameter estimates
Using a price signal designed for system identification according to Appendix B.4, the parameters are estimated by minimising (B.5), obtaining the values shown in Table 3. The time unit used here is seconds, and so the estimate of C being 12,720 for the water tower means that it is estimated that all the water towers could be filled in = 3.5 12720 3600 hours without any demand. Perhaps more relevant, it is estimated to take = 8.6 3.5 0.41 hours to fill it if the demand equals the average normalised demand of 0.41. For the buildings it is estimated to take between 32 and 56 min to fill their state of charge. Inspecting the simulations shows that the temperature in the buildings never exceed the minimum temperature by more than 1 kelvin. This means that the 32 and 56 min are really the estimated times it takes to raise the temperature by 1 kelvin, which seems reasonable. Δ is estimated to equal 1 in all cases, which is not surprising considering that the systems are 100% flexible. Fig. 3 shows the estimated price relationships. For the water tower, it is seen that the relationship can approximately be considered as 3 overall regions. When the price is between 0.2 and 0.55 there is a close to linear relation between price and demand. For prices below 0.2, the effect is close to constant, slowly converging to 1. For prices above 0.55 the effect is very flat, with almost no effect of price. This indicates that the controller considers all prices above 0.55 to be expensive, but does not care about the exact value. Prices below 0.2 are considered cheap, and it will pump close to its maximal potential for all prices in this range. Between 0.2 and 0.55 it adjusts demand proportionally to the price. For the buildings g u ( ) is very close to −1 for > u 0.25, which means that the heating will be shut off almost no matter what, whenever prices are above 0.25.
Similarly, the relationship between energy demand and state of charge is shown on Fig. 4. For the water tower, it is seen that ≈ f (0.5) 0, which indicates that the natural state of charge is 0.5, meaning that the water towers are usually filled around 50%, if there are no price incentives to do otherwise. For levels between 0.15 and 0.85 the effect is modest. For levels lower than 0.15 it quickly approaches 1, to make sure that there is always water available. Similarly for when the state of charge is above 0.85 it quickly converges to −1. This indicates that the controller does not care much about the exact level of the water, as long as it is between 0.15 and 0.85. This is even more pronounced for the Fig. 2. Information flow for using flexibility function to design price signals according to energy bought on the market. Table 3 Parameter estimates for the energy flexibility model based on the electricity consumption of the pumps controlling the water towers and each of the three buildings. α and β are parameters of the state of charge and price responsiveness respectively.  buildings. Especially for building 1 and 3, f X ( ) is almost equal to 0 for < < X 0. 25 65. This indicates that the controller is almost indifferent about the exact value of X, as long as it is not close to the boundaries. For building 2, f intersects the x-axis at around 0.7, meaning that it has a preference for being close to the upper boundary of the state of charge. Fig. 5 shows the predicted demand of the water tower over the course of 3 days versus the measured demand. The estimated baseline demand is also shown. The difference between the baseline and the demand is due to the use of energy flexibility. The model is clearly very accurate, with predictions that correspond well to the observations, especially for the first 24 h. Considering that the model will not be used for predictions of more than 24 h, this is satisfactory. The model explains most of the variation not explained by the baseline, reducing the root-mean-squared error of the baseline of 9.23 kWh to 3.99 kWh for the model.

Bidding energy flexibility into spot market
The energy flexibility is sequentially bid into the spot market for 9 days using flexi orders according to the bidding strategy explained in Appendix C, and prices designed to make the expected demand equal the bought energy are sent to the water towers and buildings. A sample of the demand compared to the energy bought is shown in Fig. 6 for the water towers. In this figure the prediction equals the bought energy, and it is seen that the actual demand follows quite well. The main deviations occur when the actual demand equals almost exactly zero or one, which is typically not anticipated by the model. In other cases the demand is similar to the prediction, and so the consumed energy fits well with what was bought, so that the usage of the balance market is very limited.
The economic results can be seen in Table 4, where simulated results are compared. The baseline scenario is described in Appendix B.2, where the energy demand of the water towers and buildings are not influenced. This is obtained by simply using a constant price, while purchasing electricity in the spot market according to the estimated baseline demand. The costs are computed according to (5), which is the sum of costs on the spot market and on the balance market. For the water towers, the energy flexibility yields expected savings of 4.1%, amounting to yearly savings of 1830 EUR. Comparatively, the average price that was paid per MWh was reduced by 4.8%, but the energy consumption was increased by 0.75%, reducing the capital savings.
To evaluate how successful the energy flexibility is being used, it should be compared to the largest possible savings. These are obtained by assuming that the water towers were provided with perfect foresight of their own demand and prices. In this way the costs are further reduced, arriving at total savings equal to 5.4%. Thus, the approach presented here managed to obtain = 76% 4.1 % 5.4 % of the potential savings. The same experiment is done for each of the buildings separately, and the economic results are shown in Table 5. It is seen how these are even better than for the water towers, both in therms of the achieved flexibilty, the potential and the share of the obtained potential. This can be attributed to the aggressive response to prices revealed by Fig. 3, where it was shown that the buildings are able to heat only when the price is very low.

Conclusion
It was shown that energy consumption of price-responsive systems can be accurately predicted by price. This was done by modelling the relation through a combination of physical considerations and statistical methods. The method was tested with success for water towers and    6. Energy flexible demand of the water towers when exposed to designed price signals compared to the amount of energy bought on day-ahead market. The mismatch between Demand and Prediction is bought or sold on the balance market. Table 4 Costs of running three water tower, while being price-ignorant, using flexi orders and the potential when controlling the water towers with perfect foresight of spot prices. buildings controlled by economic model predictive controllers. Because of the physical considerations, the estimated relationship between price and consumption proved causal, in the sense that consumption can be controlled through price signals. Thus, this can be considered a useful characterisation of energy flexibility. The model is general enough to be used for many other energy flexible systems.
The developed models of the energy flexibility of the water towers and buildings were used make price signals for indirect control of the energy flexibility. For the water towers this amounted to operational savings of 4.1%, corresponding to obtaining 76% of potential savings achievable with perfect foresight. For the buildings savings of 8.4% to 10.8% correspond to 63% to 98% of the potential. This shows that, even without compromising autonomousity most of the available energy flexibility can be utilised through indirect price-based control.
The water demand profiles were real data, and the water towers were simulated using very accurate models. Since the energy flexibility was used on the day-ahead market, the model predictive controller can be supplied with future prices. This, combined with the fact that the assumed market products already exist means that the method could be employed in practice today.

Perspectives
The optimal way of using flexi orders was not pursued in this paper. This would have to be investigated to reach the full potential of the method. There are far too many possible combinations of flexi orders to test them all in a brute force manner, but it is expected that the physical interpretation of the flexibility parameters could be used to make heuristic procedures to find good combinations of flexi orders.
Because of the simplicity of operating in the day-ahead market this was chosen as the market in this paper. For future studies the method should be employed for the regulation market, since here the price variations are larger, and thus the potential savings are also larger. However, it is more difficult as well, since the prices are never known in advance, and thus it is difficult to supply the model predictive controller of the water towers with accurate price forecasts.

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. where B k t (·; , ) j is the j'th B-spline of a collection of k'th order B-splines with knots at t. Notice, that, since the B-splines have compact support, the Isplines equal exactly 0 for small inputs and exactly 1 for large inputs: x a I x k t y b I y k t , : : ( ; , ) 0 : ( ; , ) 1. The strength of this procedure comes from the fact that u t is an input; thus, given that the variable is known, I u ( ) k can be computed for all ∈ … k N 1, 2, , g before estimating the parameters. This reduces the task of estimating g to restricted linear regression, which can be done efficiently while estimating the rest of the parameters. Notice that the I-splines are chosen since they are monotonously increasing, and can be formulated such that → I : (0, 1) [0, 1] k . This, combined with the restrictions of β, ensures that g is monotonously decreasing and maps values to − [ 1,1], as required. The accuracy of the spline-based estimates depends on the location of their knots. Close to the knots accuracy is high, meaning that the data will be fitted closely. This is a virtue when there is enough data, but a disadvantage when there is too little, since the result will be overfitted. Thus, the knots should be placed far apart in data-sparse areas and close in data-rich areas. This can be done by locating them according to the quantiles in the data [28], and so, in this study they are placed at the (20%, 40%, 60%, 80%) quantiles of the price signal.
For f, the same method is not feasible, since the estimated values of the state, X, depend on the values of the parameter estimates, and thus the value of the splines would have to be re-estimated for each iteration of the parameter estimation. This has been obtained by parameterising f as , the intersection will take place for smaller values of x. In general, α 1 controls how skewed the relation towards the state of charge is. In addition, notice how, since ⩽ ⩽ X 0 1 t , and > α 0 2 , then the main (·) is always between 0 and 1; thus, f is monotonously decreasing.
All exponents in expression (A.1) have been chosen to be positive so the parameterisation is symmetric around = x 0.5. It is important to notice how, an increase of α 3 and/or α 4 would make α 2 decrease. Thus, (·) gets small when x is close to 0.5. This results in a sub-linear price relationship. Likewise, having small values of α 3 and α 4 will result in having super-linear price relationships. The former would imply that the system cares little about the state of charge unless it is close to being empty or full; on the other hand, the latter suggests that the system mainly cares about whether the state of charge is above or below steady state, but not how much. where θ contains the parameters of the model, as described in Table 2 is the collection of the first N inputs (Baseline demand and energy price).̂| y k 0 and | σ k 0 2 are the value and variance of the k-step prediction made at time 0, and are given bŷ for large > λ 0. This results in a differentiable objective function, and thus the software TMB [30] can be used to provide efficient evaluation of both the objective function and its gradient. These were used to minimise the function using the method of moving asymptotes [31]. By using the gradient the optimisation time is significantly reduced compared to usual methods that do not rely on the gradient.

Appendix C. Bidding Strategy
In this paper, the flexi orders are used by assuming that the total demand should equal the estimated baseline demand. In this way a proportion, κ 1 , of the expected baseline demand is bought in each hour using conventional and non-flexible hour-bids. The remaining energy is bought using two flexi orders, each with an interval of 24 h. For one of them energy is requested in 16 h and for the second it is requested for 8 h. In this way κ 2 and − − κ κ 1 1 2 of the whole energy demand is bought. This means that if μ is the average hourly demand, then for the 8 most expensive hours, κ B t . This means that the pumps of the water towers are running to some extend at all times, but mostly in the cheap hours. Notice that even when the flexi orders are accepted such that the water towers cannot deliver the sufficient amount of energy flexibility, it is not very expensive to use the balance market to make up for it. Optimising κ 1 and κ 2 is out of this papers scope, since it would require more data to avoid overfitting. of this demand being bought in the 8 cheapest hours and the rest in the 8 intermediate hours.