Delta Risk#

Using Solvers#

The Solver serves two purposes:

  • solving curves relative to calibrating instruments and market rates,

  • obtaining risk sensitivities to those calibrating instruments.

The mathematical processes involved here are technical and better explained in the supplementary material (TODO link). Essentially a mapping is created between the fundamental derivatives obtained through AD and the calibrating instrument rates. The Solver stores and uses this mapping to create the delta().

In [1]: usd_curve = Curve(
   ...:     nodes={
   ...:         dt(2022, 1, 1): 1.0,
   ...:         dt(2022, 2, 1): 1.0,
   ...:         dt(2022, 4, 1): 1.0,
   ...:         dt(2023, 1, 1): 1.0,
   ...:      },
   ...:     id="sofr",
   ...: )
   ...: 

In [2]: instruments = [
   ...:     IRS(dt(2022, 1, 1), "1m", "A", curves="sofr"),
   ...:     IRS(dt(2022, 1, 1), "3m", "A", curves="sofr"),
   ...:     IRS(dt(2022, 1, 1), "1y", "A", curves="sofr"),
   ...: ]
   ...: 

In [3]: usd_solver = Solver(
   ...:     curves=[usd_curve],
   ...:     id="usd_sofr",
   ...:     instruments=instruments,
   ...:     s=[2.5, 3.25, 4.0],
   ...:     instrument_labels=["1m", "3m", "1y"],
   ...: )
   ...: 
SUCCESS: `func_tol` reached after 3 iterations (levenberg_marquardt), `f_val`: 2.479770306840636e-13, `time`: 0.0030s

In [4]: irs = IRS(
   ...:     effective=dt(2022, 1, 1),
   ...:     termination="6m",
   ...:     frequency="A",
   ...:     currency="usd",
   ...: )
   ...: 

In [5]: irs.curves = "sofr"

In [6]: irs.delta(solver=usd_solver)
Out[6]: 
local_ccy                    usd
display_ccy                  usd
type        solver   label      
instruments usd_sofr 1m     0.00
                     3m    16.59
                     1y    32.24

A typical scenario in which FX exposures are created (if the instrument is not multi-currency) is when base is set to something other than local currency.

In [7]: fxr = FXRates({"eurusd": 1.1})

In [8]: irs.fixed_rate = 6.0  # create a negative NPV of approx -11.2k USD

In [9]: irs.delta(solver=usd_solver, base="eur", fx=fxr)
Out[9]: 
local_ccy                     all   usd      
display_ccy                   eur   eur   usd
type        solver   label                   
instruments usd_sofr 1m      0.00  0.00  0.00
                     3m     15.25 15.25 16.77
                     1y     29.64 29.64 32.60
fx          fx       eurusd  0.93  0.93  0.00

The NPV of the IRS in EUR here is approximately -10.2k. If the EURUSD exchange rate increases by 1000 pips to 1.20, then the EUR NPV increases to only about -9.3k, meaning a gain of about 900 EUR. The FX sensitivity of about 0.9 EUR/pip is visible in the delta exposure dataframe.