Skip to main content

samplepaths

Tests Documentation PyPI version Python versions Weekly downloads Total downloads License

Generate realizations (sample paths) of stochastic processes as NumPy arrays.

Realizations of a Brownian motion with drift and their quantile bands

from samplepaths import BrownianMotion

bm = BrownianMotion(drift=1, scale=2, t=10)
path = bm.sample(1000)  # 1001 values on [0, 10]
  • 37 processes in four families: continuous-time, diffusion, discrete-time and noise
  • One interface: every process is a class with a sample(n) method
  • Reproducible: built on numpy.random.Generator, per process or through a seedable default
  • Typed: type hints throughout, checked with mypy in strict mode
  • Light: depends only on NumPy and SciPy

Full documentation: https://samplepaths.readthedocs.io/

Installation

pip install samplepaths

samplepaths requires Python 3.12 or newer, NumPy 2.2 or newer and SciPy 1.15 or newer.

Quickstart

Create a process with its parameters, then call sample(n) to generate a realization of n increments. For a process on a time interval, the realization holds n + 1 values and times holds the matching time values.

import matplotlib.pyplot as plt
from samplepaths import FractionalBrownianMotion

fbm = FractionalBrownianMotion(hurst=0.7, t=5)

for _ in range(3):
    path = fbm.sample(512)
    plt.plot(fbm.times, path)

plt.show()

Reproducible results

Give a process its own generator, or seed the generator shared by all processes created without one.

import numpy as np
from samplepaths import BrownianMotion
from samplepaths import random

bm = BrownianMotion(rng=np.random.default_rng(42))

random.seed(value=42)

Sampling at chosen times

Most continuous-time processes can be sampled at times of your choice with sample_at().

from samplepaths import BrownianMotion

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

More than one way to sample

sample(n) has the same signature on every process. Variants have their own methods.

from samplepaths import FractionalGaussianNoise
from samplepaths import GeometricBrownianMotion
from samplepaths import PoissonProcess

prices = GeometricBrownianMotion(drift=0.05, volatility=0.2).sample_with_initial(252, initial=100.0)
arrivals = PoissonProcess(rate=2.0).sample_with_length(10.0)
noise = FractionalGaussianNoise(hurst=0.6).sample_hosking(32)

Generic simulation code

Because the interface is shared, simulation code does not depend on the process it simulates.

import numpy as np
from samplepaths import CoxIngersollRossProcess
from samplepaths import GeometricBrownianMotion
from samplepaths.base import BaseTimeProcess


def final_values(process: BaseTimeProcess, n: int, paths: int) -> np.ndarray:
    """Simulate a number of paths and collect the last value of each."""
    return np.array([process.sample(n)[-1] for _ in range(paths)])


final_values(GeometricBrownianMotion(drift=0.05, volatility=0.2), n=64, paths=1000)
final_values(CoxIngersollRossProcess(speed=1, mean=1, vol=0.5), n=64, paths=1000)

Processes

One example process of each of the four families

Every process can be imported from samplepaths or from the subpackage of its family.

Family Subpackage Processes
Continuous-time samplepaths.continuous BesselProcess, BrownianBridge, BrownianExcursion, BrownianMeander, BrownianMotion, CauchyProcess, FractionalBrownianMotion, GammaProcess, GeometricBrownianMotion, InverseGaussianProcess, MixedPoissonProcess, MultifractionalBrownianMotion, PoissonProcess, SquaredBesselProcess, VarianceGammaProcess, WienerProcess
Diffusion samplepaths.diffusion DiffusionProcess, ConstantElasticityVarianceProcess, CoxIngersollRossProcess, ExtendedVasicekProcess, OrnsteinUhlenbeckProcess, VasicekProcess
Discrete-time samplepaths.discrete BernoulliProcess, ChineseRestaurantProcess, DirichletProcess, MarkovChain, MoranProcess, RandomWalk
Noise samplepaths.noise GaussianNoise, FractionalGaussianNoise, ColoredNoise, VioletNoise, BlueNoise, WhiteNoise, PinkNoise, RedNoise, BrownianNoise

Diffusion processes are approximated with the Euler-Maruyama method.

Documentation

The documentation at https://samplepaths.readthedocs.io/ contains:

Coming from stochastic

samplepaths is an independently maintained fork of stochastic 0.7.0 by Christopher Flynn. It keeps the original processes and algorithms and modernizes everything around them: current Python, NumPy and SciPy, type hints, one sampling interface, and corrected drift handling.

Porting is mostly a change of import:

# stochastic
from stochastic.processes.continuous import BrownianMotion

# samplepaths
from samplepaths.continuous import BrownianMotion

See the migration guide for the full list of changes.

Development

The project is managed with uv and make.

git clone https://github.com/samplepaths/samplepaths.git
cd samplepaths
make install  # create the environment
make check    # lint, type check, test and build the docs

Run make to list all targets. Bug reports and pull requests are welcome on GitHub.

License

samplepaths is released under the MIT license.

It is maintained by Bassem Girgis.

Metadata

Release files for samplepaths 0.2.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 samplepaths 0.2.0
File Size Uploaded Provenance Actions
samplepaths-0.2.0.tar.gz 41.7 kB Without provenance Details for samplepaths-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 100.0 kB

Release files / samplepaths-0.2.0.tar.gz

Download URL samplepaths-0.2.0.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cb848ea8867519af3faedd5a5d7d681d0c0d4ad5043cd0660079ba5a30efef0b
BLAKE2b-256 checksum
How to use checksums
d6e7128b4413c28bcaa07008f4b1a4b545244abf6d11cc9b840c8ebefb97eea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / samplepaths-0.2.0-py3-none-any.whl

Download URL samplepaths-0.2.0-py3-none-any.whl
Size 58.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13df0f09ac9ae32e2fd07575d31e415eed0b2fb4f8f08d75ccc264c23931dc93
BLAKE2b-256 checksum
How to use checksums
1d33cf2155ce5e0db13397fd7b3f938a80024d4f760a8a9fd73688ea6b53c4f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for samplepaths 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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