Skip to main content

A Python library for actuarial loss modeling using frequency-severity methods.

Project description

lossmodels

Python License

A Python library for actuarial loss modeling using frequency–severity methods.


Overview

lossmodels provides a clean, modular implementation of core actuarial techniques from Loss Models: Data to Decisions (Klugman, Panjer, Willmot), including:

  • frequency–severity modeling
  • aggregate loss modeling (simulation, Panjer recursion, FFT)
  • parameter estimation (MLE, method of moments)
  • credibility theory
  • risk measurement (VaR, TVaR, stop-loss)

Designed for:

  • actuaries and actuarial analysts
  • quantitative developers
  • data scientists in insurance

Quick Example

from lossmodels.frequency import Poisson
from lossmodels.severity import Lognormal
from lossmodels.aggregate import CollectiveRiskModel

freq = Poisson(lam=2.0)
sev = Lognormal(mu=10.0, sigma=0.8)

model = CollectiveRiskModel(freq, sev)

print("Mean:", model.mean())
print("VaR 95%:", model.var(0.95))
print("TVaR 95%:", model.tvar(0.95))

Installation

pip install lossmodels

Or for development:

pip install -e .

Core Features

Frequency Models

  • Poisson
  • Negative Binomial
  • Binomial
  • Geometric
  • Empirical frequency

Severity Models

  • Exponential
  • Gamma
  • Lognormal
  • Pareto
  • Weibull
  • Empirical severity

Aggregate Modeling

  • Monte Carlo simulation
  • Panjer recursion
  • FFT (Fast Fourier Transform)

Estimation

  • Maximum Likelihood Estimation (MLE)
  • Method of Moments
  • Generic numerical MLE

Model Selection

  • Best severity selection (AIC / BIC)
  • Best frequency selection (Poisson, Negative Binomial)

Credibility

  • Bühlmann
  • Bühlmann–Straub

Risk Measures

  • VaR
  • TVaR
  • Stop-loss
  • Limited Expected Value (LEV)
  • PMF-based VaR / TVaR / stop-loss

Aggregate Methods

Simulation

samples = model.sample(100_000)

Panjer Recursion

from lossmodels.aggregate import discretize_severity, panjer_recursion

pmf = discretize_severity(sev, h=0.01, max_loss=20.0)
agg = panjer_recursion(freq, pmf, n_steps=5000)

FFT

from lossmodels.aggregate import fft_aggregate_poisson

agg = fft_aggregate_poisson(freq, pmf, n_steps=5000)

Risk Measures from PMF

from lossmodels.aggregate import var_from_pmf, tvar_from_pmf

var95 = var_from_pmf(agg, h=0.01, q=0.95)
tvar95 = tvar_from_pmf(agg, h=0.01, q=0.95)

Parameter Estimation

from lossmodels.estimation import fit_lognormal, fit_best_severity

model = fit_lognormal(data)
best = fit_best_severity(data)

Examples

See the examples/ directory:

  • fit_and_compare_models.py
  • panjer_vs_simulation.py
  • panjer_vs_fft_vs_simulation.py
  • credibility_example.py

Testing

pytest -v

Fast tests only:

pytest -v -m "not slow"

Project Status

Core Loss Models functionality is implemented.

Planned improvements:

  • Extreme Value Theory (EVT)
  • Bootstrap methods
  • Performance optimization
  • Additional distributions
  • Documentation

License

MIT License

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

lossmodels-0.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

lossmodels-0.1.0-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file lossmodels-0.1.0.tar.gz.

File metadata

  • Download URL: lossmodels-0.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for lossmodels-0.1.0.tar.gz
Algorithm Hash digest
SHA256 66b693d7e8b2353e0c30e49b6fb1905bec4e2c3020070a4a9d42236a7cf803f8
MD5 5a6e0e0c2c63c134d9f7074861e873ee
BLAKE2b-256 e590f1e07d8a495748ca503b0031418076bdedca71e93f5e052fd3857d85f306

See more details on using hashes here.

File details

Details for the file lossmodels-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lossmodels-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for lossmodels-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a68bca1eddbac09e5185f798e0b82db525034dfee2883a31d03285bc6d673851
MD5 5aa5a935fb71ec27b75ce9c1154b357b
BLAKE2b-256 6ca4dab88941f43385e88e906356f6d753056c6cf8f30afc41d6fffb1d20ffcd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page