docstr: Tests that the European Call option price is computed correctly.
docstr_tok: ["Tests","that","the","European","Call","option","price","is","computed","correctly","."]
code: def testDocStringExample(self, bc_type, batch_grid):
      """Tests that the European Call option price is computed correctly."""
      num_equations = 2  # Number of PDE
      num_grid_points = 1024  # Number of grid points
      dtype = np.float64
      # Build a uniform grid
      if batch_grid:
          s_min = [0.01, 0.05]
          s_max = [200.0, 220]
          sizes = [num_grid_points, num_grid_points]
      else:
          s_min = [0.01]
          s_max = [200.0]
          sizes = [num_grid_points]
  
      grid = grids.uniform_grid(
          minimums=s_min, maximums=s_max, sizes=sizes, dtype=dtype
      )
      # Shape [[batch_dim, num_grid_points]]
      grid = [tf.stack(grid, axis=0)]
      # Specify volatilities and interest rates for the options
      volatility = np.array([0.3, 0.15], dtype=dtype).reshape([-1, 1])
      rate = np.array([0.01, 0.03], dtype=dtype).reshape([-1, 1])
      expiry = 1.0
      strike = np.array([50, 100], dtype=dtype).reshape([-1, 1])
  
      def second_order_coeff_fn(t, location_grid):
          del t
          return [
              [tf.square(volatility) * tf.square(location_grid[0]) / 2]
          ]
  
      def first_order_coeff_fn(t, location_grid):
          del t
          return [rate * location_grid[0]]
  
      def zeroth_order_coeff_fn(t, location_grid):
          del t, location_grid
          return -rate
  
      @dirichlet
      def lower_boundary_fn(t, location_grid):
          del t, location_grid
          return 0
  
      @dirichlet
      def upper_boundary_fn(t, location_grid):
          return location_grid[0][..., -1] + tf.squeeze(
              -strike * tf.math.exp(-rate * (expiry - t))
          )
  
      final_values = tf.nn.relu(grid[0] - strike)
      # Broadcast to the shape of value dimension, if necessary.
      final_values += tf.zeros(
          [num_equations, num_grid_points], dtype=dtype
      )
      if bc_type == "Default":
          boundary_conditions = [(None, upper_boundary_fn)]
      else:
          boundary_conditions = [(lower_boundary_fn, upper_boundary_fn)]
      # Estimate European call option price
      estimate = fd_solvers.solve_backward(
          start_time=expiry,
          end_time=0,
          coord_grid=grid,
          values_grid=final_values,
          num_steps=None,
          start_step_count=0,
          time_step=0.001,
          one_step_fn=crank_nicolson_step(),
          boundary_conditions=boundary_conditions,
          values_transform_fn=None,
          second_order_coeff_fn=second_order_coeff_fn,
          first_order_coeff_fn=first_order_coeff_fn,
          zeroth_order_coeff_fn=zeroth_order_coeff_fn,
          dtype=dtype,
      )[0]
      estimate = self.evaluate(estimate)
      # Extract estimates for some of the grid locations and compare to the
      # true option price
      value_grid_first_option = estimate[0, :]
      value_grid_second_option = estimate[1, :]
      # Get two grid locations (correspond to spot 51.9537332 and 106.25407758,
      # respectively).
      loc_1 = 256
      loc_2 = 512
      # True call option price (obtained using black_scholes_price function)
      if batch_grid:
          spots = tf.stack([grid[0][0][loc_1], grid[0][-1][loc_2]])
      else:
          spots = tf.stack([grid[0][0][loc_1], grid[0][0][loc_2]])
      call_price = tff.black_scholes.option_price(
          volatilities=volatility[..., 0],
          strikes=strike[..., 0],
          expiries=expiry,
          discount_rates=rate[..., 0],
          spots=spots,
      )
      self.assertAllClose(
          call_price,
          [
              value_grid_first_option[loc_1],
              value_grid_second_option[loc_2],
          ],
          rtol=1e-03,
          atol=1e-03,
      )
  
imports: import math
  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 10 for calling the ParabolicEquationStepperTest obj's underlying member method code with example usage: obj.testDocStringExample(bc_type, batch_grid) and returns: list, list, unknown, int, unknown