Stock Score History, Migration, and Change Attribution
Install and import#
npm install fintech-algorithmsimport { stockScoreHistoryMigrationAndChangeAttribution } from "fintech-algorithms/fundamental-analysis-and-valuation/integrated-equity-scoring/stock-score-history-migration-and-change-attribution";Signature#
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 | Notes |
|---|---|---|
data | { history: Array<{ as_of: string; overall_score: number; band: string; components: Record<string, number> }> } | 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#
executed 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#
{
"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#
stockScoreHistoryMigrationAndChangeAttribution(data)Returns#
object with 14 fields: state, method, previous_as_of, latest_as_of, previous_score, latest_score, score_change, prior_band, …
{
"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#
This module also 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.
Diagrams#
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.
References#
- EDGAR XBRL Guide — U.S. Securities and Exchange Commission
- Conceptual Framework for Financial Reporting — International Accounting Standards Board
- Beginners' Guide to Financial Statements — U.S. Securities and Exchange Commission
- Conceptual Framework for Financial Reporting — International Accounting Standards Board
- Evidence boundary