Spaces:
Sleeping
Sleeping
Initial: Gradio app + SEO-optimized README
Browse files- README.md +75 -8
- app.py +96 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,14 +1,81 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.
|
| 9 |
app_file: app.py
|
| 10 |
-
pinned:
|
| 11 |
license: cc-by-4.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: US Treasury Yield Curve Spread
|
| 3 |
+
emoji: 📉
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
python_version: '3.10'
|
| 9 |
app_file: app.py
|
| 10 |
+
pinned: true
|
| 11 |
license: cc-by-4.0
|
| 12 |
+
short_description: 2Y vs 10Y Treasury — recession indicator.
|
| 13 |
+
datasets:
|
| 14 |
+
- iizy/calcfi-open-data
|
| 15 |
+
tags:
|
| 16 |
+
- finance
|
| 17 |
+
- treasury
|
| 18 |
+
- yield-curve
|
| 19 |
+
- recession
|
| 20 |
+
- federal-reserve
|
| 21 |
+
- data-viz
|
| 22 |
+
- open-data
|
| 23 |
+
- gradio
|
| 24 |
---
|
| 25 |
|
| 26 |
+
# US Treasury Yield Curve Spread
|
| 27 |
+
|
| 28 |
+
[](https://doi.org/10.6084/m9.figshare.32332290)
|
| 29 |
+
[](https://doi.org/10.5281/zenodo.20302283)
|
| 30 |
+
[](https://creativecommons.org/licenses/by/4.0/)
|
| 31 |
+
|
| 32 |
+
Visualize the 2-year vs 10-year Treasury yield spread alongside the Federal Funds Rate. When the 10Y drops below the 2Y, the curve inverts — historically a leading indicator of US recessions with a 12-24 month lead time.
|
| 33 |
+
|
| 34 |
+
## Why these series matter
|
| 35 |
+
|
| 36 |
+
The 2s/10s yield curve has inverted before every US recession since 1955, with a single false signal in the mid-1960s. The inversion itself is not the cause; it is the bond market pricing in expected Fed rate cuts in response to slowing growth. The lead time from inversion to recession averages 14 months but has ranged from 6 to 24 months. Pair this with the Federal Funds Rate to see how Fed policy itself drives the front end of the curve.
|
| 37 |
+
|
| 38 |
+
A library of free, primary-source-cited financial calculators that use these macro indicators as inputs is available at [calcfi.app](https://calcfi.app).
|
| 39 |
+
|
| 40 |
+
## Methodology
|
| 41 |
+
|
| 42 |
+
- **Federal Funds Rate (Effective)** — Federal Reserve via FRED, series `DFF` — [https://fred.stlouisfed.org/series/DFF](https://fred.stlouisfed.org/series/DFF)
|
| 43 |
+
- **2-Year Treasury Constant Maturity** — US Treasury via FRED, series `DGS2` — [https://fred.stlouisfed.org/series/DGS2](https://fred.stlouisfed.org/series/DGS2)
|
| 44 |
+
- **10-Year Treasury Constant Maturity** — US Treasury via FRED, series `DGS10` — [https://fred.stlouisfed.org/series/DGS10](https://fred.stlouisfed.org/series/DGS10)
|
| 45 |
+
|
| 46 |
+
No smoothing, no imputation, no seasonal adjustment. Each observation passes through verbatim from the primary source. Provenance headers are preserved in the underlying [CalcFi Open Data](https://huggingface.co/datasets/iizy/calcfi-open-data) dataset.
|
| 47 |
+
|
| 48 |
+
## Data source
|
| 49 |
+
|
| 50 |
+
The Space loads data live from the CalcFi Open Data dataset on Hugging Face:
|
| 51 |
+
[`iizy/calcfi-open-data`](https://huggingface.co/datasets/iizy/calcfi-open-data).
|
| 52 |
+
|
| 53 |
+
The same dataset is mirrored with permanent DOIs at:
|
| 54 |
+
|
| 55 |
+
- Figshare: [10.6084/m9.figshare.32332290](https://doi.org/10.6084/m9.figshare.32332290)
|
| 56 |
+
- Zenodo (CERN-backed): [10.5281/zenodo.20302283](https://doi.org/10.5281/zenodo.20302283)
|
| 57 |
+
- OSF: [10.17605/OSF.IO/PUMKT](https://doi.org/10.17605/OSF.IO/PUMKT)
|
| 58 |
+
- Kaggle: [10.34740/kaggle/dsv/16356447](https://doi.org/10.34740/kaggle/dsv/16356447)
|
| 59 |
+
- Mendeley Data: [10.17632/jsnwhy6vjn.1](https://doi.org/10.17632/jsnwhy6vjn.1)
|
| 60 |
+
|
| 61 |
+
## Related Spaces
|
| 62 |
+
|
| 63 |
+
Part of a small collection of CalcFi Open Data interactive explorers:
|
| 64 |
+
|
| 65 |
+
- [US Mortgage Rate Explorer](https://huggingface.co/spaces/iizy/calcfi-mortgage-rate-explorer)
|
| 66 |
+
- [Inflation vs Wage Growth Tracker](https://huggingface.co/spaces/iizy/calcfi-inflation-wage-tracker)
|
| 67 |
+
- [US Treasury Yield Curve Spread](https://huggingface.co/spaces/iizy/calcfi-yield-curve-spread)
|
| 68 |
+
- [Fed Funds Rate Cycle Explorer](https://huggingface.co/spaces/iizy/calcfi-fed-funds-cycle)
|
| 69 |
+
- [Oil and Gas Price Tracker](https://huggingface.co/spaces/iizy/calcfi-oil-gas-tracker)
|
| 70 |
+
|
| 71 |
+
## Citation
|
| 72 |
+
|
| 73 |
+
> Salmisto, J. (2026). *CalcFi Open Data: 34 Free CC-BY Financial and Macro Time Series Mirrored from Primary Sources* [Dataset]. Figshare. https://doi.org/10.6084/m9.figshare.32332290
|
| 74 |
+
|
| 75 |
+
## License
|
| 76 |
+
|
| 77 |
+
Code: CC0 1.0. Data: CC BY 4.0 — attribution to [CalcFi](https://calcfi.app/developers) and the named primary source per series.
|
| 78 |
+
|
| 79 |
+
## Live tools
|
| 80 |
+
|
| 81 |
+
Free calculators that use these series as inputs at [calcfi.app](https://calcfi.app). No signup, every formula cited to a primary source.
|
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
US Treasury Yield Curve Spread — CalcFi Open Data.
|
| 3 |
+
|
| 4 |
+
Data loaded live from the CalcFi Open Data dataset on Hugging Face.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import pandas as pd
|
| 9 |
+
|
| 10 |
+
DATASET_BASE = (
|
| 11 |
+
"https://huggingface.co/datasets/iizy/calcfi-open-data/resolve/main/datasets"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
SERIES = [
|
| 15 |
+
{"slug": "federal-funds-rate", "label": "Federal Funds Rate"},
|
| 16 |
+
{"slug": "2-year-treasury", "label": "2-Year Treasury Yield"},
|
| 17 |
+
{"slug": "10-year-treasury", "label": "10-Year Treasury Yield"},
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def load_series(slug: str, label: str) -> pd.DataFrame:
|
| 22 |
+
url = f"{DATASET_BASE}/{slug}/data.csv"
|
| 23 |
+
df = pd.read_csv(url, comment="#", parse_dates=["date"])
|
| 24 |
+
df["series"] = label
|
| 25 |
+
return df[["date", "value", "series"]]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def load_all() -> pd.DataFrame:
|
| 29 |
+
frames = []
|
| 30 |
+
for s in SERIES:
|
| 31 |
+
try:
|
| 32 |
+
frames.append(load_series(s["slug"], s["label"]))
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"failed to load {s['slug']}: {e}")
|
| 35 |
+
if not frames:
|
| 36 |
+
return pd.DataFrame(columns=["date", "value", "series"])
|
| 37 |
+
return pd.concat(frames, ignore_index=True).sort_values("date")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def filter_view(start_year: int, end_year: int, selected_series: list[str]) -> pd.DataFrame:
|
| 41 |
+
df = load_all()
|
| 42 |
+
if start_year > end_year:
|
| 43 |
+
start_year, end_year = end_year, start_year
|
| 44 |
+
mask = (df["date"].dt.year >= start_year) & (df["date"].dt.year <= end_year)
|
| 45 |
+
df = df[mask]
|
| 46 |
+
if selected_series:
|
| 47 |
+
df = df[df["series"].isin(selected_series)]
|
| 48 |
+
return df
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
INITIAL_DF = load_all()
|
| 52 |
+
MIN_YEAR = int(INITIAL_DF["date"].dt.year.min()) if not INITIAL_DF.empty else 1970
|
| 53 |
+
MAX_YEAR = int(INITIAL_DF["date"].dt.year.max()) if not INITIAL_DF.empty else 2026
|
| 54 |
+
ALL_LABELS = [s["label"] for s in SERIES]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
with gr.Blocks(
|
| 58 |
+
title="US Treasury Yield Curve Spread — CalcFi Open Data",
|
| 59 |
+
theme=gr.themes.Soft(),
|
| 60 |
+
) as demo:
|
| 61 |
+
gr.Markdown("# US Treasury Yield Curve Spread")
|
| 62 |
+
gr.Markdown("Visualize the 2-year vs 10-year Treasury yield spread alongside the Federal Funds Rate. When the 10Y drops below the 2Y, the curve inverts — historically a leading indicator of US recessions with a 12-24 month lead time. Released under CC BY 4.0. Source dataset: [calcfi-open-data](https://huggingface.co/datasets/iizy/calcfi-open-data).")
|
| 63 |
+
|
| 64 |
+
with gr.Row():
|
| 65 |
+
with gr.Column(scale=1):
|
| 66 |
+
start_year = gr.Slider(
|
| 67 |
+
MIN_YEAR, MAX_YEAR, value=max(MIN_YEAR, MAX_YEAR - 25),
|
| 68 |
+
step=1, label="Start year",
|
| 69 |
+
)
|
| 70 |
+
end_year = gr.Slider(
|
| 71 |
+
MIN_YEAR, MAX_YEAR, value=MAX_YEAR, step=1, label="End year",
|
| 72 |
+
)
|
| 73 |
+
series_picker = gr.CheckboxGroup(
|
| 74 |
+
ALL_LABELS, value=ALL_LABELS, label="Series",
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
chart = gr.LinePlot(
|
| 78 |
+
filter_view(max(MIN_YEAR, MAX_YEAR - 25), MAX_YEAR, ALL_LABELS),
|
| 79 |
+
x="date",
|
| 80 |
+
y="value",
|
| 81 |
+
color="series",
|
| 82 |
+
title="US Treasury Yield Curve Spread",
|
| 83 |
+
x_title="Date",
|
| 84 |
+
y_title="Value",
|
| 85 |
+
height=500,
|
| 86 |
+
width=900,
|
| 87 |
+
tooltip=["date", "value", "series"],
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
inputs = [start_year, end_year, series_picker]
|
| 91 |
+
for inp in inputs:
|
| 92 |
+
inp.change(filter_view, inputs, chart)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
pandas>=2.0.0
|