Last updated: 2023-03-16.
tf_quant_finance.rates.forwards.forward_rates_from_yields#
Computes forward rates given a set of zero rates. (deprecated)
tf_quant_finance.rates.forwards.forward_rates_from_yields(
yields, times, groups=None, dtype=None, name=None
)
Deprecated: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Please use tff.rates.analytics.forwards.forward_rates_from_yields instead.
Denote the price of a zero coupon bond maturing at time t by Z(t). Then
the zero rate to time t is defined as
r(t) = - ln(Z(t)) / t (1)
This is the (continuously compounded) interest rate that applies between time
0 and time t as seen at time 0. The forward rate between times t1 and
t2 is defined as the interest rate that applies to the period [t1, t2]
as seen from today. It is related to the zero coupon bond prices by
exp(-f(t1, t2)(t2-t1)) = Z(t2) / Z(t1) (2)
f(t1, t2) = - (ln Z(t2) - ln Z(t1)) / (t2 - t1) (3)
f(t1, t2) = (t2 * r(t2) - t1 * r(t1)) / (t2 - t1) (4)
Given a sequence of increasing times [t1, t2, ... tn] and the zero rates
for those times, this function computes the forward rates that apply to the
consecutive time intervals i.e. [0, t1], [t1, t2], ... [t_{n-1}, tn] using
Eq. (4) above. Note that for the interval [0, t1] the forward rate is the
same as the zero rate.
Additionally, this function supports this computation for a batch of such
rates. Batching is made slightly complicated by the fact that different
zero curves may have different numbers of tenors (the parameter n above).
Instead of a batch as an extra dimension, we support the concept of groups
(also see documentation for tf.segment_sum which uses the same concept).
Example#
The following example illustrates this method along with the concept of
groups. Assuming there are two sets of zero rates (e.g. for different
currencies) whose implied forward rates are needed. The first set has a total
of three marked tenors at [0.25, 0.5, 1.0]. The second set
has four marked tenors at [0.25, 0.5, 1.0, 1.5].
Suppose, the zero rates for the first set are:
[0.04, 0.041, 0.044] and the second are [0.022, 0.025, 0.028, 0.036].
Then this data is batched together as follows:
Groups: [0, 0 0, 1, 1, 1 1 ]
First three times for group 0, next four for group 1.
Times: [0.25, 0.5, 1.0, 0.25, 0.5, 1.0, 1.5]
First three rates for group 0, next four for group 1.
Rates: [0.04, 0.041, 0.044, 0.022, 0.025, 0.028, 0.036]
dtype = np.float64
groups = np.array([0, 0, 0, 1, 1, 1, 1])
times = np.array([0.25, 0.5, 1.0, 0.25, 0.5, 1.0, 1.5], dtype=dtype)
rates = np.array([0.04, 0.041, 0.044, 0.022, 0.025, 0.028, 0.036],
dtype=dtype)
forward_rates = forward_rates_from_yields(
rates, times, groups=groups, dtype=dtype)
References:#
[1]: John C. Hull. Options, Futures and Other Derivatives. Ninth Edition. June 2006.
Args:#
yields: Real rank 1Tensorof sizen. The discount/zero rates.times: Real positive rank 1Tensorof sizen. The set of times corresponding to the supplied zero rates. If nogroupsis supplied, then the whole array should be sorted in an increasing order. Ifgroupsare supplied, then the times within a group should be in an increasing order.groups: Optional intTensorof sizencontaining values between 0 andk-1wherekis the number of different curves. Default value: None. This implies that all the rates are treated as a single group.dtype:tf.Dtype. If supplied the dtype for theyieldsandtimes. Default value: None which maps to the default dtype inferred fromyields.name: Python str. The name to give to the ops created by this function. Default value: None which maps to ‘forward_rates_from_yields’.
Returns:#
Real rank 1 Tensor of size n containing the forward rate that applies
for each successive time interval (within each group if groups are
specified).