quantlab.dataset.fred#
Single-symbol panel of one FRED interest-rate series, such as the 3-month T-bill rate.
FRED (Federal Reserve Economic Data, St. Louis Fed) publishes each series
as one value per observation date. FredAcquisition
(quantlab.acquisition.fred) downloads a series into the usual daily raw
tier, month=YYYY-MM/ parquet shards whose symbol is the series id
and whose value is the published number, NaN where FRED has none (a
holiday). FredRateDataset turns one series of that tier into a panel
with one symbol, the series id, on the dates FRED published a value for (a
holiday FRED lists without one is no bar: a factor merging the rate with
stock prices counts its warm-up on the merged calendar, and holiday bars
would shorten it):
rate: the value as published, in annualized percent;risk_free:rate / 100 / days_per_year, a decimal return per bar (per trading day with the default 252), which a factor subtracts from stock returns.
The panel has one symbol so that it is stored once; a factor that needs the rate on every stock broadcasts it across symbols itself. The rate of a day is published the next business day (H.15), so a factor that must not look ahead lags it one bar; the dataset does not.
Examples#
Download DTB3 (no API key) and build its store:
from quantlab.acquisition.config import AcquisitionConfig
from quantlab.acquisition.fred import FredAcquisition
FredAcquisition(AcquisitionConfig(
market="us_equity", frequency="1d", vendor="fred",
raw_data_dir_path="/data/quantlab/downloads/us_equity/1d/macro/fred",
watermark_path="/data/quantlab/downloads/us_equity/1d/macro/_watermarks/fred",
symbols=("DTB3",), start_date="1954-01-04",
)).download()
config = FredRateConfig(
zarr_file_path="/data/quantlab/market/fred/fred_dtb3_1d/fred_dtb3_1d.zarr",
raw_data_dir_path="/data/quantlab/downloads/us_equity/1d/macro/fred",
)
FredRateDataset(config).update()
FredRateDataset(config).panel("2024-01-02", "2024-12-31")["risk_free"]
Classes
Single-symbol daily panel of one FRED rate series: |