\documentclass[a4paper]{article}
\usepackage{amsfonts,amssymb,amsmath,amsthm,latexsym,amsbsy,graphicx,float,hyperref,ifthen,color}
\usepackage{makecourse}
\usepackage{tikz}
\allowdisplaybreaks

\newcommand{\mvs}{\vspace{2.5cm}\\}
\newcommand{\mvv}{\vspace{4.0cm}\\}
\newcommand{\expt}{\textrm{E}}
\newcommand{\pr}{\textrm{Pr}}
\newcommand{\logn}{\textrm{ln}}
\newcommand{\var}{\textrm{Var}}
\newcommand{\RR}{\mathrm{I\!R\!}}
\newcommand{\R}{$\mathsf{R\;}$}

\setcounter{section}{2}
\begin{document}
\section{Estimating Volatility}
In order to apply the Black-Scholes pricing formula, we need five parameters -- initial stock price $S_{0}$, volatility of the stock $\sigma^2$, riskless interest rate $r$, maturity of the option $T$ and strike price $K$. Note that four of the five parameters are known and the value of $\sigma^2$ needs to be estimated. One possibility is to use historic data. In this Section we will detail how to estimate $\sigma^2$ using daily closing prices and also opening and closing prices. We will also consider implied volatility.   

\subsection{Using Closing Data}
Suppose that $Y_{1},\ldots , Y_{n}$ are independent random variables having a common probability distribution with mean $\mu_{0}$ and variance $\sigma^{2}_{0}$. For unknown $\mu_{0}$, the usual estimator of $\sigma^{2}_{0}$ is the sample variance,
\[
\hat\sigma^{2}_{0}=\frac{\sum_{i=1}^{n}(Y_{i}-\bar{Y})^{2}}{n-1}=\frac{\sum_{i=1}^{n}Y_{i}^{2}-n\bar{Y}^{2}}{n-1}\, .
\]
Note that the estimator is a random variable (and the capitalisation of the $Y_i$ reflects this). 
Recall that the above is an unbiased estimator of $\sigma^{2}_{0}$ since
\[
E(\hat\sigma^{2}_{0})=\sigma^{2}_{0} \, .
\]
%\textbf{Exercise}: show that $\expt(\hat\sigma^{2}_{0})=\sigma^{2}_{0}$.

Furthermore, if the $Y_{i}$ are Normally distributed, it can be shown that
\[
Var(\hat\sigma^{2}_{0})=\frac{2\sigma_{0}^{4}}{n-1}.
\]
In this case, $\hat\sigma^{2}_{0}$ is a consistent estimator of $\sigma^{2}_{0}$. Recall that for consistency, we need asymptotic unbiasedness and 
the variance of the estimator to tend to zero as the sample size increases.

\subsubsection*{Proof of unbiasedness}
We can show that $E(\hat\sigma^{2}_{0})=\sigma^{2}_{0}$ as follows. We have that
\[
E(\hat\sigma^{2}_{0})=\frac{1}{n-1}\left(\sum_{i=1}^n E(Y_i^2)-nE(\bar{Y}^2)\right).
\]
Now, 
\[
Var(Y_i)=\sigma^2_0=E(Y_i^2)-[E(Y_i)]^2.
\]
Hence, using $E(Y_i)=\mu_0$ and re-arranging the above gives
\[
E(Y_i^2)=\sigma^2_0+\mu_0^2.
\]
In a very similar manner, we obtain
\[
E(\bar{Y}^2)=\frac{\sigma^2_0}{n}+\mu_0^2.
\]
Finally,
\begin{eqnarray*}
E(\hat\sigma^{2}_{0})&=&\frac{1}{n-1}\left(n\times (\sigma^2_0+\mu_0^2)-n\times(\sigma^2_0/n+\mu_0^2)\right)\\
&=& \frac{1}{n-1}(n-1)\times \sigma^2_0\\
&=& \sigma^2_0
\end{eqnarray*}
as required.

\subsubsection*{Application to p.a. volatility estimation}
We apply this procedure to estimate the volatility of a stock price as follows. Suppose the \emph{closing price} of a stock is observed at fixed intervals of time (e.g. every day) and is assumed to follow a G.B.M. with volatility $\sigma^2$ (per annum). Define:
\begin{itemize}
\item$n+1$: Number of observations
\item$C_{i}$: Closing price at the end of interval $i$ ($i=0,\ldots ,n$)
\item$\Delta t$: Length of time interval in years
\end{itemize}
and let
\[
Y_{i}=\log\left(\frac{C_{i}}{C_{i-1}}\right) \, .
\]
Now, under the assumption of G.B.M. $Y_{i}$ follows a Normal distribution with variance $\sigma^{2}\Delta t$. In this context, the sample variance would give an unbiased estimator of $\sigma^{2}\Delta t$. Therefore we construct the estimator of $\sigma^2$ as 
\[
\hat\sigma^2 = \frac{1}{\Delta t}\frac{\sum_{i=1}^{n}(Y_{i}-\bar{Y})^{2}}{n-1}=\frac{1}{\Delta t}\frac{\sum_{i=1}^{n}Y_{i}^{2}-n\bar{Y}^{2}}{n-1} \, .
\]

%\newpage

\subsubsection*{Comments}
\begin{itemize}
\item Choosing a value $n$ is not as straightforward as would appear. Naturally, more data will lead to more accuracy. However, it may not be reasonable to assume that the volatility of a particular stock is the same now as, say ten years ago. We will come back to this point later on.
\item The procedure is typically used with daily data. An important point is whether volatility should be measured per calendar year or trading year. Evidence suggests that volatility is largely caused by trading itself and therefore $\sigma^2$ is typically measured per trading year. Since there are (approximately) 252 trading days in a year (so that 1 day $= 1/252$ years), the estimator of $\sigma^2$ based on $n+1$ days of data is  
\[
\hat\sigma^2 = 252\frac{\sum_{i=1}^{n}(Y_{i}-\bar{Y})^{2}}{n-1}=252\frac{\sum_{i=1}^{n}Y_{i}^{2}-n\bar{Y}^{2}}{n-1} \, .
\]
\end{itemize}


\subsubsection*{Example 3.1}
Consider the following closing day Gas prices (in dollars) observed on 21 consecutive days.
\begin{table}[ht]
\begin{center}
\begin{tabular}{cccc}
\hline
Day ($i$) & Closing Price ($C_{i}$) & Day ($i$) & Closing Price ($C_{i}$)\\
\hline
0 & 52.75 & 11 & 59.48  \\
1 & 53.43 & 12 & 58.12  \\
2 & 54.51 & 13 & 57.40  \\
3 & 53.77 & 14 & 56.38  \\
4 & 53.90 & 15 & 57.60  \\
5 & 53.66 & 16 & 57.25  \\
6 & 54.54 & 17 & 57.44  \\
7 & 54.92 & 18 & 56.07  \\
8 & 55.00 & 19 & 56.21  \\
9 & 56.88 & 20 & 57.76  \\
10& 57.80 &    &  \\
\hline
\end{tabular}
\end{center}
\caption{Commodity Prices (dollars)}\label{tab:tabcom}
\end{table}
Assuming that Gas price follows a G.B.M., we estimate the volatility $\sigma^2$ (per annum) by computing
\[
\sum_{i=1}^{20}y_{i}^{2}=\sum_{i=1}^{20}\left[\log\left(\frac{C_{i}}{C_{i-1}}\right)\right]^{2}=0.00615 
\]
and
\[
\bar{y}=\frac{1}{20}\sum_{i=1}^{20}\log\left(\frac{C_{i}}{C_{i-1}}\right)=0.00454\, .
\]
Hence we obtain the \emph{estimate}
\[
\hat\sigma^2=252\frac{0.00615-20\times 0.00454^{2}}{19}= 0.0761\, .
\]

\numbas[Test yourself:]{https://numbas.mathcentre.ac.uk/question/145109/estimating-volatility/embed/?token=2ed44708-888f-465d-b7c5-8a68dac67b27}

\subsubsection*{Example 3.2}
Here, we will consider daily closing values of the Standard and Poors 500 (S\&P500) index from January 03, 2012 until October 25, 2022. The data set can be downloaded from the course page (click \emph{Download SandP500.RData} and double click the file once it's downloaded) or can be read directly from the URL using the first line of the code below. The data will then be loaded into \R (RStudio) where a new vector called `sp' will be loaded into the R environment. The following commands can be used to plot:
\begin{verbatim}
load(url("https://www.mas.ncl.ac.uk/~nak102/teaching/mas3904/SandP500.RData"))

plot(ts(sp,start=2012,deltat=1/252),xlab="Time (years)",ylab="Price (dollars)")
\end{verbatim} %$
We can plot the \emph{daily returns}, $\log(C_{i}/C_{i-1})$ with
\begin{verbatim}
len = length(sp)
ret = log(sp[2:len]/sp[1:(len-1)])
plot(ts(ret,start=2012,deltat=1/252),xlab="Time (years)",ylab="Returns")
\end{verbatim}

\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.5]{sp.pdf}
\end{center}
\caption{Daily closing prices and returns of the S\&P500 index}\label{fig:fig_sp}
\end{figure}

Figure \ref{fig:fig_sp} shows daily closing prices and returns. Assuming that the S\&P500 index data follows a G.B.M. we can estimate the volatility per annum, using the full set of observations, with the command,
\begin{verbatim}
var(ret)*252
\end{verbatim}
which yields $\hat\sigma^{2}=0.0294$. Note that in computing this estimate we have assumed that the volatility is constant over the period January 03, 2012 -- October 25, 2022. Figure~\ref{fig:fig_vol} shows estimates of square root annual volatility, $\sigma$, obtained by taking the S\&P500 data for each year in turn, and applying the formula (and square-rooting). On inspection of this plot, it appears that our assumption of a constant volatility over the entire period may be an unreasonable one. 

\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.5]{vol.pdf}
\end{center}
\caption{Estimated square root volatility against year, using the S\&P500 data.}\label{fig:fig_vol}
\end{figure}

\subsection{Using Opening and Closing Data (not examinable)}
Let $C_{i}$ denote the (closing) price of a particular stock at the end of trading day $i$. Assuming that stock price follows a geometric Brownian motion, $\log(C_{i}/C_{i-1})$ follows a Normal distribution with variance $\sigma^{2}/252$. Now let $O_{i}$ denote the \emph{opening price} at the start of trading day $i$ and write
\begin{eqnarray*}
\log\left(\frac{C_{i}}{C_{i-1}}\right)&=& \log\left(\frac{C_{i}}{O_{i}}\frac{O_{i}}{C_{i-1}}\right)\\
&=& \log\left(\frac{C_{i}}{O_{i}}\right)+\log\left(\frac{O_{i}}{C_{i-1}}\right)\, .
\end{eqnarray*}
Now, assuming that the ratio price change during a trading day is independent of the change that happened when the market was closed (i.e. $C_{i}/O_{i}$ and $O_{i}/C_{i-1}$ are independent) it follows that
\begin{eqnarray*}
\var\left(\log(C_{i}/C_{i-1})\right)&=&\var\left(\log(C_{i}/O_{i})\right)+\var\left(\log(O_{i}/C_{i-1})\right)\\
&=& \var\left(C_{i}^{*}-O_{i}^{*}\right) + \var\left(O_{i}^{*}-C_{i-1}^{*}\right)
\end{eqnarray*}
where $C_{i}^{*}=\log(C_{i})$ and $O_{i}^{*}=\log(O_{i})$. If we observe closing prices on days $0,1\ldots ,n$ and opening prices on days $1,2,\ldots n$ and assume that $C_{i}^{*}-O_{i}^{*}$ and $O_{i}^{*}-C_{i-1}^{*}$ both have a mean of approximately 0, then we may estimate $\sigma^2$ by
\begin{equation}
\hat\sigma^2 = 252\frac{\sum_{i=1}^{n}\left[(C_{i}^{*}-O_{i}^{*})^{2}+(O_{i}^{*}-C_{i-1}^{*})^{2}\right]}{n-1} \, .
\end{equation} 
\subsubsection*{Example 3.3}
Consider the following opening and closing day prices (in dollars) of the S\&P500 observed on 11 consecutive days.
\begin{table}[ht]
\begin{center}
\begin{tabular}{ccc}
\hline
Day ($i$) & Open ($O_{i}$) & Close ($C_{i}$) \\
\hline
0 &  & 241.13     \\
1 &241.24  &242.49     \\
2 &242.71  &245.73     \\
3 &245.73  &248.13     \\
4 &248.18  &244.35     \\
5 &244.12  &241.99     \\
6 &241.13  &244.06     \\
7 &244.56  &250.84     \\
8 &250.67  &252.04     \\
9 &252.12  &254.70     \\
10&254.70  &251.79    \\
\hline
\end{tabular}
\end{center}
\caption{S\&P500 opening and closing prices (dollars)}\label{tab:taboc}
\end{table}

We estimate the per annum volatility $\sigma^{2}$ by computing
\[
n+1=11, \qquad n=10,\qquad
\]
so that
\[
\sum_{i=1}^{10}(\log(C_{i})-\log(O_{i}))^{2} =\sum_{i=1}^{10}(C_{i}^{*}-O_{i}^{*})^{2}=0.00165
\]
and
\[
\sum_{i=1}^{10}(\log(O_{i})-\log(C_{i-1}))^{2}=\sum_{i=1}^{10} (O_{i}^{*}-C_{i-1}^{*})^{2}=1.94\times 10^{-5}
\]
Hence our estimate is
\[
\hat\sigma^2 = \frac{252}{9}\sum_{i=1}^{10}\left[(C_{i}^{*}-O_{i}^{*})^{2}+(O_{i}^{*}-C_{i-1}^{*})^{2}\right]=0.047
\] 

\newpage

\subsection{Implied Volatility}
We have seen how to estimate $\sigma$ from historic data. In practice, traders usually work 
with \emph{implied volatilities}. These are the volatilities implied by option prices observed 
in the market.

\subsubsection*{Definition 3.1}
The implied volatility of an option is the value of the volatility (of the underlying stock process) 
which when input into an option pricing model gives a value equal to the current/quoted price of the 
option.

\subsubsection*{Example 3.4}

Suppose that stock prices follow a risk neutral G.B.M. (with parameters $r$ and $\sigma^{2}$). 
Now suppose that the fair price of one ECO is $1.875$ when $S_{0}=21$, $K=20$, $r=0.1$ 
and $T=0.25$. The implied volatility is the value of $\sigma$ that, when substituted into the Black-Scholes 
formula gives $C_0 =1.875$.

Unfortunately, it is not possible to analytically express $\sigma$ as a function of $S_{0}, K, r, T$ 
using the Black-Scholes formula. An iterative search procedure can be used instead. For example, start with 
a value $\sigma=0.2$ and calculate a value for $C_0$. The following R function should be useful:

\begin{runnableCode}{r}
bs=function(s0=21,K=20,r=0.1,T=0.25,sig)
{
 omega=(r*T+sig*sig*T/2-log(K/s0))/(sig*sqrt(T))
 #Return BS price
 s0*pnorm(omega,0,1)-K*exp(-r*T)*pnorm(omega-sig*sqrt(T))
}
bs(sig=0.3)
\end{runnableCode}

Then, \texttt{bs(sig=0.2)} gives $C_0 =1.76$, which is too low. Since the fair price is increasing in $\sigma$ 
(proof of which is beyond the scope of the course), we could try $\sigma=0.3$. We perform the following in R:
\begin{verbatim}
bs(sig=0.3)
[1] 2.101014
> bs(sig=0.25)
[1] 1.926831
> bs(sig=0.21)
[1] 1.795785
> bs(sig=0.22)
[1] 1.827633
> bs(sig=0.23)
[1] 1.860137
> bs(sig=0.235)
[1] 1.876611
> bs(sig=0.234)
[1] 1.873305
\end{verbatim}
which suggests an implied volatility of 0.234-0.235. More powerful iterative search procedures, 
such as the Newton-Raphson method could be used. 

\end{document}

\newpage

\subsection*{Section quiz}

\begin{itemize}
\item[\textbf{Q1}] Suppose that an estimate of p.a. volatility based on 100 days of data is 0.1=10\%. If the 
\emph{same} data were assumed monthly rather than daily, the p.a. estimate of volatility would be 
\begin{itemize}
\item[\textbf{(a)}] the same.
\item[\textbf{(b)}] bigger.
\item[\textbf{(c)}] smaller.
\end{itemize}

\item[\textbf{Q2}] An estimator is
\begin{itemize}
\item[\textbf{(a)}] a random variable.
\item[\textbf{(b)}] a realisation of a random variable.
\end{itemize}

\item[\textbf{Q3}] The estimator of volatility based on historic data is  
\begin{itemize}
\item[\textbf{(a)}] unbiased but not consistent.
\item[\textbf{(b)}] unbiased and consistent.
\item[\textbf{(c)}] consistent but not unbiased.
\end{itemize}
\end{itemize}