Package com.quantfinlib.risk


@NullMarked package com.quantfinlib.risk
Risk measurement, decomposition, 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 and conditional coverage tests of a VaR series).

The market-risk workflow (docs/MARKET_RISK.md): Dependence (Spearman, Kendall's τ, the elliptical-copula bridge), Pca (Jacobi eigen-decomposition; level, slope and curvature factors), GaussianCopula (Gaussian and Student-t samplers; the t copula has tail dependence, the Gaussian has none), 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).

Regulatory capital: FrtbSa, FrtbDrc, FrtbRrao and FrtbNmrf (FRTB standardised approach and NMRF, styled after BCBS d457, not certified), and SaCcr with SaCcrHaircuts (BCBS 279).

  • 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 using the FX/gold factors of the Basel Current Exposure Method (1988 Accord Annex 3 as amended in 1995: <1y 1%, 1–5y 5%, >5y 7.5%), applied to every trade whatever its product.
     
    Ledoit-Wolf covariance shrinkage (2004, "A well-conditioned estimator for large-dimensional covariance matrices"): the standard fix for the dirty secret of portfolio optimization.
     
    Rank-based dependence measures — what Pearson correlation misses.
    Extreme value theory via peaks-over-threshold — the statistically principled way to ask about quantiles beyond the sample.
    A fitted POT tail model.
    A maximum-likelihood GPD fit with asymptotic standard errors Var ξ̂ = (1+ξ)²/m, Var β̂ = 2β²(1+ξ)/m (Smith 1987).
    Fundamental equity factor risk model in the Barra USE4 style: a market factor, one dummy factor per sector and standardised style factors, estimated by weighted cross-sectional regression each period.
    Ex-ante risk of one portfolio under the model.
    Estimation settings.
    FRTB standardised default risk charge (DRC) for non-securitisation positions, styled after BCBS d457 chapter MAR22.
    Default risk weights by credit quality (MAR22.24 Table 2, verified).
    A net JTD per obligor (signed) and its risk weight.
    FRTB standardised default risk charge (DRC) for securitisations, both outside the correlation trading portfolio (non-CTP, MAR22.27 to MAR22.35) and inside it (CTP, MAR22.36 to MAR22.45).
    The 11 asset classes of MAR22.31(2)(a), plus the corporates bucket of MAR22.31(1).
    Long-term rating grades of SEC-ERBA Tables 2 and 4 (CRE42.4, CRE42.13).
    Short-term rating grades of SEC-ERBA Tables 1 and 3 (CRE42.2, CRE42.12).
    A net JTD of one tranche (signed, positive long) and its DRC risk weight per unit of JTD.
    A non-CTP bucket (MAR22.31, MAR22.32).
    A net tranche JTD tagged with its bucket key (a FrtbDrcSecuritisation.NonCtpBucket, or an index name for the CTP).
    The four regions of MAR22.31(2)(b).
    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).
    Capital for non-modellable risk factors (NMRF) under the FRTB internal models approach, styled after BCBS d457 chapter MAR33.
    FRTB residual risk add-on, styled after BCBS d457 chapter MAR23.
    FRTB standardised approach, sensitivities-based method (SBM), styled after BCBS d457 (January 2019) chapter MAR21.
    One bucket: weighted sensitivities and the medium-scenario intra-bucket correlation matrix (diagonal ignored).
    Bucket-level result.
    Commodity parameters, buckets 1-11.
    Credit spread risk, non-securitisation (MAR21.51 to MAR21.57).
    Equity (spot) parameters, buckets 1-13.
    FX parameters.
    General interest rate risk parameters.
    One risk class: delta, vega and curvature inputs (any may be empty).
    Correlation scenarios of MAR21.
    CSR securitisation (non-CTP), buckets 1-25 (MAR21.62 to MAR21.71).
    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.
    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.
     
     
    Factorisation and repair of symmetric positive semi-definite matrices: the one place in the risk, simulation and copula code that decides what a "valid covariance" is.
    Eigenvalues (descending) and matching unit eigenvectors vectors[k].
    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.
    Standardised approach for counterparty credit risk, SA-CCR (Basel Committee, "The standardised approach for measuring counterparty credit risk exposures", BCBS 279, March 2014, Annex 4).
    The five SA-CCR asset classes.
    The four commodity hedging sets (para 161).
    Credit rating buckets and their supervisory factors (Table 2).
    Hedging-set kind of a trade (paras 162-163) and its multiplier on the supervisory factor.
    Margin agreement terms for a margined netting set.
    SA-CCR outputs for one netting set.
    One part of a netting set for SaCcr.subNettingSets(List): the trades under one margin agreement (or the unmargined trades when margin is null) and the haircut collateral that belongs to them.
    Supervisory haircuts for the collateral C and the NICA that enter SA-CCR.
    Collateral kinds of the supervisory haircut table.
    Issue rating buckets for debt collateral.
    Debt classes of the CRE22.50 table (jurisdictions without external ratings).
    Which supervisory haircut table to use.
    One derivative as the SA-CCR sees it (BCBS 279, March 2014, Annex 4): the asset class, the hedging-set key, the inputs to the trade-level adjusted notional and the supervisory delta.
    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 is not.
    The reverse-stress answer: the most-probable shock vector and its distance.
    Empirical value-at-risk and expected shortfall of a loss sample, with one tail definition shared by every class in the library that reports them.
    VaR and ES of one sample, both in loss units.
    VaR model validation: do the exceptions (losses beyond VaR) occur at the promised rate, and independently?
    Result of the Basel traffic-light test.
     
    Backtesting zones of the Basel internal models approach (MAR32.8).
    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.