fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Score Stability and Migration Matrix

Install and import#

bash
npm install fintech-algorithms
ts
import { scoreStabilityAndMigrationMatrix } from "fintech-algorithms/model-validation-and-backtesting/classification-and-score-validation/score-stability-and-migration-matrix";

Signature#

scoreStabilityAndMigrationMatrix(inputs)

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

inputs
{
  "baseline": [
    {
      "id": "E01",
      "score": 0.08
    },
    {
      "id": "E02",
      "score": 0.14
    },
    {
      "id": "E03",
      "score": 0.19
    }
  ],
  "current": [
    {
      "id": "E01",
      "score": 0.1
    },
    {
      "id": "E02",
      "score": 0.18
    },
    {
      "id": "E03",
      "score": 0.17
    }
  ],
  "band_edges": [0, 0.2, 0.4, 0.6, 0.8, 1],
  "higher_score_higher_risk": true,
  "baseline_observed_at": "2025-01-01T00:00:00Z",
  "current_observed_at": "2026-01-01T00:00:00Z"
}

Call#

scoreStabilityAndMigrationMatrix(inputs)

Returns#

object with 17 fields: band_edges, matrix, row_rates, baseline_band_shares, current_band_shares, migrations, matched_count, stable_count, …

{
  "band_edges": [0, 0.2, 0.4, 0.6, 0.8, 1],
  "matrix": [
    [3, 0, 0, 0, 0],
    [0, 2, 1, 0, 0],
    [0, 0, 2, 1, 0]
  ],
  "row_rates": [
    [1, 0, 0, 0, 0],
    [0, 0.6666666666666666, 0.3333333333333333, 0, 0],
    [0, 0, 0.6666666666666666, 0.3333333333333333, 0]
  ],
  "baseline_band_shares": [0.25, 0.25, 0.25, 0.16666666666666666, 0.08333333333333333],
  "current_band_shares": [0.25, 0.16666666666666666, 0.25, 0.16666666666666666, 0.16666666666666666],
  "migrations": [
    {
      "id": "E01",
      "baseline_score": 0.08,
      "current_score": 0.1,
      "baseline_band": 1,
      "current_band": 1,
      "band_move": 0,
      "score_change": 0.020000000000000004
    },
    {
      "id": "E02",
      "baseline_score": 0.14,
      "current_score": 0.18,
      "baseline_band": 1,
      "current_band": 1,
      "band_move": 0,
      "score_change": 0.03999999999999998
    },
    {
      "id": "E03",
      "baseline_score": 0.19,
      "current_score": 0.17,
      "baseline_band": 1,
      "current_band": 1,
      "band_move": 0,
      "score_change": -0.01999999999999999
    }
  ],
  "matched_count": 12,
  "stable_count": 9,
  "improved_count": 0,
  "worsened_count": 3,
  "stable_rate": 0.75,
  "mean_band_move": 0.25,
  "mean_absolute_band_move": 0.25,
  "mean_score_change": 0.02583333333333333
}

Showing 14 of 17 fields.

Other exports#

This module also exports rocCurveAndRocAuc, precisionRecallCurveAndPrAuc, brierScore, logLoss, reliabilityDiagramAndExpectedCalibrationError, gainsLiftAndDecileCapture, costSensitiveThresholdOptimization, sliceBasedValidationBySectorCountryAndRegime, rareEventBacktestAndConfidenceBounds, calculate. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Score Stability and Migration Matrix — article hero
Score Stability and Migration Matrix — decision boundaries
Score Stability and Migration Matrix — method selection
Score Stability and Migration Matrix — system map

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Classification and Score Validation family#