PYPI PACKAGE AUDIT v0.5.0 Paquete Saludable

samplepaths

Generar realizaciones de procesos estocásticos

PyPkgScore samplepaths
Metodología y Criterios ♥ Donate
770 / 1000
Instalación Rápida
pip install samplepaths
1. Gobernanza
100/200
2. Metadatos PEP
200/200
3. Seguridad
150/200
4. Docs y SEO
155/200
5. Ingeniería CI
165/200
📣 Compartir Auditoría: Comparte este informe y la vista previa en el idioma actual
Advertisement
TELEMETRÍA PYPI

Descargas y Adopción en la Comunidad

Últimos 30 días (sin espejos)
Últimos 7 días
575
Últimos 30 días
575
Total (180 días)
575
Métrica / Ecosistema Estado / Valor Fuente
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✕ Not detected PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 770 / 1000 PyPkgScore Engine

Análisis de Salud e Ingeniería (5 Pilares)

1. Gobernanza y Comunidad100 / 200 ▾
LICENSE✓ 50 pts
SECURITY.md✕ 0 pts
CONTRIBUTING.md✓ 50 pts
CODE_OF_CONDUCT.md✕ 0 pts
2. Metadatos y Empaquetado PEP200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. Seguridad y Cadena de Suministro150 / 200 ▾
Cero CVEs (OSV)✓ 60 pts
Trusted Publishing (OIDC)✕ 0 pts
Snyk / Audit Link✓ 40 pts
Repositorio HTTPS✓ 50 pts
4. Documentación, SEO y Ecosistema155 / 200 ▾
README Estructurado✓ 60 pts
Read the Docs✓ 50 pts
Django Packages✕ 0 pts
Sitio Web / Artículos Técnicos✓ 45 pts
5. Ingeniería, CI y Calidad165 / 200 ▾
Pruebas Automatizadas✓ 65 pts
GitHub Actions CI✓ 65 pts
CHANGELOG.md✕ 0 pts
Env & Lockfile (uv/rye/poetry/pdm/hatch)✓ 35 pts
Advertisement
README & DOCS

Documentación Oficial y Guía de Uso — samplepaths

PyPI Metadata v0.5.0
Mostrar documentación original completa (README en inglés) ▾

samplepaths

Tests Documentation PyPI version Python versions Weekly downloads Total downloads License

Generate realizations (sample paths) of stochastic processes as NumPy arrays. Pure Python, and for large simulations as fast as compiled code.

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]
paths = bm.sample_paths(1000, paths=5000)  # 5000 realizations at once
  • 68 processes in six families: continuous-time, diffusion, discrete-time, time series, several components and noise
  • One interface: every process is a class with sample(n) and sample_paths(n, paths) methods
  • Pure Python, and fast: vectorized with NumPy and multi-threaded; 100,000 Brownian paths of 64 steps take 6 ms on 14 cores, level with a Rust implementation (comparison)
  • 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.11 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)

Many realizations at once

sample_paths(n, paths) returns a two-dimensional array with one realization per row; for a process with several components, such as a Heston model, the components form a second axis. For most processes it is 2 to 13 times faster than a loop over sample(), and workers=8 spreads a large batch over 8 threads.

import numpy as np
from samplepaths import GeometricBrownianMotion

gbm = GeometricBrownianMotion(drift=0.05, volatility=0.2, rng=np.random.default_rng(1))
prices = gbm.sample_paths_with_initial(n=64, paths=100_000, initial=100.0)

payoffs = np.maximum(prices[:, -1] - 105.0, 0.0)
print(np.exp(-0.05) * payoffs.mean())  # a European call price, close to 8.02

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 process.sample_paths(n, paths)[:, -1]


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 six 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, FractionalGeometricBrownianMotion, GammaProcess, GeometricBrownianMotion, CompoundPoissonProcess, HawkesProcess, InverseGaussianProcess, KouJumpDiffusion, MertonJumpDiffusion, MixedPoissonProcess, NormalInverseGaussianProcess, MultifractionalBrownianMotion, PoissonProcess, SquaredBesselProcess, VarianceGammaProcess, WienerProcess
Diffusion samplepaths.diffusion DiffusionProcess, ConstantElasticityVarianceProcess, CoxIngersollRossProcess, ExtendedVasicekProcess, OrnsteinUhlenbeckProcess, VasicekProcess, JacobiProcess, KimuraProcess, VerhulstProcess, GompertzProcess, FellerLogisticProcess, FractionalOrnsteinUhlenbeckProcess, FractionalVasicekProcess, FractionalCoxIngersollRossProcess, FractionalJacobiProcess, HoLeeProcess
Discrete-time samplepaths.discrete BernoulliProcess, ChineseRestaurantProcess, DirichletProcess, MarkovChain, MoranProcess, RandomWalk
Time series samplepaths.timeseries AutoregressiveProcess, MovingAverageProcess, ARIMAProcess, SARIMAProcess, ARCHProcess, GARCHProcess, TGARCHProcess, AGARCHProcess, EGARCHProcess
Several components samplepaths.multivariate CorrelatedBrownianMotions, HestonModel, BatesModel, SABRModel, HullWhiteTwoFactorModel, TwoFactorCoxIngersollRossModel
Noise samplepaths.noise GaussianNoise, FractionalGaussianNoise, ColoredNoise, VioletNoise, BlueNoise, WhiteNoise, PinkNoise, RedNoise, BrownianNoise

Diffusion processes are approximated with the Euler-Maruyama method; the Cox-Ingersoll-Ross process and the variance of the Heston model can also be sampled from their exact distributions.

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; see CONTRIBUTING.md.

License

samplepaths is released under the MIT license.

It is maintained by Bassem Girgis.