File size: 1,339 Bytes
d825735
 
 
bc87714
d825735
 
 
 
 
 
 
 
bc87714
 
d825735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import yfinance as yf
import pandas as pd
from pytickersymbols import PyTickerSymbols
from config import ticker_dict

def get_stocks_from_index(idx):
    stock_data = PyTickerSymbols()
    index = ticker_dict[idx]
    stocks = list(stock_data.get_stocks_by_index(index))
    stock_names = [f"{stock['name']}:{stock['symbol']}" for stock in stocks]
    return stock_names

def get_stock_data(ticker_name, interval, start_date, end_date):
    series = yf.download(tickers=ticker_name, start=start_date, end=end_date, interval=interval)
    return series.reset_index()

def get_company_info(ticker):
    stock = yf.Ticker(ticker)
    info = stock.info
    
    fundamentals = {
        "Company Name": info.get("longName", "N/A"),
        "Sector": info.get("sector", "N/A"),
        "Industry": info.get("industry", "N/A"),
        "Market Cap": f"${info.get('marketCap', 'N/A'):,}",
        "P/E Ratio": round(info.get("trailingPE", 0), 2),
        "EPS": round(info.get("trailingEps", 0), 2),
        "52 Week High": f"${info.get('fiftyTwoWeekHigh', 'N/A'):,}",
        "52 Week Low": f"${info.get('fiftyTwoWeekLow', 'N/A'):,}",
        "Dividend Yield": f"{info.get('dividendYield', 0) * 100:.2f}%",
        "Beta": round(info.get("beta", 0), 2),
    }
    
    return pd.DataFrame(list(fundamentals.items()), columns=['Metric', 'Value'])