VaRCalc Documentation — Dr Krzysztof Ozimek, PRM
VaRCalc Documentation — Dr Krzysztof Ozimek, PRM

VaRCalc — Documentation

Dr Krzysztof Ozimek, PRM  |  Version 1.0

Open Full VaRCalc Back to VaRCalc Download Documentation

VaRCalc — Multi-Method Value at Risk Calculator

VaRCalc is a multi-method Value at Risk calculator covering four estimation approaches — Historical Simulation, Parametric, Monte Carlo, and Cornish-Fisher — with Kupiec backtesting and visual diagnostics. This page documents the mathematical methodology underlying each method.

Introduction

This document explains the methodology and logic implemented in the VaRCalc application for calculating Value at Risk (VaR) based on returns from a single asset or multi-asset portfolio. The tool provides four different VaR estimation methods (there exist far more methods), complemented by statistical validation, descriptive analysis, and graphical visualization through a histogram.

The purpose of this document is to familiarize users with the underlying calculations, assumptions, statistical test, and the procedure for constructing the histogram that together support the results displayed by the calculator.

1. No-formula VaR Definition

\(\mathit{VaR}_{\alpha,h}\) is the potential (maximum) loss, expressed either as a percentage or in monetary terms, that a portfolio may incur with a given probability \(\alpha\) (confidence level) over a fixed time (risk) horizon \(h\).

2. Data

Data should be provided as a single-column CSV file without a header. This column must contain consecutive observations of either a single asset's prices or portfolio values, recorded at regular time intervals. These intervals are treated in the calculations as the base periods, corresponding to \(h = 1\) in the calculator.

3. Methods Implemented in VaRCalc

All the formulas for VaR: \eqref{eq:var-hs}, \eqref{eq:var-param}, \eqref{eq:var-mc}, and \eqref{eq:var-cf} calculate it as a positive value (loss) expressed in relative terms. To express it in percentage form or in dollar terms, it should be multiplied by 100% or by the portfolio value in dollars, respectively. The calculator displays VaRs in dollars.

The most frequently used components applied in the VaR calculations, apart from \(\alpha\) and \(h\), across four presented methods are: \(\mu\), \(\sigma\), and \(\Phi^{-1}(\alpha)\).

\(\mu\) is the sample arithmetic mean of returns (\(r\)) calculated on base-period intervals (\(h = 1\)), as provided in the dataset. Thus, it is calculated as follows:

\[ \mu = \bar{r} = \frac{\displaystyle\sum_{i=1}^{n} r_i}{n} \label{eq:mu} \tag{1} \]

where \(n\) denotes the number of return periods, which is by one less than the number of all raw data points in the dataset.

\(\sigma\) is the corresponding sample standard deviation:

\[ \sigma = \sqrt{\frac{\displaystyle\sum_{i=1}^{n}(r_i - \mu)^{2}}{n - 1}}\,. \label{eq:sigma} \tag{2} \]

In turn, \(\Phi^{-1}(\alpha)\) denotes the quantile of order \(\alpha\) of the standard normal distribution \(N(0,1)\).

3.1 Historical Simulation Method

The approach employed here follows the classic method for a base period (one-period), \(h = 1\). In this case, the VaR is just the quantile of order \(1 - \alpha\), denoted \(q_{1-\alpha}\), of the historical distribution of returns.

When \(h \neq 1\) (which can be optionally specified in the calculator), a scaling method introduced by the author is applied. It consists in multiplying \(q_{1-\alpha}\) by a multiplier:

\[ \frac{\Phi^{-1}(\alpha)\sqrt{h}\,\sigma - h\mu}{\Phi^{-1}(\alpha)\sigma - \mu}\,. \label{eq:hs-multiplier} \tag{3} \]

In the first case (\(h = 1\)), the method is fully non-parametric. In the second case (\(h \neq 1\)), it can be classified as a semi-parametric method (partially non-parametric and partially parametric).

Thus, in the general case VaR following this method can be expressed as:

\[ \mathit{VaR}_{\alpha,h} = -q_{1-\alpha} \cdot \frac{\Phi^{-1}(\alpha)\sqrt{h}\,\sigma - h\mu}{\Phi^{-1}(\alpha)\sigma - \mu}\,. \label{eq:var-hs} \tag{4} \]

The sample quantile \(q_{1-\alpha}\) is calculated as follows:

\[ q_{p} = r_{\lfloor s \rfloor} + \bigl(s - \lfloor s \rfloor\bigr) \cdot \bigl(r_{\lfloor s \rfloor + 1} - r_{\lfloor s \rfloor}\bigr) \label{eq:quantile} \tag{5} \]

where \(s = p \cdot (n + 1)\), and \(\lfloor \cdot \rfloor\) is the rounding down operator.

3.2 Parametric Method

The widely used classical parametric method of VaR calculation is based on the assumption that returns are normally distributed, that is,

\[ r \sim N\!\left(\mu,\, \sigma^{2}\right). \label{eq:normality} \tag{6} \]

To put it mildly, this method is generally not considered the best choice in practice. Nevertheless, it is quite simple:

\[ \mathit{VaR}_{\alpha,h} = \Phi^{-1}(\alpha)\sqrt{h}\,\sigma - h\mu = -\Phi^{-1}(1-\alpha)\sqrt{h}\,\sigma - h\mu. \label{eq:var-param} \tag{7} \]

In this case, VaR is the quantile of order \(\alpha\) of a random variable that follows the distribution \(N\!\left(\mu h,\, \sigma^{2} h\right)\).

3.3 Monte Carlo Simulation Method

The core of the Monte Carlo method is sampling from randomly distributed returns. Depending on whether simple or logarithmic returns are used, the distributions of these returns differ slightly.

The derivation of these distributions starts from the assumption that asset prices or portfolio values follow a geometric Brownian motion:

\[ \frac{dS_t}{S_t} = \mu\, dt + \sigma\sqrt{dt}\, Z \label{eq:gbm} \tag{8} \]

where \(Z \sim N(0,1)\), \(dt\) is a deterministic, very small time increment.

Keeping this in mind, the simple return over horizon \(h\) can be approximated and drawn randomly as:

\[ r_{\text{simple},h} = \frac{\Delta S_{0,h}}{S_0} = \mu h + \sigma\sqrt{h}\, Z \sim N\!\left(\mu h,\, \sigma^{2} h\right), \label{eq:simple-return} \tag{9} \]

while the log-return is given by:

\[ r_{\log,h} = \ln\!\left(\frac{S_h}{S_0}\right) = \left(\mu - \tfrac{1}{2}\sigma^{2}\right)h + \sigma\sqrt{h}\, Z \sim N\!\!\left(\left(\mu - \tfrac{1}{2}\sigma^{2}\right)h,\; \sigma^{2} h\right). \label{eq:log-return} \tag{10} \]

After the random sample of synthetic draws is collected, following formula \eqref{eq:quantile}, the quantile of order \(1 - \alpha\) is computed from this sample. Denoting this quantile by \(q^{MC}_{1-\alpha}\), the Monte Carlo VaR is calculated as:

\[ \mathit{VaR}_{\alpha,h} = -q^{MC}_{1-\alpha}\,. \label{eq:var-mc} \tag{11} \]

3.4 Cornish-Fisher Expansion Method

The Cornish-Fisher VaR approximation is a semi-parametric method used in finance to estimate VaR for distributions that are not normal. It accounts for skewness and kurtosis, which are typical characteristics of many financial return distributions that have "fat tails" (more frequent extreme outcomes than a normal distribution). In this case, VaR is calculated as:

\[ \mathit{VaR}_{\alpha,h} = -\tilde{q}_{1-\alpha}\,\sigma\sqrt{h} - \mu h \label{eq:var-cf} \tag{12} \]

where:

\[ \tilde{q}_{p} = z_{p} + \frac{S}{6\sqrt{h}}\left(z_{p}^{2} - 1\right) + \frac{K_{e}}{24h}\left(z_{p}^{3} - 3z_{p}\right) - \frac{S^{2}}{36h}\left(2z_{p}^{3} - 5z_{p}\right) \label{eq:cf-expansion} \tag{13} \]

where \(z_{p} = \Phi^{-1}(p)\), \(S\) — base-period sample skewness, \(K_{e}\) — base-period sample excess kurtosis.

The base-period sample skewness and kurtosis here are calculated as adjusted measures that correct the commonly used analogues:

  • Skewness:

    \[ g_1 = \frac{m_3}{m_2^{3/2}} \label{eq:skew-unadj} \tag{14} \]
  • Excess kurtosis:

    \[ g_2 = \frac{m_4}{m_2^{2}} - 3 \label{eq:kurt-unadj} \tag{15} \]

where \(\displaystyle m_k = \frac{\sum_{i=1}^{n}(r_i - \mu)^{k}}{n}\) is the sample central moment of order \(k\).

The bias-corrected (adjusted) versions used in the calculation are:

  • Adjusted Skewness:

    \[ S = \frac{\sqrt{n(n-1)}}{n - 2}\, g_1 \label{eq:skew-adj} \tag{16} \]
  • Adjusted Excess Kurtosis:

    \[ K_{e} = \frac{n-1}{(n-2)(n-3)} \left[(n+1)\, g_2 + 6\right]. \label{eq:kurt-adj} \tag{17} \]

4. Kupiec Unconditional Coverage Test

To run the Kupiec test (unconditional coverage test) we use the statistic:

\[ LR_{\text{uc}} = \frac{\pi_{\exp}^{n_1}\left(1 - \pi_{\exp}\right)^{n_0}} {\pi_{\text{obs}}^{n_1}\left(1 - \pi_{\text{obs}}\right)^{n_0}} \label{eq:kupiec-lr} \tag{18} \]

where \(\pi_{\exp} = 1 - \alpha\) is the expected proportion of exceedances, \(\pi_{\text{obs}} = \dfrac{n_1}{n}\) is the observed proportion of exceedances, \(n_1\) is the observed number of exceedances, and \(n_0 = n - n_1\), where \(n\) is the sample size. The asymptotic distribution of the test statistic \(-2\ln LR_{\text{uc}}\) is chi-squared with one degree of freedom.

The null hypothesis of this test states that the observed frequency of exceedances matches the expected frequency — in this case, the calculated VaR can be considered reasonably accurate:

\[ H_0\colon \pi_{\text{obs}} = \pi_{\exp}\,. \label{eq:h0} \tag{19} \]

The alternative hypothesis states that the observed frequency of exceedances differs from the expected one — meaning the calculated VaR is statistically inaccurate. In this case, the model either underestimates risk (too many exceedances) or overestimates risk (too few exceedances):

\[ H_1\colon \pi_{\text{obs}} \neq \pi_{\exp}\,. \label{eq:h1} \tag{20} \]

The null hypothesis is rejected if the p-value of the test statistic, \(-2\ln LR_{\text{uc}}\), is lower than the chosen significance level, for example 0.05.

5. Basic Descriptive Statistics

To calculate the mean and standard deviation of the returns, formulas \eqref{eq:mu} and \eqref{eq:sigma} are used, respectively.

6. Histogram Construction

When creating the histogram, the Rice rule is applied to determine the number of bins. Applying this rule and limiting the total number of bins to 25, the number of bins in the histogram is:

\[ \min\!\left\{\left\lceil 2 \cdot \sqrt[3]{n} \right\rceil,\; 25\right\} \label{eq:rice} \tag{21} \]

where \(\lceil\,\cdot\,\rceil\) is the rounding up operator.

Open Full VaRCalc Back to VaRCalc Download Documentation