finance-yahoo-data / README.md
ZipLime's picture
Add ziplime PIT dataset: docs, manifest, recipe, ingest, workflow, bundle
6ed0b9a verified
|
Raw
History Blame Contribute Delete
6.29 kB
metadata
license: other
language:
  - en
pretty_name: Yahoo Equity Daily Bars (PIT)
tags:
  - point-in-time
  - pit
  - ziplime
  - backtesting
  - alternative-data
  - finance
  - us_equities
task_categories:
  - time-series-forecasting
size_categories:
  - n<1K
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/data_bundle/**/*.parquet

πŸ“ˆ Yahoo Equity Daily Bars (PIT)

Daily OHLCV bars for US equities, delivered as a point-in-time ziplime bundle.

Part of the ziplime Point-in-Time (PIT) data layer β€” append-only datasets with an explicit split between when a fact happened (event_date) and when it became known (knowledge_date). A simulation at time T can only ever observe rows with knowledge_date <= T, so restatements, publication lag and hindsight can't leak into a backtest. The identical code path runs live with T = now.

  • Data class: Market data β€” daily equity OHLCV
  • Entity domain: us_equities β€” US-listed equity, keyed by ticker (resolves via the entity_map dataset).
  • Origin: Yahoo Finance (yfinance), auto-adjusted daily bars
  • License: Yahoo Finance terms β€” research use only
  • Update cadence: every US trading day, shortly after the 16:00 ET close (0 22 * * 1-5)
  • Format: ziplime Delta Lake bundle (data_type: PIT_DATA)

Why point-in-time?

Backtests on non-price data are systematically optimistic when the data layer has no notion of when a fact became known. Three failure modes this dataset is built to avoid:

  1. Restatements β€” a value reported one quarter and revised the next. Storing only the final value lets a backtest "know" the revision months early.
  2. Publication lag β€” fundamentals keyed by fiscal-period-end, joined to prices at period end rather than the (weeks-later) filing date.
  3. Hindsight in derived signals β€” a recent model scoring old text has already seen how the story ended.

All three are the same bug, and it is fixed in the data layer, not in strategy code.

Schema

System columns (every PIT dataset)

Column Type Semantics
entity_id Utf8 Stable entity identifier (resolved via the entity_map PIT dataset)
event_date Timestamp(UTC, Β΅s) The moment the fact refers to
knowledge_date Timestamp(UTC, Β΅s) The moment it became publicly known β€” the only column the as-of filter uses
knowledge_estimated Boolean true if knowledge_date was reconstructed by a lag model rather than taken from the source
ingested_at Timestamp(UTC, Β΅s) When our pipeline wrote the row (audit only; never used in as-of)

Value columns (this dataset)

Column Type Description
open Float64 Session open (auto-adjusted)
high Float64 Session high
low Float64 Session low
close Float64 Session close (auto-adjusted)
volume Float64 Session volume
price Float64 Convenience alias of close

The logical key of a fact is (entity_id, event_date). A revision is a new row with the same key and a later knowledge_date. Written rows are immutable; history is never rewritten.

As-of access

Inside a ziplime strategy there is no T parameter β€” the knowledge moment always equals the simulation clock (live: wall clock):

async def initialize(context):
    context.ds = await context.pit("finance-yahoo-data")

async def handle_data(context, data):
    # only rows with knowledge_date <= current simulation time are visible
    latest = await context.ds.latest(
        assets=[context.asset], fields=['open', 'high']
    )
    history = await context.ds.as_of(
        assets=[context.asset], fields=['open'],
        event_range=("2022-01-01", None),
    )

Reading it outside ziplime (plain Polars + delta-rs)

import polars as pl

T = "2025-06-01T00:00:00Z"          # "what was known at T"
lf = pl.scan_delta("hf://datasets/ZipLime/finance-yahoo-data/data/data_bundle/yahoo_finance_daily_data/1784755946/data.delta")
as_of = (
    lf.filter(pl.col("knowledge_date") <= T)
      .sort("knowledge_date")
      .group_by(["entity_id", "event_date"], maintain_order=True)
      .last()
)
print(as_of.collect())

Delta time-travel (AS OF <version>) pins the table for reproducibility; the knowledge_date <= T filter is what enforces point-in-time. They compose: a backtest records (dataset, delta_version) and replays read the table at that version and apply the filter.

Updates

recipe.py implements the collection contract fetch(since: datetime) -> pl.DataFrame in the PIT schema above; ingest.py dedups and appends to the Delta bundle (never rewrites). The scheduled job in .github/workflows/update.yml runs it every US trading day, shortly after the 16:00 ET close.

# recipe.py (contract)
async def fetch(since: datetime) -> "pl.DataFrame": ...

Knowledge-date convention

For quotes knowledge_date β‰ˆ event_date: a daily bar is only complete once its session closes, so it is stamped visible from the close of that session. OHLCV is the one class the design doc keeps out of full PIT treatment β€” this dataset is the bootstrap bundle that seeds the format.

What's in this repo

README.md                     # this card
manifest.json                 # PIT dataset manifest (schema, source, schedule)
recipe.py                     # fetch(since) -> PIT rows
ingest.py                     # dedup + append-only Delta writer
.github/workflows/update.yml  # scheduled ingestion
data/                         # ziplime Delta bundle + registry manifest
  bundle_registry/yahoo_finance_daily_data_1784755946.json
  data_bundle/yahoo_finance_daily_data/1784755946/data.delta/

The data/ bundle is a ready-to-load ziplime Delta Lake market-data bundle (five US equity tickers, daily bars) that seeds the pipeline and lets you exercise the loader end-to-end today. Point pl.scan_delta (above) at it, or register it with ziplime's FileSystemBundleRegistry.


Generated for the ziplime PIT data-layer prototype. Manifest and schema follow the ziplime PIT spec; source.* fields declare origin and license per the dataset manifest.