class_docstr: Generic Ito process defined from a drift and volatility function.
class_docstr_tok: ["Generic","Ito","process","defined","from","a","drift","and","volatility","function","."]
docstr: Initializes the Ito process with given drift and volatility functions.
  
  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 `b_{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. Sampling from 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
  ```
  
  ```python
  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 `GenericItoProcess`
  process = GenericItoProcess(dim=2, drift_fn=drift_fn, volatility_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,
            time_step=0.01,
            seed=42)
  ```
  
  #### References
  [1]: Brent Oksendal. Stochastic Differential Equations: An Introduction with
    Applications. Springer. 2010.
  
  Args:
    dim: Python int greater than or equal to 1. The dimension of the Ito
      process.
    drift_fn: A Python callable to compute the drift of the process. The
      callable should accept two real `Tensor` arguments of the same dtype.
      The first argument is the scalar time t, the second argument is the
      value of Ito process X - `Tensor` of shape
      `batch_shape + sample_shape + [dim]`, where `batch_shape` represents
      a batch of models and `sample_shape` represents samples for each of the
      models. The result is value of drift a(t, X). The return value of the
      callable is a real `Tensor` of the same dtype as the input arguments and
      of shape `batch_shape + sample_shape + [dim]`. For example,
      `sample_shape` can stand for `[num_samples]` for Monte Carlo sampling,
      or `[num_grid_points_1, ..., num_grid_points_dim]` for Finite Difference
      solvers.
    volatility_fn: A Python callable to compute the volatility of the process.
      The callable should accept two real `Tensor` arguments of the same dtype
      and shape `times_shape`. The first argument is the scalar time t, the
      second argument is the value of Ito process X - `Tensor` of shape
      `batch_shape + sample_shape + [dim]`, where `batch_shape` represents
      a batch of models and `sample_shape` represents samples for each of the
      models. The result is value of volatility S_{ij}(t, X). The return value
      of the callable is a real `Tensor` of the same dtype as the input
      arguments and of shape `batch_shape + sample_shape + [dim, dim]`. For
      example, `sample_shape` can stand for `[num_samples]` for Monte Carlo
      sampling, or `[num_grid_points_1, ..., num_grid_points_dim]` for Finite
      Difference solvers.
    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: str. The name scope under which ops created by the methods of this
      class are nested.
      Default value: None which maps to the default name
        `generic_ito_process`.
  
  Raises:
    ValueError if the dimension is less than 1, or if either `drift_fn`
      or `volatility_fn` is not supplied.
docstr_tok: ["Initializes","the","Ito","process","with","given","drift","and","volatility","functions",".","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","`","b_","{","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",".","Sampling","from","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","``","`","``","`","python","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","`","GenericItoProcess","`","process","=","GenericItoProcess","(","dim=2",",","drift_fn=drift_fn",",","volatility_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",",","time_step=0.01",",","seed=42",")","``","`","#","#","#","#","References","[","1","]",":","Brent","Oksendal",".","Stochastic","Differential","Equations",":","An","Introduction","with","Applications",".","Springer",".","2010",".","Args",":","dim",":","Python","int","greater","than","or","equal","to","1",".","The","dimension","of","the","Ito","process",".","drift_fn",":","A","Python","callable","to","compute","the","drift","of","the","process",".","The","callable","should","accept","two","real","`","Tensor","`","arguments","of","the","same","dtype",".","The","first","argument","is","the","scalar","time","t",",","the","second","argument","is","the","value","of","Ito","process","X","-","`","Tensor","`","of","shape","`","batch_shape","+","sample_shape","+","[","dim","]","`",",","where","`","batch_shape","`","represents","a","batch","of","models","and","`","sample_shape","`","represents","samples","for","each","of","the","models",".","The","result","is","value","of","drift","a","(","t",",","X",")",".","The","return","value","of","the","callable","is","a","real","`","Tensor","`","of","the","same","dtype","as","the","input","arguments","and","of","shape","`","batch_shape","+","sample_shape","+","[","dim","]","`",".","For","example",",","`","sample_shape","`","can","stand","for","`","[","num_samples","]","`","for","Monte","Carlo","sampling",",","or","`","[","num_grid_points_1",",","...",",","num_grid_points_dim","]","`","for","Finite","Difference","solvers",".","volatility_fn",":","A","Python","callable","to","compute","the","volatility","of","the","process",".","The","callable","should","accept","two","real","`","Tensor","`","arguments","of","the","same","dtype","and","shape","`","times_shape","`",".","The","first","argument","is","the","scalar","time","t",",","the","second","argument","is","the","value","of","Ito","process","X","-","`","Tensor","`","of","shape","`","batch_shape","+","sample_shape","+","[","dim","]","`",",","where","`","batch_shape","`","represents","a","batch","of","models","and","`","sample_shape","`","represents","samples","for","each","of","the","models",".","The","result","is","value","of","volatility","S_","{","ij","}","(","t",",","X",")",".","The","return","value","of","the","callable","is","a","real","`","Tensor","`","of","the","same","dtype","as","the","input","arguments","and","of","shape","`","batch_shape","+","sample_shape","+","[","dim",",","dim","]","`",".","For","example",",","`","sample_shape","`","can","stand","for","`","[","num_samples","]","`","for","Monte","Carlo","sampling",",","or","`","[","num_grid_points_1",",","...",",","num_grid_points_dim","]","`","for","Finite","Difference","solvers",".","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",":","str",".","The","name","scope","under","which","ops","created","by","the","methods","of","this","class","are","nested",".","Default","value",":","None","which","maps","to","the","default","name","`","generic_ito_process","`",".","Raises",":","ValueError","if","the","dimension","is","less","than","1",",","or","if","either","`","drift_fn","`","or","`","volatility_fn","`","is","not","supplied","."]
code: def __init__(
      self, dim, drift_fn, volatility_fn, dtype=None, name=None
  ):
      """Initializes the Ito process with given drift and volatility functions.
  
      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 `b_{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. Sampling from 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
      ```
  
      ```python
      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 `GenericItoProcess`
      process = GenericItoProcess(dim=2, drift_fn=drift_fn, volatility_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,
                time_step=0.01,
                seed=42)
      ```
  
      #### References
      [1]: Brent Oksendal. Stochastic Differential Equations: An Introduction with
        Applications. Springer. 2010.
  
      Args:
        dim: Python int greater than or equal to 1. The dimension of the Ito
          process.
        drift_fn: A Python callable to compute the drift of the process. The
          callable should accept two real `Tensor` arguments of the same dtype.
          The first argument is the scalar time t, the second argument is the
          value of Ito process X - `Tensor` of shape
          `batch_shape + sample_shape + [dim]`, where `batch_shape` represents
          a batch of models and `sample_shape` represents samples for each of the
          models. The result is value of drift a(t, X). The return value of the
          callable is a real `Tensor` of the same dtype as the input arguments and
          of shape `batch_shape + sample_shape + [dim]`. For example,
          `sample_shape` can stand for `[num_samples]` for Monte Carlo sampling,
          or `[num_grid_points_1, ..., num_grid_points_dim]` for Finite Difference
          solvers.
        volatility_fn: A Python callable to compute the volatility of the process.
          The callable should accept two real `Tensor` arguments of the same dtype
          and shape `times_shape`. The first argument is the scalar time t, the
          second argument is the value of Ito process X - `Tensor` of shape
          `batch_shape + sample_shape + [dim]`, where `batch_shape` represents
          a batch of models and `sample_shape` represents samples for each of the
          models. The result is value of volatility S_{ij}(t, X). The return value
          of the callable is a real `Tensor` of the same dtype as the input
          arguments and of shape `batch_shape + sample_shape + [dim, dim]`. For
          example, `sample_shape` can stand for `[num_samples]` for Monte Carlo
          sampling, or `[num_grid_points_1, ..., num_grid_points_dim]` for Finite
          Difference solvers.
        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: str. The name scope under which ops created by the methods of this
          class are nested.
          Default value: None which maps to the default name
            `generic_ito_process`.
  
      Raises:
        ValueError if the dimension is less than 1, or if either `drift_fn`
          or `volatility_fn` is not supplied.
      """
      if dim < 1:
          raise ValueError("Dimension must be 1 or greater.")
      if drift_fn is None or volatility_fn is None:
          raise ValueError(
              "Both drift and volatility functions must be supplied."
          )
      self._dim = dim
      self._drift_fn = drift_fn
      self._volatility_fn = volatility_fn
      self._dtype = dtype
      self._name = name or "generic_ito_process"
  
file_path: tf-quant-finance/tf_quant_finance/models/generic_ito_process.py
imports: import tensorflow.compat.v2
  from tf_quant_finance.math.pde import fd_solvers
  from tf_quant_finance.models import euler_sampling
  from tf_quant_finance.models import ito_process
label_desc: Use image node_id 1 to create a new GenericItoProcess object from inherited base classes: ito_process with example: obj = GenericItoProcess(dim, drift_fn, volatility_fn, dtype, name)