chainladder Python Package

repository·main·Indexed 42 days ago

https://github.com/casact/chainladder-python

A P&C loss reserving library for actuarial loss development and triangle analysis. Version 0.10.1 features a core Triangle data structure with a pandas-style API and scikit-learn compatible estimators. It includes tools for development patterns (MackChainladder, BornhuetterFerguson, CapeCod), tail factor extrapolation (TailCurve, TailBondy), and data adjustments (Trend, DisposalRate), as well as workflow orchestration via Pipeline and GridSearch.

Tokens
13.9K
Snippets
38
Records
73
Agent score
54%

What's inside chainladder

  1. Overview of chainladder-python capabilities

    main

    The chainladder-python package is designed for actuarial reserving and pricing tasks in Python. It provides tools for:

    • Triangle data manipulation: Handling development triangles.
    • Link ratios calculation: Computing development factors.
    • IBNR estimates: Estimating Incurred But Not Reported claims using both deterministic and stochastic models.

    The library follows a minimalistic API design, mimicking the syntax of pandas for data manipulation and scikit-learn for model construction to reduce the learning curve for users familiar with the Python data science ecosystem.

  2. Overview of chainladder for Property and Casualty Loss Reserving

    main

    The chainladder package is a Python library designed for actuarial needs in Property and Casualty (P&C) loss reserving. It provides tools for triangle data manipulation, link ratio calculation, and IBNR (Incurred But Not Reported) estimates using both deterministic and stochastic models.

    To minimize the learning curve, the package follows API design patterns familiar to users of pandas (for data manipulation) and scikit-learn (for model construction).

  3. Understand the chainladder-python directory structure

    main

    The chainladder package is organized into functional subpackages that separate data structures, estimation methods, and preprocessing logic:

    • core/: Contains the central Triangle data structure and its associated slicing, I/O, and pandas-style API capabilities.
    • development/: Implements estimators for development patterns (e.g., weighted LDF, Tweedie GLM, Munich adjustment).
    • tails/: Contains estimators specifically for tail factor extrapolation (e.g., TailCurve, TailBondy).
    • methods/: Implements reserve estimation methods like MackChainladder, BornhuetterFerguson, and CapeCod.
    • adjustments/: Provides preprocessing transformers to adjust triangle data (e.g., Trend, DisposalRate, ParallelogramOLF).
    • workflow/: Utilities for building pipelines and ensembles, such as GridSearch and VotingChainladder.
    • utils/: Internal helpers for sparse arrays, GPU (CuPy) shims, and Dask parallelization.
  4. Understand the chainladder-python Code of Conduct

    main

    The project is committed to an open, welcoming, and respectful community. Contributors and maintainers are expected to treat all individuals with respect, focus on project improvement, and provide constructive feedback.

    Unacceptable behaviors include:

    • Harassment, discrimination, or personal attacks.
    • Trolling or disruptive comments.
    • Sharing private information without permission.
    • Over-relying on AI/automated systems to shift the burden of validation or review onto others.
    • Attempting to sell services or work.
    • Any behavior creating a hostile environment.

    Violations can be reported to the Project Maintainers or the CAS.

  5. Understand the Triangle class structure and accessors

    main

    The Triangle class is the primary data structure in chainladder. It is built using a mixin-based architecture that provides a rich API for data manipulation.

    Instead of using inheritance for slicing, Triangle uses composition. When you create a Triangle instance, it holds internal instances of accessor classes. This allows you to use pandas-style indexing to slice the triangle or access virtual columns.

    Key accessors available on a Triangle instance:

    • .iloc: Integer-based indexing (e.g., triangle.iloc[0, :]).
    • .loc: Label-based indexing (e.g., triangle.loc['2023', 'Jan']).
    • .iat: Integer-based scalar access.
    • .at: Label-based scalar access.
    • .virtual_columns: Access to lazy-computed columns registered on the triangle.
    # Example of how accessors are used via composition
    triangle.iloc[0, :]
    triangle.loc['label', 'column']
    triangle.at['label', 'column']
  6. Technical decision making and voting processes

    main

    While community contributors are encouraged to discuss feedback, Project Maintainers have final authority over technical decisions. If maintainers disagree on a significant decision, they follow these protocols:

    Single-issue voting:

    • +1: approve
    • 0: abstain (must provide a supporting reason)
    • -1: disapprove (must provide a supporting reason)

    Choosing among multiple alternatives:

    • Ranked-choice voting is used to select from a list of options.

    If consensus cannot be reached, additional maintainers are brought in to resolve the disagreement, or maintainers may seek external input from the working group or the general public.

  7. AI Usage Policy for Contributors

    main

    AI-assisted development is permitted, but contributors must follow these rules:

    Requirements:

    • You must disclose AI/LLM usage in the PR description.
    • You must manually review and test all AI-generated code locally.
    • All external contributions and project interactions must be initiated by a human.

    Acceptable Uses:

    • Looking up language features.
    • Checking code snippets for syntax.
    • Using AI as a second pair of eyes for data/figures or a sounding board for design.
    • Checking written work for typos.

    Unacceptable Uses:

    • Submitting AI-generated code without full review/understanding.
    • Using AI to answer questions intended for project maintainers.
    • Failing to disclose AI usage in PRs.
  8. Release Lifecycle and Versioning

    main

    Chainladder follows semantic versioning (MAJOR.MINOR.PATCH):

    • MAJOR: Incompatible API changes.
    • MINOR: Backward-compatible functionality additions.
    • PATCH: Backward-compatible bug fixes.

    Deprecation Policy: Deprecated functionality must remain available for at least three months or one minor release, whichever is longer. Deprecations should emit clear warnings whenever practical.

    Release Platforms: Packages are published to GitHub, PyPI, and Conda.

  9. Development standards for APIs and documentation

    main

    The project follows established industry conventions to ensure consistency with the Python data science ecosystem:

    API Design

    • Triangle & Options APIs: Interfaces should closely align with the Pandas DataFrame API whenever appropriate.
    • Estimator APIs: Implementations should follow the Scikit-Learn estimator and transformer architecture.
    • Parameter Naming: Public parameter names should be intuitive and consistent with Pandas and Scikit-Learn conventions.

    Coding and Documentation

    • Linting: Code formatting and linting are enforced using Ruff.
    • Docstrings: Documentation must follow NumPy docstring conventions.
    • Examples: Documentation should include executable examples where appropriate and be updated whenever user-facing behavior changes.
  10. Understand the Triangle core data structure

    main

    The central abstraction in the chainladder library is the Triangle. It is the primary data structure used for actuarial loss development analysis. The Triangle class extends Pandas-like functionality to support specialized insurance development patterns.

    Key capabilities of the Triangle include:

    • Initialization: Creating triangles via base.py functionality.
    • Slicing: Using .loc and .iloc for label-based and integer-based indexing, as well as boolean indexing via slice.py.
    • Pandas-style Operations: Access to methods like .groupby() via pandas.py.
    • Specialized Actuarial Methods: Chainladder-specific logic (not found in standard Pandas) provided in triangle.py.
    • Arithmetic: Operator overloading for addition, subtraction, multiplication, and division via dunders.py.
    • Serialization: Saving and loading triangles using pickle and JSON via io.py.
    • Analysis: Performing Mack correlation tests via correlation.py.
  11. How Estimators follow the scikit-learn contract

    main

    All estimators in chainladder are designed to be compatible with the scikit-learn ecosystem. They follow the standard BaseEstimator / TransformerMixin pattern, implementing the following methods:

    • fit(): Trains the estimator on the provided data.
    • transform(): Applies the learned parameters to the data.
    • predict(): Generates predictions (for reserve methods).

    Estimators are categorized into several groups:

    1. Development Estimators: Used for Link Ratio Development (LDF) fitting (e.g., Development, ClarkLDF, TweedieGLM).
    2. Method Estimators: Implement the fit/predict contract for specific reserve methods (e.g., MackChainladder, BornhuetterFerguson).
    3. Standalone Transformers: Used for adjustments (e.g., BerquistSherman, Trend).
    4. Workflow Tools: Includes GridSearch and Pipeline (which extends sklearn.pipeline.Pipeline with EstimatorIO).