markowitz.data_providers.polygon¶
markowitz.data_providers.polygon
¶
Polygon.io REST client for end-of-day OHLCV and reference data.
Public surface is :class:PolygonProvider, which exposes three methods used
elsewhere in this package:
- :meth:
get_eod— daily OHLCV for a single ticker over an inclusive window. - :meth:
get_ticker_meta— the/v3/reference/tickers/{ticker}payload. - :meth:
get_grouped_daily— every actively-traded US stock on a given date.
The grouped-daily snapshot is what makes the survivorship-bias-aware S&P 500 universe builder possible: it tells us which tickers had a real bar on the historical date, so we never request OHLCV for a symbol that was not yet trading (or had already been delisted).
Adjusted vs raw
Every aggregate request sets adjusted=true so split- and
dividend-adjusted prices are returned. This is the right default for total-
return research; consumers that need raw prices should construct their own
provider variant.
Rate-limit / retry
A sliding-window token bucket caps outbound traffic at ~100 requests per 60 seconds (the Polygon Starter tier ceiling). Each transient failure (HTTP 429 or 5xx, or a low-level network error) triggers exponential backoff with three attempts (1s, 2s, 4s plus jitter). The bucket is process-local; cross-process throttling would need an external store.
PolygonProvider(api_key: str | None = None, session: httpx.Client | None = None, rpm: int = _STARTER_RPM)
¶
Polygon.io REST adapter with point-in-time accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Polygon API key. If |
None
|
session
|
Client | None
|
Optional pre-built :class: |
None
|
rpm
|
int
|
Requests-per-minute ceiling for the token bucket. Defaults to the Polygon Starter tier limit of 100. |
_STARTER_RPM
|
Source code in src/markowitz/data_providers/polygon.py
get_eod(ticker: str, start: date, end: date) -> pd.DataFrame
¶
Return daily OHLCV for ticker in the inclusive window [start, end].
Output is TitleCase (Open/High/Low/Close/Volume) with a tz-naive
:class:~pandas.DatetimeIndex named Date. Close is split- and
dividend-adjusted (Polygon adjusted=true).
Source code in src/markowitz/data_providers/polygon.py
get_grouped_daily(date_: date) -> pd.DataFrame
¶
Grouped-daily snapshot of every actively-traded US stock on date_.
Index is the ticker symbol; columns are TitleCase OHLCV. Used by the S&P 500 universe builder to know which symbols actually traded on a given historical date.
Source code in src/markowitz/data_providers/polygon.py
get_ticker_meta(ticker: str) -> dict[str, Any]
¶
Return the /v3/reference/tickers/{ticker} payload as a dict.