A canonical, well-specified, cross-language (Python + TypeScript) reference implementation of point-in-time filing revision versioning. Companies restate. The number in your backtest should be the one that existed at the time — not the final restated figure that today's database hands you for every date. This module selects the 10-K or 10-K/A that was current for your research system at a knowledge instant.
📖 Full article (canonical): Filing Revision Versioning — The Fintech Builder
This repository is the runnable, production-oriented companion to that article. The article teaches the concept; this repo is the code you install and build on.
🧭 Browse all algorithms: Awesome FinTech Algorithms — the full index of the library.
🗂️ This algorithm's domain: Corporate Actions and Security Master Data › Point-in-Time Universe
📥 Just want to call it? It also ships in the fintech-algorithms npm package — see Two ways to use this.
| Catalog topic | D02-F04-A04 |
| Domain | D02 — Corporate Actions and Security Master Data |
| Family | D02-F04 — Point-in-Time Universe |
| Languages | Python, TypeScript |
- A real restatement
- Whose clock decides
- Three rules, one of them honest
- Whole-filing selection drops facts
- Two ways to use this
- Install
- Quickstart
- Views: the analysis surface
- Input shape
- API reference
- Edge cases & limitations
- Testing
- Related algorithms
- License
The fixture is a real SEC filing history — CIK 0000033619, fiscal year ending 29 September 2017:
asOf 2018-02-01T00:00:00Z 10-K 0001564590-17-024189 EPS 3.94 not yet ingested: 0001564590-18-007244
asOf 2018-03-30T14:50:00Z 10-K 0001564590-17-024189 EPS 3.94 not yet ingested: 0001564590-18-007244
asOf 2018-03-30T15:05:00Z 10-K/A 0001564590-18-007244 EPS 3.75 not yet ingested: (none)
For four months the only EPS in existence was 3.94. A backtest reading today's database uses 3.75 for all of them.
Every filing carries two clocks:
acceptedAt |
when the regulator accepted it — a fact about the world |
ingestedAt |
when your research system had it — a fact about you |
Eligibility is decided by ingestedAt. Among the versions you had, the latest accepted one
wins, with the amendment number and then the accession breaking exact ties.
That is why the middle row above says 3.94. At 14:50 on 30 March the SEC had accepted the 10-K/A (14:43:54) and it was on EDGAR. Your pipeline ingested it at 15:00. Selecting it at 14:50 is look-ahead, even though it was public.
When nothing had been ingested by asOf, the selector raises — there is no filing to report,
and an empty answer shaped like a filing would be read as one.
selection_policy_comparison evaluates the same instant under the three rules people actually
use:
pointInTime 10-K 0001564590-17-024189 EPS 3.94
acceptanceClock 10-K/A 0001564590-18-007244 EPS 3.75
hindsight 10-K/A 0001564590-18-007244 EPS 3.75
acceptance clock reads a filing you had not seen: yes
hindsight reads a later filing: yes
window 0001564590-17-024189 2017-11-21T16:32:41Z -> 2017-11-21T16:40:00Z 439.000000 s asOf inside: no
window 0001564590-18-007244 2018-03-30T14:43:54Z -> 2018-03-30T15:00:00Z 966.000000 s asOf inside: yes
- Point in time — ingested by
asOf. The only rule that uses information you had. - Acceptance clock — accepted by
asOf. It feels point-in-time, and inside every acceptance-to-ingestion window it reads a filing your system had not seen. - Hindsight — the latest version, full stop. What a backtest on today's database does, without ever calling it a choice.
Selection is whole-filing: the chosen version supplies every fact. That is right when an amendment restates the financial statements — and silently wrong when it amends something narrower. Add a later 10-K/A that only amends Part III:
selected filing 0001564590-18-009999
facts it silently drops basicEpsUsdPerShare, netEarningsUsdMillions
basicEpsUsdPerShare selected - latest reported 3.75
directorCount selected 9 latest reported 9
netEarningsUsdMillions selected - latest reported 111.554
The selector is behaving exactly as specified, and EPS has disappeared from the answer.
fact_lineage names every fact this happens to, alongside the most recent value you actually had.
This repo is the production home: the full implementation, the analysis surface below, and 242 tests across two languages.
The fintech-algorithms npm package
ships the same topic as one import among several hundred.
fintech-algorithms/corporate-actions-and-security-master-data/point-in-time-universe/filing-revision-versioning
Python
cd python pip install -e ".[dev]"
TypeScript
cd typescript
npm install
npm run buildfrom fintech_filing_versions import calculate, selection_policy_comparison result = calculate({ "entityId": "CIK0000033619", "reportPeriod": "2017-09-29", "formFamily": "10-K", "asOf": "2018-03-30T14:50:00Z", # the knowledge instant "records": [...], # every version, each with two clocks }) result["form"] # '10-K' result["facts"]["basicEpsUsdPerShare"] # 3.94 result["excludedNotYetIngested"] # ['0001564590-18-007244']
TypeScript is the same call with camelCase names:
import { calculate, selectionPolicyComparison } from 'fintech-filing-versions'; calculate(request).facts.basicEpsUsdPerShare;
Run the tour in either language:
cd python && python examples/quickstart.py cd typescript && npm run example
Both print byte-identical output.
Shown above. Per fact: the value under each rule, acceptanceClockLooksAhead,
hindsightLooksAhead. Per filing: its acceptance-to-ingestion window and whether asOf falls
inside it. Works even when nothing was ingested yet (status: "nothing_ingested"), because the
other two rules may still have an answer — which is the point.
basicEpsUsdPerShare restated by -0.048223 in force 3.75
netEarningsUsdMillions restated by -0.049690 in force 111.554
For each fact: every version's value in acceptance order, the value in force, latestReported,
droppedByWholeFilingSelection, restatedByAsOf, relativeRestatement (a six-decimal string),
and the hindsight value with a flag for when it differs from what you had.
2017-11-21T16:39:59Z nothing_ingested - EPS -
2017-11-21T16:40:00Z selected 0001564590-17-024189 EPS 3.94
2018-03-30T15:00:00Z selected 0001564590-18-007244 EPS 3.75
restated at 2018-03-30T15:00:00Z: basicEpsUsdPerShare 3.94 -> 3.75
restated at 2018-03-30T15:00:00Z: netEarningsUsdMillions 117.387 -> 111.554
Each change lists facts changed, added and dropped, and per-filing ingestion lags. A back-filled original — ingested after its own amendment — correctly changes nothing.
theSelectedVersionWasIngestedByAsOf yes
noLaterAcceptedVersionWasIngested yes
eligibleAndExcludedPartitionTheHistory yes
theReportedFieldsAreTheSelectedVersions yes
theHistoryHasExactlyOneOriginal yes
Pass a second argument to audit somebody else's selection. Feed it the restated 10-K/A reported as
current at 14:50 — a hindsight read — and it fails on ingestion, selection order and the exclusion
partition. theHistoryHasExactlyOneOriginal checks the data rather than the answer: two originals
for one period is a contradiction no selection rule can fix.
{
"entityId": "CIK0000033619",
"reportPeriod": "2017-09-29",
"formFamily": "10-K",
"asOf": "2018-03-30T14:50:00Z", // knowledge instant, explicit offset required
"records": [{
"entityId": "CIK0000033619",
"reportPeriod": "2017-09-29",
"form": "10-K/A", // formFamily or formFamily + "/A"
"accessionNo": "0001564590-18-007244",// unique
"amendmentNumber": 1, // 0 exactly for the base form, > 0 for /A
"acceptedAt": "2018-03-30T14:43:54Z", // the regulator's clock
"ingestedAt": "2018-03-30T15:00:00Z", // your clock; never before acceptedAt
"amendmentScope": ["Item 6", "Item 7", "Item 8", "Item 9A", "Item 15"],
"facts": { "basicEpsUsdPerShare": 3.75, "netEarningsUsdMillions": 111.554 }
}]
}Python — from fintech_filing_versions import ...
| function | returns |
|---|---|
calculate(data) / select_filing_version(data) |
the selected version, its facts and the audit trail |
selection_policy_comparison(data) |
point-in-time vs acceptance clock vs hindsight |
fact_lineage(data) |
every version of every fact, and dropped facts |
revision_timeline(data) |
the selection at every ingestion instant |
verify_selection(data, result=None) |
five checks; pass result to audit a supplied selection |
validate_request(data) · select_version(records, cutoff, clock) · order_key(record) |
the steps, exposed |
parse_instant(value, name) · render_instant(us) |
the strict grammar, as epoch microseconds |
TypeScript — import { ... } from 'fintech-filing-versions'
The same functions in camelCase (compareOrder in place of order_key). Instants are bigint
microseconds.
- Nothing ingested raises. Both reference implementations and the reference tests throw here,
and so does this port. (The catalog metadata for this topic says the case is "reported on the
result"; the metadata is what disagrees with the implemented behaviour.) The sweeping views report
nothing_ingestedas a state instead. - Integral floats are returned as ints.
3.0comes back as3and-0.0as0, because Python writes3.0and JavaScript writes3. The value is unchanged. - Byte-identity has a documented edge. Facts are numbers, and the two JSON encoders choose
different thresholds for exponent notation (Python
1e-05, JavaScript0.00001; JavaScript1e+21, Python all the digits). Values agree; bytes differ for magnitudes below1e-4or at1e21and above. Integer-like fact keys ("2017") are also reordered by JavaScript objects. - A strict instant grammar.
YYYY-MM-DDTHH:MM:SS[.ffffff](Z|+HH:MM|-HH:MM). The reference accepts more, and its Python and TypeScript twins accept different things. - Whole-filing selection is the contract.
calculatenever merges facts across filings;fact_lineageshows what that costs instead of silently doing something else. - Direct ingestion only. A filing ingested before it was accepted is refused. A vendor feed
that backdates
ingestedAtwould need a different clock model.
cd python && pytest -q # 123 tests cd typescript && npm test # 119 tests
Both suites reproduce the three published cutoffs exactly.
The two implementations were compared directly across 1,500 scenarios and 7,500 calls — the selector and all four surfaces — and their JSON output is byte-identical (16.8 MB). The examples are byte-identical too.
The Python selector was separately differentially tested against the reference implementation on 12,000 generated filing histories — one to four versions, inverted ingestion order, UTC offsets and fractional seconds, and nine kinds of malformed record — with zero unexplained divergences. 3,809 integral-float facts exercised the one normalisation, and a grammar probe found 5 of 10 spellings accepted identically, 5 accepted only by the reference, none only by this port.
Same family — D02-F04 Point-in-Time Universe
- IPO Availability Timestamping — the same ingestion-versus-occurrence discipline for listing events.
- Historical Constituent Reconstruction — a roster replayed under two clocks.
- Survivorship-Bias Guard — a universe that forgets the companies that left.
Related — D01-F04 Data Quality
- Point-in-Time Availability Guard — the same no-look-ahead rule for ordinary observations.
MIT — see LICENSE.