fred-loader 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fred_loader/__init__.py +96 -0
- fred_loader/load.py +143 -0
- fred_loader/macro_scores.py +833 -0
- fred_loader/series.py +553 -0
- fred_loader/utils.py +303 -0
- fred_loader-0.1.0.dist-info/METADATA +64 -0
- fred_loader-0.1.0.dist-info/RECORD +10 -0
- fred_loader-0.1.0.dist-info/WHEEL +5 -0
- fred_loader-0.1.0.dist-info/licenses/LICENSE +21 -0
- fred_loader-0.1.0.dist-info/top_level.txt +1 -0
fred_loader/__init__.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""A readable Python interface to the FRED macro data API."""
|
|
2
|
+
|
|
3
|
+
from .load import pull_fred
|
|
4
|
+
from .macro_scores import available_scores, list_scored_columns, score
|
|
5
|
+
from .utils import Config, available, info, resolve_series, search
|
|
6
|
+
|
|
7
|
+
# Categories
|
|
8
|
+
from .series import INFLATION, OUTPUT, LABOR, RATES, MONEY, HOUSING, CONSUMER
|
|
9
|
+
from .series import TRADE, FINANCIAL, FISCAL, COMMODITIES, INEQUALITY, SEP, DEMOGRAPHICS
|
|
10
|
+
from .series import ALL_SERIES, CATEGORIES, SUBCATEGORIES
|
|
11
|
+
|
|
12
|
+
# Subcategories (importable directly, per the series catalog docs)
|
|
13
|
+
from .series import CPI, PCE, PPI, IMPORT_EXPORT_PRICES, INFLATION_EXPECTATIONS
|
|
14
|
+
from .series import GDP, PRODUCTION, BUSINESS_SURVEYS
|
|
15
|
+
from .series import EMPLOYMENT, UNEMPLOYMENT, JOLTS, PRODUCTIVITY
|
|
16
|
+
from .series import FED_FUNDS, OVERNIGHT_RATES, TREASURIES, YIELD_SPREADS
|
|
17
|
+
from .series import CREDIT_SPREADS, OTHER_RATES
|
|
18
|
+
from .series import MONEY_SUPPLY, BANK_CREDIT, CONSUMER_CREDIT
|
|
19
|
+
from .series import HOME_PRICES, HOUSING_ACTIVITY, HOUSING_INVENTORY
|
|
20
|
+
from .series import CONSUMER_SPENDING, CONSUMER_INCOME
|
|
21
|
+
from .series import TRADE_BALANCE, DOLLAR_INDICES, EXCHANGE_RATES
|
|
22
|
+
from .series import EQUITY_MARKETS, VOLATILITY, FINANCIAL_CONDITIONS
|
|
23
|
+
from .series import FEDERAL_DEBT, FEDERAL_BUDGET
|
|
24
|
+
from .series import ENERGY, METALS, AGRICULTURE, COMMODITY_INDICES
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
# Entry points and configuration
|
|
28
|
+
"pull_fred",
|
|
29
|
+
"Config",
|
|
30
|
+
"score",
|
|
31
|
+
"available_scores",
|
|
32
|
+
"list_scored_columns",
|
|
33
|
+
# Discovery: browse and search the catalog without reading series.py
|
|
34
|
+
"available",
|
|
35
|
+
"search",
|
|
36
|
+
"info",
|
|
37
|
+
"resolve_series",
|
|
38
|
+
# Composites and lookups
|
|
39
|
+
"ALL_SERIES",
|
|
40
|
+
"CATEGORIES",
|
|
41
|
+
"SUBCATEGORIES",
|
|
42
|
+
# Categories
|
|
43
|
+
"INFLATION",
|
|
44
|
+
"OUTPUT",
|
|
45
|
+
"LABOR",
|
|
46
|
+
"RATES",
|
|
47
|
+
"MONEY",
|
|
48
|
+
"HOUSING",
|
|
49
|
+
"CONSUMER",
|
|
50
|
+
"TRADE",
|
|
51
|
+
"FINANCIAL",
|
|
52
|
+
"FISCAL",
|
|
53
|
+
"COMMODITIES",
|
|
54
|
+
"INEQUALITY",
|
|
55
|
+
"SEP",
|
|
56
|
+
"DEMOGRAPHICS",
|
|
57
|
+
# Subcategories
|
|
58
|
+
"CPI",
|
|
59
|
+
"PCE",
|
|
60
|
+
"PPI",
|
|
61
|
+
"IMPORT_EXPORT_PRICES",
|
|
62
|
+
"INFLATION_EXPECTATIONS",
|
|
63
|
+
"GDP",
|
|
64
|
+
"PRODUCTION",
|
|
65
|
+
"BUSINESS_SURVEYS",
|
|
66
|
+
"EMPLOYMENT",
|
|
67
|
+
"UNEMPLOYMENT",
|
|
68
|
+
"JOLTS",
|
|
69
|
+
"PRODUCTIVITY",
|
|
70
|
+
"FED_FUNDS",
|
|
71
|
+
"OVERNIGHT_RATES",
|
|
72
|
+
"TREASURIES",
|
|
73
|
+
"YIELD_SPREADS",
|
|
74
|
+
"CREDIT_SPREADS",
|
|
75
|
+
"OTHER_RATES",
|
|
76
|
+
"MONEY_SUPPLY",
|
|
77
|
+
"BANK_CREDIT",
|
|
78
|
+
"CONSUMER_CREDIT",
|
|
79
|
+
"HOME_PRICES",
|
|
80
|
+
"HOUSING_ACTIVITY",
|
|
81
|
+
"HOUSING_INVENTORY",
|
|
82
|
+
"CONSUMER_SPENDING",
|
|
83
|
+
"CONSUMER_INCOME",
|
|
84
|
+
"TRADE_BALANCE",
|
|
85
|
+
"DOLLAR_INDICES",
|
|
86
|
+
"EXCHANGE_RATES",
|
|
87
|
+
"EQUITY_MARKETS",
|
|
88
|
+
"VOLATILITY",
|
|
89
|
+
"FINANCIAL_CONDITIONS",
|
|
90
|
+
"FEDERAL_DEBT",
|
|
91
|
+
"FEDERAL_BUDGET",
|
|
92
|
+
"ENERGY",
|
|
93
|
+
"METALS",
|
|
94
|
+
"AGRICULTURE",
|
|
95
|
+
"COMMODITY_INDICES",
|
|
96
|
+
]
|
fred_loader/load.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FRED Loader — Public API
|
|
3
|
+
=========================
|
|
4
|
+
|
|
5
|
+
Single entry point for pulling, resampling, and scoring FRED macro data.
|
|
6
|
+
|
|
7
|
+
Quick start::
|
|
8
|
+
|
|
9
|
+
from fred_loader import pull_fred
|
|
10
|
+
|
|
11
|
+
# Full ~80-series macro dataset with scores
|
|
12
|
+
df = pull_fred("fred_master.csv", output_path="./data")
|
|
13
|
+
|
|
14
|
+
Cherry-pick series categories::
|
|
15
|
+
|
|
16
|
+
from fred_loader import pull_fred, INFLATION, LABOR, RATES
|
|
17
|
+
|
|
18
|
+
df = pull_fred(
|
|
19
|
+
"policy_inputs.csv",
|
|
20
|
+
output_path="./data",
|
|
21
|
+
series={**INFLATION, **LABOR, **RATES},
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
Available categories::
|
|
25
|
+
|
|
26
|
+
INFLATION — CPI, PCE, breakevens, inflation expectations
|
|
27
|
+
OUTPUT — GDP (nominal/real), industrial production, vehicle sales
|
|
28
|
+
LABOR — unemployment, payrolls, claims, earnings, JOLTS, LFPR
|
|
29
|
+
RATES — fed funds, Treasury curve, yield spreads, credit spreads, mortgage
|
|
30
|
+
MONEY — M2, reserves, commercial loans, consumer credit
|
|
31
|
+
HOUSING — Case-Shiller, starts, permits, existing sales, months of supply
|
|
32
|
+
CONSUMER — Michigan sentiment, retail sales, PCE, savings rate
|
|
33
|
+
TRADE — trade balance, trade-weighted dollar
|
|
34
|
+
FINANCIAL — VIX, S&P 500, NFCI, St. Louis financial stress
|
|
35
|
+
FISCAL — federal debt, surplus/deficit, monthly Treasury statement
|
|
36
|
+
INEQUALITY — Gini index
|
|
37
|
+
SEP — FOMC dot-plot medians (fed funds, GDP, unemployment, PCE)
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
import pandas as pd
|
|
41
|
+
from .utils import Config, load_fred_master
|
|
42
|
+
from .macro_scores import score
|
|
43
|
+
|
|
44
|
+
# Re-export every category so users only need `from fred_loader import ...`
|
|
45
|
+
from .series import ( # noqa: F401
|
|
46
|
+
INFLATION,
|
|
47
|
+
OUTPUT,
|
|
48
|
+
LABOR,
|
|
49
|
+
RATES,
|
|
50
|
+
MONEY,
|
|
51
|
+
HOUSING,
|
|
52
|
+
CONSUMER,
|
|
53
|
+
TRADE,
|
|
54
|
+
FINANCIAL,
|
|
55
|
+
FISCAL,
|
|
56
|
+
INEQUALITY,
|
|
57
|
+
SEP,
|
|
58
|
+
ALL_SERIES,
|
|
59
|
+
CATEGORIES,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def pull_fred(config: Config, apply_scores: bool = False) -> pd.DataFrame | None:
|
|
64
|
+
"""
|
|
65
|
+
Pull FRED data, resample to a uniform frequency, and optionally score.
|
|
66
|
+
|
|
67
|
+
Parameters
|
|
68
|
+
----------
|
|
69
|
+
filename : str
|
|
70
|
+
Name of the output CSV (e.g. ``"fred_master.csv"``).
|
|
71
|
+
|
|
72
|
+
output_path : str or Path, default ``"./data"``
|
|
73
|
+
Directory where the CSV will be written.
|
|
74
|
+
|
|
75
|
+
start : str, default ``"1990-01-01"``
|
|
76
|
+
Earliest observation date to request from FRED (``'YYYY-MM-DD'``).
|
|
77
|
+
|
|
78
|
+
resample_rule : str, default ``"W-FRI"``
|
|
79
|
+
Pandas offset alias that controls output frequency.
|
|
80
|
+
``"W-FRI"`` = weekly ending Friday. Other useful values:
|
|
81
|
+
``"MS"`` (month start), ``"ME"`` (month end), ``"QE"`` (quarter end).
|
|
82
|
+
|
|
83
|
+
mean_freqs : set of str, optional
|
|
84
|
+
Native-frequency codes whose series are averaged when resampling
|
|
85
|
+
(e.g. ``{"D"}`` averages daily series into weekly buckets).
|
|
86
|
+
All other frequencies take the last observation per period.
|
|
87
|
+
Defaults to ``{"D"}``.
|
|
88
|
+
|
|
89
|
+
series : dict, optional
|
|
90
|
+
Custom series catalog. Keys are FRED series IDs, values are
|
|
91
|
+
``(friendly_name, native_frequency)`` tuples. Build one by
|
|
92
|
+
merging category dicts::
|
|
93
|
+
|
|
94
|
+
from fred_loader import INFLATION, LABOR, RATES
|
|
95
|
+
series = {**INFLATION, **LABOR, **RATES}
|
|
96
|
+
|
|
97
|
+
When ``None`` (default), the full built-in catalog is used.
|
|
98
|
+
|
|
99
|
+
apply_scores : bool, default ``True``
|
|
100
|
+
When ``True``, run the macro scoring layer (derived series,
|
|
101
|
+
regime flags, continuous scores, and lead/lag signals).
|
|
102
|
+
Set ``False`` to get only the raw FRED data.
|
|
103
|
+
|
|
104
|
+
inflation_target : float, default ``2.0``
|
|
105
|
+
Fed inflation target (percent) used in Taylor rule, mandate
|
|
106
|
+
tension, and expectations-anchoring scores.
|
|
107
|
+
|
|
108
|
+
nairu : float, default ``4.0``
|
|
109
|
+
Natural rate of unemployment (percent) used in Taylor rule
|
|
110
|
+
and employment-pressure scores.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
pd.DataFrame
|
|
115
|
+
Wide DataFrame with one column per series (plus scored columns
|
|
116
|
+
if ``apply_scores=True``), indexed by date.
|
|
117
|
+
"""
|
|
118
|
+
cfg = config if isinstance(config, Config) else None
|
|
119
|
+
if cfg is None:
|
|
120
|
+
print("Incorrect Configuration Format.")
|
|
121
|
+
return None
|
|
122
|
+
if cfg.SERIES != ALL_SERIES:
|
|
123
|
+
print("Custom series catalog provided. Pulling subset of FRED data.")
|
|
124
|
+
|
|
125
|
+
raw = load_fred_master(config=config)
|
|
126
|
+
|
|
127
|
+
if apply_scores:
|
|
128
|
+
output = score(
|
|
129
|
+
raw,
|
|
130
|
+
pi_star=config.INFLATION_TARGET,
|
|
131
|
+
u_star=config.NATURAL_RATE_UNEMPLOYMENT,
|
|
132
|
+
)
|
|
133
|
+
else:
|
|
134
|
+
output = raw
|
|
135
|
+
# ── Save ──────────────────────────────────────────────────────────────
|
|
136
|
+
# set reference to project root (for reproducibility across environments) and ensure output dir exists
|
|
137
|
+
|
|
138
|
+
config.OUTPUT_PATH.mkdir(parents=True, exist_ok=True)
|
|
139
|
+
out_file = config.OUTPUT_PATH / config.FILENAME
|
|
140
|
+
output.to_csv(out_file)
|
|
141
|
+
|
|
142
|
+
print(f"\nSaved → {out_file}")
|
|
143
|
+
return output
|