VaR and ES application — R exploration

Reproduce the VaR and ES application analyses using R code running directly in the browser

You can reproduce the VaR and ES application analyses in R using the code blocks below. Each block runs directly in the browser — edit the parameters and re-run to experiment.

Loading the data

1. Unconditional VaR and ES

Under the normal distribution assumption, VaR and ES at confidence level \(\alpha\) are:

\[ \text{VaR}_\alpha = -\mu - \sigma \, \Phi^{-1}(1-\alpha), \qquad \text{ES}_\alpha = -\mu + \sigma \, \frac{\phi(\Phi^{-1}(1-\alpha))}{1 - \alpha} \]

Unconditional VaR and ES at multiple confidence levels

Returns with unconditional VaR threshold

2. RiskMetrics VaR and ES

The RiskMetrics model uses an exponentially weighted moving average (EWMA) for volatility:

\[ \sigma^2_{t+1} = \lambda \, \sigma^2_t + (1 - \lambda) \, R^2_t \]

Returns with RiskMetrics VaR and ES

RiskMetrics annualised volatility

3. Rolling window VaR and ES

The rolling window approach computes the sample standard deviation over the most recent \(W\) days:

Returns with rolling window VaR and ES

Rolling window vs RiskMetrics VaR

4. Time horizon scaling

The square-root-of-time rule scales 1-day risk measures to a \(T\)-day horizon:

\[ T\text{-day VaR} = 1\text{-day VaR} \times \sqrt{T}, \qquad T\text{-day ES} = 1\text{-day ES} \times \sqrt{T} \]