diff options
Diffstat (limited to 'services/data_service.py')
| -rw-r--r-- | services/data_service.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/services/data_service.py b/services/data_service.py index c278a2f..e3f46cc 100644 --- a/services/data_service.py +++ b/services/data_service.py @@ -213,6 +213,22 @@ def get_insider_transactions(ticker: str) -> pd.DataFrame: @st.cache_data(ttl=3600) +def get_revenue_ttm(ticker: str) -> float | None: + """Return trailing-twelve-month revenue from the last 4 reported quarters.""" + try: + t = yf.Ticker(ticker.upper()) + inc_q = t.quarterly_income_stmt + if inc_q is None or inc_q.empty or "Total Revenue" not in inc_q.index: + return None + vals = inc_q.loc["Total Revenue"].iloc[:4].dropna() + if len(vals) != 4: + return None + return float(vals.sum()) + except Exception: + return None + + +@st.cache_data(ttl=3600) def compute_ttm_ratios(ticker: str) -> dict: """Compute all key financial ratios from raw yfinance quarterly statements. |
