This release is a pre-release and may not be stable for production use.
StochX
StochX is a lightweight Python library for turning stochastic-process mathematics, time-series methods, and state-space models into executable, validated, and testable objects.
It is designed around a simple idea: each mathematical object should have a clear Python representation, a predictable API, numerical validation, and runnable examples.
What makes StochX different
StochX connects course-faithful stochastic-process mathematics with practical time-series analysis and forecasting.
| Area | Main objects |
|---|---|
| Discrete-time Markov chains | MarkovChain |
| Poisson processes | PoissonProcess, NonHomogeneousPoissonProcess |
| Continuous-time Markov chains | ContinuousTimeMarkovChain, CTMCPath |
| Birth-death processes | BirthDeathProcess |
| Finite probability spaces | FiniteProbabilitySpace, RandomVariable, Partition |
| Conditional expectation | FiniteProbabilitySpace, RandomVariable |
| Filtrations and martingales | Filtration, Martingale, StoppingTime, StoppedProcess |
| Time-series analysis | AR, MA, ARMA, ARIMA, SARIMA, correlograms, stationarity tests |
| Box–Jenkins workflow | identification, candidate estimation, validation, deterministic selection, forecasting |
| State-space / Kalman | filtering, smoothing, forecasting, likelihood estimation, innovation diagnostics, adequacy |
The repository preserves explicit numerical contracts and deterministic regression fixtures across the major workflows.
Installation
python -m pip install stochx
For development:
python -m pip install -e ".[dev]"
For documentation development:
python -m pip install -e ".[docs]"
mkdocs serve
Quick start
Discrete-time Markov chain
import numpy as np
from stochx.stochastic import MarkovChain, empirical_state_frequencies
P = [
[0.7, 0.3],
[0.4, 0.6],
]
chain = MarkovChain(P, states=["A", "B"])
print(chain.n_step_transition(5))
print(chain.stationary_distribution())
path = chain.simulate(
10_000,
initial_state="A",
rng=np.random.default_rng(0),
)
print(empirical_state_frequencies(path, chain.states))
State-space filtering
from stochx.timeseries import local_level_filter
result = local_level_filter(
[1.0, 2.0, 3.0],
process_variance=0.0,
observation_variance=1.0,
initial_level=0.0,
initial_variance=1.0,
)
print(result.states)
print(result.log_likelihood)
Full state-space workflow
import numpy as np
from stochx.timeseries import run_local_level_workflow
result = run_local_level_workflow(
np.array([1.0, 1.2, np.nan, 1.3, 1.4, 1.25, 1.5, 1.55]),
diagnostic_lags=2,
alpha=0.10,
forecast_steps=3,
)
print(result.smoother.smoothed_state)
print(result.forecast.forecast)
Public API
The public stochastic namespace is available from stochx.stochastic, while time-series and state-space functionality is exposed from stochx.timeseries.
The detailed reference is maintained in the API documentation.
Examples
Every major mathematical area has runnable examples. The examples directory includes focused stochastic-process examples as well as the time-series and state-space workflows.
examples/
├── 01_discrete_markov_chain.py
├── 02_poisson_process.py
├── 03_continuous_markov_chain.py
├── 04_birth_death_process.py
├── 05_conditional_expectation.py
├── 06_martingale.py
├── 07_api_operations.py
├── 08_eviews_time_series_workflow.py
├── 09_state_space_kalman.py
├── 10_state_space_workflow.py
└── api_quickstart.py
CI executes every examples/*.py script and builds the documentation strictly.
Documentation
The documentation site separates:
- Course material for mathematical development.
- Package / API for public Python objects and validation rules.
- Time Series for the USTHB-style analysis workflow and state-space extensions.
- Worked Examples for executable end-to-end usage.
- Release readiness for distribution, migration, and release-surface requirements.
Start at the documentation site.
For users upgrading from the 0.2.x line, see the 0.2.x migration guide.
Development and quality gates
The repository uses GitHub Actions to run the full test suite on Python 3.10, 3.11, and 3.12. The CI pipeline also checks:
- public API docstring coverage;
- API-reference page coverage;
- documentation structure;
- runnable example coverage;
- package identity;
- strict MkDocs builds;
- source and wheel distribution builds;
- Twine metadata validation;
- clean-wheel installation/import verification.
Run the main suite locally with:
pytest -q tests --disable-warnings
Run all examples locally with:
for example in examples/*.py; do
echo "=== $example ==="
python "$example" >/dev/null
done
Build and validate distributions locally before a release:
python -m build
python -m twine check dist/*
Versioning
StochX follows semantic versioning for public API changes:
MAJORfor incompatible public API changes;MINORfor backwards-compatible features;PATCHfor backwards-compatible fixes.
The package version is defined once in stochx/__init__.py and is used by the build configuration, avoiding separate version values that can drift.
Release status
StochX is currently in the release-hardening phase following the frozen Stage 8–11 numerical contracts. The current package version remains 0.2.0 until a release-candidate decision explicitly selects the next published version.
PyPI publishing is prepared through a tag-based release workflow; publication requires the repository's PyPI trusted publisher configuration.
License
MIT
Metadata
Release files for stochx 0.3.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stochx-0.3.0rc1.tar.gz | 211.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stochx-0.3.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 328.7 kB
Release files / stochx-0.3.0rc1.tar.gz
| Download URL | stochx-0.3.0rc1.tar.gz |
|---|---|
| Size | 211.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2bc8960116965d05e833ca474648e9a441fa51f72a8a8187a8a5c48c95a2782
|
|
BLAKE2b-256 checksum How to use checksums |
323975f5aa3c61f2ce325939078784ab6979fa20c4a55f8451471a3fc29c0226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / stochx-0.3.0rc1-py3-none-any.whl
| Download URL | stochx-0.3.0rc1-py3-none-any.whl |
|---|---|
| Size | 117.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4cf4856fefb1946bead6f325aab2beef6917bbd1a87570dd06c0ac2f194ca46c
|
|
BLAKE2b-256 checksum How to use checksums |
cc247852384c032d1bcc044dd8dd47a523a228d0de8e0058cecb52476d8ff3b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency log