Docs / nablatensor-risk / com.nablatensor.risk

final class

ValueAtRisk

Value at Risk and Expected Shortfall by the three standard routes:

  • Historical / full-revaluation — an empirical quantile of a PnlVector. Feed it a bootstrapped-scenario revaluation and this is full-revaluation VaR; feed it a window of realised daily P&L and it is historical-simulation VaR.
  • Delta-normalz_alpha * sqrt(s' Sigma s), the variance-covariance method, exact for a linear portfolio and a Gaussian risk-factor move.
  • Delta-gamma Cornish-Fisher — the quadratic P&L delta' x + 0.5 x' Gamma x has a skewed, fat-tailed distribution; its first four cumulants are computed in closed form and the quantile comes from a Cornish-Fisher expansion.

Every result is a positive loss quoted at confidence alpha (e.g. 0.99). Multi-day figures use the square-root-of-time scaling the caller supplies via horizonDays (a one-day covariance times sqrt(horizonDays)).

Methods

static double historical(PnlVector sample, double alpha)

Empirical VaR: the alpha-quantile of the loss sample, linearly interpolated.

static double expectedShortfall(PnlVector sample, double alpha)

Empirical Expected Shortfall: the mean loss in the (1 - alpha) tail beyond VaR.

static double deltaNormal(double[] sensitivities, double[][] covariance, double alpha, double horizonDays)
sensitivities
dP/dx per risk factor (the adjoint gradient)
covariance
one-period risk-factor covariance matrix, same order
alpha
confidence, e.g. 0.99
horizonDays
holding period; the covariance is scaled by sqrt(horizonDays)
static double deltaNormal(Sensitivities sensitivities, List<RiskFactor> order, double[][] covariance, double alpha, double horizonDays)

Delta-normal from a Sensitivities vector and an explicit factor order.

static QuadraticCumulants quadraticCumulants(double[] delta, double[][] gamma, double[][] sigma)

Cumulants of Q = delta' x + 0.5 x' Gamma x for x ~ N(0, Sigma). Diagonalises Sigma^{1/2} Gamma Sigma^{1/2} so Q becomes a sum of independent a_i y_i + 0.5 b_i y_i^2 terms with y_i ~ N(0,1).

static double deltaGammaCornishFisher(double[] delta, double[][] gamma, double[][] sigma, double alpha, double horizonDays)

Delta-gamma VaR via a fourth-order Cornish-Fisher expansion of the loss quantile.