tf_quant_finance.math.piecewise.PiecewiseConstantFunc

Last updated: 2023-03-16.

tf_quant_finance.math.piecewise.PiecewiseConstantFunc#

View source

Creates a piecewise constant function.

tf_quant_finance.math.piecewise.PiecewiseConstantFunc(
    jump_locations, values, dtype=None, name=None
)

Args:#

  • jump_locations: A real Tensor of shape batch_shape + [num_jump_points]. The locations where the function changes its values. Note that the values are expected to be ordered along the last dimension. Repeated values are allowed but it is up to the user to ensure that the corresponding values are also repeated.

  • values: A Tensor of the same dtype as jump_locations and shape batch_shape + [num_jump_points + 1] + event_shape. Defines values[batch_rank * slice(None), i] on intervals (jump_locations[..., i - 1], jump_locations[..., i]). Here event_shape allows for array-valued piecewise constant functions and batch_rank = len(batch_shape).

  • dtype: Optional dtype for jump_locations and values. Default value: None which maps to the default dtype inferred from jump_locations.

  • name: Python str name prefixed to ops created by this class. Default value: None which is mapped to the default name PiecewiseConstantFunc.

Raises:#

  • ValueError: If jump_locations and values have different batch shapes or, in case of static shapes, if the event shape of values is different from num_jump_points + 1.

Methods#

__call__

View source

__call__(
    x, left_continuous=True, name=None
)

Computes value of the piecewise constant function.

Returns a value of the piecewise function with jump locations and values given by the initializer.

Args:#

  • x: A real Tensor of shape batch_shape + [num_points]. Points at which the function has to be evaluated.

  • left_continuous: Python bool. Whether the function is left- or right- continuous, i.e., at the jump_locations[..., i] left-continuity means that the function has the same value values[batch_rank * slice(None), i], whereas for right-continuity, the value is values[batch_rank * slice(None), i + 1]. Default value: True which means that the function is left-continuous.

  • name: Python str name prefixed to ops created by this method. Default value: None which is mapped to the default name self.name() + _call.

Returns:#

A Tensor of the same dtype as x and shape batch_shape + [num_points] + event_shape containing values of the piecewise constant function.

dtype

View source

dtype()

The underlying data type.

integrate

View source

integrate(
    x1, x2, name=None
)

Integrates the piecewise constant function between end points.

Returns a value of the integral on the interval [x1, x2] of a piecewise constant function with jump locations and values given by the initializer.

Args:#

  • x1: A real Tensor of shape batch_shape + [num_points]. Left end points at which the function has to be integrated.

  • x2: A Tensor of the same shape and dtype as x1. Right end points at which the function has to be integrated.

  • name: Python str name prefixed to ops created by this method. Default value: None which is mapped to the default name self.name() + _integrate``.

Returns:#

A Tensor of the same dtype as x and shape batch_shape + [num_points] + event_shape containing values of the integral of the piecewise constant function between [x1, x2].

jump_locations

View source

jump_locations()

The jump locations of the piecewise constant function.

name

View source

name()

The name to give to the ops created by this class.

values

View source

values()

The value of the piecewise constant function between jump locations.