%====================================================================================
\section{The model}
%====================================================================================

\begin{frame}{The model}
	\begin{itemize}
		\item The following model in the first observation:
				\begin{gather}
						y_{i1}=\beta x_{i}+\mu_{i}+\nu_{i1}  \label{model} \\
				  	\intertext{and}
						E\left(\nu _{i1}|x_{i1},\mu_{i}\right) = 0 \notag
				\end{gather} \pause
			\vspace{-.5cm}
		\item Why do we require $\mu_{i}$ to be observed? \pause
				\begin{itemize}
					\item Fixed effects (invariant in time) \pause
					\item Idiosincratic effects. \pause
				\end{itemize}
		\item In the model (\ref{model}) $\beta$ is identified even if we do not observe $\mu_{i}$ but you require that they $(x_{i}$ and $\mu_{i})$ are not correlated:
			\vspace{-.5cm}
				\begin{gather}
					cov\left( x_{i1},\mu _{i}\right) =0 \qquad \beta =\frac{cov\left(x_{i1},y_{i1}\right) }{var\left(x_{i1}\right) }  \label{option1}
				\end{gather} \pause
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Instrumental variables for identification}
		Or the ability to have an instrument
			\begin{align}
				cov\left(Z_{i},\mu_{i}\right) & = 0 \label{option2} \\
				\beta & = \frac{cov\left(Z_{i},y_{i1}\right) }{cov\left(Z_{i},x_{i1}\right)} \notag
			\end{align}
		If $\mu _{i}$ is correlated with $x_{i}?$. So it is true that:
			\begin{eqnarray}
				cov\left(Z_{i},  x_{i}\right) & \neq 0 \notag \\
				cov\left(Z_{i},\mu_{i}\right) & = 0			  \\
				cov\left(Z_{i},\nu_{i}\right) & = 0	   \notag
			\end{eqnarray}
		What we need is the second one for regression strategy to work. we should replace $x_{i}$ with some variable we know is not correlated with $\mu_{i}$ but correlated with $x_{i}$
\end{frame}
%------------------------------------------------
\begin{frame}{We need something else!}
	\begin{itemize}
		\item Suppose that neither of these two above options are available, so a valid strategy is:
				$$y_{i2}=\beta x_{i2}+\mu _{i}+\nu _{i2}$$
			  satisfying
				$$E\left( \nu _{it}|x_{i2},x_{i1},\mu _{i}\right) =0$$
			  taking first differences (difference-in-difference estimator)%
				\begin{gather}
					\beta =\frac{cov\left( \Delta x_{i2},\Delta y_{i2}\right) }{var\left( \Delta x_{i2}\right)}
				\end{gather}
		\item \textbf{Conclusion}: Panel data help us for identifying structural parameters. \pause
	\end{itemize}
\end{frame}

%------------------------------------------------------------------------------------
\subsection{Within-Group estimator}
%------------------------------------------------------------------------------------
\begin{frame}{Within-Group (WG) estimator}
	A simplistic homogeneous model%
		\begin{align}
			y_{it} & =\alpha +X_{it}^{\prime }\beta +u_{it}  \label{earning} \\
			u_{it} & =\mu_{i}+\nu_{it}  \notag
		\end{align}
	heterogeneity given by $\mu _{i}.$\\

	Model (\ref{earning}) $y_{it}$ could be a earning equation. So, the dependent variable could be the log of wage. $X$ gathers experience, experience$^{2},$schooling, sex, race, union, marital status and so on., $\mu_{i}$ is the individual specific ability.$\nu_{it}$ is the classical disturbance \emph{iid}. Also, we should take notice that we have the same $\beta$ for all individuals.
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group (WG) estimator}
	Arellano (2003) states that the name "withing-group" was originated in the context of data with a group structure. Panel data can be regarded as a special case of this type of data in which the group is formed by the time series observations from a given individual.
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator and some matrix algebra}
	In order to get the WG estimator we need some matrix algebra. the folowingmodel (another way to present the fixed effects model):
		\begin{align*}
			\underset{NT\times 1}{y} & = \underset{NT\times 1}{\alpha \iota _{NT}}+\underset{NT\times K\text{ }K\times 1}{X\beta }+\underset{NT\times 1}{u} \\
			u & = Z_{\mu }\mu +\nu
		\end{align*}
	where $Z_{\mu}=I_{N}\otimes \iota _{T}.$ $Z_{\mu }$ is a matrix of ones and zeros. Baltagi calls $Z_{\mu}$ the ``matrix of individual dummies''.(\emph{auditorium: we did not get it!}).
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator and some matrix algebra}
	The matrix $Z_{\mu }$ and for $T=3.$
		$$ Z_{\mu} = \left[	\begin{array}{ccccc}
								1 & 0 & \ldots & 0 & 0 \\
								1 & 0 & \ldots & 0 & 0 \\
								1 & 0 & \ldots & 0 & 0 \\
								0 & 1 & \ldots & 0 & 0 \\
								0 & 1 & \ldots & 0 & 0 \\
								0 & 1 & \ldots & 0 & 0 \\
								\vdots & \vdots & \ddots & \vdots & \vdots \\
								0 & 0 & \ldots & 0 & 1 \\
								0 & 0 & \ldots & 0 & 1 \\
								0 & 0 & \ldots & 0 & 1
				     		\end{array}
				     \right]$$
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator and some matrix algebra}
	some curiosities (it is worth getting them!):%
		\begin{gather}
			Z_{\mu }Z_{\mu }^{\prime }=I_{N}\otimes J_{T}  \label{curiosity1}
		\end{gather}
	where $J_{T}$ is a matrix of ones of dimension T. How did you get expression $\left( \ref{curiosity1}\right)$?.
		\begin{align*}
			Z_{\mu }Z_{\mu }^{\prime } &= \left( I_{N}\otimes \iota _{T}\right) \left(
			I_{N}\otimes \iota _{T}\right) ^{\prime } \\
			Z_{\mu }Z_{\mu }^{\prime } &= I_{N}\otimes \iota _{T}\iota _{T}^{\prime } \\
			Z_{\mu }Z_{\mu }^{\prime } &= I_{N}\otimes J_{T}
		\end{align*}
	(\emph{auditorium: Fred, why you are showing this? where are we going to?})
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator and some matrix algebra}
	a new matrix (an idempotent one!):
		$$P_{\mu }=Z_{\mu }\left( Z_{\mu }^{\prime }Z_{\mu }\right) ^{-1}Z_{\mu}^{\prime }$$
	P is an inetersting matrix because if you pre multiply this matrix with a row vector, you will have a vector of meaned series across time. (\emph{ auditorium: How do you get this result?}). Let's see, we know that
		\begin{align*}
			Z_{\mu}^{\prime}Z_{\mu} & = \left(I_{N}\otimes \iota_{T}^{\prime}\right) \left(I_{N}\otimes \iota_{T}\right) \\
			Z_{\mu}^{\prime}Z_{\mu} & = I_{N}\otimes T \\
			Z_{\mu}^{\prime}Z_{\mu} & = T\cdot I_{N}
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator and some matrix algebra}
	considering expression for $P_{\mu }$ (projection matrix on $Z_{\mu }$) and incorporating on it the above results:
		\begin{align*}
			P & = T^{-1}\left(I_{N}\otimes J_{T}\right) \\
			P & = I_{N}\otimes \overline{J}_{T}
		\end{align*}
	where $\overline{J}_{T} = J_{T} \cdot T^{-1}.$ So, it is clear that
		\begin{itemize}
			\item $\underset{NT\times 1}{Py}$ which has a typical element $\overline{y}_{i}=T^{-1}\sum_{t=1}^{T}y_{it}$ \pause
			\item $\underset{NT\times 1}{Qy}$ which has a typical element $\widetilde{y}_{it}=y_{it}-T^{-1}\sum_{t=1}^{T}y_{it}.$ $Q=I-P_{\mu}.$
		\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	the matrix $\underset{NT\times NT}{Q}$ is known as the deviations-from time-means or withing group estimator because it transforms the originals eries into deviations from time means
		$$\widetilde{y}_{i}=Qy_{i}$$
	again $\underset{NT\times 1}{Qy}$ which has a typical element $\widetilde{y}_{i}=y_{it}-T^{-1}\sum_{t=1}^{T}y_{it}.$ $Q=I-P_{\mu }.$
	    \begin{block}{Some properties}
			\begin{center}
				$P+$Q=$I$ \\
				$P,$Q idempotent $P$P=$P,\, $Q $Q$=Q \\
				and $P$Q=0
			\end{center}
		\end{block}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	Considering the model:
		\begin{align*}
			\underset{NT\times 1}{y} & = \underset{NT\times 1}{\alpha \iota _{NT}}+\underset{NT\times K\text{ }K\times 1}{X\beta }+\underset{NT\times 1}{u} \\
			u & =Z_{\mu }\mu +\nu
		\end{align*}
	$Z_{\mu }$ is the ``matrix of individual dummies'',$\mu $ is a $N\times 1$ column vector. Setting up the transformation:
		$$Qy=QX\beta +Q\nu$$
	the estimator withing group (recall econometric review session)
		$$\widehat{\beta}_{WG}=\left(X^{\prime }QX\right)^{-1}\left(X^{\prime}Qy\right)$$
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	the estimator withing group:
		\begin{gather}
			\widehat{\beta}_{WG}=\left(X^{\prime }QX\right)^{-1}\left(X^{\prime}Qy\right) \label{within-group}
		\end{gather}
	the individual effects are wiped out. Vector $\beta_{WG}$ gathers parameters of interest, incidental parameters are not included because they are individual effects. Expression (\ref{within-group}) is the withing-group or fixed effects estimator This estimator is very popular and most of econometric softwares have implement it. STATA and Eviews do this procedure and they construct the dummies series (for each member of panel) but they do not show the dummies.
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	we need an estimate of $V$
		$$\widehat{V}=\frac{1}{N}\widetilde{X}^{\prime }\widehat{\Xi }\text{ } \widetilde{X}$$
	where
$$\widehat{\Xi }=\left[
		\begin{array}{cccc}
			\underset{\left( T\times 1\right) \left( 1\times T\right) }{\widehat{\nu }%
				_{1\cdot }\widehat{v}_{1\cdot }^{\prime }} & \mathbf{0} & \cdot & \mathbf{0}
			\\
			\mathbf{0} & \underset{\left( T\times 1\right) \left( 1\times T\right) }{%
				\widehat{\nu }_{2\cdot }\widehat{v}_{2\cdot }^{\prime }} & \cdot & \mathbf{0}
			\\
			\cdot & \cdot & \cdot & \cdot \\
			\mathbf{0} & \mathbf{0} & \cdot & \underset{\left( T\times 1\right) \left(
				1\times T\right) }{\widehat{\nu }_{N\cdot }\widehat{v}_{N\cdot }^{\prime }}%
		\end{array}
\right]_{\dim \, NT\times NT}$$
	where $\widehat{\nu}_{i}=\widetilde{y}_{i}-\widetilde{X}_{i}\widehat{\beta}$
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	\begin{center}
		\Huge{Let's go to Excel!}
	\end{center}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	In Arellano's terms
		\begin{align*}
			\widehat{\beta }_{WG}  = & \left[ \sum_{i=1}^{N}\sum_{t=1}^{T}\left( x_{it}-%
			\overline{x}_{i}\right) \left( x_{it}-\overline{x}_{i}\right) ^{\prime }%
			\right] ^{-1} \\
			& \left[ \sum_{i=1}^{N}\sum_{t=1}^{T}\left( x_{it}-\overline{x}_{i}\right)
			\left( y_{it}-\overline{y}_{i}\right) ^{\prime }\right]
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator Vs. OLS}
	Biased and inconsistency parameters under a true model.
		\begin{center}
			\input{tikzs/pd_1}
		\end{center}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator is not a Panacea}
	(Real) heterogeneity in panel data
		\begin{center}
			\input{tikzs/pd_2}
		\end{center}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator's disadvantages}
	\begin{itemize}
		\item N-1 dummies for those fixed effects. A lof of degrees of freedom lost but people like and want to see dummies.
		\item ``\emph{I wanted to see the dummy for year 2006, but I couldn't!}''. Stata randomly drops one or more dummies if there is perfect collinearity.
		\item A lot of dummies vs a procedure which estimates just 1 parameter.
		\item the procedure wipes out individual time-invariant specifical variables which maybe we are interested (in earning equations variables as sex, race and religion and so on are important).
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator's advantages}
	\begin{itemize}
		\item In terms of specification: OLS baised and inconsistent if within-group effects are important (omitted variables problem).
		\item Specifical variables are already interesting in our study (in earning equations variables as sex, race and religion and so on are important). But that is not a problem if we deal with LSDV (least squares dummy variables).
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator's Interpretation}
	\begin{itemize}
		\item $\mu_{i}$ are fixed $($Baltagi ``\emph{or random but hopelessly correlated with }$\mathit{X}_{it}'')$
		\item In other words if the true model does have fixed effects so OLS is biased and inconsistent.
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group STATA syntax}
	in Stata syntax:
		$$\colorbox{codegray}{\text{\texttt{xtreg \textit{depvar} [\textit{indepvars}] [if] [in] [, fe \textit{FE\_options}]}}}$$
	an example for variables \colorbox{codegray}{\texttt{Y1 X1 X2}} and group identifier \colorbox{codegray}{\texttt{varname}}
		$$\colorbox{codegray}{\textcolor{codeblue}{xtreg} Y1 X1 X2, fe}$$
	before you perform \colorbox{codegray}{\textcolor{codeblue}{\texttt{xtreg}}} you should set up the panel structure, use \colorbox{codegray}{\texttt{xtsset}}.\\
		\medskip
	See \colorbox{codegray}{\textcolor{codeblue}{\texttt{help xtreg}.}}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group STATA syntax}
	\begin{figure}
		\centering
			\includegraphics[width = 0.9\linewidth]{figures/panel_01.png}
	\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group STATA output}
	\begin{itemize}
		\item At the top of the output we can see an ``\textit{overall}'' F\ test but this includes only of those terms ``we are interested'' (excluding incidental parameters).
		\item There is a F-test under the null: all $\mu _{i}=0.$
		\item $rho=\frac{\sigma_{\mu }^{2}}{\sigma_{\mu}^{2}+\sigma_{\nu}^{2}}$
		\item The output shows the unrestricted correlation between $\mu_{i}$ and $X\prime s.$
		\item Under this command \texttt{xtreg} the dummies (fixed effects) are not shown.
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{FE options}
	\begin{figure}
		\centering
			\includegraphics[width = 0.9\linewidth]{figures/panel_02.png}
	\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group STATA}
	Other way to estimate fixed effects
		$$\colorbox{codegray}{areg depvar [\textit{indepvars}] [if] [in] ,a(\textit{varname}) [options]}$$
	an example for variables \texttt{Y1 X1 X2} and group identifier \texttt{varname}
		$$\colorbox{codegray}{\texttt{\textcolor{codeblue}{areg} Y1 X1 X2, a(id)}}$$
	See \colorbox{codegray}{\textcolor{codeblue}{\texttt{h areg}}}. This \emph{absorb} command is useful because you also have an overall F test including the dummies variables
\end{frame}
%------------------------------------------------
\begin{frame}{Options}
	\colorbox{codegray}{\textcolor{codeblue}{\texttt{areg}}}
		\begin{figure}
			\centering
			\includegraphics[width = 0.9\linewidth]{figures/panel_03.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Output}
	\colorbox{codegray}{\textcolor{codeblue}{\texttt{areg}}}
		\begin{figure}
			\centering
			\includegraphics[width = 0.9\linewidth]{figures/panel_04.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Least squares dummy variables (LSDV)}
	Incorporating the dummies in the X matrix and perform:%
		\begin{gather}
			\widehat{\beta}_{LSDV}=\left(X^{+\prime}X^{+}\right) ^{-1}\left(X^{+\prime }y^{+}\right)
		\end{gather}
	where $X^{+}=\left[ X\quad I_{N}\otimes \iota _{T}\right] .$ In Stata syntax:
		$$\colorbox{codegray}{\texttt{xi [, prefix(\textit{string})noomit] i. varname}}$$
	an example for variables \colorbox{codegray}{\texttt{Y1 X1 X2}} and group identifier \colorbox{codegray}{\texttt{varname}}
		\begin{exampleblock}{STATA code}
			\centering
			\texttt{\textcolor{codeblue}{xi}: \textcolor{codeblue}{reg} Y1 X1 X2, i.varname}
		\end{exampleblock}
\end{frame}
%------------------------------------------------
\begin{frame}{Least squares dummy variables (LSDV)}
	Other way to get the dummies into the regresion.\\
	In Stata syntax:
		\begin{eqnarray*}
			&&\cdot \text{[\texttt{quietly] tab \textit{varname}, [gen(\textit{stubname}%
					)]}} \\
			&&\cdot \text{\texttt{reg depvar [\textit{indepvar}] \textit{stubname*}[if]
					[in] [,\textit{options}]}}
		\end{eqnarray*}%
	an example for variables \colorbox{codegray}{\texttt{Y1 X1 X2}} and group identifier \colorbox{codegray}{\texttt{varname}}
	    \begin{exampleblock}{STATA code}
	    	\centering
	    		\texttt{\textcolor{codeblue}{quietly tab} id, gen(dum)}\\
	    		\hspace{-1.65cm} \texttt{\textcolor{codeblue}{reg} Y1 X1 X2 dum*}
		\end{exampleblock}
\end{frame}
%------------------------------------------------
\begin{frame}{Let's go to STATA}
	Let's go to STATA. Please, Download data from \colorbox{codegray}{\texttt{\textcolor{codecrimson}{\textquotedbl www.wiley.co.uk/baltagi\textquotedbl}}}. Definition of variables is as follows
		\begin{itemize}
			\item $I_{it}$ denotes real gross investment for firm $i$ in year $t.$
			\item $F_{it}$ is the real value of the firm (shares outstanding).
			\item $C_{it}$ is the real value of the capital stock.
		\end{itemize}
	10 large US\ manufacturing firms over 20 years 1935-54.
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator}
	therefore, the robust asymptotic variance and covariance matrix of $\beta$ is estimated by:
		\begin{align}
			var\left( \beta \right) & = \frac{1}{N}\cdot \left( \widetilde{\mathbf{X}}%
			^{\prime }\widetilde{\mathbf{X}}\right) ^{-1}N\cdot \left( \frac{1}{N}%
			\widetilde{\mathbf{X}}^{\prime }\widehat{\Xi }\text{ }\widetilde{\mathbf{X}}%
			\right) \cdot \left( \widetilde{\mathbf{X}}^{\prime }\widetilde{\mathbf{X}}%
			\right) ^{-1}N  \notag \\
			var\left( \beta \right) & = \left( \widetilde{\mathbf{X}}^{\prime }\widetilde{%
				\mathbf{X}}\right) ^{-1}\cdot \left( \widetilde{\mathbf{X}}^{\prime }%
			\widehat{\Xi }\text{ }\widetilde{\mathbf{X}}\right) \cdot \left( \widetilde{%
				\mathbf{X}}^{\prime }\widetilde{\mathbf{X}}\right) ^{-1}
		\end{align}
	if $\widehat{\Xi }$ $=\sigma ^{2}I_{NT}$ so:
		$$var\left( \beta \right) =\sigma ^{2}\left( \widetilde{\mathbf{X}}^{\prime }\widetilde{\mathbf{X}}\right) ^{-1}$$
\end{frame}
%------------------------------------------------
\begin{frame}{Within-Group estimator, summarizing...}
	\begin{itemize}
		\item OLS\ biased and inconsistent when the true model is a FE model. Baltagi states this result is because of an ``omitted variables problem''.
		\item Test for individual dummies (standard F test). Useful for testing Pooling models.
		\item Test using LR test (imposing restrictions).
		\item Robust Standard Errors (Arellano;1987).
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	\begin{itemize}
		\item Withing group estimator is not the only transformation that will drop out the individual effects.
		\item Difference-indifference estimator makes the trick as well.
		\item Strategy of information only estimates parameters of "interest".
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	Which in compact form can be written as
		$$Dy_{i}=DX_{i}\beta +D\nu _{i}$$
	where D is the $\left( T-1\right) \times T$ matrix ``first-difference operator''
		$$D=\left[ \begin{array}{cccccc}
						-1 & 1 & 0 & \cdots & 0 & 0 \\
						0 & -1 & 1 & \cdots & 0 & 0 \\
						\vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\
						0 & 0 & 0 & \cdots & -1 & 1
					\end{array}
			\right]$$
	under assumptions $E\left( D\nu_{i}|x_{i}\right) = 0$ and/or $E\left( D\nu_{i}|x_{i}\right) =0$ (Arellano; 2003)$,$
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	In terms of panel structure
		$$\underset{\dim N\times T-1}{D_{N}}=I_{N}\otimes D$$
	thus pre-multiplying this matrix to data
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	OLS estimates of $\beta $ in this system given by
		$$\widehat{\beta}_{D}=\left(\left(D_{N}X\right)^{\prime}\left(D_{N}X\right) \right) ^{-1}\left(\left(D_{N}X\right)^{\prime}\left(D_{N}y\right) \right)$$
	Arellano (2003) considers
		$$\widehat{\beta}_{D}=\left(\sum_{i=1}^{N}\left(X_{i}^{\prime }D^{\prime}DX_{i}\right) \right)^{-1}\sum_{i=1}^{N}\left(DX_{i}\right)^{\prime}\left(Dy_{i}\right)$$
	this $\widehat{\beta}_{D}$ is unbiased and consistent for large $N$. What about the variance?
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	the variance matrix of errors
		$$var\left(D_{N}\nu|X\right)=\left(\sigma_{\nu }^{2}I_{NT}\right) \cdot D_{N}D_{N}^{\prime}$$
	which show an autocorrelation structure%
		$$var\left( D_{N}\nu |X\right) =\left[
				\begin{array}{cccccc}
					2\sigma _{\nu }^{2} & 0 & 0 & \ldots & 0 & 0 \\
					-\sigma _{\nu }^{2} & 2\sigma _{\nu }^{2} & 0 & \ldots & 0 & 0 \\
					0 & -\sigma _{\nu }^{2} & 2\sigma _{\nu }^{2} & \ldots & 0 & 0 \\
					\vdots & \vdots & \vdots & \ddots & \vdots & 0 \\
					0 & 0 & 0 & \ldots & -\sigma _{\nu }^{2} & 2\sigma _{\nu }^{2}
				\end{array}
			  \right]$$
	result: difference in difference estimator is not BLUE because it is inefficient (but unbiased). That means that Gauss Markov theorem is not hold.
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	\textbf{Solution: generalized squares}. Following the standard procedure we should use GLS. This matrix makes the trick:
		$$P_{D_{N}}=D_{N}^{\prime }\left( D_{N}^{\prime }D_{N}\right) ^{-1}D_{N}$$
	$P_{D_{N}}$ is idempotent $P_{D_{N}}P_{D_{N}}^{\prime }=P_{D_{N}}$ or $P_{D_{N}}P_{D_{N}}=P_{D_{N}}.$ So,
		$$\widehat{\beta }_{WG}=\left( \sum_{i=1}^{N}\left( X_{i}^{\prime
		}P_{D_{N}}X_{i}\right) \right) ^{-1}\sum_{i=1}^{N}X_{i}^{\prime
		}P_{D_{N}}y_{i}$$
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	such a nice surprise!. The idempotent matrix $P_{D_{N}}$ also takes the form:
		$$P_{D_{N}}=I_{NT}-I_{N}\otimes \overline{J}_{T}=Q$$
	So, the difference in difference estimator is unbiased and consistent.
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	\textbf{Orthogonal deviations}. Finally, we have realized that if we are using difference and difference we need to do 2 transformations: a) to get differenced data and b) remove the moving-average serial correlation (known pattern) induced by a). The overall tranformation is:
		$$A=\left( D_{N}D_{N}^{\prime }\right) ^{-\frac{1}{2}}D_{N}$$
	therefore $\nu ^{\ast }=A\nu $ which will have $T-1$ elements by $i$
		\begin{align*}
			s_{it}^{\ast } & = c_{t}\cdot \left[s_{it}-\frac{1}{T-t}\left(s_{it+1}+...+s_{iT}\right) \right] \text{ } \\
			t & = 1,...,T-1
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Alternative estimator for fixed effects: difference in difference}
	where $c_{t}=\left( \frac{T-t}{T=t-1}\right)^{\frac{1}{2}}.$(see Arellano and Bover; 1995). thus, we get for each first ($T-1$) observations we substract the mean of the remaining future observations in the sample. The weighting $c_{t}$ is introduced because variances of transformed erros must be equalized. This transformation is called ``\emph{forward orthogonal deviations}''.
\end{frame}
%------------------------------------------------
\begin{frame}{Difference in difference estimator: summarizing...}
	\begin{itemize}
		\item FE is more efficient than difference in difference (FD) estimator when  $\nu_{it}$ are \emph{iid}.
		\item FD is more efficient than FE estimator when $\nu_{it}$ is random walk.
		\item Both estimators are affected in different ways when there are measurements errors.
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Efficiency of difference-in-difference estimator}
	\begin{itemize}
		\item FD is more efficient than FE estimator when $\nu_{it}$ is random walk $\left( \nu_{it}=\nu_{it-1}+\xi_{it}\right) $. Recalling that
			\begin{align*}
				var\left( D_{N}\nu |X\right) & = D_{N}vv^{\prime }D_{N}^{\prime } \\
											 & = \xi \xi ^{\prime } \\
											 & = \sigma _{\xi }^{2}\cdot I_{NT}
			\end{align*}
	\end{itemize}
\end{frame}

%------------------------------------------------------------------------------------
\subsection{Between-Group estimator}
%------------------------------------------------------------------------------------

\begin{frame}{Between-Group estimator}
		\begin{itemize}
			\item This estimator between group can be derived using the projection matrix $P$
					\begin{align*}
						\underset{NT\times 1}{y} & = \underset{NT\times 1}{\alpha \iota
													 _{NT}}+\underset{NT\times K\text{ }K\times 1}{X\beta }+\underset{NT\times 1}{u} \\
											   u & = Z_{\mu }\mu +\nu
					\end{align*}
		\end{itemize}
	premultiplying by P
		\begin{gather}
			Py=P\iota _{NT}+PX\beta +Pu  \label{BE0}
		\end{gather}
	the LS estimator under (\ref{BE0}). (Recall econometric review session)
		\begin{gather}
			\beta_{BE}=\left( X^{\prime }\left( P-\overline{J}_{NT}\right) X\right)^{-1}\left( X^{\prime}\left( P-\overline{J}_{NT}\right) y\right)
		\end{gather}
\end{frame}
%------------------------------------------------
\begin{frame}{Between-Group estimator}
	\begin{itemize}
		\item The estimator between group (in easy format):
			\begin{gather}
				\overline{y}_{i}=\alpha +\overline{X}_{i}\beta +\overline{u}_{i}  \label{BE}
			\end{gather}
		the cross-section regression is based on N observations. The STATA syntax is
			$$\colorbox{codegray}{\texttt{xtreg \textit{depvar} [\textit{indepvars}] [if] [in] [,be \textit{BE\_options}]}}$$
		an example for variables \colorbox{codegray}{\texttt{Y1 X1 X2}} and group identifier \colorbox{codegray}{\texttt{varname}}
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{BE options}
	\begin{figure}
		\centering
		\includegraphics[width = \linewidth]{figures/panel_05.png}
	\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{BE-estimator output}
	\begin{figure}
		\centering
		\includegraphics[width = \linewidth]{figures/panel_06.png}
	\end{figure}
\end{frame}

%------------------------------------------------------------------------------------
\subsection{Random Efects model}
%------------------------------------------------------------------------------------

\begin{frame}{Random Effect model}
	\begin{itemize}
		\item Baltagi states that within-group estimation would mean a loss of degrees of freedom. That statement comes from the fact that within-group estimator needs to estimate $N$ fixed effects or include $(N-1)$ dummies as regresors. \pause
		\item In this especification the individual effect is characterized as random and drawn from a sample, inference is conducted using that sample. \pause
		\item Nerlove and Balestra (1996)'s estimator. \pause
		\item Haavelmo (1944).
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	A simplistic homogeneous model
		\begin{align}
			y_{it} & = \alpha +X_{it}^{\prime }\beta +u_{it} \\
			u_{it} & = \mu _{i}+\nu _{it}  \notag
		\end{align}
	heterogeneity given by $\mu _{i}.$ $\mu _{i}\backsim N\left( 0,\sigma _{\mu
	}^{2}\right) $ and $\nu _{it}\backsim N\left( 0,\sigma _{\nu }^{2}\right) .$
		\begin{align*}
			u_{it}u_{it}^{\prime } & = \left( \mu _{i}+\nu _{it}\right) \left( \mu
										_{i}+\nu _{it}\right) ^{\prime } \\
			\sigma ^{2} & = \sigma _{\mu }^{2}+\sigma _{\nu }^{2}
		\end{align*}%
	$\sigma ^{2}$ is the variance \ based in the latter we construct $\rho = \frac{\sigma _{\mu }^{2}}{\sigma ^{2}}$ (\emph{equicorrelation}).
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	the error component for $it$
		$$u_{it}=\mu _{i}+\nu _{it}$$
	the error component for all (matrix form)%
		$$u=\left( I_{N}\otimes \iota _{T}\right) \mu +\nu$$
	we need to have the total (expected) variance of the error component%
		\begin{align*}
			u^{\prime }u & = \mu ^{\prime }\left( I_{N}\otimes \iota _{T}\right) ^{\prime
							 }\left( I_{N}\otimes \iota _{T}\right) \mu +\nu ^{\prime }v \\
						 & = \mu ^{\prime }\left( I_{N}\otimes \iota _{T}^{\prime }\iota _{T}\right)
							 \mu +\nu ^{\prime }v
		\end{align*}
	Taking expectations
		\begin{gather}
			E(u^{\prime }u)=T\sigma _{\mu }^{2}+\sigma _{\nu }^{2}
		\end{gather}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	getting the ``verall'' matrix variance%
		$$u=\left( I_{N}\otimes \iota _{T}\right) \mu +\nu$$
	So,
		\begin{align*}
			\underset{NT\times NT}{\Omega } & = E(uu^{\prime }) \\
			\underset{NT\times NT}{\Omega } & = \sigma _{\mu }^{2}\left( I_{N}\otimes
												J_{T}\right) +\sigma _{\mu }^{2}\left(
												I_{N}\otimes I_{T}\right)
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
		\begin{align*}
			\underset{NT\times NT}{\Omega } & = T\sigma _{\mu }^{2}\left( I_{N}\otimes
												\overline{J}_{T}\right) +\sigma _{\nu }^{2}\left( I_{N}\otimes \left( E_{T}+%
												\overline{J}_{T}\right) \right) \\
			\underset{NT\times NT}{\Omega } & = \left( T\sigma _{\mu }^{2}+\sigma _{\nu
												}^{2}\right) \left( I_{N}\otimes \overline{J}_{T}\right) +\sigma _{\nu
												}^{2}\left( I_{N}\otimes E_{T}\right) \\
			\underset{NT\times NT}{\Omega } & = \sigma _{1}^{2}P+\sigma _{v}^{2}Q
		\end{align*}
	where $P=\left( I_{N}\otimes \overline{J}_{T}\right) $, $Q=I_{N}\otimes E_{T} $ and $\sigma _{1}^{2}=\left( T\sigma _{\mu }^{2}+\sigma _{\nu}^{2}\right)$
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	trick: Replace
		\begin{align*}
			& J_{T}\text{ by }T\overline{J}_{T} \\
			& I_{T}\text{ by }E_{T}+\overline{J}_{T}
		\end{align*}%
	where
		\begin{align*}
					   E_{T} & = I_{T}-\overline{J}_{T} \\
			\overline{J}_{T} & = \frac{J_{T}}{T}
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	the variance
		$$\underset{NT\times NT}{\Omega }=\sigma _{1}^{2}P+\sigma _{\nu }^{2}Q$$
	Fuller and Battese (1974)'s result considers $r=\frac{-1}{2}$
		$$\underset{NT\times NT}{\Omega ^{-\frac{1}{2}}}=\sigma _{1}^{-1}P+\sigma_{\nu }^{-1}Q$$
	\emph{Remember that is very difficult to inverse a }$NT\times NT$\emph{\ matrix.}
\end{frame}
%------------------------------------------------
\begin{frame}{Baltagi says...}
	premultiplying by $y$
		\begin{gather}
			\underset{NT\times NT}{\Omega ^{-\frac{1}{2}}y}=\sigma _{1}^{-\frac{1}{2}}Py+\sigma _{\nu }^{-\frac{1}{2}}Qy
		\end{gather}
	so $Py=\underset{NT\times NT}{\overline{y}_{i}}$ and $Qy=\underset{NT\times NT}{y_{it}-\overline{y}_{i}}.$%
		$$\underset{NT\times NT}{\Omega ^{-\frac{1}{2}}y}=\sigma _{1}^{-1}\overline{y}_{i}+\sigma _{\nu }^{-1}\left( y_{it}-\overline{y}_{i}\right)$$
\end{frame}
%------------------------------------------------
\begin{frame}{Baltagi says...}
	finally
		\begin{align*}
			\underset{NT\times NT}{\Omega ^{-\frac{1}{2}}y} & = \sigma _{1}^{-1}\overline{
																y}_{i}+\sigma _{\nu }^{-1}\left( y_{it}-\overline{y}_{i}\right) \\
			\underset{NT\times NT}{\Omega ^{-\frac{1}{2}}y} & = \sigma _{\nu
																}^{-1}(y_{it}-\left( 1-\frac{\sigma _{1}^{-1}}{\sigma _{\nu }^{-1}}\right)
																\overline{y}_{i}) \\
			\underset{NT\times NT}{\sigma _{\nu }\Omega ^{-\frac{1}{2}}y} & = (y_{it}-\theta \overline{y}_{i})
		\end{align*}
	being $\theta =1-\frac{\sigma_{v}}{\sigma_{1}}$ or $\theta=1-\sqrt{\frac{\sigma_{v}^{2}}{T\sigma_{\mu}^{2}+\sigma_{\nu }^{2}}}$
\end{frame}
%------------------------------------------------
\begin{frame}{GLS}
	The question is: have we got an $i.i.d$ error disturbance with this ``\emph{long-step}'' transformation?. in the case of the first observation of vector $y$
		\begin{align*}
			var\left( y_{i=i,t=0}\right) = & var(y_{i0})+\theta ^{2}\frac{
											 \sum_{j}^{T}var(y_{i0})}{T}+ \\
										   & -2\theta cov\left( y_{i0},\overline{y}_{i}\right)
		\end{align*}
	so
		\begin{align*}
			var\left( y_{i=i,t=0}\right) = &\left( 1-\theta \right) ^{2}var(y_{i0}) \\
										 = & \frac{\sigma _{\nu }^{2}}{\sigma _{1}^{2}}var(y_{i0})=\sigma _{\nu }^{2}
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Theta's interpretation}
	\begin{itemize}
		\item if $\sigma _{\mu }^{2}=0\Rightarrow \theta =0\Rightarrow $ OLS is enough. \pause
		\item if $T\rightarrow \infty \Rightarrow \theta \rightarrow 1.$ Within effects! (macro data). \pause
		\item So, $0<\theta <1$ for random effects. \pause
		\item We need to estimate the variance components in $\theta .$ That means 1 parameter instead of $N-1$ dummies!. \pause
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model: summarizing}
	\begin{itemize}
		\item OLS still unbiased and consistent if the true model is RE model.
		\item But standard errors are wrong $\Rightarrow $ t-statistics are wrong. The estimator is inefficient!.
		\item GLS is ok (some cases are straightforward to treat) but we need to implement FGLS
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{FGLS in a Random effect model.}
	Estimators
		\begin{itemize}
			\item Wallace and Hussain (1969)
			\item Amemiya (1971)
			\item Swamy \& Arora (1972)
			\item Breusch (1987) iterative GLS using MLE.
			\item MINQUE
			\item MIVQUE
		\end{itemize}
	Softwares : STATA, EVIEWS, RATS, GAUSS, OX,R. (\emph{Auditorium: On above estimator, what do they want?})
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	\begin{itemize}
		\item The variance-covariance matrix%
				\begin{gather}
					\Omega =\left( I_{N}\otimes \iota _{T}\right) E\left( \mathbf{\mu \mu }%
					^{\prime }\right) \left( I_{N}\otimes \iota _{T}\right) ^{^{\prime
					}}+E\left( \mathbf{\nu \nu }^{\prime }\right) \notag\\
					\Omega =\sigma _{\mu }^{2}\left( I_{N}\otimes \iota _{T}\right) \left(
					I_{N}\otimes I_{T}\right) \left( I_{N}\otimes \iota _{T}\right) ^{^{\prime
					}}+\sigma _{\nu }^{2}\left( I_{N}\otimes I_{T}\right)
				\end{gather}
		this implies a homoskedastic variance $var\left( \epsilon _{it}\right)=\sigma _{\mu }^{2}+\sigma _{\nu }^{2}.$ for all $i$ and $t$. Baltagi states that block-diagonal covariance matrix exhibits serial correlation over time
			$$	\begin{array}{cclccc}
					cov\left( \epsilon _{it},\epsilon _{js}\right) & = & \sigma _{\mu }^{2}+\sigma_{\nu }^{2} & \text{for} i = j & , & t = s\\
																{} & = & \sigma _{\mu }^{2} & \text{for} i = j & , & t \neq s
				\end{array}$$
	\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	Because of Baltagi's assumption we have that for $i\not=j$ and $t=s$ the following covariance should be zero:%
		\begin{align*}
			cov\left( \epsilon _{it},\epsilon _{jt}\right) = & E\left( \mu _{i}\mu_{j}\right) +E\left( \mu _{i}\nu _{jt}\right) + \\
														     & E\left( \mu _{j}\nu _{it}\right) +E\left( \nu _{it}\nu _{jt}\right)
		\end{align*}
	at first thought $E\left( \mu _{i}\nu _{jt}\right) =E\left( \mu _{j}\nu_{it}\right) =0$ and we need to think in "very good reasons" to have other terms not equal to zero.
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	Maddala (1971) shows that the GLS\ estimator can be expressed as follows:%
		\begin{align*}
			\widehat{\beta }_{GLS} = & \left[ \frac{\left( X^{\prime }QX\right) }{\sigma
									   _{\nu }^{2}}+\frac{X^{\prime }\left( P-\overline{J}_{NT}\right) X}{\sigma
									   _{1}^{2}}\right] ^{-1} \\
									 & \left[ \frac{\left( X^{\prime }Qy\right) }{\sigma _{\nu }^{2}}+\frac{
									 	X^{\prime }\left( P-\overline{J}_{NT}\right) y}{\sigma _{1}^{2}}\right]
		\end{align*}
	simplifying:
		\begin{gather}
			\widehat{\beta }_{GLS}=\left[ W_{xx}+\phi ^{2}B_{xx}\right] ^{-1}\left[W_{xy}+\phi ^{2}B_{xy}\right]  \label{maddala}
		\end{gather}
	where $W_{xx}=X^{\prime }QX,W_{xy}=X^{\prime }Qy,B_{xx}=X^{\prime }\left( P-\overline{J}_{NT}\right) X,B_{xy}=X^{\prime }\left( P-\overline{J}_{NT}\right) y$ and $\phi ^{2}=\frac{\sigma _{\nu }^{2}}{\sigma _{1}^{2}}.$ Expression (\ref{maddala}) is the Maddala's GLS estimator
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	thus, recall that
		\begin{align*}
			\widehat{\beta }_{WG} & = W_{xx}^{-1}W_{xy} \\
			\widehat{\beta }_{BE} & = B_{xx}^{-1}B_{xy}
		\end{align*}
	So,
		\begin{gather}
			\widehat{\beta }_{GLS}=\vartheta \widehat{\beta }_{WG}+\left( 1-\vartheta \right) \widehat{\beta }_{BE}  \label{wgls}
		\end{gather}
	where $\vartheta =\left[ W_{xx}+\phi ^{2}B_{xx}\right] ^{-1}W_{xx}.$ Expression (\ref{wgls}) tells us that GLS estimator is a weighted average between within-group estimator and between-group estimator.
\end{frame}
%------------------------------------------------
\begin{frame}{Random Effect model}
	three cases to be considered:
		\begin{itemize}
			\item if $T\rightarrow \infty $ $\Rightarrow \phi^{2}\rightarrow 0\Rightarrow \vartheta \rightarrow 1:$ In this case $\widehat{\beta}_{GLS}$ asymptotically approachs to within-group estimator. \pause
			\item if $\phi^{2}\rightarrow \infty \Rightarrow \vartheta \rightarrow 0:$ In this case $\widehat{\beta}_{GLS}$ asymptotically approachs to between-group estimator. \pause
			\item if $\sigma_{\mu}^{2}=0\Rightarrow \phi^{2}=1:$ In this case $\widehat{\beta}_{GLS}$ is equal to $\widehat{\beta}_{OLS}$
		\end{itemize}
\end{frame}
%------------------------------------------------
\begin{frame}{FGLS strategy: Amemiya}
	Considering the total variance%
		$$\underset{NT\times NT}{\Omega }=\sigma _{1}^{2}P+\sigma _{\nu }^{2}Q$$
	So,
		\begin{align*}
			\widehat{\sigma}_{1}^{2} & = \frac{u^{\prime}Pu}{N}=\frac{T\sum_{i=1}^{N}
										 \overline{u}_{i}}{N} \\
			\widehat{\sigma}_{\nu}^{2} & = \frac{u^{\prime }Qu}{N\left(T-1\right) }=
											\frac{T\sum_{i=1}^{N}\sum_{t=1}^{T}\left( u_{it}-\overline{u}_{i}\right) ^{2}
											}{N\left( T-1\right) }
		\end{align*}
\end{frame}
%------------------------------------------------
\begin{frame}{Random-Effect-model STATA syntax}
		\begin{figure}
			\centering
			\includegraphics[width = 0.85\linewidth]{figures/panel_07.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Random-Effect (RE) options}
		\begin{figure}
			\centering
			\includegraphics[width = \linewidth]{figures/panel_08.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{FGLS strategy: MLE iterative}
	Breusch (1987) concentrates the likelihood with respect to:%
			$$\widehat{\phi }^{2}=\frac{d^{\prime }Qd}{\left( T-1\right) d^{\prime }\left(
				P-\overline{J}_{NT}\right) d}=\frac{\sum_{i=1}^{N}\sum_{t=1}^{T}\left(
				d_{it}-\overline{d}_{i}\right) ^{2}}{T\left( T-1\right) \sum_{i=1}^{N}\left(
				\overline{d_{i\cdot }}-\overline{d}_{\cdot \cdot }\right) ^{2}}$$
	where $d=y-X\widehat{\beta }$, and $\phi ^{2}=\frac{\sigma _{\nu }^{2}}{\sigma _{1}^{2}},$ in fact $\theta \backsim 1-\phi $
		\begin{align*}
			\widehat{\beta }_{mle} = & \left[X^{\prime}\left(Q+\phi^{2}\left(P-
									   \overline{J}_{NT}\right) \right) X\right] ^{-1} \\
									 & \left[X^{\prime}\left(Q+\phi^{2}\left(P-\overline{J}_{NT}\right)
									   \right)y\right]^{-1}
		\end{align*}
	iteration process in order to get $\widehat{\beta}_{mle}.$ be careful of values $\phi$ this should be positive and finite.
\end{frame}
%------------------------------------------------
\begin{frame}{MLE iterative STATA syntax}
		\begin{figure}
			\centering
			\includegraphics[width = 0.5\linewidth]{figures/panel_09.png}
		\end{figure}
\end{frame}
%------------------------------------------------
\begin{frame}{Interpretation of Phi}
	\begin{itemize}
		\item if $\phi =0\Rightarrow $ within-group estimator
		\item if $\phi =\infty \Rightarrow $ between-group estimator
	\end{itemize}
\end{frame}

%------------------------------------------------------------------------------------
\subsection{Estimating in STATA}
%------------------------------------------------------------------------------------

\begin{frame}{Estimating in STATA}
	\begin{center}
		\Huge{Let's go to STATA!}
	\end{center}
\end{frame}

\begin{frame}{Summarizing the STATA results}
		\begin{figure}
			\centering
			\includegraphics[width = 0.9\linewidth]{figures/panel_stata_01.png}
		\end{figure}
\end{frame}

\begin{frame}{Summarizing the STATA results}
		\begin{figure}
			\centering
			\includegraphics[width = \linewidth]{figures/panel_stata_02.png}
		\end{figure}
\end{frame}

\begin{frame}{Summarizing the STATA results}
		\begin{figure}
			\centering
			\includegraphics[width = \linewidth]{figures/panel_stata_03.png}
		\end{figure}
\end{frame}


\section{Computing the generalised eigenvalue decomposition}

In the above, we have silently assumed that we have access to the generalised
eigenvectors $\w_i$ of $(\A, \B)$. This section gives some insight into how
these eigenvectors are actually calculated.

From the definition of generalised eigenvectors (\cref{eq:GEVD}), if $\B$ is
of full rank and thus invertible, we can write
\[
\B^{-1} \A \w_i = \lambda_i \w_i
\]
The generalised eigenvectors and eigenvalues of $(\A, \B)$ are thus the
ordinary eigenvectors and eigenvalues of $\B^{-1} \A$.

This is mathematically exact, but a poor method to actually calculate
generalised eigenvectors on a computer when $\B$ is
ill-conditioned\footnotemark{} (this is the case for e.g. $\B = \Rnn$ when
two electrodes / channels are strongly correlated -- as is often the case in
practice).

\footnotetext{The condition $\kappa(\B)$ of a matrix $\B$ denotes how close
$\B$ is to being rank-deficient. A matrix is rank-deficient (and has $\kappa
= \infty$) when the dimension of the space spanned by its column vectors is
lower than the number of those vectors. This is the case when one of the
column vectors is a linear combination of the other column vectors.
$\kappa(\B)$ is thus large, and $\B$ is ill-conditioned, when one of $\B$'s
columns is \emph{almost} a linear combination of its other columns. (This is
e.g. the case when $\B$ has two nearly identical columns).}
%
% The precise definition of $\kappa$ depends on which norm is chosen to
% measure the size of vectors and matrices. For the 2-norm, $\kappa$ can be
% calculated as $\kappa = \sigma_{\max} / \sigma_{\min}$ where
% $\sigma_{\max}$ and $\sigma_{\min}$ are the largest and smallest singular
% values of $\B$, respectively.

The reason is two-fold. Small changes in an ill-conditioned $\B$ will lead to
large changes in its inverse $\B^{-1}$ \cite{Trefethen1997,Golub2013}.
Second, most numbers cannot be represented exactly in
computers.\footnotemark{} Storing $\B$ on a computer inevitably leads to
small representation errors, which in turn lead to disproportionally large
errors in $\B^{-1}$, and therefore also in $\B^{-1}\A$, and in the calculated
eigenvectors of $(\A,\B)$. We say that this is a numerically unstable method
to calculate generalised eigenvectors.

\footnotetext{Or at least not when floating point representations are used,
as is most often done. Only finite sums (of e.g. 53 terms for the popular
`double' floating point numbers of the IEEE 754 standard) of consecutive
powers of 2 can be represented exactly. All other numbers are rounded to the
nearest such digital number.}

\subsection{A stable algorithm to compute generalised eigenvalues}

In 1973, Moler and Stewart published the \emph{QZ-algorithm}, a numerically
stable method to calculate generalised eigenvalues \cite{Moler1973}. It is a
generalisation of the famous QR-algorithm \cite{Trefethen1997} for ordinary
eigenvalue problems. The following paragraphs give an overview of the
QZ-algorithm, without explaining details.

The QZ-algorithm, similarly to the QR-algorithm, is an iterative procedure to
calculate two upper triangular matrices $\Tt = f(\A)$ and $\Ss = f(\B)$ that
have the same generalised eigenvalues as $\A$ and $\B$. As described above,
the generalised eigenvalues of $(\Tt,\Ss)$ are mathematically equivalent to
the ordinary eigenvalues of $\Ss^{-1} \Tt$. Because $\Tt$ and $\Ss$ are upper
triangular however,\footnotemark{} we can extract their generalised
eigenvalues without having to invert $\Ss$.

\footnotetext{To be precise, only $\Ss$ is truly triangular; $\Tt$ is
sometimes ``quasi-triangular''. This poses no problems; see \cite{Moler1973},
\cite{Watkins2007}, or \cite{Golub2013} for how to adapt the reasoning in
this section when $\Tt$ is quasi-triangular.}

To show this, first note the following useful properties of triangular
matrices \cite{Horn2013}: the inverse of a (square, invertible) upper
triangular matrix is also an upper triangular matrix, and its diagonal
entries are the reciprocals of the corresponding diagonal entries of the
original matrix. $\Ss^{-1}$ is thus upper triangular, and its diagonal
entries are $1 / s_{ii}$. The product of two upper triangular matrices is
also an upper triangular matrix, and its diagonal entries are the products of
the corresponding diagonal entries of the original matrices. The diagonal
entries of $\Ss^{-1} \Tt$ are therefore equal to $t_{ii} / s_{ii}$. Finally,
the eigenvalues of a triangular matrix are its diagonal elements. The
eigenvalues of $\Ss^{-1}\Tt$ (and therefore also the generalised eigenvalues
$\lambda_i$ of $(\Tt,\Ss)$) are thus the diagonal elements of $\Ss^{-1} \Tt$,
i.e.
%
\begin{equation}
\label{eq:lambda}
\lambda_i = \frac{t_{ii}}{s_{ii}}.
\end{equation}
%
Note that $t_{ii}$ and $s_{ii}$ can be read out from $\Tt$ and $\Ss$, without
having to actually calculate $\Ss^{-1} \Tt$.

If $\Tt$ and $\Ss$ are defined as $\Tt = \Q \A \Z$ and $\Ss = \Q \B \Z$, with
$\Q$ and $\Z$ orthogonal transformations,\footnotemark{} the pair $(\Tt,
\Ss)$ will have the same eigenvalues as $(\A, \B)$. This can be shown as
follows. Suppose that $\lambda_i$ is an eigenvalue of $(\Tt,\Ss)$ with
associated eigenvector $\x_i$. Then, from the definitions of $\Tt$ and $\Ss$
and making use of $\Q^T \Q = \I$:
\begin{align*}
\Q \A \Z \x_i      &= \lambda_i \Q \B \Z \x_i  \\
\A \Z \x_i         &= \lambda_i \B \Z \x_i  \\
\A \w_i            &= \lambda_i \B \w_i,
\end{align*}
with $\w_i = \Z \x_i$. $\lambda_i$ is thus also an eigenvector of $(\A, \B)$,
with associated eigenvector $\w_i = \Z \x_i$.

$\Q^T \Tt \Z^T = \A$ and $\Q^T \Ss \Z^T = \B$ are so called ``generalized
Schur decompositions'' of $\A$ and $\B$. It can be shown that there exist
such $\Q$ and $\Z$ that triangularize $\A$ and $\B$ \cite[Theorem
3.1]{Stewart1972}. The iterative QZ-algorithm \cite{Moler1973} then describes
how these $\Q$ and $\Z$ can actually be constructed.

\footnotetext{An orthogonal transformation (by which most often actually an
``orthonormal'' transformation is meant) is a linear transformation that can
only rotate and flip vectors around the origin, without shearing or scaling
them. The columns of its transformation matrix have norm $1$, and are
orthogonal to each other. Therefore, if $\Q$ is an orthonormal matrix, its
transpose is its inverse: $\Q^T \Q = \Q \Q^T = \I$.}

More precisely, in each iteration of the QZ-algorithm, orthogonal matrices
$\Q_k$ and $\Z_k$ are applied to $\A$ and $\B$, such that:
%
\begin{align*}
\Tt &= \lim_{k \to \infty} \Q_k \cdots \Q_2 \Q_1 \A \Z_1 \Z_2 \cdots \Z_k \\
\Ss &= \lim_{k \to \infty} \Q_k \cdots \Q_2 \Q_1 \B \Z_1 \Z_2 \cdots \Z_k,
\end{align*}
%
i.e. $\Q = \Q_k \cdots \Q_2 \Q_1$ and $\Z = \Z_1 \Z_2 \cdots \Z_k$ for $k \to
\infty$ (a product of orthogonal matrices is still an orthogonal matrix). In
practice, a very good approximation to $\Tt$ and $\Ss$ is reached after
already a few iterations.

An important reason for using orthogonal transformations is that they do not
amplify errors in the input matrices. Geometrically, small errors do not get
stretched out -- they only rotate around the origin, without changing size.

For descriptions of the practical QZ-algorithm (including how the orthogonal
matrices $\Q_k$ and $\Z_k$ are actually found), see \cite{Moler1973} and
\cite[Section 7.7]{Golub2013}. For a more recent description of the
algorithm, with modern additions and generalisations, see \cite[Chapter
6]{Watkins2007}.\footnote{When learning the QZ-algorithm, it makes sense to
first learn the QR-algorithm, as the QZ-algorithm is a generalisation to it.
\cite{Trefethen1997} gives a good didactic explanation of the QR-algorithm.}

\subsection{Extracting eigenvectors from the Schur decompositions}

The sources \cite{Moler1973}, \cite{Golub2013}, and \cite{Watkins2007} focus
mostly on eigenvalues, and do not describe how the eigenvectors $\x_i$ of
$(\Tt,\Ss)$ (and therefore of $(\A,\B)$) can be found.\footnotemark{} The
process is relatively straightforward though.

\footnotetext{\Cite{Moler1973} mentions only that ``the generalized
eigenvectors of this reduced problem can be found by a back-substitution
process which is a straightforward extension of the method used in
\texttt{hqr2}'', where \texttt{hqr2} is a verbose ALGOL program from
\cite{Wilkinson1971}.}

Each generalised eigenvector $\x_i$ of $(\Tt,\Ss)$ must satisfy $\Tt \x_i =
\lambda_i \Ss \x_i$ or $(\Tt - \lambda_i \Ss) \x_i = \vb{0}$. Let us denote
the upper triangular matrix $(\Tt - \lambda_i \Ss)$ by $\M_i$. We then find
the eigenvector $\x_i$ as a solution to
\begin{equation}
\label{eq:M}
\M_i \x_i = \vb{0}
\end{equation}
%
Due to \cref{eq:lambda}, for the $i$-th eigenvalue $\lambda_i$, the $i$-th
diagonal element of $\M_i$ is zero, i.e. $m_{i,ii} = 0$.
%
For ease of reading, and with a straightforward generalisation to higher
dimensions, suppose $N = 4$, i.e. $\M_i \in \reals^{4 \cross 4}$. \Cref{eq:M}
is then expanded as:
\begin{align*}
m_{i,11} x_{i,1}
+ m_{i,12} x_{i,2} + m_{i,13} x_{i,3} + m_{i,14} x_{i,4} &= 0 \\
  m_{i,22} x_{i,2} + m_{i,23} x_{i,3} + m_{i,24} x_{i,4} &= 0 \\
                     m_{i,33} x_{i,3} + m_{i,34} x_{i,4} &= 0 \\
                                        m_{i,44} x_{i,4} &= 0
\end{align*}
%
Suppose we are calculating the fourth eigenvector, i.e. the solution to $\M_4
\x_4 = \vb{0}$. In the last equation, $m_{4,44} = 0$. We can therefore choose
$x_{4,4}$ freely. $x_{4,3}$ can then be found by solving the second-to-last
equation. Then the third-to-last equation can be solved, etcetera, until the
whole eigenvector $\x_4$ is found.

When calculating the third eigenvector, $m_{3,44}$ is generally not $0$.
$x_{3,4}$ is then $0$. In the second-to-last equation, both $m_{3,33} = 0$
and $x_{3,4} = 0$, and therefore $x_{3,3}$ can be freely chosen. $x_{3,2}$
can then be calculated from the second equation, and so on.

All generalised eigenvectors can be calculated via this back-substitution
process with an increasing amount of zero components. Combined in one matrix,
the eigenvectors $\x_i$ of $(\Tt,\Ss)$ thus have the following shape (where
an $\cross$ represents a non-zero number):
\[
\begin{bmatrix}
\cross & \cross & \cross & \cross \\
     0 & \cross & \cross & \cross \\
     0 &      0 & \cross & \cross \\
     0 &      0 &      0 & \cross \\
\end{bmatrix}
\]

Finally, the generalised eigenvectors $\w_i$ of $(\A, \B)$ are then found as
$\w_i = \Z \x_i$.

To calculate generalised eigenvectors in practice, the \texttt{eig(A,B)}
functions from MATLAB or from SciPy's \texttt{linalg} module can be used,
which both use implementations of the QZ-algorithm and the back-substitution
process as described above.


\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}    % need for subequations
\usepackage{amsfonts}
\usepackage[ocgcolorlinks]{hyperref}

\setlength{\baselineskip}{16.0pt}    % 16 pt usual spacing between lines

\setlength{\parskip}{3pt plus 2pt}
\setlength{\parindent}{20pt}
\setlength{\oddsidemargin}{0.5cm}
\setlength{\evensidemargin}{0.5cm}
\setlength{\marginparsep}{0.75cm}
\setlength{\marginparwidth}{2.0cm}
\setlength{\marginparpush}{1.0cm}
\setlength{\textwidth}{150mm}

\begin{document}

\section{Exercise 2.13: Tolerances}

\[
    t_{a/b} = t_{ab} = \frac{t_a + t_b}{1 + t_a t_b}
\]

\[
    t_{a+b} = \frac{at_a + bt_b}{a+b}
\]

\[
    t_{a-b} = \frac{at_a + bt_b}{a-b}
\]

\section{Exercise 2.15: Error bounds}

\[
    \min{t_a,t_b} \le \frac{t_a + t_b}{2} \le t_{a/b} = t_{ab} \le t_a + t_b
\]

\[
    \min{t_a,t_b} \le t_{a+b} \le t_a + t_b \le t_{a-b}
\]

\[
    t_a > 0 \implies t_{a/a} \ge t_a > 0
\]

\end{document}


% njr.tex
\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{graphicx} % support the \includegraphics command and optio
\usepackage[fleqn]{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{authblk}

\newcommand{\Var}{\mathop{\rm{Var}}}
\newcommand{\Cov}{\mathop{\rm{Cov}}}
\theoremstyle{definition}
\newtheorem*{example}{}

% \usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

\title{A General Formula for Option Pricing}
\author[1]{Peter Carr}
\author[2]{Keith A. Lewis}
\affil[1]{NYU Tandon School of Engineering}
\affil[2]{KALX, LLC}
\date{\today}

\begin{document}
\maketitle
\begin{abstract}
One of the many nice features of the Black Merton Scholes (BMS)
model is that it generates a simple formula for European option
values. Unfortunately, the model typically contradicts observations
whenever two or more co-terminal option prices are observed. This
is because the model has only one free  parameter sigma which
determines both the mean and variance of the normally distributed log
price. By eschewing normality, one can be consistent with any observed
arbitrage-free volatility smile. In this paper, we present a new general
explicit formula for pricing European options in terms of the cumulants
of normalized log price.

\end{abstract}

\section{Outline}
Consider the problem of determining an arbitrage-free price of
a European put written on a single risky asset.
%Suppose that the put and a zero coupon bond both mature at a fixed future date $t$.
The first Fundamental Theorem of Asset Pricing
(FTAP) implies the existence of an equivalent martingale measure
$\mathbb{Q}$, which corresponds to the choice of the money market account as numeraire.
Assuming that the final price $F$  of the
underlying risky asset is strictly positive,
there exists an equivalent probability measure $\mathbb{Q}^*$,
which corresponds to the choice of the put's underlying as numeraire.
We refer to $\mathbb{Q}$ and $\mathbb{Q}^*$ as risk-neutral measure and share measure respectively.
Let $E$ and $E^*$ respectively denote expectations under the two measures.

The forward value of a $t$ maturity European put option having strike \(k > 0\) is
\begin{equation}
E \max\{k - F, 0\} = E(k - F)1(F \le k) = k \mathbb{Q} (F\le k) - f \mathbb{Q}^* (F\le k),
\label{afp}
\end{equation}
where $f = E F$ is the futures price of the underlying risky asset,  assuming continuous marking to market.
The share measure $\mathbb{Q}^*$ is related to the risk-neutral measure
$\mathbb{Q}$
by $d\mathbb{Q}^*/d\mathbb{Q} = F/f$,
which is the {\em Esscher transform}\cite{Ess1932} of the risk-neutral
measure $\mathbb{Q}$ evaluated at one. In this paper,
we derive explicit series representations of the two probabilities of
the put finishing in-the-money,
\(\mathbb{Q}(F\le k)\) and \(\mathbb{Q}^*(F\le k)\).
The truncated version of these series representations will be accurate
when the log price relative  $L \equiv \log \left( \frac{F}{f} \right)$ is approximately normal.

We suppose that $L$ has finite mean and standard deviation under both
measures \(\mathbb{Q}\) and \(\mathbb{Q}^*\).
Let $s = \sqrt{E (L - EL)^2} > 0$ be the standard deviation of $L$ under
$\mathbb{Q}$.  Call $\kappa \equiv \log E e^{L - EL}$ the cumulant of $L$
under $\mathbb{Q}$.  The cumulant can be interpreted as the analog of
standard deviation when the exponential function replaces the quadratic
function as the convex function in Jensen's inequality. Option prices
can be interpreted as a strike-dependent reflection of the dispersion of
returns on their underlying asset, but this dispersion can be captured
equally well by $s$ or by $\kappa$.

Let $X \equiv \frac{L - EL}{s}$ be the normalized log price relative.
By construction, $X$ has zero mean and unit standard deviation under  \(\mathbb{Q}\).
Clearly, $L - E L = sX$, so the cumulant
can also be written as \(\kappa = \log E e^{sX} \equiv \kappa(s)\).
The function $\kappa(s)$ relating $\kappa$ to $s$ is called
the {\em cumulant generating function} (CGF) of \(X\).
Exponentiating both sides of $\kappa(s) \equiv \log E e^{sX}$
implies that \( E e^{sX -\kappa(s)} = 1 \) for all $s$.
By letting \(F = f e^{sX -\kappa(s)} \), we have \(EF = f\).
The quantity $f > 0$ can be observed as the unique strike at which
European call and put values equate.
Clearly, \( L \equiv \log \left( \frac{F}{f} \right) =  sX -\kappa(s)  \).
Taking expectations under $\mathbb{Q}$,
$EL = -\kappa(s)$.
%Taking expectations under $\mathbb{Q}^*$ instead,
%$E^*L = s E^*X -\kappa(s) \equiv - \kappa^*s$.

We now show that the quantity $s>0$ can be obtained from the
out-of-the-money (OTM) put and call price profiles
$p(k), k \in (0,f)$ and $c(k), k \in [f,\infty)$.
First, calculate the forward price of the log contact
$f_{\log} \equiv E  \log \left( \frac{F}{f} \right)$. From Carr-Madan\cite{CM2001}:
\[
	f_{\log} = \int_0^f \frac{p(k)}{k}\,\frac{dk}{k}
	+ \int_f^{\infty} \frac{c(k)}{k}\,\frac{dk}{k}.
\]
Second, calculate the forward price of the squared log contract
$f_{\log^2} \equiv E  \left( \log^2 \left( \frac{F}{f} \right) \right)$.
\[
	f_{\log^2} = \int_0^f \frac{2}{k^2}
	  \left[ 1 - \log \left( \frac{k}{f} \right) \right] p(k)\,dk
          + \int_f^{\infty} \frac{2}{k^2}\left[ 1
	  - \log \left( \frac{k}{f} \right) \right] c(k)\,dk.
\]
Then $s = \sqrt{f_{\log^2} - f^2_{\log} } > 0$.

% \(m = \frac{ \log (k/f) + \kappa(s) }{s}\)

Since \(F = f e^{sX -\kappa(s)} \),
the two probabilities of the put finishing in-the-money,
\(\mathbb{Q}(F\le k)\) and \(\mathbb{Q}^*(F\le k)\)
can each be expressed as
$\mathbb{Q} (X\le m)$ and $\mathbb{Q}^* (X\le m)$,
where \(m = \frac{ \log (k/f) + \kappa(s) }{s}\)
%and \(m^* = \frac{ \log (k/f) + \kappa^*(s) }{s}\)
measures the put's {\em moneyness}.
%under each measure.
As a result, the formula (\ref{afp}) for the arbitrage-free put futures price can be expressed as
\[
p(k) = E \max\{k - F, 0\} = k \mathbb{Q} (X\le m) - f \mathbb{Q}^* (X \le m).
\]

If \(X\) is standard normal and \(s = \sigma\sqrt{t}\),
then this is the Black\cite{Bla1976} put formula. Recall
\(
E\exp(N) = \exp(E N + \Var(N)/2)
\)
if \(N\) is
normal, and
\(
E \exp(N) f(M) = E\exp(N) Ef(M + \Cov(N,M))
\)
if \(N\) and \(M\) are jointly normal. We have
\(\kappa(s) = \log E \exp(sX) = s^2/2 \) and
\(E^* f(X) = E \exp(sX-s^2/2) f(X)
= E f(X + s)\). In the usual notation,
\(m = -d_2 = (\log (k/f) + \sigma^2t/2)/\sigma\sqrt{t} \)
and \(\mathbb{Q}^*(X \le m) = \mathbb{Q} (X + \sigma\sqrt{t} \le -d_2)
= \mathbb{Q}(X \le -d_1)\) where \(d_1 = d_2 + \sigma\sqrt{t}\).

In section 2, we recall some basic facts about cumulants and their
relationship to moments involving Bell polynomials.  Section 3 uses an
Edgeworth expansion, and Hermite polynomials to get an explicit formula
for the cumulative distribution function of the perturbed distribution.

A formula for calculating the Esscher transform with unit argument is
developed in section 4 using the same technique as in the preceding
section.

Section 5 catalogs how to use the general formula to calculate
option prices for many known models: Merton's jump diffusion \cite{},
Carr-Madan-???? variance gamma \cite{}, Kou's double exponential jump
\cite{}.
The primary contribution of this paper is an efficient option
pricing formula for any model that is a perturbation of
Black-Scholes/Merton.

The paper concludes with some general remarks.

\section{Cumulants}

The {\em cumulant generating function} of the random variable \(X\)
is \(\kappa(s) = \log Ee^{sX}\).
When they exist, the {\em cumulants}, \((\kappa_n)\),
are defined by
\[
\kappa(s) = \sum_{n=1}^\infty \kappa_n \frac{s^n}{n!}
\]
Since the \(n\)-th derivative evaluated at \(0\)
satisfies \(\kappa^{(n)}(s)|_{s = 0} = \kappa_n\)
it is easy to
work out that
\(\kappa_1 = EX\) and \(\kappa_2 = \Var(X)\). Higher order
cumulants are less intuitive but the third and fourth are
related to skew and kurtosis. [Insert explicit formulas here.]

The cumulants of a random variable plus a constant are the
same except the first cumulant is increased by the constant.
More generally, the cumulants of the sum of two independent
random variables are the sums of their cumulants.
They scale homogeneously, the \(n\)-th cumulant of a constant
times a random variable is
\(\kappa_n(cX) = c^n\kappa_n(X)\).

The exponential of the cumulant in terms of
powers of \(s\) is
\[
Ee^{sX} =  \exp(\sum_{n=1}^\infty \kappa_n \frac{s^n}{n!})
= \sum_{n=0}^\infty B_n(\kappa_1,\dots,\kappa_n) \frac{s^n}{n!}
\]
where \(B_n(\kappa_1,\dots,\kappa_n)\) is the \(n\)-th complete
Bell polynomial.
This is just a special case of the
Fa\`a di Bruno formula first proved by Louis Fran\c{c}ois Antoine
Arborgast in 1800\cite{Arb1800}.
Bell polynomials satisfy the recurrence \cite{Com1974} \(B_0 = 1\) and
\[
B_{n+1}(x_1,\dots,x_{n+1}) = \sum_{k=0}^n \binom{n}{k}
B_{n - k}(x_1,\dots, x_{n - k}) x_{k+1}.
\]

The first few Bell polynomials are $B_0 = 1$, $B_1(x_1) = x_1$,
$B_2(x_1, x_2) = x_1^2 + x2$,
$B_3(x_1, x_2, x_3) =
%= B2 x1 + 2 B1 x2 + B0 x3
%= x1^3 +  x2 x1 + 2 x1 x2 + x3
x_1^3 + 3x_1x_2 + x_3$,
$B_4(x_1, x_2, x_4) =
%= B3 x1 + 3 B2 x2 + 3 B1 x3 + B0 x4
%= (x1^3 + 3 x_1 + x3)x1 + 3 (x1^2 + x2) x2 + 3 x1 x3 + B0 x4
%= (x1^4 + 3 x_1^2x_2 + x1x3) + 3 (x1^2x2 + x2^2)  + 3 x1 x3 + x4
%= x1^4 + 6 x_1^2x_2 + 4x1x3 + 3x2^2  + x4
x1^4 + 6 x_1^2 x_2 + 4 x_1 x_3 + 3 x_2^2  + x4$.

\section{Edgeworth Expansion}
Let $\psi$ be the probability density of a random variable, $X$,
with expected value 0 and mean 1.
The the Fourier transform is

\begin{align*}
E e^{-iuX} &= e^{\sum_{n=1}^\infty \kappa_n (-iu)^n/n!}\\
           &= e^{-u^2/2} e^{\sum_{n=3}^\infty \kappa_n (-iu)^n/n!}\\
           &= e^{-u^2/2} \sum_{n=0}^\infty B_n(0, 0, \kappa_3,...,\kappa_n)(-iu)^n/n!.\\
	   &= e^{-u^2/2} (1 + \sum_{n=3}^\infty B_n(0, 0, \kappa_3,...,\kappa_n)(-iu)^n/n!.\\
\end{align*}

where \((\kappa_n)\) are the cumulants of \(X\).

The Fourier transform, \(\hat{f}(u) = Ee^{-iuX}\),
of \(f'\) is \(iu \hat f(u)\) so
the Fourier transform of the \(n\)-th derivative
\(f^{(n)}\) is \((iu)^n\hat f(u)\) hence
\begin{align*}
\hat{\psi}(u) &= \hat{\phi}(u)(1 + \sum_{n=3}^\infty B_n(0, 0,\kappa_3,...,\kappa_n) (-iu)^n/n!\\
	&= \hat{\phi}(u) + \sum_{n=3}^\infty (-1)^n B_n(0, 0, \kappa_3,...,\kappa_n)
	\widehat{\phi^{(n)}}(u)/n!\\
\end{align*}
where \(\phi(x) = e^{-x^2/2}\). Note \(\hat{\phi}(u) = e^{-u^2/2}\).
Taking inverse Fourier transforms and integrating both
sides yields
\begin{equation}
	\Psi(x) = \Phi(x) + \sum_{n=3}^\infty (-1)^n B_n(0,0,\kappa_3,...,\kappa_n) \Phi^{(n)}(x)/n!.
\end{equation}

\subsection{Hermite Polynomials}
The derivatives of the standard normal density
can be computed using Hermite polynomials\cite{AbrSte1964}
pp. 793--801.
One definition is
\[
H_n(x) = (-1)^n e^{x^2/2}\frac{d^n}{dx^n}e^{-x^2/2}.
\]
They satisfy the recurrence \(H_0(x) = 1\), \(H_1(x) = x\) and
\[
H_{n+1}(x) = xH_n(x) - n H_{n-1}(x).
\]
Note some authors use \(He_n(x)\) instead of \(H_n(x)\).
This shows \(\phi^{(n)}(x) = (-1)^n\phi(x) H_n(x)\)
so \(\Phi^{(n)} = (-1)^{n-1} H_{n-1}(x)\) for \(n > 0\).

We now have an explicit formula for the cumulative
distibution function of \(X\):
\begin{equation}
\Psi(x) = \Phi(x) - \phi(x)\sum_{n=1}^\infty
B_n(\kappa_1,\dots,\kappa_n) H_{n-1}(x)/n!
\end{equation}

\section{The Esscher Transform}

Given any random variable, \(X\), and number \(s\), define
\(X^*\) by \(P(X^*\le x) = P^*(X\le x)\) where
\(dP^*/dP = e^{-\kappa(s) + sX}\).
The cumulant of \(X^*\) is \(\kappa^*(u) = \kappa(u + s) - \kappa(s)\),
where \(\kappa\) is the cumulant of \(X\).
This follows from \(E^* e^{uX} = Ee^{sX - \kappa(s)} e^{uX}
= e^{\kappa(s + u) - \kappa(s)}\).

It follows that the \(n\)-th derivative satisfies
\(\kappa^{*(n)}(u) = \kappa^{(n)}(u + s)\), for \(n > 0\),\
and setting $u=0$, \(\kappa^*_n = \kappa^{*(n)}(0) = \kappa^{(n)}(s)\).

The last expression can be expressed as \(\kappa^{(n)}(s) =
\sum_{k=0}^\infty \kappa_{n - k} s^k/k!\), but for many random variables,
we can use the closed form solution on the left-hand side instead of
the infinite sum.

%
%The Edgeworth series expands the exponential in a power series.
%\[\exp\bigl(\sum_{n=0}^\infty \Delta\kappa_n (iu)^n/n!\bigr)
%= \sum_{k=0}^\infty (\sum_{n=0}^\infty \Delta\kappa_n (iu)^n/n!)^k/k!\]
%

%\subsection{Computations}
%Explicit formulas the first few Bell polynomials:
%\begin{align*}
%B_0 &= 1\\
%B_1 &= x_1\\
%B_2 &= B_1 x_1 + B_0 x_2\\
%&= x_1^2 + x_2\\
%B_3 &= B_2 x_1 + 2B_1 x_2 + B_0 x_3\\
%&= x_1^3 + x_1 x_2 + 2x_1 x_2 + x_3\\
%&= x_1^3 + 3x_1 x_2 + x_3\\
%B_4 &= B_3 x_1 + 3 B_2 x_2 + 3 B_1 x_3 + B_0 x_4\\
%&= (x_1^3 + 3x_1 x_2 + x_3) x_1  + 3 (x_1^2 + x_2)x_2 + 3 x_1 x_3 + x_4\\
%&= x_1^4 + 6x_1^2 x_2 + 4 x_1 x_3 + 3x_2^2 + x_4\\
%\end{align*}
%Explicit formulas for the first few Hermite polynomials:
%\begin{align*}
%H_0 &= 1\\
%H_1 &= x\\
%H_2 &= x^2 - 1\\
%H_3 &= x^3 - x\\
%H_4 &= x^4 - 6x^2 + 3\\
%H_5 &= x^5 - 10x^3 + 15x\\
%H_6 &= x^6 - 15x^4 + 45x^2 - 15\\
%\end{align*}
%
%Assuming \(\kappa_1 = \kappa_2 = 0\) the first few terms of the Edgeworth expansion are:
%\begin{align*}
%G(x) &= \sum_{n=0}^\infty (-1)^n B_n F^{(n)}(x)/n!\\
%&= F(x) - B_1 F'(x) + B_2F''(x)/2 - B_3F^{(3)}(x)/6 + B_4F^{(4)}/24\\
%&= F(x) + (-\kappa_3 (x^2 - 1)/6 - \kappa_4 (x^3-x)/24)e^{-x^2/2}/\sqrt{2\pi}\\
%\end{align*}
%The distribution is unimodal if and only if the second derivative has exactly one root.
%\begin{align*}
%G''(x) &= \sum_{n=0}^\infty (-1)^n B_n F^{(n+1)}(x)/n!\\
%&= F^{(2)}(x) - B_1 F^{(3)}(x) + B_2F^{(4)}(x)/2 - B_3F^{(5)}(x)/6 + B_4F^{(6)}/24\\
%&= (-x - \kappa_3 (x^4 - 6x^2 + 3)/6
%	 - \kappa_4 (x^5 - 10x^3 + 15x)/24)e^{-x^2/2}/\sqrt{2\pi}\\
%\end{align*}
%
\subsection{Examples}
\begin{example}[Normal]
A normally distributed random variable, \(X\), has density function
\(f(x) = e^{-(x - \mu)^2/2\sigma^2}/\sigma\sqrt{2\pi}\), \(-\infty<x<\infty\),
with mean \(\mu\) and variance \(\sigma^2\).
The cumulant is \(\kappa(s) = \mu s + \sigma^2s^2/2\) so
\(\kappa_1 = \mu\) and \(\kappa_2 = \sigma^2\) are the only non-zero
cumulants.

Since \(\kappa^*(u) = \kappa(u + s) - \kappa(s) = (\mu + \sigma^2s)u + \sigma^2u/2\)
we see that \(\kappa^*_1 = \kappa_1 + \sigma^2\) and \(\kappa^*_2 = \kappa_2\). The
Esscher transform of a normally distributed random variable is normal
with mean \(\mu^* = \mu + \sigma^2\) and variance \(\sigma^{*2} = \sigma^2\).

If the cumulants of a random variable vanish after some some point, then it must
be normal\cite{Luk1970} (Theorem 7.3.5). \end{example}

\begin{example}[Gamma]
A gamma distributed random variable, \(X\), has density function
\(f(x) = x^{\alpha - 1} e^{-x/\beta}/\beta^\alpha\Gamma(\alpha)\), \(x > 0\),
with mean \(\alpha\beta\) and variance \(\alpha\beta^2\).
The cumulant is \(\kappa(s) = -\alpha\log(1 - \beta s)\) so
\(\kappa_n = \kappa^{(n)}(0) = (n-1)!\alpha\beta^n\) since
\(\kappa^{(n)}(s) = (n-1)!\alpha\beta^n/(1 - \beta s)^n\).

Since \(\kappa^*(u) = \kappa(u + s) - \kappa(s) = -\alpha\log (1 - \beta u/(1 - \beta s)\),
the Esscher transform of a gamma distributed random variable is gamma
with \(\alpha^* = \alpha\) and \(\beta^* = \beta/(1 - \beta s)\).

Note that an exponentially distributed random variable is the special case when
\(\alpha = 1\).
\end{example}

\begin{example}[Poisson]
If \(X\) is Poisson
with mean \(\mu\) then \(\kappa(s) = \mu(e^s - 1)\) so
\(\kappa_n = \mu\) for all \(n\) and
\(\kappa_n^* = \mu e^s\).
\end{example}
%\begin{example}[Compound Poisson]
%If \(Y\) is Poisson with mean \(\mu\) and \(Z_j\) are
%independent and identically distributed, define
%\(X = \sum_{j=1}^{Y} Z_j\). The cumulants of \(X\)
%are \(\kappa_n = ?\).
%\end{example}
%\begin{align*}
%Ee^{uX} &= \sum_{k=0}^\infty Ee^{u(Z_1 + \cdots Z_k)}\mu^k/k!\,e^{-\mu}\\
%&= \sum_{k=0}^\infty (Ee^{u Z_1})^k\mu^k/k!\,e^{-\mu}\\
%&= \sum_{k=0}^\infty (Ee^{u Z_1}\mu)^k/k!\,e^{-\mu}\\
%&= e^{\mu Ee^{u Z_1}}\,e^{-\mu}\\
%&= e^{\mu (Ee^{u Z_1} - 1)}\\
%\end{align*}
%Define \(\lambda(u) = \log Ee^{uZ_1}\). Then
%\(\log E e^{uX} = \mu(e^{\lambda(u)} -1)\).

\begin{example}[VG]
The Variance Gamma model is the difference of independent Gamma distributions
so \(\kappa_n = (n-1)!(\alpha\beta^n - \alpha'\beta'^n)\).
In order for this to be a perturbation of a standard normal
distribution we need \(0 = \alpha\beta - \alpha'\beta'\)
and \(1 = \alpha\beta^2 - \alpha'\beta'^2\).
Using mean and standard deviation
\(\mu = \mu'\) and \(\sigma^2 = 1 + \sigma'^2\).
For convergence we need \(1 < \sigma^2 \lll \mu\).
\end{example}

\begin{example}[Compound Poisson]
Assume \(Y_i\) are independent and identically distributed. If \(N\) is
Poisson with parameter \(\lambda\) then \(X\) is {\em compound Poisson}
if \(X = \sum_{i=0}^N Y_i\).
The exponential of the cumulant of X is
\begin{align*}
Ee^{sX} &= Ee^{s\sum_{i=0}^N Y_i}\\
&= \sum_{k=0}^\infty \frac{\lambda^k}{k!}e^{-\lambda}(Ee^{Y_i})^k\\
&= \sum_{k=0}^\infty \frac{\lambda^k}{k!}e^{-\lambda}(e^{\kappa^Y(s)})^k\\
&= \sum_{k=0}^\infty \frac{(\lambda e^{\kappa^Y(s)})^k}{k!}e^{-\lambda}\\
&= e^{\lambda(e^{\kappa(s) - 1})}
\end{align*}
\end{example}

\begin{example}[Jump Diffusion]
Merton's \cite{Mer?} jump diffusion model assumes
\(X = \alpha Z + \beta\sum_{k=0}^N Y_k\) where
\(N\) is Poisson and \(Y_k\) are independent normal.
\end{example}

\begin{example}[Double Exponential]
\(f(y) = p\eta_1 e^{-\eta_1 y}1(y > 0) + (1 - p)\eta_2 e^{\eta_2 y}1(y < 0)\)

\begin{align*}
Ee^{sY} &= \int_0^\infty e^{sx} pe^{-\eta_1 y}\,dy
+ \int_{-\infty}^0 e^{sy} (1-p)e^{\eta_2 y}\,dy\\
&= \frac{p}{1-s/\eta_1} + \frac{1-p}{1 + s/\eta_2}
\end{align*}

\(\kappa^Y_n = n!(\frac{p}{\eta_1^n} + \frac{1-p}{(-\eta_2)^n})\)
\end{example}

%\begin{align*}
%Ee^{uX} &= \int_0^\infty e^{ux} x^{\alpha-1} e^{-\beta x}
%\frac{\beta^\alpha}{\Gamma(\alpha)}\,dx\\
%&= \int_0^\infty x^{\alpha-1} e^{-(\beta -u) x}
%\frac{\beta^\alpha}{\Gamma(\alpha)}\,dx\\
%&= \frac{\Gamma(\alpha)}{(\beta - u)^\alpha} \frac{\beta^\alpha}{\Gamma(\alpha)}\\
%&= (1 - u/\beta)^{-\alpha}\\
%\end{align*}
%so
%\(
%\log E e^{uX} = \alpha \sum_{n=1}^\infty (u/\beta)^n/n\).

%At the money pricing ???
%%F = fe^{-k(s) + s X}, x \le k(s)/s
%
%\begin{align*}
%&P(F\le f) - P^*(F\le f) \\
%&= P(Y\le \kappa(s)/s) - P^*(Y\le \kappa(s)/s) \\
%&= G(\kappa(s)/s) - G^*(\kappa(s)/s) \\
%&= \sum_{n=1}^\infty (-B_n(\Delta\kappa) + B_n(\Delta\kappa^*))
%    e^{-(\kappa(s)/s)^2/2} H_{n-1}(\kappa(s)/s)/sqrt{2\pi} \\
%& = \Phi(s/2) - \Phi(-s/2) \\
%\end{align*}

%\(\chi^2\) with \(r\) degrees of freedom \(\kappa_n = 2^{n-1}(n-1)!r\).

\subsection{L\'evy Processes}

%Let \(X = aN + bP + c\) where \(N\) is standard normal and \(P\)
%is Poisson with mean \(\mu\).

%\(EX = b\mu + c\) and \(\Var X = a^2 + b^2\). Taking
%\(b = \sqrt{1 - a^2}\)

Kolmogorov's precursor to the L\'evy-Khintchine theorem\cite{Kol1992}
states that if a random variable \(X\) is infinitely divisible
and has finite variance
there exists a number \(\gamma\) and a non-decreasing function
\(G\) defined on the real line such that
\[
\kappa(s) = \log Ee^{sX} = \gamma s + \int_{-\infty}^\infty K_s(x)\,dG(x),
\]
where \(K_s(x) = (e^{sx} - 1 - sx)/x^2 = \sum_{n=2}^\infty s^nx^{n-2}/n!\).
Note the first cumulant of \(X\) is \(\gamma\) and for \(n\ge 2\),
\(\kappa_n = \int_{-\infty}^\infty x^{n-2}\,dG(x)\).

The Hamburger moment problem[cite?] provides the answer to
what the allowable cumulants are: the Hankel matrix
\([\kappa_{i+j}]_{i,j\ge 2}\) must be positive definite.

Since \(K_s(0) = s^2/2\) is the cumulant of the standard normal
distribution and \(a^2K_s(a) + as\) is the cumulant of a
Poisson distribution having mean \(a\),
infinitely divisible random variables can be
approximated by a normal plus a linear combination of
independent Poisson distributions.

%The K-model takes \(\gamma = 0\) and \(G\) of the form
%\[
%G(x) =
%\begin{cases}
%a e^{x/\alpha} &x < 0\\
%1 - be^{-x/\beta} & x > 0\\
%\end{cases}
%\]
%Note \(G\) jumps by \(1 - a - b\) at the origin. If \(a = b = 0\)
%this reduces to a standard normal distribution.
%
%The cumulants are simple to compute: \(\kappa_1 = 0\), \(\kappa_2 = 1\),
%and \(\kappa_{n+2} = (a(-\alpha)^n + b\beta^n)n!\) for \(n > 1\).

\section{Greeks}

$F = fe^{sX - \kappa(s)}$.

$v = E g(F)$.

$dv/df = Eg'(F) e^{sX - \kappa(s)} = E^*g'(F)$.

$dv/ds = E g'(F) fe^{sX - \kappa(s)} (X - \kappa'(s))
       = fE^* g'(F) (X - E^*X)$

\section{Remarks}
The Gram-Charlier A series expands the quotients of cumulative
distribution functions \(G/F\) using Hermite polynomials, but does not
have asymptotic convergence, whereas the Edgeworth expansion involves
the quotient of characteristic functions \(\hat G/\hat F\) in terms of
cumulants and does have asymptotic convergence, ignoring some dainty
facts \cite{Pet1975}.

If \((X_t)\) is a L\'evy process then \(X_1\) is
infinitely divisible and \(\log Ee^{sX_t} = t\kappa(s)\).
A consequence is that the volatility smile at a single
maturity determines the entire volatility surface, a fact that
may indicate L\'evy processes are not appropriate for
modeling stock prices.

A software implementation in C++ is available at
\url{https://fmsgjr.codeplex.com} and Excel add-ins
at \url{https://xllgjr.codeplex.com} that require
\url{https://xll.codeplex.com}.

\bibliographystyle{amsplain}
\bibliography{njr}

\end{document}


% $Id: aboutcryptool.tex 3714 2016-04-08 18:34:16Z esslinger $
% ............................................................................
%      O v e r v i e w   (Text of the 4th page, before the Content)
%
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\clearpage\phantomsection

\addcontentsline{toc}{chapter}{Overview about the Content of the CrypTool Book}
\chapter*{Overview about the Content of the CrypTool Book}

\parskip 4pt
%\vskip +12 pt
The rapid spread of the Internet has led to intensified research in the
technologies involved, especially within the area of cryptography where a good
deal of new knowledge has arisen.

In this {\em book accompanying the CrypTool programs} \index{CrypTool}
you will find predominantly mathematically oriented information on using
cryptographic procedures. Also included are many sample code pieces written in the
computer algebra system {\bf SageMath}\index{SageMath} (see appendix~\ref{s:appendix-using-sage}).
The main chapters have been written by various {\bf authors}
(see appendix~\ref{s:appendix-authors})
and are therefore independent from one another. At the end of most chapters
you will find references and web links.
The sections have been enriched with many {\em footnotes}. Within the footnotes
you can see where the described functions can be called in the different CrypTool
versions.

The \hyperlink{Chapter_EncryptionSecDefinitions}{first chapter} explains the
principles of symmetric and asymmetric \hyperlink{Chapter_EncryptionSecDefinitions}
{\bf encryption} and list definitions for their resistibility.

Because of didactic reasons the \hyperlink{Chapter_PaperandPencil}
{second chapter} gives an exhaustive overview about
\hyperlink{Chapter_PaperandPencil}{\bf paper and pencil encryption methods}.

Big parts of this book are dedicated to the fascinating topic of
\hyperlink{Chapter_Primes}{\bf prime numbers} (chap. \ref{Chapter_Primes}).
Using numerous examples, \hyperlink{Chapter_ElementaryNT}{\bf modular arithmetic}
and \hyperlink{Chapter_ElementaryNT}{\bf elementary number theory}
(chap. \ref{Chapter_ElementaryNT}) are introduced. Here, the features
of the {\bf RSA procedure} are a key aspect.

By reading chapter \ref{Chapter_ModernCryptography}
you'll gain an insight into the mathematical ideas and concepts behind
\hyperlink{Chapter_ModernCryptography}{\bf modern cryptography}.

Chapter \ref{Chapter_Hashes-and-Digital-Signatures} gives
an overview about the status of attacks against modern
\hyperlink{Chapter_Hashes-and-Digital-Signatures}{\bf hash algorithms}
and is then shortly devoted to \hyperlink{Chapter_Hashes-and-Digital-Signatures}
{\bf digital signatures},
which are an essential component of e-business applications.

Chapter \ref{Chapter_EllipticCurves} describes \hyperlink{Chapter_EllipticCurves}
{\bf elliptic curves}: They could be used as an alternative to RSA and in addition
are extremely well suited for implementation on smartcards.

Chapter \ref{Chapter_BitCiphers} introduces \hyperlink{Chapter_BitCiphers}{\bf Boolean algebra}.
Boolean algebra is the foundation for most modern, symmetric encryption algorithms
as these operate on bit streams and bit groups. Principal construction
methods are described and implemented in SageMath.

Chapter \ref{Chapter_HomomorphicCiphers} describes
\hyperlink{Chapter_HomomorphicCiphers}{\bf homomorphic crypto
functions}: They are a modern research topic which got especial attention
in the course of cloud computing.

Chapter \ref{Chapter_Dlog-FactoringDead} describes
\hyperlink{Chapter_Dlog-FactoringDead}{\bf Current Results
for Solving Discrete Logarithms and Factoring}.
It provides a broad picture and comparison about the currently best
algorithms for (a) computing discrete logarithms in various groups,
for (b) the status of the factorization problem, and for (c) elliptic
curves. This survey was put together as a reaction to a provocative
talk at the Black Hat Conference 2013 which caused some uncertainty
by incorrectly extrapolating progress at finite fields of small
characteristics to the fields used in real world.

The \hyperlink{Chapter_Crypto2020}{last chapter}
\hyperlink{Chapter_Crypto2020}{\bf Crypto2020}
discusses threats for currently used cryptographic methods and introduces
alternative research approaches (post-quantum crypto) to achieve long-term
security of cryptographic schemes.

Whereas the CrypTool \textit{e-learning programs}\index{e-learning} motivate
and teach you how to use cryptography in practice, the \textit{book} provides
those interested in the subject with a deeper understanding of the mathematical
algorithms used -- trying to do it in an instructive way.

Within the \hyperlink{appendix-start}{\bf appendices}
\ref{s:appendix-menu-overview-CT1},
\ref{s:appendix-template-overview-CT2},
\ref{s:appendix-function-overview-JCT}, and
\ref{s:appendix-function-overview-CTO}
you can gain a fast overview about the functions delivered by the different
CrypTool variants\index{CT1}\index{CT2}\index{JCT}\index{CTO} via:
\begin{itemize}
  \item the function list and
        the \hyperlink{appendix-menu-overview-CT1}
                      {menu tree of CrypTool~1 (CT1)},
  \item the function list and
        the \hyperlink{appendix-template-overview-CT2}
                      {templates in CrypTool~2 (CT2)},
  \item the \hyperlink{appendix-function-overview-JCT}
                      {function list of JCrypTool (JCT)}, and
  \item the \hyperlink{appendix-function-overview-CTO}
                      {function list of CrypTool-Online (CTO)}.
\end{itemize}

% Bernhard Esslinger, Matthias B\"uger, Bartol Filipovic, Henrik Koy,
% Roger Oyono and J\"org Cornelius Schneider
The authors would like to take this opportunity to thank their colleagues
in the particular companies and at the universities of Bochum, Darmstadt,
Frankfurt, Gie\ss en, Karlsruhe, Lausanne, Paris, and Siegen.

\enlargethispage{12pt}
As with the e-learning program CrypTool\index{CrypTool}, the quality of the
book is enhanced by your suggestions and ideas for improvement.
We look forward to your feedback.

% Local Variables:
% TeX-master: "../script-en.tex"
% End:


\subsection{Hedonic games}

\subsubsection{Introduction}

\subsubsection{Core stability}