Spaces:
Sleeping
Sleeping
File size: 4,483 Bytes
0c591a7 | 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | """
Ticker Lookup - Maps company names to stock ticker symbols.
"""
import re
from typing import Optional
# Common company name to ticker mappings
TICKER_MAP = {
# Tech Giants
"apple": "AAPL",
"microsoft": "MSFT",
"google": "GOOGL",
"alphabet": "GOOGL",
"amazon": "AMZN",
"meta": "META",
"facebook": "META",
"nvidia": "NVDA",
"tesla": "TSLA",
"netflix": "NFLX",
"adobe": "ADBE",
"salesforce": "CRM",
"oracle": "ORCL",
"intel": "INTC",
"amd": "AMD",
"ibm": "IBM",
"cisco": "CSCO",
"qualcomm": "QCOM",
"broadcom": "AVGO",
"paypal": "PYPL",
"shopify": "SHOP",
"zoom": "ZM",
"uber": "UBER",
"lyft": "LYFT",
"airbnb": "ABNB",
"palantir": "PLTR",
"snowflake": "SNOW",
"crowdstrike": "CRWD",
"datadog": "DDOG",
# Finance
"jpmorgan": "JPM",
"jp morgan": "JPM",
"bank of america": "BAC",
"wells fargo": "WFC",
"goldman sachs": "GS",
"morgan stanley": "MS",
"citigroup": "C",
"visa": "V",
"mastercard": "MA",
"american express": "AXP",
"berkshire hathaway": "BRK.B",
"blackrock": "BLK",
"charles schwab": "SCHW",
# Healthcare
"johnson & johnson": "JNJ",
"johnson and johnson": "JNJ",
"pfizer": "PFE",
"unitedhealth": "UNH",
"eli lilly": "LLY",
"merck": "MRK",
"abbvie": "ABBV",
"bristol-myers squibb": "BMY",
"amgen": "AMGN",
"gilead": "GILD",
"moderna": "MRNA",
"regeneron": "REGN",
"biogen": "BIIB",
"cvs health": "CVS",
# Consumer
"walmart": "WMT",
"costco": "COST",
"home depot": "HD",
"target": "TGT",
"lowes": "LOW",
"nike": "NKE",
"starbucks": "SBUX",
"mcdonalds": "MCD",
"coca-cola": "KO",
"coca cola": "KO",
"pepsi": "PEP",
"pepsico": "PEP",
"procter & gamble": "PG",
"procter and gamble": "PG",
"disney": "DIS",
# Industrial
"boeing": "BA",
"caterpillar": "CAT",
"general electric": "GE",
"3m": "MMM",
"honeywell": "HON",
"lockheed martin": "LMT",
"raytheon": "RTX",
"union pacific": "UNP",
"ups": "UPS",
"fedex": "FDX",
# Energy
"exxon": "XOM",
"exxonmobil": "XOM",
"chevron": "CVX",
"conocophillips": "COP",
"schlumberger": "SLB",
# Telecom
"att": "T",
"at&t": "T",
"verizon": "VZ",
"t-mobile": "TMUS",
# Automotive
"ford": "F",
"general motors": "GM",
"rivian": "RIVN",
"lucid": "LCID",
}
def get_ticker(company_name: str) -> Optional[str]:
"""
Get stock ticker symbol from company name.
Args:
company_name: Company name (e.g., 'Tesla', 'Apple Inc.')
Returns:
Ticker symbol (e.g., 'TSLA', 'AAPL') or None if not found
"""
if not company_name:
return None
# Clean up the company name
name = company_name.lower().strip()
# Remove common suffixes
suffixes = [
" inc", " inc.", " incorporated",
" corp", " corp.", " corporation",
" ltd", " ltd.", " limited",
" llc", " plc", " co", " co.",
" company", " companies",
" holdings", " group"
]
for suffix in suffixes:
if name.endswith(suffix):
name = name[:-len(suffix)].strip()
# Check if input is already a ticker (all caps, 1-5 chars)
if re.match(r'^[A-Z]{1,5}$', company_name.strip()):
return company_name.strip().upper()
# Look up in mapping
if name in TICKER_MAP:
return TICKER_MAP[name]
# Try partial match
for key, ticker in TICKER_MAP.items():
if key in name or name in key:
return ticker
# If no match found, assume input might be ticker
clean = re.sub(r'[^A-Za-z]', '', company_name).upper()
if len(clean) <= 5:
return clean
return None
def normalize_company_name(company_name: str) -> str:
"""
Normalize company name for display.
Args:
company_name: Raw company name input
Returns:
Cleaned company name
"""
if not company_name:
return ""
# Title case
name = company_name.strip().title()
# Fix common acronyms
replacements = {
"Ibm": "IBM",
"Amd": "AMD",
"Att": "AT&T",
"Ups": "UPS",
"3M": "3M",
"Jp Morgan": "JPMorgan",
"Jpmorgan": "JPMorgan",
}
for old, new in replacements.items():
name = name.replace(old, new)
return name
|