Class StressTester

java.lang.Object
com.quantfinlib.risk.StressTester

public final class StressTester extends Object
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. Three modes over one book representation (factor exposures δ, optional gammas Γ):
  • Named scenarios — a vector of factor shocks (fractions: −0.20 = down 20%) applied through the delta-gamma P&L δ'Δx + ½Δx'ΓΔx. Ship-your-own scenarios, plus blackMonday1987(), lehman2008() and covidMarch2020() as STARTING TEMPLATES — stylized single-day shock magnitudes from the public record for a [equity, rates(bp/1e4), FX-USD, commodity, vol-points/1e2] factor ordering, documented as approximations to edit, not gospel to trust;
  • Sensitivity ladders — one factor swept over a shock range, everything else flat: the "what does ±X% do" table every risk report carries;
  • Reverse stress — the question regulators now ask first: "what move BREAKS us?" For a linear book under covariance Σ, the most-probable shock producing a target loss L has the closed form Δx* = −(L/(δ'Σδ))·Σδ: the worst direction is along Σδ, and its Mahalanobis distance L/√(δ'Σδ) says how implausible the breaking move is (in "sigmas") — a book broken by a 2σ move has a problem TODAY.

Losses are returned as negative P&L (a scenario that makes money reports positive). Research lane, deterministic, static.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    The reverse-stress answer: the most-probable shock vector and its distance.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    1987-10-19 stylized: equities −20%, flight-to-quality rates, vol explosion.
    static double[]
    2020-03-16 stylized: −12% equities, −30bp, USD squeeze, oil collapse, VIX ATH.
    static double[]
    2008-09-15 (Lehman week) stylized: −9% equities, −40bp, USD bid, oil down, vol +16pts.
    reverseStress(double[] exposures, double[][] covariance, double targetLoss)
    The most-probable factor move (under Gaussian factors with covariance Σ) that loses exactly targetLoss on a linear book — closed form, no search.
    static double
    scenarioPnl(double[] exposures, double[] shocks)
    Delta-only scenario P&L: δ'Δx.
    static double
    scenarioPnl(double[] exposures, double[][] gamma, double[] shocks)
    Delta-gamma scenario P&L: δ'Δx + ½Δx'ΓΔx.
    static double[]
    sensitivityLadder(double[] exposures, double[][] gamma, int factor, double range, int steps)
    The delta-gamma ladder: the same sweep with the swept factor's own curvature ½·Γ_ff·shock² included — the rung table a short-gamma book actually needs, since its down rungs are WORSE than the linear ladder admits (cross-gammas stay out: the other factors are flat by construction).
    static double[]
    sensitivityLadder(double[] exposures, int factor, double range, int steps)
    One factor swept over [−range, +range] in steps increments, everything else flat — the sensitivity ladder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • scenarioPnl

      public static double scenarioPnl(double[] exposures, double[] shocks)
      Delta-only scenario P&L: δ'Δx.
    • scenarioPnl

      public static double scenarioPnl(double[] exposures, double[][] gamma, double[] shocks)
      Delta-gamma scenario P&L: δ'Δx + ½Δx'ΓΔx.
    • sensitivityLadder

      public static double[] sensitivityLadder(double[] exposures, int factor, double range, int steps)
      One factor swept over [−range, +range] in steps increments, everything else flat — the sensitivity ladder. Returns P&L per rung, ascending shock. DELTA-ONLY: curvature is ignored — a book carrying gamma needs the delta-gamma overload, or the down rungs will look symmetric when they are not.
    • sensitivityLadder

      public static double[] sensitivityLadder(double[] exposures, double[][] gamma, int factor, double range, int steps)
      The delta-gamma ladder: the same sweep with the swept factor's own curvature ½·Γ_ff·shock² included — the rung table a short-gamma book actually needs, since its down rungs are WORSE than the linear ladder admits (cross-gammas stay out: the other factors are flat by construction).
    • reverseStress

      public static StressTester.ReverseStress reverseStress(double[] exposures, double[][] covariance, double targetLoss)
      The most-probable factor move (under Gaussian factors with covariance Σ) that loses exactly targetLoss on a linear book — closed form, no search. The returned Mahalanobis distance is the plausibility verdict: how many "joint sigmas" away the breaking scenario sits.
      Parameters:
      targetLoss - positive loss to reverse-engineer, currency units
    • blackMonday1987

      public static double[] blackMonday1987()
      1987-10-19 stylized: equities −20%, flight-to-quality rates, vol explosion.
    • lehman2008

      public static double[] lehman2008()
      2008-09-15 (Lehman week) stylized: −9% equities, −40bp, USD bid, oil down, vol +16pts.
    • covidMarch2020

      public static double[] covidMarch2020()
      2020-03-16 stylized: −12% equities, −30bp, USD squeeze, oil collapse, VIX ATH.