pfhedge.stochastic.generate_vasicek

pfhedge.stochastic.generate_vasicek(n_paths, n_steps, init_state=None, kappa=1.0, theta=0.04, sigma=0.04, dt=0.004, dtype=None, device=None)[source]

Returns time series following Vasicek model.

The time evolution of the process is given by:

\[dX(t) = \kappa (\theta - X(t)) dt + \sigma dW(t) .\]

References

  • Gillespie, D.T., 1996. Exact numerical simulation of the Ornstein-Uhlenbeck process and its integral. Physical review E, 54(2), p.2084.

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 a float. If None (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=0.04) – 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 (see torch.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_vasicek
...
>>> _ = torch.manual_seed(42)
>>> generate_vasicek(2, 5)
tensor([[0.0400, 0.0409, 0.0412, 0.0418, 0.0423],
        [0.0400, 0.0395, 0.0451, 0.0435, 0.0446]])