Skip to content

docs: add doctest examples for correlation classes#844

Open
priyam0k wants to merge 2 commits into
casact:mainfrom
priyam0k:docs/704-correlation-examples
Open

docs: add doctest examples for correlation classes#844
priyam0k wants to merge 2 commits into
casact:mainfrom
priyam0k:docs/704-correlation-examples

Conversation

@priyam0k
Copy link
Copy Markdown
Contributor

@priyam0k priyam0k commented May 25, 2026

Adds Sphinx doctest Examples sections to the DevelopmentCorrelation and ValuationCorrelation classes.

Refs #704 (Development Pattern Estimators → DevelopmentCorrelation and ValuationCorrelation rows).

Summary of Changes

  • Adds an Examples block to DevelopmentCorrelation in chainladder/core/correlation.py.
  • Adds an Examples block to ValuationCorrelation in the same file.
  • Each block opens with the Mack chain-ladder assumption being tested, then exercises the decision the user actually makes.

DevelopmentCorrelation example:

  • Runs on the RAA sample.
  • Prints t_expectation, both ends of confidence_interval, and the t_critical boolean — so the reader sees 0.0696 sitting inside (-0.1275, 0.1275) and understands why the test does not reject independence.

ValuationCorrelation example:

  • One testcode block for total=False (Mack 1997) printing the per-diagonal z_critical matrix.
  • A second testcode block for total=True (Mack 1993) printing the whole-triangle z and boolean (14.0, False).
  • One-line interpretation tying each result back to the chain-ladder workflow.

All numeric outputs use round(float(...), 4) (same pattern as #836) so the doctest is stable across numpy versions and array backends. Docstring-only; no runtime logic or public API changes.

Related GitHub Issue(s)

Additional Context for Reviewers

  • Doctest CI passed locally.

  • pytest chainladder/core/tests -x -q → no regressions.

  • Drafted against the four-point rubric @henrydingliu posted on API Reference Examples #704 / More robust PR template and contributing guidelines #827: each example opens with a practical chain-ladder assumption check, stays consistent with Mack 1993 / 1997, points to the existing Mack section of the user guide rather than duplicating it, and prints the full decision signal (statistic, confidence band, boolean) rather than a single boolean.

  • Intentionally excludes .github/workflows/sync-main-to-docs.yml, matching the split-PR convention from docs: add tail estimator doctest examples #801 and docs: add BootstrapODPSample doctest examples #836.

  • Happy to also embed a worked MackChainladder call inside the example if reviewers want the chain-ladder tie-in to be more concrete — left out here to keep the PR small.

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)


Note

Low Risk
Docstring and doctest narrative only; no executable code or API behavior changes.

Overview
Documentation only for ValuationCorrelation in correlation.py: the Sphinx Examples section is tightened so the opening text no longer mixes per-diagonal and whole-triangle modes in one sentence.

A short bridge paragraph now introduces the second doctest block, explaining that the same calendar-effect check can run as per-diagonal (total=False, Mack 1997) or whole-triangle (total=True, Mack 1993) before the existing total=True example that prints aggregated z and z_critical.

No changes to correlation logic, parameters, or public API—only how reviewers read the worked examples.

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

Adds Sphinx doctest Examples sections to DevelopmentCorrelation and ValuationCorrelation. Each example opens with the Mack chain-ladder assumption being tested, prints the full decision signal (statistic, confidence band, and boolean) rather than a single boolean, and ties the result back to the chain-ladder workflow.

Refs casact#704
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.94%. Comparing base (6ea3577) to head (3d827d9).
⚠️ Report is 221 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #844      +/-   ##
==========================================
+ Coverage   85.12%   86.94%   +1.81%     
==========================================
  Files          85       86       +1     
  Lines        4909     4994      +85     
  Branches      629      644      +15     
==========================================
+ Hits         4179     4342     +163     
+ Misses        521      462      -59     
+ Partials      209      190      -19     
Flag Coverage Δ
unittests 86.94% <ø> (+1.81%) ⬆️

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.

Comment thread chainladder/core/correlation.py Outdated
reserving practice). ``ValuationCorrelation`` flags any diagonal on
which the split of high versus low link ratios is unlikely under random
ordering, and can be evaluated per-diagonal (``total=False``, Mack 1997)
or for the whole triangle (``total=True``, Mack 1993).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can move this line between per-diagonal test and total test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, moving it between the two blocks so the intro stays scoped to the concept and the total=True form is introduced where it actually runs. Pushed as 3d827d9.

@henrydingliu
Copy link
Copy Markdown
Collaborator

thanks for putting this together. there's actually no longer any examples with developmentcorrelation in the doc. so this was much needed. just one small nitpick

Per @henrydingliu review on casact#844: opening paragraph now scoped to the calendar-effect concept; the per-diagonal vs whole-triangle distinction is introduced as a transition between the two testcode blocks.

Refs casact#704
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.

2 participants