Skip to content

DOCS: Add examples to deterministic IBNR methods (#704)#721

Open
EKtheSage wants to merge 1 commit intocasact:mainfrom
EKtheSage:docs/issue-704-deterministic-methods-examples
Open

DOCS: Add examples to deterministic IBNR methods (#704)#721
EKtheSage wants to merge 1 commit intocasact:mainfrom
EKtheSage:docs/issue-704-deterministic-methods-examples

Conversation

@EKtheSage
Copy link
Copy Markdown
Contributor

@EKtheSage EKtheSage commented Apr 26, 2026

What does this pull request do?

Addresses #704 for the deterministic IBNR estimator classes (the third tranche after #714 for the Triangle constructor and #719 for Triangle methods/properties).

Adds doctest-validated Examples blocks to the five deterministic estimator classes, matching the same Polars-style format established in #714 and #719: no import statements, ... continuation prefixes, strict output indentation, and byte-exact output with no NORMALIZE_WHITESPACE flag.

Coverage

File Blocks What was added
chainladder.py 3 Class docstring Examples, fit, predict
mack.py 8 Class Examples, fit, predict (full new docstring — none existed before), plus full docstrings for the five Mack-specific properties: full_std_err_, total_process_risk_, mack_std_err_, total_mack_std_err_, summary_
bornferg.py 3 Class Examples, fit, predict
benktander.py 3 Class Examples, fit, predict
capecod.py 3 Class Examples, fit, predict

Total: 20 doctest blocks.

Teaching points worth flagging

  • BornhuetterFerguson class docstring documents the canonical cl_ult * 0 + value idiom for constructing a flat per-origin apriori. sample_weight must be a chainladder Triangle, not a scalar; passing sample_weight=14000 raises AttributeError. New users hit this constantly.
  • Benktander class docstring shows side-by-side that n_iters=1 reproduces Bornhuetter-Ferguson and increasing n_iters pulls the ultimates toward the chainladder estimate.
  • CapeCod class docstring contrasts the role of sample_weight (exposure here, vs. apriori expected ultimate in BF/Benktander) and shows the effect of trend and decay on the derived apriori_.
  • MackChainladder.total_mack_std_err_ docstring notes that the across-origin total exceeds the quadrature sum of per-origin mack_std_err_ because parameter risk is correlated across origins (each origin uses the same estimated age-to-age factors).

Out of scope

Inherited methods from sklearn (get_params, set_params, get_metadata_routing, set_fit_request, set_predict_request) and from chainladder mixins (intersection, set_backend, to_json, to_pickle, plus the Common properties ibnr_, full_triangle_, full_expectation_, ldf_, latest_diagonal) are not documented here. The mixin methods are shared across many subclasses and warrant their own follow-up PR.

Validation

All 20 example blocks were executed with Python's doctest module in strict mode (no NORMALIZE_WHITESPACE flag) and pass with byte-exact output comparison.

Relevent Github ticket(s)?

Issue #704. Companion to PRs #714 (constructor) and #719 (Triangle methods/properties).


Note

Low Risk
Documentation-only changes that add doctest-validated examples to several actuarial estimators; primary risk is brittle doctest output expectations affecting CI, with no runtime logic changes.

Overview
Adds doctest-validated Examples documentation to the deterministic IBNR estimators Chainladder, BornhuetterFerguson, Benktander, and CapeCod, covering typical fit/predict workflows and key attributes like ultimate_, ibnr_, and apriori_.

Expands MackChainladder docs with new predict documentation and detailed example blocks for Mack-specific outputs (full_std_err_, total_process_risk_, mack_std_err_, total_mack_std_err_, summary_).

Reviewed by Cursor Bugbot for commit 37beb69. Bugbot is set up for automated code reviews on this repo. Configure here.

Adds doctest-validated Examples blocks to the five deterministic IBNR
estimator classes, matching the Polars-style format used in PRs casact#714
and casact#719: no imports, "..." continuation lines, strict output
indentation, and byte-exact output (no NORMALIZE_WHITESPACE).

Per-class coverage:

- Chainladder: class docstring, fit, predict
- MackChainladder: class docstring, fit, predict (predict had no
  docstring before this PR), and five property docstrings written from
  scratch: full_std_err_, total_process_risk_, mack_std_err_,
  total_mack_std_err_, summary_
- BornhuetterFerguson: class docstring, fit, predict. Class docstring
  notes the apriori-as-Triangle requirement (a literal int sample_weight
  raises AttributeError) and explains the canonical
  "cl_ult * 0 + value" broadcasting idiom for building a flat per-origin
  apriori
- Benktander: class docstring, fit, predict. Class docstring shows that
  n_iters interpolates between BF (n_iters=1) and chainladder (n_iters
  large)
- CapeCod: class docstring, fit, predict. Class docstring contrasts
  CapeCod with BF/Benktander (sample_weight is exposure, apriori is
  derived) and demonstrates the trend and decay parameters

All 20 example blocks validated with strict doctest.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.12%. Comparing base (6ea3577) to head (37beb69).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #721   +/-   ##
=======================================
  Coverage   85.12%   85.12%           
=======================================
  Files          85       85           
  Lines        4909     4909           
  Branches      629      629           
=======================================
  Hits         4179     4179           
  Misses        521      521           
  Partials      209      209           
Flag Coverage Δ
unittests 85.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant