Skip to main content

A comprehensive Python library for P&C actuarial ratemaking

Project description

Ratemaking

A comprehensive Python library for Property & Casualty actuarial ratemaking, providing tools for credibility analysis, trending, exposure calculations, and data processing.

Python 3.8+ License: MIT

Features

Currently Available

  • Credibility Analysis: Classical, Bühlmann, and Bayesian credibility methods
  • Complement Calculations: First-Dollar methods from Werner & Modlin Chapter 12
  • Comprehensive Testing: Test suite with actuarial validation

Installation

pip install ratemaking

Quick Start

Classical Credibility

from ratemaking import (
    classical_full_credibility_frequency,
    classical_partial_credibility
)

# Calculate full credibility standard
n_full = classical_full_credibility_frequency(p=0.95, k=0.05)

# Calculate credibility factor  
z = classical_partial_credibility(n=observed_claims, n_full=n_full)

# Apply credibility blend
estimate = z * observed_rate + (1 - z) * complement_rate

Bühlmann Credibility

from ratemaking import BuhlmannInputs, buhlmann

data = {"risk_1": [1.2, 1.5], "risk_2": [2.1, 1.9]}
result = buhlmann(BuhlmannInputs(data=data))
print(f"Credibility weights: {result.Z_by_risk}")

Bayesian Credibility

from ratemaking import bayes_poisson_gamma

# Poisson-Gamma conjugate updating
posterior = bayes_poisson_gamma(
    prior_alpha=2.0, prior_beta=100.0,
    total_counts=15, total_exposure=120
)
print(f"Posterior mean: {posterior.mean}")
print(f"Credibility weight: {posterior.credibility_Z}")

Complement Calculations

from ratemaking.complements import (
    trended_present_rates_loss_cost,
    trended_present_rates_rate_change_factor,
    larger_group_applied_rate_change_to_present_rate,
    HarwayneInputs,
    harwayne_complement,
)

# Trended present rates method
complement = trended_present_rates_loss_cost(
    present_rate=100.0,
    prior_indicated_factor=1.10,  # 10% indicated
    prior_implemented_factor=1.06,  # 6% implemented 
    loss_trend_annual=0.05,  # 5% annual loss trend
    trend_years=2.0
)

# Harwayne's method for multi-state complements
inputs = HarwayneInputs(
    target_class_exposures=target_exposures,
    target_avg_pure_premium=120.0,
    related_state_class_pp=related_pp_data,
    related_state_class_exposures=related_exposure_data,
    class_of_interest='ClassA'
)
complement = harwayne_complement(inputs)

Package Structure

ratemaking/
├── credibility/           # Credibility analysis tools
│   ├── classical.py      # Classical (Limited Fluctuation) credibility
│   ├── buhlmann.py       # Bühlmann & Bühlmann-Straub credibility
│   └── bayesian.py       # Bayesian credibility with conjugate priors
├── complements/          # Complement calculation methods
│   └── first_dollar.py   # First-Dollar methods (Werner & Modlin Ch.12)
├── trending/             # Trending analysis tools (coming soon)
├── exposure/             # Exposure calculation tools (coming soon)
└── utils/                # Data processing utilities (coming soon)

Modular Usage

For organized imports, use the submodules:

# Organized by functionality
from ratemaking.credibility import classical, buhlmann, bayesian
from ratemaking.complements import first_dollar

# Use specific functions
n_full = classical.classical_full_credibility_frequency(p=0.95, k=0.05)
complement = first_dollar.trended_present_rates_loss_cost(...)

Testing

Run the test suite:

pytest tests/ -v

Development

Setting up for development:

git clone https://github.com/little-croissant/ratemaking.git
cd ratemaking
pip install -e .
pip install -e ".[test]"

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

ratemaking-0.1.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

ratemaking-0.1.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ratemaking-0.1.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ratemaking-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b5e59bad4dec3efe7d2707c8e1242aa489aabe21621d479517721515d1c8fd8f
MD5 ea42b6410af0a82fecca3e35603d1fb4
BLAKE2b-256 600306cc2f16a35b18a489071f0c6f6ae4d69de04f3d1d9ae34542ad50fe2531

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ratemaking-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ratemaking-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5172790c19e48af971b983561b87f26a4b944e3737fe11c2baf103551547c7d8
MD5 3bb8bfd6ef374329ec16f3bfab705cb9
BLAKE2b-256 8cdb33e27ed07e55cbb34fc39a0e14b92d37a8424e1cbce65008b417fd511ba7

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