Introduction: 1-day VaR

The Idea behind the VaR is to calculate the worst price movement an asset can observe in most cases.

Suppose we have $P$ assets with a certain current Value. We model the movement of this asset in the "next future time step" (the coming day) as random variable $$ X \sim \mathcal N (\mu, \sigma^2). $$ Hence in $c = 95 \%$ of the cases we have using the cdf $F_{\mathcal N(\mu, \sigma^2)}$ of $X$ $$ X \geq F^{-1}_{\mathcal N(\mu, \sigma^2)} (1-c) = \mu + \sigma \cdot \Phi^{-1}(1-c), $$ where $\Phi$ is the cdf (cumulation distribution function) of the standard normal distribution.

This results in the VaR: $$ \mathrm{VaR}^{(1)} = - P * F^{-1}_{\mathcal N(\mu, \sigma^2)} (1-c). $$

Note, that in general the value $F^{-1}_{\mathcal N(\mu, \sigma^2)} (1-c)$ will be negative so that our $\mathrm{VaR}^{(1)}$ formula will give a positive result.

In Python one can implement this as follows


In [1]:
from scipy.stats import norm

P = 8.4546
mu = 0.6
sigma = 0.87
c = 0.95

alpha = norm.ppf(1-c, mu, sigma)

VaR = - P * alpha

print(VaR)


7.02596414275

Generalisation: $n$-day VaR

Now we are interested in the $n$-day VaR. For this we model the price movement of our assets in the following $n$ days as independent realisations of the above distribution: $$ X_1, X_2, \ldots, X_n \overset{\text{i.i.d.}}{\sim} \mathcal N(\mu,\sigma^2). $$ It is well known, that $$ \sum_{i=1}^n X_i \sim \mathcal N(n\mu, n\sigma^2), $$ and hence we have $$ \sum_{i=1}^n X_i \geq F^{-1}_{\mathcal N(n\mu, n\sigma^2)} (1-c) = n\mu + \sqrt{n} \sigma \cdot \Phi^{-1}(1-c). $$ This results in the following formula for the $n$-day VaR: $$ \mathrm{VaR}^{(n)} = - P * F^{-1}_{\mathcal N(n\mu, n\sigma^2)} (1-c) $$ and the following Python code:


In [2]:
from scipy.stats import norm
from math import sqrt

P = 8.4546
mu = 0.6
sigma = 0.87
n = 5
c = 0.95

alpha = norm.ppf(1-c, n*mu, sqrt(n)*sigma)

VaR = - P * alpha

print(VaR)


1.6897696242

In [ ]: