What Can a Strategy Actually See on Backtest Day? A Step-by-Step PIT Walkthrough
Working through a compact synthetic dataset with trading dates, delayed disclosures, revision chains, and late ingestion to calculate exact Point-in-Time (PIT) visibility, market vs. system modes, and total-return completeness gates.
Almost nobody writes a backtest that intentionally peeks at tomorrow's close. Real lookahead bias slips in through subtler shortcuts: filtering financial statements by report_period, reading the latest overwritten row after a revision, or assuming an empty dividend table means zero dividends occurred.
In AI-Portfolio Research (ai-portfolio-research), Point-in-Time (PIT) visibility is enforced directly in storage queries and research gates. Rather than staying abstract, let us walk a tiny synthetic dataset — combining daily bars, delayed disclosures, a bond revision chain, late ingestion, and dividend completeness — through the exact selection logic on a chosen backtest timestamp.
Separate Four Distinct Timestamps First
A single financial observation carries at least four different clocks:
- Economic date (
trade_date/report_period/nav_date): the day or fiscal period the value describes. - Publication timestamp (
published_at): when the exchange or issuer released it. - Market availability timestamp (
available_at/revision_available_at): when market participants could reliably observe and act on it. - System ingestion timestamp (
retrieved_at): when our local pipeline actually fetched and stored it in SQLite.
One rule governs PIT selection: what is visible at as_of depends on available_at (never the economic date), and revisions fall back along their predecessor chain rather than blindly reading MAX(version).
1. The Synthetic Dataset
Suppose our strategy evaluates a portfolio at 2026-04-01 15:00 +08:00 (2026-04-01T07:00:00Z, the April 1 market close decision point). Our local database holds 6 records across daily prices, financial statements, and bond terms (normalized from China time to UTC in timing.py, where daily closes default to 18:00 +08:00 under estimated_daily_close_18h):
| ID | Table / Symbol | Economic Date | Payload | available_at (+08:00) | retrieved_at (+08:00) | Quality / Verification |
|---|---|---|---|---|---|---|
R1 | stock_daily (510300) | 2026-03-31 | Close 4.10 | 2026-03-31 18:00 | 2026-03-31 20:00 | estimated_daily_close_18h |
R2 | stock_daily (510300) | 2026-04-01 | Close 4.18 | 2026-04-01 18:00 | 2026-04-01 19:10 | estimated_daily_close_18h |
R3 | financial_statements (A001) | 2025-12-31 | FY2025 ROE 14.2% | 2026-04-21 18:00 (disclosed Apr 20, next-day 18:00) | 2026-04-21 21:00 | estimated_next_calendar_day_18h |
R4a | bond_instrument_versions (BOND-01) | Effective 2026-01-13 | r1 coupon 5.00% | 2026-01-13 18:00 | 2026-07-01 08:00 | verified (content_verified=true) |
R4b | bond_instrument_versions (BOND-01) | Revises r2 → r1 | r2 coupon revised to 6.00% | 2026-06-15 18:00 (revision_available_at) | 2026-07-01 08:00 | verified (content_verified=true) |
R5 | financial_statements (A002) | 2025-12-31 | Legacy import ROE 11.0% | NULL (date-only legacy row) | 2026-03-25 10:00 | unknown_legacy_availability |
2. Step-by-Step Evaluation at 2026-04-01 15:00 +08:00
Step 1: Availability and Quality Whitelist Gate
Every PIT query in database.py enforces two non-negotiable predicates:
available_at IS NOT NULL AND julianday(available_at) <= julianday(as_of)quality_status IN ('verified', 'estimated_daily_close_18h', 'estimated_next_calendar_day_18h')
Applying them directly:
R5is rejected (AVAILABILITY_UNKNOWN): Even though it was ingested on March 25, a legacy row withavailable_at = NULLis never admitted as verified history.R1is admitted:2026-03-31 18:00 <= 2026-04-01 15:00with whitelisted quality. The strategy sees yesterday's close4.10.R2is rejected (AVAILABLE_AFTER_AS_OF): Even thoughtrade_dateis2026-04-01, the cleaned daily close is only guaranteed available at18:00— three hours after15:00. If a strategy intends to trade on the next session using confirmed April 1 closes, it must explicitly setas_ofafter2026-04-01 18:00 +08:00.R3is rejected (AVAILABLE_AFTER_AS_OF): Classic fundamental lookahead trap. The fiscal period ended2025-12-31, but the annual report was not disclosed until April 20. On April 1,14.2%does not exist yet.
Step 2: Revision Chains Fall Back Instead of Reading MAX(version)
Look at BOND-01 (R4a and R4b):
- On June 15,
R4b(r2, coupon6.00%) supersededR4a(r1, coupon5.00%). - At
as_of = 2026-04-01 15:00,R4bfails becauserevision_available_at = 2026-06-15 > as_of. - Overwriting
r1in place would leak June's6.00%back into April; checking only the chain tip would falsely report no instrument found. - Instead, the selector filters admissible versions first (
{R4a}) and picks the latest admissible member of the chain — returningR4a(5.00%) on April 1 and seamlessly switching toR4b(6.00%) onceas_ofmoves past June 15 (e.g.,2026-08-01). And if someone tries to import a revision without a knownrevision_available_at, the import contract rejects it outright before it can corrupt history.
Step 3: Market Knowledge vs. System Knowledge (system_as_of)
Notice R4a has retrieved_at = 2026-07-01 08:00: the market knew it on January 13, but our pipeline only backfilled it on July 1.
| Mode | Query Parameters | Is R4a Visible on Apr 1? | Question Answered |
|---|---|---|---|
| Market research mode (default) | as_of = 2026-04-01 15:00 | Yes (5.00%) | Could a market participant objectively know this on April 1? |
| System-knowledge mode | as_of = 2026-04-01 15:00, system_as_of = 2026-04-01 15:00 | No (RETRIEVED_AFTER_SYSTEM_AS_OF) | Did our actual local database already have this row on April 1? |
Separating available_at from retrieved_at lets historical market studies use backfilled records cleanly while keeping live-system replay audits strictly honest.
3. Two Subtle Boundaries That Break Naive Backtests
Missing Window Endpoints Return boundary_unavailable
Stocks follow exchange sessions, bond funds follow valuation days, and money-market funds accrue every calendar day. If a request asks for [2026-01-01, 2026-04-01] where 2026-01-01 is a holiday or 2026-04-01 is not yet available at as_of (R2), ExplicitSessionCalendar blocks with boundary_unavailable instead of silently snapping endpoints to the nearest trading day. Cross-asset alignment only aggregates downward onto real shared endpoints — never upsampling NAV, zero-filling gaps, or treating suspensions as zero returns.
An Empty Dividend Table Does Not Prove Zero Dividends
Suppose we request total return for 510300 over [2026-01-01, 2026-03-31] and corporate_actions returns zero rows. Zero rows could mean no dividend occurred, or it could mean corporate actions were never synced.
risk/completeness.py closes this hole with verify_completeness():
- Explicit evidence for the instrument and event family (
corporate_actionsorfund_distributions) must exist incompleteness.json. - That evidence must itself satisfy
available_at <= as_ofand belong toSTRICT_PIT_QUALITY_STATUS. - The merged
[coverage_start, coverage_end]intervals of admitted evidence must cover[window_start, window_end]with zero gaps.
Without valid coverage — or whenever any event inside the window is excluded by PIT — formal total-return metrics return null with unsupported_total_return (without leaking excluded event details), falling back to clearly labeled price-only series.
Final Summary Table
At 2026-04-01 15:00 +08:00, here is the complete verdict across all 6 synthetic rows:
| Record | Market Mode (as_of = Apr 1 15:00) | System Mode (+ system_as_of = Apr 1 15:00) | Reason Code |
|---|---|---|---|
R1 (Mar 31 close 4.10) | Admitted | Admitted | OK |
R2 (Apr 1 close 4.18) | Rejected | Rejected | AVAILABLE_AFTER_AS_OF |
R3 (FY2025 report, disclosed Apr 20) | Rejected | Rejected | AVAILABLE_AFTER_AS_OF |
R4a (Bond r1 5.00%, fetched Jul 1) | Admitted (fallback) | Rejected | Market OK / System RETRIEVED_AFTER_SYSTEM_AS_OF |
R4b (Bond r2 6.00%, revised Jun 15) | Rejected | Rejected | AVAILABLE_AFTER_AS_OF |
R5 (Legacy report, available_at=NULL) | Rejected | Rejected | AVAILABILITY_UNKNOWN |
Once economic date, disclosure time, availability time, and ingestion time stop sharing one column — and once revision chains, window endpoints, and event completeness fail closed — almost all accidental lookahead bias disappears before a single strategy metric is printed.
For how these gates pair with Frozen Bundle v3 semantic-hash replay, see the AI-Portfolio Research project page or inspect the source in ai-portfolio-research.