code: def _get_loss_for_price_based_calibration(
      *,
      prices,
      strikes,
      expiries,
      forwards,
      is_call_options,
      discount_rates,
      dividend_rates,
      optimizer_arg_handler,
      dtype,
  ):
      """Creates a loss function to be used in volatility-based calibration."""
  
      def _price_transform(x):
          return tf.math.log1p(x)
  
      scaled_target_values = _price_transform(prices)
  
      @make_val_and_grad_fn
      def loss_function(x):
          """Loss function for the price-based optimization."""
          candidate_initial_variance = (
              optimizer_arg_handler.get_initial_variance(x)
          )
          candidate_theta = optimizer_arg_handler.get_theta(x)
          candidate_volvol = optimizer_arg_handler.get_volvol(x)
          candidate_rho = optimizer_arg_handler.get_rho(x)
          candidate_mean_reversion = (
              optimizer_arg_handler.get_mean_reversion(x)
          )
  
          values = approximations.european_option_price(
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call_options,
              variances=tf.expand_dims(
                  candidate_initial_variance, axis=-1
              ),
              mean_reversion=tf.expand_dims(
                  candidate_mean_reversion, axis=-1
              ),
              volvol=tf.expand_dims(candidate_volvol, axis=-1),
              rho=tf.expand_dims(candidate_rho, axis=-1),
              theta=tf.expand_dims(candidate_theta, axis=-1),
              discount_rates=discount_rates,
              dividend_rates=dividend_rates,
              dtype=dtype,
          )
  
          scaled_values = _price_transform(values)
          return tf.math.reduce_mean(
              (scaled_values - scaled_target_values) ** 2, axis=-1
          )
  
      return loss_function
  
imports: from typing import Callable, Tuple
  import tensorflow.compat.v2
  import tf_quant_finance
  from tf_quant_finance import types
  from tf_quant_finance import utils
  from tf_quant_finance.math import make_val_and_grad_fn
  from tf_quant_finance.math import optimizer
  from tf_quant_finance.models.heston import approximations
label_desc: Use image node_id 2 for calling a global function with example usage: _get_loss_for_price_based_calibration() and returns: loss_function, tf, tf