Skip to main content

build rtd codecov pypi pyversions

A python package for generating realizations of stochastic processes.

Installation

The stochastic package is available on pypi and can be installed using pip

pip install stochastic

Dependencies

Stochastic uses numpy for many calculations and scipy for sampling specific random variables.

Processes

This package offers a number of common discrete-time, continuous-time, and noise process objects for generating realizations of stochastic processes as numpy arrays.

The diffusion processes are approximated using the Euler–Maruyama method.

Here are the currently supported processes and their class references within the package.

  • stochastic.processes

    • continuous

      • BesselProcess

      • BrownianBridge

      • BrownianExcursion

      • BrownianMeander

      • BrownianMotion

      • CauchyProcess

      • FractionalBrownianMotion

      • GammaProcess

      • GeometricBrownianMotion

      • InverseGaussianProcess

      • MixedPoissonProcess

      • MultifractionalBrownianMotion

      • PoissonProcess

      • SquaredBesselProcess

      • VarianceGammaProcess

      • WienerProcess

    • diffusion

      • DiffusionProcess (generalized)

      • ConstantElasticityVarianceProcess

      • CoxIngersollRossProcess

      • ExtendedVasicekProcess

      • OrnsteinUhlenbeckProcess

      • VasicekProcess

    • discrete

      • BernoulliProcess

      • ChineseRestaurantProcess

      • DirichletProcess

      • MarkovChain

      • MoranProcess

      • RandomWalk

    • noise

      • BlueNoise

      • BrownianNoise

      • ColoredNoise

      • PinkNoise

      • RedNoise

      • VioletNoise

      • WhiteNoise

      • FractionalGaussianNoise

      • GaussianNoise

Usage patterns

Sampling

To use stochastic, import the process you want and instantiate with the required parameters. Every process class has a sample method for generating realizations. The sample methods accept a parameter n for the quantity of steps in the realization, but others (Poisson, for instance) may take additional parameters. Parameters can be accessed as attributes of the instance.

from stochastic.processes.discrete import BernoulliProcess


bp = BernoulliProcess(p=0.6)
s = bp.sample(16)
success_probability = bp.p

Continuous processes provide a default parameter, t, which indicates the maximum time of the process realizations. The default value is 1. The sample method will generate n equally spaced increments on the interval [0, t].

Sampling at specific times

Some continuous processes also provide a sample_at() method, in which a sequence of time values can be passed at which the object will generate a realization. This method ignores the parameter, t, specified on instantiation.

from stochastic.processes.continuous import BrownianMotion


bm = BrownianMotion(drift=1, scale=1, t=1)
times = [0, 3, 10, 11, 11.2, 20]
s = bm.sample_at(times)

Sample times

Continuous processes also provide a method times() which generates the time values (using numpy.linspace) corresponding to a realization of n steps. This is particularly useful for plotting your samples.

import matplotlib.pyplot as plt
from stochastic.processes.continuous import FractionalBrownianMotion


fbm = FractionalBrownianMotion(hurst=0.7, t=1)
s = fbm.sample(32)
times = fbm.times(32)

plt.plot(times, s)
plt.show()

Specifying an algorithm

Some processes provide an optional parameter algorithm, in which one can specify which algorithm to use to generate the realization using the sample() or sample_at() methods. See the documentation for process-specific implementations.

from stochastic.processes.noise import FractionalGaussianNoise


fgn = FractionalGaussianNoise(hurst=0.6, t=1)
s = fgn.sample(32, algorithm='hosking')

Metadata

Release files for stochastic 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stochastic 0.7.0
File Size Uploaded
stochastic-0.7.0.tar.gz 28.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stochastic 0.7.0
File Interpreter ABI Platform
stochastic-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 76.3 kB

Release files / stochastic-0.7.0.tar.gz

Download URL stochastic-0.7.0.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c166b5f7707d0857597125dbffa03f59cb1ffb668cb027396d4cca69b3df1b7b
BLAKE2b-256 checksum
How to use checksums
f08f487894eeb36fff56b4675a1e77242fea0f56bc1632aa56de53b9bc502964
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.2 Darwin/20.1.0

Release files / stochastic-0.7.0-py3-none-any.whl

Download URL stochastic-0.7.0-py3-none-any.whl
Size 48.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b39b807886b9e92b7cba2848e85629cc07bab964f87a3317168b6b9de2e3394f
BLAKE2b-256 checksum
How to use checksums
eec5b0eeb721c07f634ad7fdf9bfc8d397eb5af1150f922fc7620f282f1af5bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.2 Darwin/20.1.0

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page