# Survivorship-Bias Guard

> Keep Historical Failures in the Test

`D02-F04-A02` · Corporate Actions and Security Master Data → Point-in-Time Universe · archetype `row-classify` · difficulty 4/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/corporate-actions-and-security-master-data/point-in-time-universe/survivorship-bias-guard/
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 { guardSurvivorship } from "fintech-algorithms/corporate-actions-and-security-master-data/point-in-time-universe/survivorship-bias-guard";
```

## Signature

```ts
guardSurvivorship(input)
```

Compares a universe you intend to test against the point-in-time roster and reports what is missing. It is a gate rather than a transform: the failure is the product.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `input` | `{ universeId: string; definitionId: string; effectiveAt: string; knownAt: string; candidateUniverse: object; universeDefinitions: object[]; membershipRecords: object[]; comparisonRoster: object }` | yes | `candidateUniverse` is the roster under test — typically whatever a data pull returned — and `comparisonRoster` is the point-in-time truth to check it against. |

## Returns

`{ status, definitionVersion, candidateUniverseAsOf, missingSecurities, extraSecurities, … }`

Which securities are missing from the candidate and which should not be there, with the definition version the comparison used.

## Errors

- When the universe definition is unknown at knownAt — reported as a status rather than thrown

## Complexity

Time `O(members)`, space `O(members)`.

## Worked example

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

### Input

`input`:

```json
{
  "universeId": "UNIVERSE:SYNTH:CORE",
  "definitionId": "DEF:SYNTH:CORE",
  "effectiveAt": "2023-12-31T23:59:59Z",
  "knownAt": "2024-01-02T12:00:00Z",
  "candidateUniverse": {
    "construction": "historical_membership_ledger",
    "asOf": "2023-12-31T23:59:59Z",
    "availableAt": "2024-01-02T10:00:00Z",
    "securityIds": ["SEC:A", "SEC:B", "SEC:C", "SEC:D"],
    "sourceId": "SYNTH-CANDIDATE-LEDGER"
  },
  "universeDefinitions": [
    {
      "definitionId": "DEF:SYNTH:CORE",
      "universeId": "UNIVERSE:SYNTH:CORE",
      "revision": 1,
      "effectiveFrom": "2020-01-01T00:00:00Z",
      "effectiveTo": null,
      "announcedAt": "2019-12-15T12:00:00Z",
      "availableAt": "2019-12-15T12:05:00Z",
      "status": "active",
      "baseType": "named_research_universe",
      "baseId": "BASE:SYNTH:001",
      "ruleSummary": "Synthetic members documented by effective-dated membership evidence.",
      "sourceId": "SYNTH-DEFINITION-R1"
    },
    {
      "definitionId": "DEF:SYNTH:CORE",
      "universeId": "UNIVERSE:SYNTH:CORE",
      "revision": 2,
      "effectiveFrom": "2020-01-01T00:00:00Z",
      "effectiveTo": null,
      "announcedAt": "2024-02-01T09:00:00Z",
      "availableAt": "2024-02-01T09:05:00Z",
      "status": "active",
      "baseType": "named_research_universe",
      "baseId": "BASE:SYNTH:001",
      "ruleSummary": "Later documentation revision; unavailable to the canonical query.",
      "sourceId": "SYNTH-DEFINITION-R2"
    }
  ],
  "membershipRecords": [
    {
      "membershipId": "MEM-A",
      "revision": 1,
      "universeId": "UNIVERSE:SYNTH:CORE",
      "securityId": "SEC:A",
      "validFrom": "2020-01-01T00:00:00Z",
      "validTo": null,
      "announcedAt": "2019-12-15T12:00:00Z",
      "availableAt": "2019-12-15T12:05:00Z",
      "status": "active",
      "changeType": "entry",
      "eventId": "EVENT-A-ENTRY",
      "sourceId": "SYNTH-MEM-A"
    },
    {
      "membershipId": "MEM-B",
      "revision": 1,
      "universeId": "UNIVERSE:SYNTH:CORE",
      "securityId": "SEC:B",
      "validFrom": "2020-01-01T00:00:00Z",
      "validTo": "2024-06-01T00:00:00Z",
      "announcedAt": "2023-12-20T10:00:00Z",
      "availableAt": "2023-12-20T10:05:00Z",
      "status": "active",
      "changeType": "exit",
      "eventId": "EVENT-B-EXIT",
      "sourceId": "SYNTH-MEM-B-R1"
    },
    {
      "membershipId": "MEM-B",
      "revision": 2,
      "universeId": "UNIVERSE:SYNTH:CORE",
      "securityId": "SEC:B",
      "validFrom": "2020-01-01T00:00:00Z",
      "validTo": "2023-12-15T00:00:00Z",
      "announcedAt": "2024-01-10T08:00:00Z",
      "availableAt": "2024-01-10T08:05:00Z",
      "status": "active",
      "changeType": "revision",
      "eventId": "EVENT-B-CORRECTION",
      "sourceId": "SYNTH-MEM-B-R2"
    }
  ],
  "comparisonRoster": {
    "observedAt": "2025-01-02T00:00:00Z",
    "availableAt": "2025-01-02T12:00:00Z",
    "securityIds": ["SEC:A", "SEC:C", "SEC:D"],
    "sourceId": "SYNTH-CURRENT-ROSTER"
  }
}
```

### Call

```ts
guardSurvivorship(input)
```

### Returns

object with 7 fields: status, definitionVersion, eligibleSecurityIds, ineligibleSecurityIds, unknownSecurityIds, ambiguousSecurityIds, hindsightDiagnostics

```json
{
  "status": "resolved",
  "definitionVersion": "DEF:SYNTH:CORE@1",
  "eligibleSecurityIds": ["SEC:A", "SEC:B", "SEC:C"],
  "ineligibleSecurityIds": ["SEC:D"],
  "unknownSecurityIds": [],
  "ambiguousSecurityIds": [],
  "hindsightDiagnostics": {
    "historicallyEligibleMissingFromCurrent": ["SEC:B"],
    "currentRosterNotHistoricallyEligible": ["SEC:D"],
    "retentionRatio": 0.666667
  }
}
```

## Other exports

`compareEqualWeightedReturns`. 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 input-expected).

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.1.
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/corporate-actions-and-security-master-data/point-in-time-universe/survivorship-bias-guard/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/corporate-actions-and-security-master-data/point-in-time-universe/survivorship-bias-guard/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/corporate-actions-and-security-master-data/llms.txt
