File size: 1,686 Bytes
6ed0b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
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  # noqa: F401
    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"),
            # a daily bar is known at its own session close
            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())