1. Learning Objectives

By the end of this lesson, you will be able to:

  • Understand the regulatory framework for market risk (Basel III, FRTB) and the role of internal models.

  • Derive and implement traditional VaR methods (historical, parametric, Monte Carlo) and identify their limitations.

  • Apply AI techniques (GARCH-family neural networks, LSTM volatility forecasting, copula-GANs) for improved risk measurement.

  • Implement Expected Shortfall (ES) using conditional quantile regression and neural networks.

  • Design and execute stress testing scenarios using generative models (GANs, VAEs) and adversarial approaches.

  • Backtest VaR and ES models using Kupiec, Christoffersen, and Acerbi-Szekely tests.


2. Market Risk: Regulatory and Mathematical Foundations

2.1 The Regulatory Landscape

Market risk is the risk of losses arising from movements in market prices. The Basel Committee on Banking Supervision (BCBS) has established a framework for market risk capital requirements.

Basel II/III: Banks must hold capital against market risk using either the Standardized Approach (SA) or the Internal Models Approach (IMA). Under IMA, banks use their own VaR models to calculate capital requirements. The capital charge is based on the 99% 10-day VaR, multiplied by a factor (typically 3) and adjusted for backtesting results.

Fundamental Review of the Trading Book (FRTB): Implemented in 2023, FRTB replaces VaR with Expected Shortfall (ES) at 97.5% confidence over a 10-day horizon for capital calculation. It also introduces a non-modellable risk factors (NMRF) framework for illiquid risks.

2.2 Mathematical Formulation of VaR

The Value-at-Risk at confidence level α over horizon h is the α-quantile of the portfolio return distribution:

P(R_p(h) ≤ -VaR_α(h)) = 1 - α

Equivalently:

VaR_α(h) = -F^{-1}_{R_p(h)}(1 - α)

where F is the cumulative distribution function of portfolio returns.

For a single asset with normally distributed returns (mean μ, volatility σ), the parametric VaR is:

VaR_α(h) = -μ_h + σ_h * Φ^{-1}(α)

where Φ^{-1}(α) is the inverse standard normal CDF (e.g., Φ^{-1}(0.99) ≈ 2.326 for α = 99%).

2.3 Expected Shortfall (ES) – The Coherent Alternative

ES is the expected loss conditional on the loss exceeding VaR:

ES_α(h) = -E[ R_p(h) | R_p(h) ≤ -VaR_α(h) ]

For a continuous distribution, ES can be expressed as the average of VaR across all confidence levels above α:

ES_α(h) = (1/(1-α)) * ∫_{α}^{1} VaR_u(h) du

For a normal distribution, ES has a closed-form:

ES_α(h) = -μ_h + σ_h * ( φ(Φ^{-1}(α)) / (1-α) )

where φ is the standard normal PDF.

ES is a coherent risk measure (sub-additive, monotone, positive homogeneous, translation invariant), whereas VaR is not sub-additive (a portfolio’s VaR can exceed the sum of individual VaRs).


3. Traditional VaR Methods and Their Limitations

3.1 Historical Simulation

The historical simulation method computes VaR using the empirical distribution of historical portfolio returns. It does not assume any distribution.

Algorithm:

  1. Calculate the portfolio return for each day in the historical window (e.g., 500 days).

  2. Sort the returns.

  3. VaR is the α-quantile of the sorted returns (e.g., the 5th percentile for 95% VaR).

Advantages: Non-parametric, captures fat tails and correlations naturally.
Limitations: Assumes the past is representative; does not incorporate volatility clustering; slow to react to changing market conditions.

3.2 Parametric (Variance-Covariance) Method

Assumes returns are multivariate normal. The portfolio variance is:

σ_p² = wᵀ Σ w

where w is the weight vector and Σ is the covariance matrix. VaR is computed as above.

Advantages: Simple, fast, easy to implement.
Limitations: Assumes normality (underestimates tail risk); covariance matrix estimation is unstable; does not capture non-linear instruments (options).

3.3 Monte Carlo Simulation

Generates a large number of random scenarios for the risk factors (e.g., using a multivariate normal or t-distribution), computes the portfolio P&L for each scenario, and takes the quantile.

Algorithm:

  1. Estimate the parameters of the risk factor distribution (mean, covariance).

  2. Generate N scenarios (e.g., 10,000) from the distribution.

  3. For each scenario, compute the portfolio return (including revaluation of options).

  4. Sort the portfolio returns and compute VaR and ES.

Advantages: Can handle non-linear instruments, any distribution, and complex portfolios.
Limitations: Computationally expensive; sensitive to the choice of distribution and parameter estimates.


4. AI-Enhanced Volatility Forecasting

4.1 GARCH Models and Their Neural Extensions

The GARCH (Generalized Autoregressive Conditional Heteroskedasticity) model is a standard tool for volatility forecasting. The GARCH(1,1) model:

σ_t² = ω + α r_{t-1}² + β σ_{t-1}²

where ω > 0α ≥ 0β ≥ 0, and α + β < 1.

The model can be extended with neural GARCH where the conditional variance is a function of past returns and volatilities, with parameters learned by a neural network:

σ_t² = f_θ(r_{t-1}, ..., r_{t-L}, σ_{t-1}², ..., σ_{t-L}²)

where f_θ is a neural network (e.g., with LSTM or fully connected layers). The network is trained by maximizing the likelihood of the returns:

L(θ) = ∑_{t} [ -0.5 * ln(σ_t²) - 0.5 * r_t² / σ_t² ]

This allows for non-linear patterns in volatility, such as asymmetries (leverage effect) that are not captured by standard GARCH.

4.2 LSTM Volatility Forecasting

LSTM networks are well-suited for volatility forecasting because they can capture long-term dependencies.

Architecture:

  1. Input: Historical returns, squared returns, volatility measures (e.g., realized volatility, VIX).

  2. LSTM layers: Extract temporal features.

  3. Output layer: The predicted volatility for the next period (or multi-step ahead).

The loss function is the mean squared error between the predicted volatility and the realized volatility (computed from high-frequency data, e.g., 5-minute returns).

Example:

python
model = Sequential([
    LSTM(64, input_shape=(lookback, n_features), return_sequences=True),
    Dropout(0.2),
    LSTM(32),
    Dropout(0.2),
    Dense(1, activation='softplus')  # ensure positive volatility
])
model.compile(optimizer='adam', loss='mse')
4.3 Copula-GANs for Multivariate Tail Dependence

Copula-GANs combine generative adversarial networks with copula theory to model tail dependence. The idea:

  1. Use a GAN to model the joint distribution of returns directly. The generator maps noise to returns; the discriminator distinguishes real returns from generated ones.

  2. The GAN implicitly captures the dependence structure (including tail dependence) without assuming a specific copula.

Alternatively, we can model the marginal distributions (using GARCH models) and then use a GAN to model the copula of the standardized residuals. This provides a flexible and data-driven method for simulating extreme scenarios with realistic tail dependence.


5. AI for Expected Shortfall (ES) Estimation

5.1 Conditional Quantile Regression (Quantile Regression Neural Networks)

ES is the average of quantiles above the VaR threshold. We can use quantile regression to estimate multiple quantiles:

Q_α(r_t | x_t) = x_t^T β(α)

where β(α) is estimated by minimizing the asymmetric loss:

ρ_α(u) = u * (α - 1{u < 0})

A neural network can be trained to output multiple quantiles simultaneously (multi-quantile loss). The ES is then approximated by averaging the quantiles for α > α_0.

5.2 Direct ES Estimation via Neural Networks

Direct ES estimation minimizes the ES-specific loss function:

L_ES = (1/N) * ∑_{t=1}^{N} [ 1 - (1/(α * N)) * ∑_{t} (y_t - ES_t) * 1{y_t ≤ -ES_t} + ... ]

This loss is more complex but directly optimizes the ES estimate. In practice, we often use quantile regression as a reliable proxy.


6. Stress Testing and Adversarial Scenarios

Stress testing evaluates the portfolio under extreme but plausible scenarios. Traditional stress testing uses predetermined scenarios (e.g., a 30% equity crash). AI can generate more realistic and diverse scenarios.

6.1 Generative Models for Scenario Generation

Variational Autoencoders (VAEs): Learn a low-dimensional latent representation of the market data. We can perturb the latent variables to generate out-of-sample scenarios (e.g., an extreme volatility regime).

GANs: Train a GAN on historical data. The generator can be conditioned on specific risk factors (e.g., interest rate shock). To generate stress scenarios, we sample from the generator with the condition set to an extreme value.

Adversarial attacks: Apply FGSM (Fast Gradient Sign Method) to the historical data to find the smallest perturbation that causes a large portfolio loss. This identifies the most vulnerable directions in the portfolio.

6.2 Reverse Stress Testing

Reverse stress testing asks: “What scenario would cause the portfolio to lose a given amount (e.g., 50% of capital)?” We can use an optimization approach:

min_x ||x - x_0||_2 subject to Portfolio_Loss(x) ≥ Loss_target

where x_0 is the current market state. The optimization can be done using gradient descent if the loss function is differentiable.


7. Backtesting VaR and ES

7.1 Kupiec Test (Proportion of Failures Test)

The Kupiec test checks if the number of exceedances (days where loss > VaR) is consistent with the expected number.

For a sample of T days, let N be the number of exceedances. Under the null hypothesis that the VaR model is correct, N ~ Binomial(T, 1-α). The test statistic is:

LR_K = -2 * ln[ (1-α)^{T-N} α^N / ( (1 - N/T)^{T-N} (N/T)^N ) ]

which is asymptotically χ² with 1 degree of freedom. A high LR_K indicates rejection.

7.2 Christoffersen Test (Conditional Coverage)

The Christoffersen test checks both the unconditional coverage and the independence of exceedances (i.e., that exceedances are not clustered). It tests if the probability of an exceedance depends on whether the previous day had an exceedance.

Let n_{ij} be the number of days with state i followed by state j (0 = no exceedance, 1 = exceedance). The likelihood ratio is:

LR_CC = -2 * ln[ (1-π)^{T-N} π^N / ( (1-π_01)^{n_{00}} π_01^{n_{01}} (1-π_11)^{n_{10}} π_11^{n_{11}} ) ]

where π = N/Tπ_01 = n_{01}/(n_{00}+n_{01})π_11 = n_{11}/(n_{10}+n_{11}). This is asymptotically χ² with 2 degrees of freedom.

7.3 Acerbi-Szekely Test for ES

Backtesting ES is more challenging because we do not observe the conditional expectation. The Acerbi-Szekely test uses the fact that for a correct ES model, the sequence of returns below VaR should have an average equal to ES. The test statistic is:

Z = (1/N) * ∑_{t: r_t < -VaR_t} (r_t / ES_t) - 1

Under the null hypothesis, Z should be close to 0. The test is distribution-free and has good power.


8. Summary for the AI Practitioner

  • Market risk models (VaR, ES) are the foundation of regulatory capital and internal risk management.

  • Traditional methods (historical, parametric, Monte Carlo) have limitations in capturing non-linearities, fat tails, and changing market conditions.

  • AI techniques (neural GARCH, LSTM, copula-GANs) can improve volatility forecasting and tail dependence modeling.

  • ES is the preferred risk measure under FRTB; it can be estimated directly using quantile regression or neural networks.

  • Stress testing should use generative models (VAEs, GANs) to create realistic and diverse extreme scenarios.

  • Backtesting is essential; the Kupiec and Christoffersen tests are standard for VaR, while the Acerbi-Szekely test is used for ES.