<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.rates.forwards.forward_rates_from_yields" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.rates.forwards.forward_rates_from_yields

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/rates/analytics/forwards.py">View source</a>



Computes forward rates given a set of zero rates. (deprecated)

```python
tf_quant_finance.rates.forwards.forward_rates_from_yields(
    yields, times, groups=None, dtype=None, name=None
)
```



<!-- Placeholder for "Used in" -->

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

```None
  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

```None
  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]


```python
  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:


* <b>`yields`</b>: Real rank 1 `Tensor` of size `n`. The discount/zero rates.
* <b>`times`</b>: Real positive rank 1 `Tensor` of size `n`. The set of times
  corresponding to the supplied zero rates. If no `groups` is supplied, then
  the whole array should be sorted in an increasing order. If `groups` are
  supplied, then the times within a group should be in an increasing order.
* <b>`groups`</b>: Optional int `Tensor` of size `n` containing values between 0 and
  `k-1` where `k` is the number of different curves.
  Default value: None. This implies that all the rates are treated as a
    single group.
* <b>`dtype`</b>: `tf.Dtype`. If supplied the dtype for the `yields` and `times`.
  Default value: None which maps to the default dtype inferred from
  `yields`.
* <b>`name`</b>: 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).
