Skip to main content

Python port of nonlinear nonparametric statistics from R NNS

Project description

NNS Python

PyPI package Python License

ovvo-nns brings Nonlinear Nonparametric Statistics to Python as the nns import package. It is a parity-focused port of the R NNS 13.0+ package, designed for real-world data that violate symmetry, linearity, or distributional assumptions.

NNS is built around partial moments, the lower and upper components of variance, and uses them across nonlinear dependence, correlation, causation, regression, classification, forecasting, stochastic dominance, stochastic superiority, Monte Carlo simulation, and numerical differentiation workflows.

NNS was created by Fred Viole as the companion R package to Viole, F. and Nawrocki, D. (2013), Nonlinear Nonparametric Statistics: Using Partial Moments. Book (2nd Edition): https://ovvo-financial.github.io/NNS/book/

Implementation: For a direct quantitative finance implementation of NNS, see OVVO Labs

Package at a glance

Item Value
Distribution package ovvo-nns
Import package nns
Current version 1.0.3
Python >=3.11
Required runtime dependencies NumPy, SciPy
R required at runtime No
Native acceleration Private, optional nns._nnscore kernels where available
Public API status Stable, parity-focused
License GPL-3.0-only

The public package is Python-native and does not call R at runtime. Some core kernels can use the private _nnscore extension when it is present, while public functions keep Python implementations and explicit fallback behavior.

Install

pip install ovvo-nns

This includes the matplotlib plotting API (nns.plotting); matplotlib is a regular dependency and is imported lazily, so import nns stays light. See docs/plot_parity_policy.md.

Use the package as nns:

import nns

print(nns.__version__)

Source builds use scikit-build-core and nanobind for the optional native extension. Published wheels should be preferred when available.

Quick start

import numpy as np
from nns import lpm, nns_dep, nns_reg, upm

x = np.array([-2.0, -1.0, 0.5, 3.0], dtype=np.float64)

lower = lpm(degree=2, target=0.0, x=x)
upper = upm(degree=2, target=0.0, x=x)

print("lower partial moment:", lower)
print("upper partial moment:", upper)

Measure nonlinear dependence:

import numpy as np
from nns import nns_cor, nns_dep

grid = np.linspace(-2.0, 2.0, 80, dtype=np.float64)
y = grid**2

print("NNS dependence:", nns_dep(grid, y))
print("NNS correlation:", nns_cor(grid, y))

Fit a nonlinear regression and estimate new points:

import numpy as np
from nns import nns_reg

x = np.linspace(-3.0, 3.0, 80, dtype=np.float64)
y = np.sin(x) + 0.2 * x
points = np.array([-1.5, 0.0, 1.5], dtype=np.float64)

fit = nns_reg(x, y, point_est=points, confidence_interval=None)

print("R2:", fit["R2"])
print(np.column_stack((points, fit["Point.est"])))

Forecast a univariate series:

import numpy as np
from nns import nns_arma, nns_seas

t = np.arange(1, 60, dtype=np.float64)
series = 10.0 + np.sin(t / 3.0) + 0.05 * t

seasonality = nns_seas(series, modulo=[3, 4, 6], mod_only=True)
forecast = nns_arma(series, h=3, seasonal_factor=4, method="lin")

print("best seasonal period:", seasonality["best.period"])
print("forecast:", forecast)

Main API areas

Area Representative functions
Partial moments lpm, upm, lpm_ratio, upm_ratio, pm_matrix
Classical moment helpers mean_pm, var_pm, skew_pm, kurt_pm, nns_moments
Dependence, correlation, copula nns_dep, nns_cor, nns_copula
Causation nns_causation, causal_matrix
Regression and classification nns_reg, nns_m_reg, nns_stack, nns_boost
Forecasting nns_seas, nns_arma, nns_arma_optim, nns_var
Distribution tools nns_cdf, nns_anova, nns_norm
Stochastic dominance fsd, ssd, tsd, nns_sd_cluster, sd_efficient_set
Stochastic superiority and simulation nns_ss, nns_mc, nns_meboot
Differentiation nns_diff, dy_dx, dy_d
Categorical helpers encode_factor_codes, factor_2_dummy, factor_2_dummy_fr, prepare_factor_predictors

See API status for implemented, partial, guarded, and known-gap paths.

Design boundaries

NNS Python prioritizes stable public behavior from installed R NNS 13.0+, not private helper parity. The package returns NumPy arrays and plain dictionaries rather than R data.table objects, uses explicit Python errors for several unsafe R coercions, and generally ignores plotting side effects.

Important boundaries:

  • R is used only for parity tests and local cache regeneration, not normal runtime use.
  • Stochastic exact stream parity is not expected because Python paths use NumPy random generation.
  • Factor and class ordering should be passed explicitly when ordering matters.
  • Direct raw-factor nns_m_reg(..., factor_2_dummy=True) is intentionally guarded. Use prepare_factor_predictors(...) before nns_m_reg(...).
  • Compute functions still return values, not figures; passing plot=True (where R has it) additionally renders a Matplotlib figure as a side effect via the nns.plotting layer, which is color/element-faithful to R but not pixel-diffed. The plot functions can also be called directly on a computed result.

See behavior conventions for detailed compatibility notes.

Examples and notebooks

Runnable examples live in docs/examples:

Topic Script
Partial moments partial_moments.py
Dependence dependence.py
Distributions and ANOVA distributions_anova.py
Regression regression.py
Classification classification.py
Forecasting forecasting.py

Run one example:

uv run python docs/examples/partial_moments.py

Run all script examples:

for example in docs/examples/*.py; do uv run python "$example"; done

Notebook workflows are also available under docs/examples/notebooks.

Documentation

Development

uv sync --group dev
uv run pytest
uv run ruff check .
uv run mypy

Run benchmark tests explicitly:

uv run pytest -n0 -m benchmark --benchmark-enable tests/benchmarks/

The default parity suite is cache-backed and does not require Rscript. Rscript and the R NNS package are needed only when regenerating parity caches or running live R comparison scripts.

Benchmarks

Benchmarks compare selected Python paths with installed R NNS 13.0+ baselines. Many core operations are faster in Python, while some large stochastic-dominance workloads remain faster in R because the R package uses compiled kernels for those paths. See benchmarks for current measurements and commands.

Authors and contributors

  • Fred Viole — author and maintainer
  • Roberto Spadim — contributor
  • Rasheed Khoshnaw — contributor

Attribution

Upstream R package and reference implementation: OVVO-Financial/NNS

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ovvo_nns-1.0.3.tar.gz (8.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ovvo_nns-1.0.3-cp313-cp313-win_amd64.whl (231.6 kB view details)

Uploaded CPython 3.13Windows x86-64

ovvo_nns-1.0.3-cp313-cp313-musllinux_1_2_x86_64.whl (730.5 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.3-cp313-cp313-macosx_11_0_arm64.whl (246.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ovvo_nns-1.0.3-cp313-cp313-macosx_10_14_x86_64.whl (270.3 kB view details)

Uploaded CPython 3.13macOS 10.14+ x86-64

ovvo_nns-1.0.3-cp312-cp312-win_amd64.whl (231.6 kB view details)

Uploaded CPython 3.12Windows x86-64

ovvo_nns-1.0.3-cp312-cp312-musllinux_1_2_x86_64.whl (730.5 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.3-cp312-cp312-macosx_11_0_arm64.whl (246.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ovvo_nns-1.0.3-cp312-cp312-macosx_10_14_x86_64.whl (270.4 kB view details)

Uploaded CPython 3.12macOS 10.14+ x86-64

ovvo_nns-1.0.3-cp311-cp311-win_amd64.whl (231.9 kB view details)

Uploaded CPython 3.11Windows x86-64

ovvo_nns-1.0.3-cp311-cp311-musllinux_1_2_x86_64.whl (730.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.3-cp311-cp311-macosx_11_0_arm64.whl (247.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ovvo_nns-1.0.3-cp311-cp311-macosx_10_14_x86_64.whl (270.6 kB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

File details

Details for the file ovvo_nns-1.0.3.tar.gz.

File metadata

  • Download URL: ovvo_nns-1.0.3.tar.gz
  • Upload date:
  • Size: 8.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3b7e422fa02644eb245e9a288ab51b45ece41881548840eee00e3566091d6391
MD5 d4c7ca34c62ea9bb3ad09d37d96dad8f
BLAKE2b-256 06807b86b6284cc19d5df931c0c7fbc5e640beead60e0e90a909daab436f4444

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3.tar.gz:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 231.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1e4457c0ad0c3baa3cefd1a1345cabe864560ada1505b4bfbb4e77afb343b17a
MD5 1dd6c71187a07dd79f704cf9edf4c87d
BLAKE2b-256 0b336976a44015a71d41fe0e44798e01cf50cb9dc2a2470e64753923a8e5f18d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp313-cp313-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 28400920fc6e869c87674e60eced9310d6bef2c34481f6c9bd70ff1dcda4b2a3
MD5 d085c1a7671637084bea0b552a451139
BLAKE2b-256 eaeba1fc1b72780b2e23f3d05c8989cfec815c74037a209fa4c813ae960b767f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89210adcd15a754e49cccacfc26d46b15bf7f46cad160db82767a5d165df9402
MD5 39b68679890e337bab8663285207d53d
BLAKE2b-256 599c6e47679d3c57d1c51725cc1083bd83b61bd47888e4e29fa0949654524809

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a8de4bcf114682d44e9417f4779bae1d01ca04fe3312fdbccdad86ce6bf747ea
MD5 84138ae5d957d716c908ceac4ad68a0b
BLAKE2b-256 5e9d3e060c8324c738de8021cb7159fb8d6cac5ece51cff130305cefa05f791a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp313-cp313-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp313-cp313-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a958edd7ae2d51ff03ea5532e52c1d603598ac371f6797b06c5e3499709470fd
MD5 7d2dfa65e755c136823711a64f14111b
BLAKE2b-256 5e94d23663448aa605ddc0624aeee8f60a1df9d3e28901f12a6d0bcc6af58979

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp313-cp313-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 231.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 909a2ed3fa8c3cc91d0d33bec459da5023558813a3383034bdb6dcf636b97a90
MD5 00a0adb32c8f26a518a5734b706f793b
BLAKE2b-256 b88df1851f50cc6500aecfed92de45041ae22595b4bf6f9e2792cb298c0e9a9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp312-cp312-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 67d7566b649cd8ab165f706a1da681381877f345e47dbbded067e9ac5fecd36a
MD5 cac1eb09d2e289fdb5338761df7099e9
BLAKE2b-256 b6fc5be2471f14fb40be9c505fe68bb23d6170ee4661c5e0d17fc8929e047797

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d206a005ac117d5a1d077da101d9a876dc546077d6efb4897bc40aa3d484e39
MD5 9e6a3b0185da4852cbe859adc098e23d
BLAKE2b-256 9c0968fad38fa037e8b0ecbaf72c18fbd0a2508c697c639c1539237600f479c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f5399c87b74cab0da460aaadba2b02e7c8df411b472dc8f31cde7ed956e262f
MD5 b5d6a752b357729b3bedb7104b3cd525
BLAKE2b-256 922cb392359ceb171938ddcf90f57f4ee0690322ffd3b37855e63f5cf1b1a63f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b817008582338cca1934a9e6bb8c9c309dc62c44467552abae40332c2f549313
MD5 08078e8173a7c98229f9c3f02eaa1700
BLAKE2b-256 d9beca35b91c5aa61fceb7ca29a991cd2253ddd7166e41b8e5256fc6d773eaf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp312-cp312-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 231.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7056f1583ac4f388efd599b770fd748de908dadaef5ce82cd67beb253587400d
MD5 9b4c35cf6f20d1e1efb73c51142b8172
BLAKE2b-256 29bdec911ee6cabd4516661c7b26f972a5e9ff235154140a1e0ba3c92c6c5f23

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp311-cp311-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 16e9513370dd7252ee8f18db30341b9cfb3360b2f6703aaa5e061c95719392fe
MD5 f64fb9f41f16781ddf8d252d3e29cfa4
BLAKE2b-256 03496ab6e97f7316acecbe69954d499653f89c78d3712bbf285c2cac4d10738b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78f59df7bff3bcfdb0363e363d06fe2b6690403f3f1617953958ebd58d46cc3e
MD5 d1fdc0bee025c0c9ad3294f1f7df0d0f
BLAKE2b-256 d37d483063b58b3d0f8301105086d7438a0706f2b3de52bc77d5839c37f0a73c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6af164d110f7cce2b2577bf7506aac161cb79fff823ee4725f40614f576db05a
MD5 166ca718d611017b53f88c6560b9903d
BLAKE2b-256 165f48342768eba56567fec186449aa6bc2cf22251335de1b865b632376d08d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ovvo_nns-1.0.3-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.3-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 813a9a250a8a28fc681c3e36401fd8ab15651c526a03959d287aa3cdc54f29fb
MD5 e611a0cb82560567ff073c424cd92c3c
BLAKE2b-256 e9ffbdae9d47becaeffc97732fc3421c62fe74b5e088f6a65e161e032f5293f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.3-cp311-cp311-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page