PPSplineDual#

class rateslib.splines.PPSplineDual(k, t, c)#

Piecewise polynomial spline composed of float-64 values on the x-axis and Dual values on the y-axis.

Parameters:
  • k (int) – The order of the spline.

  • t (sequence of float) – The knot sequence of the spline.

  • c (sequence of Dual or None) – The coefficients of the spline, optional.

Attributes

Variables:
  • c – sequence of Dual

  • k – int

  • n – int

  • t – sequence of float

See also

PPSplineF64: Spline where the y-axis contains float-64 data types.

PPSplineDual2: Spline where the y-axis contains Dual2 data types.

Methods Summary

bsplev(x, i)

Evaluate value of the i th b-spline at x coordinates.

bspldnev(x, i, m)

Evaluate m order derivative on the i th b-spline at x coordinates.

bsplmatrix(tau, left_n, right_n)

Evaluate the 2d spline collocation matrix at each data site.

csolve(tau, y, left_n, right_n, allow_lsq)

Solve the spline coefficients given the data sites.

ppev(x)

Evaluate an array of x coordinates derivatives on the pp spline.

ppev_single(x)

Evaluate a single x coordinate value on the pp spline.

ppev_single_dual(x)

Evaluate a single x coordinate value on the pp spline.

ppdnev(x, m)

Evaluate an array of x coordinates derivatives on the pp spline.

ppdnev_single(x, m)

Evaluate a single x coordinate derivative from the right on the pp spline.

ppdnev_single_dual(x, m)

Evaluate a single x coordinate derivative from the right on the pp spline.

Methods Documentation

bsplev(x, i)#

Evaluate value of the i th b-spline at x coordinates.

Repeatedly applies bsplev_single().

Warning

The x coordinates supplied to this function are treated as float, or are converted to float. Therefore it does not guarantee the preservation of AD sensitivities.

Parameters:
  • x (1-d array of float) – x-axis coordinates

  • i (int) – Index of the B-spline to evaluate.

Return type:

1-d array of float

bspldnev(x, i, m)#

Evaluate m order derivative on the i th b-spline at x coordinates.

Repeatedly applies bspldnev_single().

Warning

The x coordinates supplied to this function are treated as float, or are converted to float. Therefore it does not guarantee the preservation of AD sensitivities.

Parameters:
  • x (1-d array of float) – x-axis coordinates.

  • i (int) – The index of the B-spline to evaluate.

  • m (int) – The order of derivative to calculate value for.

Return type:

1-d array

bsplmatrix(tau, left_n, right_n)#

Evaluate the 2d spline collocation matrix at each data site.

Parameters:
  • tau (1-d array of float) – The data sites x-axis values which will instruct the pp spline.

  • left_n (int) – The order of derivative to use for the left most data site and top row of the spline collocation matrix.

  • right_n (int) – The order of derivative to use for the right most data site and bottom row of the spline collocation matrix.

Return type:

2-d array of float

Notes

The spline collocation matrix is defined as,

\[[\mathbf{B}_{k, \mathbf{t}}(\mathbf{\tau})]_{j,i} = B_{i,k,\mathbf{t}}(\tau_j)\]

where each row is a call to bsplev(), except the top and bottom rows which can be specifically adjusted to account for left_n and right_n such that, for example, the first row might be,

\[[\mathbf{B}_{k, \mathbf{t}}(\mathbf{\tau})]_{1,i} = \frac{d^n}{dx}B_{i,k,\mathbf{t}}(\tau_1)\]
csolve(tau, y, left_n, right_n, allow_lsq)#

Solve the spline coefficients given the data sites.

Parameters:
  • tau (list[f64]) – The data site x-coordinates.

  • y (list[type]) – The data site y-coordinates in appropriate type (float, Dual or Dual2) for self.

  • left_n (int) – The number of derivatives to evaluate at the left side of the data sites, i.e. defining an endpoint constraint.

  • right_n (int) – The number of derivatives to evaluate at the right side of the datasites, i.e. defining an endpoint constraint.

  • allow_lsq (bool) – Whether to permit least squares solving using non-square matrices.

Return type:

None

ppev(x)#

Evaluate an array of x coordinates derivatives on the pp spline.

Repeatedly applies ppev_single(), and is typically used for minor performance gains in chart plotting.

Warning

The x coordinates supplied to this function are treated as float, or are converted to float. Therefore it does not guarantee the preservation of AD sensitivities. If you need to index by x values which are Dual or Dual2, then you should choose to iteratively map the provided methods ppev_single_dual() or ppev_single_dual2() respectively.

Return type:

1-d array of float

ppev_single(x)#

Evaluate a single x coordinate value on the pp spline.

Parameters:

x (float) – The x-axis value at which to evaluate value.

Return type:

float, Dual or Dual2 based on self

Notes

The value of the spline at x is the sum of the value of each b-spline evaluated at x multiplied by the spline coefficients, c.

\[\$(x) = \sum_{i=1}^n c_i B_{(i,k,\mathbf{t})}(x)\]
ppev_single_dual(x)#

Evaluate a single x coordinate value on the pp spline.

Parameters:

x (Dual) – The x-axis value at which to evaluate value.

Return type:

Dual

Notes

This function guarantees preservation of accurate AD Dual sensitivities. It also prohibits type mixing and will raise if Dual2 data types are encountered.

ppdnev(x, m)#

Evaluate an array of x coordinates derivatives on the pp spline.

Repeatedly applies ppdnev_single().

Warning

The x coordinates supplied to this function are treated as float, or are converted to float. Therefore it does not guarantee the preservation of AD sensitivities.

Parameters:
  • x (1-d array of float) – x-axis coordinates.

  • m (int) – The order of derivative to calculate value for.

Return type:

1-d array of float

ppdnev_single(x, m)#

Evaluate a single x coordinate derivative from the right on the pp spline.

Parameters:
  • x (float) – The x-axis value at which to evaluate value.

  • m (int) – The order of derivative to calculate value for (0 is function value).

Return type:

float, Dual, or Dual2, based on self

Notes

The value of derivatives of the spline at x is the sum of the value of each b-spline derivatives evaluated at x multiplied by the spline coefficients, c.

Due to the definition of the splines this derivative will return the value from the right at points where derivatives are discontinuous.

\[\frac{d^m\$(x)}{d x^m} = \sum_{i=1}^n c_i \frac{d^m B_{(i,k,\mathbf{t})}(x)}{d x^m}\]
ppdnev_single_dual(x, m)#

Evaluate a single x coordinate derivative from the right on the pp spline.

Parameters:
  • x (Dual) – The x-axis value at which to evaluate value.

  • m (int) – The order of derivative to calculate value for (0 is function value).

Return type:

Dual

Notes

This function guarantees preservation of accurate AD Dual sensitivities. It also prohibits type mixing and will raise if any Dual2 data types are encountered.