fhs-market-risk
Zero-network Filtered Historical Simulation (EWMA FHS), exact fractional-probability Expected Shortfall (ES) with additive component attribution, strictly causal walk-forward Kupiec/Christoffersen VaR backtesting, and base-currency FX translation sensitivity.
Built to pair cleanly with eod-market-data (or used directly on numpy return matrices).
Features
- Empirical VaR & Exact Additive Expected Shortfall (
tail_statistics): Inverse-CDF VaR and exact fractional-probability tail mean so component ES values sum identically to portfolio ES (preserving negative/hedging contributions). - Causal EWMA Filtered Historical Simulation (
filtered_scenarios): Zero-mean log-return EWMA with a strictly causal expanding second-moment variance floor (zero look-ahead) that preserves joint cross-asset shock dates. - Walk-Forward VaR Backtesting (
backtest_var,kupiec_pof_test,christoffersen_test): Strictly causal out-of-sample VaR exceedances with exact Kupiec POF ($\chi^2_1$), Christoffersen independence ($\chi^2_1$), and conditional coverage ($\chi^2_2$) tests — zeroscipyruntime dependency. - Calendar- & Split-Aware Book Engine (
build_market_risk): Replays dated joint shocks on current exposures usingeod-market-datahistory, respecting exchange calendars, split divisors, gross dividends, futures notional, and explicit exclusion diagnostics (missing exposures never become zero risk). - Base-Currency FX Translation Sensitivity (
sensitivity,implied_fx_rates,product_currency): One-factor balance-sheet FX shocks with NAV reconciliation for any base currency (EUR,USD,GBP, etc.).
Installation
pip install fhs-market-risk
Quick Start
import numpy as np
from fhs_market_risk import backtest_var, filtered_scenarios, tail_statistics
rng = np.random.default_rng(42)
returns = rng.normal(0.0, 0.012, size=(250, 2))
exposure = np.array([60_000.0, 40_000.0])
# 1D Filtered Historical Simulation scenarios
filtered_log, forecast_vol = filtered_scenarios(np.log1p(returns))
scenario_pnl = np.expm1(filtered_log) * exposure
stats = tail_statistics(scenario_pnl, confidence=0.975)
print(stats["var"], stats["es"], stats["components"])
# Strictly causal walk-forward VaR backtest
bt = backtest_var(returns, exposure, confidence=0.95)
print(bt["status"], bt["exceedances"], bt["observations"], bt["p_value_pof"], bt["p_value_cc"])
CLI
fhs-risk backtest returns.csv --confidence 0.95 --weights 60000,40000
License
MIT — see LICENSE.
Metadata
Release files for fhs-market-risk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fhs_market_risk-0.1.0.tar.gz | 121.6 kB | Without provenance | Details for fhs_market_risk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fhs_market_risk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for fhs_market_risk-0.1.0-py3-none-any.whl |
Total release size: 138.8 kB
Release files / fhs_market_risk-0.1.0.tar.gz
| Download URL | fhs_market_risk-0.1.0.tar.gz |
|---|---|
| Size | 121.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b60249d5e3aaa91c4590c243a4d1f95d08af09e4138224b7f4eaad4f417c7e4
|
|
BLAKE2b-256 checksum How to use checksums |
c2b04f52a69c4cbc2cbf23ffce1503c3a002ab1fff3c088dc564244a17ad46f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fhs_market_risk-0.1.0-py3-none-any.whl
| Download URL | fhs_market_risk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b76117310b1bc68d29d2ccd1e3b936e903e72a2a4be933b3b1bc3df75cdf5c06
|
|
BLAKE2b-256 checksum How to use checksums |
038a7cbc69d168b6261bf43b78cac4ff7fefe9aef70c14a64ea8c4c87c5b5b7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for fhs-market-risk 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.