Files
All-in-one-Financial-Analysis/atlas-terminal/server/services/sector_heatmap.py
T
shawnkim1997 38c56a5a43 feat: deliver multi-asset analytics, OCR exchange selection, and heatmap UX
Add asset-type aware market/overview flows, portfolio OCR reverse-engineering with exchange overrides, and interactive index heatmap features. Update README with recent updates and wire backend/frontend APIs for FX matrix, exchange options, and improved portfolio editing flows.

Made-with: Cursor
2026-03-21 17:08:00 +00:00

38 lines
1.0 KiB
Python

"""Sector performance heatmap service."""
from __future__ import annotations
SECTOR_ETFS = {
"Technology": "XLK",
"Healthcare": "XLV",
"Financials": "XLF",
"Consumer Disc.": "XLY",
"Industrials": "XLI",
"Energy": "XLE",
"Utilities": "XLU",
"Materials": "XLB",
"Real Estate": "XLRE",
"Comm. Services": "XLC",
"Consumer Staples": "XLP",
}
async def get_sector_heatmap() -> list[dict]:
"""Return daily percent change for major US sector ETFs."""
import yfinance as yf
results = []
for sector, etf in SECTOR_ETFS.items():
try:
hist = yf.Ticker(etf).history(period="2d")
if hist is None or len(hist) < 2:
continue
prev = float(hist["Close"].iloc[-2])
cur = float(hist["Close"].iloc[-1])
change = ((cur - prev) / prev * 100) if prev else 0.0
results.append({"sector": sector, "etf": etf, "change_pct": round(change, 2)})
except Exception:
continue
return results