\documentclass[]{article}

%opening
\title{Vision and Perception}
\author{Nijat Mursali | 1919669}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds}
\usepackage{graphicx}
\begin{document}

\maketitle

\begin{abstract}
	This document is used to illustrate all the homework exercises that has been given during Vision and Perception course in 2020/21. There are overall 14 exercises that needed to be done during this time.

\end{abstract}

\section{Homework 1 - Degenerate Conic}
As mentioned during the video of Geometric Parameters, we needed to compute the $M_{2}$ as we did for $M_{1}$ and then computing the null space of $M_{1}$ and verifying that is 2, then computing the cross product of null space vectors and after normalizing to obtain the $x_{3} = 1$, we needed to think about the result.
\vspace{0.4em}

The idea is here space of $M_{1}$ and verifying that is 2, then computing the cross product of null space vectors and after normalizing to obtain the $x_{3} = 1$, we needed to think about the result.

\centerline {
\begin{tikzpicture}
\draw (-1.5, 0) coordinate(A) -- (2,0.2) coordinate (B) node [black, scale=1] {$l_{1}$};
\draw (-1,-1) coordinate(C) -- (1.5,1.5) coordinate (D) node [black, scale=1] {$l_{2}$};
\node[red,scale=3] at (intersection of  A--B and C--D){.};
\end{tikzpicture}
}
Thus, we need to consider the two intersecting lines that we have seen in our lecture:

\centerline {
$l_{1} = (0.2500, 3.200, 1.0000)^T$
$l_{2} = (-2.0000, 0.5000, 1.0000)^T$
}

\centerline {
	$x = l_{1} \times l_{2} = (-0.4138, 0.3448, 1.0000)^T$
}

\vspace{0.5em}

\centerline {
$M_{1} = l_{1}l_{1}^T =
\left( {\begin{array}{*{20}c}
	0.0625 & 0.8000 & 0.2500 \\
	0.8000 & 10.2400 & 3.2000 \\
	0.2500 &  3.2000 & 1.0000
	\end{array} } \right)$
}

Thus, by computing the degenerate conic for $l_{2}$, we could get something following:

\centerline {
$M_{2} = l_{2}l_{2}^T =
\left( {\begin{array}{*{20}c}
	4.0000 & -1.0000 & -2.0000 \\
	-1.0000 & 0.2500 & 0.5000 \\
	-2.0000 &  0.5000 & 1.0000
	\end{array} } \right)$
}

As we see from the book, the null space can be computed by span as following:

\centerline {
	$Null(M_{1}) = Span\{\left( {\begin{array}{*{20}c}
	0.2210 \\
	0.2751 \\
	-0.9357
	\end{array} } \right),\left( {\begin{array}{*{20}c}
	-0.9724 \\
	 0.1353 \\
	-0.1899
	\end{array} } \right) \}$
}

and

\centerline { $Null(M_{2}) = Span\{\left( {\begin{array}{*{20}c}
	0 \\
	0.8944 \\
	-0.4472
	\end{array} } \right),\left( {\begin{array}{*{20}c}
	-0.4880 \\
	-0.3904 \\
	-0.7807
	\end{array} } \right) \}$ }

Finally, we need to calculate the cross-product of the null-space components of $M_{1}$ as:

$M_{1} = (0.2210, 0.2751, -0.9357) \times (-0.9724, 0.1353, -0.18,99) = (0.0744, 0.9518, 0.2974)^T$
\vspace{0.2em}
then, for $M_{2}$ it will be like:
\vspace{0.2em}

$M_{2} = (0, 0.8944 - 0.4472) \times (-0.4880, -0.3904, -0.7807) = (-.8728, 0.2182, 0.4365)^T$

We come up to the result that these two results are no more than the original lines, $l_{1}$ and $l_{2}$ with unitary norm.

\section{Homework 2 - Five Points Define a Conic}

As we know for each point the conic passes through

\centerline {$ax_{i}^2 + bx_{i}y_{i} + cy_{i}^2 + dx_{i} + ey_{i} + f = 0$ }

\vspace{0.4em}

or

\centerline {
	($x_{i}^2, x_{i}y_{i}, y_{i}^2, x_{i}, y_{i}, f)c = 0$, where $c = (a,b,c,d,e,f)$
}

stacking constraints yields

\centerline {
	$\left[ {\begin{array}{*{20}c}
		x_1^2 & x_1y_1 & y_1^2 & x_1 & y_1 & 1 \\
		x_2^2 & x_2y_2 & y_2^2 & x_2 & y_2 & 1 \\
		x_3^2 & x_3y_3 & y_3^2 & x_3 & y_3 & 1 \\
		x_4^2 & x_4y_4 & y_4^2 & x_4 & y_4 & 1 \\
		x_5^2 & x_5y_5 & y_5^2 & x_5 & y_5 & 1
		\end{array} } \right]c = 0$
}

thus to determine the parameters of the equation, we need at least five points. Consider the following:

\centerline {
	\includegraphics[scale=0.5]{scr2}
}

As we see from the equation, we need to determine the parameters of the equation with at least five points. So, for this homework we just chose 4 points in xy plane with different values, thus we have the following set of equations:

\centerline {
	$\left[ {\begin{array}{*{20}c}
			0 & 0 & 16 & 0 & 4 & 1 \\
			1 & 1 & 1  & 1 & 1 & 1 \\
			9 & 24 & 64  & 3 & 8 & 1 \\
			36 & 36 & 36  & 6 & 6 & 1 \\
			49 & 21 & 9  & 7 & 3 & 1\\
	\end{array} } \right]
	\left[ {\begin{array}{*{20}c}
			a \\
			b \\
			c \\
			d \\
			e \\
			f
	\end{array} } \right] = 0 $
}

from which we obtain the following values:

\centerline {
	$a = 0.0876$, $b = 0.0258$, $c = 0.0532$, $d = -0.7038$, $e = -0.4629$, $f = 1$,
}

thus giving us following result:

\centerline {
\includegraphics[scale=0.5]{scr1}
}

\section{Homework 3 - Compute the DLT algorithm}
In order to solve this problem, we needed to take one picture and apply the algorithm to check the coordinates of the shape. The idea is to pick 4 points on two different images by hand and apply the DLT algorithm showing the calculations. Additionally, the point selection is arbitrary.

Thus, we consider the following picture where we selected the four points as DLT algorithm stated in order to get 2D point correspondences {$x_i \leftrightarrow  x_i'$}.

\centerline {
	\includegraphics[scale=0.4]{src}
}

From the 2D to 2D point correspondences we need to determine 2D homography matrix H such that $x_i' = Hx_i$.

The fundamental goal of ours is to apply homography so that the outline shape of object forms a rectangle. The homogeneous coordinates for the shape are:

\centerline {
	$A = \left[ {\begin{array}{*{20}c}
		281.0 & 234.0 & 1.0 \\
		587.0 & 580.0 & 1.0 \\
		808.0 & 375.0 & 1.0 \\
		506.0 & 45.0 & 1.0
		\end{array} } \right]$
}

and our target shape has the coordinates:

\centerline {
	$B = \left[ {\begin{array}{*{20}c}
		172.0 & 347.0 & 1.0 \\
		566.0 & 580.0 & 1.0 \\
		763.0 & 340.0 & 1.0 \\
		336.0 & 166.0 & 1.0
		\end{array} } \right]$
}

thus yielding the following equation:

\centerline {
	$B = AH$
}

in which we ought to find the homography that produces such transformation. The matrix A is non-square, thus it cannot be inverted, we have to resort to the Direct Linear Transformation algorithm, in which at least three non-co-linear points are used to find the 8 independent terms of the transformation matrix. Since our settings have four points, our system is over determined, from which we derive the following transformation matrix:

\vspace{0.5em}

\centerline {
	$H = \left[ {\begin{array}{*{20}c}
		9.7955 & 2.1074 & -1.4142 \\
		-3.4637 & 7.1861 & 2.9439 \\
		-4.2166 & -1.3235 & 1.000
		\end{array} } \right] $
}

\vspace{0.5em}

from which we finally obtain the following transformation:

\vspace{0.5em}
\centerline {
	\includegraphics[scale=0.4]{out}
}

\vspace{0.5em}

\section{Homework 4 - Affine Transformations}

The task for this exercise is to show that an affine transformation preserves both parallel lines and area. First of all let's describe what exactly affine transformation is. Affine transformation is a function mapping an affine space onto itself that preserves the dimension of any affine subspaces and also preserves the ratio of the lengths of parallel line segments. Additionally, those sets of parallel affine subspaces still remain the same parallel after an affine transformation and and in this exercise we needed to show that.

\subsection{Affine transformation preserves parallel lines}
As we have talked in the lecture, we have:

\vspace{0.5em}

\centerline {
	$l_1 = (0, 1, 1)^T$ and $l_2=(0,2.45,1)^T$
}

\vspace{0.5em}

These lines are parallel as they cross-product give us the following:

\vspace{0.5em}

\centerline {
	$l_1 \times l_2 = (-1.45, 0, 0)^T$
}

\vspace{0.5em}
Points of the two lines can be obtained as follows:

\vspace{0.5em}

\centerline {
	$p_1$, $p_2 = Null(l_1)$,
}

\vspace{0.5em}

\centerline {
	$p_1=(-0.707, 0.500, -0.500)^T$ and $p_2=(-0.707, -0.500, 0.500)$
}

\vspace{0.5em}

Conversely,

\centerline {
	$q_1$, $q_2 = Null(l_2)$,
}

\vspace{0.5em}

\centerline {
	$q_1=(-0.936, 0.123, -0.328)^T$ and $q_2=(-0.351, -0.328, 0.877)$
}

Given the following transformation parameters: $\alpha = 0.7$, $s_1=1.4$, $s_2=0.9$, $t_x=t_y=1.2$, we obtain the following affine transformation matrix:

\vspace{0.5em}

\centerline {
	$H = \left[ {\begin{array}{*{20}c}
		1.07080 & 0.0618 & 1.2000 \\
		0.9019 & 1.8825 & 1.2000 \\
		0 & 0 & 1.0000
		\end{array} } \right] $
}

\vspace{0.5em}

Applying the affine transformation onto the lines, we obtain:

\vspace{0.5em}

\centerline {
	$l_1' = l_1H = (0.902, 1.88, 2.20)$ and $l_2' = l_2H = (2.40, 5.02, 4.20)$
}

\vspace{0.5em}

and so, we verify:

\centerline {
	$l_1' \times l_2'=(-3.14, 1.51, 0)^T$
}

Given the last coordinate in 0, we can ascertain that the lines remain parallel after the transformation.

\subsection{Affine transformation preserves area}

Given the two triangles formed by an arbitrary collection of lines, $l_1, l_2, l_3$ and $l_4$:

\centerline {
	\includegraphics[scale=0.3]{hw4}
}

where $l_1$ and $l_2$ are parallel. We also know from the first example that, we can calculate the $p_i$ as $p_1 = l_1 \times l_3$, $p_2 = l_1 \times l_4$, $p_3 = l_3 \times l_4$ and also finding $q_i$ will be as $q_1 = l_2 \times l_4$, $q_2 = l_2 \times l_3$.We can calculate the area $S$ of the triangles $A$ and $B$, using Heron's relation:

\centerline {
	$S_A = \sqrt{s(s-a)(s-b)(s-c)}$
}

where s is the semi-perimeter of the triangle $S$.

For triangle A, the relation is as follows:

\centerline {
	$S_A=\sqrt{s_A(s_A - \overline{p_1p_3})(s_A - \overline{p_1p_2}) (s_A - \overline{p_2p_3})}$
}

As for triangle $B$, we have:

\centerline {
	$S_B=\sqrt{s_B(s_B - \overline{p_1p_3})(s_B - \overline{p_1p_2}) (s_B - \overline{p_2p_3})}$
}

Hence, for both triangles, their respective areas can be simply described by the distance of the intersecting points. Given an arbitrarily affine transformation $H$, that can be described as:

\centerline{ $H = \left[ {\begin{array}{*{20}c}
		A & t \\
		\overrightarrow{0} & 1
		\end{array} } \right]$ }

Taking a line segment of each triangles, we can get the ratio as:

\centerline {
	$\frac{\overline{p_1p_3}}{\overline{q_2q_3}} = \frac{\sqrt{(l_3 \times l_4 - l_1 \times l_3)(l_3 \times l_4 - l_1 \times l_3)}}{\sqrt{(l_3 \times l_4 - l_2 \times l_3)(l_3 \times l_4 - l_2 \times l_3)}}$
}

If we analyze the ratio's behavior under the transformation H by simply multiplying them with H, we get the following equation:

\centerline {
	$\frac{\overline{p_1p_3}'}{\overline{q_2q_3}'} = \frac{\overline{p_1p_3}}{\overline{q_2q_3}}$
}

This relation can be naturally extended to any two line segments, thus the ratio between the areas of the triangle are also preserved.

\section{Homework 5 - Homography keeps lines tangent to conics}
Consider the following line $l$, tanget to the conic $C$ at the point $x$,

\centerline {
	\includegraphics[scale=0.5]{scr3}
}

As we have seen in our class slides, we know that $l = Cx$ and $x^Tl=x^TCx = 0$. For this exercise, we need to show that $X^TCX=0$ that $l=Cx$. Additionally it was required to show the configuration $l^Tx=0$. Using the homography $H$ on $x$, we get $x'=Hx$, and to reverse this transformation, we can use the inverse homography $H^-1$. With the aformentioned properties, we can rewrite the equations like so:

\vspace{0.5em}

\centerline {
	$x^TCx = (H^{-1}x')^TC(H^{-1}x') = 0$
}
\vspace{0.5em}

this, in turn, is equivalent to :

\vspace{0.5em}

\centerline {
	$x^TCx = x'(H^{-1})^TCH^{-1}x' = x'C'x' = 0$.
}

\vspace{0.5em}

From the relation $l = Cx$, we have:

\vspace{0.5em}

\centerline {
	$(H^{-1})^Tl = (H^{-1})^TCx$,
}

\vspace{0.5em}

which can be rewritten to:

\vspace{0.5em}

\centerline {
	$(H^{-1})^Tl = (H^{-1})^TC(H^{-1}H)x$.
}

\vspace{0.5em}

As we have previously seen: $C' = (H^{-1})^TCH^{-1}$, and so the previous equation becomes:

\centerline {
	$(H^{-1})^Tl = C'Hx$
}

\vspace{0.5em}

which finally gives us:

\vspace{0.5em}

\centerline {
	$l' = C'x'$
}

which it shows from the equation that $l'$ is also tangent to $C'$.

\section{Homework 6 - SVD for given matrix}
As we have seen from the example, the matrix A which we out to decompose is the following:

\vspace{0.5em}

\centerline{ $A = \left[ {\begin{array}{*{20}c}
		2 & 3 & 1 \\
		1 & 4 & -2
		\end{array} } \right]$ }

The singular value decomposition (SVD) property proposes that any given matrix can be decomposed in three matrices that is:

\vspace{0.5em}

\centerline { $A = U \Sigma V^T$}

\vspace{0.5em}

where $\Sigma$ is a rectangular diagonal matrix and, $U$ and $V^T$ are orthogonal matrices. To obtain these matrices, we first compute the product $A^TA$ as following:

\vspace{0.5em}

\centerline {
	$A^TA = (U \Sigma V^T)^T U \Sigma V^T = V (\Sigma^T \Sigma)V^T $
}

\vspace{0.5em}

which will be equal to

\vspace{0.5em}

\centerline{ $A^TA = \left[ {\begin{array}{*{20}c}
		5 & 10 & 0 \\
		10 & 25 & -5 \\
		0 & -5 & 5
		\end{array} } \right]$
}

\vspace{0.5em}

from this relation, we extract the eigenvalues of $A^TA$ as follows:

\vspace{0.5em}

\centerline {
	$(A^TA - I \lambda) x = 0$
}

\vspace{0.5em}

in which, in order to obtain a non-trivial solution, the following property must hold:

\vspace{0.5em}

\centerline {
	$det(A^TA - I \lambda) = 0$
}

\vspace{0.5em}

which gives the following equation:

\vspace{0.5em}

\centerline {
	$(5- \lambda) (25 - \lambda)(5 - \lambda) - 25(5 - \lambda) - 100(5 - \lambda) = 0 $
}

\vspace{0.5em}

From this equation, we arrive at the following solutions:

\vspace{0.5em}

\centerline {
	$\lambda_{1} = 30$, $\lambda_{2} = 5$, $\lambda_{3} = 0$
}

\vspace{0.5em}

To obtain the eingenvectors, we must find the vectors that lie in the null-space of the resulting matrices once
each eigenvalue is substituted:

For $\lambda = 30$:

\vspace{0.5em}

\centerline{ $\left[ {\begin{array}{*{20}c}
		-25 & 10 & 0 \\
		10 & -5 & -5 \\
		0 & -5 & -25
		\end{array} } \right] x = 0$,  }

Giving us the following expressions:

\vspace{0.5em}

\centerline {
	$-25x_{1} + 10x_{2} = 0$,
}

\vspace{0.5em}

\centerline {
	$10x_{1} - 5x_{2} - 5x_{3} =0$,
}

\vspace{0.5em}

\centerline {
	$-5x_{2} - 25x_{3} = 0$
}

\vspace{0.5em}

from this linear set of equations, we arrive at the following solution:

\centerline {
	$x = [-1, -2.5, 0.5]^T$,
}

\vspace{0.5em}

which is then normalized:

\vspace{0.5em}

\centerline {
	$x = [-0.3651, -0.9129, 0.1826]^T$.
}

\vspace{0.5em}

Repeating the same procedure for the other eigenvalues, we arrive at:

\vspace{0.5em}

\centerline {
	$x = [-0.4472, 0, -0.8944]^T$ and $x = [0.8165, -0.4082, -0.4082]^T$
}

\vspace{0.5em}

Like so, we obtain the matrix $V$, compose of the column vectors:

\vspace{0.5em}

\centerline{ $V = \left[ {\begin{array}{*{20}c}
		-0.3651 & -0.4472 & 0.8165 \\
		-0.9129 & 0 & -0.4082 \\
		0.1826 & -0.8944 & -0.4082
		\end{array} } \right]$
}

\vspace{0.5em}

furthemore, we also obtain the matrix $\lambda$, which is the square root of the diagonal matrix composed of the calculated eigenvalues:

\vspace{0.5em}

\centerline{ $\Sigma = \left[ {\begin{array}{*{20}c}
		\sqrt{30} & 0 & 0 \\
		0 & \sqrt{5} & 0 \\
		0 & 0 & 0
		\end{array} } \right]$
}

\vspace{0.5em}

since the last row is a product of any above row, we can write:

\vspace{0.5em}

\centerline{ $\Sigma = \left[ {\begin{array}{*{20}c}
		\sqrt{30} & 0 & 0 \\
		0 & \sqrt{5} & 0
		\end{array} } \right]$
}

\vspace{0.5em}

The last step is to determine the orthonormal matrix $U$. This can be obtained by the following product:

\vspace{0.5em}

\centerline {
	$AV = U \Sigma V^TV$
}

\vspace{0.5em}

where we cross out the $\Sigma V^TV$ that gives us only $AV = U$. Hence:

\vspace{0.5em}

\centerline{ $\left[ {\begin{array}{*{20}c}
		2 & 3 & 1 \\
		1 & 4 & -2
		\end{array} } \right]
			\left[ {\begin{array}{*{20}c}
		-0.3651 & -0.4472 & 0.8165 \\
		-0.9129 & 0 & -0.4082 \\
		0.1826 & -0.8944 & -0.4082
		\end{array} } \right] = U \left[ {\begin{array}{*{20}c}
		\sqrt{30} & 0 & 0 \\
		0 & \sqrt{5} & 0
		\end{array} } \right]$
}

\vspace{0.5em}

which gives us the following matrix $U$:

\vspace{0.5em}
\centerline {
	$U = \left[ {\begin{array}{*{20}c}
		-0.6 & -0.8 \\
		-0.8 & 0.6
		\end{array} } \right]$
}

\section{Homework 7 - Projective Transformation}
The task here is to find the projective transformation $H$ and define the type of quadric from the quadric equation.

Firstly, let's clarify some points we have learned in our lectures.

\centerline {
	3D point in $R^3$ which is $X = (X, Y, Z)^T$ in $P^3 : (x_1, x_2, x_3, x_4)^T$,
}

\centerline {
	Euclidean frame $\pi : ax + by + cz +d = 0$, where
	$\pi^TX = 0 => (a b c d) ^T\left[ {\begin{array}{*{20}c}
		x_1 \\
		x_2 \\
		x_3 \\
		x_4
		\end{array} } \right] = 0$
}

Thus,

\centerline {
	$X = (X_1, X_2, X_3, X_4)$ derives,
}

\vspace{0.5em}

\centerline {
		$X^TAX = 4x_1^2 + 4x_1x_2 - 2x_1x_3 + 2x_1x_4 + 5x_2^2 - 2x_2x_4 + 2x_3^2 + 2x_3x_4 + 2x_4^2 = 0$
}

\vspace{0.5em}

\centerline {
	$\sum_{1 \leq i \leq  j \leq 4 }^{4} a_{ij}x_iy_i  = 4*x_1^2 + 2*2x_1x_2 + $
}

\vspace{0.5em}

\centerline {
	$+ 2 * (-1)x_1x_3 + 2* (1)x_1x_4 + 5*x_2^2 + 2(0)x_2x_3 + 2(-1)x_2x_4 +$
}

\vspace{0.5em}

\centerline {
	$+  2*x_3^2 + 2*(-1)x_2x_4 + 2* x_3^2 + 2*(1)x_3x_4 + 2*x_4 = 0$
}

\vspace{0.5em}

Then, we get the following A matrix,

\vspace{0.5em}

\centerline {
	$A = a_ia_j = \left[ {\begin{array}{*{20}c}
		a_{11} & a_{12} & a_{13} & a_{14} \\
		a_{21} & a_{22} & a_{23} & a_{24} \\
		a_{31} & a_{32} & a_{31} &  a_{34} \\
		a_{41} & a_{42} & a_{43} & a_{44}
		\end{array} } \right] =  \left[ {\begin{array}{*{20}c}
		4 & 2 & -1 & 1 \\
		2 & 5 & 0 & -1 \\
		0 & 0 & 2 &  1 \\
		0 & 0 & 0 & 2
		\end{array} } \right] = 0 $
}

\vspace{0.5em}

We also need to remember $Q = U^TDU$ which is equal to $H^TDH$ where U is orthogonal matrix and D is diagonal matrix.

Then from the following equation we are getting the $\lambda$ values.

\vspace{0.5em}

\centerline {
	$|\lambda I - A| = \left[ {\begin{array}{*{20}c}
		\lambda - 4 & -2 & 1 & -1 \\
		-2 & \lambda - 5 & 0 & 1 \\
		1 & 0 & \lambda - 2 &  -1 \\
		-1 & 1 & -1 & \lambda - 2
		\end{array} } \right] = 0$
}

\vspace{1.0em}

\centerline {
	$\lambda ^4 - 13 \lambda ^3 + 52 \lambda ^2 - 81 \lambda + 25 = 0$,
}

\vspace{1.0em}

\centerline {
	$\lambda _1 = 6.6637$, $\lambda _2 = 3.6360$, $\lambda _3 = 2.7153$, $\lambda _4 = -0.0151$
}

\vspace{1.0em}

Then, from the matrix we get the $V$ values,

\vspace{0.5em}

\centerline {
	$V_1 = \left[ {\begin{array}{*{20}c}
		-9.2387 \\
		-11.7071 \\
		2.1953 \\
		1
		\end{array} } \right]$,
	$V_2 = \left[ {\begin{array}{*{20}c}
		0.9476 \\
		-0.6564 \\
		0.0319 \\
		1
		\end{array} } \right]$,
	$V_3 = \left[ {\begin{array}{*{20}c}
		-0.5125 \\
		0.9964 \\
		2.1143 \\
		1
		\end{array} } \right]$,
	$V_4 = \left[ {\begin{array}{*{20}c}
		-0.6963 \\
		0.4770 \\
		-0.8417 \\
		1
		\end{array} } \right]$,
}

\vspace{1.0em}

Then, from the formula of $U_i = \frac{AV_i}{\sigma _i}$, we tried to find the $U$ value and got the following values:

\centerline  {
	$U_1 = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		-23.8491 \\
		-30.312 \\
		5.6681 \\
		2.5814
		\end{array} } \right] $, 	$U_2 = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		1.6564 \\
		-1.2517 \\
		0.3620 \\
		2.0575
		\end{array} } \right] $
}

\vspace{1.0em}

\centerline {
	$U_3 = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		-0.3444 \\
		1.4607 \\
		3.4840 \\
		1.6768
		\end{array} } \right] $, 	$U_4 = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		-0.0856 \\
		0.0418 \\
		-0.1043 \\
		0.1220
		\end{array} } \right] $
}

Thus, the final $U$ will be:

\vspace{0.5em}

\centerline {
	$U = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		0.4475 & 0.2008 & −0.6208 & −0.6115 \\
		−0.3066 & −0.3472 & 0.4300 & −0.7749 \\
		0.5410 & −0.8281 & −0.0210 & 0.1453 \\
		−0.6427 & −0.3917 & −0.6551 & 0.0662
		\end{array} } \right] $
}

\vspace{0.5em}

As we have found the $U$ matrix, now we could get the homography $H$ by finding the inverse of $U$ which gives us:

\vspace{0.5em}

\centerline {
	$H = U^{-1} = \frac{AV_i}{\sigma _i} = \left[ {\begin{array}{*{20}c}
		0.4475 & −0.3066 & 0.5410 & −0.6427 \\
		0.2008 & −0.3472 & −0.8281 & −0.3917 \\
		−0.6208 & 0.4300 & −0.0210 & −0.6551 \\
		−0.6115 & −0.7749 & 0.1453 & 0.0662
		\end{array} } \right] $
}

\vspace{0.5em}

Finally, we could find the class by calculating $(H^{-1})^TAH^{-1}$ which gives the following matrix:

\vspace{0.5em}

\centerline {
	$(H^{-1})^TAH^{-1} =  \left[ {\begin{array}{*{20}c}
		-0.0152 & 0 & 0 & 0 \\
		0 & 2.7154 & 0 & 0 \\
		0 & 0 & 3.6361 & 0 \\
		0 & 0 & 0 & 6.6637
		\end{array} } \right] $
}

As we know from our lectures, the result is circular hyperboloid.
\section{Homework 8 - Point Equations}
The task here is to define the pairs of point equations for the direction and pair of plane equations for coordinate planes. As we know that, in $P2$ the lines and points are dual, but in $P3$ two points have 6 degree of freedom which is represented by two 4-vectors. Thus, for a given homogeneous coordinate system in $P3$, we have the following set of point equations that define the axes:

As we have learned from the lecture

\centerline {
	$ax_1 + bx_2 + cx_3 + dx_4 = 0$ gives $(a: b: c: d)$
}

where

\centerline {
	$\pi ^TX = 0$ gives  $(a, b, c, d)^T \left[ {\begin{array}{*{20}c}
		x_1 \\
		x_2 \\
		x_3 \\
		x_4
		\end{array} } \right] = 0$
}

\vspace{0.5em}

\centerline {
	$x = (1, 0, 0, 1)^T$, $y = (0, 1, 0, 1)^T$ and $z = (0, 0, 1, 1)^T$
}

\vspace{0.5em}

and the coordinate planes:

\vspace{0.5em}

\centerline {
	$x - y = (0, 0, 1, 1)^T$, $y - z = (1, 0, 0, 1)^T$ and $x - z = (0, 1, 0, 1)^T$
}

\vspace{0.5em}

Given the equation of the quadric used in the previous exercise:

\vspace{0.5em}

\centerline {
	$X^TAX = 4x_1^2 + 4x_1x_2 - 2x_1x_3 + 2x_1x_4 + 5x_2^2 - 2x_2x_4 + 2x_3^2 + 2x_3x_4 + 2x_4^2$
}

\vspace{0.5em}

which can be rewritten as:

\vspace{0.5em}

\centerline {
	$Q = \left[ {\begin{array}{*{20}c}
		4 & 2 & -1 & 1\\
		2 & 5 & 0 & -1 \\
		-1 & 0 & 2 & 1 \\
		1 & -1 & 1 & 2
		\end{array} } \right]$,
}

\vspace{0.5em}

as well as the following coordinates of a plane:

\vspace{0.5em}

\centerline {
	$\pi = (2, 3, 1, 1)^T$
}

thus giving us the following null space:

\vspace{0.5em}

\centerline {
	$M_ \pi = \left[ {\begin{array}{*{20}c}
		−0.775 & −0.258 & −0.258 \\
		0.604 & -0.132 & -0.132 \\
		-0.132 & 0.956 & -0.044 \\
		-0.132 & -0.044 & 0.956
		\end{array} } \right]$,
}

\vspace{0.5em}

From the relation of  $C = M_ \pi ^TQM_ \pi$, we obtain the relation for the conic:

\vspace{0.5em}

\centerline {
	$C = \left[ {\begin{array}{*{20}c}
		2.617 & 0.717 & −1.437 \\
		0.717 & 2.742 & 1.358 \\
		-1.437 & 1.358 & 1.973
		\end{array} } \right]$,
}

\vspace{0.5em}

thus, the conic is represented as following:

\vspace{0.5em}

\centerline {
	$C = 2.617x_1^2 + 0.358x_1x_2 + 2.742x_2^2 - 0.718x_1x_3 + 0.679x_2x_3 + 1.973x_3^2$
}

\section{Homework 9 - Equation of Conic}

First of all, as we know a quadric is a surface in $P3$ defined by the equation

\vspace{0.5em}

\centerline {
	$X^TQX = 0$
}

\vspace{0.5em}

where $Q$ is a symmetric $4 \times 4$ matrix.

It's also clear that plane $\pi$ can be found as following:

\vspace{0.5em}

\centerline {
	$\pi : ax + by + cz + d = 0$ and $n(x,y,z)^T + d = 0$
}

\vspace{0.5em}

where  $n$ is the normal to the plane computed by $n=(a,b,c)^T$ and $a$, $b$, $c$, $d$ are the points.

The intersection of a plane $\pi$ with a quadric $Q$ is a conic. Computing the conic can be tricky because it requires a coordinate system for the plane. As we know, a coordinate system for the plane can be defined by complement space to $\pi$ as

\centerline {
	$X= Mx$.
}

Points on $\pi$ are on $Q$ if

\vspace{0.5em}

\centerline {
	$X^TQX = x^TM^TQMx = 0$
}

\vspace{0.5em}

These points lie on a conic $C$, since $x^TCx = 0$ with $C = M^TQM$.
\section{Homework 10 - Proof for $cos(\theta)$}

Points on the plane at infinity $(\pi _ \infty)$, which may be written as $X_ \infty = (d^T, 0)^T$ are mapped to the image plane by a general camera $P = CR[I|t]$ as

\vspace{0.5em}

\centerline {
	$x = PX_ \infty = CR[I|t](d^T, 0)^T = CRd$
}

\vspace{0.5em}

Thus, in this case $H = CR$ is the planar homography between $(\pi _ \infty)$ and the image plane. Since the absolute conic $(\Omega _ \infty)$ is on $(\pi _ \infty)$, we can compute its image as

\vspace{0.5em}

\centerline {
	$\omega = (CC^T)^-1 = C^-TC^1$
}

\vspace{0.5em}

We can simply prove this by $\omega = (CR)^{-T} I (CR)^{-1}$ which is lastly equal to $C^{-T}C^{-1}$.

\vspace{0.5em}

Like  $(\Omega _ \infty)$, $\omega$ is an imaginary point conic with no real points. It cannot really be observed in an image. $\omega$ is dependent only on the internal parameters of the camera and is independent of the camera's position or orientation. Thus,
it follows from above that the angle between two rays is given by the simple equation:

\vspace{0.5em}

\centerline {
	$cos \theta = \frac{x_1^T(C^{-T}C^{-1})x_2}{\sqrt{x_1^T(C^{-T}C^{-1})x_x \sqrt{x_2^T(C^{-T}C^{-1})x_2}}} = \frac{x_1^T \omega x_1}{\sqrt{x_1^T \omega x_1} \sqrt{x_2^T \omega x_2}}$
}

\vspace{0.5em}

The above expression is independent of the choice of the projective coordinate on the image. To see this consider any 2D projective transformation $H$. The points $x_i$ are transformed to $Hx_i$, and $\omega$ transforms to $H^-T \omega H^-1$. Hence, the expression for $cos (\theta)$ is unchanged. Thus, it will still be valid for any projective frame.

\section{Homework 11 - Euclidean Rotation}

The idea here is that dual conic here the duality is between planes and points. Thus, $Q_ \infty ^*$ is made by planes tangent to $(\Omega _ \infty)$, therefore any plane that belongs to $Q_ \infty ^*$ envelope is tangent to $\Omega$.

\vspace{0.5em}

\centerline {
	$\pi = \Omega _ \infty X = \pi ^TQ_ \infty ^* = 0$
}

\vspace{0.5em}

\centerline {
	$Q_ \infty ^* = \left[ {\begin{array}{*{20}c}
		I & 0 \\
		0^T & 0
		\end{array} } \right]$,
}

\vspace{0.5em}

When we consider the Euclidean transformation represented by the matrix

\vspace{0.5em}

\centerline {
	$H_E = \left[ {\begin{array}{*{20}c}
		R & 0 \\
		0^T & 1
		\end{array} } \right] =  \left[ {\begin{array}{*{20}c}
		cos \theta & -sin \theta & 0 & 0 \\
		sin \theta & cos \theta  & 0 & 0 \\
		0 & 0 & 1 & 0 \\
		0 & 0 & 0 & 1
		\end{array} } \right] $,
}

\vspace{0.5em}

This is a rotation by $ \theta $ about the z-axis with a zero translation. Geometrically it is evident that the family of XY -planes orthogonal to the rotation axis are simply rotated about the Z -axis by this transformation.

This means that there is a pencil of fixed planes orthogonal to the Z -axis. The planes
are fixed as sets, but not point-wise as any (finite) point (not on the axis) is rotated in horizontal circles by this Euclidean action. Algebraically, the fixed planes of H are the eigenvectors of $H^T$. We also need to mention that fixed planes are eigen-vectors of $H_E^T$ which we need to find it in order to define the planes.

For defining planes, we have to find the eigenvectors of $H_E^T$ by:

\vspace{0.5em}

\centerline {
	$[H_E^T - \lambda I]v = 0 $ which gives $\left[ {\begin{array}{*{20}c}
		cos \theta - \lambda & sin \theta & 0 & 0 \\
		-sin \theta & cos \theta - \lambda & 0 & 0 \\
		0 & 0 & 1 - \lambda & 0 \\
		0 & 0 & 0 & 1 - \lambda
		\end{array} } \right] $
}

\vspace{0.5em}

Thus, we have to find such $\lambda$ that satisfies $det(H_E^T - \lambda I) = 0$

\vspace{0.5em}

Corresponding eigenvectors of $H_E^T$ are

\vspace{0.5em}

\centerline {
	$E_1 = \left( {\begin{array}{*{20}c}
		1 \\
		i \\
		0 \\
		0
		\end{array} } \right)$, $E_2 = \left( {\begin{array}{*{20}c}
		1 \\
		-i \\
		0 \\
		0
		\end{array} } \right)$, 	$E_3 = \left( {\begin{array}{*{20}c}
		0 \\
		0 \\
		1 \\
		0
		\end{array} } \right)$, 	$E_4 = \left( {\begin{array}{*{20}c}
		0 \\
		0 \\
		0 \\
		1
		\end{array} } \right)$
}

\vspace{0.5em}

The eigenvectors $E_3$ and $E_4$ are degenerate. However, $E_1$ and $E_2$ doesn't correspond to real planes. Thus there is a pencil of fixed planes which is spanned by these eigenvectors ($E_3$ and $E_4$). The axis of this pencil is the line of intersection of the the planes (perpendicular to the Z -axis) with $\pi _ \infty$, and the pencil includes $\pi _ \infty$ .

The example also illustrates the connection between the geometry of the projective
plane, $P_2$ , and projective 3-space, $P_3$ . A plane $\pi$ intersects $\pi _ \infty$ in a line which is the line at infinity,  $l_ \infty$ , of the plane $\pi$. A projective transformation of $P3$ induces a subordinate plane projective transformation on $\pi$.

To conclude the ideas, those planes are span of eigen-vectors and they will not be affected because of transformation (not translation, but rotation).

\section{Homework 12 - Camera Centre }

The camera centre $C$ is the point for which $PC = 0$. Numerically, this right null-vector may be obtained from the SVD of $R$. Algebraically, the centre $C = (X, Y,Z,T)^T$, where

\centerline {
	$X=det([p_2, p_3, p_4])$, $Y=-det([p_1, p_3, p_4])$,
}

\centerline {
	$Z=det([p_1, p_2, p_4])$, $T=-det([p_1, p_2, p_3])$
}

and the $P$ is

\centerline {
	$P=[M | -MC] = K[R | -RC ]$
}

We can easily find K nad R by decomposing M as $M = KR$ using the $RQ$ decomposition. The matrix $R$ gives the orientation of camera, whereas $K$ is calibration matrix.

\centerline {
		$K = \left[ {\begin{array}{*{20}c}
		\alpha _x & s & x_0\\
		0 & \alpha _y & y_0 \\
		0 & 0 & 1
		\end{array} } \right]$ and $R|t = \left[ {\begin{array}{*{20}c}
		r_{11} & r_{12} & r_{13} & t_1 \\
		r_{21} & r_{22} & r_{23} & t_2 \\
		r_{31} & r_{32} & r_{33} & t_3
		\end{array} } \right]$
}

For our problem we have $P$ as:

\centerline {
	$P = $
}

Thus, when we decompose the matrix $M$ as $KR$ using QR-decomposition

\centerline {
	$P = [M| -MC]$ the centre $C = -R^Tt$
}

For our problem, $M$ and $MC$ equals

\centerline {
	$M = \left[ {\begin{array}{*{20}c}
		0.6773 & 8.6606 & 7.9236 \\
		-4.2765 & 5.4432 & 7.8011 \\
		-0.91189 & 0.4426 & 10.4433
		\end{array} } \right]$, $MC = \left[ {\begin{array}{*{20}c}
		-2000000.61370 \\
		1000 \\
		30.0518
		\end{array} } \right] $
}

Then, we can compute $C$ by

We get  $C$

\centerline {
	$C = \left[ {\begin{array}{*{20}c}
		27964.6 &  19.410.2 & 1635.09
		\end{array} } \right]^T$
}

b) For this exercise, we needed to find the translation vector which can be calculated as

\centerline {
	$t = -RC$, thus $t =\left[ {\begin{array}{*{20}c}
		31751.7 \\
		19688.7 \\
		-15127.2
		\end{array} } \right] $
}

\section{Homework 13 - Calibration Device }
\subsection{Implement a example of a simple calibration device}

\centerline {
	\includegraphics[scale=0.5]{squares}
}

The idea here is to take the image of three squares and compute the K. For this, we need to take several steps. As we know, for implementing the simple calibration device, we used to follow the steps that showed in the book. Firstly, we need to find the homography H for each square.

Then, we need to compute the imaged circular points for the plane of that square as $H(1, \pm i, 0)^T$.

Before the last step, we need to fit a conic $\omega$ to the six imaged circular points. The constraint that the imaged circular points lie on $\omega$ may be rewritten as two real contrains. If $h_1 \pm ih_2$ lies on $\omega$ then $(h_1 \pm ih_2)^T \omega ()h_1 \pm ih_2) = 0$, and the imaginary and real parts give respectively:

\vspace{0.5em}

\centerline {
	$h_1^T \omega h_2 = 0$ and $h_1^T \omega h_1 = h_2^T \omega h_2$
}

\vspace{0.5em}

which are equations linear in $\omega$.

Finally, we need to compute the calibration $K$ from $\omega = (KK^T)-1$ using the Cholesky factorization.

\vspace{0.4em}

Thus, for the first step, we used OpenCV library in order to get the corners of the squares. The points are as following:

\vspace{0.5em}

\centerline {
		$S_1 =\left[ {\begin{array}{*{20}c}
		77.7704 & 75.5438 & 1.0 \\
		111.0461 & 208.2040 & 1.0  \\
		246.7895 & 165.1987 & 1.0 \\
		243.4158 & 38.8666 & 1.0
		\end{array} } \right] $, $S_2 =\left[ {\begin{array}{*{20}c}
		302.4889 & 42.3844 & 1.0 \\
		301.1318 & 164.1352 & 1.0  \\
		423.8295 & 229.9800 & 1.0 \\
		452.5454 & 100.7878 & 1.0
		\end{array} } \right] $
}

\vspace{0.5em}

and the last square's coordinates are:

\vspace{0.5em}

\centerline {
	$S_3 =\left[ {\begin{array}{*{20}c}
		250.2883 & 197.7703 & 1.0 \\
		174.3199 & 164.1352 & 1.0  \\
		423.8295 & 229.9800 & 1.0 \\
		348.1797 & 362.9188 & 1.0
		\end{array} } \right] $
}

\vspace{0.5em}

Then, we needed to find the homographies, and we have done it also using the library which gave overall three homographies.

\vspace{0.5em}

\centerline {
	$H_1 =\left[ {\begin{array}{*{20}c}
		1.09317181e-03 & 4.96735473e-03 & -4.61466910e-01 \\
		4.28243203e-03 & -1.13379462e-03 & -2.42372406e-01  \\
		-8.34657587e-04 & -1.04738101e-03 & 1.00000000e+00
		\end{array} } \right] $
}

\vspace{0.5em}

\centerline {
	$H_2 =\left[ {\begin{array}{*{20}c}
		-4.38946955e-03 & 1.28792782e-02 & 7.44873229e-01 \\
		1.49341334e-02 & -1.30224096e-04 & -4.48894349e+00  \\
		3.27712794e-03 & -2.49170706e-03 & 1.00000000e+00
		\end{array} } \right] $
}

\vspace{0.5em}

\centerline {
	$H_3 =\left[ {\begin{array}{*{20}c}
		-4.73274525e-03 & 1.87530587e-02 & -2.50705370e+00 \\
		1.22991572e-02 & 8.54371755e-03 & -4.48894349e+00  \\
		2.36397229e-04 & 4.24985472e-03 & 1.00000000e+00
		\end{array} } \right] $
}

\vspace{0.5em}

Then, we had to compute the imaged circular points for the plane of that square as we mentioned above. Writing $H=[h_1, h_2, h_3]$, the imaged circular points are $h_1 +ih_2$ and $h_1 - ih_2$. From those equations, we have got the P matrices.

As the following step, we needed to fit a conic $\omega$ to the six imaged circular points. The constraint that the imaged circular points lie on $\omega$ may be written as two real constraints. Then, we had to find the $\omega$ which we found by A matrix which is found by the columns of $H$ matrix. We have found the $\omega$ as:

\vspace{0.5em}

\centerline {
	$ \omega =\left[ {\begin{array}{*{20}c}
		0.00000000e+00 \\
		7.07106781e-01 \\
		1.11022302e-16 \\
		1.00613962e-16 \\
		-7.07106781e-01 \\
		-5.32072216e-16
		\end{array} } \right] $
}

\vspace{0.5em}

Then, we have divided the $\omega$ with Numpy array into three conics and stored it into the array to find the Cholensky factorization. We have got the new matrix as following:

\vspace{0.5em}

\centerline {
	$ W =\left[ {\begin{array}{*{20}c}
		5.15012402e-01 & 7.07106781e-01 & 1.00613962e-16 \\
		7.07106781e-01 & 1.11022302e-16 & 2.55616781e-01\\
		1.00613962e-16 & 5.42056781e-05 & 3.45077216e-16
		\end{array} } \right] $
}

\vspace{0.5em}

Finally, using the Cholensky factorization (with \textit{np.linalg}), we have computed the $K$ as following:

\vspace{0.5em}

\centerline {
	$ K =\left[ {\begin{array}{*{20}c}
		1046.5 & -9.5 & 505.2 \\
		0 & 1064.2 & 374.4 \\
		0 & 0 & 1
		\end{array} } \right] $
}

\vspace{0.5em}

\subsection{Implement Vanishing Points}

Firstly, vanishing point is the image of a point at infinity. Since parallel lines intersect at infinity, the intersection of parallel lines in the image is the vanishing point. As a result, we can two parallel lines, and find the intersection in the image, and the intersection is one vanishing points. Repeat this process, we can find a second and third vanishing point.

As we have discussed in class, there can be several vanishing in an image, depending on where the images were taken. It's also dependent on how many objects you have in the image. In order to find the vanishing points, you need to have several steps in mind: \\

1. remember that all parallel lines will meet in a vanishing point

2. know which lines in the image are really parallel \\

For example, in the following picture we have found three vanishing points.

\vspace{0.5em}

\centerline {
	\includegraphics[scale=0.4]{vanishing}
}

\section{Homework 14 - Computing the DLT Algorithm}

The task here was to build a reference shape for calibration as a check-board typically checker-board must not be square. One side must contain an even number of squares and the other side must contain an odd number of squares. We need to measure the dimension of the check-board square.

Using the harry corner detector, we first found the corners and added them into our code for further computation. For our example, we have taken overall 8 points as shown in the following matrix where first row shows the $x$ axis and second row shows the $y$ axis. As the checker-board is in 2D we don't care about z-axis. At this stage, we get the matrix as following:

\vspace{0.5em}

\centerline {
	$ x =\left[ {\begin{array}{*{20}c}
		454 & 663 & 238 & 658 & 237 & 25 & 442 & 445 \\
		236 & 442 & 1382 & 623 & 814 & 442 & 1317 & 412 \\
		1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 &
		\end{array} } \right] $
}

\vspace{0.5em}

When we normalize the matrices (by checking them with the ruler as mentioned in class), we get the following results:

\vspace{0.5em}

\centerline {
	$ X =\left[ {\begin{array}{*{20}c}
		6 & 9 & 3 & 9 & 3 & 0 & 6 & 6 \\
		3 & 6 & 18 & 9 & 12 & 6 & 18 & 6 \\
		1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 &
		\end{array} } \right] $
}

\vspace{0.5em}

The next step was to compute the A matrix using the points we have got, but before that we needed to get the correspondences of the coordination points. When, we computed them we also computed the A matrix which had overall 12 columns.

Then, we have tried to compute $H$ by $H=AA^T$, as our A matrix had 12 columns, when we multiply it with it's transpose it will also give the same columns as $A$. After computing the $H$ matrix, we could get the $V$ by using eigen-vectors and after that we could get the $P$ which is the calibration matrix. The following matrix is calibration matrix which is $3 \times 4$:

\vspace{0.5em}

\centerline {
	$ P =\left[ {\begin{array}{*{20}c}
		65.4500 & 7.1226 & -14.6073 & 283.6928 \\
		-15.0209 & 39.2664 & 64.1435 & -1175.6065 \\
		0.0094 & 0.0249 & -0.0506 & 1.7929
		\end{array} } \right] $
}

\vspace{0.5em}

As we know from the $Exercise$ $12$, we could find M (which is the first $3 \times 3$ matrix in P) and then we could get the $R$ and $K$ from the QR-decomposition of $M$. The following matrices are $M$, $R$ accordingly.

\vspace{0.5em}

 \centerline {
 	$ M =\left[ {\begin{array}{*{20}c}
 		65.4500 & 7.1226 & -14.6073  \\
 		-15.0209 & 39.2664 & 64.1435  \\
 		 0.0094 & 0.0249 & -0.0506
 		\end{array} } \right] $, $ R =\left[ {\begin{array}{*{20}c}
 		-0.9746 & -0.2236 & -0.0002  \\
 		0.2236 & -0.9746 & -0.0005  \\
 		-0.0001 & -0.0006 & 0.9999
 		\end{array} } \right] $
 }

\vspace{0.5em}

Finally, we could find the $K$ which is the following matrix:

\vspace{0.5em}

\centerline {
	$ K =\left[ {\begin{array}{*{20}c}
		-67.1516 & 1.84118 & 28.5852  \\
		0.00000 & -39.8647 & -59.2506  \\
		0.00000 & 0.00000 & -0.0839
		\end{array} } \right] $,
}

\vspace{0.5em}

Finally, it was asked to compute the algebraic and geometric errors and then comparing the results obtained by the DLT with the results obtained with the calibration using the absolute conic. In our case error decreased after every iteration and the table is as follows:

\begin{table}[h!]
	\begin{center}
		\label{tab:table1}
		\begin{tabular}{l|c|r}
			$iter$ & $error$ \\
			\hline
			1 & 1.53 \\
			2 & 1.10 \\
			... & ... \\
			8 & 0.35 \\
		\end{tabular}
	\end{center}
\end{table}

\end{document}


% !TeX root = ../thesis.tex
% !TeX spellcheck = en_GB
% !TeX encoding = UTF-8

A forward start option is an option that starts at a specified future date (called the \emph{determination date}), with an expiration date set further in the future\footnote{\url{http://www.math.umn.edu/~spirn/5076/Lecture16.pdf} (Page 5)}. A forward start option starts at a specified date in the future; however, the premium is paid in advance, and the time of expiration is established at the time the forward start option is purchased. Since the asset price at the start of this option is not known a priori, it is common to specify that the strike price will be set in the future so that the option is initially at the money or a certain percentage in the money or out of the money.

The payoff of a forward start call option with time to expiration $ T $ and such that the strike is determined at the money at time $ u $ is given by $ (S_T - S_u)_+ $\footnote{\url{http://www.stat.nus.edu.sg/~stalimtw/MFE5010/PDF/L2forward.pdf}}.

A \emph{cliquet option} or a \emph{ratchet option} is an exotic option consisting of a series of consecutive forward start options. The first such option is active immediately, and once it expires the second comes into existence, and so on. Each option is struck \emph{at-the-money} when it becomes active. Therefore, such an option periodically settles and resets its strike price at the level of the underlying during the time of settlement. Investors can opt to receive their payout either when each option expires or wait until the entire time has elapsed.

Usually, the return on a cliquet option is capped and floored. The capping and flooring may be local or global (or both). The motivation behind bounding the return is to provide the investor safety against downside risks, yet allowing significant upside potential. Consequently, the investor is also constrained from having unbounded gains. Capping the maximum ensures that the payoff is never too extreme and therefore that the value of the contract is not too outrageous. Some variants of cliquet options are as follows:
\begin{description}
	\item[Reverse cliquet] Amounts to a cash flow minus a capped cliquet of puts.
	\item[Digital cliquet] The forward-starting options are digital options.
\end{description}

The following example, copied verbatim from Investopedia\footnote{\url{http://www.investopedia.com/terms/c/cliquet.asp}}, provides a good illustration.
\begin{eg}
	A three-year cliquet option with a strike of 1000 would expire worthless on the first year if the underlying was to be 900. This value (900) would then be the new strike price for the following year and should the underlying on the settlement be 1200, the contract holder would receive a payout and the strike would reset to this new level. Higher volatility provides better conditions for investors to earn profits.
\end{eg}

\paragraph{Literature review}
The literature for pricing of cliquet options is primarily based on partial differential equations (PDE) techniques. Notable mentions include Wilmott's finite difference (FD) approach in a non-linear uncertain volatility model (UVM) in 2002 \cite{Wilmott2002}. Later in 2006, Windcliff et al.\cite{Windcliff2006} explored a variety of modelling alternatives, including jump diffusion models, local volatility and UVM models, again using finite differences methods. They compared the use of a running sum of returns formulation to an average return formulation. Methods for grid construction, interpolation of jump conditions, and application of boundary conditions were also compared.

\paragraph{Lattice method}
Gaudenzi \emph{et al}\cite{Gaudenzi2011} introduced a discrete method for pricing cliquet options in the Cox Ross Rubinstein model \cite{Cox1979} introduced in Chapter \ref{cha:models}. This singular points method is faster than the alternative lattice based approaches available, while retaining a fair bit of flexibility to handle varying volatilities and rates of interest. Most of the chapter is inspired by this paper.

The central idea of the method, as we saw in Chapter \ref{cha:asian}, is to give, at every monitoring date, a continuous representation of the cliquet option price as a piecewise-linear function of the sum of the returns over the corresponding period. This function is characterized only by a set of points, called \emph{singular points}, which can easily be computed recursively by backward induction. Although the number of singular points grows rapidly at every monitoring date, it is possible to reduce their number drastically in a
straightforward way, controlling the error involved by the elimination procedure at the same time. Moreover, the error control process leads automatically to the convergence of the approximations to the continuous value.

\section{Cliquet contracts and models}
\label{sec:clq-models}

Just as in the case of Asian options, we shall assume that the evolution of the prices of the risky asset $ (S_t)_t $ is governed by the Black-Scholes stochastic differential equation as discussed in Equation \ref{eq:continuous-risky-sde-risk-neutral} of Chapter \ref{cha:models}. Its solution is given by Equation \ref{eq:continous-risky}b. Whenever there is a continuous divident yield, we modify the equation according the remark \ref{rem:continuous-dividend}. Moreover, we shall consider the discrete model setup exactly as described in the beginning of Section \ref{sec:asian-binom} of Chapter \ref{cha:asian}.

Let $T$ be the maturity of the cliquet contract. Let the payoffs depend on the $ N $ preordained observation times $ t_1, t_2, \dots, t_{N} $ ($ t_0 = 0 $). At these observation times, the value of the underlying are $ ( S_i )_i, S_i = S_{t_i}, i \in \left[ N \right] $. The returns for the time interval $ ( t_{i-1}, t_i ] $ are given by
\begin{equation}
	\label{eq:clq-return}
	R_i = \frac{S_i - S_{i-1}}{S_{i-1}} = \frac{S_i}{S_{i-1}} - 1 \ .
\end{equation}

During each time interval, the return is capped and floored locally by the quantities $ C_{loc} $ and $ F_{loc} $. In other words, we consider the quantity $ \max \{ F_{loc}, \min \{ C_{loc}, R_i \} \} $ rather than the return itself. The sum of these quantities till time $t_i$ is called the `running sum' and is given by
\begin{equation}
	\label{eq:clq-rsz}
	Z_i = \sum_{k = 1}^{i} \max \{ F_{loc}, \min \{ C_{loc}, R_k \} \}.
\end{equation}

We also consider a global cap $ C_{glob} $ and floor $ F_{glob} $. Thus, the expression for the payoff finally becomes
\begin{equation}
	\label{eq:clq-payoff}
	\mathrm{payoff} = \mathrm{notional} \cdot \max \{ F_{glob}, \min \{ C_{glob}, Z_{N} \} \}.
\end{equation}

For ease of notation, we take $ \mathrm{notional} = 1 $.

We note that the case $ C_{glob} > N C_{loc} $ is equivalent to $ C_{glob} = N C_{loc} $. Similarly, the case $ F_{glob} < N F_{loc} $ is equivalent to $ F_{glob} = N F_{loc} $. In general, we may write the following.
\begin{subequations}
	\label{eq:clq-update-glob}
	\begin{align*}
		F_{glob} &= \max \{ N F_{loc}, F_{glob} \}  \\
		C_{glob} &= \min \{ N C_{loc}, C_{glob} \}
	\end{align*}
\end{subequations}

We assume that the difference between two observation times is constant and we denote by $m$ the number of steps of the binomial tree in every period (so that the total number of steps of the binomial tree is $ n = m N $).

\section{The singular points method for cliquet options}
\label{sec:clq-sp}

The binomial method may always be used to price any option, including path-dependent ones. The binomial method looks through all possible paths of the underlying in order to price the option. The number of possible paths are $ 2 ^ {m N} $. Thus, the method is inherently extremely computationally expensive due to the exponential dependence of the number of paths on $m$ and $ N $. The theoretical computational complexity is $ O( m^{N} ) $, as in \cite[Page 128]{Gaudenzi2011}.

A modification of the singular points method described in the previous chapter solves this problem for cliquet options by the process of approximation. The method of approximation selectively removes certain paths that would be normally considered, but which do not affect the result in a significant manner. This may be done by putting an \emph{a priori} error bound while removing points. The method turns out to be significantly faster and memory efficient compared to known binomial techniques. Moreover, its flexible is evinced by the fact that it is adaptable for varying interest rate and volatility in each observational period.

The price function in the cliquet case is not necessarily convex due to the presence of a global cap (see Figure \ref{fig:clq-maturity}), as opposed to the Asian case. Since the algorithm starts from maturity, it follows that we cannot assume convexity at any point of time. It was primarily the convexity of the price functions in the Asian case that allowed us to obtain simple upper and lower bounds of the exact binomial price. Nevertheless, in the case of cliquet options, the singular points approach still provides an efficient binomial framework, even in the absence of convexity of the price functions, as we shall see.

We redefine singular points to exclude the constraint of convexity. The reader is advised to keep in mind the ideas introduced in Section \ref{subsec:asian-notations} of Chapter \ref{cha:asian}.

\begin{dfn}[singular points and singular values]
	\label{def:clq-sp}
	Let $ P = (P_i)_{i \in [n]} = ( (x_i, y_i) )_{i \in [n]} $, $ n \in \mathbb{N} $ be a sequence of points such that $ a = x_0 < x_1 < \dots < x_{n-1} < x_n = b \  \forall i \in [n] $.

	Let $ f:[a,b] \to [0, \infty) $ be the function obtained by linear interpolation of the points in $P$. The definition of $f$ ensures that the function is continuous and piecewise-linear.

	Then, the elements of $P$ are called \emph{singular points of $f$} and the abscissae $ \{ x_i \}_{i \in [n]} $ are called \emph{singular values of $f$}.
\end{dfn}

\begin{rem}[characterisation]
	\label{rem:clq-char}
	Note that the singular points characterise such a function completely, even without the requirement of convexity. This is clear from \ref{rem:asian-char}.
\end{rem}

\subsection{The method}
\label{subsec:clq-method}

Our aim is to look at every possible value taken by the running sum $Z$ within the bounds $ [ F_{loc}, C_{loc} ] $ for each time interval $ t_1, \dots, t_{N} $. If we know the price function at maturity, we may use a backward procedure (in time) in order to obtain a continuous representation of the cliquet price as a piecewise-linear function of the running sum $Z$. Since it is piecewise-linear and continuous, the function may be represented using its singular points. Thus, we see an evolution of singular points as we go back in time. Since the number of singular points may be significantly high for any computer, we shall introduce an error controlled approximation procedure to reduce the number of singular points.

Let the number of singular points at each observational time $ t_i $ be $ L_{i} $, where $ i \in \{ 1, \dots, N \} $. For each singular point $ l \in \{ 1, \dots, L_i \} $, the abscissa is called the \emph{singular running sum} $ Z_i^l $ and the ordinate is called the \emph{singular price} $ P_i^l $. Thus, the singular points are denoted by
\begin{equation*}
	( Z_i^l, P_i^l ) \qquad \forall l \in \{ 1, \dots, L_i \}
\end{equation*}

\paragraph{At maturity}
At maturity ($ t_{N{obs}} = T $), for every running sum $Z$, the price of the cliquet option $ V_{N}(Z) $ as function of $Z$, is given by
\begin{equation}
	\label{eq:clq-vnobs-maturity}
	V_{N}(Z) = \max \{ Fglob, \min\{ Cglob, Z \} \}
\end{equation}

We note the following.
\begin{enumerate}
	\item $ V_{N}(Z) $ is a continuous and piecewise-linear function
	\item $ V_{N}(Z) $ is defined in the interval $ [ N F_{loc}, N C_{loc} ] $
	\item There are only four points where the function changes slope, namely $ N F_{loc} $, $ F_{glob} $, $ C_{glob} $ and $ N C_{loc} $. This is because if $ Z < F_{glob} $, the price is constant. Same can be said about $ Z > C_{glob} $. Thus the four numbers enumerated above form the complete set of singular running sums at maturity ($ L_N = 4 $).
\end{enumerate}

Focusing further on point 3 above, we note down the singular running sums and corresponding prices.
\begin{table}[h]
	\centering
	\caption{Singular points at maturity}
	\label{tab:clq-maturity}
	\begin{tabular}{ccc}
		\toprule
		$l$  &  $ Z_{N}^l $  &  $ P_{N}^l $ \\
		\midrule
		1  &  $ N F_{loc} $  &  $ F_{glob} $ \\
		2  &  $ F_{glob} $  &  $ F_{glob} $ \\
		3  &  $ C_{glob} $  &  $ C_{glob} $ \\
		4  &  $ N C_{loc} $  &  $ C_{glob} $ \\
		\bottomrule
	\end{tabular}
\end{table}

A more visual representation of the price function at maturity is given in Figure \ref{fig:clq-maturity}.
\begin{figure}[h]
	\centering

	\definecolor{cqcqcq}{rgb}{0.7529411764705882,0.7529411764705882,0.7529411764705882}
	\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1.}
	\definecolor{qqqqff}{rgb}{0.,0.,1.}
	\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
	\draw[->,color=black] (0.,0.) -- (9.,0.);
	\foreach \x in {,1.,2.,3.,4.,5.,6.,7.,8.}
	\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
	\draw[color=black] (8.77813297657717,0.054247335995569544) node [anchor=south west] { Z};
	\draw[->,color=black] (0.,0.) -- (0.,5.);
	\foreach \y in {,1.,2.,3.,4.}
	\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
	\draw[color=black] (0.06780919373316127,4.698691618151926) node [anchor=west] { P};
	\clip(-0.5,-0.5) rectangle (9.,5.);
	\draw [line width=1.2pt] (1.,1.)-- (2.,1.);
	\draw [line width=1.2pt] (2.,1.)-- (7.,4.);
	\draw [line width=1.2pt] (7.,4.)-- (8.,4.);
	\draw [line width=0.4pt,color=cqcqcq] (1.,1.)-- (1.,0.);
	\draw [line width=0.4pt,color=cqcqcq] (2.,1.)-- (2.,0.);
	\draw [line width=0.4pt,color=cqcqcq] (7.,4.)-- (7.,0.);
	\draw [line width=0.4pt,color=cqcqcq] (8.,4.)-- (8.,0.);
	\draw [line width=0.4pt,color=cqcqcq] (1.,1.)-- (0.,1.);
	\draw [line width=0.4pt,color=cqcqcq] (7.,4.)-- (0.,4.);
	\begin{scriptsize}
	\draw [fill=qqqqff] (1.,1.) circle (1.5pt);
	\draw[color=qqqqff] (0.9258283422770954,1.3896041224221845) node {$S_1$};
	\draw [fill=qqqqff] (2.,1.) circle (1.5pt);
	\draw[color=qqqqff] (1.7666623445682952,1.3896041224221845) node {$S_2$};
	\draw [fill=qqqqff] (7.,4.) circle (1.5pt);
	\draw[color=qqqqff] (7.204959681967829,3.5594975622449665) node {$S_3$};
	\draw [fill=qqqqff] (8.,4.) circle (1.5pt);
	\draw[color=qqqqff] (8.181412071725351,3.6001830642416435) node {$S_4$};
	\draw [fill=xdxdff] (1.,0.) circle (1.5pt);
	\draw[color=xdxdff] (0.5732205348646567,-0.31918696143825614) node {$F_{loc} N$};
	\draw [fill=xdxdff] (2.,0.) circle (1.5pt);
	\draw[color=xdxdff] (2.254888539447056,-0.31918696143825614) node {$F_{glob}$};
	\draw [fill=xdxdff] (7.,0.) circle (1.5pt);
	\draw[color=xdxdff] (6.526867744636216,-0.31918696143825614) node {$C_{glob}$};
	\draw [fill=xdxdff] (8.,0.) circle (1.5pt);
	\draw[color=xdxdff] (8.452648846657995,-0.3463106294360409) node {$C_{loc} N$};
	\draw [fill=xdxdff] (0.,1.) circle (1.5pt);
	\draw[color=xdxdff] (-0.050624047480426926,0.73863609047535) node {$F_{glob}$};
	\draw [fill=xdxdff] (0.,4.) circle (1.5pt);
	\draw[color=xdxdff] (-0.07774772497369145,3.7358014042305676) node {$C_{glob}$};
	\end{scriptsize}
	\end{tikzpicture}

	\caption{The price function at maturity}
	\label{fig:clq-maturity}
\end{figure}

\paragraph{The penultimate time step}

We consider the time step $ N - 1 $. If the running sum at time $ t_{N - 1} $ is denoted by $ Z $, then the corresponding price depends on the possible returns of the underlying asset during the time interval $ [ t_{N - 1}, T ] $.

We revisit equation \ref{eq:clq-return} once more. Now we note that since the number of time steps in each interval is $m$, there will be $m$ up movements or down movements of the asset. Thus, there are $ m + 1 $ possible outcomes, given by $ S_i = u^{-m + 2j} S_{i-1}, j \in [m] $. Corresponding to these cases, there are also $ m + 1 $ returns, given by
\begin{equation}
	\label{eq:clq-return-final}
	R_j = u^{-m + 2j} - 1 \qquad j \in [m]
\end{equation}

Since the probability of an up movement in time $ \Delta T $ is $p$, we have that the probability of each return is distributed binomially, and is given by
\begin{equation}
	\label{eq:clq-prb-binom}
	p_j = \binom{m}{j} p^j (1-p)^{m-j}
\end{equation}

The above derivations assume that there has been no local flooring or capping of the returns. In the case of such bounds, the actual possibilities are fewer in number, and we need to put bounds on $j$. We can do this in the following fashion.

In the case of a local floor, we must have
\begin{alignat*}{9}
	                 &&  F_{loc}  \quad & \ge \quad  u^{ -m + 2 j_{\min} } - 1 && \\
	\implies  \qquad &&  \log(F_{loc} + 1)  \quad & \ge \quad  ( -m + 2 j_{\min} ) \log(u)  &&  \qquad \qquad \dots (\log \text{is monotonic}) \\
	\implies  \qquad &&  \frac{\log(F_{loc} + 1)}{\log(u)}  \quad & \ge \quad  ( -m + 2 j_{\min} )  &&  \qquad \qquad \dots (u > 1 \implies \log(u) > 0) \\
	\implies  \qquad &&  j_{\min}  \quad & \le \quad  \frac{ \log(F_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2}  &&  \qquad \qquad \dots (u = e^{ \sigma \Delta T }) \\
	\implies  \qquad &&  j_{\min}  \quad & = \quad  \floor{ \frac{ \log(F_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2} }  &&  \qquad \qquad \dots (j \in [m]) \\
\end{alignat*}
Where $ \floor{\cdot} $ denotes the floor function.

Similarly, in the case of local cap, we have
\begin{alignat*}{9}
	                 &&  C_{loc}  \quad & \le \quad  u^{ -m + 2 j_{\max} } - 1 && \\
	\implies \qquad  &&  \log(C_{loc} + 1)  \quad & \le \quad  ( -m + 2 j_{\max} ) \log(u)  &&  \qquad \qquad \dots (\log \text{is monotonic}) \\
	\implies \qquad  &&  \frac{\log(C_{loc} + 1)}{\log(u)}  \quad & \le \quad  ( -m + 2 j_{\max} )  &&  \qquad \qquad \dots (u > 1 \implies \log(u) > 0) \\
	\implies \qquad  &&  j_{\max}  \quad & \ge \quad  \frac{ \log(C_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2}  &&  \qquad \qquad \dots (u = e^{ \sigma \Delta T }) \\
	\implies \qquad  &&  j_{\max}  \quad & = \quad  \ceil{ \frac{ \log(C_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2} }  &&  \qquad \qquad \dots (j \in [m]) \\
\end{alignat*}
Where $ \ceil{\cdot} $ denotes the ceiling function.

We represent by $ j_0 $ the number of possibilities of the return after enforcing the local floor and cap. Summarising
\begin{subequations}
	\label{eq:clq-j-mix-max}
	\begin{align}
		j_{\min} &= \floor{ \frac{ \log(F_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2} }  \\
		j_{\max} &= \ceil { \frac{ \log(C_{loc} + 1) }{ 2 \sigma \Delta T } + \frac{m}{2} }  \\
		j_0 &= j_{\max} - j_{\min}
	\end{align}
\end{subequations}

$ \forall j \le j_{\min} $, the return is $ F_{loc} $, and $ \forall j \ge j_{\max} $, the return is $ C_{loc} $. For the other indices, the return remains unchanged.

We shift the indices from $ \{ j_{\min}, \dots, j_{\max} \} $ to $ \{ 0, \dots, j_0 \} $ by putting $ j' = j - j_{\min} $. Table \ref{tab:clq-shift} highlights the shifted indices, and the corresponding returns and probabilities.
\begin{table}[h]
	\centering
	\caption{Shifted returns and probabilities}
	\label{tab:clq-shift}
	\begin{tabular}{cccc}
		\toprule
		Range$(j)$  &  $ j' $  &  $ R_j' $  &  $ p_j' $  \\
		\midrule
		$ j \le j_{\min} $  &  $ 0 $  &  $ F_{loc} $  &  $ \sum_{k=0}^{j_{\min}} p_k $  \\
		$ \{ j_{\min} + 1, \dots, j_{\max} - 1 \} $  &  $ j - j_{\min} $ &  $ R_{j + j_{\min}} $  &  $ p_{j + j_{\min}} $  \\
		$ j \ge j_{\max} $  &  $ j_0 $  &  $ C_{loc} $  &  $ \sum_{k=j_{\max}}^{m} p_k $  \\
		\bottomrule
	\end{tabular}
\end{table}

\begin{rem}[shifted indices]
	\label{rem:clq-shift}
	Note that the $ j' $s represents the indices of the possible paths that can \emph{actually} be taken respecting the constraints of the local floor and cap, whereas $ j $ represents the indices of all possible paths without respect to any constraints. Thus, we are more interested in the shifted indices. Similarly, $ p_j' $ represents the probability of taking the path $ j' $, and $ R_j' $ represents the corresponding return.
\end{rem}

Now we focus on how to determine the price function at time $ t_{N - 1} $. Recall that at maturity, the function $ V_{N}(Z) $ giving the price of the cliquet option as a function of the running sum $ Z $ at maturity, is the piecewise linear function whose singular points are presented in Table \ref{tab:clq-maturity}. At the penultimate time step $ t_{N - 1} $, we must have $ Z \in [ (N-1) F_{loc}, (N-1) C_{loc} ] $. Note that $ Z $ is the running sum till the penultimate time step. The price function at this time is given as a discounted conditional expectation of the price function at maturity given the information at penultimate time. Thus
\begin{equation}
	\label{eq:clq-penultimate}
	V_{N-1} (Z) = e^{- m \Delta T} \sum_{j=0}^{j_0} \left[ p_j' V_{N} (Z + R_j') \right] ,
\end{equation}
where $ p_j' $ and $ R_j' $ are given in Table \ref{tab:clq-shift}.

Since $ V_{N} $ is piecewise-linear and continuous, and the above is just a linear combination of such functions, the resulting function is also piecewise-linear and continuous, and thus may be completely represented by singular points. The next logical step is of course to figure out a method to compute these singular points.

From equation \ref{eq:clq-penultimate}, we note that each singular point $ l $ at maturity may have $ j_0 + 1 $ possible returns, given by
\begin{equation}
	\label{eq:clq-b}
	B_{l,j} = Z_N^l - R_j' \qquad j \in [j_0]
\end{equation}

Then the maximum number of singular points at time $ t_{N-1} $ is $ ( j_0 + 1 ) L_N $. But not all the running sums at time $ t_{N-1} $ would belong to the interval $ [ (N-1) F_{loc}, (N-1) C_{loc} $. All the $ B_{l,j} $ which belong to the interval become the abscissa of a singular point at time $ t_{N-1} $. The corresponding singular price is determined by formula \ref{eq:clq-penultimate}. The term $ V_{N} (B_{l,j} + R_k') $, required by the formula, is computed using linearity of the price function at maturity. We just need to figure out the interval $ l_0 $ such that $ ( B_{l,j} + R_k' ) \in [ Z_N^{l_0}, Z_N^{l_0 + 1} ] $, and evaluate $ V_{N} (B_{l,j} + R_k') $ by linear interpolation of the extrema. Such an interpolation gives not an approximation by the exact value due to the piecewise-linear nature of the original function.

Finally, the singular points thus obtained are sorted in ascending order on the basis of the running sums. This ordered sequence of singular points $ ( ( Z_{N-1}^l, P_{N-1}^l ) )_l , l \in \{ 1, \dots, L_{N-1} \} $ completely characterises the price function at time $ V_{N-1}(Z) $.

\paragraph{At all times}
The previous argument may be applied iteratively in a backward fashion at each step $ N-2, N-3, \dots, 1, 0 $ to obtain the singular points at each time step. At time 0, there is only one singular point $ (0, P_0^1) $, and $ P_0^1 $ provides the exact binomial price of the cliquet option. The equality of this price and the exact binomial price is proved in Proposition \ref{thm:clq-equality}.

\begin{prp}[The singular points method gives the binomial price]
	\label{thm:clq-equality}
	$ P_0^l $ coincides with the exact binomial price with $ n $ time steps of the cliquet option.
\end{prp}

\begin{proof}
	Let the running sum $ Z_{i_1, \dots, i_k} = \sum_{j=1}^{k} R_{i_j}', \  (i_1, \dots, i_k) \in [j_0]^k, k \in \{ 1, \dots, N \} $, and associate them to the prices $ P_{i_1, \dots, i_k} $.
	Then the exact binomial price $ Q_n $ of the cliquet option is given by
	\begin{equation*}
		Q_n = e^{-rT} \sum_{i_1, \dots, i_N = 0}^{j_0} \left( p_{i_1}' \cdot \dots \cdot p_{i_N}' \max \left\{ F_{glob}, \min \left\{ C_{glob}, Z_{i_1, \dots, i_N} \right\} \right\} \right) ,
	\end{equation*}
	where $ p_{i_k}' $ is the probability of actually taking the path $ i_k $ at the time interval $ k $. This expression can be computed backward.

	At maturity, set $ P_{i_1, \dots, i_N} = \max \left\{ F_{glob}, \min \left\{ C_{glob}, Z_{i_1, \dots, i_N} \right\} \right\} $.

	Along the tree the prices $ P_{i_1, \dots, i_k}, k \in [N-1] $, are evaluated by the
	backward formula
	\begin{equation*}
		P_{i_1, \dots, i_k}  =  e^{-r \frac{T}{N}}  \sum_{j=0}^{j_0} p_j' P_{i_1, \dots, i_k, j}
	\end{equation*}

	Finally, we get $ Q_n = e^{-r \frac{T}{N}}  \sum_{j=0}^{j_0} p_j' P_j $.

	We now prove the result by backward induction. At maturity, for every choice of the running sum $ Z = Z_{i_1, \dots, i_N} $, the price $ P_{i_1, \dots, i_N} $ coincides with the value of the option $ v_N(Z) $. By construction (Equation \ref{eq:clq-penultimate}), this holds true
	also for every running sum evaluated at step $ N - 1 $, and iteratively, at all the nodes
	of the tree. Thus, the price $ Q_n $ coincides with the price $ P_0^1 $ determined by the singular points algorithm.
\end{proof}

\begin{rem}[Generalisation]
	The method is easily generalised to cases with (discrete) time-varying interest rates and volatilities. In other words, for each \emph{observed} time interval $ [t_{i-1}, t_{i}] $ denoted by $ i \in \{1, 2, \dots, N \} $, we can take different values of $ r_i, \sigma_i $. The technique requires modification only for the computation of the probabilities $ p' $ and the returns $ R' $ which have to be evaluated at every observation time by using the corresponding $ r_i $ and $ \sigma_i $.

	In fact, we may even take varying local floors and caps, denoted $ F_i^{loc}, C_i^{loc} $. In this case, we also have to compute $ j_{\min}, j_{\max}, j_0 $ for each period individually.
\end{rem}

\begin{rem}[Computational dependence on volatility]
	The time of computation of the pure binomial method for cliquet options is strongly dependent on the volatility. In fact the total number of paths needed to determine the price is $ m^N $. Because of the presence of the global cap and floor, the number of paths can be reduced to $ ( j_0 + 1 ) N $, where $ j_0 = j_{\max} - j_{\min} $. But $ j_0 $ is strictly dependent on $ \sigma $ (see Equation \ref{eq:clq-j-mix-max}) and the difference in the computational time between large and small volatilities becomes very high (see also Table \ref{tab:clq-results}).
\end{rem}

\subsection{Approximation}
\label{subsec:clq-approx}

The method demonstrated in Section \ref{subsec:clq-method} gives us the actual binomial price of the cliquet option. But as was mentioned earlier, the computational complexity of the method is theoretically the same as that of the binomial method, which is $ m^N $. But contrary to the binomial method, the singular point method enables us to use precise, efficient and controlled approximation to accelerate the procedure significantly. Thus its efficacy become apparent when we have time and memory constraints, or we wish to substantially increase the number of intermediate time steps.

The prime idea of the approximation procedure is to remove singular points in a controlled manner in order to simplify the computations. To this end, we fix a given maximal level $ h > 0 $ of the error in each period. Now, we eliminate singular points in a fashion so that the function after deletion of the points ($ \tilde{V}_i $) is different from the original function by less than ($ h $) at each point. This may be achieved as follows.

Start with the point $ ( Z_i^1, P_i^1 ) $. Find the largest index $ l > 1 $ such that the distances between the straight line joining $ ( Z_i^1, P_i^1 ) $ and $ ( Z_i^l, P_i^l ) $ and the points $ ( Z_i^2, P_i^2 ), ( Z_i^3, P_i^3 ), \dots, ( Z_i^{l-1}, P_i^{l-1} ) $ are always less than $ h $. Note that this, coupled with the fact that the original function is piecewise-linear, ensures that the differences in the values of the functions for any value of the running sum would be bounded over by $ h $. Now delete the points $ ( Z_i^2, P_i^2 ), ( Z_i^3, P_i^3 ), \dots, ( Z_i^{l-1}, P_i^{l-1} ) $. The point $ ( Z_i^l, P_i^l ) $ now becomes the second singular point, and we continue the procedure iteratively starting with this point till we cover all the points. Figure \ref{fig:clq-approx} elaborates on this graphically. The elimination of points $ S_3 $ to $ S_6 $ gives function $ V_1 $ (bold, blue), which has maximum error $ \le h $. Elimination of points $ S_3 $ to $ S_7 $ gives function $ V_2 $ (dashed, red), which has maximum error $ > h $. Thus we choose $ V_1 $ as the approximation function.

Since at each $ N $ the upper bound for the error is $ h $, if we repeat the approximation procedure at every observational time, the total error infused in the price of the option is bounded by $ Nh $.

\begin{figure}[h]
	\centering

	\definecolor{ffqqqq}{rgb}{1.,0.,0.}
	\definecolor{cqcqcq}{rgb}{0.7529411764705882,0.7529411764705882,0.7529411764705882}
	\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1.}
	\definecolor{qqqqff}{rgb}{0.,0.,1.}
	\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
	\draw[->,color=black] (0.,0.) -- (12.,0.);
	\foreach \x in {,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.}
	\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
	\draw[color=black] (11.72949725895975,0.0665249798016828) node [anchor=south west] { Z};
	\draw[->,color=black] (0.,0.) -- (0.,8.);
	\foreach \y in {,1.,2.,3.,4.,5.,6.,7.}
	\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
	\draw[color=black] (0.08315626418944566,7.641135707448683) node [anchor=west] { P};
	\clip(-0.5,-0.5) rectangle (12.,8.);
	\draw [line width=2.pt,color=qqqqff] (1.,1.)-- (2.,1.);
	\draw [line width=1.2pt] (2.,1.)-- (3.,1.75);
	\draw [line width=1.2pt] (3.,1.75)-- (4.,2.);
	\draw [color=cqcqcq] (1.,1.)-- (1.,0.);
	\draw [color=cqcqcq] (2.,1.)-- (2.,0.);
	\draw [color=cqcqcq] (3.,1.75)-- (3.,0.);
	\draw [color=cqcqcq] (4.,2.)-- (4.,0.);
	\draw [color=cqcqcq] (1.,1.)-- (0.,1.);
	\draw [line width=1.2pt] (4.,2.)-- (6.,2.75);
	\draw [line width=1.2pt] (8.,4.)-- (9.,5.);
	\draw [line width=2.pt,color=qqqqff] (9.,5.)-- (10.,7.);
	\draw [color=cqcqcq] (6.,2.75)-- (6.,0.);
	\draw [color=cqcqcq] (9.,5.)-- (9.,0.);
	\draw [color=cqcqcq] (11.,7.)-- (11.,0.);
	\draw [line width=1.2pt] (6.,2.75)-- (8.,4.);
	\draw [color=cqcqcq] (8.,4.)-- (8.,0.);
	\draw [color=cqcqcq] (10.,7.)-- (10.,0.);
	\draw [line width=2.pt,color=qqqqff] (10.,7.)-- (11.,7.);
	\draw [line width=2.pt,color=qqqqff] (2.,1.)-- (9.,5.);
	\draw [line width=1.2pt,dash pattern=on 4pt off 4pt,color=ffqqqq] (2.,1.)-- (10.,7.);
	\draw [line width=1.6pt,dotted,color=qqqqff] (6.004094596374262,3.288054055071007)-- (6.,2.75);
	\draw [color=cqcqcq] (10.,7.)-- (0.,7.);
	\draw [line width=1.6pt,dotted,color=ffqqqq] (7.999695997451529,5.499771998088647)-- (8.,4.);
	\begin{scriptsize}
	\draw [fill=qqqqff] (1.,1.) circle (1.5pt);
	\draw[color=qqqqff] (0.9857079256833694,1.3545251161896577) node {$S_1$};
	\draw [fill=qqqqff] (2.,1.) circle (1.5pt);
	\draw[color=qqqqff] (1.8339018204157151,1.40441885104092) node {$S_2$};
	\draw [fill=qqqqff] (3.,1.75) circle (1.5pt);
	\draw[color=qqqqff] (2.9149332548785085,2.0530374041073274) node {$S_3$};
	\draw [fill=qqqqff] (4.,2.) circle (1.5pt);
	\draw[color=qqqqff] (4.21217097623386,1.8201999748014375) node {$S_4$};
	\draw [fill=xdxdff] (1.,0.) circle (1.5pt);
	\draw[color=xdxdff] (0.9191829143318129,-0.3917556036045157) node {$Z_1$};
	\draw [fill=xdxdff] (2.,0.) circle (1.5pt);
	\draw[color=xdxdff] (1.950320590280939,-0.35849311370367437) node {$Z_2$};
	\draw [fill=xdxdff] (3.,0.) circle (1.5pt);
	\draw[color=xdxdff] (2.948195760554287,-0.35849311370367437) node {$Z_3$};
	\draw [fill=xdxdff] (4.,0.) circle (1.5pt);
	\draw[color=xdxdff] (3.9294396779897456,-0.3917556036045157) node {$Z_4$};
	\draw [fill=xdxdff] (0.,1.) circle (1.5pt);
	\draw[color=xdxdff] (0.05435776676157797,0.8888502575778783) node {$F_{glob}$};
	\draw [fill=xdxdff] (0.,7.) circle (1.5pt);
	\draw[color=xdxdff] (0.021095261085799705,6.8262047048780685) node {$C_{glob}$};
	\draw [fill=qqqqff] (6.,2.75) circle (1.5pt);
	\draw[color=qqqqff] (6.1413963054290015,2.5519747526199485) node {$S_5$};
	\draw [fill=qqqqff] (8.,4.) circle (1.5pt);
	\draw[color=qqqqff] (8.153777898813587,3.8159493688519217) node {$S_6$};
	\draw [fill=qqqqff] (9.,5.) circle (1.5pt);
	\draw[color=qqqqff] (9.201546827600602,4.847086555778005) node {$S_7$};
	\draw [fill=qqqqff] (10.,7.) circle (1.5pt);
	\draw[color=qqqqff] (10.16615949219817,6.809573459927647) node {$S_8$};
	\draw [fill=qqqqff] (11.,7.) circle (1.5pt);
	\draw[color=qqqqff] (11.197297168147298,6.792942214977227) node {$S_9$};
	\draw [fill=xdxdff] (6.,0.) circle (1.5pt);
	\draw[color=xdxdff] (5.95845252421222,-0.3418618687532536) node {$Z_5$};
	\draw [fill=xdxdff] (8.,0.) circle (1.5pt);
	\draw[color=xdxdff] (7.954202864758916,-0.35849311370367437) node {$Z_6$};
	\draw [fill=xdxdff] (9.,0.) circle (1.5pt);
	\draw[color=xdxdff] (8.952078035032265,-0.37512435865409505) node {$Z_7$};
	\draw [fill=xdxdff] (11.,0.) circle (1.5pt);
	\draw[color=xdxdff] (10.897934617065292,-0.37512435865409505) node {$Z_9$};
	\draw [fill=xdxdff] (10.,0.) circle (1.5pt);
	\draw[color=xdxdff] (9.933321952467724,-0.35849311370367437) node {$Z_8$};
	\draw[color=qqqqff] (6.607071384889897,3.849211858752763) node {$V_1$};
	\draw[color=ffqqqq] (5.675721225968106,3.9822618183561285) node {$V_2$};
	\draw [color=qqqqff] (6.004094596374262,3.288054055071007)-- ++(-1.5pt,-1.5pt) -- ++(3.0pt,3.0pt) ++(-3.0pt,0) -- ++(3.0pt,-3.0pt);
	\draw[color=qqqqff] (6.340971339483671,3.0841745910334106) node {$\le$ h};
	\draw [color=ffqqqq] (7.999695997451529,5.499771998088647)-- ++(-1.5pt,-1.5pt) -- ++(3.0pt,3.0pt) ++(-3.0pt,0) -- ++(3.0pt,-3.0pt);
	\draw[color=ffqqqq] (8.30345917435459,4.847086555778005) node {>h};
	\end{scriptsize}
	\end{tikzpicture}

	\caption{Approximation procedure}
	\label{fig:clq-approx}
\end{figure}

\begin{rem}[Comparison with Asian options]
	While using approximations for Asian options, the error bound was $ nh $, where $ n $ was the number of time steps considered for computation (refer to Section \ref{sec:asian-approx} of Chapter \ref{cha:asian}). But in the case of the cliquet options, the error depends only on the $ h $ and the number of observations - precluding any dependence on the computational parameters. This technique gives a precise approximation of the price without considering upper and lower estimates.
\end{rem}

The following proposition proves that the approximation of the price obtained by this method does converge to the price of the cliquet option in the continuous model. The proposition and proof is directly from .

\begin{prp}[Convergence to the continuous model]
	\label{thm:convergence-continuous}
	Let us denote by $ Q_n^h $ the approximation of the price evaluated with $ n $ time steps and with maximal level of error at every monitoring date $ h = h(n) $. If $ h(n) \to 0 $ as $ n \to \infty $, then $ Q_n^{h(n)} $ converges to the price of the cliquet option in the continuous model.
\end{prp}

We skip the proof of the proposition since it is not the main focus of our exposition. The proof is mathematically delicate, and needs a general result on the weak convergence of stochastic processes. This is a generalisation of what we saw in Section \ref{subsec:discrete-to-continuous} of Chapter \ref{cha:models}. The result may be found in \cite{kushner1984approximation} and \cite{Kushner:1992:NMS:151172}, and we refer the interested reader to \cite[Proposition 2]{Gaudenzi2011} for a rigorous proof.

\clearpage
\section{The program}
\label{sec:clq-program}

\subsection{Algorithm}

\begin{algorithm}[H]
	\DontPrintSemicolon

	\KwIn{\\
		\qquad \emph{Contract details}  \\
		\qquad \quad time to maturity: $ T $ \\
		\qquad \quad number of observations: $ N $ \\
		\qquad \quad local floor and cap: $ F_{loc}, C_{loc} $  \\
		\qquad \quad global floor and cap: $ F_{glob}, C_{glob} $ \\

		\qquad \emph{Details of the underlying asset}  \\
		\qquad \quad initial price: $ s_0 $, volatility: $ \sigma $, continuous dividend rate: $ q $  \\

		\qquad \emph{Market parameters} -- spot interest rate: $ r $ \\

		\qquad \emph{Computational parameters} -- time steps within each observed period: $ m $ \\
	}

	\KwOut{The price of the option at the initial time}

	\Begin{
		Update $ F_{glob} $ and $ C_{glob} $ using Equations \ref{eq:clq-update-glob}. \;

		Set $ \Delta T, u, p $ from the formulae in Section \ref{sec:clq-models}. \;

		Compute the returns and probabilities using Equation \ref{eq:clq-return-final} and Equation \ref{eq:clq-prb-binom}. \;

		Compute $ j_{\min}, j_{\max}, j_0 $ (Equations \ref{eq:clq-j-mix-max}) and shifted returns (Table \ref{tab:clq-shift}). \;

		\tcp{$ S_i $ and $ S_+ $ denotes the current ($ i^{\mathrm{th}} $) and next ($ (i+1)^{\mathrm{th}} $) list of singular points.}

		$ S_N \leftarrow \{ (N F_{loc}, F_{glob}), (F_{glob}, F_{glob}), (C_{glob}, C_{glob}), (N C_{loc}, C_{glob}) \} $ \tcp{Table \ref{tab:clq-maturity}.}

		$ S_+ \leftarrow S_N $ \;

		\For{$ i \in \{ N-1, \dots, 0 \} $}{
			$ S_i \leftarrow \emptyset, \qquad L_+ \leftarrow \mathrm{length}(S_+) $ \;

			\ForAll{$ (l, j) \in [L_+] \times [j_0 + 1] $}{
				Compute $ B_{l,j} $ using Equation \ref{eq:clq-b}, replacing $ N $ by $ i $. \;

				\If{ $ ( B_{l,j} + R_k' ) \notin [ Z_N^{l_0}, Z_N^{l_0 + 1} ] $ } {
					Continue \tcp*{to the next item in the loop}
				}

				Find $ l_0 $ such that $ ( B_{l,j} + R_k' ) \in [ Z_{i+1}^{l_0}, Z_{i+1}^{l_0 + 1} ] $. \;

				Evaluate $ V_{i+1} (B_{l,j} + R_k') $ by linear interpolation of the extrema. \;

				Evaluate $ V_{i}(B_{l,j}) $ by using Equation \ref{eq:clq-penultimate}, replacing $ N $ by $ i $. \;

				$ S_i \leftarrow S_i \cup (B_{l,j}, V_{N-1}(B_{l,j})) $ \;
			}

			Approximate as described in Section \ref{subsec:clq-approx}. \;

			$ S_+ \leftarrow S_i $ \;
		}
		\KwRet{$ (S_i)_{1,2} $    \tcp*{Singular price at time 0} }
	}

	\caption{Pricing cliquet options using the singular points method}
\end{algorithm}

\clearpage
\subsection{Implementation}
The algorithm was implemented in Python 3.5.0 (2015-09-13).

\paragraph{mymath.py}
This file contains the $ \binom{n}{k} $ function.

\inputminted[tabsize=4]{python}{../code/mymath.py}
\label{lst:mymath}

\paragraph{cliquet.py}
This file contains the function \emph{cliquet\_sp}, which returns the price of the cliquet option at time 0.

\inputminted[tabsize=4]{python}{../code/cliquet.py}
\label{lst:clq}

\clearpage
\section{Results and conclusions}
\label{sec:clq-results}

In this section, we provide some numerical results that we have obtained from our program, along with the reported values of the same from \cite[Section 4]{Gaudenzi2011}. They compare the results with other techniques, namely Monte Carlo and the finite difference method of Windcliff et al\cite{Windcliff2006}. In all the experiments, the number of time steps considered were 10, 20, 50, 100, 200, 500 and 1000. The cases considered are as follows:
\begin{enumerate}
	\item Constant volatility of $ \sigma = 0.2 $
	\item Constant volatility of $ \sigma = 0.02 $, in order to test the efficiency of the methods for low volatility cases
	\item Varying volatility for each observational period, as $ \sigma(i) = 0.05 + 0.04i, i = 1, \dots, 8 $. (This is denoted by \emph{Var} in the $ \sigma $ column of Table \ref{tab:clq-results}.) The contract maturity is of 2 years, with quarterly monitoring dates.
\end{enumerate}
In order to obtain corroboration with the continuous value, we also report the price obtained by using Monte Carlo method with 1,000,000 of trials, along with the values in the 95\% confidence interval.

The specifications of the cliquet contract for the cases with constant volatility are as follows.
\begin{itemize}
	\item $ F_{loc} = 0, C_{loc} = 0.08, F_{glob} = 0.16, C_{glob} = \infty $
	\item $ T = 5 $ years
	\item $ N = 5 $
	\item $ r = 0.03 $
\end{itemize}

All simulations were run on a computer with the specifications given in Table \ref{tab:specs} of Chapter \ref{cha:asian}. All times were measured to 3 significant digits in seconds using the \emph{timeit} module of python, run from the terminal.

Table \ref{tab:clq-results} highlights the results.
\begin{table}[h]
	\centering
	\caption{Results for cliquet options}
	\label{tab:clq-results}
	%	\rowcolors{1}{Burlywood1}{}
	\begin{tabular}{rrccccc}
		\toprule
		\multirow{2}{1em}{$ \sigma $}  &  \multirow{2}{1em}{$ m $}
		&  \multicolumn{3}{c}{Price}  &  \multicolumn{2}{c}{Time (s)\tablefootnote{$ \infty $ means time taken is more than an hour.}}  \\
		\cmidrule(lr){3-5}\cmidrule(lr){6-7}
		&&  Bin  &  SP  &  MC  &  Bin  &  SP  \\
		\midrule
		\multirow{7}{2em}{$ 0.2 $}
		&    10  &  0.165661911  &  0.165661911  &  \multirow{7}{5em}{0.174106 (0.17398 -- 0.17423)}  &  0.000561  &  0.000555  \\
		&    20  &  0.172300056  &  0.172300056  &    &  0.000671  &  0.000675  \\
		&    50  &  0.172501269  &  0.172501269  &    &  0.00185  &  0.00175  \\
		&   100  &  0.172501269  &  0.173927464  &    &  0.00413  &  0.00297  \\
		&   200  &  0.173716366  &  0.173716366  &    &  0.0165  &  0.00828  \\
		&   500  &  0.173922597  &  0.173922671  &    &  0.0875  &  0.0437  \\
		&  1000  &  0.174051949  &  0.174051983  &    &  2.38  &  0.183  \\
		\midrule
		\multirow{7}{2em}{$ 0.02 $}
		&    10  &  0.151234115  &  0.151234416  &  \multirow{7}{5em}{0.150525 (0.150472 -- 0.150578)}  &  0.128  &  0.0295  \\
		&    20  &  0.149734212  &  0.149734992  &    &  1.01  &  0.199  \\
		&    50  &  0.150228984  &  0.150230185  &    &  7.96  &  0.868  \\
		&   100  &  0.150386306  &  0.150387954  &    &  70  &  2.36  \\
		&   200  &  0.150465004  &  0.150466828  &    &  600  &  6.09  \\
		&   500  &  0.150508871  &  0.150510526  &    &  $ \infty $  &  24.2  \\
		&  1000  &  0.150522368  &  0.150524027  &    &  $ \infty $  &  55  \\
		\midrule
		\multirow{7}{2em}{Var}
		&    10  &  0.188738321  &  0.188738321  &  \multirow{7}{5em}{0.226169 (0.225978 -- 0.226360)}  &  0.00258  &  0.00253  \\
		&    20  &  0.192927333  &  0.192927296  &    &  0.0153  &  0.0139  \\
		&    50  &  0.192650261  &  0.192650204  &    &  0.510  &  0.0638  \\
		&   100  &  0.193452450  &  0.193452358  &    &  2.43  &  0.162  \\
		&   200  &  0.193657595  &  0.193657617  &    &  14.6  &  0.364  \\
		&   500  &  0.193742799  &  0.193742732  &    &  3600  &  1.11  \\
		&  1000  &  0.193776040  &  0.193776165  &    &  $ \infty $  &  2.97  \\
		\bottomrule
	\end{tabular}
\end{table}

\begin{rem}[Computational dependence on volatility]
	The computational time of the pure binomial method for cliquet options is strongly dependent on the volatility. In fact the total number of paths needed to determine the price is $ m N $. Because of the presence of the global cap and floor, the number of paths can be reduced to $ (j_0 + 1) N $. But $ j_0 $ is strictly dependent on $ \sigma $ (see Equation \ref{eq:clq-j-mix-max}), and the difference in the computational time between large and small volatilities becomes very high, as is evinced from the constant volatility cases in Table \ref{tab:clq-results}.
\end{rem}

% This plot was generated by plotly
\begin{figure}[h]
	\centering
	\includegraphics[width=\linewidth]{img/timing-cliquet}
	\caption[Timing -- cliquet]{Timing the singular point method for cliquet option with constant volatility $ \sigma = 0.2 $. The quadratic curve provides a pragmatic bound for the runtimes. The exponential curve is too conservative.}
	\label{fig:clq-timing}
\end{figure}

\begin{rem}[Computational complexity]
	We remarked earlier that although the computational complexity of the algorithm without approximation is the same as that of the binomial model, enabling approximations decreases the complexity to a polynomial time algorithm. In fact, the Figure \ref{fig:clq-timing} corroborates exactly to this. The blue dots denotes the time taken to run the algorithm for constant volatility of $ \sigma = 0.2 $. The brown bold curve is a quadratic function of the number of time steps $ m $, whereas the green dash-dot curve is an exponential function of the same. We varied the parameters so that the curves fits the data. We see that the quadratic function serves as an upper bound for the running time for most data points in the plot, except for a few points, which may be treated as outliers. Thus, we may conclude that the computational complexity of the algorithm is $ O(m^2) $ in this case. In fact, our experiments show that this is indeed the general trend. Thus, even though we have not found out the theoretical complexity of the algorithm, in practice the algorithm is competitive.

	Note that for the Asian case, the experimental complexity is $ O(n^3) $, whereas in the cliquet case, it is $ O(m^2) $. (Recall that in the cliquet case, $ n = N m $, where we can consider $ N $ as constant as it is specified in the contract.)
\end{rem}

\paragraph{Concluding remarks}
We note that, in all cases, the difference between the prices in obtained by the singular points method and the binomial method is significantly smaller than the theoretical value of $ N \cdot 10^{-6} $. Moreover, as in the case examined $ N C_{loc} < C_{glob} $ (which is equivalent to $ N C_{loc} = C_{glob} $), the price functions $ V_i(Z) $ are always convex and this implies that the approximation procedure will provide an upper estimate of the exact binomial value.

Thus, the singular points method is quite capable in pricing cliquet options in a Black-Scholes framework with piecewise constant interest rates and volatilities. The implementation is quite simple, and the price obtained by the method converges to the price of continuous model. In absence of approximation, the price matches the exact binomial price. The ability to set \emph{a priori} error bounds differentiates it from the alternative algorithms.

Numerical comparisons indicate that the method is accurate both for standard and small volatilities, and that it avoids the computational problems arising from the application of the standard binomial method. For small volatilities and large numbers of observation times in particular, the improvement with respect to the binomial standard technique is very significant. Experimental results show that the computational complexity in practice is around $ O(m^2) $.

%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% mode: latex
%%% TeX-master: t
%%% End:


\subsection{Within-group variance and between-group variance}

\subsubsection{Introduction}


\section{Model}

The TMD system is described by
the effective tight-biding, low-energy, two-valley Hamiltonian
\cite{PhysRevLett.108.196802},
\begin{equation}
  \label{eq:tmd:hamiltonian}
  H_τ^0 \ofK
  = a t \left( τ k_x σ_x + k_y σ_y \right) ⊗ I_2
    + \frac{Δ}{2} σ_z ⊗ I_2 - λ τ \left(σ_z - 1 \right) ⊗ S_z.
\end{equation}
The (periodic) Bloch orbital states
(see \cref{s:appendix:tight-binding}) are
\begin{equation}
  \ketOrbitalK{ν}
  = \frac{T_{\vK +  τ \vc{K}}}{\sqrt{N}}
    ∑_{n = 1}^N e^{i \left( \vK + τ \vc{K} \right) ⋅ \vRn{n}}
    T \of{\vRn{n}} \ketOrbital{ν},
\end{equation}
where $N$ is the number of \ce{M}-type atoms in the system,
\begin{subequations}
  \begin{alignat}{2}
    & \ketOrbital{+} && = \Ket{d_{z^2}} ⊗ \Ket{\s}, \\
    & \ketOrbital{-} && = \frac{1}{\sqrt{2}}
        \left( \Ket{d_{x^2 - y^2}} + i τ \Ket{d_{xy}} \right) ⊗ \Ket{\s},
  \end{alignat}
\end{subequations}
and $\Ket{d_{xy}}$ and $\Ket{d_{x^2 - y^2}}$
refer to the angular momentum orbitals
in the symmetry group $E \left( d_{xy}, d_{x^2 - y^2} \right)$.
The operators $σ_i$ are Pauli operators acting
on the two Bloch orbital states
(indexed by $ν = ±$)
such that $σ_z \ketOrb{±}{\ofK} = ± \ketOrb{±}{\ofK}$.
The valley index $τ = ±$, corresponding to the $± \vc{K}$ points,
and the spin index ${\s} = ±$ (or ${\s} =\ ↑↓$),
corresponding to the $z$-component of the spin through $s_z = {\s} / 2$,
are good quantum numbers.%
\footnote{%
  Only in this chapter do we use $s$ to denote spin.
  In the appendices, we adopt the more traditional symbol $σ$.
}
The momentum $\vK$ is measured from the valley center,
i.e., for a given valley, the total momentum relative to the center
of the Brillouin zone is $\vK + τ \vc{K}$.
The energy gap is $Δ$, the spin splitting in the valence band is $2 λ$,
the lattice constant is $a$, and $t$ is the effective hopping integral.
\Cref{eq:tmd:hamiltonian}
can be written in matrix form in the Bloch orbital basis,
\begin{equation}
  \left[ H_{τ \s}^0 \ofK \right]
  = \left[
    \begin{matrix}
      \dfrac{Δ}{2}                     & a t \left( τ k_x - i k_y \right) \\
      a t \left( τ k_x + i k_y \right) & λ τ \s - \dfrac{Δ}{2}
    \end{matrix}
    \right].
\end{equation}

The energy spectrum,
\begin{equation}
  \label{eq:energy}
  \fnEnergy{n} \of{k}
  = \frac{1}{2} \left( λ τ {\s} + n \sqrt{{\left( 2 a t k \right)}^2
  + {\left( Δ - λ τ {\s} \right)}^2} \right),
\end{equation}
with $k = \abs{\vK}$
and $n = 1$ ($n = -1$) indexing the conduction (valence) band
is shown in \cref{fig:energy}.
For a fixed band, we have the inverse relation,
\begin{equation}
  {\left( \frac{a t k}{Δ / 2} \right)}^2
  = {\left( \frac{2 E}{Δ} \right)}^2
    + 2 τ \s \left( \frac{λ}{Δ} \right) \left( 1 - \frac{2 E}{Δ} \right) - 1,
\end{equation}
where $E > Δ / 2$ for $n = 1$ and
$E < - \left( Δ / 2 - λ τ \s \right)$ for $n = -1$.
Note the relations
\begin{subequations}
  \begin{align}
    θ_{-↓}^{n} \of{k} + θ_{+↑}^{n} \of{k} & = 2π , \\
    \fnTheta{+} - \fnTheta{-} & = - τ π, \\
    ϕ_{-\vK} - ϕ_{\vK} & = π.
  \end{align}
\end{subequations}

\begin{figure}
  \includegraphics[width=\columnwidth]{figures/energy-bands}
  \caption{%
    Energy bands for $\ce{WSe2}$ as given by \cref{eq:energy}
    with $a t = \SI{3.939}{\electronvolt \per \angstrom}$,
    $Δ = \SI{1.60}{\electronvolt}$,
    and $λ = \SI{0.23}{\electronvolt}$.
    Each valley is centered at $± \vc{K}$ relative to the center of the
    Brillouin zone.
    The energy for a given band depends only on the distance $k$
    measured from the valley center.
  }\label{fig:energy}
\end{figure}

We focus on doped systems
such that the chemical potential $μ$ lies in the upper valence bands.
Within each band, the Bloch basis eigenstates are written
in terms of the orbital states as elements on the Block sphere,
\begin{equation}
  \Ket{u_{τ {\s}}^n \of{k, ϕ}}
  = \cos{\frac{\fnTheta{n}}{2}} \ketOrb{+}{\of{k, ϕ}}
  + e^{-i τ ϕ}
    \sin{\frac{\fnTheta{n}}{2}} \ketOrb{-}{\of{k, ϕ}},
\end{equation}
where $k_x + i τ k_y = k e^{i τ ϕ}$ and
\begin{equation}
  \tan{\frac{\fnTheta{n}}{2}}
  = \frac{a t τ k}{\dfrac{Δ}{2} - \fnEnergy{-n} \of{k}}
  = \frac{a t τ k}{\fnEnergy{n} \of{k} - \fnEnergy{-} \of{0}}.
\end{equation}
The polar angle on the Bloch sphere
of the conduction and valence bands are related by
$\fnTheta{-} - \fnTheta{+} = τ π$.
The mapping of the energy band to the Bloch sphere,
parametrized by $\left( θ, ϕ \right)$,
encodes the topological character:
as one moves from the node out to infinity,
the states sweep either the northern or southern hemisphere
with a chirality determined by the Berry curvature.