JumpDiffusion

class samplepaths.continuous.JumpDiffusion(*, drift=0.0, volatility=1.0, rate=1.0, t=1.0, rng=None)[source]

Bases: GaussianNoise

Base class of the geometric Brownian motions with jumps.

A price \(S_t\) which follows a geometric Brownian motion between the jumps of a Poisson process with rate \(\lambda\), and is multiplied by \(e^{Y}\) at each jump:

\[S_t = S_0 \exp \left( \left( \mu - \frac{\sigma^2}{2} - \lambda \kappa \right) t + \sigma W_t + \sum_{k=1}^{N_t} Y_k \right)\]

where \(\kappa = E[e^{Y} - 1]\) is the mean relative jump. The term \(\lambda \kappa\) compensates the jumps, so that the expected value is \(S_0 e^{\mu t}\) whatever the jumps.

A subclass defines the distribution of the jump sizes \(Y\).

Parameters:
  • drift (float) – the expected rate of return, or \(\mu\) above

  • volatility (float) – the volatility between jumps, or \(\sigma\) above

  • rate (float) – the rate of the jumps, or \(\lambda\) above

  • t (float) – the right hand endpoint of the time interval \([0,t]\) for the process

  • rng (Generator | None) – a custom random number generator

property drift: float

Expected rate of return, or \(\mu\).

property volatility: float

Volatility between jumps, or \(\sigma\).

property rate: float

Rate of the jumps, or \(\lambda\).

abstract property mean_relative_jump: float

Mean relative jump, or \(\kappa = E[e^{Y} - 1]\).

sample(n)[source]

Generate a realization.

Parameters:

n (int) – the number of increments to generate

Returns:

the realization

Return type:

NDArray[float64]

property n: int

Number of increments of the most recent realization.

Raises:

RuntimeError – if no realization has been generated yet

property rng: Generator

Random number generator used by the process.

This is the generator passed at instantiation, or the package default samplepaths.random.generator when none was given.

sample_at(times)[source]

Generate a realization at specified times.

Parameters:

times (NDArray[float64]) – a vector of increasing time values at which to generate the realization

Returns:

the realization

Raises:

NotImplementedError – if the process does not support sampling at specified times

Return type:

NDArray[float64]

sample_paths(n, paths, workers=1)

Generate several independent realizations at once.

The realizations have the distribution of those of sample(). Many processes generate them together, which is much faster than calling sample() repeatedly. For a given seed, the values differ from those of repeated calls to sample(), because the random numbers are drawn in a different order.

With workers greater than one, the realizations are generated on that many threads, each with its own generator derived from the generator of the process. The result is reproducible for a given seed and number of workers, and differs between numbers of workers. Processes which generate their realizations one after the other ignore workers.

Parameters:
  • n (int) – the number of increments of each realization

  • paths (int) – the number of realizations

  • workers (int) – the number of threads to use

Returns:

a two-dimensional array with one realization per row

Return type:

NDArray[float64]

set_times(n)

Generate the time values of n increments on [0, t].

Parameters:

n (int) – the number of increments

Returns:

True if the time values changed, False if they were already generated for the same arguments

Return type:

bool

set_times_with_t(end_t, n)

Generate the time values of n increments on [0, end_t].

Parameters:
  • end_t (float) – the right hand endpoint of the time interval

  • n (int) – the number of increments

Returns:

True if the time values changed, False if they were already generated for the same arguments

Return type:

bool

property t: float

End time of the process.

property times: ndarray[tuple[Any, ...], dtype[float64]]

Time values of the most recent realization.

Holds n + 1 equally spaced values on the interval \([0,t]\).

Raises:

RuntimeError – if no realization has been generated yet

sample_with_initial(n, initial=1.0)[source]

Generate a realization starting from an initial value.

Parameters:
  • n (int) – the number of increments to generate

  • initial (float) – the initial value of the process \(S_0\)

Returns:

the realization

Return type:

NDArray[float64]

sample_at_with_initial(times, initial=1.0)[source]

Generate a realization at specified times from an initial value.

Parameters:
  • times (NDArray[float64]) – a vector of increasing time values at which to generate the realization

  • initial (float) – the initial value of the process \(S_0\)

Returns:

the realization

Return type:

NDArray[float64]

sample_paths_with_initial(n, paths, initial=1.0, workers=1)[source]

Generate several realizations starting from an initial value.

Parameters:
  • n (int) – the number of increments of each realization

  • paths (int) – the number of realizations

  • initial (float) – the initial value of the process \(S_0\)

  • workers (int) – the number of threads to use

Returns:

a two-dimensional array with one realization per row

Return type:

NDArray[float64]