heavytails 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- heavytails-0.1.0/CHANGELOG.md +127 -0
- heavytails-0.1.0/CITATION.cff +68 -0
- heavytails-0.1.0/LICENSE +21 -0
- heavytails-0.1.0/PKG-INFO +231 -0
- heavytails-0.1.0/README.md +193 -0
- heavytails-0.1.0/heavytails/__init__.py +75 -0
- heavytails-0.1.0/heavytails/__main__.py +13 -0
- heavytails-0.1.0/heavytails/_special.py +307 -0
- heavytails-0.1.0/heavytails/cli.py +817 -0
- heavytails-0.1.0/heavytails/discrete.py +194 -0
- heavytails-0.1.0/heavytails/extensions.py +695 -0
- heavytails-0.1.0/heavytails/extra_distributions.py +351 -0
- heavytails-0.1.0/heavytails/heavy_tails.py +611 -0
- heavytails-0.1.0/heavytails/performance.py +1047 -0
- heavytails-0.1.0/heavytails/plotting.py +27 -0
- heavytails-0.1.0/heavytails/py.typed +0 -0
- heavytails-0.1.0/heavytails/roadmap.py +1106 -0
- heavytails-0.1.0/heavytails/tail_index.py +64 -0
- heavytails-0.1.0/heavytails/utilities.py +1146 -0
- heavytails-0.1.0/heavytails/validation.py +986 -0
- heavytails-0.1.0/pyproject.toml +328 -0
- heavytails-0.1.0/tests/test_comprehensive.py +691 -0
- heavytails-0.1.0/tests/test_copulas.py +568 -0
- heavytails-0.1.0/tests/test_discrete.py +363 -0
- heavytails-0.1.0/tests/test_extra_distributions.py +542 -0
- heavytails-0.1.0/tests/test_generalized_pareto.py +8 -0
- heavytails-0.1.0/tests/test_heavy_tails.py +554 -0
- heavytails-0.1.0/tests/test_log_normal.py +8 -0
- heavytails-0.1.0/tests/test_pareto.py +17 -0
- heavytails-0.1.0/tests/test_performance.py +628 -0
- heavytails-0.1.0/tests/test_plotting.py +169 -0
- heavytails-0.1.0/tests/test_roadmap.py +672 -0
- heavytails-0.1.0/tests/test_special.py +78 -0
- heavytails-0.1.0/tests/test_tail_accuracy.py +224 -0
- heavytails-0.1.0/tests/test_tail_index.py +66 -0
- heavytails-0.1.0/tests/test_utilities.py +651 -0
- heavytails-0.1.0/tests/test_validation.py +714 -0
- heavytails-0.1.0/tests/test_zenodo_metadata.py +58 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Python 3.13 support, covered by the CI test matrix and declared in the package
|
|
13
|
+
classifiers.
|
|
14
|
+
- `py.typed` marker, so the type annotations that ship with the package are
|
|
15
|
+
visible to downstream type checkers. The `Typing :: Typed` classifier was
|
|
16
|
+
previously advertised without one.
|
|
17
|
+
- `heavytails.__version__`, resolved from the installed distribution metadata.
|
|
18
|
+
- `--version` / `-V` flag on the `heavytails` command-line interface.
|
|
19
|
+
- `cli` installation extra (`pip install "heavytails[cli]"`). The console script
|
|
20
|
+
depends on `typer` and `rich`, which were previously development-only
|
|
21
|
+
dependencies, so the entry point was broken for anyone installing from PyPI.
|
|
22
|
+
- CodeQL analysis and dependency-review workflows.
|
|
23
|
+
- `.github/CODEOWNERS`, `.gitattributes` and `.zenodo.json`.
|
|
24
|
+
- `StudentT.cdf`, `StudentT.sf` and `StudentT.ppf`. The class previously offered
|
|
25
|
+
only `pdf` and `rvs`, with a docstring stating that the CDF and PPF "require
|
|
26
|
+
special functions not in stdlib" — but the regularized incomplete beta needed
|
|
27
|
+
to write them was already implemented in `extra_distributions`. All three
|
|
28
|
+
agree with SciPy to around 1e-14.
|
|
29
|
+
- `Cauchy.sf`, `Frechet.sf` and `GEV_Frechet.sf`, so every continuous family now
|
|
30
|
+
provides the full interface the documentation advertises.
|
|
31
|
+
- `YuleSimon.sf` and `YuleSimon.ppf`. The survival function uses the closed form
|
|
32
|
+
`P(X > k) = k * B(k, rho + 1)`, and the quantile function brackets and bisects
|
|
33
|
+
rather than scanning linearly.
|
|
34
|
+
- `heavytails._special`, holding the shared numeric special functions so that
|
|
35
|
+
both distribution modules can use them without an import cycle. The previous
|
|
36
|
+
names remain importable from `heavytails.extra_distributions`.
|
|
37
|
+
- `_betaincinv_reg`, an inverse for the regularized incomplete beta. It solves in
|
|
38
|
+
log-space with a symmetry reduction, which is what keeps extreme quantiles
|
|
39
|
+
accurate.
|
|
40
|
+
- Documentation pages that existing pages already linked to but which had never
|
|
41
|
+
been written: CLI reference, diagnostics guide, extreme value theory, tail
|
|
42
|
+
index estimation theory, validation studies, architecture, benchmarking, code
|
|
43
|
+
review, and an executable `basic_usage` notebook.
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
- Migrated project metadata to the PEP 621 `[project]` table.
|
|
48
|
+
- Grouped Dependabot updates so routine bumps arrive as a few reviewable pull
|
|
49
|
+
requests rather than one per package.
|
|
50
|
+
- Continuous integration now also runs on pull requests targeting `develop`,
|
|
51
|
+
builds and metadata-checks the distributions before publishing, verifies that
|
|
52
|
+
`poetry.lock` matches `pyproject.toml`, and builds the documentation with
|
|
53
|
+
`--strict`.
|
|
54
|
+
- Security scanning fails the build on findings instead of uploading a report
|
|
55
|
+
that no one reads. `safety` was replaced by `pip-audit`, which needs no
|
|
56
|
+
account to run.
|
|
57
|
+
- Refreshed the locked dependency set, clearing 116 known vulnerabilities
|
|
58
|
+
reported against the previously locked development and documentation
|
|
59
|
+
toolchain.
|
|
60
|
+
- Pre-commit hooks are pinned to the same tool versions as the development
|
|
61
|
+
dependencies, so local hooks and CI now agree.
|
|
62
|
+
- Replaced the `Makefile` targets, which measured coverage of `scripts/` rather
|
|
63
|
+
than of the package.
|
|
64
|
+
- `mkdocstrings` is configured for Google-style docstrings, which is what the
|
|
65
|
+
package actually uses. Under the previous `numpy` setting no `Args:` or
|
|
66
|
+
`Returns:` section was parsed anywhere in the API reference.
|
|
67
|
+
- The documentation navigation lists every page. Five API reference entries all
|
|
68
|
+
pointed at the same directory, and the `gen-files` script duplicated the
|
|
69
|
+
hand-written reference pages while `literate-nav` looked for a `SUMMARY.md`
|
|
70
|
+
that was never generated.
|
|
71
|
+
|
|
72
|
+
### Fixed
|
|
73
|
+
|
|
74
|
+
- `heavytails benchmark` raised `ZeroDivisionError` on platforms with a
|
|
75
|
+
low-resolution wall clock, because a sub-millisecond timing measured exactly
|
|
76
|
+
zero seconds. Timings now use `time.perf_counter()`.
|
|
77
|
+
- The same defect in the performance tests, which failed intermittently on
|
|
78
|
+
Windows.
|
|
79
|
+
- Removed an invalid PyPI classifier (`Topic :: Scientific/Engineering ::
|
|
80
|
+
Statistics`) that would have been rejected on upload.
|
|
81
|
+
- `scripts/pyproject_updater.py` depends on `tomlkit` and `packaging`, which
|
|
82
|
+
were never declared and only happened to be installed transitively.
|
|
83
|
+
- Pinned Poetry 2.2.1 in every workflow. The previous 1.8.3 pin cannot read the
|
|
84
|
+
version 2.1 lock file this repository uses.
|
|
85
|
+
- Removed a `preferred-citation` entry from `CITATION.cff` that pointed at an
|
|
86
|
+
unpublished paper with a placeholder DOI, which citation tooling would have
|
|
87
|
+
emitted as a real reference.
|
|
88
|
+
- `YuleSimon.pmf` raised `OverflowError` for k of about 170 and above, because
|
|
89
|
+
it multiplied gamma functions that overflow individually even though their
|
|
90
|
+
ratio is small. Since sampling called it in a loop, drawing from the tail
|
|
91
|
+
crashed. It is now evaluated with `lgamma`.
|
|
92
|
+
- Nineteen documentation links pointed at pages that did not exist. The
|
|
93
|
+
documentation job now builds with `--strict`, so a broken link fails CI.
|
|
94
|
+
- `convergence_validation` took a `_max_iter` parameter that was never used and
|
|
95
|
+
documented it under a different name.
|
|
96
|
+
- Removed a stale `xfail` marker on the Student-t PPF convergence test. It was
|
|
97
|
+
recording precision loss that the new incomplete beta inverse eliminates.
|
|
98
|
+
|
|
99
|
+
### Removed
|
|
100
|
+
|
|
101
|
+
- `tox.ini`, which ran the test suite against `scripts/` instead of the package
|
|
102
|
+
and duplicated the CI matrix.
|
|
103
|
+
- `IMPROVEMENT_PLAN.md` from the repository root. It described gaps that have
|
|
104
|
+
since been closed; forward-looking plans live in
|
|
105
|
+
[ROADMAP.md](https://github.com/DiogoRibeiro7/heavytails/blob/main/ROADMAP.md).
|
|
106
|
+
- The `isort` development dependency and its configuration, superseded by
|
|
107
|
+
Ruff's `I` rules.
|
|
108
|
+
|
|
109
|
+
## [0.1.0] - 2025-10-25
|
|
110
|
+
|
|
111
|
+
### Added
|
|
112
|
+
|
|
113
|
+
- Continuous heavy-tailed distributions implemented from first principles:
|
|
114
|
+
Pareto, Cauchy, Student-t, Log-Normal, Weibull, Fréchet and GEV (ξ > 0).
|
|
115
|
+
- Additional continuous families: Generalized Pareto, Burr XII, Log-Logistic
|
|
116
|
+
(Fisk), Inverse-Gamma and Beta-Prime.
|
|
117
|
+
- Discrete heavy-tailed distributions: Zipf, Yule–Simon and Discrete Pareto.
|
|
118
|
+
- Tail index estimators: Hill, Pickands and moment.
|
|
119
|
+
- Diagnostic plotting helpers for log–log tail and QQ plots.
|
|
120
|
+
- Deterministic RNG wrapper for reproducible sampling.
|
|
121
|
+
- Custom incomplete-gamma and incomplete-beta implementations, and a
|
|
122
|
+
safeguarded-Newton numeric PPF solver for families without a closed form.
|
|
123
|
+
- `heavytails` command-line interface.
|
|
124
|
+
- Documentation site built with MkDocs Material.
|
|
125
|
+
|
|
126
|
+
[Unreleased]: https://github.com/DiogoRibeiro7/heavytails/compare/v0.1.0...HEAD
|
|
127
|
+
[0.1.0]: https://github.com/DiogoRibeiro7/heavytails/releases/tag/v0.1.0
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: "heavytails: A Pure-Python Library for Heavy-Tailed Probability Distributions"
|
|
3
|
+
message: "If you use this library, please cite as below."
|
|
4
|
+
type: software
|
|
5
|
+
authors:
|
|
6
|
+
- family-names: Ribeiro
|
|
7
|
+
given-names: Diogo
|
|
8
|
+
orcid: "https://orcid.org/0009-0001-2022-7072"
|
|
9
|
+
affiliation: "ESMAD - Escola Superior de Média Arte e Design; Mysense.ai"
|
|
10
|
+
email: dfr@esmad.ipp.pt
|
|
11
|
+
repository-code: "https://github.com/DiogoRibeiro7/heavytails"
|
|
12
|
+
url: "https://diogoribeiro7.github.io/heavytails"
|
|
13
|
+
abstract: >
|
|
14
|
+
heavytails is a pure-Python library implementing heavy-tailed probability
|
|
15
|
+
distributions, built from first principles without third-party dependencies.
|
|
16
|
+
The library provides comprehensive support for continuous and discrete
|
|
17
|
+
heavy-tailed distributions, tail index estimation methods, and diagnostic
|
|
18
|
+
utilities for extreme value analysis, risk management, and financial modeling.
|
|
19
|
+
keywords:
|
|
20
|
+
- heavy tails
|
|
21
|
+
- heavy-tailed distributions
|
|
22
|
+
- probability distributions
|
|
23
|
+
- statistics
|
|
24
|
+
- data science
|
|
25
|
+
- machine learning
|
|
26
|
+
- extreme value theory
|
|
27
|
+
- tail index estimation
|
|
28
|
+
- risk management
|
|
29
|
+
- finance
|
|
30
|
+
- tail risk
|
|
31
|
+
- python
|
|
32
|
+
- simulation
|
|
33
|
+
- teaching
|
|
34
|
+
license: MIT
|
|
35
|
+
version: 0.1.0
|
|
36
|
+
date-released: 2025-10-25
|
|
37
|
+
references:
|
|
38
|
+
- type: book
|
|
39
|
+
title: "Extreme Value Theory: An Introduction"
|
|
40
|
+
authors:
|
|
41
|
+
- family-names: de Haan
|
|
42
|
+
given-names: Laurens
|
|
43
|
+
- family-names: Ferreira
|
|
44
|
+
given-names: Ana
|
|
45
|
+
publisher: "Springer"
|
|
46
|
+
year: 2006
|
|
47
|
+
isbn: "978-0-387-23946-0"
|
|
48
|
+
- type: book
|
|
49
|
+
title: "Heavy-Tailed Distributions in Finance"
|
|
50
|
+
authors:
|
|
51
|
+
- family-names: Rachev
|
|
52
|
+
given-names: Svetlozar T.
|
|
53
|
+
- family-names: Mittnik
|
|
54
|
+
given-names: Stefan
|
|
55
|
+
publisher: "Academic Press"
|
|
56
|
+
year: 2000
|
|
57
|
+
isbn: "978-0-12-574340-4"
|
|
58
|
+
- type: article
|
|
59
|
+
title: "A Simple General Approach to Inference About the Tail of a Distribution"
|
|
60
|
+
authors:
|
|
61
|
+
- family-names: Hill
|
|
62
|
+
given-names: Bruce M.
|
|
63
|
+
journal: "The Annals of Statistics"
|
|
64
|
+
year: 1975
|
|
65
|
+
volume: 3
|
|
66
|
+
issue: 5
|
|
67
|
+
pages: "1163-1174"
|
|
68
|
+
doi: "10.1214/aos/1176343247"
|
heavytails-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Diogo Ribeiro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: heavytails
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pure-Python heavy-tailed probability distributions for research, teaching, and simulation.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: heavy-tailed,statistics,probability,extreme-values,distributions,finance,risk-management,tail-risk,extreme-value-theory
|
|
8
|
+
Author: Diogo Ribeiro
|
|
9
|
+
Author-email: dfr@esmad.ipp.pt
|
|
10
|
+
Maintainer: Diogo Ribeiro
|
|
11
|
+
Maintainer-email: dfr@esmad.ipp.pt
|
|
12
|
+
Requires-Python: >=3.10,<3.14
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Intended Audience :: Education
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Provides-Extra: cli
|
|
28
|
+
Requires-Dist: rich (>=14.0,<15.0) ; extra == "cli"
|
|
29
|
+
Requires-Dist: typer (>=0.20,<1.0) ; extra == "cli"
|
|
30
|
+
Project-URL: Changelog, https://github.com/DiogoRibeiro7/heavytails/blob/main/CHANGELOG.md
|
|
31
|
+
Project-URL: Documentation, https://diogoribeiro7.github.io/heavytails
|
|
32
|
+
Project-URL: Discussions, https://github.com/DiogoRibeiro7/heavytails/discussions
|
|
33
|
+
Project-URL: Homepage, https://github.com/DiogoRibeiro7/heavytails
|
|
34
|
+
Project-URL: Issues, https://github.com/DiogoRibeiro7/heavytails/issues
|
|
35
|
+
Project-URL: Repository, https://github.com/DiogoRibeiro7/heavytails
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# heavytails
|
|
39
|
+
|
|
40
|
+
**A pure-Python library of heavy-tailed probability distributions**
|
|
41
|
+
|
|
42
|
+
[](https://github.com/DiogoRibeiro7/heavytails/actions/workflows/ci.yml)
|
|
43
|
+
[](https://codecov.io/gh/DiogoRibeiro7/heavytails)
|
|
44
|
+
[](https://pypi.org/project/heavytails/)
|
|
45
|
+
[](https://pypi.org/project/heavytails/)
|
|
46
|
+
[](LICENSE)
|
|
47
|
+
[](https://diogoribeiro7.github.io/heavytails)
|
|
48
|
+
[](https://github.com/astral-sh/ruff)
|
|
49
|
+
[](https://mypy-lang.org/)
|
|
50
|
+
|
|
51
|
+
`heavytails` implements continuous and discrete heavy-tailed distributions, tail
|
|
52
|
+
index estimators, and diagnostic utilities — **using only the Python standard
|
|
53
|
+
library**. Every density, quantile and sampler is derived from first principles,
|
|
54
|
+
so the implementation can be read, checked and taught rather than taken on faith.
|
|
55
|
+
|
|
56
|
+
It targets research, teaching and simulation work in risk, finance, insurance and
|
|
57
|
+
extreme-value analysis.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Features
|
|
62
|
+
|
|
63
|
+
- **No runtime dependencies.** The library imports nothing outside `math`,
|
|
64
|
+
`random` and friends, so it installs anywhere Python does.
|
|
65
|
+
- **Complete distribution interface.** PDF/PMF, CDF, survival function, quantile
|
|
66
|
+
function and random sampling for every family, with survival functions computed
|
|
67
|
+
directly so they stay accurate far into the tail where `1 - cdf(x)` has lost
|
|
68
|
+
every significant digit.
|
|
69
|
+
- **Reproducible sampling** through a deterministic RNG wrapper.
|
|
70
|
+
- **Special functions from scratch** — incomplete gamma and incomplete beta —
|
|
71
|
+
plus a safeguarded-Newton numeric PPF for families with no closed form.
|
|
72
|
+
- **Tail index estimation** with the Hill, Pickands and moment estimators.
|
|
73
|
+
- **Parameter fitting** by maximum likelihood and method of moments, with
|
|
74
|
+
AIC/BIC model comparison.
|
|
75
|
+
- **Diagnostics** for log–log tail plots and QQ plots.
|
|
76
|
+
- **A command-line interface** for sampling, fitting, comparison and
|
|
77
|
+
benchmarking.
|
|
78
|
+
- **Typed throughout**, with a `py.typed` marker so downstream type checkers see
|
|
79
|
+
the annotations.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install heavytails
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The command-line interface needs two extra packages; install it with the `cli`
|
|
90
|
+
extra:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install "heavytails[cli]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To work on the library itself:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
git clone https://github.com/DiogoRibeiro7/heavytails.git
|
|
100
|
+
cd heavytails
|
|
101
|
+
poetry install --with dev,docs
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Requires Python 3.10 or newer.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Quick start
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from heavytails import BurrXII, Pareto, hill_estimator
|
|
112
|
+
|
|
113
|
+
pareto = Pareto(alpha=1.5, xm=1.0)
|
|
114
|
+
|
|
115
|
+
pareto.pdf(2.0) # density
|
|
116
|
+
pareto.cdf(2.0) # distribution function
|
|
117
|
+
pareto.sf(10.0) # survival function: P(X > 10)
|
|
118
|
+
pareto.ppf(0.99) # 99th percentile
|
|
119
|
+
samples = pareto.rvs(10_000, seed=42)
|
|
120
|
+
|
|
121
|
+
# Recover the tail index from the sample. The estimators return the
|
|
122
|
+
# extreme-value index gamma = 1 / alpha, so invert it to read alpha back.
|
|
123
|
+
gamma = hill_estimator(samples, k=100) # ≈ 0.65
|
|
124
|
+
alpha = 1 / gamma # ≈ 1.53, against a true 1.5
|
|
125
|
+
|
|
126
|
+
burr = BurrXII(c=1.2, k=2.5, s=3.0)
|
|
127
|
+
burr.ppf(0.95)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Command line
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
heavytails list-distributions
|
|
134
|
+
heavytails sample pareto --params '{"alpha": 2.0, "xm": 1.0}' -n 1000 -o samples.txt
|
|
135
|
+
heavytails estimate-tail samples.txt --method hill
|
|
136
|
+
heavytails compare samples.txt
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Run `heavytails --help` for the full command list.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Available distributions
|
|
144
|
+
|
|
145
|
+
### Continuous
|
|
146
|
+
|
|
147
|
+
| Distribution | Module | Heavy-tail regime |
|
|
148
|
+
| ----------------------- | ------------------------ | ----------------- |
|
|
149
|
+
| Pareto | `heavy_tails` | always |
|
|
150
|
+
| Cauchy | `heavy_tails` | always |
|
|
151
|
+
| Student-t | `heavy_tails` | small ν |
|
|
152
|
+
| Log-Normal | `heavy_tails` | always |
|
|
153
|
+
| Weibull | `heavy_tails` | k < 1 |
|
|
154
|
+
| Fréchet | `heavy_tails` | always |
|
|
155
|
+
| GEV (Fréchet branch) | `heavy_tails` | ξ > 0 |
|
|
156
|
+
| Generalized Pareto | `extra_distributions` | ξ > 0 |
|
|
157
|
+
| Burr XII | `extra_distributions` | always |
|
|
158
|
+
| Log-Logistic (Fisk) | `extra_distributions` | always |
|
|
159
|
+
| Inverse-Gamma | `extra_distributions` | always |
|
|
160
|
+
| Beta-Prime | `extra_distributions` | always |
|
|
161
|
+
|
|
162
|
+
### Discrete
|
|
163
|
+
|
|
164
|
+
| Distribution | Module | Heavy-tail regime |
|
|
165
|
+
| ---------------- | ---------- | ----------------- |
|
|
166
|
+
| Zipf | `discrete` | always |
|
|
167
|
+
| Yule–Simon | `discrete` | always |
|
|
168
|
+
| Discrete Pareto | `discrete` | always |
|
|
169
|
+
|
|
170
|
+
Every continuous family provides `pdf`, `cdf`, `sf`, `ppf` and `rvs`; every
|
|
171
|
+
discrete family provides `pmf`, `cdf`, `ppf` and `rvs`.
|
|
172
|
+
|
|
173
|
+
### Estimation and diagnostics
|
|
174
|
+
|
|
175
|
+
| Module | Contents |
|
|
176
|
+
| ------------ | ----------------------------------------------------- |
|
|
177
|
+
| `tail_index` | Hill, Pickands and moment tail index estimators |
|
|
178
|
+
| `plotting` | Log–log tail plots and QQ plots |
|
|
179
|
+
| `utilities` | Data I/O, automatic fitting and model comparison |
|
|
180
|
+
| `validation` | Mathematical and numerical validation of the families |
|
|
181
|
+
| `cli` | Command-line entry point |
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Documentation
|
|
186
|
+
|
|
187
|
+
Full documentation, including the mathematical background, is at
|
|
188
|
+
**<https://diogoribeiro7.github.io/heavytails>**.
|
|
189
|
+
|
|
190
|
+
To build it locally:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
make docs-serve
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Development
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
make install-dev # install every dependency group
|
|
202
|
+
make hooks # install the pre-commit hooks
|
|
203
|
+
make check # everything CI runs: lint, format, types, tests, security
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Individual targets are listed by `make help`. Contributions are welcome — see
|
|
207
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for the branch flow, commit conventions and
|
|
208
|
+
review process, and [ROADMAP.md](ROADMAP.md) for what is planned next.
|
|
209
|
+
|
|
210
|
+
Notable changes are recorded in [CHANGELOG.md](CHANGELOG.md).
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT License © 2025 Diogo Ribeiro. See [LICENSE](LICENSE).
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Citation
|
|
221
|
+
|
|
222
|
+
If you use this package in research or teaching, please cite it. GitHub's
|
|
223
|
+
"Cite this repository" button reads [CITATION.cff](CITATION.cff), or use:
|
|
224
|
+
|
|
225
|
+
> Ribeiro, D. (2025). *heavytails: A Pure-Python Library for Heavy-Tailed Probability Distributions*.
|
|
226
|
+
> <https://github.com/DiogoRibeiro7/heavytails>
|
|
227
|
+
|
|
228
|
+
Shared citation metadata is maintained in `CITATION.cff`; Zenodo-specific
|
|
229
|
+
archive metadata is maintained in `.zenodo.json`. The DOI will be added after
|
|
230
|
+
the first archived GitHub release.
|
|
231
|
+
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# heavytails
|
|
2
|
+
|
|
3
|
+
**A pure-Python library of heavy-tailed probability distributions**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/DiogoRibeiro7/heavytails/actions/workflows/ci.yml)
|
|
6
|
+
[](https://codecov.io/gh/DiogoRibeiro7/heavytails)
|
|
7
|
+
[](https://pypi.org/project/heavytails/)
|
|
8
|
+
[](https://pypi.org/project/heavytails/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://diogoribeiro7.github.io/heavytails)
|
|
11
|
+
[](https://github.com/astral-sh/ruff)
|
|
12
|
+
[](https://mypy-lang.org/)
|
|
13
|
+
|
|
14
|
+
`heavytails` implements continuous and discrete heavy-tailed distributions, tail
|
|
15
|
+
index estimators, and diagnostic utilities — **using only the Python standard
|
|
16
|
+
library**. Every density, quantile and sampler is derived from first principles,
|
|
17
|
+
so the implementation can be read, checked and taught rather than taken on faith.
|
|
18
|
+
|
|
19
|
+
It targets research, teaching and simulation work in risk, finance, insurance and
|
|
20
|
+
extreme-value analysis.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **No runtime dependencies.** The library imports nothing outside `math`,
|
|
27
|
+
`random` and friends, so it installs anywhere Python does.
|
|
28
|
+
- **Complete distribution interface.** PDF/PMF, CDF, survival function, quantile
|
|
29
|
+
function and random sampling for every family, with survival functions computed
|
|
30
|
+
directly so they stay accurate far into the tail where `1 - cdf(x)` has lost
|
|
31
|
+
every significant digit.
|
|
32
|
+
- **Reproducible sampling** through a deterministic RNG wrapper.
|
|
33
|
+
- **Special functions from scratch** — incomplete gamma and incomplete beta —
|
|
34
|
+
plus a safeguarded-Newton numeric PPF for families with no closed form.
|
|
35
|
+
- **Tail index estimation** with the Hill, Pickands and moment estimators.
|
|
36
|
+
- **Parameter fitting** by maximum likelihood and method of moments, with
|
|
37
|
+
AIC/BIC model comparison.
|
|
38
|
+
- **Diagnostics** for log–log tail plots and QQ plots.
|
|
39
|
+
- **A command-line interface** for sampling, fitting, comparison and
|
|
40
|
+
benchmarking.
|
|
41
|
+
- **Typed throughout**, with a `py.typed` marker so downstream type checkers see
|
|
42
|
+
the annotations.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install heavytails
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The command-line interface needs two extra packages; install it with the `cli`
|
|
53
|
+
extra:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install "heavytails[cli]"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
To work on the library itself:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/DiogoRibeiro7/heavytails.git
|
|
63
|
+
cd heavytails
|
|
64
|
+
poetry install --with dev,docs
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Requires Python 3.10 or newer.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from heavytails import BurrXII, Pareto, hill_estimator
|
|
75
|
+
|
|
76
|
+
pareto = Pareto(alpha=1.5, xm=1.0)
|
|
77
|
+
|
|
78
|
+
pareto.pdf(2.0) # density
|
|
79
|
+
pareto.cdf(2.0) # distribution function
|
|
80
|
+
pareto.sf(10.0) # survival function: P(X > 10)
|
|
81
|
+
pareto.ppf(0.99) # 99th percentile
|
|
82
|
+
samples = pareto.rvs(10_000, seed=42)
|
|
83
|
+
|
|
84
|
+
# Recover the tail index from the sample. The estimators return the
|
|
85
|
+
# extreme-value index gamma = 1 / alpha, so invert it to read alpha back.
|
|
86
|
+
gamma = hill_estimator(samples, k=100) # ≈ 0.65
|
|
87
|
+
alpha = 1 / gamma # ≈ 1.53, against a true 1.5
|
|
88
|
+
|
|
89
|
+
burr = BurrXII(c=1.2, k=2.5, s=3.0)
|
|
90
|
+
burr.ppf(0.95)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Command line
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
heavytails list-distributions
|
|
97
|
+
heavytails sample pareto --params '{"alpha": 2.0, "xm": 1.0}' -n 1000 -o samples.txt
|
|
98
|
+
heavytails estimate-tail samples.txt --method hill
|
|
99
|
+
heavytails compare samples.txt
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Run `heavytails --help` for the full command list.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Available distributions
|
|
107
|
+
|
|
108
|
+
### Continuous
|
|
109
|
+
|
|
110
|
+
| Distribution | Module | Heavy-tail regime |
|
|
111
|
+
| ----------------------- | ------------------------ | ----------------- |
|
|
112
|
+
| Pareto | `heavy_tails` | always |
|
|
113
|
+
| Cauchy | `heavy_tails` | always |
|
|
114
|
+
| Student-t | `heavy_tails` | small ν |
|
|
115
|
+
| Log-Normal | `heavy_tails` | always |
|
|
116
|
+
| Weibull | `heavy_tails` | k < 1 |
|
|
117
|
+
| Fréchet | `heavy_tails` | always |
|
|
118
|
+
| GEV (Fréchet branch) | `heavy_tails` | ξ > 0 |
|
|
119
|
+
| Generalized Pareto | `extra_distributions` | ξ > 0 |
|
|
120
|
+
| Burr XII | `extra_distributions` | always |
|
|
121
|
+
| Log-Logistic (Fisk) | `extra_distributions` | always |
|
|
122
|
+
| Inverse-Gamma | `extra_distributions` | always |
|
|
123
|
+
| Beta-Prime | `extra_distributions` | always |
|
|
124
|
+
|
|
125
|
+
### Discrete
|
|
126
|
+
|
|
127
|
+
| Distribution | Module | Heavy-tail regime |
|
|
128
|
+
| ---------------- | ---------- | ----------------- |
|
|
129
|
+
| Zipf | `discrete` | always |
|
|
130
|
+
| Yule–Simon | `discrete` | always |
|
|
131
|
+
| Discrete Pareto | `discrete` | always |
|
|
132
|
+
|
|
133
|
+
Every continuous family provides `pdf`, `cdf`, `sf`, `ppf` and `rvs`; every
|
|
134
|
+
discrete family provides `pmf`, `cdf`, `ppf` and `rvs`.
|
|
135
|
+
|
|
136
|
+
### Estimation and diagnostics
|
|
137
|
+
|
|
138
|
+
| Module | Contents |
|
|
139
|
+
| ------------ | ----------------------------------------------------- |
|
|
140
|
+
| `tail_index` | Hill, Pickands and moment tail index estimators |
|
|
141
|
+
| `plotting` | Log–log tail plots and QQ plots |
|
|
142
|
+
| `utilities` | Data I/O, automatic fitting and model comparison |
|
|
143
|
+
| `validation` | Mathematical and numerical validation of the families |
|
|
144
|
+
| `cli` | Command-line entry point |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Documentation
|
|
149
|
+
|
|
150
|
+
Full documentation, including the mathematical background, is at
|
|
151
|
+
**<https://diogoribeiro7.github.io/heavytails>**.
|
|
152
|
+
|
|
153
|
+
To build it locally:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
make docs-serve
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Development
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
make install-dev # install every dependency group
|
|
165
|
+
make hooks # install the pre-commit hooks
|
|
166
|
+
make check # everything CI runs: lint, format, types, tests, security
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Individual targets are listed by `make help`. Contributions are welcome — see
|
|
170
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) for the branch flow, commit conventions and
|
|
171
|
+
review process, and [ROADMAP.md](ROADMAP.md) for what is planned next.
|
|
172
|
+
|
|
173
|
+
Notable changes are recorded in [CHANGELOG.md](CHANGELOG.md).
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT License © 2025 Diogo Ribeiro. See [LICENSE](LICENSE).
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Citation
|
|
184
|
+
|
|
185
|
+
If you use this package in research or teaching, please cite it. GitHub's
|
|
186
|
+
"Cite this repository" button reads [CITATION.cff](CITATION.cff), or use:
|
|
187
|
+
|
|
188
|
+
> Ribeiro, D. (2025). *heavytails: A Pure-Python Library for Heavy-Tailed Probability Distributions*.
|
|
189
|
+
> <https://github.com/DiogoRibeiro7/heavytails>
|
|
190
|
+
|
|
191
|
+
Shared citation metadata is maintained in `CITATION.cff`; Zenodo-specific
|
|
192
|
+
archive metadata is maintained in `.zenodo.json`. The DOI will be added after
|
|
193
|
+
the first archived GitHub release.
|