Loss ratio analytics for long-term health insurance.
Project description
lossratio (Python)
Python sibling of the R lossratio package: loss ratio analytics
for long-term health insurance — cohort development analysis,
stage-adaptive projection, regime detection, and backtest validation
on long-format experience data. Stage-adaptive (SA) projection uses
an exposure-driven (ED) model before the maturity point and chain
ladder (CL) after.
This Python implementation is in active development (0.0.1.devN
release line on PyPI).
Install
pip install lossratio # polars only
pip install lossratio[pandas] # add pandas / pyarrow support
Current status
Working components:
Experience— validates loss ratio experience data (cym,uym,loss_incr,premium_incr), accepts polars or pandas input.Triangle— cohort × dev aggregation. Cumulative is the unmarked default (loss,premium,lr); per-period values carry an_incrsuffix (loss_incr,premium_incr,lr_incr).CL,ED,LR— sklearn-style estimators for chain ladder, exposure-driven, and stage-adaptive loss-ratio projection (fit(triangle)→CLFit/EDFit/LRFitwithsummary(),dfprojection frame, and per-cohort SE / CV).Triangle.maturity()— detects the development period at which age-to-age factors stabilise (returns aMaturityresult).Triangle.detect_regime()— detects structural shifts across the cohort sequence via E-Divisive or Ward hierarchical clustering (returns aRegimeresult).Backtest— calendar-diagonal hold-out backtest of any of the above estimators (returns aBacktestFitwith per-cell, by-dev, and by-diagonal AEG summaries).
Not yet ported from the R sibling: Calendar / Total
aggregations, the intermediate Link object, and the
Convergence diagnostic.
Quick Start
import polars as pl
import lossratio as lr
# Built-in synthetic experience: four coverages (CI / CAN / HOS / SUR),
# 36 monthly cohorts each, up to 36 dev months. SUR carries one regime
# shift at 2025-07.
df = lr.load_experience()
# 1. Validate the experience data and build a cohort x dev triangle.
# Pass group_var="coverage" to fit each coverage independently.
exp = lr.Experience(df)
tri = exp.triangle(group_var="coverage")
# 2. Project loss ratios with stage-adaptive method (default)
fit = lr.LR().fit(tri)
fit.summary() # per-(group, cohort) loss_ult / lr_ult / SE / CV
# 3. Detect cohort regime shifts. detect_regime works on a single
# group, so subset to the coverage of interest first.
tri_sur = lr.Experience(df.filter(pl.col("coverage") == "SUR")).triangle()
reg = tri_sur.detect_regime(loss_var="lr", K=12)
reg.breakpoints # [datetime.date(2025, 7, 1)]
# 4. Calendar-diagonal hold-out backtest on the grouped triangle.
# The last 6 diagonals are masked, the estimator is refitted on the
# remaining cells, and the projection is compared with actual loss.
bt = lr.Backtest(estimator=lr.LR(), holdout=6).fit(tri)
bt.diag_summary # actual vs predicted vs AEG by calendar diagonal
To plug in your own data, build a long-format frame with these
columns and pass it to lr.Experience(df):
cym(date) — calendar year-monthuym(date) — underwriting year-month (cohort)loss_incr(numeric) — per-period claim amountpremium_incr(numeric) — per-period premium
Triangle also accepts an optional group_var (coverage, product,
age band, ...) — each estimator and detector then fits per group.
Pandas inputs are accepted too; outputs mirror the input type
(pandas in → pandas out, polars in → polars out). Use the
[pandas] install extra (see above) to pull in pandas and
pyarrow.
R package
- Source: https://github.com/seokhoonj/lossratio
- Documentation: https://seokhoonj.github.io/lossratio/
- 한국어 문서: https://seokhoonj.github.io/lossratio/ko/
remotes::install_github("seokhoonj/lossratio")
library(lossratio)
Author
Seokhoon Joo
(@seokhoonj,
seokhoonj@gmail.com) — also maintains the R lossratio package.
License
MPL-2.0 (Mozilla Public License 2.0).
Project details
Release history Release notifications | RSS feed
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 lossratio-0.0.1.dev6.tar.gz.
File metadata
- Download URL: lossratio-0.0.1.dev6.tar.gz
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b1bc8c3fe8a2a6cb961dd94cb3d80fc18bc04734f71a3a095478e5b797db4d3
|
|
| MD5 |
b363f9c7967c3d144df29c95e6d16f26
|
|
| BLAKE2b-256 |
33e479d2ae1aba8039c6c5867380d7eea2c5f41c8d51259a4d8fd1711ce04653
|
Provenance
The following attestation bundles were made for lossratio-0.0.1.dev6.tar.gz:
Publisher:
publish.yml on seokhoonj/lossratio-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lossratio-0.0.1.dev6.tar.gz -
Subject digest:
7b1bc8c3fe8a2a6cb961dd94cb3d80fc18bc04734f71a3a095478e5b797db4d3 - Sigstore transparency entry: 1486103725
- Sigstore integration time:
-
Permalink:
seokhoonj/lossratio-py@ec5d005402297c1f452c775730584ddbd3908fc4 -
Branch / Tag:
refs/tags/v0.0.1.dev6 - Owner: https://github.com/seokhoonj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec5d005402297c1f452c775730584ddbd3908fc4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lossratio-0.0.1.dev6-py3-none-any.whl.
File metadata
- Download URL: lossratio-0.0.1.dev6-py3-none-any.whl
- Upload date:
- Size: 42.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46cd33ff0e40683796ef88471e4be397349920732035720b073d651fae4e513b
|
|
| MD5 |
fc40feefa829aec81c7517f8e048d9ca
|
|
| BLAKE2b-256 |
07b1f78607b85f860402bbf5e0213a711763e9b49387dea34e2521d12f9e9df2
|
Provenance
The following attestation bundles were made for lossratio-0.0.1.dev6-py3-none-any.whl:
Publisher:
publish.yml on seokhoonj/lossratio-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lossratio-0.0.1.dev6-py3-none-any.whl -
Subject digest:
46cd33ff0e40683796ef88471e4be397349920732035720b073d651fae4e513b - Sigstore transparency entry: 1486103748
- Sigstore integration time:
-
Permalink:
seokhoonj/lossratio-py@ec5d005402297c1f452c775730584ddbd3908fc4 -
Branch / Tag:
refs/tags/v0.0.1.dev6 - Owner: https://github.com/seokhoonj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec5d005402297c1f452c775730584ddbd3908fc4 -
Trigger Event:
push
-
Statement type: