Back to blog
Quant Research··6 min read

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.

#PIT#Backtesting#Lookahead Bias#Asset Allocation#Data Integrity
—views

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:

  1. Economic date (trade_date / report_period / nav_date): the day or fiscal period the value describes.
  2. Publication timestamp (published_at): when the exchange or issuer released it.
  3. Market availability timestamp (available_at / revision_available_at): when market participants could reliably observe and act on it.
  4. 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).

Rendering diagram…

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):

IDTable / SymbolEconomic DatePayloadavailable_at (+08:00)retrieved_at (+08:00)Quality / Verification
R1stock_daily (510300)2026-03-31Close 4.102026-03-31 18:002026-03-31 20:00estimated_daily_close_18h
R2stock_daily (510300)2026-04-01Close 4.182026-04-01 18:002026-04-01 19:10estimated_daily_close_18h
R3financial_statements (A001)2025-12-31FY2025 ROE 14.2%2026-04-21 18:00 (disclosed Apr 20, next-day 18:00)2026-04-21 21:00estimated_next_calendar_day_18h
R4abond_instrument_versions (BOND-01)Effective 2026-01-13r1 coupon 5.00%2026-01-13 18:002026-07-01 08:00verified (content_verified=true)
R4bbond_instrument_versions (BOND-01)Revises r2 → r1r2 coupon revised to 6.00%2026-06-15 18:00 (revision_available_at)2026-07-01 08:00verified (content_verified=true)
R5financial_statements (A002)2025-12-31Legacy import ROE 11.0%NULL (date-only legacy row)2026-03-25 10:00unknown_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:

  • R5 is rejected (AVAILABILITY_UNKNOWN): Even though it was ingested on March 25, a legacy row with available_at = NULL is never admitted as verified history.
  • R1 is admitted: 2026-03-31 18:00 <= 2026-04-01 15:00 with whitelisted quality. The strategy sees yesterday's close 4.10.
  • R2 is rejected (AVAILABLE_AFTER_AS_OF): Even though trade_date is 2026-04-01, the cleaned daily close is only guaranteed available at 18:00 — three hours after 15:00. If a strategy intends to trade on the next session using confirmed April 1 closes, it must explicitly set as_of after 2026-04-01 18:00 +08:00.
  • R3 is rejected (AVAILABLE_AFTER_AS_OF): Classic fundamental lookahead trap. The fiscal period ended 2025-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, coupon 6.00%) superseded R4a (r1, coupon 5.00%).
  • At as_of = 2026-04-01 15:00, R4b fails because revision_available_at = 2026-06-15 > as_of.
  • Overwriting r1 in place would leak June's 6.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 — returning R4a (5.00%) on April 1 and seamlessly switching to R4b (6.00%) once as_of moves past June 15 (e.g., 2026-08-01). And if someone tries to import a revision without a known revision_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.

ModeQuery ParametersIs R4a Visible on Apr 1?Question Answered
Market research mode (default)as_of = 2026-04-01 15:00Yes (5.00%)Could a market participant objectively know this on April 1?
System-knowledge modeas_of = 2026-04-01 15:00, system_as_of = 2026-04-01 15:00No (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():

  1. Explicit evidence for the instrument and event family (corporate_actions or fund_distributions) must exist in completeness.json.
  2. That evidence must itself satisfy available_at <= as_of and belong to STRICT_PIT_QUALITY_STATUS.
  3. 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:

RecordMarket Mode (as_of = Apr 1 15:00)System Mode (+ system_as_of = Apr 1 15:00)Reason Code
R1 (Mar 31 close 4.10)AdmittedAdmittedOK
R2 (Apr 1 close 4.18)RejectedRejectedAVAILABLE_AFTER_AS_OF
R3 (FY2025 report, disclosed Apr 20)RejectedRejectedAVAILABLE_AFTER_AS_OF
R4a (Bond r1 5.00%, fetched Jul 1)Admitted (fallback)RejectedMarket OK / System RETRIEVED_AFTER_SYSTEM_AS_OF
R4b (Bond r2 6.00%, revised Jun 15)RejectedRejectedAVAILABLE_AFTER_AS_OF
R5 (Legacy report, available_at=NULL)RejectedRejectedAVAILABILITY_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.