AutoregressiveProcess

class samplepaths.timeseries.AutoregressiveProcess(*, coefficients=0.5, scale=1.0, rng=None)[source]

Bases: LinearProcess

Autoregressive process, or AR(p).

../../_images/autoregressive_process.png

A series in which every value is a linear combination of the \(p\) previous values, plus Gaussian white noise \(\varepsilon_t\) with standard deviation \(\sigma\):

\[X_t = \sum_{k=1}^p \phi_k X_{t-k} + \varepsilon_t\]

The values before the first one are zero. The series is stationary when the roots of \(1 - \phi_1 z - \dots - \phi_p z^p\) lie outside the unit circle, which for one coefficient means \(|\phi_1| < 1\); this is not required.

Parameters:
  • coefficients (float | Sequence[float]) – the coefficients \(\phi_1, \dots, \phi_p\) above, or a single number for an AR(1)

  • scale (float) – the standard deviation of the noise, or \(\sigma\) above

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

property coefficients: tuple[float, ...]

Coefficients \(\phi_1, \dots, \phi_p\) of the previous values.

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(n)

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]

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]

property scale: float

Standard deviation of the noise, or \(\sigma\).