PPSplineF64#

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

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

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

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

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

Attributes

Variables:
  • c – sequence of float

  • k – int

  • n – int

  • t – sequence of float

See also

PPSplineDual: Spline where the y-axis contains Dual data types.

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

Notes

This class implements a piecewise polynomial spline curve defined by:

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

where \(B_{i,k,\mathbf{t}}(x)\) is one of the n b-splines, of order k over knot sequence \(\mathbf{t}\), evaluated at x, and \(c_i\) is the coefficient of the i’th b-spline for this specific piecewise polynomial.

Examples

See splines in user guide.

Methods Summary

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 (ndarray of float) – x-axis coordinates.

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

Return type:

ndarray

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 (ndarray 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:

ndarray

bsplmatrix(tau, left_n, right_n)#

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

Parameters:
  • tau (ndarray of float) – The data sites along the x axis 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:

ndarray

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 coefficients of the spline given the data sites and the endpoint constraints.

Parameters:
  • tau (sequence of float) – The x-axis data sites.

  • y (sequence of float (or Dual or Dual2)) – The y-axis data site values, of a type associated with the spline

  • left_n (int) – The derivative order of the left side endpoint constraint.

  • right_n (int) – The derivative order of the right side endpoint constraint.

  • allow_lsq (bool) – Whether to permit least squares solving.

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.

Parameters:

x (ndarray of float) – x-axis coordinates.

Return type:

ndarray

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 (or Dual or Dual2 depending upon spline type)

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.

ppev_single_dual2(x)#

Evaluate a single x coordinate value on the pp spline.

Parameters:

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

Return type:

Dual2

Notes

This function guarantees preservation of accurate AD Dual2 sensitivities.

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 (ndarray of float) – x-axis coordinates.

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

Return type:

ndarray

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.

Return type:

float (or Dual or Dual2 depending upon spline type)

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 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.

Return type:

Dual

Notes

This function guarantees preservation of accurate AD Dual sensitivities.

ppdnev_single_dual2(x, m)#

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

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

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

Return type:

Dual2

Notes

This function guarantees preservation of accurate AD Dual2 sensitivities.