Loss ratio analysis for insurance experience data (Python sibling of the R lossratio package; in development).
Project description
lossratio (Python)
Python sibling of the R lossratio package: loss-ratio analysis and
projection for long-term health insurance from long-format experience
data. Stage-adaptive (SA) projection uses an exposure-driven (ED)
model before the maturity point and chain ladder (Mack, CL) after,
supported by maturity point detection, cohort regime detection, and
a calendar-diagonal backtest framework.
This Python implementation is in active development.
Current status
Working components so far:
Experience— validates loss-ratio experience data (cym,uym,loss,rp), accepts polars or pandas input.Triangle— cohort × dev aggregation with incremental (loss,rp) and cumulative (closs,crp) sums and ratios (lr,clr) per (group, cohort, dev) lane.
Additional components (loss-ratio projection with stage-adaptive
method, maturity point and cohort regime detection, calendar-diagonal
backtest) are being added incrementally. The full working reference
implementation is the R lossratio package; see the section below
for a link.
Quick Start
import polars as pl
import lossratio as lr
# Three cohorts (2024-01, 02, 03) each observed over up to three months
df = pl.DataFrame({
"cym": [
"2024-01-01", "2024-02-01", "2024-03-01", # cohort 2024-01, dev 1-3
"2024-02-01", "2024-03-01", # cohort 2024-02, dev 1-2
"2024-03-01", # cohort 2024-03, dev 1
],
"uym": [
"2024-01-01", "2024-01-01", "2024-01-01",
"2024-02-01", "2024-02-01",
"2024-03-01",
],
"loss": [12.0, 18.0, 25.0, 15.0, 22.0, 9.0],
"rp": [100.0, 100.0, 100.0, 110.0, 110.0, 120.0],
})
exp = lr.Experience(df)
tri = exp.triangle()
print(tri.df)
#> shape: (6, 8)
#> ┌────────────┬─────┬──────┬───────┬───────┬───────┬──────────┬──────────┐
#> │ cohort ┆ dev ┆ loss ┆ rp ┆ closs ┆ crp ┆ lr ┆ clr │
#> │ date ┆ i64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
#> ╞════════════╪═════╪══════╪═══════╪═══════╪═══════╪══════════╪══════════╡
#> │ 2024-01-01 ┆ 1 ┆ 12.0 ┆ 100.0 ┆ 12.0 ┆ 100.0 ┆ 0.12 ┆ 0.12 │
#> │ 2024-01-01 ┆ 2 ┆ 18.0 ┆ 100.0 ┆ 30.0 ┆ 200.0 ┆ 0.18 ┆ 0.15 │
#> │ 2024-01-01 ┆ 3 ┆ 25.0 ┆ 100.0 ┆ 55.0 ┆ 300.0 ┆ 0.25 ┆ 0.183333 │
#> │ 2024-02-01 ┆ 1 ┆ 15.0 ┆ 110.0 ┆ 15.0 ┆ 110.0 ┆ 0.136364 ┆ 0.136364 │
#> │ 2024-02-01 ┆ 2 ┆ 22.0 ┆ 110.0 ┆ 37.0 ┆ 220.0 ┆ 0.2 ┆ 0.168182 │
#> │ 2024-03-01 ┆ 1 ┆ 9.0 ┆ 120.0 ┆ 9.0 ┆ 120.0 ┆ 0.075 ┆ 0.075 │
#> └────────────┴─────┴──────┴───────┴───────┴───────┴──────────┴──────────┘
The same triangle can be sliced by an optional grouping variable (coverage, product, age band, sum insured, ...):
df_grouped = df.with_columns(pl.lit("SUR").alias("cv_nm"))
tri = lr.Experience(df_grouped).triangle(group_var="cv_nm")
Pandas inputs are accepted too; outputs mirror the input type
(pandas in → pandas out, polars in → polars out). Install with the
optional pandas extra:
pip install lossratio[pandas]
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@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.dev4.tar.gz.
File metadata
- Download URL: lossratio-0.0.1.dev4.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d72b8206d07b1f5f5986baa2924e3028965c326df585a71908334c342bfdff54
|
|
| MD5 |
bd841ec3041542a807fd4087180d7d0a
|
|
| BLAKE2b-256 |
f6423942679a6ea91bb8585382b8cab4a7d65961f0d8cb76542daae3f6a3aba0
|
Provenance
The following attestation bundles were made for lossratio-0.0.1.dev4.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.dev4.tar.gz -
Subject digest:
d72b8206d07b1f5f5986baa2924e3028965c326df585a71908334c342bfdff54 - Sigstore transparency entry: 1461580085
- Sigstore integration time:
-
Permalink:
seokhoonj/lossratio-py@d276e49daf2611e1aa849030327ff1005289ac87 -
Branch / Tag:
refs/tags/v0.0.1.dev4 - Owner: https://github.com/seokhoonj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d276e49daf2611e1aa849030327ff1005289ac87 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lossratio-0.0.1.dev4-py3-none-any.whl.
File metadata
- Download URL: lossratio-0.0.1.dev4-py3-none-any.whl
- Upload date:
- Size: 28.4 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 |
c4a0b230665883cd652c42780e9054ba04f29711c6e7a21a5519dd5fb37e3d8c
|
|
| MD5 |
0f46ab5f1b2bb3126a26ffc8f427fd41
|
|
| BLAKE2b-256 |
7e571836870801140e89f686d7a568a7553aff35cb57555834763960302c344c
|
Provenance
The following attestation bundles were made for lossratio-0.0.1.dev4-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.dev4-py3-none-any.whl -
Subject digest:
c4a0b230665883cd652c42780e9054ba04f29711c6e7a21a5519dd5fb37e3d8c - Sigstore transparency entry: 1461580156
- Sigstore integration time:
-
Permalink:
seokhoonj/lossratio-py@d276e49daf2611e1aa849030327ff1005289ac87 -
Branch / Tag:
refs/tags/v0.0.1.dev4 - Owner: https://github.com/seokhoonj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d276e49daf2611e1aa849030327ff1005289ac87 -
Trigger Event:
push
-
Statement type: