fred-loader 0.1.0__tar.gz
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-0.1.0/LICENSE +21 -0
- fred_loader-0.1.0/PKG-INFO +64 -0
- fred_loader-0.1.0/README.md +47 -0
- fred_loader-0.1.0/pyproject.toml +25 -0
- fred_loader-0.1.0/setup.cfg +4 -0
- fred_loader-0.1.0/src/fred_loader/__init__.py +96 -0
- fred_loader-0.1.0/src/fred_loader/load.py +143 -0
- fred_loader-0.1.0/src/fred_loader/macro_scores.py +833 -0
- fred_loader-0.1.0/src/fred_loader/series.py +553 -0
- fred_loader-0.1.0/src/fred_loader/utils.py +303 -0
- fred_loader-0.1.0/src/fred_loader.egg-info/PKG-INFO +64 -0
- fred_loader-0.1.0/src/fred_loader.egg-info/SOURCES.txt +16 -0
- fred_loader-0.1.0/src/fred_loader.egg-info/dependency_links.txt +1 -0
- fred_loader-0.1.0/src/fred_loader.egg-info/requires.txt +7 -0
- fred_loader-0.1.0/src/fred_loader.egg-info/top_level.txt +1 -0
- fred_loader-0.1.0/tests/test_discovery_and_resolver.py +157 -0
- fred_loader-0.1.0/tests/test_macro_scores.py +701 -0
- fred_loader-0.1.0/tests/test_pull_loop.py +354 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ian Solberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fred-loader
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python wrapper around the Federal Reserve FRED API that abstracts away series IDs, resampling rules, and macro scoring behind a clean, human-readable interface.
|
|
5
|
+
Author: Ian Solberg
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: fredapi
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Requires-Dist: python-dotenv
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# FRED_Loader
|
|
19
|
+
|
|
20
|
+
A Python wrapper around the Federal Reserve FRED API that abstracts away
|
|
21
|
+
series IDs, resampling rules, and macro scoring behind a clean,
|
|
22
|
+
human-readable interface. Installs as `fred-loader`, for anyone who pulls
|
|
23
|
+
macroeconomic data into pandas.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install fred-loader
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or from a checkout of this repository: `pip install -e .`.
|
|
32
|
+
|
|
33
|
+
## Quickstart
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from fred_loader import Config, pull_fred
|
|
37
|
+
|
|
38
|
+
cfg = Config(filename="fred_master.csv", output_path="./data")
|
|
39
|
+
df = pull_fred(cfg)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Cherry-pick series categories:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from fred_loader import INFLATION, LABOR, RATES, Config, pull_fred
|
|
46
|
+
|
|
47
|
+
cfg = Config(
|
|
48
|
+
filename="policy_inputs.csv",
|
|
49
|
+
output_path="./data",
|
|
50
|
+
series={**INFLATION, **LABOR, **RATES},
|
|
51
|
+
)
|
|
52
|
+
df = pull_fred(cfg)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Project structure
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
src/fred_loader/
|
|
59
|
+
__init__.py # public API re-exports
|
|
60
|
+
utils.py # Config
|
|
61
|
+
load.py # pull_fred entry point
|
|
62
|
+
series.py # series catalog: categories and subcategories
|
|
63
|
+
macro_scores.py # scoring layer: score, available_scores
|
|
64
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# FRED_Loader
|
|
2
|
+
|
|
3
|
+
A Python wrapper around the Federal Reserve FRED API that abstracts away
|
|
4
|
+
series IDs, resampling rules, and macro scoring behind a clean,
|
|
5
|
+
human-readable interface. Installs as `fred-loader`, for anyone who pulls
|
|
6
|
+
macroeconomic data into pandas.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install fred-loader
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or from a checkout of this repository: `pip install -e .`.
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from fred_loader import Config, pull_fred
|
|
20
|
+
|
|
21
|
+
cfg = Config(filename="fred_master.csv", output_path="./data")
|
|
22
|
+
df = pull_fred(cfg)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Cherry-pick series categories:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from fred_loader import INFLATION, LABOR, RATES, Config, pull_fred
|
|
29
|
+
|
|
30
|
+
cfg = Config(
|
|
31
|
+
filename="policy_inputs.csv",
|
|
32
|
+
output_path="./data",
|
|
33
|
+
series={**INFLATION, **LABOR, **RATES},
|
|
34
|
+
)
|
|
35
|
+
df = pull_fred(cfg)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Project structure
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
src/fred_loader/
|
|
42
|
+
__init__.py # public API re-exports
|
|
43
|
+
utils.py # Config
|
|
44
|
+
load.py # pull_fred entry point
|
|
45
|
+
series.py # series catalog: categories and subcategories
|
|
46
|
+
macro_scores.py # scoring layer: score, available_scores
|
|
47
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fred-loader"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Python wrapper around the Federal Reserve FRED API that abstracts away series IDs, resampling rules, and macro scoring behind a clean, human-readable interface."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Ian Solberg" }]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"fredapi",
|
|
16
|
+
"pandas",
|
|
17
|
+
"numpy",
|
|
18
|
+
"python-dotenv",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
dev = ["pytest"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
@@ -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
|
+
]
|
|
@@ -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
|