docstr: Tests option pricing with a basis functions of polynomials of order 4.
docstr_tok: ["Tests","option","pricing","with","a","basis","functions","of","polynomials","of","order","4","."]
code: def test_basis_fn(self):
      """Tests option pricing with a basis functions of polynomials of order 4."""
      dtype = tf.float64
      spot = tf.constant([696, 286], dtype=dtype)
      strikes = tf.constant([2131, 408], dtype=dtype)
      risk_free_rates = tf.constant([0.2, 0.14], dtype=dtype)
      is_call_option = [True, False]
      # These are expiries at which the strike prices are computed
      expiries = tf.constant([7.2, 4.2], dtype=dtype)
      volatility = tf.constant([0.23, 0.55], dtype=dtype)
      discount_factors = tf.math.exp(-expiries * risk_free_rates)
      seed = tf.constant([4, 2])
      # Compute option prices
      am_option_prices = utils.bs_lsm_price(
          spots=spot,
          expiry_times=expiries,
          strikes=strikes,
          volatility=volatility,
          discount_factors=discount_factors,
          num_samples=6000,
          num_exercise_times=50,
          num_calibration_samples=1000,
          is_call_option=is_call_option,
          basis_fn=tff.models.longstaff_schwartz.make_polynomial_basis(
              4
          ),
          seed=seed,
          dtype=dtype,
      )
  
      # Expected prices obtained using binomial pricer
      # tff.black_scholes.option_price_binomial
      expected_prices = [262.3, 143.72]
      self.assertAllClose(
          expected_prices, am_option_prices, rtol=1e-1, atol=1e-1
      )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/american_option/utils_test.py
imports: import tensorflow.compat.v2
  import tf_quant_finance
  from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments.american_option import utils
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 2 for calling the UtilsTest obj's underlying member method code with example usage: obj.test_basis_fn() without return types