gradient#

rateslib.dual.gradient(dual, vars=None, order=1, keep_manifold=False)#

Return derivatives of a dual number.

Parameters:
  • dual (Dual or Dual2) – The dual variable from which to derive derivatives.

  • vars (str, tuple, list optional) – Name of the variables which to return gradients for. If not given defaults to all vars attributed to the instance.

  • order ({1, 2}) – Whether to return the first or second derivative of the dual number. Second order will raise if applied to a Dual and not Dual2 instance.

  • keep_manifold (bool) – If order is 1 and the type is Dual2 one can return a Dual2 where the dual2 values are converted to dual values to represent a first order manifold of the first derivative (and the dual2 values set to zero). Useful for propagation in iterations.

Return type:

float, ndarray, Dual2