docstr: Tests that the model reproduces implied volatility smile.
docstr_tok: ["Tests","that","the","model","reproduces","implied","volatility","smile","."]
code: def test_lv_correctness(
      self,
      dim,
      rho,
      risk_free_rate,
      spot,
      variance,
      pde_time_step,
      sim_time_step,
      mr,
      volvol,
      using_market_data,
  ):
      """Tests that the model reproduces implied volatility smile."""
      dtype = tf.float64
      num_samples = 10000
      var_model = lsv.LSVVarianceModel(
          mr, variance, volvol * np.sqrt(variance), dtype=dtype
      )
      val_date, expiries, expiry_times, strikes, iv = build_tensors(
          dim, spot, risk_free_rate
      )
      if using_market_data:
          model = lsv.LocalStochasticVolatilityModel.from_market_data(
              val_date,
              expiries,
              strikes,
              iv,
              var_model,
              spot,
              variance,
              rho,
              risk_free_rate,
              [0.0],
              pde_time_step,
              num_grid_points=100,
              dtype=dtype,
          )
      else:
          vs = build_volatility_surface(
              val_date, expiry_times, expiries, strikes, iv, dtype=dtype
          )
          model = lsv.LocalStochasticVolatilityModel.from_volatility_surface(
              vs,
              var_model,
              spot,
              variance,
              rho,
              risk_free_rate,
              [0.0],
              pde_time_step,
              num_grid_points=100,
              dtype=dtype,
          )
  
      paths = model.sample_paths(
          [1.0, 2.0],
          num_samples=num_samples,
          initial_state=[spot[0], variance[0]],
          time_step=sim_time_step,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[1, 2],
      )
  
      for d in range(dim):
          for i in range(2):
              for j in [1, 2, 3]:
                  sim_iv = self.evaluate(
                      self.get_implied_vol(
                          expiry_times[d][i],
                          strikes[d][i][j],
                          paths[:, i, d],
                          spot[d],
                          risk_free_rate,
                          dtype,
                      )
                  )
                  self.assertAllClose(
                      sim_iv[0], iv[d][i][j], atol=0.007, rtol=0.007
                  )
  
file_path: tf-quant-finance/tf_quant_finance/experimental/local_stochastic_volatility/local_stochastic_volatility_model_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 2 for calling the LocalStochasticVolatilityTest obj's underlying member method code with example usage: obj.test_lv_correctness(dim, rho, risk_free_rate, spot, variance, pde_time_step, sim_time_step, mr, volvol, using_market_data) without return types