% NB: use pdflatex to compile NOT pdftex.  Also make sure youngtab is
% there...

% converting eps graphics to pdf with ps2pdf generates way too much
% whitespace in the resulting pdf, so crop with pdfcrop
% cf. http://www.cora.nwra.com/~stockwel/rgspages/pdftips/pdftips.shtml




\documentclass[10pt]{beamer}
%\usetheme[everytitleformat=uppercase]{m}
\usetheme[everytitleformat=regular]{m}
\usepackage[absolute,overlay]{textpos}
\usepackage{booktabs}
\usepackage[utf8]{inputenc}

\usepackage{tikz}

\usepackage[official]{eurosym}

\usepackage[scale=2]{ccicons}


%use this to add space between rows
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}


\newcommand{\R}{\mathbb{R}}

\def\l{\lambda}
\def\m{\mu}
\def\d{\partial}
\def\cL{\mathcal{L}}
\def\co2{CO${}_2$}

\def\mw{\text{ MW}}
\def\mwh{\text{ MWh}}
\def\gw{\text{ GW}}
\def\gwh{\text{ GWh}}
\def\emwh{\text{ \euro/MWh}}
\def\bemwh{\text{ [\euro/MWh]}}

\newcommand{\ubar}[1]{\text{\b{$#1$}}}



% for sources http://tex.stackexchange.com/questions/48473/best-way-to-give-sources-of-images-used-in-a-beamer-presentation

\setbeamercolor{framesource}{fg=gray}
\setbeamerfont{framesource}{size=\tiny}


\newcommand{\source}[1]{\begin{textblock*}{4cm}(8.0cm,8.0cm)
    \begin{beamercolorbox}[ht=0.5cm,right]{framesource}
        \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1}
    \end{beamercolorbox}
\end{textblock*}}

\usepackage{hyperref}


%\usepackage[pdftex]{graphicx}


\graphicspath{{graphics/}}

\DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg}



\def\goat#1{{\scriptsize\color{green}{[#1]}}}



\let\olditem\item
\renewcommand{\item}{%
\olditem\vspace{5pt}}

\title{Electricity Markets: Summer Semester 2016, Lecture 5}
%\subtitle{---}
\author{
  Tom Brown, Mirko Schäfer
}

\institute{
  Frankfurt Institute of Advanced Studies (FIAS), Goethe-Universit\"at Frankfurt \\
  FIAS Renewable Energy System and Network Analysis (FRESNA) \\
  \\
  \url{{brown, schaefer}@fias.uni-frankfurt.de}
}


\date{9th May 2016}


\titlegraphic{%
  \vspace{7cm}
    \includegraphics[width=4cm]{FIAS-logo}
}

\begin{document}

\maketitle


\begin{frame}

  \frametitle{Table of Contents}
  \setbeamertemplate{section in toc}[sections numbered]
  \tableofcontents[hideallsubsections]
\end{frame}



\section{Supporting slides to Press Review: Splitting Germany}

\begin{frame}{Splitting Germany-Austria market zone}

  See press and research paper links at \url{http://fias.uni-frankfurt.de/~brown/courses/electricity_markets/}

\begin{columns}[T]
  \begin{column}{5cm}

   \includegraphics[width=5.5cm]{european_bidding_zones}
  \end{column}

  \begin{column}{6cm}
    \begin{itemize}
    \item Scandinavia and Italy are split up into multiple bidding zones
    \item On the other hand, Germany and Austria form a joint bidding zone
      \item To our knowledge, Sweden was split following a complaint to the
  European Commission from Denmark that Danish producers could not
  export electricity into Sweden because of internal Swedish network
  bottlenecks.

    \end{itemize}
  \end{column}
\end{columns}

  \source{Ofgem}
\end{frame}




\begin{frame}{Splitting Germany-Austria market zone}

  In windy hours Germany also shows price divergence between North and South when looking at Locational Marginal Prices. Time to split the Germany-Austria bidding zone so that the market sees the transmission bottlenecks? Alternative is increasingly expensive redispatch measures...

    \centering
   \includegraphics[width=6cm]{lmp}

  \source{PyPSA}
\end{frame}


\section{Recap of two-node example from last time}


\begin{frame}{Two-node transmission example}

  Revisit example from Kirschen and Strbac 6.3.1.2, page 152.

  We have two nodes with fixed consumption and differently-priced
  producers, connected via a transmission line of limited capacity:

  \vspace{0.5cm}

  \begin{tikzpicture}

    \fill[black] (0,2) circle (0.5);
    \draw[thick,->] (0.5,2) -- (6.5,2);
    \fill[black] (7,2) circle (0.5);
    \node[text width=4cm] at (1,0.3)
        {Node 1 \\$Q_1^B$ = 500 MW \\ $C_1'(Q_1) = 10 + 0.01 Q_1$\\ $Z_1 = Q_1 - Q_1^B$};
    \node[text width=4cm] at (8,0.3)
        {Node 2 \\$Q_2^B$ = 1500 MW \\ $C_2'(Q_2) = 13 + 0.02 Q_2$\\ $Z_2 = Q_2 - Q_2^B$};
    \node[text width=3cm] at (3,2.3)
        {$|F| \leq K$ = 400 MW};
  \end{tikzpicture}

  \vspace{0.5cm}

  In addition we can determine the flow between the nodes from the nodal imbalances $Z_i$:
  \begin{equation*}
    F = Z_1 = -Z_2
  \end{equation*}

\end{frame}

\begin{frame}{Outcomes for different values of transmission capacity $K$}


\begin{columns}[T]
  \begin{column}{5cm}

    \centering
    $K=0, F = 0,$\\
    $Q_1^* = 500, Q_2^* = 1500$

   \includegraphics[width=4.5cm]{strbac_separate_markets.pdf}
  \end{column}
  \begin{column}{5cm}

    \centering
    $K=\infty, F = 933$\\
    $Q_1^* = 1433, Q_2^* = 567$

  \includegraphics[width=4.5cm]{strbac_single_market.pdf}
  \end{column}

\end{columns}
  \centering

  $K=400, F = 400$\\
  $Q_1^* = 900, Q_2^* = 1100$

  \includegraphics[width=4.5cm]{strbac_constrained_market.pdf}

\end{frame}

\begin{frame}{Example: Numbers for different values of $K$}
  \ra{1.1}
  \begin{table}[!t]
    \begin{tabular}{lrrr}
      \toprule
        & Separate markets &  Single market & Constrained market \\
      \midrule
      $Q_1^B$ [MW] & 500 & 500 & 500 \\
      $Q_1$ [MW] & 500 & 1433 & 900 \\
      $Z_1$ [MW] & 0 & +933 & +400\\
      $\l_1$ [\euro/MWh] & 15 & 24.33 & 19 \\
$Q_2^B$ [MW] & 1500 & 1500 & 1500 \\
     $ Q_2$ [MW] & 1500 & 567 & 1100\\
      $Z_2$ [MW] & 0 & -933 & -400\\
      $\l_2$ [\euro/MWh] & 43 & 24.33 &  35 \\
      $F_{1\to 2}$ [MW] & 0 & 933 & 400\\
      $\sum_{i}\lambda_{i}\times Q_i$ [\euro] & 72000 & 48660 &  55600  \\
      $\sum_{i}\lambda_{i}\times Q_i^B$ [\euro] & 72000 & 48660 & 62000 \\
      Congestion rent & 0 & 0 & 6400 \\
      \bottomrule
    \end{tabular}
  \end{table}

  \end{frame}



\begin{frame}{Example: Congestion rent for different values of $K$}

  The congestion rent for the two-node example is given by
  \begin{equation*}
    \textrm{Congestion rent} = | \lambda_1 - \lambda_2 | \times |F|
  \end{equation*}

  As a function of $K$:

  \centering
  \includegraphics[width=7cm]{kirschen-congestion-K}
\end{frame}


\section{Efficient market operation in a multi-node system with constrained transmission: KKT}


\begin{frame}{Optimising a multi-node system}

  We want answers to the following questions:
  \begin{enumerate}
  \item What is the most efficient configuration of production and consumption when there are transmission constraints between nodes?
  \item How should the market price be set at each node to guarantee that decentralised actors reach a system-optimal solution?
    \item How does this fit in the Karush-Kuhn-Tucker framework?
  \end{enumerate}

\end{frame}

\begin{frame}{Recap of optimisation for a single node}


  Without transmission we maximised the total economic welfare, the
  sum of the consumer and the producer surplus for consumers with
  consumption $Q_i^B$ and generators generating with rate $Q_i^S$:
  \begin{align*}
    \max_{\{Q_i^B\}, \{Q_i^S\}}\left[ \sum_i U_i (Q_i^B)  -  \sum_i C_i (Q_i^S) \right]
  \end{align*}
  subject to the supply equalling the demand in the balance constraint:
  \begin{align*}
    \sum_i Q_i^B -  \sum_i Q_i^S  = 0 \hspace{1cm} \leftrightarrow \hspace{1cm} \l
  \end{align*}
  where $\l$ gave us the market price.

  How do we then extend this scheme to multiple nodes with transmission constraints inbetween?

  Answer: Maximise the combined sum of welfare at each node while implementing transmission constraints.
\end{frame}


\begin{frame}{Nodal benefit function}

  Suppose at \alert{node $k$} there are some consumers and generators
  $i\in N_{k}$, with generation $Q_{i}^S$ and consumption $Q_{i}^B$.

  We define the \alert{benefit function} $B_k(Z_k)$ of node $k$ as follows:
 \begin{align*}
    B_k(Z_k) = \max_{\{Q_i^B,Q_i^S\}}  \left[
    \sum_{i\in N_k} U_i (Q_i^B)  -  \sum_{i\in N_{k}} C_i (Q_i^S)
    \right]
 \end{align*}
 where we have introduced a new variable $Z_k$ for the total nodal
 power imbalance (supply - demand) at the node
 \begin{align*}
Z_k - \sum_{i\in N_k} Q_i^S + \sum_{i\in N_k} Q_i^B = 0 \hspace{1cm}
 \leftrightarrow \hspace{1cm} \lambda_k
  \end{align*}

The optimisation of the benefit function $B_k(Z_k)$ yields the optimal dispatch for the consumers and generators at node $k$ under the constraint that this dispatch leads to a net injection $Z_k$ at this node.

The parameter $\lambda_k$ gives the change in the objective function when we relax the respective constraint - i.e. the marginal price at this node.

\end{frame}


\begin{frame}{Full optimisation problem}

 Note: the values of the $Z_k$ are not yet fixed by the scheme. Now we fix the values by maximising total economic welfare given constraints for the nodal injections (determined by the transmission constraints):
 \begin{align*}
    &\max_{\{Z_k\}}  \left[
    \sum_k B_k(Z_k)
    \right]
 \end{align*}
 subject to
 \begin{align*}
   \sum_k Z_k =  0 &\hspace{1cm} \leftrightarrow &  \l \\
   h_\ell(\{Z_k\}) \leq d_\ell & \hspace{1cm} \leftrightarrow &  \m_\ell
  \end{align*}
  with
   \begin{align*}
    & B_k(Z_k) = \max_{\{Q_i^B,Q_i^S\}}  \left[
    \sum_{i\in N_k} U_i (Q_i^B)  -  \sum_{i\in N_{k}} C_i (Q_i^S)
    \right]\\
    & \text{subject to }
     Z_k -  \sum_{i\in N_k} Q_i^S + \sum_{i\in N_k} Q_i^B  = 0\hspace{1cm} \leftrightarrow \hspace{1cm} \l_k
  \end{align*}
\end{frame}

\begin{frame}{Optimal dispatch for two-nodes}
  We now return to our two-node example.
We have a flow on the single transmission line $F = Z_1 = -Z_2$ restricted by $|F| \leq K$.

  The optimal dispatch is given by
  \begin{align*}
    &\max_{\{Z_1,Z_2\}}  \left[
   B_1(Z_1) + B_2(Z_2)
    \right]\\
    &\text{subject to }
     Z_1 + Z_2 =  0 \hspace{1cm} \leftrightarrow \hspace{1cm} \l \\
     &\text{subject to }
     Z_1  \leq K  \hspace{1cm} \leftrightarrow \hspace{1cm} \bar{\m}\\
     &\text{subject to }
     -Z_1  \leq K \hspace{1cm} \leftrightarrow \hspace{1cm} \ubar{\m}
  \end{align*}
  with
   \begin{align*}
    & B_k(Z_k) = \max_{\{Q_i^B,Q_i^S\}}  \left[
    \sum_{i\in N_k} U_i (Q_i^B)  -  \sum_{i\in N_{k}} C_i (Q_i^S)
    \right]\\
    & \text{subject to }
     Z_k -  \sum_{i\in N_k} Q_i^S + \sum_{i\in N_k} Q_i^B = 0 \hspace{1cm} \leftrightarrow \hspace{1cm} \l_k
  \end{align*}
\end{frame}

\begin{frame}{KKT analysis}
  Considering the single total optimisation over all variables $Q_i^B, Q_i^S, Z_k$, we get from stationarity
  \begin{align*}
    \frac{\d \cL}{d Q_i^B} & \Rightarrow   U_i'(Q_i^B) - \l_k = 0 \\
    \frac{\d \cL}{d Q_i^S} & \Rightarrow   -C_i'(Q_i^S) + \l_k = 0 \\
    \frac{\d \cL}{d Z_1} & \Rightarrow   +\l -  \l_{1} - \bar{\m} + \ubar{\m} = 0 \\
    \frac{\d \cL}{d Z_2} & \Rightarrow   +\l -  \l_{2} = 0
  \end{align*}
  and from complementary slackness:
  \begin{align*}
    \bar{\m}(K-Z_1) = 0\\
    \ubar{\m}(K+Z_1) = 0
  \end{align*}

\end{frame}


\begin{frame}{Our three cases}
  For a solution where typically $\l_2^* \geq \l_1^*$ we have:

  For the separate markets ($K = 0$):
  \begin{align*}
    F = Z_1^* = -Z_2^* = 0, \l_1^* \neq \l_2^*, \bar{\m}^*  = \l_2^* - \l_1^*, \ubar{\m}^* = 0
  \end{align*}

  For the constrained markets ($K = 400$):
  \begin{align*}
    F = Z_1^* = -Z_2^* = 400, \l_1^* \neq \l_2^*, \bar{\m}^*  = \l_2^* - \l_1^*, \ubar{\m}^* = 0
  \end{align*}

  For the unconstrained markets ($K = \infty$):
  \begin{align*}
    F = Z_1^* = -Z_2^* = 933, \l_1^* = \l_2^*, \bar{\m}^*  = 0, \ubar{\m}^* = 0
  \end{align*}

\end{frame}



\begin{frame}{Beyond two nodes: radial networks}

  In a \alert{radial} network there is only one path between any two nodes on the network.

  The power flow is a simple function of the nodal power imbalances.

  \includegraphics[width=7cm]{radial}

  \source{Biggar \& Hesamzadeh}
\end{frame}


\begin{frame}{Beyond two nodes: meshed networks}

  In a \alert{meshed} network there are at least two nodes with multiple paths between them.

  The power flow is now a function of the impedances in the network.

  \includegraphics[width=7cm]{meshed}

  \source{Biggar \& Hesamzadeh}
\end{frame}


\section{Long-run efficiency: Investment in Generation}

\begin{frame}{Definition of long-run efficiency}

  Up until now we have considered \alert{short-run} equilibria that
  ensure \alert{short-run} efficiency (static), i.e. they make the best use of
  presently available productive resources.

  \alert{Long-run} efficiency (dynamic) requires in addition the optimal
  investment in productive capacity.

  Concretely: given a set of options and constraints for different
  generators (nuclear/gas/wind/solar) what is the optimal generation
  portfolio for maximising long-run welfare?

  From an indivdual generators' perspective: how best should I invest in extra capacity?

  We will show again that with perfect competition and no barriers to
  entry, the system-optimal situation can be reached by individuals
  following their own profit.

\end{frame}


\begin{frame}{Simple example: Single generator type with downward sloping demand}

  Consider the long-run efficiency of a market with a single generator
  type with linear cost function and downward-sloping demand (taken
  from Biggar-Hesamzadeh pages 21 and 183).

  We have to consider \alert{marginal costs} arising from each unit of
  production $Q$ and \alert{capital costs} that arise from fixed costs
  regardless of the rate of production (such as the investment in building
  capacity $K$).

  For a given production rate $Q$ and capacity $K$ we have in this simple example a cost
  \begin{equation*}
    C(Q,K) = cQ + fK
  \end{equation*}
  with $0 \leq Q \leq K$, where $C(Q,K)$ has units \euro/h, $c$ has units \euro/MWh, $Q$ and
  $K$ have units MW and $f$ has units \euro/MW/h (`hourised' capital
  cost).

  Note again: the term $fK$ is constant regardless of production rate $Q$.
\end{frame}


\begin{frame}{Can't just consider just one load situation}

  Up until now, in our considerations of short-run efficiency, we've
  considered just a \alert{single} demand situation.

  Now that we're considering long-term investment, we have to consider
  \alert{many} or even \alert{all} demand situations.


  \includegraphics[width=5cm]{downward_slope-single}
  \includegraphics[width=5cm]{downward_slope--600}

  We consider many different utility curves $U_t(Q)$ for different
  times $t$, each of which occurs with probability $p_t>0$, $\sum p_t =
  1$.

\end{frame}


\begin{frame}{Simple example: Consumer with downward sloping demand}

  Suppose the generators have a marginal cost of $c=$40
  \euro/MWh and the downward-sloping demand fluctuates over time.

  If total generation capacity is always below demand, the demand will
  set the price at MCB (Marginal Consumer Benefit) and the generators will always earn above their Marginal Generation Cost (MGC):

  \centering
  \includegraphics[width=6cm]{downward_slope600}

  But then why don't they build more capacity to make even more profit?

\end{frame}


\begin{frame}{Simple example: Consumer with downward sloping demand}

  If sometimes the price is set by MCB and sometimes by the MGC then the generators might still earn enough  to cover their capital costs:

    \centering
  \includegraphics[width=7cm]{downward_slope800}

\end{frame}

\begin{frame}{Simple example: Consumer with downward sloping demand}

  If generation capacity is so large that it can always cover the demand, regardless of the MCB, then generators will never earn enough money to regain their capital costs, because the price will always be set by the marginal generation cost:

    \centering
  \includegraphics[width=7cm]{downward_slope1000}

\end{frame}





\begin{frame}{Simple example: optimisation problem}

  Now consider the maximisation of long-run welfare, including the capital costs:
  \begin{equation*}
    \max_{\{Q^B_t\},\{Q^S_t\}, K} \sum_t p_t\left[ U_t(Q_t^B) - C(Q_t^S,K)\right]
  \end{equation*}
  i.e. with cost $C(Q,K) = cQ + fK$ we optimise
  \begin{equation*}
        \max_{\{Q^B_t\},\{Q^S_t\}, K} \sum_t p_t\left[ U_t(Q_t^B) - (cQ_t^S+fK)\right]
  \end{equation*}
  given
  \begin{align*}
    Q^B_t - Q^S_t =  0 \hspace{1cm}\leftrightarrow \hspace{1cm} p_t\l_t \hspace{1cm} \forall t \\
    -Q^S_t \leq 0 \hspace{1cm}\leftrightarrow \hspace{1cm} p_t\ubar{\mu}_t \hspace{1cm} \forall t \\
         Q^S_t \leq K \hspace{1cm}\leftrightarrow \hspace{1cm} p_t\bar{\mu}_t \hspace{1cm} \forall t
  \end{align*}
  (We have taken the liberty to multiply the KKT multipliers by a constant $p_t>0$, to make the resulting equations easier to read.)
\end{frame}



\begin{frame}{Simple example: KKT}

  From stationarity we get:
  \begin{align*}
    \frac{\d \cL}{\d Q_t^B} &\Rightarrow  p_tU_t' (Q_t^B) - p_t\lambda_t  = 0 \\
    \frac{\d \cL}{\d Q_t^S} &\Rightarrow  -p_t c+p_t\l_t +p_t\ubar{\m}_t - p_t\bar{\m}_t  = 0 \\
    \frac{\d \cL}{\d K} &\Rightarrow  -f+ \sum_t p_t\bar{\m}_t  = 0
  \end{align*}

  From primal feasibility we get $Q_t^B = Q_t^S = Q_t^*$ and from complementary slackness we have $\ubar{\m}_t^* = 0$, assuming the demand is always positive, and $\bar{\m}_t^* \geq 0$. Thus we get
  \begin{align*}
    \lambda_t^* & = U_t'(Q_t^*) \\
    \lambda_t^* & = c+\bar{\m}_t^* \\
    f & = \sum_t p_t \bar{\m}_t^*
  \end{align*}

\end{frame}



\begin{frame}{Simple example: KKT interpretation}

  We have
  \begin{align*}
    \lambda_t^* & = U_t'(Q_t^*) \\
    \lambda_t^* & = c+\bar{\m}_t^* \\
    f & = \sum_t p_t \bar{\m}_t^*
  \end{align*}

  So $\bar{\m}_t^*$ is the difference between the Marginal Generation Cost (MGC) $c$ and the Marginal Consumer Benefit (MCB) $U_t'(Q_t^*)$.

  If the constraint $Q_t \leq K$ is binding, then $\bar{\m}_t^* \geq 0$.

  The optimal investment level happens when the average value of $\bar{\m}_t^*$, $\sum_t p_t \bar{\m}_t^*$, is equal to the capital cost $f$.
\end{frame}


\section{Different types of generators}



\begin{frame}{Different types of generators}

\ra{1.1}
\begin{table}[!t]
	\centering
	\begin{tabular}{@{}llllll@{}}
\toprule
Fuel/Prime  & Marginal & Capital & Controllable & Predictable & CO2 \\
mover & cost & cost & & days ahead & \\
\midrule
Oil & V. High & Low & Yes & Yes & Medium \\
Gas OCGT & High & Low & Yes & Yes & Medium \\
Gas CCGT & Medium & Medium & Yes & Yes & Medium \\
Hard Coal & Medium & Lowish & Yes & Yes & High \\
Brown Coal & Low & Medium & Yes & Yes & High \\
Nuclear & V. Low & High & Partly & Yes & Zero \\
Hydro dam & Zero & High & Yes & Yes & Zero \\
Wind/Solar & Zero & High & Down & No & Zero \\
\bottomrule
	\end{tabular}
\end{table}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}{Copyright}


  Unless otherwise stated the graphics and text is Copyright
  \copyright Tom Brown and Mirko Sch\"{a}fer, 2016.

  We hope the graphics borrowed from others have been attributed
  correctly; if not, drop a line to the authors and we will correct
  this.

  The source \LaTeX, self-made graphics and Python code used to
  generate the self-made graphics are available on the course website:

  \url{http://fias.uni-frankfurt.de/~brown/courses/electricity_markets/}

  The graphics and text for which no other attribution are given are licensed under a
  \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative Commons
  Attribution-ShareAlike 4.0 International License}.

  \begin{center}\ccbysa\end{center}

\end{frame}

\end{document}
