1 Introduction

Recent advancements in renewable energy technologies and increasing government incentives have enabled a significant level of renewable energy penetration in the existing power system network. Such trends add new challenges to the reliable operation and control of the power system network, often caused by the intermittent nature of renewable energy generation. With increasing contribution of distributed energy resources (DERs) in mitigating local load demand, more advanced energy management systems have emerged as a necessary component of power system networks. The ability to manage local load demand with locally generated renewable energy promotes the adoption of microgrid systems, the optimal operation of which often depends on intelligent energy management algorithms.

In a microgrid, there could be participants with excess energy generation after meeting their own demand. On the other hand, there could be other participants who do not have sufficient generation (or any generation) to meet their demand. The participants with energy excess can act like sellers, whereas participants with energy deficit can act like buyers and they can form a local energy market. This local energy market enables peer-to-peer (P2P) energy trading [1] or transactive energy trading [2] where the aim is to balance local load demand with local generation as well as to reduce dependencies on the utility grid. A number of practical implementations of P2P energy trading has taken place recently, such as Brooklyn microgrid [3] and the City of Fremantle [4].

Optimum P2P energy trading in a microgrid can accelerate the energy efficiency and reduce the power wastage when diversity in load demand and renewable generation are considered. Bill sharing, auction-based pricing and mid-market rates are the three mechanisms commonly utilised for P2P energy trading [1]. In the bill sharing mechanism, users share the electricity cost for the same community microgrid according to the proportion of their net energy use. Auction based pricing works on the basis of the bids from participants which depends on their demand and generation. On the other hand, mid-market rate corresponds to the mid-point between energy selling and buying prices [1]. A multi-agent based simulation framework for different P2P energy trading mechanisms is investigated in [5], which concludes that mid-market rate mechanism performs well with moderate levels of solar energy penetration whereas bill sharing mechanism is relatively insensitive to seasonal changes in solar generation. The architecture of a smart energy hub enabling P2P energy trading along with the required smart grid communication mechanisms and distributed control schemes for power sharing has been elaborated in [6]. A blockchain based P2P energy trading platform is implemented in [7] which utilises incentive mechanisms to promote increasing levels of P2P energy trading while reducing self-consumption.

The energy utilization of smart homes equipped with DERs has been managed using the distributed optimisation algorithm [8], in which optimisation is decomposed into two levels namely the local home energy management system (LHEMS) and the global home energy management system (GHEMS). Home energy trading and storage systems are in the GHEMS level and consumer preferences for appliances are considered on the LHEMS level. This ensures better computational efficiency as well as maintains consumer privacy [8]. A decentralised energy trading mechanism based on proximal Jacobian alternating direction method of multipliers (PJ-ADMM) and dual decomposition is proposed in [9]. The decentralised technique is evaluated for IEEE 123 bus test systems and is found to converge with the centralised solution while achieving lower execution cost. A bilevel optimisation problem considering profit maximisation of virtual power plant aggregator at the upper level and welfare maximisation for day-ahead and real-time P2P markets, has been investigated in [10]. The approach utilises information gap decision theory to manage the uncertainty associated with intermittent renewable generation. A day-ahead bilevel energy trading bid optimisation problem is formulated in [11] considering the uncertainty costs from real-time trading while minimising consumer inconveniences. A long-term delayed reward method is developed in [12] to learn the trading patterns and utilise them to design more effective trading strategies through a deep Q-Network algorithm. A transactive energy management framework is adopted in [13] to minimise energy bills at the users by developing a pricing mechanism based on supply-demand ratio.

A transactive energy trading approach for customer prioritization within a residential microgrid is elaborated in [14] based on a multi-leader multi-follower Stackleberg game. In this scheme the buyers with more energy demand and the sellers offering the cheapest price will have higher priorities. Based on this, optimum utilities for the buyers and sellers is estimated using linear programming [14]. Similarly, modeling buyer and seller interactions in a community microgrid using the M-leader and N-follower Stackelberg game approach is considered in [15]. A Stackelberg game model considering multiple energy sharing regions where the energy sharing provider acts as leader and the prosumers act as followers, has been proposed in [16]. The authors developed a profit maximisation model which optimises different internal prices for different energy sharing regions.

It is important that network standards are maintained while achieving optimal energy trading. In this regard, the authors in [17] developed a sensitivity analysis on the energy trade between the peers on a UK low-voltage network to ensure that the network constraints and parameters are not violated. P2P energy trading can be integrated with ancillary service market to support the utility network operation by maintaining the voltage and power losses within tolerable ranges by optimising pricing for ancillary service procurement [18]. To manage the uncertainties associated with renewable generation, a probabilistic locational marginal price strategy is developed in [19] considering a spread between buying and selling prices in the P2P market. By controlling this spread, the authors have been able to minimise the chances of network constraint violations.

A multi-class energy management scheme considered by [20], co-ordinates the trade between the proactive consumers while considering energy as a heterogenous product with different energy classes. The trading is carried out to minimize the cost of the battery power depreciation and other losses in the P2P energy management platform by considering the prosumer preferences. Based on the load demand, energy prices and the renewable power generation, prosumers control and adjust the power flow by distributed price-directed optimisation mechanism together with receding horizon model predictive control strategy [20]. For prosumers with different levels of interests to trade energy, the authors in [21] have developed a P2P trading platform where the aggregator designs a range of pricing strategies for maximising its profits. An optimisation method for designing energy trading price considering profit maximisation at sellers while minimising energy cost at buyers is proposed in [22]. The authors developed a strategy for uniform pricing as well as an energy allocation policy for the consumers.

Existing research has also considered power exchange between multiple microgrids through contribution based prioritization by considering a stochastic optimisation approach while ensuring the reliable operation of the microgrid with the intermittent renewable energy sources and dynamic load consumption [23]. A new pricing scheme is developed for energy trading between multiple microgrids in [24] where buyers utilize a priority factor for making decisions on energy purchase strategies through a non-cooperative game. Optimal pricing functions for intra-microgrid and inter-microgrid P2P energy trading have been designed in [25] considering different priority groups based on the energy demand. A reputation based ranking system for energy sharing among multiple microgrids is proposed in [26]. The reputation score and power loss reduction are utilised to develop a local pricing scheme which can improve supply reliability and network voltages. The interaction of P2P energy markets with the existing wholesale energy markets need to be considered while designing pricing mechanisms for balancing settlement in the P2P energy market [27]. Recently, a joint bidding model to optimise the income of participants in the balancing energy market has been developed in [28] which aims to manage the real-time imbalances in intermittent renewable generation by considering hydro power plants as dispatchable sources. On the other hand, imbalance price optimisation has been investigated in [29] which aims for increasing profits by considering real-time changes in generation and demand mismatch.

Optimal energy trading strategies often depend on how accurately the energy demand and generation information are known to the market participants. Though existing literature has aimed to predict weather dependent variable cooling and heating load demand [30, 31], there can still be uncertainties due to intermittent renewable generation. Thus day-ahead optimisation strategies may not be optimal as generation or demand may change in real time in comparison to the forecast values. These forecasts include solar generation and electricity consumption forecasts which can be over half-hourly or hourly intervals depending on the granularity of the available data. On the other hand, large variations of energy prices with changing generation and demand conditions can cause price volatility and lessen the effectiveness of P2P energy markets. Thus, it is important to design the price bids in such a way that considers the longer term patterns in energy generation and demand and at the same time, has the provision for updating the price bids when generation and demand in real time vary from the forecasts. Existing research has considered these two aspects of the optimal P2P energy trading separately either by incorporating a large number of possible future scenarios [11] or relying completely on the real-time data ignoring longer term trends [26]. Moreover, the existing research does not consider the energy savings aspects of the buyers in the real-time energy trading [28]. To the best of our knowledge, an optimum pricing strategy that designs price and energy sell bids on a day-ahead basis and ensures that these can vary in real-time only within a certain range, has not been investigated yet.

As a result, in this paper, we have developed a new approach for optimising the P2P energy trading problem while taking into account the variations in generation or demand that can occur during the intra-day trading. The proposed approach allows individual participants to maximise their benefits in the P2P market in a decentralised manner rather than depending on the central energy management system for making the sell/purchase decisions. To be specific, we aim to address the aforementioned research gap through the following contributions:

  • A day-ahead optimisation approach for obtaining the optimal price and energy sell bids at the sellers as well as optimal energy purchase at the buyers in a P2P market is developed. The proposed approach allows each seller to obtain profit more than a given threshold and each buyer to minimise its energy deficit through the P2P market.

  • Considering the fact that generation and demand forecasts can vary in real-time (e.g. hour ahead) compared to the day-ahead values, the energy sell and price bids are updated at the sellers experiencing the variation in generation or demand. A rolling horizon based optimisation approach is adopted for the real-time updates which ensure that the price can vary within a pre-defined range of the optimal bid. Similarly, the energy purchase is updated at the buyers whose generation or demand varies in real-time.

  • The day-ahead optimisation and rolling horizon optimisation based real-time update approaches are evaluated for an existing generation and demand dataset under different seasonal conditions as well as different price limits charged to different buyers. It can be observed that the sellers can achieve higher profits and more buyers can experience energy mismatch reduction when all buyers are willing to pay a higher price (yet less than the utility rate).

The rest of the paper is organised in the following manner. Section 2 outlines the approach implemented for day-ahead optimisation of price and energy sell bids along with optimum energy purchase decisions. In addition, the real-time update mechanism to update these optimum values due to generation or demand variation is also elaborated in the same section. Section 3 illustrates numerical results for a real-life generation and demand dataset under different seasonal conditions and pricing scenarios. Finally, Sect. 4 concludes the paper.

2 Optimisation of prices and purchased energy

In this section, the mechanism for obtaining the optimum prices for sellers to maximise the profit and optimum amount of purchased energy at the buyers to maximise the savings from P2P energy trading is outlined. The optimisation process initiates in a day-ahead manner based on the forecasts available on generation and demand. However, there could be inaccuracies in the forecasts and as a result, the solutions based on the actual generation and demand can be different from that obtained with forecasts. As a result, the optimisation outcomes need to be updated in real-time (e.g. hour-ahead) when there is a variation between day-ahead forecast and real-time information (e.g., hour-ahead forecast). In the following subsections, the optimisation problem for day-ahead and real-time update stages are explained.

Table 1 Nomenclature used in the paper

2.1 Day-ahead optimisation

The day-ahead optimisation takes place based on the forecasts available on generation and demand of the participants of P2P energy trading. Based on the generation and demand forecasts, the central EMS makes decision on how many participants have energy excess (sellers) and how many of them are with energy deficit (buyers). Apart from the day-ahead forecasts, the central EMS also has information on what rate (cents/kWh) each participant is willing to pay for purchasing energy from the P2P market. In addition, the storage capacities, charging and discharging rates for participants with storages are known to the central EMS. The symbols used in this section are defined in Table 1 and have not been repeated here for the sake of brevity.

2.1.1 Optimisation at the seller side

At the beginning, the EMS forwards the demand and generation forecasts, storage status for each buyer, along with the maximum electricity rate that can be charged to each buyer by each seller. Based on the specified information, each seller optimises the amount of energy to be sold and the price to be asked for each available buyer at a certain time interval so that the daily profit achieved by the seller is maximised. The corresponding optimisation problem at the seller side can be formulated as following:

$$\begin{aligned}&{\mathop {\mathrm {max}}_{y_{j,i,t},P_{j,i,t}} \sum ^{T}_{t=1}{\sum ^B_{i=1}{y_{j,i,t}}}}P_{j,i,t} \quad \forall j\in \{1,2,\ldots ,S\} \end{aligned}$$
(1)
$$\begin{aligned}&\quad \text {Subject to:}\nonumber \\&\quad P_{feed-in}\le P_{j,i,t}\le P_{i,max} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(2)
$$\begin{aligned}&\quad \sum ^B_{i=1}{y_{j,i,t}\le G^f_{j,t}-D^f_{j,t}+ u\left( S_{j,t}-S'_{j,t}\right) } \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(3)
$$\begin{aligned}&\quad \sum ^B_{i=1}{y_{j,i,t}\le \sum ^B_{i=1}{\left( D^f_{i,t}-G^f_{i,t}\right) }+u\left( S'_{i,t} -S_{i,t}\right) } \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(4)
$$\begin{aligned}&\quad \sum ^{T}_{t=1}\sum ^B_{i=1}y_{j,i,t}P_{j,i,t}>P_j \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(5)
$$\begin{aligned}&\quad S_{j,t}-S^{'}_{j,t} = R_{dch}\ S_{max} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(6)
$$\begin{aligned}&\quad S^{'}_{i,t}- S_{i,t}=R_{ch} S_{max} \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(7)

where

$$\begin{aligned} 0\le S^{'}_{j,t}, S^{'}_{i,t}\le S_{max} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(8)

Equation (1) indicates the objective function for optimising the maximization of profit earned by the jth seller considering how much energy the seller wants to sell at the optimised price on all time intervals (indexed by t). The optimised price offered to the ith buyer will be always between the feed-in tariff and a maximum price level, as explained in (2). Equations (3) and (4) denote the amount of excess energy the seller has, after meeting all the demand. The difference between the initial and final charge on the battery after the discharge at the jth seller is equal to the rate of discharge multiplied with the maximum charge on battery as defined in (6), whereas, (7) defines the difference between the final charge and the initial charge of the battery after getting charged at the ith buyer as equal to the rate of charge multiplied with the maximum charge on the battery. Also, the stored energy will be always between zero and the maximum capacity of battery as showed in (8). If the maximum allowable price for certain buyers are less, they might not be preferred by the sellers. In that case, these buyers will be able to purchase directly from the utility to balance their energy mismatch.

2.1.2 Optimisation at the buyer side

Once each seller optimises the amount of energy to be sold and price to be asked for each buyer, it sends these energy sell and price bids to the corresponding buyers through the EMS. Based on this information, each buyer optimises the amount of energy to be purchased from a given seller so that the total energy mismatch at the buyer at a certain day can be minimised while achieving an energy cost lower than that when purchased from the utility. The corresponding optimisation problem at the buyer side can be formulated as:

$$\begin{aligned}&{\mathop {\mathrm {min}}_{x_{j,i,t}} \sum ^{T}_{t=1}{\left| \sum ^s_{j=1}{x_{j,i,t}-\left( D_{i,t}-G_{i,t}\right) +u(S^{'}_{i,t}- S_{i,t})}\right| } } \quad \forall i\in \{1,2,\ldots ,B\} \end{aligned}$$
(9)
$$\begin{aligned}&\quad \text {Subject to:}\nonumber \\&\quad \sum ^{T}_{t=1}{\sum ^S_{j=1}{\left( x_{j,i,t}*P_{j, i,t}\right) \le }}E_{cost,i} \quad \forall i\in \{1,2,\ldots ,B\} \end{aligned}$$
(10)
$$\begin{aligned}&\quad E_{cost,i}=\sum ^{T}_{t=1}{\left( D_{i,t}-G_{i,t}\right) *}P_{uti} \quad \forall i\in \{1,2,\ldots ,B\} \end{aligned}$$
(11)
$$\begin{aligned}&\quad x_{j,i,t}\le y_{j,i,t} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(12)

The objective function in (9) is minimization of the difference between energy purchased by buyer and the energy deficit for the entire trading period . Equation (10) briefs that the energy cost of the ith buyer when P2P trading is allowed, will be always less than the total energy cost for the day when the energy is purchased at the utility rate. Equation (11) represents the energy cost for each day when net energy is purchased in the utility rate. The energy purchased by all the buyers will not be more than the energy sold by the sellers as explained in (12). The optimum energy purchase decisions are finally forwarded to the EMS which notifies the corresponding sellers. If the energy prices asked by certain sellers are less, they might not be preferred by the buyers. In that case, these sellers will be able to store excess energy if they have storage or sell directly to the utility to balance their energy mismatch.

2.2 Rolling horizon optimisation based real-time update

When the real-time information on energy generation and demand available for each participant and they vary from the day-ahead forecasts, the optimisation results need to be recalculated. Here we consider that the time intervals are discretised and real-time information is available on a certain discrete time interval (e.g. an hour) before the actual event (e.g. change in generation or demand). We adopt a rolling horizon based optimisation approach to update the energy sell and price bids as well as energy purchase decisions repetitively in discrete time intervals over the entire day. During this real-time update, the price bids are allowed to vary within a certain range defined by \(\pm \Delta P\). In addition, the energy sell bids can vary from the optimum amount of energy to be purchased during day-ahead optimisation by the amount of variation in energy mismatch at the seller.

2.2.1 Optimisation at the seller side

In each round of rolling horizon optimisation, each seller compares its day-ahead forecasts on energy generation and demand with the real-time information and based on this difference, updates its energy sell and price bids. The seller still aims to maximise its profit while ensuring that the price bids vary within a certain limit and the energy to be sold takes into account any real-time variations in generation or demand. As a result, during real-time updates, the optimisation problem at the seller side can be formulated in the following manner:

$$\begin{aligned}&{\mathop {\mathrm {max}}_{y^r_{j,i,t},P^r_{j,i,t}} \sum ^B_{i=1}{y^r_{j,i,t}P^r_{j,i,t}} } \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(13)
$$\begin{aligned}&\quad \text {Subject to:}\nonumber \\&\quad P_{j,i,t}-\Delta P\le P^r_{j,i,t}\le P_{j,i,t}+\Delta P \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall i\in \{1,2,\ldots ,B\},\nonumber \\&\quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(14)
$$\begin{aligned}&\quad \sum ^B_{i=1}{y^r_{j,i,t}}\le G_{j,t}-D_{j,t}+u\left( S_{j,t}-S^{'}_{j,t}\right) \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(15)
$$\begin{aligned}&\quad \sum ^B_{i=1}{y^{r}_{j,i,t}}\le \sum ^B_{i=1} x_{j,i,t}+(\Delta G_j-\Delta D_j) \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(16)
$$\begin{aligned}&\quad S_{j,t}-S^{'}_{j,t}=R_{dch} S_{max} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(17)
$$\begin{aligned}&\quad S^{'}_{i,t}- S_{i,t}=R_{ch} S_{max} \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(18)

Where

$$\begin{aligned} 0\le S^{'}_{j,t},~~ S^{'}_{i,t}\le S_{max} \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(19)

Equation (13) indicates the objective function for the real time energy update at seller side, which is the maximization of the energy sold by the jth seller to the ith buyer at the current trading interval. The updated energy price will not vary more than the maximum allowed price variation compared to the price charged by the jth seller to the ith buyer, as explained in(14). Equation (15) shows the amount of energy sold by the jth seller to the ith buyer should be bounded by the excess energy available at the seller during current trading interval. The energy sold by the jth seller in real time will not change by more than the variation of generation and demand at the jth seller compared to the day-ahead optimised amount for the current trading interval, as explained in (16).

The difference between the initial and final stored energy on the battery after the discharge is equal to the rate of discharge multiplied with the battery capacity as defined in(17), whereas, (18) defines the difference between the final and the initial stored energy of the battery after getting charged as the rate of charge multiplied with the maximum capacity of the battery. Also, the stored energy will be always between zero and the maximum capacity of battery as shown in (19).

Fig. 1
figure 1

Day-ahead optimisation and real-time update mechanisms for P2P energy trading

2.2.2 Optimisation at the buyer side

Once the sellers update their energy sell and price bids, they forward the information to the corresponding buyers through the EMS. Each buyer compares its day-ahead forecast and real-time information on generation and demand. Based on these information, the buyer recomputes the amount of energy to be purchased in each round of rolling horizon optimisation so that its difference with the day-ahead energy purchase decision plus any variation in generation and demand can be minimised. The optimisation problem can be formulated as following:

$$\begin{aligned}&{\mathop {\mathrm {min}}_{x^r_{j,i,t}} \sum ^S_{j=1}{\left| x^r_{j,i,t}-\right. \left. \left( x_{j,i,t}+ \Delta D_{i,t}-\Delta G_{i,t}\right) +u(S^{'}_{i,t}-S_{i,t})\right| }\ }\nonumber \\&\quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(20)
$$\begin{aligned}&\quad \text {Subject to:}\nonumber \\&\quad \sum ^S_{j=1}{\left( x^r_{j,i,t}*P^r_{j,i,t}\right) \le (D_{i,t}-G_{i,t})}P_{uti} \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(21)
$$\begin{aligned}&\quad x^r_{j,i,t}\le y^r_{j,i,t} \quad \forall j\in \{1,2,\ldots ,S\}, \quad \forall i\in \{1,2,\ldots ,B\}, \quad \forall t\in \{1,2,\ldots ,T\} \end{aligned}$$
(22)

The real time update of the energy trading at the buyer side is the minimization of the difference between the updated amount of the energy purchased by the ith buyer and the day-ahead optimised amount of energy purchase added with real-time variation in energy deficit, as demonstrated in (20). The updated energy cost at the ith buyer is less than the energy cost when purchased at the utility rate, as shown in (21). The optimised amount of energy purchased by all the buyers in real-time will be always less than the optimised energy bid by the sellers for the current trading interval as explained in (22). Once the buyer obtains the optimum amount of energy to be purchased from a certain seller, it forwards the information to the central EMS who finally coordinates the energy transaction between the corresponding buyer and seller. The day-ahead optimisation and real-time update mechanisms are illustrated in the flowchart shown in Fig. 1.

3 Simulation results

In this section, we consider a case study with 6 houses whose renewable generation and electricity demand data are extracted from the Ausgrid Solar Home Electricity Dataset [32] for the location of New South Wales, Australia. Houses 1 and 2 have both solar panels and storages, houses 3 and 4 have solar panels only. On the other hand, houses 5 and 6 do not have either solar panels or storages. The solar panel capacities of the houses 1, 2, 3 and 4 are 2.16, 1.02, 1.02 and 1.05 kW, respectively. The storage capacities of houses 1 and 2 are considered as 2.16 and 1.02 kWh, respectively. The generation and demand data are collected over 48 half hourly time intervals for the dates of 1st July, 2012 and the 1st January, 2013 to represent the winter and summer conditions, respectively. The utility rate and feed-in tariff are considered as 30 cents/kWh and 10 cents/kWh, respectively. The charging and discharging rates of the storages are \(50\%\) of the storage capacities. The maximum prices charged to the houses 1, 2, 3, 4, 5 and 6 (when they are buying energy from peers) are 15, 20, 23, 28, 18 and 12 cents/kWh, respectively. These prices have been obtained as uniformly distributed random numbers between the utility rate and feed-in tariff. The half-hourly profit thresholds for the houses 1, 2, 3 and 4 are 0.1, 0.08, 0.05 and 0.05 cents, respectively. When the prices are updated in real time, the maximum allowed variation in price is 5 cents/kWh. The real-time updates are computed when the hour-ahead forecasts vary from day-ahead forecasts by \(\pm 10\%\). We consider three cases: the impact of real-time update for (i) the month of July, (ii) the month of January, and (iii) the maximum price charged as 25 cents/kWh. For all of the aforementioned cases, we investigate the impact on profit, energy purchased, average bid and maximum bid of the sellers, as well as the reduction in energy mismatch. We also analyse the impact of \(20\%\) and \(60\%\) forecasting errors for case (i) while comparing the results with that of day-ahead optimisation.

3.1 Case 1: Performance in winter month

Figure 2 shows the energy purchase with day-ahead optimisation for 1st July, 2012 on the top left, the updated energy purchased in real time when \(\pm 20\%\) and \(\pm 60\%\) forecasting errors are present on the top left and bottom, respectively. These forecasting errors represent the total forecasting error combining both the generation and demand forecasting errors. The purchased energy for real-time optimisation is less when there are forecasting errors. For example, house 2 purchases 0.2 kW at 2 pm with day-ahead optimisation. However, it is zero when \(20\%\) and \(60\%\) forecasting errors are present. It can be seen that the amount of the energy purchased with \(20\%\) forecasting error is higher than that of the \(60\%\) forecasting error for house 2. The amount of energy purchased by the house 2 for both the forecasting errors peaks at 12 pm with 0.5 kW energy purchased. When there is forecasting error, the house 4 only purchases energy after 3 pm and it is identical with \(20\%\) and \(60\%\) forecasting errors. House 3 does not purchase any energy when the forecasting error is \(60\%\). Note that with \(0\%\) forecasting error, the day-ahead optimisation results will coincide with the real-time updates.

Fig. 2
figure 2

Impact of forecasting error on the variation of real-time energy purchase and day-ahead optimisation. Top left figure represents day-ahead energy purchase, top right figure represents real-time energy purchase with 20% forecasting error and bottom figure represents real-time energy purchase with 60% forecasting error

Fig. 3
figure 3

Impact of forecasting error on the variation of real-time profits and day-ahead optimisation. Top figure represents day-ahead profits, middle and bottom figures represent real-time profits with 20% and 60% forecasting errors, respectively

Fig. 4
figure 4

Profit obtained with a Double auction based P2P energy trading

Figure 3 shows the profit obtained by sellers with day-ahead optimisation of the P2P energy trading at the top, the real-time updated profit with \(20\%\) and \(60\%\) forecasting error at the middle and bottom, respectively. When there is forecasting error, house 1 can offer excess energy during real-time update, which could not be predicated during day-ahead optimisation. Thus, the profit gained by the house 1 is the highest of all other houses and is maximum at 12pm in both cases with \(20\%\) and \(60\%\) forecasting errors. Profit earned during the optimisation with \(20\%\) forecasting error is higher than that with the \(60\%\) forecasting error. House 2 does not earn profit in any conditions as the house 2 is purchasing energy most of the times during optimisation. It is evident that the houses 3 and 4 earn more profit in the day ahead optimisation. For example, at 2 pm, house 3 and 4 do not earn any profit with real-time updates, but with day-ahead optimisation they earned some profits. The maximum profit earned by the house 4 is at 1 pm during day-ahead optimisation and real-time update with \(20\%\) forecasting error, which is approximately 0.04 AUD. When the forecasting error is \(60\%\), house 4 earns the maximum profit at 12 pm, which is approximately 0.02 AUD.

Figure 4 demonstrates the profit obtained with a benchmark mechanism for P2P energy trading, which is the double auction (DA) mechanism [33]. It can be observed that in the DA mechanism, House 4 obtains the maximum profit which is similar to the outcome of the proposed optimisation approach, as in Fig. 3a. However, the maximum profit obtained is slightly less in the DA approach. Another difference is House 1 achieves some profit with the DA approach, whereas it is not able to sell energy in the proposed approach. This is because house 1 bids a higher price in the proposed approach due to its higher profit threshold and as a result, it is less preferred by the buyers.

Fig. 5
figure 5

Impact of forecasting error on the maximum bid from each seller during real-time updates. Top and bottom figures show the maximum bid with 20% and 60% forecasting errors, respectively

Fig. 6
figure 6

Impact of forecasting error on the average bid from each seller during real-time updates. Top and bottom figures represent average bid with 20% and 60% forecasting errors, respectively

Fig. 7
figure 7

Reduction in energy mismatch after real-time updates with different levels of forecasting error. Top and bottom figures represent energy mismatch reduction at 20% and 60% forecasting errors, respectively

Fig. 8
figure 8

Real-time energy purchase in summer month with 20% forecasting error

Figure 5 illustrates how the maximum price bid by each seller after real-time updates vary with \(20\%\) and \(60\%\) forecasting error at the top and bottom, respectively. Each seller bids a different price for each buyer and the maximum of these bids are demonstrated in the aforementioned figures. It can be seen that house 2 did not participate in bidding as it did not have energy excess. The maximum bid values are relatively higher during mid to late afternoon periods. When there are higher levels of forecasting error, the maximum bids reach the utility rates sooner in the day. This is because the sellers try to ensure that their profit thresholds are maintained with the variations in energy excess/deficit scenario, which is again incorrectly estimated due to forecasting errors.

Figure 6 shows the average bid obtained by each seller during real-time updates at the top and bottom while a forecasting error of \(20\%\) and \(60\%\) are present, respectively. The different prices bid to different buyers are averaged for each seller to calculate this average bid. It can be observed that the average bid never reaches the utility rate, though it can be less than the feed-in tariff due to the fact that the real-time price variation of 5 cents/kWh is allowed in the simulation settings. With \(20\%\) forecasting error, house 3 has the highest average bid of 18 cents/kWh. On the other hand, house 4 bids the highest on average, which is 22 cents/kWh. Similar to maximum bid, the average bid also increases sooner on the day (2 p.m. instead of 5 p.m.) when \(60\%\) forecasting error is present.

Figure 7 illustrates how the energy mismatch decreases after real-time updates among the participants when \(20\%\) and \(60\%\) forecasting errors are present, respectively. The mismatch reduction is occurring in more number of trading intervals during the \(20\%\) forecasting error rather than the \(60\%\) forecasting error. The maximum reduction in energy mismatch is 100 W. With \(20\%\) forecasting error, most houses achieve the maximum reduction in energy mismatch after 11.30 am. On the other hand, with \(60\%\) forecasting error, this occurs after 2 pm.

3.2 Case 2: Performance in summer month

Figure 8 shows the energy purchased by all the houses for the energy generation and consumption scenario in 1st January 2013 in the presence of \(20\%\) forecasting error. It can be seen that the purchased energy is maximum for the house 5 during the afternoon hours and peaks at 0.5kW. During the morning hours, house 4 is purchasing most of the energy. When real-time energy optimisation is updated, houses 3, 4 and 5 purchase most of the energy.

Figure 9 illustrates the profit obtained by the seller houses in the summer condition when real-time updates of energy optimisation is considered. The sellers are gaining profits for more hours throughout the day as the duration of sunlight is more during the summer months. When compared with the winter months the house 2 is having better profit levels during the summer months, whereas it didn’t have any profits during the winter months. Similar to winter month, house 1 obtains the maximum half-hourly profit among all the sellers with a value of 0.072 AUD at 4 p.m.

Fig. 9
figure 9

Real time profit in summer month with 20% forecasting error

Fig. 10
figure 10

Maximum (top figure) and average (bottom figure) bids in summer month with 20% forecasting error

Fig. 11
figure 11

Real time energy purchase with \(20\%\) forecasting error and \(P_{max,i}\)=25 cents/kWh

Fig. 12
figure 12

Real-time profit obtained with \(20\%\) forecasting error and \(P_{max,i}\)=25 cents/kWh

Fig. 13
figure 13

Reduction in energy mismatch obtained with \(20\%\) forecasting error and \(P_{max,i}\)=25 cents/kWh

Fig. 14
figure 14

Maximum bid with \(20\%\) forecasting error and \(P_{max,i}\)=25 cents/kWh

Figure 10 demonstrates the maximum bid and the average bid asked by each seller (for all available buyers) at the top and bottom, respectively in summer conditions when energy trading is updated in real-time. It can be seen that all sellers took part in the bidding during the afternoon hours from 1.30pm to 5pm as they have excess energy. The maximum bid varies from 0.22 AUD to 0.3 AUD. A lower price occurs with high levels of solar generation. On an average, house 3 has a higher bid compared to other houses, which is 0.23 AUD at 11.30am. The average bid varies between 0.1 AUD to 0.23 AUD throughout the trading period.

3.3 Case 3: Maximum charged price=25 cents/kWh

Case 3 investigates the impact of prices on the energy purchased, profit, energy mismatch reduction and bids. Figure 11 illustrates the energy purchased by different participants with real time updates when \(20\%\) forecasting error is present and \(P_{max,i}\) is set as 25 cents/kWh for all buyers. It can be seen that house 6 purchases the highest amount of energy in this case. This is different in case 1, when different buyers are charged different maximum prices. The reason is that in case 1, house 6 was charged with a lower maximum price, which made it less profitable for sellers to consider. On the other hand, in case 3, sellers are allowed to charge a higher price to house 6, which made most sellers sell energy to house 6.

Figure 12 shows how the profit obtained by different sellers change when \(P_{max,i}=25\) cents/kWh and there is \(20\%\) forecasting error. It can be seen that house 1 achieves maximum profit of 0.12 AUD at 12 p.m. as it has higher levels of excess generation. On the other hand, house 3 and 4 earn profit for more number of hours compared with other houses as they have a smaller profit threshold. All houses (except house 2) earn higher profit (both on half-hourly or daily basis) than in case 1 as they are charging a higher price to all houses on average.

Figure 13 demonstrates how the energy mismatch is reduced at different participants when \(P_{max,i}\)=25 cents/kWh. It can be seen that house 6 observes energy mismatch reduction in 6 half-hourly intervals (including \(100\%\) reduction in 3 of the intervals). This is different from case 1 when house 6 did not observe any reduction in energy mismatch. The reason is that all sellers now sell energy to house 6 as they are able to charge higher prices to house 6, as explained in the discussion of Fig. 10. House 2 energy mismatch is reduced only at 2 time intervals, which is less than that in case 1. The reason is house 6 will have a higher energy mismatch than house 2 as house 6 does not have any solar panel to offset its energy demand.

Figure 14 shows the maximum bid asked by each seller over all available buyers for \(P_{max,i}\)=25 cents/kWh. Unlike case 1, all sellers are now asking for 30 cents/kWh in all the time intervals. This is because all buyers can now be charged 25 cents/kWh, and a variation of 5 cents/kWh is allowed real-time. On the other hand, in case 1, maximum bid reached 30 cents/kWh only after 2 p.m., when House 4 started purchasing energy and it can be asked a higher price than other houses. Given that all houses can be charged the same maximum price in case 3, all sellers have the chance to ask the same maximum bid of 30 cents/kWh.

Fig. 15
figure 15

Average bid with \(20\%\) forecasting error and \(P_{max,i}\)=25 cents/kWh

Figure 15 illustrates how the bids from different sellers change with \(P_{max,i}\)=25 cents/kWh when averaged over all available buyers at different time intervals. It can be seen that the average bids at different sellers are now same at all time intervals as the same price is asked by all sellers to a buyer for maximizing their profit. The average bid over all buyers remain similar to that in case 1 for most time intervals. However, in case 3, the average bid at 3.30 p.m. (12 cents/kWh) is smaller than that in case 1 (18 cents/kWh). This is because in case 1, house 4 was purchasing energy and could be charged a higher price. On the other hand, in case 2, house 2 is purchasing energy during 3.30 p.m. at a lower price (than that for house 4 in case 1).

4 Conclusions

In this paper, a day-ahead optimisation approach along with a rolling horizon optimisation based real-time update strategy has been evaluated to optimise the energy sell and price bids at the sellers and energy purchase decisions at the buyers. The impact of the seasonal changes and forecasting errors are investigated on the energy purchase, profit, price bids and reduction in energy mismatch. It can be observed that the real-time energy purchase do not vary significantly from the day-ahead values unless the level of forecasting errors is very high. Moreover, when all buyers are willing to pay a higher price which will still be less than the utility rate, the energy mismatch reduction and profit increase compared to the case when only certain buyers are paying higher prices. Future work will focus on evaluating the impact of information exchange mechanisms on the effectiveness of the proposed P2P energy trading optimisation approach.