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.1.tar.gz (21.6 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.1-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lossmodels-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 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.1.tar.gz
Algorithm Hash digest
SHA256 12b3a2a2b7b8a1ca47ea2a2a879c729cb379e184401190557741a76bac54395c
MD5 7f43d4df37a50eb630cc0fcd9efcb241
BLAKE2b-256 e35cfd6796a0c3bad1cf76ad1399f48494faec30753679a833419034af73d106

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lossmodels-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 35.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 14fbd1e293de733c7927f3eac8dacfce4a7d82d92e3d09683459a4714686b549
MD5 e1179130409ed071a4fc04f423e35cda
BLAKE2b-256 8fed71817e422b981eafa055e746dcf182024ec6fbdb3febbc0b87d9c65d7f57

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