class_docstr: Represents a batch of Caps and/or Floors.
  
  An interest Cap (or Floor) is a portfolio of call (or put) options where the
  underlying for the individual options are successive forward rates. The
  individual options comprising a Cap are called Caplets and the corresponding
  options comprising a Floor are called Floorlets. For example, a
  caplet on forward rate `F(T_i, T_{i+1})` has the following payoff at time
  `T_{i_1}`:
  
  caplet payoff = tau_i * max[F(T_i, T_{i+1}), 0]
  
  where `tau_i` is the daycount fraction.
  
  The CapAndFloor class can be used to create and price multiple Caps/Floors
  simultaneously. However all instruments within an object must be priced using
  common reference/discount curve.
  
  ### Example:
  The following example illustrates the construction of an IRS instrument and
  calculating its price.
  
  ```python
  import numpy as np
  import tensorflow as tf
  import tf_quant_finance as tff
  dates = tff.datetime
  instruments = tff.experimental.instruments
  rc = tff.experimental.instruments.rates_common
  
  dtype = np.float64
  notional = 100.0
  maturity_date = dates.convert_to_date_tensor([(2022, 1, 15)])
  start_date = dates.convert_to_date_tensor([(2021, 1, 15)])
  valuation_date = dates.convert_to_date_tensor([(2021, 1, 1)])
  
  period3m = dates.periods.months(3)
  cap = instruments.CapAndFloor(
      start_date,
      maturity_date,
      period3m,
      0.005,
      daycount_convention=instruments.DayCountConvention.ACTUAL_365,
      notional=notional,
      dtype=dtype)
  curve_dates = valuation_date + dates.periods.months([0, 3, 12, 24])
  reference_curve = instruments.RateCurve(
      curve_dates,
      np.array([0.005, 0.01, 0.015, 0.02], dtype=np.float64),
      valuation_date=valuation_date,
      dtype=np.float64)
  market = instruments.InterestRateMarket(
      reference_curve=reference_curve, discount_curve=reference_curve)
  
  price = cap.price(
            valuation_date,
            market,
            model=instruments.InterestRateModelType.LOGNORMAL_RATE,
            pricing_context=0.5)
  # Expected result: 1.0474063612452953
  ```
  
  ### References:
  [1]: Leif B.G. Andersen and Vladimir V. Piterbarg. Interest Rate Modeling,
      Volume I: Foundations and Vanilla Models. Chapter 5. 2010.
docstr: Computes caplet/floorlet prices using lognormal model for forward rates.
  
  The function computes individual caplet prices for the batch of caps/floors
  using the lognormal model for the forward rates. If the volatilities are
  are supplied (through the input `pricing_context`) then they are used as
  forward rate volatilies. Otherwise, volatilities are extracted using the
  volatility surface for `market`.
  
  Args:
    valuation_date: A scalar `DateTensor` specifying the date on which
      valuation is being desired.
    market: A namedtuple of type `InterestRateMarket` which contains the
      necessary information for pricing the Cap/Floor.
    pricing_context: An optional input containing the black volatility for
      for the forward rates.
  
  Returns:
    A Rank 1 `Tensor` of real type containing the price of each caplet
    (or floorlet) based using the lognormal model for forward rates.
code: def _price_lognormal_rate(
      self, valuation_date, market, pricing_context
  ):
      """Computes caplet/floorlet prices using lognormal model for forward rates.
  
      The function computes individual caplet prices for the batch of caps/floors
      using the lognormal model for the forward rates. If the volatilities are
      are supplied (through the input `pricing_context`) then they are used as
      forward rate volatilies. Otherwise, volatilities are extracted using the
      volatility surface for `market`.
  
      Args:
        valuation_date: A scalar `DateTensor` specifying the date on which
          valuation is being desired.
        market: A namedtuple of type `InterestRateMarket` which contains the
          necessary information for pricing the Cap/Floor.
        pricing_context: An optional input containing the black volatility for
          for the forward rates.
  
      Returns:
        A Rank 1 `Tensor` of real type containing the price of each caplet
        (or floorlet) based using the lognormal model for forward rates.
      """
  
      discount_curve = market.discount_curve
  
      discount_factors = tf.where(
          self._payment_dates > valuation_date,
          discount_curve.get_discount_factor(self._payment_dates),
          0.0,
      )
  
      forward_rates = self._get_forward_rate(valuation_date, market)
  
      if pricing_context is None:
          volatility_surface = market.volatility_curve
          black_vols = volatility_surface.interpolate(
              self._reset_dates, self._strike, self._term
          )
      else:
          black_vols = tf.convert_to_tensor(
              pricing_context, dtype=self._dtype
          )
  
      expiry_times = dates.daycount_actual_365_fixed(
          start_date=valuation_date,
          end_date=self._reset_dates,
          dtype=self._dtype,
      )
      caplet_prices = black_scholes.option_price(
          forwards=forward_rates,
          strikes=self._strike,
          volatilities=black_vols,
          expiries=expiry_times,
          is_call_options=self._is_cap,
      )
      intrinsic_value = tf.where(
          self._is_cap,
          tf.math.maximum(forward_rates - self._strike, 0.0),
          tf.math.maximum(self._strike - forward_rates, 0),
      )
      caplet_prices = tf.where(
          self._payment_dates < valuation_date,
          tf.constant(0.0, dtype=self._dtype),
          tf.where(
              self._accrual_start_dates < valuation_date,
              intrinsic_value,
              caplet_prices,
          ),
      )
      caplet_prices = (
          self._notional * self._daycount_fractions * caplet_prices
      )
      return discount_factors * caplet_prices
  
file_path: tf-quant-finance/tf_quant_finance/experimental/instruments/cap_floor.py
imports: import tensorflow.compat.v2
  from tf_quant_finance import black_scholes
  from tf_quant_finance import datetime
  from tf_quant_finance.experimental.instruments import rates_common
label_desc: Use image node_id 3 for calling the CapAndFloor obj's underlying member method code with example usage: obj._price_lognormal_rate(valuation_date, market, pricing_context) and returns: unknown