Calculate Delta Risk With QuantLib

QuantLib provides the building blocks to value vanilla interest-rate swaps and compute sensitivities such as DV01/Delta. Rather than relying on undocumented helpers, combine curve bootstrapping, pricing engines, and a bump-and-reprice workflow to produce regulator-ready risk numbers.

Step-by-Step Workflow

  1. Bootstrap the Curve
    • Load deposit, futures, and swap quotes into ql.SimpleQuote handles.
    • Build a ql.PiecewiseLinearZero or ql.PiecewiseLogCubicDiscount term structure.
    • Store the curve in a ql.RelinkableYieldTermStructureHandle so you can switch between base and bumped states.
  2. Define the Swap
    • Create a schedule with ql.Schedule and instantiate a ql.VanillaSwap with the correct fixed/floating conventions.
    • Attach a ql.DiscountingSwapEngine that references your discount curve handle.
  3. Compute the Base NPV
    • Call swap.NPV() (and optionally fixedLegBPS() / floatingLegBPS()) to establish the baseline valuation.
  4. Apply a Bump
    • Copy the underlying quotes, add a parallel 1 bp shift (0.0001), rebuild the curve, and re-link the handle.
    • Reprice the swap and calculate (bumped_npv - base_npv) / 0.0001.
    • For key-rate DV01, bump individual maturities or use pillar-specific shock vectors.

Practical Tips

  • Catch ql.BootstrapError exceptions so calibration failures do not silently skew sensitivity outputs.
  • Prefer central differences (±0.5 bp) when you need smoother Greeks for long-dated trades.
  • Align tenors, calendars, and day-counts with your enterprise risk system to keep reported numbers consistent.

References

Risk Notice

Interest-rate sensitivities influence regulatory capital, hedge accounting, and limit monitoring. Validate your implementation against an independent benchmark and consult model-risk teams before releasing changes to production.