Gradients#
- class rateslib.solver.Gradients#
Bases:
objectA catalogue of all the gradients used in optimisation routines and risk sensitivties.
Attributes Summary
2d Jacobian array of calibrating instrument rates with respect to curve variables, of size (n, m);
3d array of second derivatives of calibrating instrument rates with respect to curve variables, of size (n, n, m);
3d array of second derivatives of calibrating instrument rates with respect to curve variables for all
Solversincludingpre_solvers, of size (pre_n, pre_n, pre_m);3d array of second derivatives of curve variables with respect to calibrating instruments, of size (m, m, n);
3d array of second derivatives of curve variables with respect to calibrating instruments, of size (pre_m, pre_m, pre_n);
2d Jacobian array of curve variables with respect to calibrating instruments, of size (m, n);
2d Jacobian array of curve variables with respect to calibrating instruments including all pre solvers attached to the Solver, of size (pre_m, pre_n).
Alias of
J.Alias of
J2.Alias of
J2_pre.Methods Summary
grad_f_Pbase(npv, grad_f_P, f, fx_vars)1d array of derivatives of base currency PV with respect to FX rate variables, of size (len(fx_vars)).
grad_f_Ploc(npv, fx_vars)1d array of derivatives of local currency PV with respect to FX rate variable, of size (len(fx_vars)).
grad_f_f(f, fx_vars)1d array of total derivatives of FX conversion rate with respect to FX rate variables, of size (len(fx_vars));
grad_f_fT_Pbase(npv, grad_f_fT_P, f, fx_vars)2d array of derivatives of base currency PV with respect to calibrating instrument rate variables, of size (pre_m, pre_m).
grad_f_fT_Ploc(npv, fx_vars)2d array of derivatives of local currency PV with respect to FX rate variables, of size (len(fx_vars), len(fx_vars)).
grad_f_fT_f_pre(f, fx_vars)2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
grad_f_f_rT_pre(fx_vars)3d array of second derivatives of calibrating instrument rates with respect to FX rates, of size (len(fx_vars), len(fx_vars), pre_m);
grad_f_f_vT_pre(fx_vars)3d array of second derivatives of curve variables with respect to FX rates, of size (len(fx_vars), len(fx_vars), pre_n);
grad_f_rT_pre(fx_vars)2d Jacobian array of calibrating instrument rates with respect to FX rate variables, of size (len(fx_vars), pre_m);
grad_f_sT_Pbase(npv, grad_f_sT_P, f, fx_vars)2d array of derivatives of base currency PV with respect to FX variables and calibrating instrument rate variables, of size (len(fx_vars), pre_m).
grad_f_sT_Ploc(npv, fx_vars)2d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m, pre_m).
grad_f_sT_f_pre(f, fx_vars)2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
grad_f_s_vT_pre(fx_vars)3d array of second derivatives of curve variables with respect to FX rates and calibrating instrument rates, of size (len(fx_vars), pre_m, pre_n);
grad_f_vT_pre(fx_vars)2d array of the derivatives of curve variables with respect to FX rates, of size (len(fx_vars), pre_n).
grad_f_v_rT_pre(fx_vars)3d array of second derivatives of calibrating instrument rates with respect to FX rates and curve variables, of size (len(fx_vars), pre_n, pre_m);
grad_s_Pbase(npv, grad_s_P, f)1d array of derivatives of base currency PV with respect to calibrating instruments, of size (pre_m).
grad_s_Ploc(npv)1d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m).
grad_s_f_pre(f)1d array of FX conversion rate with respect to calibrating instruments, of size (pre_m);
grad_s_sT_Pbase(npv, grad_s_sT_P, f)2d array of derivatives of base currency PV with respect to calibrating instrument rate variables, of size (pre_m, pre_m).
grad_s_sT_Ploc(npv)2d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m, pre_m).
2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
gradp_f_vT_Ploc(npv, fx_vars)2d array of (partial) derivatives of local currency PV with respect to FX rate variables and curve variables, of size (len(fx_vars), pre_n).
Attributes Documentation
- J#
2d Jacobian array of calibrating instrument rates with respect to curve variables, of size (n, m);
\[[J]_{i,j} = [\nabla_\mathbf{v} \mathbf{r^T}]_{i,j} = \frac{\partial r_j}{\partial v_i}\]Depends on
self.r.
- J2#
3d array of second derivatives of calibrating instrument rates with respect to curve variables, of size (n, n, m);
\[[J2]_{i,j,k} = [\nabla_\mathbf{v} \nabla_\mathbf{v} \mathbf{r^T}]_{i,j,k} = \frac{\partial^2 r_k}{\partial v_i \partial v_j}\]Depends on
self.r.
- J2_pre#
3d array of second derivatives of calibrating instrument rates with respect to curve variables for all
Solversincludingpre_solvers, of size (pre_n, pre_n, pre_m);\[[J2]_{i,j,k} = [\nabla_\mathbf{v} \nabla_\mathbf{v} \mathbf{r^T}]_{i,j,k} = \frac{\partial^2 r_k}{\partial v_i \partial v_j}\]Depends on
self.randpre_solvers.J2.
- grad_s_s_vT#
3d array of second derivatives of curve variables with respect to calibrating instruments, of size (m, m, n);
\[[\nabla_\mathbf{s} \nabla_\mathbf{s} \mathbf{v^T}]_{i,j,k} = \frac{\partial^2 v_k}{\partial s_i \partial s_j}\]
- grad_s_s_vT_pre#
3d array of second derivatives of curve variables with respect to calibrating instruments, of size (pre_m, pre_m, pre_n);
\[[\nabla_\mathbf{s} \nabla_\mathbf{s} \mathbf{v^T}]_{i,j,k} = \frac{\partial^2 v_k}{\partial s_i \partial s_j}\]
- grad_s_vT#
2d Jacobian array of curve variables with respect to calibrating instruments, of size (m, n);
\[[\nabla_\mathbf{s}\mathbf{v^T}]_{i,j} = \frac{\partial v_j}{\partial s_i} = \mathbf{J^+}\]
- grad_s_vT_pre#
2d Jacobian array of curve variables with respect to calibrating instruments including all pre solvers attached to the Solver, of size (pre_m, pre_n).
\[[\nabla_\mathbf{s}\mathbf{v^T}]_{i,j} = \frac{\partial v_j}{\partial s_i} = \mathbf{J^+}\]
- grad_v_rT#
Alias of
J.
- grad_v_v_rT#
Alias of
J2.
- grad_v_v_rT_pre#
Alias of
J2_pre.
Methods Documentation
- grad_f_Pbase(npv, grad_f_P, f, fx_vars)#
1d array of derivatives of base currency PV with respect to FX rate variables, of size (len(fx_vars)).
\[\nabla_\mathbf{s} P^{bas}(\mathbf{v(s, f)}) = \nabla_\mathbf{s} P^{loc}(\mathbf{v(s, f)}) f_{loc:bas} + P^{loc} \nabla_\mathbf{s} f_{loc:bas}\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
grad_f_P – ndarray The local currency delta risks w.r.t. FX pair variables.
f – Dual or Dual2 The local:base FX rate.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_Ploc(npv, fx_vars)#
1d array of derivatives of local currency PV with respect to FX rate variable, of size (len(fx_vars)).
\[\begin{split}\\nabla_\\mathbf{f} P^{loc}(\\mathbf{v(s, f), f}) = \\frac{\\partial P^{loc}}{\\partial f_i}+ \\frac{\partial v_z}{\\partial f_i} \\frac{\\partial P^{loc}}{\\partial v_z}\end{split}\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_f(f, fx_vars)#
1d array of total derivatives of FX conversion rate with respect to FX rate variables, of size (len(fx_vars));
\[[\nabla_\mathbf{f} f_{loc:bas}]_{i} = \frac{d f}{d f_i}\]
- grad_f_fT_Pbase(npv, grad_f_fT_P, f, fx_vars)#
2d array of derivatives of base currency PV with respect to calibrating instrument rate variables, of size (pre_m, pre_m).
\[\nabla_\mathbf{s} \nabla_\mathbf{s}^\mathbf{T} P^{bas}(\mathbf{v(s, f), f})\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
grad_f_fT_P – ndarray The local currency gamma risks w.r.t. FX rate variables.
f – Dual or Dual2 The local:base FX rate.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_fT_Ploc(npv, fx_vars)#
2d array of derivatives of local currency PV with respect to FX rate variables, of size (len(fx_vars), len(fx_vars)).
\[\nabla_\mathbf{f} \nabla_\mathbf{s}^\mathbf{T} P^{loc}(\mathbf{v(s, f), f}) = \frac{ d^2 P^{loc}(\mathbf{v(s, f), f)}) }{d f_i d f_j}\]- Parameters:
npv – Dual2 A local currency NPV of a period of a leg.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_fT_f_pre(f, fx_vars)#
2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
\[[\nabla_\mathbf{f} \nabla_\mathbf{f}^\mathbf{T} f_{loc:bas}(\mathbf{v(s, f), f)})]_{i,j} = \frac{d^2 f}{d f_i d f_j}\]
- grad_f_f_rT_pre(fx_vars)#
3d array of second derivatives of calibrating instrument rates with respect to FX rates, of size (len(fx_vars), len(fx_vars), pre_m);
\[[\nabla_\mathbf{f} \nabla_\mathbf{f} \mathbf{r^T}]_{i,j,k} = \frac{\partial^2 r_k}{\partial f_i \partial f_j}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities.
- grad_f_f_vT_pre(fx_vars)#
3d array of second derivatives of curve variables with respect to FX rates, of size (len(fx_vars), len(fx_vars), pre_n);
\[[\nabla_\mathbf{f} \nabla_\mathbf{f} \mathbf{v^T}]_{i,j,k} = \frac{\partial^2 v_k}{\partial f_i \partial f_j}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities.
- grad_f_rT_pre(fx_vars)#
2d Jacobian array of calibrating instrument rates with respect to FX rate variables, of size (len(fx_vars), pre_m);
\[[\nabla_\mathbf{f}\mathbf{r^T}]_{i,j} = \frac{\partial r_j}{\partial f_i}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities.
- grad_f_sT_Pbase(npv, grad_f_sT_P, f, fx_vars)#
2d array of derivatives of base currency PV with respect to FX variables and calibrating instrument rate variables, of size (len(fx_vars), pre_m).
\[\nabla_\mathbf{f} \nabla_\mathbf{s}^\mathbf{T} P^{bas}(\mathbf{v(s, f), f})\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
grad_f_sT_P – ndarray The local currency gamma risks w.r.t. FX rate variables and calibrating instrument variables.
f – Dual or Dual2 The local:base FX rate.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_sT_Ploc(npv, fx_vars)#
2d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m, pre_m).
\[\nabla_\mathbf{f} \nabla_\mathbf{s}^\mathbf{T} P^{loc}(\mathbf{v(s, f), f}) = \frac{ d^2 P^{loc}(\mathbf{v(s, f), f)}) }{d f_i \partial s_j}\]- Parameters:
npv – Dual2 A local currency NPV of a period of a leg.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity
- grad_f_sT_f_pre(f, fx_vars)#
2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
\[[\nabla_\mathbf{f} \nabla_\mathbf{s}^\mathbf{T} f_{loc:bas}(\mathbf{v(s, f), f)})]_{i,j} = \frac{d^2 f}{d f_i \partial s_j}\]
- grad_f_s_vT_pre(fx_vars)#
3d array of second derivatives of curve variables with respect to FX rates and calibrating instrument rates, of size (len(fx_vars), pre_m, pre_n);
\[[\nabla_\mathbf{f} \nabla_\mathbf{s} \mathbf{v^T}]_{i,j,k} = \frac{\partial^2 v_k}{\partial f_i \partial s_j}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities.
- grad_f_vT_pre(fx_vars)#
2d array of the derivatives of curve variables with respect to FX rates, of size (len(fx_vars), pre_n).
\[[\nabla_\mathbf{f}\mathbf{v^T}]_{i,j} = \frac{\partial v_j}{\partial f_i} = -\frac{\partial r_z}{\partial f_i} \frac{\partial v_j}{\partial s_z}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities
- grad_f_v_rT_pre(fx_vars)#
3d array of second derivatives of calibrating instrument rates with respect to FX rates and curve variables, of size (len(fx_vars), pre_n, pre_m);
\[[\nabla_\mathbf{f} \nabla_\mathbf{v} \mathbf{r^T}]_{i,j,k} = \frac{\partial^2 r_k}{\partial f_i \partial v_j}\]- Parameters:
fx_vars (list or tuple of str) – The variable name tags for the FX rate sensitivities.
- grad_s_Pbase(npv, grad_s_P, f)#
1d array of derivatives of base currency PV with respect to calibrating instruments, of size (pre_m).
\[\nabla_\mathbf{s} P^{bas}(\mathbf{v(s, f)}) = \nabla_\mathbf{s} P^{loc}(\mathbf{v(s, f)}) f_{loc:bas} + P^{loc} \nabla_\mathbf{s} f_{loc:bas}\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
grad_s_P – ndarray The local currency delta risks w.r.t. calibrating instruments.
f – Dual or Dual2 The local:base FX rate.
- grad_s_Ploc(npv)#
1d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m).
\[\nabla_\mathbf{s} P^{loc} = \frac{\partial P^{loc}}{\partial s_i}\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
- grad_s_f_pre(f)#
1d array of FX conversion rate with respect to calibrating instruments, of size (pre_m);
\[[\nabla_\mathbf{s} f_{loc:bas}]_{i} = \frac{\partial f}{\partial s_i}\]
- grad_s_sT_Pbase(npv, grad_s_sT_P, f)#
2d array of derivatives of base currency PV with respect to calibrating instrument rate variables, of size (pre_m, pre_m).
\[\nabla_\mathbf{s} \nabla_\mathbf{s}^\mathbf{T} P^{bas}(\mathbf{v(s, f), f})\]- Parameters:
npv – Dual or Dual2 A local currency NPV of a period of a leg.
grad_s_sT_P – ndarray The local currency gamma risks w.r.t. calibrating instrument variables.
f – Dual or Dual2 The local:base FX rate.
- grad_s_sT_Ploc(npv)#
2d array of derivatives of local currency PV with respect to calibrating instruments, of size (pre_m, pre_m).
\[\nabla_\mathbf{s} \nabla_\mathbf{s}^\mathbf{T} P^{loc}(\mathbf{v, f}) = \frac{ \partial^2 P^{loc}(\mathbf{v(s, f)}) }{\partial s_i \partial s_j}\]- Parameters:
npv – Dual2 A local currency NPV of a period of a leg.
- grad_s_sT_f_pre(f)#
2d array of derivatives of FX conversion rate with respect to calibrating instruments, of size (pre_m, pre_m);
\[[\nabla_\mathbf{s} \nabla_\mathbf{s}^\mathbf{T} f_{loc:bas}]_{i,j} = \frac{\partial^2 f}{\partial s_i \partial s_j}\]
- gradp_f_vT_Ploc(npv, fx_vars)#
2d array of (partial) derivatives of local currency PV with respect to FX rate variables and curve variables, of size (len(fx_vars), pre_n).
\[\nabla_\mathbf{f} \nabla_\mathbf{v}^\mathbf{T} P^{loc}(\mathbf{v, f}) = \frac{ \partial ^2 P^{loc}(\mathbf{v, f)}) }{\partial f_i \partial v_j}\]- Parameters:
npv – Dual2 A local currency NPV of a period of a leg.
fx_vars – list or tuple of str The variable tags for automatic differentiation of FX rate sensitivity