# Cumulative Advance/Decline Line

> Recompute History Without Looking Ahead

`D04-F01-A03` · Market Breadth and Internals → Advance/Decline Breadth · archetype `record-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-breadth-and-internals/advance-decline-breadth/cumulative-advance-decline-line/
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 { calculateCumulativeAdvanceDeclineLine } from "fintech-algorithms/market-breadth-and-internals/advance-decline-breadth/cumulative-advance-decline-line";
```

## Signature

```ts
calculateCumulativeAdvanceDeclineLine(contract, events, knowledgeCutoff)
```

Runs net advances into a cumulative line. Its level is arbitrary; the information is in the shape, and specifically in divergence — when the index makes a high the line does not, participation is narrowing.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `contract` | `LineContract` | yes | Series identity and the `seed` the accumulation starts from. The seed only shifts the level, never the shape. |
| `events` | `BreadthEvent[]` | yes | Session events including revisions and supersessions, each with an ingest sequence. |
| `knowledgeCutoff` | `string` | yes | Point-in-time bound. Revisions arriving after the cutoff are ignored rather than applied, so the series is exactly what was computable at that moment. Breadth data is revised routinely, and a cumulative line silently rebuilt from revised inputs is not the line anyone traded. |

## Returns

`{ status, reasons, knowledge_cutoff, points, final_value, causal_prefix_diagnostic, missing_sessions, … }`

The line plus a causal-prefix diagnostic and the sessions that were missing — a gap in a cumulative series propagates forward forever, so it must be visible.

## Errors

- When events are missing an ingest sequence needed to order them — reported in reasons rather than thrown

## Complexity

Time `O(events)`, space `O(sessions)`.

## Worked example

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

### Input

`contract`:

```json
{
  "metric": "cumulative_issue_count_advance_decline_line",
  "series_id": "SYNTH-AD",
  "continuity_id": "SYNTH-CONTINUITY",
  "venue_id": "SYNTH-X",
  "universe_id": "SYNTH-5",
  "calendar_id": "SYNTH-CAL",
  "session_type": "regular",
  "comparison_basis": "comparable-prior-close",
  "seed": 0,
  "seed_lineage_id": "SEED-0",
  "seed_effective_at": "2026-01-04T21:00:00Z",
  "seed_available_at": "2026-01-04T21:05:00Z",
  "expected_sessions": [
    {
      "session_sequence": 1,
      "session_date": "2026-01-05"
    },
    {
      "session_sequence": 2,
      "session_date": "2026-01-06"
    }
  ]
}
```

`events`:

```json
[
  {
    "event_id": "AD-1",
    "ingest_sequence": 1,
    "revision_number": 1,
    "supersedes_event_id": null,
    "action": "upsert",
    "session_sequence": 1,
    "session_date": "2026-01-05",
    "effective_at": "2026-01-05T21:00:00Z",
    "available_at": "2026-01-05T21:05:00Z",
    "series_id": "SYNTH-AD",
    "continuity_id": "SYNTH-CONTINUITY",
    "venue_id": "SYNTH-X",
    "universe_id": "SYNTH-5",
    "calendar_id": "SYNTH-CAL"
  },
  {
    "event_id": "AD-2",
    "ingest_sequence": 2,
    "revision_number": 1,
    "supersedes_event_id": null,
    "action": "upsert",
    "session_sequence": 2,
    "session_date": "2026-01-06",
    "effective_at": "2026-01-06T21:00:00Z",
    "available_at": "2026-01-06T21:05:00Z",
    "series_id": "SYNTH-AD",
    "continuity_id": "SYNTH-CONTINUITY",
    "venue_id": "SYNTH-X",
    "universe_id": "SYNTH-5",
    "calendar_id": "SYNTH-CAL"
  }
]
```

`knowledgeCutoff`:

```json
"2026-01-06T22:00:00Z"
```

### Call

```ts
calculateCumulativeAdvanceDeclineLine(contract, events, knowledgeCutoff)
```

### Returns

object with 6 fields: status, reasons, final_value, contains_provisional, ignored_future_event_count, points

```json
{
  "status": "resolved",
  "reasons": [],
  "final_value": 1,
  "contains_provisional": false,
  "ignored_future_event_count": 0,
  "points": {
    "0": {
      "session_sequence": 1,
      "net_advances": 2,
      "cumulative_line": 2
    },
    "1": {
      "session_sequence": 2,
      "net_advances": -1,
      "cumulative_line": 1
    }
  }
}
```

## 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/market-breadth-and-internals/advance-decline-breadth/cumulative-advance-decline-line/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-breadth-and-internals/advance-decline-breadth/cumulative-advance-decline-line/impl.ts
- Standalone repository: https://github.com/IslamBaraka90/Fintech-Cumulative-Advance-Decline-Line-Market-Breadth-algorithm
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-breadth-and-internals/llms.txt
