Using TikZ and PGFPlots for an Investments Class

Integrating TikZ Pictures in a LaTeX environment

I provide some examples of complete LaTeX code to produce documents that include TikZ figures.

List of LaTeX documents:

  1. Minimal Working Example
  2. Standard Article

Minimal Working Example

A simple document with the minimal class: view output from pdflatex here

  \documentclass{standalone}

% --------------------------------------------------------
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{tikz}
\usepackage{pgfplots}

% --------------------------------------------------------
\usetikzlibrary{shapes, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}



% --------------------------------------------------------
\begin{document}

% Definition of blocks:
\tikzset{%
  block/.style    = {draw, thick, rectangle, minimum height = 3em,
    minimum width = 3em},
  sum/.style      = {draw, circle, node distance = 2cm}, % Adder
  input/.style    = {coordinate}, % Input
  output/.style   = {coordinate}, % Output
  >={Latex[width=2mm,length=2mm]},
  % Specifications for style of nodes:
            base/.style = {rectangle, rounded corners, draw=black,
                           minimum width=4cm, minimum height=1cm,
                           text centered, font=\sffamily},
  activityStarts/.style = {base, fill=blue!30},
       startstop/.style = {base, fill=red!30},
    activityRuns/.style = {base, fill=green!30},
         process/.style = {base, minimum width=2.5cm, fill=orange!15,
                           font=\ttfamily}
}

\begin{tikzpicture}[
  node distance=2cm,
  every node/.style={fill=white, font=\sffamily},
  align=center
  ]
  % Specification of nodes (position, etc.)
  \node (start)             [activityStarts]                {US Investor at $t=0$};
  \node (borrowing0)        [process, above=2.5cm of start]       {US Bank};
  \node (exchange0)         [process, below=2.5cm of start]       {Exchange Counterparty};  
  \node (lending01)         [process, right=3.5cm of start]       {Japanese Investor};
  \node (end)               [activityStarts, right=3.5cm of lending01] {US Investor at $t=1$};
  \node (borrowing1)        [process, above=2.5cm of end]       {US Bank};
  \node (exchange1)         [process, below=2.5cm of end]       {Exchange Counterparty};  
  % Link the nodes
 \draw[->](borrowing0) -- node[]{Borrowing in USD} (start);
 \draw[->](start)  -- node[]{Buy Yen at rate $x_0$\\ buy for $\$1$ receive $\text{\textyen}\ 1 / x_0$}(exchange0);
 \draw[->](start)  -- node[text width = 2.4cm]{Lend $1/x_0$ Yens at $t=0$} (lending01);
  \draw[->](lending01)  -- node[text width = 2.4cm]{Receive Yens: $\frac{1}{x_0} \cdot (1+r^{\text{\textyen}})$} (end);
  \draw[->](end)  -- node[]{Repay USD loan at $t=1$ for \\$1+r$} (borrowing1);
  \draw[->](exchange1)  -- node[]{Exchange the \textyen \ investment in USD\\ $\frac{1}{x_0} \cdot (1+r^{\text{\textyen}}) \cdot F_{0,1}$} (end);
\end{tikzpicture}

\end{document}

Standard Article Class

A document with the article class: view output from pdflatex here

  \documentclass{article}

% --------------------------------------------------------
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{pdflscape}
\usepackage{tikz}
\usepackage{pgfplots}

% --------------------------------------------------------
\usetikzlibrary{shapes, arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}

% --------------------------------------------------------
\begin{document}

% Definition of blocks:
\tikzset{%
  block/.style    = {draw, thick, rectangle, minimum height = 3em,
    minimum width = 3em},
  sum/.style      = {draw, circle, node distance = 2cm}, % Adder
  input/.style    = {coordinate}, % Input
  output/.style   = {coordinate}, % Output
  >={Latex[width=2mm,length=2mm]},
  % Specifications for style of nodes:
            base/.style = {rectangle, rounded corners, draw=black,
                           minimum width=4cm, minimum height=1cm,
                           text centered, font=\sffamily},
  activityStarts/.style = {base, fill=blue!30},
       startstop/.style = {base, fill=red!30},
    activityRuns/.style = {base, fill=green!30},
         process/.style = {base, minimum width=2.5cm, fill=orange!15,
                           font=\ttfamily}
}

\begin{landscape}
\begin{figure}
\begin{tikzpicture}[
  node distance=2cm,
   every node/.style={fill=white, font=\sffamily},
   align=center
  ]
  % Specification of nodes (position, etc.)
  \node (start)             [activityStarts]                {US Investor at $t=0$};
  \node (borrowing0)        [process, above=2.5cm of start]       {US Bank};
  \node (exchange0)         [process, below=2.5cm of start]       {Exchange Counterparty};  
  \node (lending01)         [process, right=3.5cm of start]       {Japanese Investor};
  \node (end)               [activityStarts, right=3.5cm of lending01] {US Investor at $t=1$};
  \node (borrowing1)        [process, above=2.5cm of end]       {US Bank};
  \node (exchange1)         [process, below=2.5cm of end]       {Exchange Counterparty};  
  % Link the nodes
  \draw[->](borrowing0) -- node[]{Borrowing in USD} (start);
  \draw[->](start)  -- node[]{Buy Yen at rate $x_0$\\ buy for $\$1$ receive $\text{\textyen}\ 1 / x_0$}(exchange0);
  \draw[->](start)  -- node[text width = 2.4cm]{Lend $1/x_0$ Yens at $t=0$} (lending01);
  \draw[->](lending01)  -- node[text width = 2.4cm]{Receive Yens: $\frac{1}{x_0} \cdot (1+r^{\text{\textyen}})$} (end);
  \draw[->](end)  -- node[]{Repay USD loan at $t=1$ for \\$1+r$} (borrowing1);
  \draw[->](exchange1)  -- node[]{Exchange the \textyen \ investment in USD\\ $\frac{1}{x_0} \cdot (1+r^{\text{\textyen}}) \cdot F_{0,1}$} (end);
\end{tikzpicture}
\end{figure}
\end{landscape}

\end{document}

Links: