docstr: Tests the LSM price of American Basket put option.
docstr_tok: ["Tests","the","LSM","price","of","American","Basket","put","option","."]
code: def test_american_basket_option_put(self):
      """Tests the LSM price of American Basket put option."""
      # This is the same example as in Section 1 of
      # Longstaff, F.A. and Schwartz, E.S., 2001. Valuing American options by
      # simulation: a simple least-squares approach. The review of financial
      # studies, 14(1), pp.113-147.
      # This is the minimum number of basis functions for the tests to pass.
      basis_fn = lsm_algorithm.make_polynomial_basis(10)
      exercise_times = [1, 2, 3]
      dtype = np.float64
      payoff_fn = lsm_algorithm.make_basket_put_payoff(
          [1.1, 1.2, 1.3], dtype=dtype
      )
      # Create a 2-d process which is simply follows the `samples` paths:
      samples = tf.convert_to_tensor(self.samples, dtype=dtype)
      samples_2d = tf.concat([samples, samples], -1)
      # Price American basket option
      american_basket_put_price = lsm_algorithm.least_square_mc(
          samples_2d,
          exercise_times,
          payoff_fn,
          basis_fn,
          discount_factors=self.discount_factors,
          dtype=dtype,
      )
      # Since the marginal processes of `samples_2d` are 100% correlated, the
      # price should be the same as of the American option computed for
      # `samples`
      american_put_price = lsm_algorithm.least_square_mc(
          self.samples,
          exercise_times,
          payoff_fn,
          basis_fn,
          discount_factors=self.discount_factors,
          dtype=dtype,
      )
      with self.subTest(name="Price"):
          self.assertAllClose(
              american_basket_put_price,
              american_put_price,
              rtol=1e-4,
              atol=1e-4,
          )
      with self.subTest(name="Shape"):
          self.assertAllEqual(american_basket_put_price.shape, [3])
  
file_path: tf-quant-finance/tf_quant_finance/models/longstaff_schwartz/lsm_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 5 for calling the LsmTest obj's underlying member method code with example usage: obj.test_american_basket_option_put() without return types