Metadata-Version: 2.4
Name: spxa
Version: 1.3.0
Summary: Stochastic processes as first-class algebraic objects
Author-email: Nityahapani <nityahapani.tges@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/Nityahapani/spxa
Project-URL: Documentation, https://nityahapani.github.io/spxa
Project-URL: Repository, https://github.com/Nityahapani/spxa
Project-URL: Issues, https://github.com/Nityahapani/spxa/issues
Project-URL: Changelog, https://github.com/Nityahapani/spxa/blob/main/CHANGELOG.md
Keywords: stochastic processes,levy processes,probability,mathematics,finance
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.0
Requires-Dist: scipy>=1.10
Requires-Dist: sympy>=1.12
Requires-Dist: matplotlib>=3.7
Requires-Dist: networkx>=3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-benchmark>=5.1.0; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: matplotlib>=3.7; extra == "dev"
Requires-Dist: jax>=0.4.0; extra == "dev"
Requires-Dist: jaxlib>=0.4.0; extra == "dev"
Requires-Dist: numba>=0.59; extra == "dev"
Provides-Extra: diff
Requires-Dist: jax>=0.4.0; extra == "diff"
Requires-Dist: jaxlib>=0.4.0; extra == "diff"
Provides-Extra: compile
Requires-Dist: numba>=0.59; extra == "compile"
Provides-Extra: docs
Requires-Dist: mkdocs; extra == "docs"
Requires-Dist: mkdocs-material; extra == "docs"
Requires-Dist: mkdocstrings[python]; extra == "docs"
Requires-Dist: mkdocs-jupyter; extra == "docs"
Dynamic: license-file

# spxa

Stochastic processes as first-class algebraic objects. Exact Lévy–Khintchine
arithmetic, a differentiable computational graph, and reverse-mode Greeks.

[![CI](https://github.com/Nityahapani/spxa/actions/workflows/ci.yml/badge.svg)](https://github.com/Nityahapani/spxa/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/spxa)](https://pypi.org/project/spxa/)
[![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://pypi.org/project/spxa/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
[![Ruff](https://img.shields.io/badge/style-ruff-000000)](https://github.com/astral-sh/ruff)

spxa is a Python library for quantitative research. It treats continuous-time
stochastic processes as first-class algebraic objects: compose them with `+`,
`*`, `@`, and their Lévy–Khintchine triplets add in closed form. A computational
graph engine compiles pricing pipelines and routes to analytical, Fourier, batch,
or Monte Carlo backends, with reverse-mode autodiff for machine-precision Greeks.

## Install

```bash
pip install spxa
```

Dev install:

```bash
git clone https://github.com/Nityahapani/spxa.git
cd spxa
pip install -e ".[dev]"
```

## Quickstart

```python
import spxa
from spxa import VarianceGamma, GammaProcess

X = VarianceGamma(sigma=0.2, nu=0.1, theta=-0.1)
Y = GammaProcess(a=1.0, b=2.0)
Z = X + 0.5 * Y            # exact triplet arithmetic

print(Z.exactness)          # ExactnessLevel.EXACT
print(Z.triplet.sigma_sq)   # 0.0
print(float(Z.triplet.b))   # 0.14542109130283806
print(Z.exactness == spxa.ExactnessLevel.EXACT)  # True
```

## Discovery and laws

`spxa.discovery` runs the algebra backwards. It searches compositions of
primitives for the one that explains a return series, its summary
statistics, or option prices. `spxa.laws` turns the axioms into executable
tests: declare a law, and spxa searches random processes for a shrunk
counterexample.

```python
import numpy as np
from spxa import VarianceGamma
from spxa.discovery import discover, grammar_from_names
from spxa.laws import compositions, expect_close, law
from spxa.laws.quantities import mean

paths = VarianceGamma(sigma=0.2, nu=0.3, theta=-0.1).simulate(2000, 1, 2000 / 52, np.random.default_rng(0))
report = discover(np.diff(paths[0]), dt=1 / 52, grammar=grammar_from_names(["BM", "VG", "NIG"], max_terms=1))
print(report.best.model.structure.key())  # VG + Drift

@law(X=compositions(max_depth=1), Y=compositions(max_depth=1))
def mean_is_additive(X, Y):
    expect_close(mean(X + Y), mean(X) + mean(Y))

print(mean_is_additive.check(n_examples=100).status)  # verified
```

`spxa-discover returns prices.csv` and `spxa-laws` run both from the shell.
See the [discovery](docs/theory/discovery.md) and [laws](docs/theory/laws.md)
guides.

| Module | Purpose |
|--------|---------|
| `spxa.core` | Process algebra, Lévy–Khintchine triplets, exactness lattice |
| `spxa.zoo` | 69 stochastic processes |
| `spxa.graph` | Differentiable computational graph & autodiff tape |
| `spxa.diff` | Greeks, pricers, neural SDEs |
| `spxa.calibration` | MLE, GMM, Kalman/particle filters, surface calibration |
| `spxa.copula` | Archimedean, elliptical, extreme-value copulas |
| `spxa.control` | Merton portfolio, market making, HJB solvers |
| `spxa.pde` | Finite-difference PDE/PIDE solvers |
| `spxa.rates` / `spxa.market` | Curves, swaps, bonds, bootstrapping |
| `spxa.vol` | SVI/SSVI surfaces, local vol, rough vol |
| `spxa.rough` | Fractional volatility, rBergomi |
| `spxa.morph` | Model morphing & barycenters |
| `spxa.geom` | Information geometry |
| `spxa.signature` | Rough path signatures |
| `spxa.discovery` | Process discovery: structures from returns or option prices |
| `spxa.laws` | Property-based testing of process laws |

## Docs

- [API reference](https://nityahapani.github.io/spxa)
- [Process registry](https://github.com/Nityahapani/spxa/blob/main/PROCESS_REGISTRY.md)
- [Theory guides](docs/theory/)
- [Tutorials](docs/tutorials/)

## Citation

[![CITATION.cff](https://img.shields.io/badge/CITATION.cff-DOI-blue)](CITATION.cff)

```bibtex
@software{spxa,
  author = {Nityahapani},
  title = {spxa: Stochastic Process Algebra \& Computational Graph Engine},
  url = {https://github.com/Nityahapani/spxa},
  version = {1.3.0},
  year = {2026},
}
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). Tests and the full audit suite must pass:

```bash
python -m pytest tests/ -q
python audits/run_master_audit.py
```

## License

[MIT](LICENSE)
