class_docstr: Cox–Ingersoll–Ross model.
  
  Represents the Ito process:
  
  ```None
    dX_i(t) = (a - k*X_i(t)) * dt +  sigma * sqrt(X_i(t)) * dW_i(t)
  ```
  where
    a / k: Corresponds to the long term mean.
    k: Corresponds to the speed of reversion.
    sigma: Corresponds to the instantaneous volatility.
  
  See [1] for details.
  
  #### References:
    [1]: A. Alfonsi. Affine Diffusions and Related Processes: Simulation,
      Theory and Applications
class_docstr_tok: ["Cox\u2013Ingersoll\u2013Ross","model",".","Represents","the","Ito","process",":","``","`","None","dX_i","(","t",")","=","(","a","-","k","*","X_i","(","t",")",")","*","dt","+","sigma","*","sqrt","(","X_i","(","t",")",")","*","dW_i","(","t",")","``","`","where","a","\/","k",":","Corresponds","to","the","long","term","mean",".","k",":","Corresponds","to","the","speed","of","reversion",".","sigma",":","Corresponds","to","the","instantaneous","volatility",".","See","[","1","]","for","details",".","#","#","#","#","References",":","[","1","]",":","A.","Alfonsi",".","Affine","Diffusions","and","Related","Processes",":","Simulation",",","Theory","and","Applications"]
docstr: Initializes the CIR Model.
  
  Args:
    theta: A positive scalar `Tensor` with shape `batch_shape` + [1].
    mean_reversion: A positive scalar `Tensor` of the same dtype and shape as
      `theta`. Means speed of reversion.
    sigma: A scalar `Tensor` of the same dtype and shape as `theta`.Means
      volatility.
    dtype: The default dtype to use when converting values to `Tensor`s.
      Default value: `None` which maps to `tf.float32`.
    name: Python string. The name to give to the ops created by this class.
      Default value: `None` which maps to the default name `cir_model`.
docstr_tok: ["Initializes","the","CIR","Model",".","Args",":","theta",":","A","positive","scalar","`","Tensor","`","with","shape","`","batch_shape","`","+","[","1","]",".","mean_reversion",":","A","positive","scalar","`","Tensor","`","of","the","same","dtype","and","shape","as","`","theta","`",".","Means","speed","of","reversion",".","sigma",":","A","scalar","`","Tensor","`","of","the","same","dtype","and","shape","as","`","theta","`",".Means","volatility",".","dtype",":","The","default","dtype","to","use","when","converting","values","to","`","Tensor","`","s",".","Default","value",":","`","None","`","which","maps","to","`","tf.float32","`",".","name",":","Python","string",".","The","name","to","give","to","the","ops","created","by","this","class",".","Default","value",":","`","None","`","which","maps","to","the","default","name","`","cir_model","`","."]
code: def __init__(
      self,
      theta: types.RealTensor,
      mean_reversion: types.RealTensor,
      sigma: types.RealTensor,
      dtype: Optional[tf.DType] = None,
      name: Optional[str] = None,
  ):
      """Initializes the CIR Model.
  
      Args:
        theta: A positive scalar `Tensor` with shape `batch_shape` + [1].
        mean_reversion: A positive scalar `Tensor` of the same dtype and shape as
          `theta`. Means speed of reversion.
        sigma: A scalar `Tensor` of the same dtype and shape as `theta`.Means
          volatility.
        dtype: The default dtype to use when converting values to `Tensor`s.
          Default value: `None` which maps to `tf.float32`.
        name: Python string. The name to give to the ops created by this class.
          Default value: `None` which maps to the default name `cir_model`.
      """
  
      dim = 1
      dtype = dtype or tf.float32
      name = name or "cir_model"
      with tf.name_scope(name):
  
          def _convert_param_to_tensor(param):
              """Converts `param` to `Tesnor`.
  
              Args:
                param: `Scalar` or `Tensor` with shape `batch_shape` + [1].
  
              Returns:
                `param` if it `Tensor`, if it is `Scalar` convert it to `Tensor` with
                [1] shape.
              """
              param_t = tf.convert_to_tensor(param, dtype=dtype)
              return param_t * tf.ones(shape=dim, dtype=dtype)
  
          def _get_batch_shape(param):
              """`param` must has shape `batch_shape + [1]`."""
              param_shape = tff_utils.get_shape(param)
              # Last rank is `1`
              return param_shape[:-1]
  
          # Converts params to `Tensor` with shape `batch_shape + [1]`
          self._theta = _convert_param_to_tensor(theta)
          self._mean_reversion = _convert_param_to_tensor(
              mean_reversion
          )
          self._sigma = _convert_param_to_tensor(sigma)
  
          self._batch_shape = _get_batch_shape(self._theta)
          self._batch_shape_rank = len(self._batch_shape)
  
          def _drift_fn(t, x):
              del t
  
              expand_rank = (
                  tff_utils.get_shape(x).rank
                  - self._batch_shape_rank
                  - 1
              )
              # `axis` is -2, because the new dimension needs to be added before `1`
              theta_expand = self._expand_param_on_rank(
                  self._theta, expand_rank, axis=-2
              )
              mean_reversion_expand = self._expand_param_on_rank(
                  self._mean_reversion, expand_rank, axis=-2
              )
              return theta_expand - mean_reversion_expand * x
  
          def _volatility_fn(t, x):
              del t
  
              expand_rank = (
                  len(tff_utils.get_shape(x))
                  - self._batch_shape_rank
                  - 1
              )
              # `axis` is -2, because the new dimension needs to be added before `1`
              sigma_expand = self._expand_param_on_rank(
                  self._sigma, expand_rank, axis=-2
              )
              return tf.expand_dims(sigma_expand * tf.sqrt(x), axis=-1)
  
      super(CirModel, self).__init__(
          dim, _drift_fn, _volatility_fn, dtype, name
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/cir/cir_model.py
imports: from typing import Optional
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance import utils
  from tf_quant_finance.math import random_ops
  from tf_quant_finance.models import generic_ito_process
label_desc: Use image node_id 1 to create a new CirModel object from inherited base classes: generic_ito_process with example: obj = CirModel(theta, mean_reversion, sigma, dtype, name)