Skip to content

Commit

Permalink
Merge pull request #141 from webbsledge/main
Browse files Browse the repository at this point in the history
Added function to find individual company ticker from CIK value
  • Loading branch information
dgunning authored Nov 3, 2024
2 parents 63fb9b3 + 3887b55 commit 90fd1a9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions edgar/reference/tickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,44 @@ def find_company_cik(ticker):
ticker = ticker.upper().replace('.', '-')
return lookup.get(ticker)

def find_company_ticker(cik: Union[int, str]) -> Union[str, List[str], None]:
"""
Find the ticker for a given CIK.
:param cik (int or str): The CIK to look up
:return Union[str, List[str]]: A single ticker string if only one ticker is found,
a list of ticker strings if multiple tickers are found,
or an empty list if no tickers are found.
"""
try:
# Ensure cik is a string without leading zeros, then convert to int
cik = str(cik).lstrip('0')
cik = int(cik)
except (ValueError, TypeError):
return None

# Get DataFrame of CIK-Ticker mappings
df = get_cik_tickers()

# Ensure 'cik' and 'ticker' columns exist
if 'cik' not in df.columns or 'ticker' not in df.columns:
return None

# Filter DataFrame for the given CIK
ticker_series = df[df['cik'] == cik]['ticker']

# If no tickers found, return None
if ticker_series.empty:
return None

# Filter out None values from tickers
tickers = [ticker for ticker in ticker_series.values if ticker is not None]

# Return a single ticker if only one found
if len(tickers) == 1:
return tickers[0]

return tickers

def find_cik(ticker):
"""
Expand Down

0 comments on commit 90fd1a9

Please sign in to comment.