aboutsummaryrefslogtreecommitdiff
path: root/components/macro.py
diff options
context:
space:
mode:
Diffstat (limited to 'components/macro.py')
-rw-r--r--components/macro.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/components/macro.py b/components/macro.py
index a166855..c8e8b0c 100644
--- a/components/macro.py
+++ b/components/macro.py
@@ -15,12 +15,11 @@ _INDICES = {
"VIX": "^VIX",
}
-# (symbol, divisor) — yfinance encodes yields as rate×divisor
_YIELDS = {
- "3M": ("^IRX", 100),
- "5Y": ("^FVX", 10),
- "10Y": ("^TNX", 10),
- "30Y": ("^TYX", 10),
+ "3M": "^IRX",
+ "5Y": "^FVX",
+ "10Y": "^TNX",
+ "30Y": "^TYX",
}
_SECTORS = {
@@ -74,15 +73,15 @@ def _get_macro_data() -> dict:
indices[name] = None
yields = {}
- for label, (sym, div) in _YIELDS.items():
+ for label, sym in _YIELDS.items():
try:
hist = yf.Ticker(sym).history(period="5d")
if hist.empty:
yields[label] = None
continue
closes = hist["Close"].dropna()
- curr = float(closes.iloc[-1]) / div
- prev = float(closes.iloc[-2]) / div if len(closes) >= 2 else None
+ curr = float(closes.iloc[-1])
+ prev = float(closes.iloc[-2]) if len(closes) >= 2 else None
yields[label] = {"rate": curr, "change_1d": (curr - prev) if prev is not None else None}
except Exception:
yields[label] = None
@@ -176,8 +175,8 @@ def _render_index_table(indices: dict) -> None:
def _render_yield_curve(yields: dict) -> None:
labels = list(yields.keys())
- rates = [yields[l]["rate"] if yields[l] else None for l in labels]
- valid = [(l, r) for l, r in zip(labels, rates) if r is not None]
+ rates = [yields[lbl]["rate"] if yields[lbl] else None for lbl in labels]
+ valid = [(lbl, r) for lbl, r in zip(labels, rates) if r is not None]
fig = go.Figure()
if valid:
@@ -283,7 +282,8 @@ def _render_sector_heatmap(sectors: dict) -> None:
# ── Public entry point ────────────────────────────────────────────────────────
def render_macro() -> None:
- data = _get_macro_data()
+ with st.spinner("Loading macro data…"):
+ data = _get_macro_data()
st.markdown(
"<h5 style='font-family:\"IBM Plex Sans\",sans-serif;font-size:10px;font-weight:600;"