ConditionalVarianceProcess

class samplepaths.timeseries.ConditionalVarianceProcess(*, omega, rng=None)[source]

Bases: BaseSequenceProcess

Base class of the time series models with a changing variance.

A series of values with a zero mean whose variance depends on the past,

\[X_t = \sigma_t z_t, \quad z_t \sim N(0, 1)\]

where the variance \(\sigma_t^2\) is a function of the previous values and of their variances. Calm and agitated periods alternate, as in the returns of financial assets.

A subclass defines that function. A realization starts from the stationary state of the model: the variances before the first value are at their long-run level, and the values before it are drawn at that level.

After a call to sample() or sample_paths(), the attribute volatility holds the standard deviations \(\sigma_t\) of the values.

Parameters:
  • omega (float) – the constant term of the variance

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

property omega: float

Constant term of the variance, or \(\omega\).

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

Standard deviations \(\sigma_t\) of the most recent realization.

An array of the shape of the result of sample() or sample_paths(), whichever was called last.

Raises:

RuntimeError – if no realization has been generated yet

sample(n)[source]

Generate a realization.

Parameters:

n (int) – the number of increments to generate

Returns:

the realization. Processes with integer values, such as the state of a Markov chain, return an array of integers.

Return type:

NDArray[float64]

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_paths(n, paths, workers=1)[source]

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]