Last updated: 2023-03-16.
tf_quant_finance.rates.analytics.cashflows.present_value#
Computes present value of a stream of cashflows given discount factors.
tf_quant_finance.rates.analytics.cashflows.present_value(
cashflows, discount_factors, dtype=None, name=None
)
# 2 and 3 year bonds with 1000 face value and 4%, 6% semi-annual coupons.
# Note that the first four entries in the cashflows are the cashflows of
# the first bond (group=0) and the next six are the cashflows of the second
# bond (group=1).
cashflows = [[20, 20, 20, 1020, 0, 0],
[30, 30, 30, 30, 30, 1030]]
# Corresponding discount factors for the cashflows
discount_factors = [[0.96, 0.93, 0.9, 0.87, 1.0, 1.0],
[0.97, 0.95, 0.93, 0.9, 0.88, 0.86]]
present_values = present_value(
cashflows, discount_factors, dtype=np.float64)
# Expected: [943.2, 1024.7]
Args:#
cashflows: A realTensorof shapebatch_shape + [n]. The set of cashflows of underlyings.nis the number of cashflows per bond andbatch_shapeis the number of bonds. Bonds with different number of cashflows should be padded to a common numbern.discount_factors: ATensorof the samedtypeascashflowsand of compatible shape. The set of discount factors corresponding to the cashflows.dtype:tf.Dtype. If supplied the dtype for the input and outputTensors. Default value: None which maps to the default dtype inferred fromcashflows.name: Python str. The name to give to the ops created by this function. Default value: None which maps to ‘present_value’.
Returns:#
Real Tensor of shape batch_shape. The present values of the cashflows.