\section{Preliminaries}
\label{sec:2}

\subsection{Market participants}

The aim of this section is to give some details on the model we consider, describing how the various agents act in the energy market according to
their own, different goals. As we will see, the model of the electricity market we consider in this work is a simple one made up of three groups of
participants: the suppliers, or producers, the consumers and an independent system operator (ISO). The goal of the participating consumers and
suppliers is to maximize their own benefit - i.e.\ the value they can draw from their engagement in the market. On the other hand, the ISO is a
non--for--profit player which aims to maximize the total social welfare (the aggregate surplus of consumers and producers, which descend from the
notion of optimality we consider) under the constraint of matching supply and demand. The ISO obviously has also to take into account the physical
constraints of the network, since it is charged also of the distribution of the electricity.
Now we describe in detail the characteristics of these market participants.\\
\begin{enumerate}
\item \textit{The Consumers and the Producers}: Let's assume we have two index sets $S:= \{1,\dots,n_s\}$
and $D:= \{1,\dots,n_d\}$  which represent the suppliers and consumers respectively. A value function $v_j(x)$
is associated to each customer $j \in D$, and it represents the economical value deriving from the consumption of
$x$ units of electricity.  Similarly, a cost function $c_i(x)$  represents the cost for each producer $i \in S$ to supply $x$
energy units.\\
We assume the cost function $c_i(\cdot) \in \mathcal{C}^{2}[0,\infty)$,  is strictly increasing and strictly convex, $ \forall i \in S$.
Analogously, $\forall j \in D$, the value function $v_j(\cdot) \in \mathcal{C}^{2}[0,\infty)$ is supposed to be strictly increasing and strictly concave.\\
It is assumed that the utility function of supplier  $i \in S$ is
given by $u_{i}(\lambda,x):= \lambda x - c_i(x)$, where $\lambda$ is
the clearing prize. Equivalently, the utility function of the
consumer $j \in D$ is given by $u_{j}(\lambda,x):= v_j(x) - \lambda
x$, therefore the utility functions are quasi-linear. In this
context, the utility functions represent the net benefit that an
agent can draw from the engagement in the market, i.e.\ from
producing  or consuming $x$ units of electricity when $\lambda$ is
the market price per unit. Let
$d_{j}\,:\,\mathbb{R}_{+}\mathbb{\rightarrow R}_{+}$, $j\in D$, and
$s_{i}\,:\,\mathbb{R}_{+}\mathbb{\rightarrow R}_{+}$, $i\in S$,
denote $\mathcal{C}^1$ functions mapping price to consumption and
production respectively. According to the framework of utility
maximizing agents, we assume that each agent maximizes the net
benefit that can be achieved from the market. Consequently:
\begin{eqnarray}
d_{j}(\lambda) & = & \arg\max_{x\in\mathbb{R}_{+}}v_{j}(x)-\lambda x,\quad j\in D \label{prima}
\\
s_{i}(\lambda) & = & \arg\max_{x\in\mathbb{R}_{+}}\lambda x-c_{i}(x),\quad i\in S \label{seconda}
\end{eqnarray}
When $\lambda \in [0,\infty)$, the maximization problems defined in
(\ref{prima}) e (\ref{seconda}) have a unique solution in
$\mathbb{R}_{+}$ and the functions $d_{j}(\cdot)$ and $s_{i}(\cdot)$
are well-defined, thanks to the hypothesis we made on $v_{j}(\cdot)$
and $c_{i}(\cdot)$. Hence:
\begin{eqnarray*}
d_{j}(\lambda) & = & \max \{0,\arg\{\dot v_{j}(x)=\lambda\}\}=\max\{0,\dot v_{j}^{-1}(\lambda)\}
\\
s_{i}(\lambda) & = & \max \{0,\arg\{\dot c_{i}(x)=\lambda\}\}=\max\{0,\dot c_{i}^{-1}(\lambda)\}
\end{eqnarray*}
In the interest of simplicity we assume that $d_{j}(\lambda)=\dot
v_{j}^{-1}(\lambda)$ and $s_{i}(\lambda)=\dot c_{i}^{-1}(\lambda)$.
This is mathematically justified by adding the assumptions $\dot
c_{i}(0)=0$ and $\dot v_{j}(0)=\infty$, or by assuming that $\lambda
\in [\min \dot c_{i}(0), \max \dot v_{j}(0)]$, or even extending the
inverse functions  to define $\dot v_{j}^{-1}(\lambda) = 0, \forall
\lambda > \dot v_{j}(0)$, and $\dot c_{i}^{-1}(\lambda) = 0, \forall
\lambda < \dot c_{i}(0)$.

\begin{definition}
The \emph{social welfare} is defined as the aggregate benefit of the producers and the customers:
\begin{equation}
\mathcal{S} = \sum_{j \in D} u_{j}(\lambda,d_j) + \sum_{i \in S} u_{i}(\lambda,s_i) \label{social_welfare_gen}.
\end{equation}
When the system is at the equilibrium, i.e.\ the total supply equals the total demand and there is a unique clearing prize $\lambda$
for the entire system, then:
\begin{equation}
\mathcal{S} = \sum_{j \in D} v_{j}(d_j) - \sum_{i \in S} c_{_i}(s_i) \label{social_welfare}.
\end{equation}

\end{definition}

\item \textit{The Independent System Operator}: The system operator is an independent non-for-profit organization,
whose primary function is to optimally match supply and demand,
subject to network constraints. In particular, real-time market
balancing
 involves solving a constrained optimization problem, with the
goal of maximizing the social welfare as shown in
(\ref{social_welfare}). The network constraints are referred to
power flow, transmission lines, generators' capacity and local and
system-wide reserve capacity requirements. A set of the Locational
Marginal Prices (LMPs), corresponding to the nodal power balance
constraints, emerge. When the transmission lines are congested, the
prices may vary from location to location as they represent the
marginal cost of supplying electricity at each particular node. When
there is sufficient capacity in the network, then no transmission
line will be congested, and therefore the entire network will have a
unique
price per unit of energy. \\
In order to develop simple mathematical
models, we make the following simplifying assumptions:
\begin{itemize}
    \item Resistive losses in transmission/distribution lines are negligible.
    \item The line capacities are high enough, so that no congestion will occur.
    \item There are no capacity constraints on the generators.
    \item There are no reserve capacity requirements.
\end{itemize}
The ISO's optimization problem can be written as:
\begin{equation}
\begin{split}
\max &\quad \sum_{j \in D} v_{j}(d_j)  - \sum_{i \in S} c_{_i}(s_i)\\
s.t. &\quad \sum_{j \in D}d_j = \sum_{i \in S}s_i
\label{opt prob}
\end{split}
\end{equation}
The following Lemma is taken from \cite{Sanjoy}, adopted from \cite{kelly}.
\begin{lemma} Let $d^*=[d_{1}^{*},\dots,d_{n_{d}}^{*}]$, and $s^*=[s_{1}^{*},\dots,s_{n_{s}}^{*}]$
where $d_j^*$, $j \in D$ and  $s_i^*$, $i \in S$, solve (\ref{opt prob}). There exists a
price $\lambda^* \in [0,\infty)$, such that $(d^*,s^*)$ solves (\ref{prima}) e (\ref{seconda}).
Furthermore, $\lambda^*$ is the Lagrangian multiplier corresponding to the balance constraint.
\label{lemmasanj}
\end{lemma}
\begin{proof}
The proof, based on Lagrangian duality, in \cite{kelly} would be applicable here with some minor adjustments.
\end{proof}
The implication of Lemma \ref{lemmasanj} is that by setting the
market price to $\lambda^*$, the Lagrangian multiplier corresponding
to (\ref{opt prob}), the ISO creates an environment in which the
collective selfish behavior of the participants results in a
system-wide optimal condition. In other words, the aggregate surplus
is maximized while each agent maximizes his own profit.

\item \textit{Representative Agent Model}: We now develop an abstraction of the model in (\ref{opt prob}),
with only one producer agent and one consumer agent, representing the whole group of producers and customers respectively. In fact, when the price is
uniform all over the system, the ISO is not interested into the individual consumer/producer reaction to real-time prices, as the quantity of
interest is the aggregate response. In multi-agent systems, especially in the economics context, a representative agent is an abstract agent whose
decisions and responses to signals and events are mathematically equivalent to the aggregate decision of a group of agents. This result is a well
studied subject in economics \cite{hartley}.
\begin{lemma}
Let functions $v_j$, $j \in D$, and $c_i$, $i \in S$, satisfying our
hypothesis, and $\dot v_j(0)=\infty$, $\forall j$, and $\dot
c_i(0)=0$, $\forall i$. Suppose that there exists functions $\bar v$
and $\bar c$ satisfying the assumptions of concavity and convexity
respectively, such that:
\begin{equation}
\lambda = \dot{\bar{v}}\left(\sum_{i=1}^{n_{d}}\dot{v}_{i}^{-1}(\lambda)\right),\quad\forall\lambda\in\mathbb{R}_{+} \label{primeq}
\end{equation}
and
\begin{equation}
\lambda = \dot{\bar{c}}\left(\sum_{i=1}^{n_{s}}\dot{c}_{i}^{-1}(\lambda)\right),\quad\forall\lambda\in\mathbb{R}_{+} \label{secondeq}
\end{equation}
Then:
\begin{itemize}
\item If $(d^*,s^*)$ solves (\ref{opt prob}), then $\bar{d}^{*}:=\sum\bar{d}_{j}^{*}$ and $\bar{s}^{*}:=\sum\bar{s}_{i}^{*}$ satisfy:
\[\bar{d}^{*}=\bar{s}^{*}=x^{*}
\]
where $x^*$ solves:
\begin{equation}
\max_x \quad \bar{v}(x)-\bar{c}(x) \label{terzeq}
\end{equation}

\item If $\lambda^*$ and $\bar\lambda^*$ are the optimal clearing prices corresponding to (\ref{opt prob}) and (\ref{terzeq}) respectively, then $\lambda^*=\bar\lambda^*=\dot{\bar{v}}(x^*)=\dot{\bar{c}}(x^*)$.
\end{itemize}
\label{lemmaduesanj}
\end{lemma}

Lemma \ref{lemmaduesanj} presents a construction for the representative agent model applicable to the development in this article.

\begin{remark}
Consider the case where $v_i(x):=\alpha_i \log(1+x)$, and define $\bar v (x):= \bar{\alpha} \log(n_d + x)$, where $\bar{\alpha}=\sum \alpha_i$. Then $\bar v$ satisfies (\ref{primeq}). However, since $\dot v_i(0)=\alpha_i< \infty$, the response to a price $\lambda$ of the representative agent with value function $\bar{\alpha} \log(n_d + x)$ is equal to the sum of the responses of the individual agents only when $\lambda \leq \min_i \alpha_i$. So if $\alpha_i$ are sufficient big, then there will be no problems in pratical applications.
\end{remark}
\end{enumerate}

 \subsection{Dynamic Supply-Demand Model}

In this section we review the a dynamical system model proposed to simulate the interaction of wholesale supply and retail demand in electricity
markets, under the assumption of modeling all customers as a single representative agent, as well as we will do for all producers. The cost and value
functions $c(\cdot)$ and $v(\cdot)$ represent supply and demand respectively. In a power grid, the aggregate supply has to match exactly the
aggregate demand at each time step. Therefore, in real-time pricing, supply must follow the demand. In other words, the exact amount of power
requested by the consumers
needs to be supplied at each instant of time.\\
At discrete time intervals, the ISO computes and announces the
price for the next time interval, according to a mechanism which is
called \textit{exant\'e pricing}.

\begin{remark}
A different price assignment is also possible, in the sense that the price announced at time $t=k$ could correspond to the time interval $[k-1,k]$.
In this case, we have the so--called \textit{expost pricing}, and of course the demand is affected by some uncertainty, as the actual price per unit
of energy will be revealed only at the end of the period of consumption. On the contrary, in \textit{exant\'e pricing}, it is up to the ISO to face
the economic risk deriving from the gap between the predicted and real price at each time interval, as the suppliers are supposed to get payed
according to the actual marginal cost of production. Anyway, it can be proved (see \cite{Sanjoy}) that this second possible choice leads to the same
dynamics as the previous one, i.e.\ the exant\'e pricing.
\end{remark}
%The real-time market is cleared at discrete time intervals and the prices are calculated and announced by the ISO at
%each interval.
%When the price announced at time $t=k$ corresponds to the time interval $[k-1,k]$, it is called \textit{expost pricing}.
%In expost pricing the demand is subject to some price uncertainty, as the actual price will be revealed after the
%consumption has materialized. When the announced price corresponds to the next time interval ahead (based on predicted
%demand), it is called \textit{exant\'e pricing}. In exant\'e pricing the ISO faces price uncertainty, as it will have
%to pay generators based on the actual marginal cost of production (that is, the expost price), while it can charge the
%demand only based on the exant\'e price, which is only a prediction
%of the actual price.
%In this article we suppose that the ISO controls price dynamic under \textit{exant\'e pricing}.\\
Let $\lambda^{r}_{t}$ be the exant\'e retail price per unit of electricity announced by the ISO at time $t$ for the time interval $[t,t+1]$, and let
$d_t$ be the actual consumption that will occur during this time interval. As a consequence of the myopic autonomy given to the consumers, the
aggregate demand is set to
$$
d_{t} = \arg\max_{x\in\mathbb{R}_{+}} v(x)-\lambda^{r}_{t} x.
$$
It is reasonable to assume that the ISO does not know the value
function, hence the utility function, of the consumers. Moreover,
even the consumers could not have complete information about the
exact form of their value function (see Section
\ref{sec:5}). Under these conditions, an exact model
of the consumers' response to the announced price is not available,
and the ISO can only estimate the demand, and consequently calculate
the retail price. During the time interval $[t,t+1]$, the producers
supply an amount of energy which is exactly the total demand $d_{t}$
for this time period, and get paid by the ISO according to their
actual marginal cost of production $\lambda^{w}_{t}$. At time $t+1$
the ISO needs to announce $\lambda^{r}_{t+1}$. The following
equations describe the dynamics of the market:
\begin{equation}
\begin{split}
d_t\quad  = &\quad \arg\max v(x)-\lambda^{r}_{t} x = \dot v ^{-1}(\lambda^{r}_{t})\\
s_t\quad  = &\quad d_t = x_{t}\\
\lambda^{w}_{t}\quad = &\quad \dot c(x_{t})\\
\lambda^{r}_{t+1} \quad = &\quad \Pi(\lambda^{r}_{t},\lambda^{w}_{t})
\label{modello}
\end{split}
\end{equation}
where $\Pi : \mathbb{R}^{2}_{+} \rightarrow \mathbb{R}_{+}$ is the pricing function.\\ This algorithm is depicted in the block diagram in Figure
\ref{fig:alg_Pi}.

\begin{figure} [!hh]
\centering
\epsfig{file=algoritmo_solo_Pi.pdf, width=0.65\columnwidth}
\caption{Block diagram describing the prices' dynamic control algorithm.\label{fig:alg_Pi}}
\end{figure}

\subsection{ISO's risk}
The ISO commits to a price $\lambda^{r}_{t}=
\Pi(\lambda^{r}_{t-1},\lambda^{w}_{t-1})$ for the consumers, while it
has to pay
 the generators $\lambda^{w}_{t}= \dot c(x_{t})$. The ISO's risk or revenue differential is therefore given by:
\begin{equation}
i(t)=\left(\lambda^{r}_{t}-\lambda^{w}_{t}\right) x_{t}.
\label{iso risk}
\end{equation}
