Skip to content

Rollforward Workflow API Reference

Rollforward Workflow

Rollforward is the single object for all three rollforward surfaces: .run(mode="model") (in-memory), .run(mode="workflow", output_dir=...) (artifact-emitting), and .readiness(...). The module-level run(df) is a one-line convenience over model mode. Run readiness checks first when working with a new dataset. The result types (RollforwardRunSummary, operational_status, etc.) are the canonical cross-surface summary contract.

Every surface returns a RollforwardResult (RollforwardWorkflowResult is an alias for RollforwardResult, and ReadinessRunResult is a thin subclass retaining the deprecated 0.3.0 dict-access shim on .summary until 0.4.0) with .summary(), .tables(), .plot(), .assumptions(), and .to_dict(). All produced tables are retained in memory regardless of whether artifacts were written to output_dir. ReadinessRunResult.report holds the full readiness scoring dict; .summary() returns its scalar entries as a one-row DataFrame.

cranalytics.rollforward

Unified public front door for the rollforward workflow.

Rollforward is the single object for all three rollforward surfaces, hiding the multi-module session / evaluation / reporting / result-translation chain behind a small interface:

  • .run(mode="model") -> in-memory :class:RollforwardResult
  • .run(mode="workflow") -> artifact-emitting :class:RollforwardResult
  • .readiness(...) -> :class:ReadinessRunResult (subclass of :class:RollforwardResult)

model and workflow share the same session engine and differ only in whether artifacts are written, so they are two modes of one run. readiness uses a distinct session, config, and defaults, so it is a sibling method on the same object rather than a mode with half-ignored parameters. All surfaces retain their produced tables in memory; output_dir is optional on readiness for purely in-memory runs. The module-level run (workflow-namespaced: cranalytics.rollforward.run) is a thin convenience over model mode.

This module carries the workflow's real entry-point logic (the Rollforward class), unlike the pure re-export facades used by other workflows — there is no separate flat module to preserve here.

ReadinessRunResult dataclass

Bases: RollforwardResult

Readiness specialization of :class:RollforwardResult.

Retained as a thin subclass through 0.3.x so result.summary keeps both the new result.summary() DataFrame method and the deprecated 0.3.0 dict access (raising a DeprecationWarning) until 0.4.0.

RollforwardResult dataclass

Bases: WorkflowResult

Unified result for rollforward modeling, workflow, and readiness runs.

Every rollforward surface (Rollforward.run(mode="model"), Rollforward.run(mode="workflow", output_dir=...), and Rollforward.readiness(...)) returns a :class:RollforwardResult (with :class:ReadinessRunResult as a thin subclass until 0.4.0 for the deprecated dict-access shim on .summary). All produced tables are retained in memory so .tables() and .to_dict() do not depend on output_dir staying intact on disk.

summary() -> pd.DataFrame

Primary summary table for the active rollforward surface.

plot(**kwargs: Any) -> Any

Render a rollforward summary chart. Requires matplotlib.

Rollforward

is_ready_to_model() -> bool

Quick pre-flight: no critical data issues and sufficient MOB history (>=18).

run(*, mode: RollforwardRunMode = 'model', output_dir: Path | str | None = None, holdout_months: int = 6, min_train_months: int = 12, step_months: int = 1, variants: list[str] | None = None, monitor_thresholds: dict[str, float] | None = None, segment: str | None = None, strict: bool = False) -> RollforwardResult

Run the rollforward workflow in-memory (model) or with artifacts (workflow).

Parameters:

Name Type Description Default
mode RollforwardRunMode

"model" returns an in-memory result; "workflow" also writes committee-ready artifacts to output_dir.

'model'
output_dir Path | str | None

Required when mode="workflow"; ignored otherwise.

None
holdout_months int

Final months reserved for holdout evaluation.

6
min_train_months int

Minimum historical months required for training.

12
step_months int

Backtest step size.

1
variants list[str] | None

Optional candidate variant names.

None
monitor_thresholds dict[str, float] | None

Optional KPI threshold overrides.

None
segment str | None

Optional single segment to model.

None
strict bool

Whether warnings should fail validation.

False

Returns:

Type Description
RollforwardResult

class:RollforwardResult with in-memory tables (plus

RollforwardResult

output_dir and run_metadata populated in workflow mode).

Raises:

Type Description
ValueError

If mode is not "model" or "workflow", or if mode="workflow" is used without output_dir. For readiness reports use :meth:readiness.

readiness(*, output_dir: Path | str | None = None, holdout_months: int = 6, min_train_months: int = 6, segment: str | None = None, strict: bool = False, scoring_config: ReadinessConfig | None = None, weights: Mapping[str, float] | None = None) -> ReadinessRunResult

Generate a rollforward readiness report (and optionally emit artifacts).

Readiness uses a distinct session and scoring configuration from :meth:run, including a lower default min_train_months. The input frame is copied, so the caller's DataFrame is never mutated. When output_dir is omitted, readiness runs purely in memory.

run(df: pd.DataFrame, **kwargs) -> RollforwardResult

Convenience one-liner: initialize, run in-memory model mode, return result.

For artifact-emitting workflow runs or readiness reports, use the :class:Rollforward object directly (.run(mode="workflow", ...) / .readiness(...)).

Rollforward Contract

The contract module owns reusable validation for aggregated monthly flow data. Use it when integrating a new source or diagnosing alias resolution.

cranalytics.rollforward._contract

Public input-contract helpers for the Rollforward workflow.

RollforwardContractResult dataclass

Bases: IssueTableResultMixin

Normalized rollforward data plus collected contract issues.

normalized_df(*, segment: str | None = None) -> pd.DataFrame

Return normalized rollforward data, optionally filtered to one segment.

amtloan_series(*, segment: str | None = None) -> pd.Series | None

Return resolved denominator series, optionally filtered to one segment.

amtloan_map(*, segment: str | None = None) -> dict[str, float]

Return resolved denominators as a segment->value mapping.

validate_rollforward_input_contract(df: pd.DataFrame, *, amtloan_col: str = 'amtloan', strict: bool = False) -> RollforwardContractResult

Normalize columns, resolve aliases, and collect rollforward data issues.

Rollforward Backtest

Backtest helpers compare candidate Rollforward variants over historical holdouts. Use these lower-level functions when you need custom evaluation control beyond the workflow boundary.

cranalytics.rollforward._backtest

Backtesting helpers for Rollforward workflow variants.

run_rollforward_backtest_sweeps(df: pd.DataFrame, *, variants: list[str] | None = None, holdout_horizons: tuple[int, ...] = (3, 6), min_train_months: int = 12, step_months: int = 1, amtloan_by_segment: pd.Series | None = None, amtloan_col: str = 'amtloan') -> pd.DataFrame

Run rolling OOT backtests across configured rollforward variants.

summarize_rollforward_variant_performance(results: pd.DataFrame) -> pd.DataFrame

Aggregate split-level rollforward backtest results to one row per variant.

select_rollforward_champion_and_challengers(summary: pd.DataFrame, *, benchmark_variant: str = 'baseline_flat_last_hazard', challenger_count: int = 2) -> dict[str, Any]

Select a champion variant subject to baseline promotion rules.