Stochastic process realizations.
Project description
A python package for generating realizations of common (and perhaps some less common) stochastic processes, with some optimization for repeated simulation.
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 discretetime, continuoustime, 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
continuous
 BesselProcess
 BrownianBridge
 BrownianExcursion
 BrownianMeander
 BrownianMotion
 CauchyProcess
 FractionalBrownianMotion
 GammaProcess
 GeometricBrownianMotion
 InverseGaussianProcess
 MultifractionalBrownianMotion
 PoissonProcess
 SquaredBesselProcess
 VarianceGammaProcess
 WienerProcess
diffusion
 ConstantElasticityVarianceProcess
 CoxIngersollRossProcess
 OrnsteinUhlenbeckProcess
 VasicekProcess
discrete
 BernoulliProcess
 ChineseRestaurantProcess
 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.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.continuous import BrownianMotion bm = BrownianMotion(drift=1, scale=1, t=1) times = [0, 3, 10, 11, 11.2, 20] s = 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.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 processspecific implementations.
from stochastic.noise import FractionalGaussianNoise fgn = FractionalGaussianNoise(hurst=0.6, t=1) s = fgn.sample(32, algorithm='hosking')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size stochastic0.4.0py2.py3noneany.whl (43.6 kB)  File type Wheel  Python version py2.py3  Upload date  Hashes View 
Filename, size stochastic0.4.0.tar.gz (31.7 kB)  File type Source  Python version None  Upload date  Hashes View 
Hashes for stochastic0.4.0py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  59bc3e1bc1c7b8645d996e36c3e75ed19b8397bac9de3f5ac7abaf07f37c3025 

MD5  63443747d536ce9e18b5078d5455f642 

BLAKE2256  62fb1bdf5bef80bb31369306290c308371a64aebf825029520602570135ea7f1 