class_docstr: Base class for Ito processes.
  
    Represents a general Ito process:
  
    ```None
      dX_i = a_i(t, X) dt + Sum(S_{ij}(t, X) dW_j for 1 <= j <= n), 1 <= i <= n
    ```
  
  The vector coefficient `a_i` is referred to as the drift of the process and
  the matrix `S_{ij}` as the volatility of the process. For the process to be
  well defined, these coefficients need to satisfy certain technical conditions
  which may be found in Ref. [1]. The vector `dW_j` represents independent
  Brownian increments.
  
  #### Example. 2-dimensional Ito process of the form
  
  ```none
  dX_1 = mu_1 * sqrt(t) dt + s11 * dW_1 + s12 * dW_2
  dX_2 = mu_2 * sqrt(t) dt + s21 * dW_1 + s22 * dW_2
  ```
  
  class SimpleItoProcess(ito_process.ItoProcess):
    def __init__(self, dim, drift_fn, vol_fn, dtype=tf.float64):
      self._dim = dim
      self._drift_fn = drift_fn
      self._vol_fn = vol_fn
      self._dtype = dtype
  
    def dim(self):
      return self._dim
  
    def drift_fn(self):
      return self._drift_fn
  
    def volatility_fn(self):
      return self._vol_fn
  
    def dtype(self):
      return self._dtype
  
    def name(self):
      return 'simple_ito_process'
  
  mu = np.array([0.2, 0.7])
  s = np.array([[0.3, 0.1], [0.1, 0.3]])
  num_samples = 10000
  dim = 2
  dtype=tf.float64
  
  # Define drift and volatility functions
  def drift_fn(t, x):
    return mu * tf.sqrt(t) * tf.ones([num_samples, dim], dtype=dtype)
  
  def vol_fn(t, x):
    return s * tf.ones([num_samples, dim, dim], dtype=dtype)
  
  # Initialize `SimpleItoProcess`
  process = SimpleItoProcess(dim=2, drift_fn=drift_fn, vol_fn=vol_fn,
                             dtype=dtype)
  # Set starting location
  x0 = np.array([0.1, -1.1])
  # Sample `num_samples` paths at specified `times` locations using built-in
  # Euler scheme.
  times = [0.1, 1.0, 2.0]
  paths = process.sample_paths(
            times,
            num_samples=num_samples,
            initial_state=x0,
            grid_step=0.01,
            seed=42)
  
  #### References
  [1]: Brent Oksendal. Stochastic Differential Equations: An Introduction with
    Applications. Springer. 2010.
docstr: Returns a solver for solving Feynman-Kac PDE associated to the process.
  
  Constructs a finite differences grid solver for solving the final value
  problem as it appears in the Feynman-Kac formula associated to this Ito
  process. The Feynman-Kac PDE is closely related to the backward Kolomogorov
  equation associated to the stochastic process and allows for the inclusion
  of a discount rate.
  
  A limited version of Feynman-Kac formula states the following.
  Consider the expectation
  
  ```None
    V(x, t, T) = E_Q[e^{-R(t, T)} f(X_T) | X_t = x]
  ```
  
  where `Q` is a probability measure under which `W_j` is an n-dimensional
  Wiener process, `X` is an n-dimensional Ito process satisfying:
  
  ```None
    dX_i = mu_i dt + Sum[Sigma_{ij} dW_j, 1 <= j <= n]
  ```
  
  and `R(t, T)` is a positive stochastic process given by:
  
  ```None
    R(t,T) = Integral[ r(s, X_s) ds, t <= s <= T]
  ```
  
  This expectation is the solution of the following second order linear
  partial differential equation:
  
  ```None
    V_t + Sum[mu_i(t, x) V_i, 1<=i<=n] +
      (1/2) Sum[ D_{ij} V_{ij}, 1 <= i,j <= n] - r(t, x) V = 0
  ```
  
  In the above, `V_t` is the derivative of `V` with respect to `t`,
  `V_i` is the partial derivative with respect to `x_i` and `V_{ij}` the
  (mixed) partial derivative with respect to `x_i` and `x_j`. `D_{ij}` are
  the components of the diffusion tensor:
  
  ```None
    D_{ij} = (Sigma . Transpose[Sigma])_{ij}
  ```
  
  This method provides a finite difference solver to solve the above
  differential equation. Whereas the coefficients `mu` and `D` are properties
  of the SDE itself, the function `r(t, x)` may be arbitrarily specified
  by the user (the parameter `discounting_fn` to this method).
  
  Args:
    final_time: Positive scalar real `Tensor`. The time of the final value.
      The solver is initialized to this final time.
    discounting_fn: Python callable corresponding to the function `r(t, x)` in
      the description above. The callable accepts two positional arguments.
      The first argument is the time at which the discount rate function is
      needed. The second argument contains the values of the state at which
      the discount is to be computed.
      Default value: None which maps to `r(t, x) = 0`.
    grid_spec: An iterable convertible to a tuple containing at least the
      attributes named 'grid', 'dim' and 'sizes'. For a full description of
      the fields and expected types, see `grids.GridSpec` which provides the
      canonical specification of this object.
    time_step: A real positive scalar `Tensor` or None. The fixed
      discretization parameter along the time dimension. Either this argument
      or the `time_step_fn` must be specified. It is an error to specify both.
      Default value: None.
    time_step_fn: A callable accepting an instance of `grids.GridStepperState`
      and returning the size of the next time step as a real scalar tensor.
      This argument allows usage of a non-constant time step while stepping
      back. If not specified, the `time_step` parameter must be specified. It
      is an error to specify both.
      Default value: None.
    values_batch_size: A positive Python int. The batch size of values to be
      propagated simultaneously.
      Default value: 1.
    name: Python str. The name to give this op.
      Default value: None which maps to `fd_solver_backward`.
    **kwargs: Any other keyword args needed.
  
  Returns:
    An instance of `BackwardGridStepper` configured for solving the
    Feynman-Kac PDE associated to this process.
docstr_tok: ["Returns","a","solver","for","solving","Feynman-Kac","PDE","associated","to","the","process",".","Constructs","a","finite","differences","grid","solver","for","solving","the","final","value","problem","as","it","appears","in","the","Feynman-Kac","formula","associated","to","this","Ito","process",".","The","Feynman-Kac","PDE","is","closely","related","to","the","backward","Kolomogorov","equation","associated","to","the","stochastic","process","and","allows","for","the","inclusion","of","a","discount","rate",".","A","limited","version","of","Feynman-Kac","formula","states","the","following",".","Consider","the","expectation","``","`","None","V","(","x",",","t",",","T",")","=","E_Q","[","e^","{","-R","(","t",",","T",")","}","f","(","X_T",")","|","X_t","=","x","]","``","`","where","`","Q","`","is","a","probability","measure","under","which","`","W_j","`","is","an","n-dimensional","Wiener","process",",","`","X","`","is","an","n-dimensional","Ito","process","satisfying",":","``","`","None","dX_i","=","mu_i","dt","+","Sum","[","Sigma_","{","ij","}","dW_j",",","1","<","=","j","<","=","n","]","``","`","and","`","R","(","t",",","T",")","`","is","a","positive","stochastic","process","given","by",":","``","`","None","R","(","t",",","T",")","=","Integral","[","r","(","s",",","X_s",")","ds",",","t","<","=","s","<","=","T","]","``","`","This","expectation","is","the","solution","of","the","following","second","order","linear","partial","differential","equation",":","``","`","None","V_t","+","Sum","[","mu_i","(","t",",","x",")","V_i",",","1","<","=i","<","=n","]","+","(","1\/2",")","Sum","[","D_","{","ij","}","V_","{","ij","}",",","1","<","=","i",",","j","<","=","n","]","-","r","(","t",",","x",")","V","=","0","``","`","In","the","above",",","`","V_t","`","is","the","derivative","of","`","V","`","with","respect","to","`","t","`",",","`","V_i","`","is","the","partial","derivative","with","respect","to","`","x_i","`","and","`","V_","{","ij","}","`","the","(","mixed",")","partial","derivative","with","respect","to","`","x_i","`","and","`","x_j","`",".","`","D_","{","ij","}","`","are","the","components","of","the","diffusion","tensor",":","``","`","None","D_","{","ij","}","=","(","Sigma",".","Transpose","[","Sigma","]",")","_","{","ij","}","``","`","This","method","provides","a","finite","difference","solver","to","solve","the","above","differential","equation",".","Whereas","the","coefficients","`","mu","`","and","`","D","`","are","properties","of","the","SDE","itself",",","the","function","`","r","(","t",",","x",")","`","may","be","arbitrarily","specified","by","the","user","(","the","parameter","`","discounting_fn","`","to","this","method",")",".","Args",":","final_time",":","Positive","scalar","real","`","Tensor","`",".","The","time","of","the","final","value",".","The","solver","is","initialized","to","this","final","time",".","discounting_fn",":","Python","callable","corresponding","to","the","function","`","r","(","t",",","x",")","`","in","the","description","above",".","The","callable","accepts","two","positional","arguments",".","The","first","argument","is","the","time","at","which","the","discount","rate","function","is","needed",".","The","second","argument","contains","the","values","of","the","state","at","which","the","discount","is","to","be","computed",".","Default","value",":","None","which","maps","to","`","r","(","t",",","x",")","=","0","`",".","grid_spec",":","An","iterable","convertible","to","a","tuple","containing","at","least","the","attributes","named","'grid","'",",","'dim","'","and","'sizes","'",".","For","a","full","description","of","the","fields","and","expected","types",",","see","`","grids.GridSpec","`","which","provides","the","canonical","specification","of","this","object",".","time_step",":","A","real","positive","scalar","`","Tensor","`","or","None",".","The","fixed","discretization","parameter","along","the","time","dimension",".","Either","this","argument","or","the","`","time_step_fn","`","must","be","specified",".","It","is","an","error","to","specify","both",".","Default","value",":","None",".","time_step_fn",":","A","callable","accepting","an","instance","of","`","grids.GridStepperState","`","and","returning","the","size","of","the","next","time","step","as","a","real","scalar","tensor",".","This","argument","allows","usage","of","a","non-constant","time","step","while","stepping","back",".","If","not","specified",",","the","`","time_step","`","parameter","must","be","specified",".","It","is","an","error","to","specify","both",".","Default","value",":","None",".","values_batch_size",":","A","positive","Python","int",".","The","batch","size","of","values","to","be","propagated","simultaneously",".","Default","value",":","1.","name",":","Python","str",".","The","name","to","give","this","op",".","Default","value",":","None","which","maps","to","`","fd_solver_backward","`",".","*","*","kwargs",":","Any","other","keyword","args","needed",".","Returns",":","An","instance","of","`","BackwardGridStepper","`","configured","for","solving","the","Feynman-Kac","PDE","associated","to","this","process","."]
code: def fd_solver_backward(
      self,
      final_time,
      discounting_fn=None,
      grid_spec=None,
      time_step=None,
      time_step_fn=None,
      values_batch_size=1,
      name=None,
      **kwargs,
  ):
      """Returns a solver for solving Feynman-Kac PDE associated to the process.
  
      Constructs a finite differences grid solver for solving the final value
      problem as it appears in the Feynman-Kac formula associated to this Ito
      process. The Feynman-Kac PDE is closely related to the backward Kolomogorov
      equation associated to the stochastic process and allows for the inclusion
      of a discount rate.
  
      A limited version of Feynman-Kac formula states the following.
      Consider the expectation
  
      ```None
        V(x, t, T) = E_Q[e^{-R(t, T)} f(X_T) | X_t = x]
      ```
  
      where `Q` is a probability measure under which `W_j` is an n-dimensional
      Wiener process, `X` is an n-dimensional Ito process satisfying:
  
      ```None
        dX_i = mu_i dt + Sum[Sigma_{ij} dW_j, 1 <= j <= n]
      ```
  
      and `R(t, T)` is a positive stochastic process given by:
  
      ```None
        R(t,T) = Integral[ r(s, X_s) ds, t <= s <= T]
      ```
  
      This expectation is the solution of the following second order linear
      partial differential equation:
  
      ```None
        V_t + Sum[mu_i(t, x) V_i, 1<=i<=n] +
          (1/2) Sum[ D_{ij} V_{ij}, 1 <= i,j <= n] - r(t, x) V = 0
      ```
  
      In the above, `V_t` is the derivative of `V` with respect to `t`,
      `V_i` is the partial derivative with respect to `x_i` and `V_{ij}` the
      (mixed) partial derivative with respect to `x_i` and `x_j`. `D_{ij}` are
      the components of the diffusion tensor:
  
      ```None
        D_{ij} = (Sigma . Transpose[Sigma])_{ij}
      ```
  
      This method provides a finite difference solver to solve the above
      differential equation. Whereas the coefficients `mu` and `D` are properties
      of the SDE itself, the function `r(t, x)` may be arbitrarily specified
      by the user (the parameter `discounting_fn` to this method).
  
      Args:
        final_time: Positive scalar real `Tensor`. The time of the final value.
          The solver is initialized to this final time.
        discounting_fn: Python callable corresponding to the function `r(t, x)` in
          the description above. The callable accepts two positional arguments.
          The first argument is the time at which the discount rate function is
          needed. The second argument contains the values of the state at which
          the discount is to be computed.
          Default value: None which maps to `r(t, x) = 0`.
        grid_spec: An iterable convertible to a tuple containing at least the
          attributes named 'grid', 'dim' and 'sizes'. For a full description of
          the fields and expected types, see `grids.GridSpec` which provides the
          canonical specification of this object.
        time_step: A real positive scalar `Tensor` or None. The fixed
          discretization parameter along the time dimension. Either this argument
          or the `time_step_fn` must be specified. It is an error to specify both.
          Default value: None.
        time_step_fn: A callable accepting an instance of `grids.GridStepperState`
          and returning the size of the next time step as a real scalar tensor.
          This argument allows usage of a non-constant time step while stepping
          back. If not specified, the `time_step` parameter must be specified. It
          is an error to specify both.
          Default value: None.
        values_batch_size: A positive Python int. The batch size of values to be
          propagated simultaneously.
          Default value: 1.
        name: Python str. The name to give this op.
          Default value: None which maps to `fd_solver_backward`.
        **kwargs: Any other keyword args needed.
  
      Returns:
        An instance of `BackwardGridStepper` configured for solving the
        Feynman-Kac PDE associated to this process.
      """
      raise NotImplementedError(
          "Backward Finite difference solver not "
          "implemented for ItoProcess."
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/legacy/ito_process.py
imports: import abc
  import six
  import tensorflow.compat.v2
  from tf_quant_finance.math import random_ops
label_desc: Use image node_id 7 for calling the ItoProcess obj's underlying member method code with example usage: obj.fd_solver_backward(final_time, discounting_fn, grid_spec, time_step, time_step_fn, values_batch_size, name) without return types