ekjotsingh commited on
Commit
0feb7d3
·
verified ·
1 Parent(s): 05ee76b

Update analysis.py

Browse files
Files changed (1) hide show
  1. analysis.py +36 -20
analysis.py CHANGED
@@ -1,29 +1,45 @@
 
1
  import yfinance as yf
2
- import os
3
- from huggingface_hub import InferenceClient
4
 
5
  class FundamentalAnalyst:
6
- def analyze(self, ticker):
7
  try:
8
- stock = yf.Ticker(ticker)
 
9
  info = stock.info
10
 
11
- # THE UNIVERSAL PHYSICS: ROE and Debt-to-Equity
12
- roe = info.get('returnOnEquity', 0)
13
- debt_to_eq = info.get('debtToEquity', 100)
14
- fcf = info.get('freeCashflow', 0)
15
 
16
  score = 0
17
- # Capital Allocation Check: Generating >15% on equity?
18
- if roe > 0.15: score += 50
19
- # Risk Premium Check: Is debt low?
20
- if debt_to_eq < 50: score += 25
21
- # Cash Engine: Is FCF positive?
22
- if fcf > 0: score += 25
23
 
24
- return {
25
- "score": score,
26
- "metrics": f"ROE: {roe*100:.1f}% | Debt/Eq: {debt_to_eq}",
27
- "physics": "Strong Capital Allocation" if score > 70 else "Weak Unit Economics"
28
- }
29
- except: return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
  import yfinance as yf
 
 
3
 
4
  class FundamentalAnalyst:
5
+ def analyze(self, ticker, session=None):
6
  try:
7
+ # Use session for requests if provided
8
+ stock = yf.Ticker(ticker, session=session)
9
  info = stock.info
10
 
11
+ # Physics of Finance (Hard Filters)
12
+ roe = info.get('returnOnEquity', 0) or 0
13
+ pe = info.get('trailingPE', 0) or 100
14
+ profit_growth = info.get('revenueGrowth', 0) or 0
15
 
16
  score = 0
17
+ if roe > 0.15: score += 40
18
+ if profit_growth > 0.10: score += 30
19
+ if pe < 50: score += 30
 
 
 
20
 
21
+ metrics = f"ROE: {roe*100:.1f}% | PE: {pe:.1f} | Growth: {profit_growth*100:.1f}%"
22
+ return {"score": score, "metrics": metrics}
23
+ except:
24
+ return None
25
+
26
+ class TechnicalAnalyst:
27
+ def analyze(self, ticker, session=None):
28
+ try:
29
+ stock = yf.Ticker(ticker, session=session)
30
+ # Fetch 1 year of history
31
+ hist = stock.history(period="1y")
32
+ if hist.empty: return "NO DATA"
33
+
34
+ # Simple Moving Averages
35
+ sma_50 = hist['Close'].rolling(50).mean().iloc[-1]
36
+ sma_200 = hist['Close'].rolling(200).mean().iloc[-1]
37
+ price = hist['Close'].iloc[-1]
38
+
39
+ trend = "SIDEWAYS"
40
+ if price > sma_50 > sma_200: trend = "UPTREND"
41
+ elif price < sma_50 < sma_200: trend = "DOWNTREND"
42
+
43
+ return trend
44
+ except:
45
+ return "ERROR"