code: def continuation_value_fn(cashflow, discount_factors, exercise_index):
      """Returns the discounted value of the right hand part of the cashflow tensor.
  
      Args:
        cashflow: A real `Tensor` of shape
          `[num_samples, payoff_dim, num_exercise]`. Tracks the optimal cashflow of
           each sample path for each payoff dimension at each exercise time.
        discount_factors: A `Tensor` of shape `[num_exercise_times + 1]` or a shape
          compatible with `[num_samples, num_exercise_times + 1]` and the same
          `dtype` as `samples`, the `k`-th element of which represents the discount
          factor at time tick `k + 1`. `discount_factors[0]` is `1` which is the
          discount factor at time `0`.
        exercise_index: An integer scalar `Tensor` representing the index of the
          exercise time of interest. Should be less than `num_exercise_times`.
  
      Returns:
        A `[num_samples, payoff_dim]` `Tensor` whose entries represent the sum of
        those elements to the right of `exercise_index` in `cashflow`, discounted to
        the time indexed by `exercise_index`. When `exercise_index` is zero, the
        return represents the sum of the cashflow discounted to present value for
        each sample path.
      """
      total_discount_factors = discount_factors[
          ..., exercise_index + 1 :
      ] / tf.expand_dims(discount_factors[..., exercise_index], axis=-1)
      return tf.math.reduce_sum(
          cashflow[..., exercise_index:]
          * tf.expand_dims(total_discount_factors, axis=1),
          axis=2,
      )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/lsm_algorithm/lsm.py
imports: import collections
  import tensorflow.compat.v2
label_desc: Use image node_id 4 for calling a global function with example usage: continuation_value_fn(cashflow, discount_factors, exercise_index) and returns: tf