evtpooling contains the framework needed to improve tail risk forecasts
Project description
evtpooling provides a comprehensive framework for improving tail risk forecasts by combining robust statistical modeling, data transformation, and diagnostic backtesting.
It features a production-ready ETL pipeline for financial time series data, modular forecasting evaluation tools, and implementations of advanced tail-based clustering and testing methods. This includes RMTC-based clustering, HMIX mixture modeling, and a fully integrated traffic-light backtesting system with Diebold-Mariano forecast comparison.
The codebase follows modern Python packaging and style standards via pyproject.toml, and uses pre-commit for enforcing formatting (Black, Ruff), linting, and type safety.
Note that this package includes some constants accesible under evtpooling.constants that are used for convenience. These constants are mostly used for the etl_pipeline but can be modified to suit your needs.
Features
Full ETL pipeline for financial time series data
Robust loss return calculations (daily, weekly, anchor-based)
RMTC (Robust Model-based Tail Clustering) algorithm
HMIX (Heteroscedastic Mixture) tail modeling with robust optimization
Integrated backtesting framework with: - Traffic light logic - Diebold-Mariano forecast accuracy tests
Visualizations of loss distributions, VaR exceedances, and tail index behavior
Data validation (missing values, dtypes, fuzzy categorical matching)
Clean, testable architecture (ETL, transform, modeling, testing modules)
Interactive result summaries via DataFrames and matplotlib plots
Fully automated testing with pytest
Centralized configuration using pyproject.toml
Pre-commit hooks for Ruff, Black, and Mypy integration
CI-friendly and GitHub Actions-compatible
Installation
You can install the released version from PyPI using:
pip install evtpooling
Or install directly from the source (development version):
git clone https://github.com/JTKimQF/evtpooling.git
cd evtpooling
pip install -e .
Usage Example
The package supports a full ETL-to-evaluation pipeline for tail risk modeling and backtesting. Below is a simplified example of its usage:
import numpy as np
from evtpooling import (
etl_pipeline,
get_alpha_dict,
get_var_dict,
kmeans_pooling,
rmtc_pooling,
basel_backtesting,
sener_backtesting,
dm_test,
)
# Load and transform input data
weekly_losses, daily_losses = etl_pipeline("path/to/input.csv", return_day_data=True)
# Estimate tail indices (alphas) from the training portion
k_thresh = 60
weekly_losses_train = weekly_losses[weekly_losses.index <= "2018-12-31"]
alpha_dict = get_alpha_dict(weekly_losses_train, k_threshold=k_thresh)
# Generate non-pooled VaR estimates
var_dict = get_var_dict(weekly_losses_train, k_threshold=k_thresh)
# KMeans-based clustering and pooled VaR
df_kmeans = kmeans_pooling(weekly_losses_train, k_threshold=k_thresh, num_clusters=4)
var_dict_kmeans = dict(zip(df_kmeans.index, df_kmeans["kmeans_var"]))
# RMTC-based clustering and pooled VaR
df_rmtc, beta_list = rmtc_pooling(
losses=weekly_losses_train,
k_threshold=k_thresh,
beta=([0.4, 0.4, 0.2], [(1.9, 0.2), (2.3, 0.3), (3.0, 0.5)]),
threshold=1e-4,
max_iter=50,
)
var_dict_rmtc = dict(zip(df_rmtc.index, df_rmtc["rmtc_var"]))
# Backtesting on evaluation data
weekly_losses_eval = weekly_losses[weekly_losses.index > "2018-12-31"]
df_backtest_kmeans = basel_backtesting(weekly_losses_eval, var_dict=var_dict_kmeans)
df_backtest_rmtc = basel_backtesting(weekly_losses_eval, var_dict=var_dict_rmtc)
# Forecast accuracy comparison using Diebold-Mariano test
dm_kmeans = dm_test(weekly_losses_eval, var_dict1=var_dict, var_dict2=var_dict_kmeans)
dm_rmtc = dm_test(weekly_losses_eval, var_dict1=var_dict, var_dict2=var_dict_rmtc)
print("DM test (non-pooling vs KMeans):")
print(dm_kmeans)
print("DM test (non-pooling vs RMTC):")
print(dm_rmtc)
For further details check out the testing_script.py file
Documentation
Full documentation and function reference is available inside the code base (src/evtpooling/…).
License
MIT License
Copyright (c) 2025 J.T. Kim
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file evtpooling-0.3.2.tar.gz.
File metadata
- Download URL: evtpooling-0.3.2.tar.gz
- Upload date:
- Size: 51.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27142c0145acc73c8ac99aeeeeeb0b62ac7ceed56f76ca04c0dee4c5f8b193d9
|
|
| MD5 |
4cfc338cc8bd4ba983af3f5d87d43621
|
|
| BLAKE2b-256 |
12f017043262baa41f16f4154d523d42dcdb37616232574d57a3a88293c59e73
|
File details
Details for the file evtpooling-0.3.2-py3-none-any.whl.
File metadata
- Download URL: evtpooling-0.3.2-py3-none-any.whl
- Upload date:
- Size: 38.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1055741150185c60d8ec17b5e2c6cbc60731f0d1936fd84712d7e92a4faca135
|
|
| MD5 |
b9aa7ad10798ab3b6e6c97bedd899a11
|
|
| BLAKE2b-256 |
1f3f4998a1324b42016d3871dc3e745acbe24335baac459029a333817fbfc9d4
|