NSE_AI_Stock_Analyzer / fundamental_agent.py
nitishkarvekar's picture
Update fundamental_agent.py
35ca926 verified
raw
history blame contribute delete
811 Bytes
import yfinance as yf
def analyze_fundamentals(tickers):
results = {}
for ticker in tickers:
score = 0
try:
info = yf.Ticker(ticker).info
pe = info.get("trailingPE")
roe = info.get("returnOnEquity")
debt = info.get("debtToEquity")
margin = info.get("profitMargins")
growth = info.get("earningsGrowth")
if pe and pe < 40:
score += 1
if roe and roe > 0.15:
score += 1
if debt and debt < 1:
score += 1
if margin and margin > 0.1:
score += 1
if growth and growth > 0.1:
score += 1
except:
pass
results[ticker] = score
return results