Package com.quantfinlib.risk


package com.quantfinlib.risk
Risk: measurement, decomposition, credit/limits, and model validation. Portfolio analytics (RiskMetrics, PortfolioRiskAnalyzer, CorrelationMatrix, RiskMetricRegistry for custom metrics); pre-trade and credit controls (PreTradeLimitChecker, CounterpartyExposureTracker, SettlementRiskAnalyzer for Herstatt windows, ConcentrationRisk); and validation — VarBacktest (Kupiec, Christoffersen, conditional coverage) turns produced VaR numbers into validated ones.

The market-risk workflow (docs/MARKET_RISK.md): Dependence (Spearman, Kendall's τ, the elliptical-copula bridge), Pca (Jacobi — level/slope/curvature honesty about factor counts), GaussianCopula (Gaussian + Student-t samplers; the t has the tail dependence 2008 taught everyone the Gaussian lacks), VarEngine (portfolio delta-normal / Monte Carlo / delta-gamma Cornish-Fisher / historical, each with expected shortfall), ExtremeValueTheory (POT/GPD tail fits that refuse a finite ES when the tail has no mean), StressTester (scenarios, ladders, and closed-form reverse stress with an implausibility verdict), FrtbEs (the 97.5% ES liquidity-horizon cascade, stressed calibration, Basel traffic light — styled after BCBS MAR33, not certified) and PnlAttribution (the FRTB PLAT: Spearman + Kolmogorov-Smirnov with green/amber/red zones).

  • Class
    Description
    COMPONENT VaR — the answer to the risk committee's actual question.
     
    Concentration risk metrics over exposures (by asset, counterparty, sector, currency, ...): Herfindahl-Hirschman index, effective number of positions, top-N share, and single-name limit breaches.
    Correlation and covariance matrices from a returns matrix laid out as returns[asset][time].
    Counterparty credit exposure modeling with netting: Current exposure — max(0, net mark-to-market) per netting set. Potential future exposure — notional add-ons by tenor bucket (BIS current-exposure-method style FX factors: <1y 1%, 1–5y 5%, >5y 7.5%).
     
    LEDOIT-WOLF covariance shrinkage (2004, "A well-conditioned estimator for large-dimensional covariance matrices") — the standard fix for the dirty secret of portfolio optimization: the sample covariance matrix is the MAXIMALLY overfit estimate.
     
    Rank-based dependence measures — what Pearson correlation misses.
    Extreme value theory via peaks-over-threshold — the statistically honest way to ask about quantiles BEYOND the sample.
    A fitted POT tail model.
    FRTB Internal Models Approach expected shortfall — the market-risk capital measure that replaced 10-day VaR: ES at 97.5%, computed on a base 10-day horizon and scaled up across LIQUIDITY HORIZONS (how long each risk factor class realistically takes to exit under stress: 10 days for major FX and rates, up to 120 for exotic credit), then anchored to a STRESSED period:
    The Basel backtesting traffic light over 250 days of 99% VaR exceptions: GREEN ≤ 4 (model fine), AMBER 5-9 (capital multiplier rises), RED ≥ 10 (model presumed wrong).
    Gaussian and Student-t copula samplers — dependence separated from marginals, which is the entire point of copula modeling: "these five factors co-move like THIS" (the copula) is a different statement from "each factor's own distribution looks like THAT" (the marginals), and gluing arbitrary marginals to a chosen dependence structure is how joint risk scenarios get built.
    Principal component analysis of a covariance matrix — the risk-factor compressor.
    FRTB P&L attribution test (PLAT) — the exam a risk MODEL must pass to keep internal-model approval: does the risk engine's theoretical P&L (RTPL — what the model's factors and pricers say the desk made) actually track the desk's hypothetical P&L (HPL — what revaluing the real book on real prices says)?
    The PLAT verdict for one desk over one window.
     
    Multi-asset portfolio of positions with live price updates.
     
    Portfolio-level risk engine: portfolio VaR/CVaR/volatility, asset-level risk, exposure analysis, correlation analysis, and risk decomposition (marginal contribution to risk).
    Full risk report.
    Pre-trade risk gate: validates every order against configured limits before it reaches the market — order size, notional, resulting position, price collar versus a reference mid, restricted symbols, and counterparty credit headroom.
     
     
    Pluggable risk metric over a periodic return series.
    Custom Risk Metrics Framework: registry of built-in and user-defined risk metrics, evaluated together over a return series.
    Core quantitative risk metrics.
    Settlement (Herstatt) risk: the exposure created when you pay away one currency before receiving the other leg.
    One settlement instruction pair: we pay one leg and receive the other.
    Stress testing and scenario analysis — the risk numbers VaR cannot give you, because VaR is calibrated to the recent past and a stress test deliberately is not.
    The reverse-stress answer: the most-probable shock vector and its distance.
    VaR model validation: do the exceptions (losses beyond VaR) occur at the promised rate, and independently?
     
    Portfolio Value-at-Risk, all four classic flavors over one input shape: factor EXPOSURES (currency P&L per unit factor return — a delta vector) against a factor covariance matrix or a factor-return history.
    Revalues the book under one scenario's factor moves.
    VaR and ES from Gaussian Monte Carlo factor scenarios.