Skip to main content

risk-kernel

The risk model liquidation kernels as a standalone package — pure compute (numpy + stdlib), zero DB access, no write path. This package is the source of truth for kernel logic: both core and core-api install it and run the kernels in-process.

Three model namespaces plus one shared:

  • risk_kernel.common — model-version-neutral vocabulary shared by every consumer: the liquidator dataclass contract (BorrowerPosition, MarketDescriptor, MarketContext, PricePaths, SellOrderbook, CRRSummary, …) and slippage_for_amount. Promoted out of risk_kernel.v2 (office #863) so v2 can be retired without breaking the surviving consumers.
  • risk_kernel.v2 — the v2 liquidation-simulation kernel. Operates on in-memory PricePaths / SellOrderbook / BorrowerPosition structures (defined in risk_kernel.common.types, re-exported unchanged at risk_kernel.v2.liquidator.types).
  • risk_kernel.v3 — the v3 market-clearing kernel: clearing kernel, impact law, CRR stats, liquidation-wall curve math, FHS residuals/simulator. Entry points risk_kernel.v3.kernel.run_clearing_kernel / run_multi_asset_kernel on KernelInputs / MultiAssetKernelInputs.
  • risk_kernel.concentration — the Laniakea correlation-framework concentration engine: position classification, L(category, scenario) loss matrix, Method A/B exposure caps (classify.classify_positionsloss.build_loss_matrixcaps.method_a / caps.method_b). calibration.py holds the generated factor shocks / static losses; number changes land as ordinary constants PRs referencing the analysis-repo run. Needs the concentration extra (balabs-risk-kernel[concentration] — pandas + cvxpy); the base install stays numpy-only, so importing the namespace without the extra fails at import time.

Loading inputs from a database is the consumer's job, never this package's.

Consumers

Both install balabs-risk-kernel from PyPI and run the kernels in-process:

  • core — the production risk model. Consumes the pure kernel here and keeps only the impure orchestration in-tree (src/risk_model_v2/, src/risk_model_v3/: datasources, pipelines, tasks, models, persistence, calibration). The pure compute modules were removed from core in office #553 — they live here now.
  • core-api — runs the kernels for the on-demand LTV↔CRR estimator endpoint (office #490 / #537).

Both currently pin balabs-risk-kernel==0.2.1.

Change flow

Kernel logic changes land here first. Release, then bump consumers:

  1. Make the change in src/risk_kernel/v2/ or src/risk_kernel/v3/.
  2. Merge with a conventional-commit message — release.yml runs python-semantic-release, which bumps the version and publishes to PyPI.
  3. Bump the pin in consumers (core, core-api pyproject.toml).

There is no per-model commit pin and no diff-against-core sync step: this repo no longer mirrors core. core is a consumer, not the origin.

What the package deliberately excludes

The kernels here are pure compute only — the impure layers that live in core (datasources, pipelines, persistence, tasks, calibration, forecasters, wall fetchers/sources) are intentionally not vendored.

The one non-obvious exclusion, carried over from when this repo was seeded from core: the v2 persistence path is stripped from v2/liquidator/pipeline/processors/liquidator.py (the _persist_market_crr / _persist_scenario_paths / _rewrite_market_crr_tiers / _prune_market_crr_snapshot24 methods, their sync() call sites, and the risk_model_v2.models import block). sync() computes and returns CRRSummary objects, nothing else. pipeline/scenario_paths.py is unused after the strip but kept verbatim.

Download files

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

Source Distribution

balabs_risk_kernel-0.4.0.tar.gz (75.9 kB view details)

Uploaded Source

Built Distribution

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

balabs_risk_kernel-0.4.0-py3-none-any.whl (90.4 kB view details)

Uploaded Python 3

File details

Details for the file balabs_risk_kernel-0.4.0.tar.gz.

File metadata

  • Download URL: balabs_risk_kernel-0.4.0.tar.gz
  • Upload date:
  • Size: 75.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for balabs_risk_kernel-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0e7d3d16e8fad0ba5d19eb914e3afdd3f0e4b06567cb356e9e9936670d4305e4
MD5 bea795b19bd85d0ec4f714edc9bc05cb
BLAKE2b-256 528a39ee115e81d3168f9b179c682e327a1c30c954f3dd699c30412815df17fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for balabs_risk_kernel-0.4.0.tar.gz:

Publisher: release.yml on blockanalitica/risk-kernel

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

File details

Details for the file balabs_risk_kernel-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for balabs_risk_kernel-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21f679ae1f400c92c8d43b4976711fc2b82a26a5b2fd1aa1cb965e488b900d1e
MD5 3d9a1a7ad6c958e25446a2e2c727c365
BLAKE2b-256 6587a95c58bb8a6ab7dda6e9100b6937cd2a292dfb4d7c4ab83c97291721ce8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for balabs_risk_kernel-0.4.0-py3-none-any.whl:

Publisher: release.yml on blockanalitica/risk-kernel

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

Release history Release notifications | RSS feed

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page