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.
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
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
ratemaking-0.3.1.tar.gz
(22.5 kB
view details)
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 ratemaking-0.3.1.tar.gz.
File metadata
- Download URL: ratemaking-0.3.1.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7aee9e7bd484ff4cc8c211ab913ae2a3ff64b17468279ab015c9213946e698
|
|
| MD5 |
9bf95cd649b449401fbcd3b1fc305e9a
|
|
| BLAKE2b-256 |
bd7fce438a1c2b59f247733a3a173de6e2a7d91e21fcab4cd6b9b72f88a83ae4
|
File details
Details for the file ratemaking-0.3.1-py3-none-any.whl.
File metadata
- Download URL: ratemaking-0.3.1-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bad8e695b2122d1982e221dd3b4f715336c05b381a0954597e9fe8eee91354e
|
|
| MD5 |
109dc5c147bc0f5acb25fdf1e50d5f68
|
|
| BLAKE2b-256 |
bb2d19863f7f3e412dc2c530bb6093f131ca30dc53c2d5308cf061027deccc2a
|