cranalytics 0.3.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cranalytics-0.3.0 → cranalytics-0.3.1}/.gitignore +2 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/CHANGELOG.md +278 -0
- cranalytics-0.3.1/PKG-INFO +205 -0
- cranalytics-0.3.1/README.md +159 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/pyproject.toml +6 -5
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/README.md +3 -4
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/__init__.py +22 -3
- cranalytics-0.3.1/src/cranalytics/_check.py +493 -0
- cranalytics-0.3.1/src/cranalytics/_check_guidance.py +250 -0
- cranalytics-0.3.1/src/cranalytics/_cli_output.py +200 -0
- cranalytics-0.3.1/src/cranalytics/_cli_skills.py +402 -0
- cranalytics-0.3.1/src/cranalytics/_contract_helpers.py +206 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/_contract_issues.py +43 -1
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/_helpers.py +58 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/_quickstart_ui.py +2 -7
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/_version.py +1 -1
- cranalytics-0.3.1/src/cranalytics/_workflow_results.py +302 -0
- cranalytics-0.3.1/src/cranalytics/_workflow_validation.py +134 -0
- cranalytics-0.3.1/src/cranalytics/ax_spec.py +353 -0
- cranalytics-0.3.1/src/cranalytics/cli.py +1511 -0
- cranalytics-0.3.1/src/cranalytics/contracts.py +106 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/data_shapes.py +6 -5
- cranalytics-0.3.1/src/cranalytics/distributions.py +31 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_survival.py +56 -52
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/fpf_workflow.py +10 -2
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/feature_analytics/__init__.py +12 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/feature_analytics/_early_performance.py +288 -35
- cranalytics-0.3.0/src/cranalytics/fpf_workflow.py → cranalytics-0.3.1/src/cranalytics/feature_analytics/_fpf.py +61 -6
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/feature_analytics/_score_monitoring.py +119 -2
- cranalytics-0.3.1/src/cranalytics/fpf_workflow.py +31 -0
- cranalytics-0.3.1/src/cranalytics/governance_models.py +36 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loan_tape/__init__.py +38 -6
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loan_tape/_contract.py +107 -48
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loan_tape/_history.py +24 -28
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loan_tape/_snapshot.py +0 -55
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loss_forecasting.py +246 -83
- cranalytics-0.3.1/src/cranalytics/method_selection.py +39 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/onboarding.py +74 -11
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/portfolio.py +45 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/predictive/__init__.py +6 -1
- cranalytics-0.3.1/src/cranalytics/predictive/_backtest.py +474 -0
- cranalytics-0.3.1/src/cranalytics/predictive/_contract.py +410 -0
- cranalytics-0.3.1/src/cranalytics/predictive/_forecasting_bridge.py +368 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/predictive/_modeling.py +22 -0
- cranalytics-0.3.1/src/cranalytics/predictive/_session.py +215 -0
- cranalytics-0.3.1/src/cranalytics/predictive/_targets.py +370 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/quickstart.py +76 -19
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/reserve.py +17 -5
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/__init__.py +63 -62
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_contract.py +9 -9
- cranalytics-0.3.0/src/cranalytics/governance_models.py → cranalytics-0.3.1/src/cranalytics/rollforward/_governance.py +5 -9
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_reporting.py +1 -1
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_results.py +341 -97
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/simulation.py +67 -3
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/loss-forecasting/SKILL.md +38 -75
- cranalytics-0.3.1/src/cranalytics/skills/loss-forecasting/references/model-selection-guide.md +78 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/portfolio-diagnostics/SKILL.md +31 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/predictive-credit-modeling/SKILL.md +79 -28
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/predictive-credit-modeling/references/early-performance-guide.md +25 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/predictive-credit-modeling/references/score-monitoring-guide.md +17 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/vintage-loss-curves/SKILL.md +41 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/survival/__init__.py +4 -0
- cranalytics-0.3.1/src/cranalytics/survival/_core.py +1061 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/survival/_session.py +64 -17
- cranalytics-0.3.1/src/cranalytics/survival/_validation.py +691 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/survival_flows.py +28 -4
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/__init__.py +20 -5
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/_dispatch.py +20 -2
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/_flow.py +97 -5
- cranalytics-0.3.1/src/cranalytics/validation/_forecast_bridge.py +83 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/_loan.py +85 -2
- cranalytics-0.3.1/src/cranalytics/validation/_target_panel.py +71 -0
- cranalytics-0.3.1/src/cranalytics/validation/_transition_history.py +85 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/_vintage.py +12 -5
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/__init__.py +16 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_contract.py +37 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_fitting.py +64 -14
- cranalytics-0.3.0/src/cranalytics/method_selection.py → cranalytics-0.3.1/src/cranalytics/vintage/_selection.py +4 -3
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_session.py +71 -3
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/viz/__init__.py +40 -2
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/viz/_early_performance.py +212 -21
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/viz/_heatmaps.py +13 -5
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/viz/_reserve.py +9 -7
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/viz/_smoothing.py +32 -16
- cranalytics-0.3.1/src/cranalytics/viz/_theme.py +492 -0
- cranalytics-0.3.0/PKG-INFO +0 -507
- cranalytics-0.3.0/README.md +0 -461
- cranalytics-0.3.0/src/cranalytics/_check.py +0 -176
- cranalytics-0.3.0/src/cranalytics/_contract_helpers.py +0 -53
- cranalytics-0.3.0/src/cranalytics/_quickstart_demos.py +0 -485
- cranalytics-0.3.0/src/cranalytics/_workflow_results.py +0 -73
- cranalytics-0.3.0/src/cranalytics/cli.py +0 -1081
- cranalytics-0.3.0/src/cranalytics/predictive/_backtest.py +0 -183
- cranalytics-0.3.0/src/cranalytics/predictive/_contract.py +0 -192
- cranalytics-0.3.0/src/cranalytics/predictive/_forecasting_bridge.py +0 -250
- cranalytics-0.3.0/src/cranalytics/predictive/_session.py +0 -106
- cranalytics-0.3.0/src/cranalytics/predictive/_targets.py +0 -278
- cranalytics-0.3.0/src/cranalytics/survival/_core.py +0 -349
- {cranalytics-0.3.0 → cranalytics-0.3.1}/LICENSE +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/__main__.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/_loan_states.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/datasets.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/__init__.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_feature_analytics.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_lifetime_loss.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_ml_modeling.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_rollforward.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_segmentation.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_simulation.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/examples/core_vintage.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/feature_analytics/_model_development.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/finance.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/loan_tape/_normalization.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/metrics.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/py.typed +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_backtest.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_evaluation.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_readiness_session.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_session.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_splitting.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/rollforward/_variants.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/loss-forecasting/agents/openai.yaml +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/loss-forecasting/references/flow-hazard-guide.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/loss-forecasting/references/stress-scenario-guide.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/loss-forecasting/references/transition-matrix-guide.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/portfolio-diagnostics/agents/openai.yaml +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/portfolio-diagnostics/references/lgd-methodology.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/predictive-credit-modeling/agents/openai.yaml +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/predictive-credit-modeling/references/model-training-guide.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/vintage-loss-curves/agents/openai.yaml +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/vintage-loss-curves/references/methodology.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/vintage-loss-curves/references/smoother-guide.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/skills/vintage-loss-curves/references/validation-api.md +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/validation/_core.py +0 -0
- /cranalytics-0.3.0/src/cranalytics/distributions.py → /cranalytics-0.3.1/src/cranalytics/vintage/_distributions.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_smoothing.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_transforms.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_validation.py +0 -0
- {cranalytics-0.3.0 → cranalytics-0.3.1}/src/cranalytics/vintage/_wide.py +0 -0
|
@@ -7,6 +7,284 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.1] - 2026-11-27
|
|
11
|
+
|
|
12
|
+
Released as a patch: no public name or argument from 0.3.0 is removed. The APIs
|
|
13
|
+
renamed or moved since 0.3.0 now warn instead of failing, and go away in 0.4.0.
|
|
14
|
+
Scripts that test for exit code 1 specifically should read the exit-code entries
|
|
15
|
+
under Changed. This release also includes the 0.3.1 fixes dated 2026-10-02,
|
|
16
|
+
which were never published.
|
|
17
|
+
|
|
18
|
+
### Deprecated
|
|
19
|
+
- **`ReadinessRunResult.summary` as a dict.** In 0.3.0 `summary` was the readiness
|
|
20
|
+
scoring dict; it is now a method returning a one-row DataFrame, and the dict is
|
|
21
|
+
`result.report`. Until 0.4.0, `result.summary["key"]`, `.get()`, `in`,
|
|
22
|
+
iteration and `dict(result.summary)` keep working and raise a
|
|
23
|
+
`DeprecationWarning`; calling `result.summary()` does not warn.
|
|
24
|
+
- **`cranalytics rollforward check`.** Use `cranalytics rollforward readiness`,
|
|
25
|
+
which takes the same arguments. Until 0.4.0 the old spelling still runs
|
|
26
|
+
readiness: it prints a warning on stderr, or adds a `deprecation` field to the
|
|
27
|
+
`--json` output. It is left out of `--help`.
|
|
28
|
+
- **`build_targets_from_loan_history` and `loan_snapshot_to_survival_data` from
|
|
29
|
+
`cranalytics.loan_tape`.** Import them from `cranalytics.predictive` and
|
|
30
|
+
`cranalytics.survival`. Until 0.4.0 the old imports still work and raise a
|
|
31
|
+
`DeprecationWarning`. They are no longer listed in `cranalytics.loan_tape.__all__`.
|
|
32
|
+
- **`cranalytics.governance_models`.** The governance metadata models moved into
|
|
33
|
+
the rollforward package. Until 0.4.0 importing the old module still works,
|
|
34
|
+
re-exports the same classes and functions, and raises a `DeprecationWarning`.
|
|
35
|
+
- **`cranalytics.contracts`.** The unused Pydantic contract models are
|
|
36
|
+
deprecated and removed in 0.4.0, and no longer rendered in `llms.txt`.
|
|
37
|
+
- **`cranalytics.distributions`, `cranalytics.method_selection`, and
|
|
38
|
+
`cranalytics.fpf_workflow`.** Folded into their owning subpackages
|
|
39
|
+
(`cranalytics.vintage._distributions`, `cranalytics.vintage`, and
|
|
40
|
+
`cranalytics.feature_analytics`). Until 0.4.0 the old modules still work with
|
|
41
|
+
a `DeprecationWarning`.
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
- **`cranalytics.simulation.run` and `cranalytics.portfolio.run`** return
|
|
45
|
+
workflow results for portfolio simulation (`SimulationResult`: horizon totals,
|
|
46
|
+
cashflows, balance by state, chart) and FICO segmentation
|
|
47
|
+
(`SegmentationResult`: band mix, segmented loans, risk grades, balance by
|
|
48
|
+
band). `simulation.run` also accepts a plain transition matrix.
|
|
49
|
+
- **`cranalytics.loss_forecasting.run`** returns a lifetime loss workflow result
|
|
50
|
+
(`LifetimeLossResult`): the reserve summary, losses by status and by loan, the
|
|
51
|
+
transition matrix used, the assumptions, and a chart. It takes the same inputs
|
|
52
|
+
as `forecast_lifetime_loss` and agrees with `summarize_lifetime_loss`.
|
|
53
|
+
- `plot_odds_ratio_chart` in `cranalytics.viz`: a log-scale forest plot of
|
|
54
|
+
per-bin odds ratios with Woolf confidence intervals, built from the
|
|
55
|
+
`compute_woe_iv` table.
|
|
56
|
+
- **One result shape for the vintage, ML modeling, survival and rollforward
|
|
57
|
+
workflows.** Every result now has `tables()` (named DataFrames),
|
|
58
|
+
`assumptions()` (workflow, version and the parameters used) and `to_dict()`
|
|
59
|
+
(JSON-safe; the summary in full, other tables capped at 200 rows with a
|
|
60
|
+
`truncated` flag), plus a notebook HTML display of `summary()`. See
|
|
61
|
+
`docs/adr/0001-every-workflow-returns-a-workflow-result.md`.
|
|
62
|
+
- `check()` accepts CLI workflow names such as `lifetime-loss`, `simulation`,
|
|
63
|
+
`survival` and `ml-modeling`, using the existing onboarding registry to select
|
|
64
|
+
their base contract. Reports retain the contract name in `workflow`; model
|
|
65
|
+
roles, transition inputs and event mappings still require workflow validation.
|
|
66
|
+
- Publishing verifies README examples, the non-interactive quickstart and all
|
|
67
|
+
registered demos from the installed wheel, outside the source checkout.
|
|
68
|
+
The data guide now distinguishes source tapes, modeling frames, long vintage
|
|
69
|
+
observations and wide triangles, with runnable examples.
|
|
70
|
+
- **Segment rates now say how far to trust each slice.**
|
|
71
|
+
`compute_segment_rates` adds `vs_portfolio` (`higher`, `lower` or `unclear`,
|
|
72
|
+
from whether the segment's confidence interval clears the portfolio rate) and
|
|
73
|
+
`reliability` (`low`, `medium` or `high`, from the number of loans with an
|
|
74
|
+
event; tune with `reliability_thresholds=`), plus an `n_event_loans` count.
|
|
75
|
+
Pass `adjusted=True` for a `rate_adjusted` column that pulls thin segments
|
|
76
|
+
toward the portfolio average (empirical-Bayes beta-binomial), for ranking
|
|
77
|
+
segments of very different sizes. Existing columns are unchanged.
|
|
78
|
+
`viz.plot_segment_rates` now draws confidence intervals, a portfolio-rate
|
|
79
|
+
reference line, and fades low-reliability segments.
|
|
80
|
+
- **Charge-off (or any event) probability by a horizon, per segment:**
|
|
81
|
+
`cranalytics.survival.estimate_event_probability(df, horizon=12,
|
|
82
|
+
group_by=...)` uses Kaplan-Meier so loans not yet at the horizon still count,
|
|
83
|
+
and returns `event_prob` with a confidence interval, `vs_portfolio`,
|
|
84
|
+
`reliability`, `n_reached_horizon`, `horizon_observed` and `method`. With
|
|
85
|
+
competing outcomes (e.g. payoff coded 2) it uses Aalen-Johansen cumulative
|
|
86
|
+
incidence instead of Kaplan-Meier. Inputs are validated with the new
|
|
87
|
+
`cranalytics.validation.make_survival_event_schema`.
|
|
88
|
+
- **The A/E table speaks plainly too.** `compute_actual_vs_expected` adds
|
|
89
|
+
`actual_ci_lower`/`actual_ci_upper`, `ae_ci_lower`/`ae_ci_upper`,
|
|
90
|
+
`vs_expected` (`worse`, `better` or `in line`, following the
|
|
91
|
+
segment-count-corrected `significant` flag), `reliability` and
|
|
92
|
+
`n_event_loans`. `viz.plot_actual_vs_expected` draws the actual-rate
|
|
93
|
+
intervals and fades low-reliability segments.
|
|
94
|
+
- `calculate_early_performance_rates` adds `n_event_loans` and `reliability`.
|
|
95
|
+
`viz.plot_vintage_trend` draws low-reliability vintages as hollow markers.
|
|
96
|
+
The FPF workflow report lists segments higher or lower than the portfolio
|
|
97
|
+
and how many segments are confidently worse than expected.
|
|
98
|
+
- **The CLI is now safe for agents and scripts.** Every command accepts `--json`
|
|
99
|
+
and then writes exactly one JSON object to stdout; errors become one JSON object on stderr with `error`, `message`,
|
|
100
|
+
`exit_code` and, where useful, a `hint`. Any input path accepts `-` to read
|
|
101
|
+
CSV from stdin (`cat loans.csv | cranalytics vintage run - --json`).
|
|
102
|
+
Usage errors such as an unknown flag follow `--json` too, `demo <name>
|
|
103
|
+
--json` returns the walkthrough as text in the result, and
|
|
104
|
+
`<workflow> check --show-schema --json` includes the contract as `schema`.
|
|
105
|
+
`cranalytics --help` now documents the output contract and exit codes, and
|
|
106
|
+
every `vintage run` flag has help text.
|
|
107
|
+
- **`cranalytics quickstart --json`** writes one JSON object that indexes every
|
|
108
|
+
workflow: its slug, the question it answers, the columns its `check`
|
|
109
|
+
validates, its Python entry point (null where there is none), its CLI actions,
|
|
110
|
+
its demo and whether a starter template exists. It is built from the workflow
|
|
111
|
+
registry and never opens the menu. Combined with `--workflow`,
|
|
112
|
+
`--show-requirements` or `--write-template` it is a usage error (exit 2).
|
|
113
|
+
- **`check` says what is wrong and what to do next.** A failed check names each
|
|
114
|
+
missing required column (with `column` set to that name in the JSON issues)
|
|
115
|
+
and suggests the closest column in the file, so a header such as `Loan ID` is
|
|
116
|
+
pointed at `loan_id`. Checks that depend on a missing column are skipped, so
|
|
117
|
+
the spurious "start_date cannot be in the future" line is gone. A file that
|
|
118
|
+
matches no workflow gets a report that explains itself, and `CheckReport` has a
|
|
119
|
+
short readable `repr`. A passing check ends with the exact next step (a CLI
|
|
120
|
+
command or a Python call that runs as written, including `segment_col` and
|
|
121
|
+
timezone-aware dates) and what the check did not cover. The JSON gains
|
|
122
|
+
`missing_columns`, `suggestions`, `message`, `next_step`, `not_covered` and
|
|
123
|
+
`candidate_contracts`; no existing field changes.
|
|
124
|
+
- **`llms.txt` describes the package as it is, and cannot drift.** It lists the
|
|
125
|
+
eight workflows with their Python entry points, CLI actions and required
|
|
126
|
+
columns, the shared result surface and the CLI output contract. It is
|
|
127
|
+
generated by `cranalytics-ax-spec`, and `cranalytics-ax-spec --check llms.txt`,
|
|
128
|
+
a test and `scripts/ci/check_static.py` fail when the committed file differs.
|
|
129
|
+
- **Direct segment-vs-segment comparison (`cranalytics.feature_analytics.compare_segments`).**
|
|
130
|
+
Compares event rates between two segments using the Newcombe hybrid score
|
|
131
|
+
interval (built from the two Wilson intervals, using effective sample size
|
|
132
|
+
when weighted), returning `rate_a`, `rate_b`, `difference`, `diff_ci_lower`,
|
|
133
|
+
`diff_ci_upper`, `ratio`, `verdict` (`"A is higher"` / `"A is lower"` /
|
|
134
|
+
`"unclear"`), and `reliability_a` / `reliability_b`.
|
|
135
|
+
- **Opt-in multiple-comparison control on `vs_portfolio`.**
|
|
136
|
+
`feature_analytics.compute_segment_rates` and
|
|
137
|
+
`survival.estimate_event_probability` accept
|
|
138
|
+
`adjust_for_multiple_segments=True` for Bonferroni-adjusted `vs_portfolio`
|
|
139
|
+
labels while keeping displayed `ci_lower`/`ci_upper` at nominal confidence,
|
|
140
|
+
and warn when more than 20 segments are tested unadjusted.
|
|
141
|
+
- **Architecture & workflow guide (`docs/explanation/architecture_and_workflows.md`).**
|
|
142
|
+
Documents how all eight credit-risk lenses share the `check()` → `run()` →
|
|
143
|
+
`WorkflowResult` loop, the three-layer one-way package boundaries, and
|
|
144
|
+
one-line chart theming; MkDocs navigation now aligns with `README.md` and
|
|
145
|
+
registers ADR 0001.
|
|
146
|
+
|
|
147
|
+
### Changed
|
|
148
|
+
- **Unified rollforward result surface (`RollforwardResult`).** Rollforward
|
|
149
|
+
workflow and readiness results now own their `.tables()` and `.plot()`
|
|
150
|
+
in memory (surviving `output_dir` deletion), `output_dir` is optional on
|
|
151
|
+
`Rollforward.readiness()`, and `RollforwardWorkflowResult` is an alias for
|
|
152
|
+
`RollforwardResult`.
|
|
153
|
+
- **Shared survival input contract.** `check(..., workflow="survival")` and
|
|
154
|
+
`survival.run()` now share one input contract in
|
|
155
|
+
`cranalytics.survival._validation`, and `SurvivalAnalysisResult` exposes
|
|
156
|
+
non-fatal warnings via `validation_issues`.
|
|
157
|
+
- **`ReadinessRunResult.summary` is now `report`.** `result.summary()` is a method
|
|
158
|
+
returning the scalar readiness entries as a one-row DataFrame, like every other
|
|
159
|
+
workflow result. Read the full scoring dict from `result.report`. Reading
|
|
160
|
+
`result.summary` as a dict still works until 0.4.0, with a `DeprecationWarning`.
|
|
161
|
+
- **`cranalytics rollforward check` is now `cranalytics rollforward readiness`.**
|
|
162
|
+
Every other `<workflow> check` is a quick pass or fail on columns; this command scores
|
|
163
|
+
readiness and writes a report directory, so it now has its own name. Rollforward is also
|
|
164
|
+
listed as an advanced workflow, and its quickstart entry, first win and docs describe the
|
|
165
|
+
payment and charge-off forecast, with readiness as the step before it. The old
|
|
166
|
+
`rollforward check` spelling still runs readiness until 0.4.0, with a deprecation
|
|
167
|
+
note.
|
|
168
|
+
- **CLI exit codes are now consistent:** 0 success, 1 input or validation
|
|
169
|
+
failure, 2 usage error, 3 unexpected internal error. Unexpected errors used to
|
|
170
|
+
exit 1 (or print a traceback); they now exit 3. An unknown `--skill` name on
|
|
171
|
+
install now exits 2, matching `--describe`.
|
|
172
|
+
- **The CLI never blocks on a prompt without a terminal.** `cranalytics
|
|
173
|
+
quickstart` with no flags prints the workflow list and the non-interactive
|
|
174
|
+
commands instead of waiting on the menu. `install-skills` with no skills
|
|
175
|
+
directory exits 2 and asks for `--yes` instead of prompting.
|
|
176
|
+
- **The `rollforward` tier banner moved to stderr**, so stdout holds only
|
|
177
|
+
results.
|
|
178
|
+
- **The remaining CLI exit codes follow the contract.** `quickstart
|
|
179
|
+
--workflow <unknown>` and a malformed `--competing-status` now exit 2 (usage),
|
|
180
|
+
and a `quickstart` crash exits 3. Numeric failures caused by the data
|
|
181
|
+
(overflow, division by zero) and bad values found during `check` exit 1
|
|
182
|
+
instead of 3. `demo` usage errors now point to `cranalytics demo --help`.
|
|
183
|
+
- **README trimmed for PyPI** (461 → 159 lines). It now covers what the package
|
|
184
|
+
does, how to install it (with the `ml` / `xgboost` / `lightgbm` extras), the
|
|
185
|
+
quickstart, three runnable examples, the bundled Claude skills and doc links.
|
|
186
|
+
Install troubleshooting, the rollforward Python-API example and the links to
|
|
187
|
+
the repository's larger examples moved to `docs/getting_started.md`. The
|
|
188
|
+
getting-started page now recommends the extras instead of installing
|
|
189
|
+
backends directly. New `tests/test_readme.py` runs every README Python example
|
|
190
|
+
and rejects relative links, which PyPI cannot resolve.
|
|
191
|
+
- **Loan tape validation reports problems instead of raising.**
|
|
192
|
+
`validate_loan_tape` returns a critical `MISSING_COLUMN` issue per missing
|
|
193
|
+
required column (naming the accepted aliases and the columns found) where it
|
|
194
|
+
used to raise `KeyError`; `normalize_loan_snapshot` and `normalize_loan_history`
|
|
195
|
+
raise `ValueError` with the same text, so code that caught `KeyError` needs
|
|
196
|
+
updating. `segment_fico` and `portfolio.run` raise a `ValueError` naming the
|
|
197
|
+
missing score column. Pandera failures become one readable issue per failed
|
|
198
|
+
check, and an `annual_rate` given as percentages (every value between 1 and
|
|
199
|
+
100) gets a divide-by-100 hint without being converted. Header matching now
|
|
200
|
+
ignores case, whitespace and separators (`Loan ID`, `loan-id`, `LoanID`); the
|
|
201
|
+
result has a `column_mapping`, a header that matched only that way adds an
|
|
202
|
+
`info` `COLUMN_MAPPED` row, and two headers that match the same name give a
|
|
203
|
+
critical `AMBIGUOUS_COLUMNS` issue instead of crashing. An exact canonical
|
|
204
|
+
column always wins over alias headers, which stay as extra columns.
|
|
205
|
+
- **The bundled skills start with `check` and the workflow `run` functions.**
|
|
206
|
+
Each of `vintage-loss-curves`, `loss-forecasting`, `portfolio-diagnostics`
|
|
207
|
+
and `predictive-credit-modeling` has a short "Quick Path: Check, Then Run"
|
|
208
|
+
section; the helper-function steps remain for custom work.
|
|
209
|
+
- **`dir(cranalytics)` lists only public names**: `__all__` plus the workflow
|
|
210
|
+
submodules. `Any`, `annotations`, `import_module`, `onboarding` and the
|
|
211
|
+
dunders are no longer listed; attribute access is unchanged.
|
|
212
|
+
|
|
213
|
+
### Fixed
|
|
214
|
+
- **`viz.apply_theme` and `viz.theme_context` keep Matplotlib `rcParams` and
|
|
215
|
+
the active semantic palette in sync** (and restore both cleanly on exit).
|
|
216
|
+
- **Closed `check()` ↔ `run()` validation gaps** for `ml-modeling` (structured
|
|
217
|
+
`NON_NUMERIC_TARGET` code, reserved `split_col`/`loan_id` feature guards,
|
|
218
|
+
null/duplicate `loan_id`) and `survival` (normalized date-role `group_col`).
|
|
219
|
+
- **Hardened flow, loan-history, segment-rate, and low-level survival
|
|
220
|
+
validation.** Rejected null/blank `segment_id` before string conversion,
|
|
221
|
+
`max_month` preceding the earliest observed `month_on_book`, and non-finite
|
|
222
|
+
`amtloan`; aligned `forecast_balance_flows(..., overflow_policy="scale" |
|
|
223
|
+
"warn")` with curve validation; wired Pandera duration/event validation into
|
|
224
|
+
low-level `cranalytics.survival` primitives (`fit_kaplan_meier`,
|
|
225
|
+
`compare_kaplan_meier_cohorts`, `plot_kaplan_meier_cohorts`, `fit_cox_ph`,
|
|
226
|
+
`fit_competing_risks`, `calculate_c_index`).
|
|
227
|
+
- `viz.place_legend` accepts caller overrides for placement and frame options;
|
|
228
|
+
`plot_odds_ratio_chart` follows the selected palette for markers and reference
|
|
229
|
+
lines. The CLI reference consistently names `rollforward readiness`.
|
|
230
|
+
- Simulation workflow assumptions preserve the annual CPR scalar or the list
|
|
231
|
+
of period-by-period rates used, rather than replacing every Series with
|
|
232
|
+
`"vector"`.
|
|
233
|
+
- Corrected the Pandera dependency minimum to 0.24.0, which provides the
|
|
234
|
+
`pandera.pandas` API imported by the package.
|
|
235
|
+
- **`vintage run` accepts the quickstart vintage template.** `check` accepts the
|
|
236
|
+
contract names `vintage_name` and `mob`, but `run` defaulted to `vintage_date`
|
|
237
|
+
and `months_on_book` and failed on the same file. `vintage.run()` and
|
|
238
|
+
`cranalytics vintage run` now use the contract names when the default column
|
|
239
|
+
is absent and the contract column is present, and report it in
|
|
240
|
+
`assumptions()["column_fallbacks"]`, as a note on stderr and as `notes` in
|
|
241
|
+
`--json`. Explicit `vintage_col=` / `mob_col=` and frames that have the default
|
|
242
|
+
columns behave as before.
|
|
243
|
+
- **`CurveFitter` rejects mistakes early.** An unknown `method` raises a
|
|
244
|
+
`ValueError` at construction that lists the valid methods and suggests the
|
|
245
|
+
closest one, and `fit` raises when given fewer observations than the method
|
|
246
|
+
has parameters (3, or 4 for Burr); a two-point Weibull fit used to "succeed"
|
|
247
|
+
with a meaningless ultimate loss.
|
|
248
|
+
- **Survival no longer invents event dates.** A row with a known event status
|
|
249
|
+
(default or competing) and a missing end date used to get `current_date` as its
|
|
250
|
+
event time. `calculate_duration_and_event` now raises in strict mode and
|
|
251
|
+
otherwise warns and drops the row, and `survival.run` applies that to one
|
|
252
|
+
common cohort for Kaplan-Meier, Cox and Aalen-Johansen. Competing event codes
|
|
253
|
+
must be integers of at least 2, and default and competing statuses must not
|
|
254
|
+
overlap. Tied competing events are now grouped at their observed month in
|
|
255
|
+
`fit_competing_risks` (three tied defaults among ten loans read 0.3, not 0.1),
|
|
256
|
+
and Cox concordance is scored on the rows used for the fit.
|
|
257
|
+
- **Flow forecasts start from the balance left after the last observed month.**
|
|
258
|
+
`forecast_balance_flows` and rollforward holdout forecasts subtract the last
|
|
259
|
+
month's payments and charge-offs from its opening `outstanding_balance`, per the
|
|
260
|
+
beginning-of-period contract. Flow validation rejects infinite amounts or
|
|
261
|
+
balances, and unsorted hazard curves are sorted before interpolation.
|
|
262
|
+
- **`fit_competing_risks` handles censored loans tied with events.** Tie-breaking
|
|
263
|
+
used to remove loans censored at the same time as events from the risk set too
|
|
264
|
+
early, overstating cumulative incidence (2 charge-offs among 10 at risk read as
|
|
265
|
+
25%, not 20%). Censored rows now stay at risk through every tied event.
|
|
266
|
+
- **`compute_actual_vs_expected` no longer calls a segment "in line" when its
|
|
267
|
+
expected rate is exactly 0 or 1 and the actual rate differs.** `z_score` is now
|
|
268
|
+
±inf in that case (so `significant` is True) instead of 0.
|
|
269
|
+
- **`compute_actual_vs_expected` no longer tests segments whose expected values
|
|
270
|
+
are not probabilities.** If any loan's expected rate falls outside [0, 1] (raw
|
|
271
|
+
scores without a `calibration_table`), the segment gets `z_score=0` and
|
|
272
|
+
`in line`, and a warning names how many segments were skipped. Previously,
|
|
273
|
+
out-of-range scores that happened to average inside [0, 1] were z-tested as if
|
|
274
|
+
they were probabilities.
|
|
275
|
+
- **`CurveFitter` could stop at a poor local optimum** and misstate the ultimate
|
|
276
|
+
loss. On a vintage that levels off at 5.3%, the default Weibull fit reported
|
|
277
|
+
11.7% (squared error about 100× the true optimum), because L-BFGS-B stopped
|
|
278
|
+
near its initial guess. `fit()` now also runs a trust-region least-squares fit
|
|
279
|
+
(`scipy.optimize.least_squares`) from the same start, and keeps whichever
|
|
280
|
+
candidate has the lower weighted squared error. A fit is never worse than
|
|
281
|
+
before, and often much better: on 200 synthetic vintages the error dropped by
|
|
282
|
+
more than 2× in about half the Weibull fits and about a third of the lognormal
|
|
283
|
+
and Burr fits. **Fitted parameters, ultimates and forecasts can change**, and
|
|
284
|
+
backtest champion selection (`method_selection`) may pick differently.
|
|
285
|
+
Fitting takes about 2–3× longer. `converged` is now False only when both
|
|
286
|
+
solvers fail.
|
|
287
|
+
|
|
10
288
|
## [0.3.0] - 2026-09-28
|
|
11
289
|
|
|
12
290
|
Breaking release. Upgrade notes are in the **Breaking** entries below. In short:
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: cranalytics
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Core credit risk analytics engine with vintage forecasting, FICO segmentation, and portfolio modeling
|
|
5
|
+
Project-URL: Homepage, https://cranalytics.vercel.app/
|
|
6
|
+
Project-URL: Documentation, https://cranalytics.vercel.app/
|
|
7
|
+
Project-URL: Repository, https://github.com/ClaySheffler/cranalytics
|
|
8
|
+
Project-URL: Issues, https://github.com/ClaySheffler/cranalytics/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ClaySheffler/cranalytics/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: CI, https://github.com/ClaySheffler/cranalytics/actions/workflows/ci.yml
|
|
11
|
+
Author-email: Clay Sheffler <clay.sheffler@gmail.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: FICO segmentation,credit risk,forecasting,portfolio modeling,vintage analysis
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: lifelines
|
|
26
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
27
|
+
Requires-Dist: numpy-financial
|
|
28
|
+
Requires-Dist: numpy>=1.24.4
|
|
29
|
+
Requires-Dist: pandas>=2.1.1
|
|
30
|
+
Requires-Dist: pandera>=0.24.0
|
|
31
|
+
Requires-Dist: plotly>=5.0.0
|
|
32
|
+
Requires-Dist: pooch>=1.9.0
|
|
33
|
+
Requires-Dist: pyarrow>=23.0.1
|
|
34
|
+
Requires-Dist: pydantic>=2
|
|
35
|
+
Requires-Dist: scikit-learn
|
|
36
|
+
Requires-Dist: scipy
|
|
37
|
+
Requires-Dist: seaborn>=0.12.0
|
|
38
|
+
Requires-Dist: statsmodels
|
|
39
|
+
Provides-Extra: lightgbm
|
|
40
|
+
Requires-Dist: lightgbm>=4.0; extra == 'lightgbm'
|
|
41
|
+
Provides-Extra: ml
|
|
42
|
+
Requires-Dist: optbinning>=0.19.0; extra == 'ml'
|
|
43
|
+
Provides-Extra: xgboost
|
|
44
|
+
Requires-Dist: xgboost>=1.7.0; extra == 'xgboost'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
# cranalytics - Credit Risk Analytics
|
|
48
|
+
|
|
49
|
+
[](https://pypi.org/project/cranalytics/)
|
|
50
|
+
[](https://pypi.org/project/cranalytics/)
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+
|
|
53
|
+
DataFrame-first credit risk analytics for consumer lending portfolios.
|
|
54
|
+
|
|
55
|
+
| Workflow | Module | What it answers |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| Vintage curve fitting | `cranalytics.vintage` | Where will each vintage's cumulative loss land? |
|
|
58
|
+
| Lifetime loss forecasting | `cranalytics.loss_forecasting` | What lifetime loss does the current book imply? |
|
|
59
|
+
| FICO segmentation | `cranalytics.portfolio` | How is risk distributed across the book? |
|
|
60
|
+
| Feature analytics | `cranalytics.feature_analytics` | Which features separate good and bad loans? |
|
|
61
|
+
| ML modeling *(advanced)* | `cranalytics.predictive` | Which loans will hit a performance flag? |
|
|
62
|
+
| Survival analysis *(advanced)* | `cranalytics.survival` | When do loans default or prepay? |
|
|
63
|
+
| Portfolio simulation *(advanced)* | `cranalytics.simulation` | How do cashflows and losses evolve month by month? |
|
|
64
|
+
| Rollforward | `cranalytics.rollforward` | Monthly payment and charge-off forecasts and readiness diagnostics from aggregated data |
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install cranalytics
|
|
70
|
+
# or: uv add cranalytics
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Python 3.10+ is supported. Visualization and survival analysis are included in
|
|
74
|
+
the base install. Optional modeling backends are extras:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install "cranalytics[ml]" # optbinning: optimal WoE binning
|
|
78
|
+
pip install "cranalytics[xgboost]" # xgboost model families
|
|
79
|
+
pip install "cranalytics[lightgbm]" # lightgbm challenger models
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Install problems with compiled dependencies? See
|
|
83
|
+
[install troubleshooting](https://cranalytics.vercel.app/getting_started/#install-troubleshooting).
|
|
84
|
+
|
|
85
|
+
## Quickstart
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
cranalytics quickstart
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Pick a workflow from the menu. Each runs in under 30 seconds on synthetic data
|
|
92
|
+
and ends with the data shape you need to run it on your own portfolio. To jump
|
|
93
|
+
straight to one workflow:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
cranalytics demo --list
|
|
97
|
+
cranalytics demo lifetime-loss
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
### Validate your data
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import pandas as pd
|
|
106
|
+
import cranalytics as ca
|
|
107
|
+
|
|
108
|
+
df = pd.DataFrame({
|
|
109
|
+
"loan_id": ["L101", "L102"],
|
|
110
|
+
"principal": [10000, 15000],
|
|
111
|
+
"annual_rate": [0.08, 0.10],
|
|
112
|
+
"term_months": [36, 36],
|
|
113
|
+
"start_date": pd.to_datetime(["2024-01-01", "2024-02-01"]),
|
|
114
|
+
"status": ["Current", "Delinquent"],
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
report = ca.check(df) # auto-detects the workflow from the columns
|
|
118
|
+
print(report.ok, report.workflow)
|
|
119
|
+
print(report.issues)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The same check runs from the shell: `cranalytics check your_data.csv`.
|
|
123
|
+
|
|
124
|
+
### Fit a vintage loss curve
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import numpy as np
|
|
128
|
+
from cranalytics.vintage import CurveFitter
|
|
129
|
+
|
|
130
|
+
mob = np.arange(1, 25)
|
|
131
|
+
losses = np.array([
|
|
132
|
+
0.001, 0.003, 0.006, 0.010, 0.014, 0.018, 0.022, 0.026,
|
|
133
|
+
0.030, 0.033, 0.036, 0.039, 0.041, 0.043, 0.045, 0.047,
|
|
134
|
+
0.048, 0.049, 0.050, 0.051, 0.052, 0.052, 0.053, 0.053,
|
|
135
|
+
])
|
|
136
|
+
|
|
137
|
+
fitter = CurveFitter(method="weibull").fit(mob, losses)
|
|
138
|
+
forecast = fitter.forecast(np.arange(1, 61))
|
|
139
|
+
print(f"Ultimate loss rate: {fitter.ultimate_:.3%}")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Forecast lifetime loss
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import pandas as pd
|
|
146
|
+
from cranalytics.loss_forecasting import forecast_lifetime_loss
|
|
147
|
+
|
|
148
|
+
portfolio_df = pd.DataFrame({
|
|
149
|
+
"loan_id": ["L101", "L102", "L103"],
|
|
150
|
+
"principal": [10000, 15000, 8000],
|
|
151
|
+
"annual_rate": [0.08, 0.10, 0.09],
|
|
152
|
+
"term_months": [36, 36, 24],
|
|
153
|
+
"start_date": pd.to_datetime(["2024-01-01", "2024-02-01", "2024-01-15"]),
|
|
154
|
+
"status": ["Current", "Delinquent", "Current"],
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
states = ["Current", "Delinquent", "Default"]
|
|
158
|
+
migration_matrix = pd.DataFrame(
|
|
159
|
+
[[0.95, 0.04, 0.01], [0.10, 0.80, 0.10], [0.00, 0.00, 1.00]],
|
|
160
|
+
index=states,
|
|
161
|
+
columns=states,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
lifetime_loss = forecast_lifetime_loss(
|
|
165
|
+
portfolio_df,
|
|
166
|
+
migration_matrix,
|
|
167
|
+
lgd=0.55,
|
|
168
|
+
as_of_date=pd.Timestamp("2024-02-01"),
|
|
169
|
+
)
|
|
170
|
+
print(f"Estimated lifetime loss: ${lifetime_loss:,.2f}")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Every workflow also has a CLI command group, such as `cranalytics vintage check
|
|
174
|
+
your_data.csv` or `cranalytics rollforward run your_rollforward_data.csv`. See
|
|
175
|
+
the CLI reference below.
|
|
176
|
+
|
|
177
|
+
## Claude skills
|
|
178
|
+
|
|
179
|
+
The package bundles skills that teach Claude Code these workflows:
|
|
180
|
+
`vintage-loss-curves`, `loss-forecasting`, `portfolio-diagnostics` and
|
|
181
|
+
`predictive-credit-modeling`.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
cranalytics install-skills --dry-run # preview
|
|
185
|
+
cranalytics install-skills --yes # install all
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
See the [Claude skills guide](https://cranalytics.vercel.app/tutorials/claude_skills_getting_started/)
|
|
189
|
+
for single-skill installs and conflict handling.
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
- [Getting started](https://cranalytics.vercel.app/getting_started/)
|
|
194
|
+
- [Choose your path](https://cranalytics.vercel.app/choose_your_path/): pick a workflow by question or data shape
|
|
195
|
+
- [Input data contracts](https://cranalytics.vercel.app/reference/input_data_contracts/): required columns, accepted values and aliases
|
|
196
|
+
- [CLI reference](https://cranalytics.vercel.app/reference/cli_reference/)
|
|
197
|
+
- [Tutorials](https://cranalytics.vercel.app/tutorials/lifetime_loss_forecasting/) and [API reference](https://cranalytics.vercel.app/api/core/)
|
|
198
|
+
- [Release history](https://pypi.org/project/cranalytics/#history)
|
|
199
|
+
|
|
200
|
+
Contributing: see [AGENTS.md](https://github.com/ClaySheffler/cranalytics/blob/main/AGENTS.md)
|
|
201
|
+
for commands, layout and workflow (repository access required).
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT licensed. The license text is included in the package distributions.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# cranalytics - Credit Risk Analytics
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/cranalytics/)
|
|
4
|
+
[](https://pypi.org/project/cranalytics/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
DataFrame-first credit risk analytics for consumer lending portfolios.
|
|
8
|
+
|
|
9
|
+
| Workflow | Module | What it answers |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Vintage curve fitting | `cranalytics.vintage` | Where will each vintage's cumulative loss land? |
|
|
12
|
+
| Lifetime loss forecasting | `cranalytics.loss_forecasting` | What lifetime loss does the current book imply? |
|
|
13
|
+
| FICO segmentation | `cranalytics.portfolio` | How is risk distributed across the book? |
|
|
14
|
+
| Feature analytics | `cranalytics.feature_analytics` | Which features separate good and bad loans? |
|
|
15
|
+
| ML modeling *(advanced)* | `cranalytics.predictive` | Which loans will hit a performance flag? |
|
|
16
|
+
| Survival analysis *(advanced)* | `cranalytics.survival` | When do loans default or prepay? |
|
|
17
|
+
| Portfolio simulation *(advanced)* | `cranalytics.simulation` | How do cashflows and losses evolve month by month? |
|
|
18
|
+
| Rollforward | `cranalytics.rollforward` | Monthly payment and charge-off forecasts and readiness diagnostics from aggregated data |
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install cranalytics
|
|
24
|
+
# or: uv add cranalytics
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Python 3.10+ is supported. Visualization and survival analysis are included in
|
|
28
|
+
the base install. Optional modeling backends are extras:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install "cranalytics[ml]" # optbinning: optimal WoE binning
|
|
32
|
+
pip install "cranalytics[xgboost]" # xgboost model families
|
|
33
|
+
pip install "cranalytics[lightgbm]" # lightgbm challenger models
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Install problems with compiled dependencies? See
|
|
37
|
+
[install troubleshooting](https://cranalytics.vercel.app/getting_started/#install-troubleshooting).
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
cranalytics quickstart
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Pick a workflow from the menu. Each runs in under 30 seconds on synthetic data
|
|
46
|
+
and ends with the data shape you need to run it on your own portfolio. To jump
|
|
47
|
+
straight to one workflow:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
cranalytics demo --list
|
|
51
|
+
cranalytics demo lifetime-loss
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Examples
|
|
55
|
+
|
|
56
|
+
### Validate your data
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import pandas as pd
|
|
60
|
+
import cranalytics as ca
|
|
61
|
+
|
|
62
|
+
df = pd.DataFrame({
|
|
63
|
+
"loan_id": ["L101", "L102"],
|
|
64
|
+
"principal": [10000, 15000],
|
|
65
|
+
"annual_rate": [0.08, 0.10],
|
|
66
|
+
"term_months": [36, 36],
|
|
67
|
+
"start_date": pd.to_datetime(["2024-01-01", "2024-02-01"]),
|
|
68
|
+
"status": ["Current", "Delinquent"],
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
report = ca.check(df) # auto-detects the workflow from the columns
|
|
72
|
+
print(report.ok, report.workflow)
|
|
73
|
+
print(report.issues)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The same check runs from the shell: `cranalytics check your_data.csv`.
|
|
77
|
+
|
|
78
|
+
### Fit a vintage loss curve
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import numpy as np
|
|
82
|
+
from cranalytics.vintage import CurveFitter
|
|
83
|
+
|
|
84
|
+
mob = np.arange(1, 25)
|
|
85
|
+
losses = np.array([
|
|
86
|
+
0.001, 0.003, 0.006, 0.010, 0.014, 0.018, 0.022, 0.026,
|
|
87
|
+
0.030, 0.033, 0.036, 0.039, 0.041, 0.043, 0.045, 0.047,
|
|
88
|
+
0.048, 0.049, 0.050, 0.051, 0.052, 0.052, 0.053, 0.053,
|
|
89
|
+
])
|
|
90
|
+
|
|
91
|
+
fitter = CurveFitter(method="weibull").fit(mob, losses)
|
|
92
|
+
forecast = fitter.forecast(np.arange(1, 61))
|
|
93
|
+
print(f"Ultimate loss rate: {fitter.ultimate_:.3%}")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Forecast lifetime loss
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import pandas as pd
|
|
100
|
+
from cranalytics.loss_forecasting import forecast_lifetime_loss
|
|
101
|
+
|
|
102
|
+
portfolio_df = pd.DataFrame({
|
|
103
|
+
"loan_id": ["L101", "L102", "L103"],
|
|
104
|
+
"principal": [10000, 15000, 8000],
|
|
105
|
+
"annual_rate": [0.08, 0.10, 0.09],
|
|
106
|
+
"term_months": [36, 36, 24],
|
|
107
|
+
"start_date": pd.to_datetime(["2024-01-01", "2024-02-01", "2024-01-15"]),
|
|
108
|
+
"status": ["Current", "Delinquent", "Current"],
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
states = ["Current", "Delinquent", "Default"]
|
|
112
|
+
migration_matrix = pd.DataFrame(
|
|
113
|
+
[[0.95, 0.04, 0.01], [0.10, 0.80, 0.10], [0.00, 0.00, 1.00]],
|
|
114
|
+
index=states,
|
|
115
|
+
columns=states,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
lifetime_loss = forecast_lifetime_loss(
|
|
119
|
+
portfolio_df,
|
|
120
|
+
migration_matrix,
|
|
121
|
+
lgd=0.55,
|
|
122
|
+
as_of_date=pd.Timestamp("2024-02-01"),
|
|
123
|
+
)
|
|
124
|
+
print(f"Estimated lifetime loss: ${lifetime_loss:,.2f}")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Every workflow also has a CLI command group, such as `cranalytics vintage check
|
|
128
|
+
your_data.csv` or `cranalytics rollforward run your_rollforward_data.csv`. See
|
|
129
|
+
the CLI reference below.
|
|
130
|
+
|
|
131
|
+
## Claude skills
|
|
132
|
+
|
|
133
|
+
The package bundles skills that teach Claude Code these workflows:
|
|
134
|
+
`vintage-loss-curves`, `loss-forecasting`, `portfolio-diagnostics` and
|
|
135
|
+
`predictive-credit-modeling`.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
cranalytics install-skills --dry-run # preview
|
|
139
|
+
cranalytics install-skills --yes # install all
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
See the [Claude skills guide](https://cranalytics.vercel.app/tutorials/claude_skills_getting_started/)
|
|
143
|
+
for single-skill installs and conflict handling.
|
|
144
|
+
|
|
145
|
+
## Documentation
|
|
146
|
+
|
|
147
|
+
- [Getting started](https://cranalytics.vercel.app/getting_started/)
|
|
148
|
+
- [Choose your path](https://cranalytics.vercel.app/choose_your_path/): pick a workflow by question or data shape
|
|
149
|
+
- [Input data contracts](https://cranalytics.vercel.app/reference/input_data_contracts/): required columns, accepted values and aliases
|
|
150
|
+
- [CLI reference](https://cranalytics.vercel.app/reference/cli_reference/)
|
|
151
|
+
- [Tutorials](https://cranalytics.vercel.app/tutorials/lifetime_loss_forecasting/) and [API reference](https://cranalytics.vercel.app/api/core/)
|
|
152
|
+
- [Release history](https://pypi.org/project/cranalytics/#history)
|
|
153
|
+
|
|
154
|
+
Contributing: see [AGENTS.md](https://github.com/ClaySheffler/cranalytics/blob/main/AGENTS.md)
|
|
155
|
+
for commands, layout and workflow (repository access required).
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT licensed. The license text is included in the package distributions.
|