code: def _estimate_initial_position(log_moneyness, total_variance):
      """Provides a heuristic initial guess for the SVI parameters.
  
      The values for `rho` and `sigma` are predetermined.
      `rho = 0` enforces the symmetry of the initial skew.
      `sigma = 0.5` enforces certain smoothness at the vertex of the skew.
  
      The value for `m` estimated as the position of the vertex of the skew:
      `m` is the log-moneyness corresponding to the smallest input variance.
  
      The values for `a`, `b` are computed using a simple linear regression, using
      the input data and the above estimates for `rho`, `sigma` and `m`.
  
      Args:
        log_moneyness: A rank 2 real `Tensor` of shape [batch_size, num_strikes].
          The log-moneyness `k := log(K/F)` of the options.
        total_variance: A rank 2 real `Tensor` of shape [batch_size, num_strikes].
          The target total variance to be approximated by the SVI model.
  
      Returns:
      A rank 2 real `Tensor` of shape [batch_size, 5], representing an initial
      guess for the SVI parameter optimization.
      """
      dtype = total_variance.dtype
  
      # Estimate `m` as the log_moneyess with the smallest target variance
      minvol_index = tf.argmin(total_variance, axis=1)
      m = tf.gather(log_moneyness, minvol_index, axis=1, batch_dims=1)
  
      # The initial guess will be a reasonably smooth symmetric smile
      sigma = 0.5 * tf.ones_like(minvol_index, dtype=dtype)
      rho = tf.zeros_like(minvol_index, dtype=dtype)
  
      # At this point, the SVI equation is reduced to `y = a + b * x`, where
      y = total_variance
      x = tf.sqrt(
          (log_moneyness - m[:, None]) ** 2 + sigma[:, None] ** 2
      )
  
      # Solve the simple regression for `a` and `b`, using the standard formulas,
      # cf. https://en.wikipedia.org/wiki/Simple_linear_regression
      e_x = tf.math.reduce_mean(x, axis=1)
      e_y = tf.math.reduce_mean(y, axis=1)
      e_xy = tf.math.reduce_mean(x * y, axis=1)
      var_x = tf.math.reduce_variance(x, axis=1)
      b = (e_xy - e_x * e_y) / var_x
      a = e_y - b * e_x
  
      initial_position = tf.transpose([a, b, rho, m, sigma])
      return initial_position
  
file_path: tf-quant-finance/tf_quant_finance/experimental/svi/calibration.py
imports: from typing import Callable, Tuple
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance.experimental.svi import parameterizations
  from tf_quant_finance.math import make_val_and_grad_fn
  from tf_quant_finance.math import optimizer
label_desc: Use image node_id 2 for calling a global function with example usage: _estimate_initial_position(log_moneyness, total_variance) and returns: initial_position