pfhedge.stochastic.generate_geometric_brownian¶
- pfhedge.stochastic.generate_geometric_brownian(n_paths, n_steps, init_state=(1.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 geometric Brownian motion.
The time evolution of the process is given by:
\[dS(t) = \mu S(t) dt + \sigma S(t) 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 afloat
.sigma (float, default=0.2) – The parameter \(\sigma\), which stands for the volatility of the time series.
mu (float, default=0.2) – The parameter \(\mu\), which stands for the volatility 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 (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 (seetorch.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_geometric_brownian >>> >>> _ = torch.manual_seed(42) >>> generate_geometric_brownian(2, 5) tensor([[1.0000, 1.0016, 1.0044, 1.0073, 0.9930], [1.0000, 1.0282, 1.0199, 1.0258, 1.0292]])