docstr: Tests that LSM price of American put option is computed as expected.
docstr_tok: ["Tests","that","LSM","price","of","American","put","option","is","computed","as","expected","."]
code: def test_american_option_put(self):
      """Tests that LSM price of American put option is computed as expected."""
      # 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.
      basis_fn = lsm.make_polynomial_basis(2)
      for dtype in (np.float32, np.float64):
          payoff_fn = payoff.make_basket_put_payoff([1.1], dtype=dtype)
          # Option price
          american_put_price = lsm.least_square_mc(
              self.samples,
              [1, 2, 3],
              payoff_fn,
              basis_fn,
              discount_factors=self.discount_factors,
              dtype=dtype,
          )
          self.assertAllClose(
              american_put_price, [0.1144], rtol=1e-4, atol=1e-4
          )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/lsm_algorithm/lsm_test.py
imports: import numpy
  import tensorflow.compat.v2
  from tf_quant_finance.experimental.lsm_algorithm import lsm
  from tf_quant_finance.experimental.lsm_algorithm import payoff
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 6 for calling the LsmTest obj's underlying member method code with example usage: obj.test_american_option_put() without return types