Monday 18 November 2013

VaR II: Parametric normal and lognormal

Let us see how to calculate VaR in practice. We'll start with the simplest cases (which are used from time to time in practice), and work our way up. First, let's again collect definitions of return
\begin{equation} \label{linret_did}
 \mathrm{r}_t:= \frac{p_{t+1}}{p_t} -1.
\end{equation}
of logreturn
\begin{equation} \label{logret_did}
\ell_t := \log\left(\frac{p_{t+1}}{p_t}\right).
\end{equation}
and what we figured out about calculating VaR based on return,
\begin{equation} \label{VaRcont}VaR_{99\%} = F_{\mathrm{r}_t}^{-1}(1\%) = r_{1\%},\end{equation}
based on logreturn
\begin{equation}\label{VaRlogret}
 VaR_{99\%} = r_{1\%} = e^{F_{\ell_t}^{-1}(1\%)} -1.
\end{equation}
all beautifully explained in the previous post on VaR VaR I: What is it? Basic setup.

Normally distributed asset
If the underlying asset price \(p_{t+1}\) is normally distributed then, because of the definition of return~\eqref{linret_did}, the return is also normally distributed and this makes the math easy. Is this a reasonable assumption? Not really, it says that negative prices are possible! I've never seen a cow that cost \(-\$100\)*. But for short time horizons, such as when \(t\) is counting days, it can be a reasonable approximation.

Using Historical data** (or perhaps implied information about the future***), let's say that we have fit a normal distribution with average \(\mu\) and standard deviation \(\sigma\) to our return, thus we're assuming that \( \mathrm{r}_t \sim \mathcal{N}(\mu, \sigma^2).\) Fortunately, there always exists an \(r_{1\%}\) such that \(r_{1\%}= F_{ \mathrm{r}_t}^{-1}(1\%)\) for the normal c.d.f is a surjective function over real numbers.  Thus we can use~\eqref{VaRcont} to calculate VaR. The problem is that most mathy software systems, like Matlab or Mathematica, only have the inverse cumulative of the standard normal variable \(Z \sim \mathcal{N}(0,1).\) We need to figure out what our inverse is.  Panic not, unknown reader. You can build any normal variable by appropriate summing and multiplying constants to the standard normal variable \(Z \sim \mathcal{N}(0,1).\) In our case, \(\mathrm{r}_t\) can be written as
\[ \mathrm{r}_t = \mu + \sigma Z.\]
Because of this, you can calculate \(F_{ \mathrm{r}_t}(r)\) using the standard normal cumulative function \(\Phi(r) = \mathbb{P}\left(Z \leq z\right).\) Observe
\begin{align*}
F_{ \mathrm{r}_t}(r) &= \mathbb{P}\left( \mathrm{r}_t \leq r\right) \\
&= \mathbb{P}\left( \mu + \sigma Z \leq r\right)\\
&= \mathbb{P}\left( Z \leq \frac{r-\mu}{\sigma}\right) \quad \mbox{(Subtract by \(\mu\), divide by \(\sigma\) inside)}\\
& = \Phi\left(\frac{r-\mu}{\sigma}\right).  \quad \mbox{(Definition of the standard normal cumulative)}
\end{align*}
To find the inverse of \(F_{ \mathrm{r}_t}(r)\), let's name  \(y = F_{ \mathrm{r}_t}(r)\) as is customary in calculus books and apply
  \(\Phi^{-1}\), the inverse of the standard cdf, to both sides of the above equation
\[  \Phi^{-1}(y) = \frac{r-\mu}{\sigma}\]
and isolating \(r\), we find that
\begin{align}\label{norminv}
F_{ \mathrm{r}_t}^{-1}(y) = r = \Phi^{-1}(y)\sigma + \mu.
\end{align}
With this we can plug in \(r_{1\%}\) to find that \(y = F_{ \mathrm{r}_t}(r_{1\%}) = 1\%\) and
\begin{equation}\label{VARnorm1}
VaR_{99\%} = r_{1\%}  = \Phi^{-1}(1\%)\sigma + \mu.
\end{equation}
Where \(\Phi^{-1}(1\%)\) is just some number that can be calculated, and is approximately  \(-2.3263\).

Lognormally distributed asset
This is a bit more reasonable. At least only positive prices are plausible, for allowing negative prices was positively preposterous! You see, lognormal random variables can only assume positive values, and the lognormal distribution sort of fits that of past asset returns. Now it's more convenient to work directly with the lognormal return~\eqref{logret_did}, for if \(p_{t+1}\) is lognormal then, by definition the definition of lognormal random variables, \(\ell_t\) is normal random variable. Say we have fit a normal distribution with mean \(\mu\) and standard deviation \(\sigma\)  for our random variable \(\ell_t\), i.e. \(\ell_t \sim \mathcal{N}(\mu,\sigma).\)  We just saw what is the inverse of a normal variable~\eqref{norminv}, thus we can apply~\eqref{VaRlogret} directly to find
\begin{equation}\label{VARlog1}
VaR_{99\%} = r_{1\%}  = e^{\Phi^{-1}(1\%)\sigma + \mu} -1.
\end{equation}
Interesting fact: The formula for VaR based on normal returns~\eqref{VARnorm1} is equivalent to the first-order Taylor approximation of the VaR formula for normal logreturn~\eqref{VARlog1}. So what? Well, if you assume that lognormal distribution of our asset is the  ``true'' model, then using~\eqref{VARnorm1} as a proxy is ok as long as \(\sigma\) and \(\mu\) are very small.

VaR for general and sample distributions
Calculating VaR for a general distribution poses an extra challenge: Cumulative distribution functions are not invertible, in general. In other words, there simply might not exist a unique value \(r_{1\%}\) that sets it's \(F_{r_t}\) to \(1\%\). This often occurs in practice because.  Why? Because instead of using a known distribution for our return, people often make a nifty change to historical returns to build a sample distribution. Is this ideal? No, but it's also not mere witch-doctery and it's an improvement over our previous normal and lognormal assumptions. For before, not only did we use past data to build our future distribution, but we also imposed a very specific distribution on our returns (normal or lognormal). I will go into detail in a future post on exactly how to do this, but for now assume we have built a sample cdf function such as the one in this figure:


Note that based on the figure, any \(r \in [-0.3694, -0.2294]\) is such that \(F(r) = 1\%\). This is the problem: we can't invert \(F(r).\) So which \(r\) do we choose to be our VaR? People who work in risk are inherently pessimistic, so we choose the worst out of these suitable returns to be our VaR. In other words, VaR of \(99\%\) is the lowest return for which the \(1\%\) lowest returns are still below it. Formally
\[VaR_{99\%} := \min\{r \in \mathbb{R} \, | \,  F(r) \geq 1\% \}.\]
In the above example this would be \(VaR_{99\%} = -0.3694\), ergo, with 99\% chance, we will not lose more then \(36.94\%\) of our assets.

Similarly, for any given confidence level \(\beta \in [0, 1]\) we can define
\[VaR_{\beta} := \min\{r \in \mathbb{R} \, | \,  F(r) \geq 1- \beta\}.\]
Though we have focused on what to do with a sample distribution, this is in fact the general definition of VaR. For the more mathy type, ask yourself, why is it that VaR given as such is always defined? Does this minimum always exist?

Next we'll look at what really matters: Calculating the VaR of a portfolio of assets.

* Ignore possible storage or disposing costs that make negative prices a possibility.
**I would suggest using Exponentially Weighted Moving Average to do this.
***Say what? Interested, ask for it on the blog

Sunday 17 November 2013

VaR I: What is it? Basic setup



Will I go bankrupt tomorrow? This question bothers many a business. When your a big business, it can be hard to come to grips with all that is you. This may sound strange for those who own a small business, say, a doughnut stand. But when your business is a sizable conglomerate, then it becomes hard to see how likely it is that failures across the different parts results in a failure of the whole company. The exact question really is: How much liquid freed-up cash do I have to keep in hand so that I can survive bad shit happening tomorrow.

How do you go about answering this? Here's an idea: let's try and conjure-up what's the worst thing that can happen tomorrow, then we'll check to see if the biz could survive. You think some more, and realize that the worst thing possible is anything from earthquakes, to a rather unlikely quantum event that teleports all of your assets into outer space. Not very useful. So let's try and rule out these truly extreme events. Instead, let's focus on the worst possible event, removing the \(1\%\) worst event. That's the idea behind Value at Risk also abbreviated to VaR (which is unfortunate as variance has already called dibs on the abbreviation VAR.) We abbreviate as \(VaR_{99\%}\) the worst possible outcome ignoring the worst \(1\%\).

A few of you, with hippie tendencies, might already be saying ``but....ohhhhhhh....the \(1\%\) worst cases is where shit really gets messed-up, world wide crisis style, and this silly VaR thing ignores it!''. Yes, VaR has no place measuring the occurrence of massively bad things happening. Instead, VaR just prepares you to deal with the next day when business is as usual. Think of a bank putting aside cash everyday so that it's clients can get their grubby hands on it through cash machines. Well, how much should the b-man put aside everyday? Everything just in case everybody wants some bling bling? But then the big-b can't invest. VaR of \(99\%\) of the amount of cash withdrawals is probably safe enough (ok, \(1\%\) of the time, some douche is not gonna get his dough).

I will address the basic concepts behind the VaR of a single asset, then move onto aggregating VaR across assets and practical methods for calculating it.

VaR of a single asset
 We start by naming things. Let \(p_t\) be the price of your single asset at time \(t\), thus \(p_t \in \mathbb{R}^+\). Let \(t\) be today*. Furthermore, let the return \(\mathrm{r}_t\) from today to tomorrow be defined by
\begin{equation*}
p_t(1+ \mathrm{r}_t) = p_{t+1}.
\end{equation*}

Thus the future value \(p_{t+1}\) can be completely determined by knowing the price today and today’s daily return. For this reason, VaR concepts focus on return instead of absolute price. It also puts things in perspective, for stuff has values of different order, e.g, a cow can be cost $1000 while a single olive can be quite cheap. Return, on the other-hand, is something typically between \(-100\%\) and \(100\%\). Isolating return in~(\ref{linret_did}), we have
\begin{equation} \label{linret_did}
 \mathrm{r}_t= \frac{p_{t+1}}{p_t} -1.
\end{equation}

A few of you might read this and argue: Hey, that's not how I define return. Yes, return can be defined in a number of ways that gives us this notion of ``how much did the value of my stuff change''. In fact, let's also define the logreturn, which, as it's name sort of suggests
\begin{equation} \label{logret_did}
\ell_t := \log\left(\frac{p_{t+1}}{p_t}\right) \quad (\mbox{same as saying})\quad p_{t+1} = p_te^{\ell_t}.
\end{equation}

To determine the worst possible return tomorrow, excluding the \(1\%\) worst, we need to assume some sort of distribution for \(\mathrm{r}_t\) as it is unknown to us. We will model this uncertainty with standard probability theory.  In this model, we need a probability measure \(\mathbb{P}\left(\right)\) that says how probable an event is, and a probability distribution for \(\mathrm{r}_t\)**. The question of picking a distribution for \(\mathrm{r}_t\) is in itself a tricky one, but assume for now we are given the c.d.f (cumulative distribution function)  \(F_{\mathrm{r}_t}: \mathbb{R} \rightarrow \mathbb{R}^+\) which is defined for each \(r \in \mathbb{R}\) as
\[F_{\mathrm{r}_t}(r) := \mathbb{P}\left( \mathrm{r}_t \leq r\right),\]
so it's a function that given a possible return \(r\), it tells us how likely is it that today’s return is at most \(r\). \(VaR_{99\%}\) is the cut-off return \(r_{1\%}\), such that the \(1\%\) worst returns are  below \(r_{1\%}.\)  In other words,  we want to find \(r_{1\%} \in \mathbb{R}\) such that \(F_{\mathrm{r}_t}(r_{1\%}) = 1\%.\) Thus \(VaR_{99\%}\) can be defined precisely as
\begin{equation} \label{VaRcont}VaR_{99\%} = F_{\mathrm{r}_t}^{-1}(1\%) = r_{1\%},\end{equation}
where \(F_{\mathrm{r}_t}^{-1}\) is the inverse of the cdf of \(\mathrm{r}_t.\)

Sometimes we will not be working directly with the return \(\mathrm{r}_t\), but instead, we will know the distribution of the logreturn~\eqref{logret_did}. So let's figure out what is \(\mathbb{P}\left(\mathrm{r}_t \leq r\right)\) in terms of logreturn. First we substitute \(\mathrm{r}_t\) for it's definition~\eqref{linret_did} to find
\begin{align}
\mathbb{P}\left( \mathrm{r}_t \leq r\right)  & = \mathbb{P}\left( p_{t+1}/p_t -1 \leq r\right) \quad \left(\mbox{Sum \(1\) to both sides of inner inequality}\right) \nonumber \\
& =  \mathbb{P}\left( \log(p_{t+1}/p_t) \leq \log(r+1)\right) \quad (\mbox{Apply log inside }\mathbb{P}\left(\right)) \nonumber\\
 & =  \mathbb{P}\left( \ell_t \leq \log(r+1)\right) \quad (\mbox{Using definition~\eqref{logret_did}}) \nonumber \\
& = F_{\ell_t} \left( \log(r+1) \right),\label{cdflogret}
\end{align}
where \(F_{\ell_t}\) is the cumulative distribution function of the logreturn \(\ell_t\). Again, remember that VaR of \(99\%\) is equal to a certain \(r_{1\%}\) that sets \(\mathbb{P}\left( \mathrm{r}_t \leq r_{1\%}\right) = 1\%.\) From~\eqref{cdflogret}, this is equivalent to finding
\[F_{\ell_t} \left( \log(r_{1\%}+1) \right) = 1\%. \]
Applying the inverse of \(F_{\ell_t}\) to both sides (and assuming we can do this!) we find

\[
\log(r_{1\%}+1)  = F_{\ell_t}^{-1}(1\%).
\]
Isolating \(r_{1\%}\) we find
\begin{equation}\label{VaRlogret}
 VaR_{99\%} = r_{1\%} = e^{F_{\ell_t}^{-1}(1\%)} -1.
\end{equation}


 But this is not always possible for all possible distribution functions and will depend on what exactly are the cdfs \(F_{\ell_t}\) and \(F_{\mathrm{r}_t}.\) Let's break this down by what we are assuming about our asset so that we may calculate VaR. Now move onto  VaR II: Parametric normal and lognormal


* We'll think in terms of days, but really we can choose the refinement of time, say nano-seconds you trader junkies?
** Formally, we would need the whole measure space set-up, i.e., name a space of events for \(\mathbb{P}\) that has enough events. If you would like a more measure theoretical rigor, comment on the post.