pfhedge.stochastic.generate_cir¶
- pfhedge.stochastic.generate_cir(n_paths, n_steps, init_state=None, kappa=1.0, theta=0.04, sigma=0.2, dt=0.004, dtype=None, device=None)[source]¶
Returns time series following Cox-Ingersoll-Ross process.
The time evolution of the process is given by:
\[dX(t) = \kappa (\theta - X(t)) dt + \sigma \sqrt{X(t)} dW(t) .\]Time series is generated by Andersen’s QE-M method (See Reference for details).
References
Andersen, Leif B.G., Efficient Simulation of the Heston Stochastic Volatility Model (January 23, 2007). Available at SSRN: https://ssrn.com/abstract=946405 or http://dx.doi.org/10.2139/ssrn.946404
- Parameters
n_paths (int) – The number of simulated paths.
n_steps (int) – The number of time steps.
init_state (tuple[torch.Tensor | float], optional) – The initial state of the time series. This is specified by a tuple \((X(0),)\). It also accepts a
torch.Tensor
or afloat
. IfNone
(default), it uses \((\theta, )\).kappa (torch.Tensor or float, default=1.0) – The parameter \(\kappa\).
theta (torch.Tensor or float, default=0.04) – The parameter \(\theta\).
sigma (torch.Tensor or float, default=2.0) – The parameter \(\sigma\).
dt (torch.Tensor or float, default=1/250) – The intervals of the time steps.
dtype (torch.dtype, optional) – The desired data type of returned tensor. Default: If
None
, uses a global default (seetorch.set_default_tensor_type()
).device (torch.device, optional) – The desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see
torch.set_default_tensor_type()
).device
will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.
- Shape:
Output: \((N, T)\) where \(N\) is the number of paths and \(T\) is the number of time steps.
- Returns
torch.Tensor
Examples
>>> from pfhedge.stochastic import generate_cir >>> >>> _ = torch.manual_seed(42) >>> generate_cir(2, 5) tensor([[0.0400, 0.0408, 0.0411, 0.0417, 0.0422], [0.0400, 0.0395, 0.0452, 0.0434, 0.0446]])