class_docstr: Local stochastic volatility model.
  
  Local stochastic volatility (LSV) models assume that the spot price of an
  asset follows the following stochastic differential equation under the risk
  neutral measure [1]:
  
  ```None
    dS(t) / S(t) =  (r - d) dt + sqrt(v(t)) * L(t, S(t)) * dW_s(t)
    dv(t) = a(v(t)) dt + b(v(t)) dW_v(t)
    E[dW_s(t)dW_v(t)] = rho dt
  ```
  where `r` and `d` denote the risk free interest rate and dividend yield
  respectively. `S(t)` is the spot price, `v(t)` denotes the stochastic variance
  and the function `L(t, S(t))`  is the leverage function which is calibrated
  using the volatility smile data. The functions `a(v(t))` and `b(v(t))` denote
  the drift and volitility of the stochastic process for the variance and `rho`
  denotes the instantabeous correlation between the spot and the variance
  process. LSV models thus combine the local volatility dynamics with
  stochastic volatility.
  
  Using the relationship between the local volatility and the expectation of
  future instantaneous variance, leverage function can be computed as follows
  [2]:
  
  ```
  sigma(T,K)^2 = L(T,K)^2 * E[v(T)|S(T)=K]
  ```
  where the local volatility function `sigma(T,K)` can be computed using the
  Dupire's formula.
  
  The `LocalStochasticVolatilityModel` class contains a generic implementation
  of the LSV model with the flexibility to specify an arbitrary variance
  process. The default variance process is a Heston type process with
  mean-reverting variance (as in Ref. [1]):
  
  ```
  dv(t) = k(m - v(t)) dt + alpha*sqrt(v(t)) dW_v(t)
  ```
  
  #### References:
    [1]: Iain J. Clark. Foreign exchange option pricing - A Practitioner's
    guide. Chapter 5. 2011.
    [2]: I. Gyongy. Mimicking the one-dimensional marginal distributions of
    processes having an ito differential. Probability Theory and Related
    Fields, 71, 1986.
docstr: Initializes the Local stochastic volatility model.
  
  Args:
    leverage_fn: A Python callable which returns the Leverage function
      `L(t, S(t))` as a function of state and time. The function must accept
      a scalar `Tensor` corresponding to time 't' and a real `Tensor` of shape
      `[num_samples, 1]` corresponding to the underlying price (S) as
      inputs  and return a real `Tensor` containing the leverage function
      computed at (S,t).
    variance_process: An instance of `ItoProcess` specifying the
      dynamics of the variance process of the LSV model. The
      `variance_process` should implement a one-factor stochastic process.
      For the common version of Heston like variance model use
      `LSVVarianceModel`.
    risk_free_rate: An optional scalar real `Tensor` specifying the
      (continuously compounded) risk free interest rate. If the underlying is
      an FX rate, then use this input to specify the domestic interest rate.
      Note that the current implementation supports constant interest rates
      and dividend yield.
      Default value: `None` in which case the input is set to zero.
    dividend_yield: An optional real scalar `Tensor` specifying the
      (continuosly compounded) dividend yield. If the underlying is an FX
      rate, then use this input to specify the foreign interest rate.
      Note that the currect implementation supports constant interest rates
      and dividend yield.
      Default value: `None` in which case the input is set to zero.
    rho: A real scalar `Tensor` specifying the correlation between the
      underlying spot price and the variance process.
      Default value: `None` in which case cross correlations are assumed
      to be zero.
    dtype: The default dtype to use when converting values to `Tensor`s.
      Default value: `None` which means that default dtypes inferred by
      TensorFlow are used.
    name: Python string. The name to give to the ops created by this class.
      Default value: `None` which maps to the default name
      `local_stochastic_volatility_model`.
docstr_tok: ["Initializes","the","Local","stochastic","volatility","model",".","Args",":","leverage_fn",":","A","Python","callable","which","returns","the","Leverage","function","`","L","(","t",",","S","(","t",")",")","`","as","a","function","of","state","and","time",".","The","function","must","accept","a","scalar","`","Tensor","`","corresponding","to","time","'t","'","and","a","real","`","Tensor","`","of","shape","`","[","num_samples",",","1","]","`","corresponding","to","the","underlying","price","(","S",")","as","inputs","and","return","a","real","`","Tensor","`","containing","the","leverage","function","computed","at","(","S",",","t",")",".","variance_process",":","An","instance","of","`","ItoProcess","`","specifying","the","dynamics","of","the","variance","process","of","the","LSV","model",".","The","`","variance_process","`","should","implement","a","one-factor","stochastic","process",".","For","the","common","version","of","Heston","like","variance","model","use","`","LSVVarianceModel","`",".","risk_free_rate",":","An","optional","scalar","real","`","Tensor","`","specifying","the","(","continuously","compounded",")","risk","free","interest","rate",".","If","the","underlying","is","an","FX","rate",",","then","use","this","input","to","specify","the","domestic","interest","rate",".","Note","that","the","current","implementation","supports","constant","interest","rates","and","dividend","yield",".","Default","value",":","`","None","`","in","which","case","the","input","is","set","to","zero",".","dividend_yield",":","An","optional","real","scalar","`","Tensor","`","specifying","the","(","continuosly","compounded",")","dividend","yield",".","If","the","underlying","is","an","FX","rate",",","then","use","this","input","to","specify","the","foreign","interest","rate",".","Note","that","the","currect","implementation","supports","constant","interest","rates","and","dividend","yield",".","Default","value",":","`","None","`","in","which","case","the","input","is","set","to","zero",".","rho",":","A","real","scalar","`","Tensor","`","specifying","the","correlation","between","the","underlying","spot","price","and","the","variance","process",".","Default","value",":","`","None","`","in","which","case","cross","correlations","are","assumed","to","be","zero",".","dtype",":","The","default","dtype","to","use","when","converting","values","to","`","Tensor","`","s",".","Default","value",":","`","None","`","which","means","that","default","dtypes","inferred","by","TensorFlow","are","used",".","name",":","Python","string",".","The","name","to","give","to","the","ops","created","by","this","class",".","Default","value",":","`","None","`","which","maps","to","the","default","name","`","local_stochastic_volatility_model","`","."]
code: def __init__(
      self,
      leverage_fn,
      variance_process,
      risk_free_rate=None,
      dividend_yield=None,
      rho=None,
      dtype=None,
      name=None,
  ):
      """Initializes the Local stochastic volatility model.
  
      Args:
        leverage_fn: A Python callable which returns the Leverage function
          `L(t, S(t))` as a function of state and time. The function must accept
          a scalar `Tensor` corresponding to time 't' and a real `Tensor` of shape
          `[num_samples, 1]` corresponding to the underlying price (S) as
          inputs  and return a real `Tensor` containing the leverage function
          computed at (S,t).
        variance_process: An instance of `ItoProcess` specifying the
          dynamics of the variance process of the LSV model. The
          `variance_process` should implement a one-factor stochastic process.
          For the common version of Heston like variance model use
          `LSVVarianceModel`.
        risk_free_rate: An optional scalar real `Tensor` specifying the
          (continuously compounded) risk free interest rate. If the underlying is
          an FX rate, then use this input to specify the domestic interest rate.
          Note that the current implementation supports constant interest rates
          and dividend yield.
          Default value: `None` in which case the input is set to zero.
        dividend_yield: An optional real scalar `Tensor` specifying the
          (continuosly compounded) dividend yield. If the underlying is an FX
          rate, then use this input to specify the foreign interest rate.
          Note that the currect implementation supports constant interest rates
          and dividend yield.
          Default value: `None` in which case the input is set to zero.
        rho: A real scalar `Tensor` specifying the correlation between the
          underlying spot price and the variance process.
          Default value: `None` in which case cross correlations are assumed
          to be zero.
        dtype: The default dtype to use when converting values to `Tensor`s.
          Default value: `None` which means that default dtypes inferred by
          TensorFlow are used.
        name: Python string. The name to give to the ops created by this class.
          Default value: `None` which maps to the default name
          `local_stochastic_volatility_model`.
      """
      self._name = name or "local_stochastic_volatility_model"
      with tf.name_scope(self._name):
          if risk_free_rate is None:
              risk_free_rate = 0.0
          if dividend_yield is None:
              dividend_yield = 0.0
          self._risk_free_rate = tf.convert_to_tensor(
              risk_free_rate, dtype=dtype
          )
          self._dtype = dtype or self._domestic_rate.dtype
          self._dividend_yield = tf.convert_to_tensor(
              dividend_yield, dtype=dtype
          )
          self._leverage_fn = leverage_fn
          self._variance_process = variance_process
          dim = 1 + variance_process.dim()
          rho = rho or 0.0
          self._rho = _create_corr_matrix(rho, self._dtype)
          self._sqrt_rho = tf.linalg.cholesky(self._rho)
  
          def _vol_fn(t, state):
              """Volatility function of LSV model."""
              num_samples = state.shape.as_list()[0]
              broadcasted_t = tf.broadcast_to(t, [1, num_samples])
              spot_prices = state[:, 0]
              variance = state[:, 1:]
              level_fun = self._leverage_fn(
                  broadcasted_t, tf.expand_dims(spot_prices, axis=0)
              )
              spot_diffusion = (
                  tf.expand_dims(level_fun[0, :], axis=-1)
                  * tf.expand_dims(spot_prices, axis=-1)
                  * tf.math.sqrt(variance)
              )
              variance_diffusion = (
                  self._variance_process.volatility_fn()(t, variance)
              )
              diffusion = tf.concat(
                  [spot_diffusion, variance_diffusion], axis=1
              )
              diffusion = tf.expand_dims(diffusion, axis=-2)
              return diffusion * self._sqrt_rho
  
          # Drift function
          def _drift_fn(t, state):
              """Drift function of LSV model."""
              spot_drift = (
                  self._risk_free_rate - self._dividend_yield
              ) * state[:, :1]
              variance_drift = self._variance_process.drift_fn()(
                  t, state[:, 1:]
              )
              return tf.concat([spot_drift, variance_drift], axis=1)
  
          super(LocalStochasticVolatilityModel, self).__init__(
              dim, _drift_fn, _vol_fn, self._dtype, self._name
          )
  
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance import math
  from tf_quant_finance import utils
  from tf_quant_finance.experimental import local_volatility
  from tf_quant_finance.experimental.pricing_platform.framework.market_data import utils
  from tf_quant_finance.math import pde
  from tf_quant_finance.math.interpolation import linear
  from tf_quant_finance.models import generic_ito_process
label_desc: Use image node_id 1 to create a new LocalStochasticVolatilityModel object from inherited base classes: generic_ito_process with example: obj = LocalStochasticVolatilityModel(leverage_fn, variance_process, risk_free_rate, dividend_yield, rho, dtype, name)