| """ |
| Yahoo Equity Daily Bars (PIT) — collection recipe. |
| |
| Contract (ziplime PIT recipe, design doc §9): |
| |
| async def fetch(since: datetime) -> pl.DataFrame |
| |
| Returns rows in the PIT schema for `finance-yahoo-data`: |
| system: entity_id, event_date, knowledge_date, knowledge_estimated |
| values: open, high, low, close, volume, price |
| |
| The shared harness (ingest.py) stamps `ingested_at`, dedups against existing rows and |
| appends to the Delta bundle. This recipe only fetches and shapes. |
| """ |
| from __future__ import annotations |
| from datetime import datetime, timezone |
|
|
|
|
| async def fetch(since: datetime): |
| import polars as pl |
| import yfinance as yf |
| import polars as pl |
|
|
| universe = ["META", "AAPL", "AMZN", "NFLX", "GOOGL"] |
| raw = yf.download( |
| tickers=universe, interval="1d", start=since, threads=1, |
| group_by="Ticker", auto_adjust=True, multi_level_index=False, progress=False, |
| ) |
| frames = [] |
| for sym in universe: |
| d = pl.from_pandas(raw[sym], include_index=True).rename({ |
| "Date": "event_date", "Open": "open", "High": "high", |
| "Low": "low", "Close": "close", "Volume": "volume", |
| }) |
| d = d.with_columns( |
| pl.lit(sym).alias("entity_id"), |
| |
| pl.col("event_date").alias("knowledge_date"), |
| pl.lit(False).alias("knowledge_estimated"), |
| pl.col("close").alias("price"), |
| ) |
| frames.append(d) |
| return pl.concat(frames) |
|
|
|
|
| if __name__ == "__main__": |
| import asyncio, polars as pl |
| df = asyncio.run(fetch(datetime(2025, 1, 1, tzinfo=timezone.utc))) |
| print(df.head()) |
|
|