File size: 1,527 Bytes
0feb7d3
32e8306
 
 
0feb7d3
32e8306
a83b72e
 
32e8306
 
0feb7d3
 
 
32e8306
 
0feb7d3
 
 
32e8306
0feb7d3
 
 
 
 
 
 
 
a83b72e
0feb7d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pandas as pd
import yfinance as yf

class FundamentalAnalyst:
    def analyze(self, ticker, session=None):
        try:
            # Removed session to allow YFinance to auto-manage connections
            stock = yf.Ticker(ticker)
            info = stock.info
            
            roe = info.get('returnOnEquity', 0) or 0
            pe = info.get('trailingPE', 0) or 100
            profit_growth = info.get('revenueGrowth', 0) or 0
            
            score = 0
            if roe > 0.15: score += 40
            if profit_growth > 0.10: score += 30
            if pe < 50: score += 30
            
            metrics = f"ROE: {roe*100:.1f}% | PE: {pe:.1f} | Growth: {profit_growth*100:.1f}%"
            return {"score": score, "metrics": metrics}
        except:
            return None

class TechnicalAnalyst:
    def analyze(self, ticker, session=None):
        try:
            stock = yf.Ticker(ticker)
            # Fetch 1 year of history
            hist = stock.history(period="1y")
            if hist.empty: return "NO DATA"
            
            # Simple Moving Averages
            sma_50 = hist['Close'].rolling(50).mean().iloc[-1]
            sma_200 = hist['Close'].rolling(200).mean().iloc[-1]
            price = hist['Close'].iloc[-1]
            
            trend = "SIDEWAYS"
            if price > sma_50 > sma_200: trend = "UPTREND"
            elif price < sma_50 < sma_200: trend = "DOWNTREND"
            
            return trend
        except:
            return "ERROR"