diff options
| author | Tyler <tyler@tylerhoang.xyz> | 2026-04-02 00:10:06 -0700 |
|---|---|---|
| committer | Tyler <tyler@tylerhoang.xyz> | 2026-04-02 00:10:06 -0700 |
| commit | 7a267bc3c28bc7a77e84eaa400667a7b4c0d5adf (patch) | |
| tree | 51b65d0ad1f1eaa1f276372a48cb319529284bb9 /services/data_service.py | |
| parent | 3806bd3b4d69917f3f5312acfa57bc4ee2886a49 (diff) | |
Refactor valuation models tab
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. |
