# Stock Score History, Migration, and Change Attribution

`D18-F09-A14` · Fundamental Analysis and Valuation → Integrated Equity Scoring · archetype `record-transform` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/fundamental-analysis-and-valuation/integrated-equity-scoring/stock-score-history-migration-and-change-attribution/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { stockScoreHistoryMigrationAndChangeAttribution } from "fintech-algorithms/fundamental-analysis-and-valuation/integrated-equity-scoring/stock-score-history-migration-and-change-attribution";
```

## Signature

```ts
stockScoreHistoryMigrationAndChangeAttribution(data)
```

Compares the two most recent score snapshots, reports the overall change and the band migration between them, and attributes the move to the component that shifted furthest.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `{ history: Array<{ as_of: string; overall_score: number; band: string; components: Record<string, number> }> }` | yes | `history` needs at least two snapshots in strictly increasing `as_of` order, each a `YYYY-MM-DD` date. Every row needs a `components` object, and the last two rows must each carry an `overall_score` and a `band`; only those two are compared, and every component score read from them must be between 0 and 100. |

## Returns

`{ state: string; method: string; previous_as_of: string; latest_as_of: string; previous_score: number; latest_score: number; score_change: number; prior_band: string; latest_band: string; migration: string; migration_direction: number; component_deltas: Record<string, number>; top_driver: string; clock_policy: string }`

`score_change` is the latest overall score minus the previous one and sets `state` to `improved`, `deteriorated` or `unchanged`. `component_deltas` covers the sorted union of both snapshots' component keys and `top_driver` names the key with the largest absolute delta, ties going to the later key name. `migration` is `unchanged` or the two bands joined by an arrow, and `migration_direction` is their rank difference on the abstain, watch, eligible, strong ladder.

## Errors

- When history is not a list of at least two points, or its dates are not strictly increasing — throws RangeError
- When a history row lacks a components object — throws TypeError
- When a history as_of is not a YYYY-MM-DD string — throws TypeError
- When a compared overall_score or component score is below 0 or above 100 — throws RangeError

## Complexity

Time `O(n + k log k)`, space `O(n + k)`.

## Worked example

Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

### Input

`data`:

```json
{
  "history": [
    {
      "as_of": "2024-12-31",
      "overall_score": 62,
      "band": "watch",
      "components": {
        "health": 60,
        "quality": 64,
        "resilience": 62
      }
    },
    {
      "as_of": "2025-03-31",
      "overall_score": 70,
      "band": "eligible",
      "components": {
        "health": 72,
        "quality": 64,
        "resilience": 68
      }
    },
    {
      "as_of": "2025-06-30",
      "overall_score": 78,
      "band": "strong",
      "components": {
        "health": 80,
        "quality": 70,
        "resilience": 74
      }
    }
  ]
}
```

### Call

```ts
stockScoreHistoryMigrationAndChangeAttribution(data)
```

### Returns

object with 14 fields: state, method, previous_as_of, latest_as_of, previous_score, latest_score, score_change, prior_band, …

```json
{
  "state": "improved",
  "method": "point-in-time-score-history-change-attribution",
  "previous_as_of": "2025-03-31",
  "latest_as_of": "2025-06-30",
  "previous_score": 70,
  "latest_score": 78,
  "score_change": 8,
  "prior_band": "eligible",
  "latest_band": "strong",
  "migration": "eligible -> strong",
  "migration_direction": 1,
  "component_deltas": {
    "health": 8,
    "quality": 6,
    "resilience": 6
  },
  "top_driver": "health",
  "clock_policy": "only knowledge-available snapshots are comparable"
}
```

## Other exports

`calculate`, `pointInTimeStockScoringInputAssembly`, `stockScoringPeerCohortResolver`, `fundamentalMetricDirectionAndPeerNormalization`, `modelApplicabilityAndVariantRouter`, `accountingFinancialHealthComposite`, `earningsQualityComposite`, `dividendSafetyScore`, `balanceSheetResilienceScore`, `distressModelEnsemble`, `crossModelConflictAndDoubleCountingResolver`, `overallExplainableStockScore`, `scoreConfidenceMissingDataPenaltyAndAbstention`, `marketWideStockScreeningAndRanking`. 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.

## Verification and provenance

Tier: **verified** (via D).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.0.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/fundamental-analysis-and-valuation/integrated-equity-scoring/stock-score-history-migration-and-change-attribution/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/fundamental-analysis-and-valuation/integrated-equity-scoring/stock-score-history-migration-and-change-attribution/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/fundamental-analysis-and-valuation/llms.txt
