Files
All-in-one-Financial-Analysis/views/tab10_kpi.py
T
shawnkim1997andClaude Opus 4.6 b2acda81ee feat: add Atlas Terminal — Next.js 14 + FastAPI full-stack migration
Complete migration from Streamlit to Next.js 14 App Router + FastAPI backend.

Frontend (Next.js 14):
- 10 pages: Overview, Research, Valuation, Technical, Markets, Earnings, News, Portfolio, Filings, Settings
- Terminal Noir dark theme with custom Tailwind config
- TradingView Lightweight Charts for candlestick/volume
- Valuation: DCF, Sensitivity Matrix, Monte Carlo, Tornado, Reverse DCF
- Financial Statements table with YoY growth badges and margin rows
- SEC EDGAR inline filing viewer with section tabs
- News split-view with iframe article embedding
- Technical Analysis with RSI, MACD, Bollinger, Fibonacci, Moving Averages
- Earnings beat/miss visualization
- AI Copilot chat panel with Gemini integration

Backend (FastAPI):
- 13 routers: market_data, financials, valuation, technical, earnings, insider, edgar, news, portfolio, analysis, chat, estimates, fx
- Services: DCF engine, Monte Carlo simulation, sensitivity analysis, risk metrics, SEC parser, technical indicators
- yfinance + yahooquery data sources with fallback pattern
- SQLite caching layer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 02:10:10 +00:00

67 lines
2.8 KiB
Python

"""
KPI section — AI-powered company-specific KPI analysis via Gemini.
Generates key performance indicators relevant to the company's industry.
"""
import streamlit as st
def render_kpi_section(ticker: str, sector: str, industry: str):
"""Render AI-generated KPI analysis for a company."""
st.markdown("---")
st.markdown("#### Company KPI Analysis (AI-Powered)")
st.caption(
"AI identifies and analyzes the most important KPIs for this company's "
"business model and industry."
)
google_api_key = (st.session_state.get("google_api_key") or "").strip()
if not google_api_key:
st.info("Enter your Google API Key in the sidebar to enable KPI analysis.")
return
kpi_key = f"kpi_analysis_{ticker}"
if st.button("Generate KPI Analysis", key=f"btn_kpi_{ticker}"):
with st.spinner("Analyzing company KPIs with Gemini..."):
try:
import google.generativeai as genai
from config.constants import GEMINI_MODEL
genai.configure(api_key=google_api_key)
model = genai.GenerativeModel(GEMINI_MODEL)
prompt = f"""You are a senior equity research analyst. For **{ticker}** (Sector: {sector}, Industry: {industry}), identify and analyze the **top 5 most critical KPIs** that investors should track.
For each KPI:
1. **KPI Name** — what it measures and why it matters for this specific company
2. **Current Context** — what investors should know about this metric's recent trajectory
3. **Industry Benchmark** — how to interpret good vs bad values
Format as a clean markdown list. Focus on KPIs that are:
- Specific to this company's business model (not generic financial ratios)
- Forward-looking indicators of growth or risk
- Examples: For NVIDIA → CUDA developer adoption, data center revenue mix, AI training chip market share
- Examples: For Starbucks → same-store sales growth, store count, average ticket size
Also include a brief section: "**Key Risks to Watch**" with 2-3 forward-looking risk indicators.
Keep under 500 words. Be specific and actionable."""
r = model.generate_content(
prompt,
generation_config={"temperature": 0.3, "max_output_tokens": 2048},
)
text = (r.text or "").strip()
if text:
st.session_state[kpi_key] = text
else:
st.error("Empty response from Gemini.")
except Exception as e:
err = str(e).lower()
if "429" in err or "resource" in err:
st.error("Rate limit. Please wait and retry.")
else:
st.error(f"Error: {e}")
if st.session_state.get(kpi_key):
st.markdown(st.session_state[kpi_key])