diff options
| author | Tyler <tyler@tylerhoang.xyz> | 2026-05-17 01:10:49 -0700 |
|---|---|---|
| committer | Tyler <tyler@tylerhoang.xyz> | 2026-05-17 01:10:49 -0700 |
| commit | 722ab4f3e3ba895879191e2be3c5361fb755a786 (patch) | |
| tree | 59a0ab2f2c77fb9926f8e6c3c2f69681be604df4 /components | |
| parent | c48218eae73f1a07fd23496837cc030d82845353 (diff) | |
Fix yield divisors and cold-cache UX in macro tab
All four treasury yield symbols return values already in percent;
the old /10 and /100 divisors were displaying ~0.04–0.46% instead
of the correct 3–5% range. Also rename ambiguous `l` variable and
add a spinner for the cold-cache load.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'components')
| -rw-r--r-- | components/macro.py | 22 |
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;" |
