%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Beamer Presentation
% LaTeX Template
% Version 1.0 (10/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ----------------------------------------------------------------------------------------
%	PACKAGES AND THEMES
% ----------------------------------------------------------------------------------------

\documentclass[hyperref={colorlinks=true}]{beamer}

\mode<presentation> {

  % The Beamer class comes with a number of default slide themes
  % which change the colors and layouts of slides. Below this is a list
  % of all the themes, uncomment each in turn to see what they look like.

  \usetheme{default}
  % \usetheme{AnnArbor}
  % \usetheme{Antibes}
  % \usetheme{Bergen}
  % \usetheme{Berkeley}
  % \usetheme{Berlin}
  % \usetheme{Boadilla}
  % \usetheme{CambridgeUS}
  % \usetheme{Copenhagen}
  % \usetheme{Darmstadt}
  % \usetheme{Dresden}
  % \usetheme{Frankfurt}
  % \usetheme{Goettingen}
  % \usetheme{Hannover}
  % \usetheme{Ilmenau}
  % \usetheme{JuanLesPins}
  % \usetheme{Luebeck}
  % \usetheme{Madrid}
  % \usetheme{Malmoe}
  % \usetheme{Marburg}
  % \usetheme{Montpellier}
  % \usetheme{PaloAlto}
  % \usetheme{Pittsburgh}
  % \usetheme{Rochester}
  % \usetheme{Singapore}
  % \usetheme{Szeged}
  % \usetheme{Warsaw}

  % As well as themes, the Beamer class has a number of color themes
  % for any slide theme. Uncomment each of these in turn to see how it
  % changes the colors of your current slide theme.

  % \usecolortheme{albatross}
  % \usecolortheme{beaver}
  % \usecolortheme{beetle}
  % \usecolortheme{crane}
  % \usecolortheme{dolphin}
  % \usecolortheme{dove}
  % \usecolortheme{fly}
  % \usecolortheme{lily}
  % \usecolortheme{orchid}
  \usecolortheme{rose}
  % \usecolortheme{seagull}
  % \usecolortheme{seahorse}
  % \usecolortheme{whale}
  % \usecolortheme{wolverine}

  % \setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line
  % \setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line

  % \setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line
}

\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage{cancel}
\usepackage{amsmath}
\usepackage{amssymb}
% \usepackage{showframe}
\usepackage{caption}

%\usepackage{subcaption}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\tcbuselibrary{skins}


\usepackage{subfig}
\beamertemplatenavigationsymbolsempty
\usepackage{color, colortbl}
\definecolor{LRed}{rgb}{1,.8,.8}
\definecolor{MRed}{rgb}{1,.6,.6}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shapes.multipart,fit,shapes.misc,positioning}
\newcommand{\der}[2]{\frac{\partial #1}{\partial #2}}
%\usepackage[labelformat=empty]{caption}

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\makeatletter
\def\@listi{\leftmargin\leftmargini
            \topsep 3\p@ \@plus2\p@ \@minus2.5\p@
            \parsep 0\p@
            \itemsep\fill}
\let\@listI\@listi
\makeatother

% \makeatletter
% \def\@listii{\leftmargin\leftmarginii
%             \topsep 3\p@ \@plus2\p@ \@minus2.5\p@
%             \parsep 0\p@
%             \itemsep\fill}
% \let\@listI\@listii
% \makeatother

\makeatletter
\def\@listii{\leftmargin\leftmarginii
              \topsep    1ex
              \parsep    0\p@   \@plus\p@
              \itemsep   \fill}
\makeatother

\makeatletter
\def\@listiii{\leftmargin\leftmarginiii
              \topsep    1ex
              \parsep    0\p@   \@plus\p@
              \itemsep   \fill}
\makeatother

\makeatletter
\def\rowcolor{\noalign{\ifnum0=`}\fi\bmr@rowcolor}
\newcommand<>{\bmr@rowcolor}{%
  \alt#1%
  {\global\let\CT@do@color\CT@@do@color\@ifnextchar[\CT@rowa\CT@rowb}%
  {\ifnum0=`{\fi}\@gooble@rowcolor}%
}

\makeatletter
\renewcommand{\itemize}[1][]{%
  \beamer@ifempty{#1}{}{\def\beamer@defaultospec{#1}}%
  \ifnum \@itemdepth >2\relax\@toodeep\else
    \advance\@itemdepth\@ne
    \beamer@computepref\@itemdepth% sets \beameritemnestingprefix
    \usebeamerfont{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamercolor[fg]{itemize/enumerate \beameritemnestingprefix body}%
    \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body begin}%
    \list
      {\usebeamertemplate{itemize \beameritemnestingprefix item}}
      {\def\makelabel##1{%
          {%
            \hss\llap{{%
                \usebeamerfont*{itemize \beameritemnestingprefix item}%
                \usebeamercolor[fg]{itemize \beameritemnestingprefix item}##1}}%
          }%
        }%
      }
  \fi%
  \setlength\itemsep{\fill}
    \ifnum \@itemdepth >1
        \vfill
    \fi%
  \beamer@cramped%
  \raggedright%
  \beamer@firstlineitemizeunskip%
}

\def\enditemize{\ifhmode\unskip\fi\endlist%
  \usebeamertemplate{itemize/enumerate \beameritemnestingprefix body end}
  \ifnum \@itemdepth >1
        \vfil
  \fi%
  }
\makeatother

\newcommand\marktopleft[1]{%
    \tikz[overlay,remember picture]
        \node (marker-#1-a) at (0,1.5ex) {};%
}
\newcommand\markbottomright[1]{%
    \tikz[overlay,remember picture]
        \node (marker-#1-b) at (7ex,0) {};%
    \tikz[overlay,remember picture,thick,dashed,inner sep=3pt]
        \node[draw=black,rounded corners=0pt,fill=red,opacity=.2,fit=(marker-#1-a.center) (marker-#1-b.center)] {};%
}


% ----------------------------------------------------------------------------------------
%	TITLE PAGE
% ----------------------------------------------------------------------------------------

\title[]{Macro II: Stochastic Processes I} % The short title appears at the bottom of every slide, the full
% title is only on the title page

\author{Professor Griffy} % Your name
\institute[University at Albany, SUNY] % Your institution as it will appear on the bottom of
% every slide, may be shorthand to save space
{
UAlbany  \ % Your institution for the title page
}
\date{Spring 2024} % Date, can be changed to a custom date

\begin{document}

\begin{frame}
  \titlepage % Print the title page as the first slide
\end{frame}




% ----------------------------------------------------------------------------------------
%	PRESENTATION SLIDES
% ----------------------------------------------------------------------------------------

% ------------------------------------------------
\section{Introduction} % Sections can be created in order to organize your presentation into discrete blocks, all sections and subsections are automatically printed in the table of contents as an overview of the talk
% ------------------------------------------------

\begin{frame}
  \frametitle{Introduction}
  \begin{itemize}
  \item Today: start talking about time series/stochastic processes.
  \item Homework due tonight?
  \item Continue stochastic processes on Tuesday.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Stochastic Processes}
  \begin{itemize}
  \item Random variables
  \item Conditional distributions
  \item Markov processes
  \end{itemize}
\end{frame}

% ------------------------------------------------

\section{Random Variables and Moments}
\begin{frame}\frametitle{Preliminaries}
\begin{itemize}
\item $X$ is a random variable, $x$ is its realization

\item Support: smallest set $S$ such that $\Pr \left( x\in S\right) =1$

\item Cumulative distribution function: $F\left( x\right) =\Pr (X\leq x)$

\item Density function: $f\left( x\right) =\frac{d}{dx}F\left( x\right) $
implying that $f\left( x\right) dx=dF\left( x\right) $\pagebreak
\end{itemize}
\end{frame}

\section{Moments}

\begin{frame}\frametitle{The Expected Value}
\begin{itemize}
\item Mean is the expectation
\begin{equation*}
\bar{X}=E\left( X\right) =\int_{-\infty }^{\infty }xdF\left( x\right)
=\int_{-\infty }^{\infty }xf\left( x\right) dx
\end{equation*}

\item The expectation of a function of a random variable, $g\left( X\right)
, $\ is%
\begin{equation*}
E\left( g\left( X\right) \right) =\int_{-\infty }^{\infty }g\left( X\right)
dF\left( x\right)
\end{equation*}

\begin{itemize}
\item Note that $E\left( g\left( X\right) \right) \neq g\left( \bar{X}%
\right) $ unless $g\left( X\right) $ is linear, i.e.%
\begin{equation*}
g\left( X\right) =b\cdot X
\end{equation*}
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}
  \frametitle{The Variance}
\begin{itemize}
\item Variance\vfill
\begin{equation*}
V\left( X\right) =E\left[ \left( X-\bar{X}\right) ^{2}\right]
\end{equation*}\vfill

\item Standard deviation%
\begin{equation*}
\left[ V\left( X\right) \right] ^{\frac{1}{2}}
\end{equation*}
\pagebreak
\end{itemize}
\end{frame}

\section{Bivariate Distribution}

\begin{frame}
  \frametitle{Jointly Distributed Random Variables}
\begin{itemize}
\item Random vector $\left( X,Y\right) $

\item Joint distribution function: $F\left( x,y\right) =\Pr (X\leq x,Y\leq
y) $

\item Covariance: $C\left( X,Y\right) =E\left[ \left( X-\bar{X}\right) \cdot
\left( Y-\bar{Y}\right) \right] $

\item Cross-correlation =$\frac{C\left( X,Y\right) }{\left[ V\left( X\right)
\cdot V\left( Y\right) \right] ^{\frac{1}{2}}}$

\item Expectation of a linear combination%
\begin{equation*}
E\left( aX+bY\right) =aE\left( X\right) +bE\left( Y\right)
\end{equation*}
\end{itemize}
\end{frame}

\section{Stochastic Processes}

\begin{frame}
  \frametitle{What is a Stochastic Process?}
\begin{itemize}
\item Stochastic process is an infinite sequence of random variables $%
\left\{ X_{t}\right\} _{t=-\infty }^{\infty }$

\item j'th autocovariance = $\gamma _{j}=C\left( X_{t},X_{t-j}\right) $

\item Strict stationarity: distribution of $\left(
X_{t},X_{t+j_{1}},X_{t+j_{2}},...X_{t+j_{n}},\right) $ does not depend on $t$

\item Covariance stationarity: $\bar{X}_{t}$ and $C\left(
X_{t},X_{t-j}\right) $ do not depend on $t$
\end{itemize}
\end{frame}

\section{Conditional distributions}

\begin{frame}
  \frametitle{Defining a Conditional Density}
\begin{itemize}
\item Work with random vector $\underline{x}=(X,Y)\thicksim F(x,y)$.

\begin{itemize}
\item $X$ and $Y$ are random variables

\item $x$ and $y$ are realizations of the random variables

\item $F(x,y)$ is joint cumulative distribution

\item $f\left( x,y\right) $ is joint density function
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Conditional Variables and Independence}
\begin{itemize}
\item Conditional probability

\begin{itemize}
\item when $\Pr (\underline{x}\in B)>0$,
\begin{equation*}
\Pr (\left. \underline{x}\in A\right\vert \underline{x}\in B)=\Pr (A|B)=%
\frac{\Pr (A\cap B)}{\Pr (B)}.
\end{equation*}
\end{itemize}

\item Conditional distribution $F(\left. y\right\vert x)$ (handles $\Pr
(B)=0 $)

\begin{itemize}
\item Marginal distribution: $F_{X}\left( x\right) =\Pr \left( X\leq
x\right) $

\item $F\left( \left. y\right\vert x\right) $ is $\Pr \left( Y\leq y\right) $
conditional on $X\leq x$
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}\frametitle{Defining a Conditional Density}
\begin{itemize}
\item Independence: The random variables $X$ and $Y$ are independent if%
\begin{equation*}
F\left( x,y\right) =F_{X}\left( x\right) F_{Y}\left( y\right)
\end{equation*}

\begin{itemize}
\item If $X$ and $Y$ are independent, then
\begin{equation*}
F\left( \left. y\right\vert x\right) =F_{Y}\left( y\right)
\end{equation*}%
and%
\begin{equation*}
F\left( \left. x\right\vert y\right) =F_{X}\left( x\right)
\end{equation*}

\item i.i.d means independent and identically distributed
\end{itemize}

\item Conditional (mathematical, rational) expectation%
\begin{equation*}
E\left( \left. Y\right\vert x\right) =\int_{-\infty }^{\infty }ydF\left(
\left. y\right\vert x\right) =\int_{-\infty }^{\infty }yf\left( \left.
y\right\vert x\right) dy.
\end{equation*}%

\end{itemize}
\end{frame}

% ------------------------------------------------

\section{Markov Chains}

% ------------------------------------------------
\begin{frame}
  \frametitle{Markov Property}
  \begin{itemize}
  \item A particular conditional process is called a Markov chain.
  \item Markov Property: A stochastic process $\{x_{t}\}$ is said to have the Markov property if for all $k\geq 1$ and all $t$,
    \begin{align}
      Prob(x_{t + 1}|x_{t},x_{t-1},...,x_{t-k}) = Prob(x_{t + 1}|x_{t})
    \end{align}
  \item That is, the dependence between random events can be summarized exclusively with the previous event.
  \item This allows us to characterize this process with a Markov chain.
  \item Markov chains are a key way of characterizing stochastic events in our models.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Markov Chains}
  \begin{itemize}
  \item For a stochastic process with the Markov property, we can characterize the process with a Markov chain.
  \item A time-invariant Markov chain is defined by the tuple:
    \begin{enumerate}
    \item an n-dimensional state space of vectors $e_{i},i=1,....,n$,
      \begin{itemize}
      \item where $e_{i}$ is an n x 1 vector where
      \item the ith entry equals 1 and the vector contains 0s otherwise.
      \end{itemize}
    \item a transiton matrix $P$ (n x n), which records the conditional probability of transitioning between states
    \item a vector $\pi_{0}$ (n x 1), that records the unconditional probability of being in state i at time 0.
    \end{enumerate}
  \item The key object here is $P$. Elements of this matrix are given by
    \begin{align}
      P_{ij} = Prob(x_{t + 1} = e_{j}|x_{t} = e_{i})
    \end{align}
  \item In other words, if you're in state i, this is the probability you enter state j.
  \end{itemize}
\end{frame}

% ------------------------------------------------
\begin{frame}
  \frametitle{Markov Chains}
  \begin{itemize}
  \item Some assumptions on $P$ and $\pi_{0}$:
    \begin{itemize}
    \item For $i = 1,...,n$, $P$ satisfies
      \begin{align}
        \sum_{j=1}^{n}P_{ij} = 1
      \end{align}
    \item $\pi_{0}$ satisfies
      \begin{align}
        \sum_{i=1}^{n}\pi_{0i} = 1
      \end{align}
    \end{itemize}
  \item Where does this first property become useful?
  \item How would you calculate $Prob(x_{t + 2} = e_{j}|x_{t} = e_{i})$?
    \begin{align}
      &= \sum_{h=1}^{n}Prob(x_{t + 2} = e_{j}|x_{t+1} = e_{h})Prob(x_{t + 1} = e_{h}|x_{t} = e_{i})\\
                                         &= \sum_{h=1}^{n}P_{ih}P_{hj} = P_{ij}^{(2)}
    \end{align}
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Markov Chains}
  \begin{itemize}
  \item This is also true in general:
    \begin{align}
      Prob(x_{t+k} = e_{j}| x_{t} = e_{i}) = P_{ij}^{(k)}
    \end{align}
  \item Why is this useful? We can use $\pi_{0}$ with this transition matrix to characterize the probability distribution over time:
    \begin{align}
      \pi_{1}' &= \pi_{0}'P\\
      \pi_{2}' &= \pi_{0}'P^{2}\\
      &\vdots
    \end{align}
  \item Thus, by knowing the initial distribution and the transition matrix, $P$, we know the distribution at time $t$
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Stationary Distributions}
  \begin{itemize}
  \item Where does this trend to over time?
  \item We know that the transition of the distribution takes the form $\pi_{t + 1}' = \pi_{t}'P$.
  \item This distribution is stationary if
    \begin{align}
      \pi_{t + 1} = \pi_{t}
    \end{align}
  \item (we will relax this to $t$ large enough momentarily)
  \item This means that for a stationary distribution, $\pi, P$ satisfy
    \begin{align}
      \pi' &= \pi' P\;\text{or}\\
      (I - P')\pi &= 0
    \end{align}
  \item Anyone recognize this?
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Stationary Distributions}
    \begin{align}
      \pi' &= \pi' P\;\text{or}\\
      (I - P')\pi &= 0
    \end{align}
  \begin{itemize}
\only<2>{\item It is useful to note (and will be useful when we think of linearized solution techniques), that
    \begin{itemize}
    \item $\pi$ is the (normalized) eigenvector of the stochastic matrix $P$.
    \item In this case, the eigenvalue (root) is 1.
    \end{itemize}}
\only<1>{\item A lot of linearizing dynamic systems is about
    \begin{itemize}
    \item finding eigenvectors with corresponding eigenvalues of less than 1 (non-explosive).
    \item solving for initial conditions that are orthogonal to the explosive eigenvectors (i.e., the system does not explode).
    \end{itemize}
  \item Intuitive refresher:
    \begin{itemize}
    \item eigenvector: tells me the direction a system moves (i.e., distance traveled)
    \item eigenvalue: tells me how many times it traveled since I last saw it.
    \end{itemize}}
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Asymptotically Stationary Distributions}
  \begin{itemize}
  \item What about when $\pi_{0}\cancel{=}\pi_{t}$? Can it still have a notion of stationarity?
  \item Yes. Asymptotic stationarity.
  \item Asymptotic stationarity:
    \begin{align}
      \lim_{t\rightarrow\infty}\pi_{t} = \pi_{\infty}
    \end{align}
  \item where $\pi_{\infty}' = \pi_{\infty}'P$
  \item Next, is this ending point unique?
  \item Does $\pi_{\infty}$ depend on $\pi_{0}$?
  \item If not, $\pi_{\infty}$ is an invariant or stationary distribution of $P$.
  \item This will be very useful when we talk about heterogeneous agents.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Some Examples}
  \begin{itemize}
  \item Let's pick a simple initial condition: $\pi_{0}' = [1\; 0\; 0]$.
  \item And a matrix
    \begin{align}
      P = \begin{bmatrix}
        0.9 & 0.1 & 0 \\
        0.2 & 0.6 & 0.2 \\
        0.1 & 0.2 & 0.7
        \end{bmatrix}
    \end{align}
  \item Now use Matlab to iterate.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Preliminaries}
    \begin{figure}[ht]
        \begin{minipage}[b]{0.4\linewidth}
            \centering
            \includegraphics[width=0.7\textwidth]{piMat1.png}
            \caption{First iteration}
            \label{fig:a}
        \end{minipage}
        \hspace{0.5cm}
        \begin{minipage}[b]{0.5\linewidth}
            \centering
            \includegraphics[width=0.55\textwidth]{piMat2.png}
            \caption{2nd iteration}
            \label{fig:b}
        \end{minipage}
    \end{figure}
    \begin{figure}[ht]
        \begin{minipage}[b]{0.4\linewidth}
            \centering
            \includegraphics[width=0.7\textwidth]{piMat100.png}
            \caption{First iteration}
            \label{fig:c}
        \end{minipage}
        \hspace{0.5cm}
        \begin{minipage}[b]{0.5\linewidth}
            \centering
            \includegraphics[width=0.55\textwidth]{piMatN.png}
            \caption{Grid of $k$ values}
            \label{fig:d}
        \end{minipage}
    \end{figure}

  \begin{itemize}
  \item This distribution ($P$) is asymptotically stationary!
  \item Unique? Try $\pi_{0}' = [0\; 0\; 1]$
    \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Preliminaries}
    \begin{figure}[ht]
        \begin{minipage}[b]{0.4\linewidth}
            \centering
            \includegraphics[width=0.7\textwidth]{piMat1.png}
            \caption{First iteration}
            \label{fig:e}
        \end{minipage}
        \hspace{0.5cm}
        \begin{minipage}[b]{0.5\linewidth}
            \centering
            \includegraphics[width=0.55\textwidth]{piMat2.png}
            \caption{2nd iteration}
            \label{fig:f}
        \end{minipage}
    \end{figure}
    \begin{figure}[ht]
        \begin{minipage}[b]{0.4\linewidth}
            \centering
            \includegraphics[width=0.7\textwidth]{piMat100.png}
            \caption{First iteration}
            \label{fig:6}
        \end{minipage}
        \hspace{0.5cm}
        \begin{minipage}[b]{0.5\linewidth}
            \centering
            \includegraphics[width=0.55\textwidth]{piMatN.png}
            \caption{Grid of $k$ values}
            \label{fig:h}
        \end{minipage}
    \end{figure}

  \begin{itemize}
  \item This distribution ($P$) is (probably) a unique invariant distribution.
  \item How would we prove this?
    \end{itemize}
\end{frame}

% ------------------------------------------------

\section{Ergodicity}

% ------------------------------------------------

\begin{frame}
  \frametitle{Ergodicity}
  \begin{itemize}
  \item We would like to be able to replace conditional expectations with unconditional expectations.
  \item i.e., not indexed by time or initial conditions.
  \item Some preliminaries:
    \begin{itemize}
    \item Invariant function: ``a random variable $y_{t} = \bar{y}'x_{t}$ is said to be invariant if $y_{t} = y_{0},\;t\geq0$, for all realizations of $x_{t},t\geq0$ that occur with positive probability under $(P,\pi)$.''
    \end{itemize}
  \item i.e., the state $x$ can move around, but the outcome $y_{t}$ stays constant at $y_{0}$.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\begin{frame}
  \frametitle{Ergodicity}
  \begin{itemize}
  \item Ergodicity:
    \begin{itemize}
    \item ``Let $(P,\pi)$ be a stationary Markov chain. The chain is said to be ergodic if the only invariant functions $\bar{y}$ are constant with probability 1 under the stationary unconditional probability distribution $\pi$.''
    \end{itemize}
  \item In other words, for any initial distribution, the only functions that satisfy the definition of an invariant function are the same.
  \end{itemize}
\end{frame}

% ------------------------------------------------

\section{Conclusion}
% ------------------------------------------------


\begin{frame}
  \frametitle{Next Time}
  \begin{itemize}
  \item More stochastic processes.
  \item Homework due in one week.
  \end{itemize}
\end{frame}


\end{document}
