pfhedge.stochastic.generate_brownian

pfhedge.stochastic.generate_brownian(n_paths, n_steps, init_state=(0.0, ), sigma=0.2, mu=0.0, dt=0.004, dtype=None, device=None, engine=<built-in method randn of type object>)[source]

Returns time series following the Brownian motion.

The time evolution of the process is given by:

\[dS(t) = \mu dt + \sigma dW(t) \,.\]
Parameters
  • n_paths (int) – The number of simulated paths.

  • n_steps (int) – The number of time steps.

  • init_state (tuple[torch.Tensor | float], default=(0.0,)) – The initial state of the time series. This is specified by a tuple \((S(0),)\). It also accepts a torch.Tensor or a float.

  • sigma (float, default=0.2) – The parameter \(\sigma\), which stands for the volatility of the time series.

  • mu (float, default=0.0) – The parameter \(\mu\), which stands for the drift of the time series.

  • dt (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.

  • engine (callable, default=torch.randn) – The desired generator of random numbers from a standard normal distribution. A function call engine(size, dtype=None, device=None) should return a tensor filled with random numbers from a standard normal distribution.

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_brownian
>>>
>>> _ = torch.manual_seed(42)
>>> generate_brownian(2, 5)
tensor([[ 0.0000,  0.0016,  0.0046,  0.0075, -0.0067],
        [ 0.0000,  0.0279,  0.0199,  0.0257,  0.0291]])