\documentclass[10pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{hyperref}
\usepackage{alltt}
\usepackage{listings}
\usepackage{array}
\usepackage{float}
\usepackage{extarrows}
\usepackage{setspace}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usepackage{hyperref}
\usepackage{graphviz}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{margin=1.5in}
\usepackage[noline, procnumbered, linesnumberedhidden, boxed]{algorithm2e}

\newcommand{\cut}[1]{}

\hypersetup{
urlcolor=blue,
colorlinks=true
}

\title{TFIDF document summarization}
\author{MSAN692\\Terence Parr}
\date{} % delete this line to display the current date

\begin{document}

\maketitle

\setlength{\algomargin}{3pt}

\section{Goal}

The goal of this lesson is to learn a core technique used in text analysis called {\em TFIDF} or {\em term frequency, inverse document frequency}. This document is background material for your TFIDF project. We will use what is called a {\em bag-of-words} representation where the order of words in a document doesn't matter---we care only about the words and how often they are present. A word's TFIDF value is often used as a feature for document clustering or classification. We will use it simply as a summarization tool for document. The more a term helps to distinguish its enclosing document from other documents, the higher its TFIDF score.

\section{Discussion}

One way to summarize a text document is to list, say, the top 25 words that seem most important. That could also be used to compare documents to see if they're talking about the same thing. For example, I had to solve a problem 15 years ago to reduce noise in the forums of a Java developer's website.  Users were posting stupid posts about movies and were also putting database questions in the forum on GUIs. The goal was to detect non-Java posts and also to detect misplaced posts. What does it mean to ``talk about Java''?  How do I know when someone is talking about databases versus GUIs? My solution was to identify the words important to Java as a whole (``Java-speak''), database, and GUI posts.  Any posts that did not have words important to Java, were tossed out as irrelevant after giving them a mild smack on the snout. Similarly, posts without words relevant to databases were compared to vocabularies associated with other topics to see if another forum would be more appropriate.

Collecting all of the words commonly used in the database forum did not work well because the model  thought that ``the'' was important to the database topic, and the GUI topic, etc... I needed to discount words used frequently in all topics.

To make this discussion simpler, let's think about individual documents versus all documents in a corpus. We boost words used frequently in a document but attenuate  that word if it is used in a lot of documents.  For more on this topic, see \href{http://nlp.stanford.edu/IR-book/html/htmledition/term-frequency-and-weighting-1.html}{Introduction to Information Retrieval}.

A word's {\em term frequency} is just the term (word) count within a document divided by the number of words in that document (some people use ``frequency'' to mean ``count'' but that is technically inaccurate):

\[\tag{Term frequency of term $t \in d$, document $d$}
tf(t,d) = \frac{count(t)}{|d|}
\]

\noindent The term frequency is higher for commonly used words within a document. So, ``the'' will be very common and thus have high term frequency in most documents.

A word's {\em document frequency} is the count of documents containing that word divided by the total number of documents:

\[\tag{Document frequency of $t$ in $N$ documents}
df(t,N) = \frac{|\{d_i : t \in d_i, \ i = 1..N\}|}{N}
\]

\noindent The document frequency is higher for words used in many documents. For example, ``the'' will have very high document frequency because it is present in just about every document. On the other hand, a word specific to a few articles such as ``simulation'' will have much lower document frequency.

The goal is to find words that helped to distinguish one document from the others. To do that we want to amplify the words used commonly in that document but attenuate that word frequency if the word is used across documents frequently.  Quantifying that information per word is called the TFIDF score. A simple division of term frequency within a document by document frequency is a simple but effective starting point:

\[\tag{First approximation to TFIDF}
\text{\em tfidf}(t,d,N) = \frac{tf(t,d)}{df(t,N)}
\]

This formula is  meaningful but gives a poor score because the document frequency tends to overwhelm the term frequency in the numerator, so we take the log of the denominator first. Here's the formula slightly rewritten as it is normally shown:

\[\tag{TFIDF with attenuated document frequency}
\text{\em tfidf}(t,d,N) = tf(t,d) \times log(\frac{1}{df(t,N)})
\]

\noindent When $t$ is in every document, $idf$ is $log(1/df(t,N)) = log(1) = 0$, which gives a TFIDF score of 0.  Such a word is a terrible word for distinguishing between documents as it exists in all of them. When $t$ is in very few documents, such as $1/10^5$, $idf$ is $log(10^5)$, which is about 11.5.

To summarize a document, we can order its terms by \text{\em tfidf} in reverse order and look at the top 20 words, for example.  (To get the lexicon of a topic like databases, we can collect a known set of database posts into a single document and compute the tfidf in association with the aggregated documents of the other topics.) For example, here is a set of terms and the associated \text{\em tfidf} computed from a sample Reuters article:

\begin{center}
\begin{tabular}{|c|c|}
\hline
Term & \text{\em tfidf}\\
\hline
    rating     & 0.123\\
    fox     & 0.119\\
    nbc     & 0.119\\
    homes     & 0.114\\
    cbs     & 0.079\\
    audiences     & 0.079\\
    neilsen     & 0.079\\
    evening     & 0.067\\
    abc     & 0.067\\
    watching     & 0.063\\
\hline
\end{tabular}
\end{center}
\label{default}

\noindent It's clear that it's talking about Nielsen ratings for news programs, without even looking at the original article.

To compute TFIDF using code, we would need an overall index that maps term $t$ to document frequency $df(t,N)$ for all $t$ in all $N$ documents and an index that maps document $d$ to another index that maps each $t \in d$ to $tf(t,d)$. From that, we could easily compute all of the TFIDF scores.

\begin{center}
\fbox{\begin{minipage}{40em}
{\bf Aside.} To prevent division by 0 errors when a term does not exist in a corpus (e.g., $df(t,N)=0$ in search applications where we pass unknown term(s) $t$), we can simply add 1 to the denominator. This is similar to {\em additive smoothing} that you will see when estimating term probabilities in document classifiers. The technique is like pretending there is an imaginary document with every unknown word (and, indeed, every possible word). To keep document frequencies in $[0..1]$, we can to bump the document count, $N$, as well.

\[\tag{$df$ with smoothing}
df(t,N) = \frac{|\{d_i : t \in d_i, \ i = 1..N\}| + 1}{N+1}
\]

For example, if we have a vector of words in a search query $[the, apple, cat, foo]$ aggregated from 100 documents, we might get a set of document frequencies like this:

\[
[\frac{100}{100}, \frac{4}{100}, \frac{9}{100}, \frac{0}{100}]
\]

\noindent With smoothing, we would get:

\[
[\frac{101}{101}, \frac{5}{101}, \frac{10}{101}, \frac{1}{101}]
\]

\noindent This is like converting zeros to some really small number (assuming $N$ is large) and adding that same small number to the other document frequencies.
\end{minipage}}
\end{center}

\section{Example}

Consider a sample set of documents:
\\

\noindent $d_1$ = ``{\bf in the new york times in}'' (repeated {\bf in})\\
$d_2$ = ``{\bf the new york post}''\\
$d_3$ = ``{\bf the los angeles times}''
\\

For these documents, we would get a combined vocabulary of [{\bf angeles, in, los, new, post, the, times, york}].   A common way to represent the documents then is as a vector from this vocabulary whose elements are the {\em term counts} (in this case, just 0, 1, and 2):

\begin{table}[H]
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c|c|c}
 & angeles & in & los & new & post & the & times & york\\
\hline
$d_1$ & 0 & 2 & 0 & 1 & 0 & 1 & 1 & 1\\
$d_2$ & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 1\\
$d_3$ & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0\\
\end{tabular}
\end{center}
\label{default}
\end{table}%

The term frequencies would be each of those numbers divided by 6 or 4 because the documents are 6 or 4 words long.

The document counts and frequencies are:

\begin{table}[H]
\begin{center}
\begin{tabular}{l|c|c|c}
$t \in d$ & {\em count(t)} & $df(t,N=3)$ & $log_{10}(\frac{1}{df(t,N=3)})$\\
\hline
angeles & 1 & 1/3 & 0.4771\\
in & 1 & 1/3 & 0.4771\\
 los & 1 & 1/3 & 0.4771\\
  new & 2& 2/3 & 0.1761\\
   post & 1& 1/3& 0.4771\\
the & 3 & 3/3 & 0.0\\
   times & 2& 2/3 & 0.1761\\
   york& 2& 2/3 & 0.1761\\
\end{tabular}
\end{center}
\label{default}
\end{table}%

The {\em tfidf} for the words in the documents are:

\begin{table}[H]
\begin{center}
\begin{footnotesize}
\begin{tabular}{c|c|c|c|c|c|c|c|c}
 & angeles & in & los & new & post & the & times & york\\
\hline
$d_1$ & 0 & 2/6*.4771 & 0 & 1/6*.1761 & 0 & 1/6*0 & 1/3*.1761 & 1/6*.1761\\
$d_2$ & 0 & 0 & 0 & 1/4*.1761 & 1/4*.4771 & 1/4*0 & 0 & 1/4*.1761\\
$d_3$ & 1/4*.4771 & 0 & 1/4*.4771 & 0 & 0 & 1/4*0 & 1/4*.1761 & 0\\
\end{tabular}
\end{footnotesize}
\end{center}
\end{table}%

\noindent Multiplied out:

 \begin{table}[H]
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c|c|c}
 & angeles & in & los & new & post & the & times & york\\
\hline
$d_1$ & 0 & {\bf 0.1590} & 0 & 0.0293 & 0 & 0 & 0.0293 & 0.0293 \\
$d_2$ & 0 & 0 & 0 & 0.0440 & {\bf 0.1193} & 0 & 0 & 0.0440\\
$d_3$ & {\bf 0.1193} & 0 & 0.1193 & 0 & 0 & 0 & 0.0440 & 0\\
\end{tabular}
\end{center}
\label{default}
\end{table}%

From this table, we can conclude that most important terms in each document are those I have bolded (the largest TFIDF scores). Notice that {\bf the} got totally wiped out because of the 0 {\em idf} score. It is useless as a distinguishing word.

\section{Exercise}

To get a feel for computing these scores, let's use Excel or some other spreadsheet to build a model we can play with. Or, for Fall 2018, I added a \href{https://github.com/parrt/msds692/blob/master/notes/tfidf.ipynb}{TFIDF example using a Pandas data frame}.

For the Excel approach, I created a number of ``tables'' as you can see from this figure:

\begin{figure}[H]
\begin{center}
\scalebox{.45}{\includegraphics{figures/tfidf-excel.png}}
\label{default}
\end{center}
\end{figure}

The count values in the document frequency (the first table) are entered manually by looking at the sample sentences. The next two columns are computed from the first column.

Then make a document-word table that represents the word vectors for each document, manually entering the word counts. Manually enter the length as well.

Create another document-word table that multiplies the term frequency by the inverse (log) document frequency from the first table. The term frequencies are the count in the word vectors divided by their length.

Once you have this in place, you can tweak the documents by changing word counts to see what happens to the various scores.

The \href{https://github.com/parrt/msds692/raw/master/notes/tfidf.xlsx}{Excel solution} is available.

\end{document}


\documentclass[12pt]{article}
\begin{document}

\section*{NYU Physics 1---In-class Exam 1}

\vfill

\paragraph{Name:} ~

\paragraph{email:} ~

\vfill

This exam consists of two problems.  Write only in this booklet.  Be
sure to show your work.

\vfill ~

\clearpage

\section*{Problem 1}

Estimate the total mass of the Silver building on Washington Square.
In case you don't remember, the building takes up one full city block,
is made of stone, and is about 10 stories tall.  Clearly state any
assumptions you make.  Do not try to get a precise answer; an order of
magnitude is sufficient.

\clearpage

\section*{Problem 2}

\textsl{(a)}~At time $t=0$, a stone is thrown vertically upward at
$5~\mathrm{m\,s^{-1}}$.  In a coordinate system with the $z$ direction
pointing vertically upward, sketch the position $z$, vertical velocity
$v_z$ and vertical acceleration $a_z$ of the stone as a function of
time, for the time interval $0<t<1~\mathrm{s}$ on three graphs below.
Assume that the stone begins at $z=0$ at $t=0$.  Be as quantitative as
you can and mark relevant times, distances, speeds, and accelerations
on your graphs where possible.  If it makes your mathematics simpler,
feel free to use $g= 10~\mathrm{m\,s^{-2}}$.  Ignore air resistance.

\clearpage

\section*{Problem 2 continued}

\textsl{(b)}~Draw a free body diagram for the stone, ie, draw all of
the forces acting on the stone, at the moment that the stone is at its
maximum $z$ position.

\end{document}


\documentclass[10pt,landscape,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[plain]{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{palatino}
\usepackage{multicol}
\usepackage{blkarray}

\usepackage{calc}
\usepackage{ifthen}
\usepackage[landscape]{geometry}
\usepackage{graphicx}
\usepackage{amsmath, amssymb, amsthm}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}

\usepackage{physics}
\usepackage{latexsym, marvosym}
\usepackage{pifont}
\usepackage{lscape}
\usepackage{dsfont}
\usepackage{graphicx}
\usepackage{array}
\usepackage{booktabs}
\usepackage[bottom]{footmisc}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{pdfpages}
\usepackage{wrapfig}
\usepackage{enumitem}
\setlist[description]{leftmargin=0pt}
\usepackage{xfrac}
\usepackage[pdftex,
            pdfauthor={Jose},
            pdftitle={Mathematical Methods for Quantitative Finance},
            pdfsubject={Cheat sheet for MITx 15.455x Mathematical Methods for Quantitative Finance},
            pdfkeywords={finance} {cheatsheet} {pdf} {cheat} {sheet} {formulas} {equations}
            ]{hyperref}
\usepackage[
            open,
            openlevel=2
            ]{bookmark}
\usepackage{relsize}
\usepackage{rotating}

% for monospace font https://tex.stackexchange.com/questions/50810/good-monospace-font-for-code-in-latex
\usepackage{inconsolata}

 \newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
    \def\independenT#1#2{\mathrel{\setbox0\hbox{$#1#2$}%
    \copy0\kern-\wd0\mkern4mu\box0}}

\newcommand{\noin}{\noindent}
\newcommand{\logit}{\textrm{logit}}
%\newcommand{\var}{\textrm{Var}}
\newcommand{\cov}{\textrm{Cov}}
\newcommand{\corr}{\textrm{Corr}}
\newcommand{\N}{\mathcal{N}}
\newcommand{\Bern}{\textrm{Bern}}
\newcommand{\Bin}{\textrm{Bin}}
\newcommand{\Beta}{\textrm{Beta}}
\newcommand{\Gam}{\textrm{Gamma}}
\newcommand{\Expo}{\textrm{Expo}}
\newcommand{\Pois}{\textrm{Pois}}
\newcommand{\Unif}{\textrm{Unif}}
\newcommand{\Geom}{\textrm{Geom}}
\newcommand{\NBin}{\textrm{NBin}}
\newcommand{\Hypergeometric}{\textrm{HGeom}}
\newcommand{\HGeom}{\textrm{HGeom}}
\newcommand{\Mult}{\textrm{Mult}}

\geometry{top=.4in,left=.2in,right=.2in,bottom=.4in}

\pagestyle{empty}
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%x
                                {\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
                                {-1explus -.5ex minus -.2ex}%
                                {0.5ex plus .2ex}%
                                {\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
                                {-1ex plus -.5ex minus -.2ex}%
                                {1ex plus .2ex}%
                                {\normalfont\small\bfseries}}
\makeatother

\setcounter{secnumdepth}{0}

\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0ex}

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

\usepackage{titlesec}

\titleformat{\section}
{\color{blue}\normalfont\normalsize\bfseries}
{\color{blue}\thesection}{0em}{}
\titleformat{\subsection}
{\color{violet}\normalfont\normalsize\bfseries}
{\color{violet}\thesection}{1em}{}
% Comment out the above 5 lines for black and white

\begin{document}

\raggedright
\footnotesize
\begin{multicols*}{3}

% multicol parameters
% These lengths are set only within the two main columns
%\setlength{\columnseprule}{0.25pt}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{1pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% TITLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{center}
    {\color{blue} \Large{\textbf{Mathematical Methods for Quantitative Finance}}}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ATTRIBUTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\scriptsize

Cheat sheet for MITx 15.455x Mathematical Methods for Quantitative Finance.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% BEGIN CHEATSHEET
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Week 1: Probability}\smallskip \hrule height 1pt \smallskip

\subsection{Random variables, distributions, and moments}

\begin{description}[topsep=0pt]
	\item[Moments of a distribution] ~
	\begin{itemize}[topsep=0pt]
		\item The \textbf{moments} of a distribution are the expectation of powers of the r.v.
		$ \mu_l = E[X^l] =  \begin{cases} \sum_k x_k^l p(x_k) \\  \int x^l p(x)dx \end{cases}$
		\item \textbf{Variance} : $\sigma^2 = \mathbb{E}[(X-\mu)^2] =\mathbb{E}[X^2]-\mathbb{E}[X]^2$
		\item \textbf{Skewness} - asymmetry parameter : $s = \frac{\mathbb{E}[(X-\mu)^3]}{\sigma^3} = \mathbb{E}\big[ \big(\frac{X-\mu}{\sigma} \big)^3\big]$
		\item \textbf{Kurtosis} - measure of tail "weights" :  $\kappa = \mathbb{E}\big[ \big(\frac{X-\mu}{\sigma} \big)^4\big] -3 $
	\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[Covariance and correlation] ~
\begin{itemize}[topsep=0pt]
	\item \textbf{covariance}: $\operatorname{Cov}(X,Y) \equiv \mathbb{E}[(X-\mu_x)(Y-mu_y)]=\mathbb{E}[XY]-\mu_x \mu_y$
	\item the \textbf{correlation} is proportional to the covariance: $\rho(X,Y) = \operatorname{Corr}(X,Y) \equiv \frac{\operatorname{Cov}(X,Y)}{\sqrt{\operatorname{Var}(X)\operatorname{Var}(Y)}} = \mathbb{E} \Big[ \Big(\frac{X-\mu_x}{\sigma_x}\Big)\Big(\frac{Y-\mu_y}{\sigma_y} \Big) \Big] $
\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[Common distributions] ~
	\begin{itemize}[topsep=0pt]
		\item \textbf{Uniform distribution}:
			$
			p(x) = \begin{cases}
				1, x \in [0,1] \\
				0, \text{otherwise}
			\end{cases}$
			, $\operatorname{Prob}(a<X<b)=b-a$
			$\mu = \int_{\infty}^{\infty}x p(x) \text{d}x= \int_{0}^{1} x \text{d}x = \frac{1}{2}$,
			$\sigma^2 = \int_{\infty}^{\infty}(x-\frac{1}{2})^2 \text{d}x= \frac{1}{12} $
			$u_l= \int_{0}^{1}x_l dx= \frac{1}{l}$
		\item \textbf{Binomial distribution}:
			$f(x;n,p) = {n \choose k} p^k q^{n-k} = \frac{n!}{k!(n-k)!} p^k q^{n-k} $,
			$\mu = np$, $\sigma^2 = npq$
		\item \textbf{Gaussian distribution}:
			$p(x) - \frac{1}{\sqrt{2 \pi \sigma ^2}} e^{- \frac{1}{2} \big(\frac{x-\mu}{\sigma} \big)^2}$ ,
			$ \Phi(x) = Prob(Z<x) = \frac{1}{\sqrt{2 \pi}}\int_{-\infty}^{x} e^{-z^2/2} dz   $ \\
			Moments: $\begin{tabular}{ |c|l|c| }
				\hline
				Order & Non-central moment & Central moment \\
				\hline
				1 & $\mu$ & 0 \\
			    2 & $\mu^2+\sigma^2$ & $\sigma^2$ \\
				3 & $\mu^3+3\mu \sigma^2$ & 0 \\
				4 & $\mu^4+6\mu^2 \sigma^2 + 3\sigma^4$ & $3 \sigma^4$ \\

				\hline
			\end{tabular}$
		\item \textbf{Lognormal distribution}: $X=\operatorname{log}Y$ , $x=\operatorname{log}y$, then $g(y)=\frac{p(x)}{|\text{d}y/\text{d}x|} = \frac{1}{y \sqrt{2 \pi \sigma^2}} e^{- (\operatorname{log}y -\mu)^2/(2 \sigma^2) }$
		\item \textbf{Poisson distribution}: $p(k;\lambda) = \frac{e^{-\lambda} \lambda^k}{k!}$. $\mu = \sigma^2 = \lambda$ . \\
		   Probability of $k$ "arrivals" during interval $t$: $p(k;\lambda) = \frac{e^{-\lambda t} (\lambda t)^k}{k!}$ \\

	\end{itemize}
\end{description}

\section{Week 2: Stochastic Processes}\smallskip \hrule height 1pt \smallskip

\subsection{The Random Walk}

\begin{description}[topsep=0pt]
	\item[Random walk model] ~
	\begin{itemize}[topsep=0pt]
		\item $S_T = z_1 + z_2 + \cdots + z_T $ . Each increment is a random IID variable. $\mathbb{E}[z_t]=0$, $\mathbb{E}[z_t^2]=1$, $\mathbb{E}[z_t z_{t'}]=0$ if $t\neq t'$. $\operatorname{Var}(S_T)=T$
		\item \textbf{Generalized random walk model}: $r_t = \sigma z_t + \mu$. $\mathbb{E}[r_t] = \mu$, $\mathbb{E}[(r_t-\mu)^2]=\sigma^2$.  $X_T \equiv \sum_{t=1}^{T}r_t$, $\mathbb{E}[X_T] = T\mu$, $\operatorname{VaR}(X_T) = T \sigma^2$.
	\end{itemize}
\end{description}

\subsection{Time series models}

\begin{description}[topsep=0pt]
	\item[Time series models] ~
	\begin{itemize}[topsep=0pt]
		\item a ts process is \textbf{stationary} if the join distribution of all of its values is invariant under time translation.
		\item a ts is \textbf{weakly stationary} if the first and second moments are invariant.
		\item MA(1): $r_t = \mu + \sigma z_t + \phi z_{t-1}$
		\item AR(p): $R_t = c_0+c_1 R_{t-1} + \dots + c_p R_{t-p} + \sigma z_t, z_t \sim IID(0,1) $
		\item ARMA(p,q):
		$R_t = c_0 + c_1 R_{t-1} + \dots + c_p R_{t-p} + \sigma z_t + \phi_1 z_{t-1} + \dots + \phi_q z_{t-q}$
		\item AR(1) used for \textbf{mean reversion}:  $R_t = c_0 + c_1 R_{t-1} + \sigma z_t$ , $E[R_t]=\frac{c_0}{1-c_1}$, for convenience: $\mu = \frac{c_0}{1-c_1}$, $\lambda = -c_1$. Then: $R_t-\mu = -\lambda (R_t-\mu) + \sigma z_t $, $|\lambda | <1$.
		$Var[R_t] = \gamma_0 = \frac{\sigma^2}{1-\lambda^2}$ . \\
		Lag-$k$ autocovariance coefficient: $\gamma_k=(-\lambda)^k \gamma_0 = \frac{(-\lambda)^k}{1-\lambda^2} \sigma^2$
	\end{itemize}
\end{description}

\section{Week 3: Time Series Models}\smallskip \hrule height 1pt \smallskip

\begin{description}[topsep=0pt]
	\item[Gambler's Ruin] ~
	\begin{itemize}[topsep=0pt]
		\item Repeated set of gambles with probability of success $p$ and of failure $q=1-p$
		\item initial capital is $x>0$, total capital $a$. Stop when winning $a$ or \textbf{ruin} as $x=0$.
		\item $Q_x$ is \textbf{probability of ruin} starting from capital $x$: $Q_x=pQ_{x+1} + p Q_{x-1}$.
		\item $Q_x = \frac{(q/p)^a-(q/p)^x}{(q/p)^a-1}$, if $p=q=1/2$, then:  $Q_x=1-\frac{x}{a}$

	\end{itemize}
\end{description}

\section{Week 4: Continuous-Time Finance}\smallskip \hrule height 1pt \smallskip

\subsection{It\^{o} processes and It\^{o}'s lemma }

\begin{description}[topsep=0pt]
	\item[It\^{o}'s lemma] ~
	\begin{itemize}[topsep=0pt]
		\item It\^{o} process: $\text{d}X = a \text{d}t+b \text{d}B$\
		\item $\text{d}F=\Big( \frac{\partial F}{\partial t}\text{d}t + \frac{\partial F}{\partial X} \text{d}X + \frac{1}{2} \frac{\partial^2 F}{\partial X^2} (\text{d}X)^2 + \cdots \Big) = \Big( \frac{\partial F}{\partial t}\text{d}t + \frac{\partial F}{\partial X} \text{d}X + \frac{1}{2} \frac{\partial^2 F}{\partial X^2} [b^2 \text{d}t] \Big) = \Big[ \frac{\partial F}{\partial t}\text{d}t + \frac{b^2}{2} \frac{\partial^2 F}{\partial X^2} \Big] \text{d}t + \Big[\frac{\partial F}{\partial X}\Big]  [ a \text{d}t+b \text{d}B]$ \\
		$\text{d}F = \Big[ \frac{\partial F}{\partial t} +a \frac{\partial F}{\partial X} + \frac{b^2}{2} \frac{\partial^2 F}{\partial X^2} \Big] \text{d}t + b \frac{\partial F}{\partial X} \text{d}B  $

		\item Heuristics: expand and replace $(\text{d}B_t)^2 \rightarrow \text{d} t $,  $(\text{d}X_t)^2 \rightarrow b^2 \text{d}t$
	\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[It\^{o} processes] ~
	\begin{itemize}[topsep=0pt]
		\item \textbf{Brownian motion with drift}: $\text{d}S_t = \mu \text{d}t+b \text{d}B_t$ \\
		   $S_T = S_0 + \mu T + \sigma (B_T-B_0)$
		\item \textbf{GBM with drift}:  $\text{d}S_t = \mu S_t \text{d}t+b S_t \text{d}B_t$ \\
		   $\text{d}(log S_t)=(\mu-\frac{\sigma^2}{2}) \text{d}t + \sigma \text{d}B_t$ ,  $S_T = S_0 e^{(\mu -\frac{\sigma^2}{2})T + \sigma (B_T-B_0)}  $
		\item \textbf{Ornstein–Uhlenbeck process}:  $\text{d}S_t = \lambda (\bar{S} -S_t) \text{d}t + \sigma \text{d}B_t$
		\item \textbf{Cox–Ingersoll–Ross process}:  $ \text{d} \rho_t = \lambda ( \bar{\rho} - \rho_t) \text{d}t + \sigma \sqrt{\rho_t} \text{d} B_t$ \\
		   Let $F=\sqrt{\rho}$ , $\frac{\partial F}{\partial \rho} = \frac{1}{2\sqrt{\rho}}$, $\frac{\partial^2F}{\partial \rho^2} = - \frac{1}{4} \rho ^{-\frac{3}{2}}$ \\
		   $ \text{d}F = \Big( \frac{4 \lambda \bar{\rho} - \sigma^2}{8F} - \frac{1}{2} \lambda F \Big) \text{d}t + \frac{1}{2} \sigma \text{d}B_t$

	\end{itemize}
\end{description}

\subsection{From SDE to PDE: The Black-Scholes equation}

\begin{description}[topsep=0pt]
	\item[Black-Scholes equation] ~
	\begin{itemize}[topsep=0pt]
		\item It\^{o} process: $\text{d}X = a \text{d}t+b \text{d}B$\
		\item $\text{d}F=\Big( \frac{\partial F}{\partial t}\text{d}t + \frac{\partial F}{\partial X} \text{d}X + \frac{1}{2} \frac{\partial^2 F}{\partial X^2} (\text{d}X)^2 + \cdots \Big) = \Big( \frac{\partial F}{\partial t}\text{d}t + \frac{\partial F}{\partial X} \text{d}X + \frac{1}{2} \frac{\partial^2 F}{\partial X^2} [b^2 \text{d}t] \Big) = \Big[ \frac{\partial F}{\partial t}\text{d}t + \frac{b^2}{2} \frac{\partial^2 F}{\partial X^2} \Big] \text{d}t + \Big[\frac{\partial F}{\partial X}\Big]  [ a \text{d}t+b \text{d}B]$ \\
		$\text{d}F = \Big[ \frac{\partial F}{\partial t} +a \frac{\partial F}{\partial X} + \frac{b^2}{2} \frac{\partial^2 F}{\partial X^2} \Big] \text{d}t + b \frac{\partial F}{\partial X} \text{d}B  $

		\item Heuristics: expand and replace $(\text{d}B_t)^2 \rightarrow \text{d} t $,  $(\text{d}X_t)^2 \rightarrow b^2 \text{d}t$
	\end{itemize}
\end{description}

\section{Week 5: It\^{o} Calculus}\smallskip \hrule height 1pt \smallskip

\subsection{Black-Scholes equation}

\begin{description}[topsep=0pt]
	\item[Summary of some key formulas] ~
	\begin{itemize}[topsep=0pt]
	 \item It\^{o} process: $\text{d}X = a \text{d}t+b \text{d}B$\
     \item It\^{o} formula: \begin{align*}
     	\text{d}F &= \frac{\partial F}{\partial t} \text{d}t + \frac{\partial^2 F}{\partial X^2} \text{d}X + \frac{b^2}{2} \frac{\partial F}{\partial X} \text{d}t \\
 	         	&=   \Bigg( \frac{\partial F}{\partial t} +a \frac{\partial F}{\partial X} + \frac{b^2}{2} \frac{\partial^2 F}{\partial X^2} \Bigg) \text{d}t + b \frac{\partial F}{\partial X} \text{d}B
 \end{align*}

      \item Stock price: $\text{d}S = \mu S \text{d}t + \sigma \text{d}B \implies \text{d}(\text{log } S) = \Big(\mu - \frac{\sigma^2}{2} \Big) \text{d}t + \sigma \text{d}B$
      \item Black-Scholes:  $\Delta = \partial V / \partial S$ , $\text{d}\pi=r \pi \text{d}t$  ,

      $$ \frac{\partial V}{\partial t} + \frac{\sigma^2 S^2}{2} \frac{\partial ^2 V}{\partial S^2} + r S \frac{\partial V}{\partial S} -rV =0 $$
	\end{itemize}
\end{description}

\subsection{Recitation 5}

\begin{description}[topsep=0pt]
	\item[Expectations from Brownian integrals] ~
	\begin{itemize}[topsep=0pt]
		\item $ dB \sim N(0,dt) $
		\item $  \int_{0}^{t} dB = B_t - B_0 \sim N(0,t ) $
		\item $E[f(B_t-B_0)] = E[f(\sqrt{t} z)] = \frac{1}{\sqrt{2\pi}} \int e^{-z^2/2}f(\sqrt{t}z) dz$
		\item Example  $E[f(B_t-B_0)] = E[(B_t-B_0)^4] = E[(\sqrt{t} z)^4] = t^2 E[z^4] = 3t^2 $ \\

		We can pull out $\sqrt{t}$,which is nonstochastic to get $t^2 E[z^4]$
		, $E[z^4]$ is a well-known Gaussian integal that we use in the kurtosis=3.
		\item Useful formula:  $E[e^{\alpha z + \beta}]  = e^{\alpha^2/2 + \beta}$
	\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[Solutions to the diffusion equation] ~
	\begin{itemize}[topsep=0pt]
		\item \textbf{diffusion equation}: $ \frac{\partial p}{\partial t} - \frac{1}{2} \frac{\partial ^2 p}{\partial z^2} = 0 $
		\item special solution $p(z,0)=f(z)$ then the general solution is: $ p(z,t) = \int p_0(z-w,t)f(w)dw $ , where
		$ p_0 = \frac{1}{\sqrt{2 \pi t}} e^{-\frac{z^2}{2t}} $
		\item  $ \text{let } u=\frac{w-z}{\sqrt{t}}  \implies  du=\frac{dw}{\sqrt{t}} $
		$ \implies  w=u \sqrt{t} + z $.  Now general solution can be computed as expectation of standard Gaussian: $p(z,t) = \mathbb{E}[f(\sqrt{t}u+z)]$ , where $u \sim N(0,1) $
		\item \textbf{example}: $p(z,0) = z^2 $, $ f(z) = z^2 $, find $ p(z,t) $ \\
		$p(z,t) = \int p_0(z-w,t)f(w)dw = \int  \frac{1}{\sqrt{2 \pi t}} e^{-\frac{(z-w)^2}{2t}} w^2 dw =  \frac{1}{\sqrt{2 \pi}} \int_{-\infty}^{\infty}  e^{-\frac{u^2}{2}} (u \sqrt{t} + z)^2 du =  \mathbb{E} [f(u \sqrt{t} + z)] =  \mathbb{E}[u^2t + 2u \sqrt{t}z + z^2] =  z^2+t $

	\end{itemize}
\end{description}

\section{Week 6: Continuous-Time Finance}\smallskip \hrule height 1pt \smallskip

\subsection{It\^{o} processes in higher dimensions}

\begin{description}[topsep=0pt]
	\item[It\^{o}'s lemma: multiple stochastic variables] ~
	\begin{itemize}[topsep=0pt]
		\item  $ \text{d}X_i = a_i(t,X_1,X_2,...) \text{d}t+  b_i(t,X_1,X_2,...)\text{d} B_i $ \\
		 $\text{d} F = \frac{\partial F}{\partial t} \text{d}t + \sum \frac{\partial F}{\partial X_i} \text{d}X_i + \frac{1}{2} \sum \rho_{ij} b_i b_j \frac{\partial ^2 F}{\partial X_i X_j} \text{d}t$
		 \item Heuristics "rule of thum" for correlated Brownian motions : \\
		    $ (\text{d}B_i)^2 \rightarrow \text{d}t $ ,
		    $ (\text{d}B_i)(\text{d}B_j) \rightarrow \rho_{ij} \text{d}t$ ,\\
		    $ (\text{d}X_i )^2 \rightarrow b^2_i \text{d}t $ ,
		    $ (\text{d}X_i)(\text{d}X_j) \rightarrow \rho_{ij} b_i b_j \text{d} t $
		\item two stochastic variables case:  $\text{d}X_1 = a_1 \text{d}t + b_1 \text{d}B_1 $, $\text{d}X_2   = a_2 \text{d}t + b_2 \text{d}B_2 $ \\
			 $\text{d}F =  \frac{\partial F}{\partial t} \text{d}t + \frac{\partial F}{\partial X_1} \text{d}X_1+  \frac{\partial F}{\partial X_2} \text{d}X_2 + \Big( \frac{b_1^2}{2}  \frac{\partial^2 F}{\partial X_1^2} + \frac{b_2^2}{2}  \frac{\partial^2 F}{\partial X_2^2} + b_1 b_2 \rho \frac{\partial^2 F}{\partial X_1 \partial X_2} \Big) \text{d}t $
		 \item With two random variables, Ito's formula for $F(t, X, Y)$ is:
			$dF = \frac{\partial F}{\partial t} dt + \frac{\partial F}{\partial X} dX + \frac{\partial F}{\partial Y} dY + \frac{1}{2} \frac{\partial^2 F}{\partial X^2} (dX)^2  +  \frac{1}{2} \frac{\partial^2 F}{\partial Y^2} (dY)^2 + \frac{\partial^2 F}{\partial X \partial Y} (dX)(dY)
			$
		 \item example: $F=X1X2 \implies \text{d}F = X1 \text{d} X_2 + X_2 \text{d} X_1 + \rho b_1 b_2 \text{d} t $ \\
		 since $(\text{d}X_i)(\text{d}X_j) \rightarrow \rho_{ij} b_i b_j \text{d} t \implies \text{d}F = X1 \text{d} X_2 + X_2 \text{d} X_1 + \text{d}X_1 \text{d}X_2 $

	\end{itemize}
\end{description}

\subsection{Measures, martingales, and Monte Carlo}

\begin{description}[topsep=0pt]
	\item[Risk-neutral pricing] ~
	\begin{itemize}[topsep=0pt]
		\item  Under measure $Q$, expected return on risky assets equals risk-free rate: $\mathbb{E}_t^Q=\big[ \frac{\text{d}S_t}{S_t}\big] = r \text{d}t$
		\item Heuristic: replace drift with risk-free rate to get risk-neutral process: $\mu \rightarrow r$
		\item All (no-arbitrage) traded assets have discounted price process that are
		martingales:  $e^{-rt}X_t = \mathbb{E}_t^Q[e^{-rT X_T}]$.  Example, call option: $C_t = e^{r(T-t)} \mathbb{E}_t^Q[\operatorname{max}(S_T-K,0)]$
		\item Monte Carlo implementation: generate ensemble of equiprobable price
		paths using \textbf{risk-neutral} drift and volatility parameters, compute terminal
		payoffs, and take average of their discounted present value.
		\item \textbf{example}: Let $S$  be the value of a stock that evolves according to GBM. A "cubic contract" has a payoff at expiration of $V_T=(S_T)^3$ . What is the value  of the contract at $V_0$ at $t=0$ :  $V_t = e^{-r(T-t)}\mathbb{E}^Q[V_T]$ setting $t=0$. Then:

			$V_T = S_T^3 = \left[S_0 e^{(r-\sigma^2/2)T + \sigma{\sqrt T}Z}\right]^3$
			$V_T= \left[ S_0^3 e^{3(r-\sigma^2/2)T} \right] e^{3\sigma{\sqrt T}Z}, \quad Z \sim{\cal N}(0,1)$ \\
			$V_t = e^{-r(T-t)}\mathbb{E}^Q[V_T]$
			$= \left[ S_0^3 e^{-rT}e^{3(r-\sigma^2/2)T} \right] \mathbb{E}^Q\left[e^{ 3\sigma{\sqrt T}Z}\right]$ \\
			$V_t= \left[S_0^3 e^{2rT} e^{-3\sigma^2T/2} \right] e^{9\sigma^2 T/2}$
			$ S_0^3 e^{2rT+3\sigma^2T}$ .

	\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[Bond pricing] ~
	\begin{itemize}[topsep=0pt]
		\item  \textbf{one-factor Vasicek model}:  The short rate  evolves according to the Ornstein-Uhlenbeck process $\text{d} y_t = \alpha(\bar{y} - y_t) \text{d}t + \sigma \text{d}B,
		$. The bond-pricing equation takes the form $\frac{\partial{V}}{\partial{t}}+\frac{\sigma^2}{2}\frac{\partial^2V}{\partial{y^2}}-yV+\alpha(\bar{y}-y)\frac{\partial{V}}{\partial{y}} = 0.
		$.  At the boundary condition $V=1$ and $t=T$ since the zero-coupon bonds returns $\$1$ at maturity.
		Find $V(t,y)$ as a funciton of $t$, $y$, and the maturity date $T$, and the constant parameters $\alpha$, $\sigma$ and $\bar{y}$. Ansatz $V=e^{f(t) - y g(t)}$

		\item Then rearranging : $\left(\alpha g -1-\frac{\text{d}g}{\text{d}t}\right) \cdot y + \left(\frac{\text{d}f}{\text{d}t}+\frac{1}{2}\cdot \sigma^2g^2-\alpha\bar{y}g\right).
		$
		\item $0= \alpha g -1-\frac{\text{d}g}{\text{d}t} \hspace{5mm} \text{and} \hspace{5mm} 0 = \frac{\text{d}f}{\text{d}t}+\frac{1}{2}\cdot \sigma^2g^2-\alpha\bar{y}g
		$  which is equivalent to: $\frac{\text{d}g}{\text{d}t}= \alpha g -1 \hspace{5mm} \text{and} \hspace{5mm} \frac{\text{d}f}{\text{d}t} = \alpha\bar{y}g - \frac{1}{2}\cdot \sigma^2g^2.
		$
		\item We impose the boundary conditions $f(T)=g(T)=0$:

			$f(t) =  \bar{y} \left[-(T-t) + \frac{1}{\alpha}\left(1-e^{-\alpha(T-t)}\right) \right]
			+ \frac{\sigma^2}{4\alpha^3}\left[ 2\alpha(T-t) - 4\left(1- e^{-\alpha(T-t)}\right) +\left(1 - e^{-2\alpha(T-t)}\right)\right]$

	\end{itemize}
\end{description}

\section{Week 7: Linear algebra of asset pricing}\smallskip \hrule height 1pt \smallskip

\begin{description}[topsep=0pt]
	\item[Linear algebra of asset pricing] ~
	\begin{itemize}[topsep=0pt]
		\item  \textbf{The payoff matrix} $A$ is a matrix $s \cross n$ with $s$ states of the world and $n$ different securities.
		\item A \textbf{portfolio} $\vec{\mathbf{x}}$ is represented as a vector of quantities held for each security.
		\item The \textbf{portfolio payoff} is determined by action on the portfolio vector with the payoff matrix: $A\vec{\mathbf{x}}$
		\item A \textbf{complete market}  is one in which every payoff can be generated by some portfolio, $\operatorname{rank}(A) = s$. If $n > s$, select a complete basis and drop $n-s$ redundant securities
		\item An \textbf{incomplete market} s one in which some payoffs cannot be generated
		by any portfolio. $\operatorname{rank}()A) < s$.
		\item Present \textbf{prices} can be represented by a vector $\vec{\mathbf{S}}$ dimension $n$.
		\item Market value of a portfolio is sum of (price) x (quantity): $MV = \sum_{i=1}^{n}S_i x_i = (S_1 \space S_2 \space \cdots) \begin{pmatrix} x_1 \\ x_2 \\ \vdots \end{pmatrix} = \vec{\mathbf{S}}^\top \vec{\mathbf{x}}$
		\item \textbf{Type I arbitrage}: Pay nothing now (i.e., negative or zero cost), $\vec{\mathbf{S}}^\top \vec{\mathbf{x}} \leq 0$. Receive only non-negative payoffs later: $A \vec{\bf x } \geq =0$ and at least one payoff $>0$.
		\item \textbf{Type II arbitrage} : There are redundant assets and non-trivial solutions to $A \vec{\bf x } =0$. There is arbitrage if the portfolio has a non-zero price, $\vec{\mathbf{S}}^\top \vec{\mathbf{x}} \neq 0$
		\item Portfolios with the special property that they have \textbf{unit} payoff in a single
		state are called Arrow-Debreu (AD) securities.
		\item In terms of a general payoff matrix, an elementary AD security can be
		replicated if there is a portfolio satisfying $A \vec{\bf x } = \vec{\bf{e}_j} = \begin{pmatrix}
			0 & 0 & \cdots &1 &  \cdots & 0
		\end{pmatrix} ^\top$.  $\vec{\bf x } = A^{-1} \vec{\bf{e}_j}$ is a portfolio with unit payoff. The payoff matrix of a set of AD securities in the complete market is the identity matrix $I$.
		\item The prices of AD securities are called \textbf{state prices}: $\psi = (\psi_1 \space \cdots \space \psi_s )$
		\item The price of any security with payoff $\vec{\bf{b}}$ is $\vec{\bf{\psi}}^\top \vec{\bf{b}}$.  Intuition: we can think of  $\vec{\bf{b}}$ as a portfolio of AD securities.

		\item \textbf{Arbitrage theorem} Consider a market with $n$ securities, $s$ states of the world, payoff matrix $A \in \mathbb{R}^{s \cross n} \text{, } A: \mathbb{R}^n \rightarrow \mathbb{R}^s$.  There is no arbitrage if and only if there exists a \textbf{strictly positive} state-price
		vector $\vec{\bf{\psi}}$ \textbf{consistent with} the security-price vector, $\vec{\bf{\psi}} \in \mathbb{R}^s \text{, } \vec{\mathbf{S}} \in \mathbb{R}^n \text{, } \vec{\mathbf{S}}=A^\top \vec{\bf{\psi}}$ . 	 For \textbf{incomplete markets}, there
		can be (infinitely) multiple solutions $\vec{\bf{\psi}}$.  If there is \textbf{at least one solution} where $\vec{\bf{\psi}} > 0$, then no arbitrage. If \textbf{every solution} has $\vec{\bf{\psi}} \leq 0$, then there is arbitrage.
		\item If $A$ is not invertible ($s<n$), $A^\top$ has \textbf{pseudo-inverse} $M$: $M \equiv (A A^\top) ^{-1}\ A$, check that $M A ^\top=I$, $ I \in \mathbb{R}^s $
		\item \textbf{Arbitrage pricing theorem} Given payoffs $A$, prices $\vec{\mathbf{S}}$, target asset with payoff $\vec{\bf{b}}$:  Find all $\vec{\bf{\psi}}>0$ such that $A^\top \vec{\bf{\psi}}=\vec{\mathbf{S}}$.  No solution $\implies$ arbitrage. 1 solution $\implies$ complete market. Multiple solution $\implies$ incomplete market.

	\end{itemize}
\end{description}

\section{Week 8: Optimization}\smallskip \hrule height 1pt \smallskip

\subsection{Portfolio Optimization}

\textbf{Portfolio risk} :  $\sigma_p^2 = \vec{\mathbf{w}}^{\top} C \vec{\mathbf{w}} = \sum w_i^2 \sigma_i^2 + 2 \sum_{i<j}w_i w_j \sigma_i \sigma_j \rho_{ij}$ \\ $\vec{\bf{w}} = \left(w_1 \hspace{2mm} w_2 \hspace{2mm} ... \hspace{2mm} w_n\right)^\top$

\begin{description}[topsep=0pt]
	\item[Portfolio optimization with budget] ~
	\begin{itemize}[topsep=0pt]
		\item
		$\mathcal{L}(\vec{\mathbf{w}}, \ell) = \frac{1}{2} \vec{\mathbf{w}}^{\top} C \vec{\mathbf{w}} + \ell (1 - \vec{\iota}^\top \vec{\mathbf{w}}^\top ) $
		\item Vary the weights: $\frac{\partial{\mathcal{L}}}{\partial{w_i}} = \left(\sum_{j \in [n]}{C_{ij}w_j}\right) - \ell\iota_i = 0$
		\item Solve for the weights by inverting matrix:
		 $C\vec{\bf{w}} - \ell \vec{\iota} =0 \implies \vec{\bf{w}} = \ell  C^{-1} \vec{\iota} $
		\item Solve Lagrande multiplier : $ \vec{\iota}^\top \vec{\bf{w}} = 1 =\ell ( \vec{\iota}^\top C^{-1} \vec{\iota} ) \implies \ell = \frac{1}{ \vec{\iota}^\top C^{-1} \vec{\iota}} $
		\item Solution: $\vec{\bf{w}}_{min} = \ell  C^{-1} \vec{\iota} = \frac{C^{-1} \vec{\iota}}{\vec{\iota}^\top C^{-1} \vec{\iota}}$ , $\hspace{2mm}$
		   $\sigma^2_{min} = \ell = \frac{1}{ \vec{\iota}^\top C^{-1} \vec{\iota}} $

	\end{itemize}
\end{description}

\begin{description}[topsep=0pt]
	\item[Portfolio optimization with budget and return constraint] ~
	 generalized to $\sum_i {w_i} = w_p$
	\begin{itemize}[topsep=0pt]
		\item
		 $\mathcal{L}(\vec{\mathbf{w}}, \ell, m) = \frac{1}{2} \vec{\mathbf{w}}^{\top} C \vec{\mathbf{w}} + \ell (w_p - \vec{\iota}^\top\vec{\mathbf{w}} ) + m(\mu_p - \vec{\mu}^\top \vec{\mathbf{w}} )$
		 \item Vary the weights:
		 $\frac{\partial{\mathcal{L}}}{\partial{w_i}} = \left(\sum_{j \in [n]}{C_{ij}w_j}\right) - \ell\iota_i-m\mu_i $
		 \item Solve for the weights:   $C\vec{\bf{w}} - \ell \vec{\iota} - m \vec{\mu} = {\bf{0}}  \implies $
		 $\vec{\bf w}=C^{-1}(l\vec{\iota}+m \vec{\mu})$
		 \item Solve for Langrange multipliers with constraints:  $ \vec{\iota}^\top\vec{\mathbf{w}} =w_p$ and  $\vec{\mu}^\top \vec{\mathbf{w}}=\mu_p$
		 $ 	w_p = \vec{\iota}^\top \vec{\mathbf{w}} = \ell(\vec{\iota}^{\top} C^{-1} \vec{\iota}) + m (\vec{\mu}^{\top} C^{-1} \vec{\iota}) $ \\
		 $ \mu_p = \vec{\vec{\mu}}^\top \vec{\mathbf{w}} = \ell (\vec{\mu}^{\top} C^{-1} \vec{\iota}) + m (\vec{\mu}^{\top} C^{-1} \vec{\mu})$ \\as
		 as matrix equation: $\begin{pmatrix} w_p \\ \mu_p \end{pmatrix} = M\begin{pmatrix} \ell \\ m \end{pmatrix}$
		 , where : $  M = \begin{pmatrix} a & b \\ b & c \end{pmatrix} $ \\
		 $a \equiv \vec{\iota}^{\top} C^{-1} \vec{\iota} $,  $b \equiv \vec{\mu}^{\top} C^{-1} \vec{\iota}$,  $c \equiv \vec{\mu}^{\top} C^{-1} \vec{\mu}$.
		 \item Solve for Langrange multiplier by inverting $M$: $\begin{pmatrix} \ell \\ m  \end{pmatrix} = M^{-1}\begin{pmatrix} w_p \\ \mu_p\end{pmatrix}$ \\
		 $M^{-1} = \frac{1}{ac-b^2}\begin{pmatrix} c & -b \\ -b & a \end{pmatrix}$, $\ell = \frac{cw_p-b\mu_p}{ac-b^2} \hspace{2mm} \text{and} \hspace{2mm} m = \frac{-bw_p+a\mu_p}{ac-b^2} .$

		 \item Solution :
		 	$\sigma^2_p  = \begin{pmatrix} \ell & m \end{pmatrix} M \begin{pmatrix} \ell \\ m \end{pmatrix} $
		 	$ = \left(\frac{cw_p-b\mu_p}{ac-b^2} \hspace{5mm} \frac{-bw_p+a\mu_p}{ac-b^2}\right) \begin{pmatrix} w_p \\ \mu_p \end{pmatrix}$ \\
		 	$ = \frac{1}{ac - b^2} \cdot (a \mu_p^2 - 2b w_p \mu_p + c w_p^2)$.

	\end{itemize}
\end{description}

\section{Useful formulas}\smallskip \hrule height 1pt \smallskip

$\operatorname{Cov}(aX+bY,Z) = a \operatorname{Cov}(X,Z)+b \operatorname{Cov}(Y,Z) $ \\
$\operatorname{Var}(aX+bY)=a^2\operatorname{Var}(X)+b^2\operatorname{Var}(Y)+2ab\, \operatorname{Cov}(X,Y)$
$\operatorname{Var}(aX-bY)=a^2\operatorname{Var}(X)+b^2\operatorname{Var}(Y)-2ab\, \operatorname{Cov}(X,Y)$
$\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}$

\newpage

\section{Recommended Resources} \smallskip \hrule height 1pt \smallskip

\bigskip

\begin{itemize}
\item MITx 15.455x
MITx 15.455x
Mathematical Methods for Quantitative Finance [Lecture Slides] (\url{https://learning.edx.org/course/course-v1:MITx+15.455x+3T2020/home})

\item Tsay, Analysis of Financial Time Series (3e), Wiley. (Tsay)
\item Capinski and Zastawniak, Mathematics for Finance, Springer. (CZ)
\item Olver, Introduction to Partial Differential Equations (2016), Springer. (Olver)
\item Campbell, Lo, and MacKinlay, Econometrics of Financial Markets (1997), Princeton. (CLM)
\item Lang, Introduction to Linear Algebra (2e), Springer (Lang)
\item Axler, Linear Algebra Done Right (3e), Springer (Axler)
\item LaTeX File (\texttt{\href{https://github.com/j053g/cheatsheets/blob/main/15.455x/15.455x_math_methods_for_quant_finance.tex}{github.com/j053g/cheatsheets/15.455x}})
\end{itemize}

\begin{center}
	\emph{Last Updated \today}
\end{center}

\end{multicols*}

\end{document}


% ====================== Packages =============================
\documentclass[a4paper,12pt]{article}
\usepackage[left=2cm, right=2cm, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{fancyhdr , lipsum}
\usepackage{mathptmx}
\usepackage{anyfontsize}
\usepackage{t1enc}
\usepackage{csquotes}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage[linktocpage]{hyperref}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subcaption}
\usepackage[section]{placeins}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage{tcolorbox}
\usepackage[english]{babel}
\usepackage[export]{adjustbox}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{setspace}
% Header and Footer
\usepackage{lipsum}%% a garbage package you don't need except to create examples.
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Data Transfer HW 1}
\rhead{ Page :  \thepage}
\cfoot{Hossein Dehghanipour - 9532250}
% End ofHeader and Footer
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\newcommand{\thedate}{\today}
\usepackage{atbegshi}% http://ctan.org/pkg/atbegshi
\AtBeginDocument{\AtBeginShipoutNext{\AtBeginShipoutDiscard}}
% ====================== Begin Doc =============================
\begin{document}
    \begin{titlepage}
        \begin{center}
            \title{\Large{\textbf{Data Transfer HW 1}}}
            \author{Hossein Dehghanipour - 9532250}
            \date{\today}
        \end{center}
    \end{titlepage}

    \maketitle

\newpage
\setmainfont{Times New Roman}
\pagenumbering{roman}
\tableofcontents
\thispagestyle{empty}
\newpage
\pagenumbering{arabic}

% *************** Questions Section ******************

\fontsize{15pt}{15pt}
\newcommand{\nnl}{\newline \noindent}
\newcommand{\ptx}{ P_{tx} }
\newcommand{\prx}{ P_{rx} }
%===================================
\section {Question 1}

\subsection{A}
\begin{doublespace}
 $ P_{tx} = 10 $\nnl
 $Att = -20 db$ \nnl
$P_{rx} = ? $ \nnl
\noindent $ att = 10 * \log_{10} {(\frac {\prx}{\ptx})}  \Longrightarrow -20 =  10 * \log_{10} {(\alpha)}   \Longrightarrow   \alpha = 10^{-2}          $ \nnl
$ \alpha = (\frac {\prx}{\ptx})  \Longrightarrow (\frac {\prx}{10})  =   \frac {1}{100}   \Longrightarrow   \prx =  \frac {1}{10} watt \Longrightarrow \prx = 10^{2} mW$\nnl
\end{doublespace}

\subsection{B}
\begin{doublespace}
$-10 = \log_{10}{\alpha} \Longrightarrow -1 = \log_{10}{\alpha} \Longrightarrow \alpha = 10^{-1}$\\
$\alpha_1 + \alpha_2 = 2 * 10^{-1} W \Longrightarrow $ Total Power = $ 200 mW$
\end{doublespace}
\line(1,0){450}

%===================================
\section {Question 2 }
\begin{doublespace}
Total Attenuation $= -12 + 35 - 10 = 13 db $ \\
$+13 = 10 * \log_{10} {(\frac {\prx}{4})}  \Longrightarrow 10^{1.3} = (\frac {\prx}{4}) \Longrightarrow \prx = 79.8 $
\end{doublespace}
\line(1,0){450}
%===================================
\section {Question 3 }

\subsection{A}
\begin{doublespace}
$Nyquist : C = 2 * W * m $ \\
$m = \log_2 {M}$\\
$M = 32 \Longrightarrow C = 2 * 10 K * \log_{2} {32}  \Longrightarrow C = 2 * 10K * 5 = 100 kb/s$\\
$C = 10^5$
\end{doublespace}

\subsection{B}
\begin{doublespace}
$C = BW * \log_2 {(1 + \frac{S}{N} )}  \Longrightarrow 100K = 10K * \log_2 {(1 + \frac{S}{N}) }  \Longrightarrow 10 = \log_2 {(1 + \frac{S}{N}) } \Longrightarrow 2^{10} = 1 + (\frac{S}{N}) \Longrightarrow (\frac{S}{N}) = 1023 $\\
$SNR = 10 * \log_{10} (\frac {S}{N}) \Longrightarrow SNR = 10 * \log_{10}{1023} \Longrightarrow SNR \approx 30 db$
\end{doublespace}

\subsection{C}
\begin{doublespace}
$C_{new} = 2 * C_{old} \Longrightarrow C_{new} = 2 * 100kb = 200kb = 2 * 10^5 b$\\
$2 * 10^5 = 10^4 * \log_2 {(1 + \frac{S}{N} ) } \Longrightarrow 20 = \log_2 {(1 + \frac{S}{N} )} \Longrightarrow \frac{S}{N} + 1 = 2 ^{20} \Longrightarrow \frac{S}{N} = 2^{20} - 1 $\\
$SNR = 10 * \log_{10}{\frac{S}{N}} \Longrightarrow SNR = 10 * \log_{10}{(2^{20} - 1) } \approx 60 db  \Longrightarrow SNR \approx 60 db$

\end{doublespace}
\line(1,0){450}

%===================================
\section {Question 4 }
\begin{doublespace}
$N = 10mW$\\
$\ptx = 20dbmW \Longrightarrow 10 \log_{10}{2} = 20 \Longrightarrow \log_{10}{S} = 2 \Longrightarrow \ptx = 10^2  mW $\\
$-5 = 10 \log_{\frac{\prx}{100}}{10} \Longrightarrow (\frac{-1}{2}) = \log_{\prx}{100} \Longrightarrow 10^{-5} = \frac{\prx}{10^2} \Longrightarrow \prx = 10^{1.5} = S$\\
$C = BW * \log_{2}{(1 + \frac{S}{N})} \Longrightarrow C = 2 * 10^6  * \log_{2}{(1 + 10^{0.5})} \Longrightarrow C = 2 * 10^6 * \log_{2}{(3.16 + 1)} \Longrightarrow  C = 2 * 10^6 * \log_{2}{(4.16)} \approx 4 MHz $
\end{doublespace}
\line(1,0){450}

%===================================
\section {Question 5 }
\begin{doublespace}
$\log_{10}{(\frac{E_b}{N_0})} = 4.2 db$\\
$E_b = S * T_b = \frac{S}{R} \Longrightarrow (\frac{E_b}{N_0}) = (\frac{S}{R N_0}) =( \frac{S}{RKT})$\\
$\Longrightarrow 10 \log_{10}{(\frac{E_b}{N_0})} = 10 \log_{10}{(S)} - 10 \log_{10}{(RKT)} \Longrightarrow 10 \log_{10}{(S)} = 10 \log_{10}{(RKT)} + 10 \log_{10}{(\frac{E_b}{N_0})} \Longrightarrow 10 \log_{10}{(S)} = 10 \log_{10}{(RKT)} + 4.2 \Longrightarrow 10 \log_{10}{(S)} = 10 \log_{10}{(270 * 3600 * 1.38 * 10^{-23})} + 4.2  \Longrightarrow  10 \log_{10}{(S)} = -164.67 \Longrightarrow  \log_{10}{(S)} = -16.467 \Longrightarrow S = 10^{-16.46} \approx 10^{-16}$
\end{doublespace}
\line(1,0){450}

%===================================
\section {Question 6 }
\begin{doublespace}
$T_s $ : Sampling Time \\
$T_x$ : TDM Sampling Time \\
$n$ : Number of Samples \\
Sampling Rate : $\frac{1}{T_x}$\\
$T_x = \frac{T_s}{n}  \Longrightarrow T_x = \frac{0.5us}{120} \Longrightarrow$ Sampling Rate $ = 240Mb/s$\\
$BW_{TDM} = \frac{1}{2T_x} \Longrightarrow BW_{TDM} = 120 MHz$ \\

\end{doublespace}
\line(1,0){450}

%===================================
\section {Question 7 }
\begin{doublespace}
10 Channels + 9 Guard Band : $\Longrightarrow  10 * (4 )KHz + 9 * (0.5) KHz = 40 + 4.5 = 44.5 KHz $
\end{doublespace}
\line(1,0){450}

%===================================

\section {Question 8 }

\subsection{A}
\begin{doublespace}
In FSK $: F_g $>$  0 \Longrightarrow f_s - \frac{R}{2}  $>$  0 \Longrightarrow  f_s - 1000 > 0 \Longrightarrow f_s > 1000 $ \\
I Assume that : $f_s = 1200 \Longrightarrow f_g = 200$ \\
$BW = 1200 + 1000 = 2200$\\
\end{doublespace}

\subsection{B}
In ASK : $BW = 2f_0 = R = 2 kHz$ \\

\subsection{C}
Both FSK and PSK are calculated with the same formula $\Longrightarrow BW = 2f_0 = R = 2 kHz $\\
\line(1,0){450}
%===================================
\section {Question 9 }
\begin{doublespace}
$10 \log_{10}{(\frac{E_b}{N_0})} = 10 \log_{10}{\frac{S}{N}} + 10 \log_{10}{W} - 10 \log_{10}{R} \Longrightarrow 18 = 15 + 10 \log_{10}{\frac{S}{R}} \Longrightarrow 3 = 10 \log_{10}{\frac{W}{R}} \Longrightarrow$\\
$ (\frac{W}{R}) = 10^{0.3} \Longrightarrow B = (\frac{R}{W}) = \frac{1}{10^{0.3}} \approx 0.5$
\end{doublespace}
\line(1,0){450}

% ====================== End Doc =============================
\end{document}

Samples/Sample 1 - Data Transfer HW 1/Tutorial.tex


\documentclass[fleqn]{article}
\usepackage{enumitem}
\setlist[enumerate]{itemsep=1.2em} % increases vertical space between items
\setlist[enumerate,1]{itemsep=1.2em} % increases vertical space between level 0 and level 1 items
\setlist[enumerate,2]{itemsep=1.2em} % increases vertical space between level 1 and level 0 items
\usepackage{amsmath}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\lhead{Henrik Samuelsson}
\rhead{henrik.samuelsson@gmail.com}

\begin{document}
\section*{Solutions Programme F.1 Arithmetic}
Solutions to exercises from the book Engineering Mathematics 7th edition. The book is divided into frames and the numbering of the following exercises refers to the numbers of these frames.

\begin{enumerate}[label=\textbf{\arabic*.},labelsep=2em]

%frame 2
\setcounter{enumi}{1}
\item
The numbers $-10$, $4$, $0$, $-13$ are of a type called integers.

%frame 3
\item

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $-3 > -6$
\item $2 > -4$
\item $-7 < 12$
\end{enumerate}

%frame 5
\setcounter{enumi}{4}
\item

\begin{enumerate}[label=\textbf{(\alph*)}]
\item $8 + (-3) = 8 - 3 = 5$
\item $9 - (-6) = 9 + 6 = 15$
\item $(-14) - (-7) = -14 + 7 = -7$
\end{enumerate}

%frame 7
\setcounter{enumi}{6}
\item
\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $(-5) \times 3 = -15$
\item $12 \div (-6) = -2$
\item $(-2) \times (-8) = 16$
\item $(-14) \div (-7) = 2$
\end{enumerate}

%frame 9
\setcounter{enumi}{8}
\item
$34 + 10 \div (2 - 3) \times 5 =
34 + 10 \div (-1) \times 5 =
34 -10 \times 5 =
34 - 50 = -16$

%frame 13
\setcounter{enumi}{12}

\item Some numbers and the rounding of these numbers to the nearest 10, 100 and 1000.

\begin{enumerate}[label=\textbf{(\alph*)}]
\item $ 1846, 1850, 1800, 2000 $
\item $ -638, -640, -600, -1000 $
\item $ 445, 450, 400, 0 $
\end{enumerate}

%frame 14
\setcounter{enumi}{13}
\item
\begin{enumerate}[label=\textbf{(\alph*)}]
\item $ 18 \times 21 - 19 \div 11 \approx 20 \times 20 - 20 \div 10 = 398 $
\item $ 99 \div 101 - 49 \times 8 \approx 100 \div 100 - 50 \times 10 = -499 $
\end{enumerate}

%frame 17
\setcounter{enumi}{16}
\item This frame holds multiple review exercises that follow below.

\begin{enumerate}[label=\textbf{\arabic*.} ,labelsep=2em]
\item

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $ -1 > -6 $
\item $ 5 > -29 $
\item $ -14 < 7 $
\end{enumerate}

\item

\begin{enumerate}[label = \textbf{(\alph*)},labelsep=2em]
\item $ 16 - 12 \times 4 + 8 \div 2 = 16 - 48 + 4 = -28 $
\item $ (16 - 12) \times (4 + 8) \div 2 = 4 \times 12 \div 2 = 24 $
\item $ 9 - 3(17 +5[5 - 7]) = 9 - 3(17 - 10) = 9 - 21 = -12$
\item $ 8(3[2 + 4] - 2[5 + 7]) = 8(3 \times 6 - 2 \times 12) = 8(18 - 24) = 8(-6) = -48$
\end{enumerate}

\item
\begin{enumerate}[label = \textbf{(\alph*)},labelsep=2em]

\item
Show that: \\
$ 6 - (3 - 2) \neq (6 -3) - 2 $

Proof: \\
$ LHS = 6 - (3 - 2) = 6 - 1 = 5 $ \\
$ RHS = (6 - 3) - 2 = 3 - 2 = 1 $ \\
$ LHS \neq RHS $

\item
Show that: \\
$ 100 \div (10 \div 5) \neq (100 \div 10) \div 5 $

Proof: \\
$ LHS = 100 \div (10 \div 5)) = 100 \div 2 = 50 $ \\
$ RHS = (100 \div 10) \div 5 = 10 \div 5 = 2$ \\
$ LHS \neq RHS $

\item
Show that: \\
$ 24 \div (2 - 6) \neq 24 \div 2 - 24 \div 6 $

Proof: \\
$ LHS = 24 \div (2 - 6) = 24 \div (-4) = -6 $ \\
$ RHS = 24 \div 2 - 24 \div 6 = 12 - 4 = 8$ \\
$ LHS \neq RHS $

\end{enumerate}
\item Some numbers and the rounding of these numbers to the nearest 10, 100 and 1000.
\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $ 2562, 2560, 2600, 3000 $
\item $ 1500, 1500, 1500, 2000 $
\item $ -3451, -3450, -3500, -3000 $
\item $ -14525, -14530, -14500, -15000 $
\end{enumerate}

\end{enumerate}
%frame 17 end

%frame 19
\setcounter{enumi}{18}
\item
\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $ 12 = 1 \times 12 = 2 \times 6 = 3 \times 4 $ \\
So the factors of 12 are 1, 2, 3, 4, 6, 12.
\item $ 25 = 1 \times 25 = 5 \times 5 $ \\
So the factors of 25 are 1, 5, 25.
\item $ 17 = 1 \times 17 $ \\
So the factors of 17 are 1, 17.
\end{enumerate}

%frame 21
\setcounter{enumi}{20}
\item
\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $ 84 = 2 \times 42 = 2 \times 2 \times 21 = 2 \times 2 \times 3 \times 7 $
\item $ 512 = 2^9 = 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 $ \\
\end{enumerate}

%frame 23
\setcounter{enumi}{22}
\item
The prime factorizations of 84 and 512 are

$84 = 2 \times 2 \times 3 \times 7$

$ 512 = 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 $

The highest common factor of 84 and 512 is hence

$ HCF = 2 \times 2 = 4 $

And the lowest common multiple is

$ LCF = 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 2 \times 3 \times 7
= 10752 $

%frame 26
\setcounter{enumi}{25}
\item This frame holds multiple review exercises that follow below.

\begin{enumerate}[label=\textbf{\arabic*.},labelsep=2em]
\item
Repeated integer division by increasingly bigger numbers gives the following products of prime factors.

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item $ 429 = 3 \times 11 \times 13 $
\item $ 1820 = 2 \times 2 \times 5 \times 7 \times 13 $
\item $ 2992 = 2 \times 2 \times 2 \times 2 \times 11 \times 17 $
\item $ 3185 = 5 \times 7 \times 7 \times 13 $
\end{enumerate}

\item

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item
The prime factorizations of 63 and 42 are

$ 63 = 3 \times 3 \times 7 $

$ 42 = 2 \times 3 \times 7 $

The highest common factor of 63 and 42 is hence

$ HCF = 3 \times 7 = 21 $

And the lowest common multiple is

$ LCF = 2 \times 3 \times 3 \times 7 = 126 $
\item
The prime factorization of 34 and 92 are

$ 34 = 2 \times 17$

$ 92 = 2 \times 2 \times 23 $

The highest common factor of 34 and 92 is hence

$ HCF = 2 $

And the lowest common multiple is

$ LCF = 2 \times 2 \times 17 \times 23 = 1564 $

\end{enumerate}

\end{enumerate} %end of frame 26

%frame 28
\setcounter{enumi}{27}
\item
An example of a proper fraction is $ \dfrac{-8}{11} $

%frame 30
\setcounter{enumi}{29}
\item
$ \dfrac{5}{9} \times \dfrac{2}{7} = \dfrac{5 \times 2}{ 9 \times 7} = \dfrac{10}{63}$

%frame 33
\setcounter{enumi}{32}
\item
$ \dfrac{3}{8}\ of\ \dfrac{5}{7} = \dfrac{3}{8} \times \dfrac{5}{7} = \dfrac{3 \times 5}{ 8 \times 7} = \dfrac{15}{56}$

%frame 34
\setcounter{enumi}{33}
\item
$ \dfrac{7}{5} $ and $ \dfrac{28}{20} $ are equivalent fractions because $ \dfrac{7}{5} \times \dfrac{4}{4} = \dfrac{7 \times 4}{5 \times 4} = \dfrac{28}{20} $

%frame 35
\setcounter{enumi}{34}
\item
$ \dfrac{84}{108} = \dfrac{42 \times 2}{54 \times 2} = \dfrac{42}{54} = \dfrac{21 \times 2}{27 \times 2} = \dfrac{21}{27} = \dfrac{7 \times 3}{ 9 \times 3} = \dfrac{7}{9} $

%frame 37
\setcounter{enumi}{36}
\item
$ \dfrac{7}{13} \div \dfrac{3}{4} = \dfrac{7}{13} \times \dfrac{4}{3} = \dfrac{28}{39}$

%frame 38
\setcounter{enumi}{37}
\item
The reciprocal of $ \dfrac{17}{4} $ is $ \dfrac{4}{17} $

%frame 39
\setcounter{enumi}{38}
\item
The reciprocal of $ -5 $ is $ -\dfrac{1}{5} $

%frame 41
\setcounter{enumi}{40}
\item
$ \dfrac{5}{9} + \dfrac{1}{6} = \dfrac{10}{18} + \dfrac{3}{18} = \dfrac{13}{18} $

%frame 43
\setcounter{enumi}{42}
\item
$ \dfrac{11}{15} - \dfrac{2}{3} = \dfrac{11}{15} - \dfrac{10}{15} = \dfrac{1}{15} $

%frame 47
\setcounter{enumi}{46}
\item
We have $ \dfrac{3}{4} = \dfrac{9}{12} $ of A, $ \dfrac{1}{6} = \dfrac{2}{12} $ of B and $ \dfrac{1}{12} $ of C in the compound.

This means that the ratio in the compound is

$ 9:2:1 $

%frame 49
\setcounter{enumi}{48}
\item
The percentage of cars that are red is

$ \dfrac{13}{100}=13\%$

%frame 50
\setcounter{enumi}{49}
\item
$ \dfrac{12}{25} = \left(\dfrac{12}{25}\times100\right)\% = \left(\dfrac{12}{25}\times25\times4\right)\% = \left(12\times4\right)\%=48\%$

%frame 52
\setcounter{enumi}{51}
\item
$ \dfrac{8}{100}\times25 = \dfrac{2\times4}{4\times25}\times25 = 2 $

%frame 54
\setcounter{enumi}{53}
\item This frame holds multiple review exercises that follow below.

\begin{enumerate}[label=\textbf{\arabic*.},labelsep=2em]

\item
Reduction of fractions to their lowest terms.

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]

\item $ \dfrac{24}{30} = \dfrac{2 \times 2 \times 2 \times 3}{2 \times 3 \times 5} = \dfrac{2 \times 2}{5} = \dfrac{4}{5} $

\item $ \dfrac{72}{15} = \dfrac{2 \times 2 \times 2 \times 3 \times 3}{3 \times 5} = \dfrac{2 \times 2 \times 2 \times 3}{5} = \dfrac{24}{5} $

\item $ -\dfrac{52}{65} = -\dfrac{2 \times 2 \times 13}{5 \times 13} = -\dfrac{2 \times 2}{5} = -\dfrac{4}{5} $

\item $ \dfrac{32}{8} = -\dfrac{4 \times 8}{8} = 4 $

\end{enumerate}

\item
Fraction evaluation.

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]

\item
$
	\dfrac{5}{9} \times \dfrac{2}{5} =
	\dfrac{5 \times 2}{ 9 \times 5} =
	\dfrac{2}{9}
$

\item
$
	\dfrac{13}{25} \div \dfrac{2}{15} =
	\dfrac{13}{25} \times \dfrac{15}{2} =
	\dfrac{13}{5 \times 5} \times \dfrac{3 \times 5}{2} =
	\dfrac{13 \times 3 \times 5}{5 \times 5 \times 2} =
	\dfrac{39}{10}
$

\item
$
	\dfrac{5}{9} + \dfrac{3}{14} =
	\dfrac{5 \times 14}{9 \times 14} + \dfrac{3 \times 9}{14 \times 9} =
	\dfrac{70}{126} + \dfrac{27}{126} =
	\dfrac{97}{126}
$

\item
$
	\dfrac{3}{8} - \dfrac{2}{5} =
	\dfrac{3 \times 5}{8 \times 5} - \dfrac{2 \times 8}{5 \times 8}=
	\dfrac{15}{40} - \dfrac{16}{40} =
	- \dfrac{1}{40}
$

\item
$
	\dfrac{12}{7} \times \left( - \dfrac{3}{5} \right) =
	- \left( \dfrac{12}{7} \times \dfrac{3}{5} \right) =
	- \dfrac{12 \times 3}{7 \times 5} =
	- \dfrac{36}{35}
$

\item
$
	\left( -\dfrac{3}{4} \right) \div \left( -\dfrac{12}{7} \right) =
	\left( -\dfrac{3}{4} \right) \times \left( -\dfrac{7}{12} \right) =
	\dfrac {(-3) \times (-7)}{4 \times 12} =
	\dfrac {3 \times 7}{4 \times 12} = \\[8pt]
	\dfrac{3 \times 7}{4 \times 3 \times 4} =
	\dfrac{7}{4 \times 4} =
	\dfrac{7}{16}
$

\item
$
	\dfrac{19}{2} + \dfrac{7}{4} =
	\dfrac{38}{4} + \dfrac{7}{4} =
	\dfrac{45}{4}
$

\item
$
	\dfrac{1}{4} - \dfrac{3}{8} =
	\dfrac{2}{8} - \dfrac{3}{8} =
	-\dfrac{1}{8}
$

\end{enumerate}

\item
Writing proportions as ratios.

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item
The proportions are

$
	\dfrac{1}{2}, \dfrac{2}{5}, \dfrac{1}{10}
$

these can be written as

$
	\dfrac{5}{10}, \dfrac{4}{10}, \dfrac{1}{10}
$

so the ratio is

$
	5:4:1
$

\item
The proportions are

$
	\dfrac{1}{3}, \dfrac{1}{5}, \dfrac{1}{4}
$

plus the remainder that we need to calculate.

The remainder will be

$
	1 - \dfrac{1}{3} - \dfrac{1}{5} - \dfrac{1}{4} = \\
	\dfrac{3 \times 4 \times 5}{3 \times 4 \times 5} -
	\dfrac{4 \times 5}{3 \times 4 \times 5} -
	\dfrac{3 \times 4 }{3 \times 4 \times 5 } -
	\dfrac{3 \times 5}{3 \times 4 \times 5} = \\
	\dfrac{60}{60} - \dfrac{20}{60} - \dfrac{12}{60} - \dfrac{15}{60} =
	\dfrac{13}{60}
$

so the ratio is

$
	20:12:15:13
$

\end{enumerate}

\item
Percentage exercises

\begin{enumerate}[label=\textbf{(\alph*)},labelsep=2em]
\item
$
	\dfrac{2}{5} = \dfrac{2 \times 20}{5 \times 20} = \dfrac {40}{100} = 40 \%
$
\end{enumerate}

\end{enumerate}

\end{enumerate} %end of frame 54

\end{document}

Solutions/Part 1 - Programme F1 - Arithmetic.tex


\section{Introduction}
This assignment involves implementation of a generation constructive hyper-
heuristics to create heuristics for the symmetric and asymmetric Travel-
ling Salesman Problem (TSP). More specifically, the toolset provided by ECJ \cite{pillay2017evohyp} - a Java toolkit for evolutionary algorithm hyper-heuristics - was used to construct a genetic programming approach to generate and evolve a population of parse trees for prioritizing routes for travelling salesman problems in the Travelling Salesman Problem Library \cite{reinelt1991tsplib}. All of the code that was used to employ the genetic algorithm can be found on GitHub at \url{https://github.com/marcus-bornman/cos_790_assignment_3}. The repository also contains all information necessary to reproduce the results that are discussed in this assignment.