Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to find individual company ticker from CIK value #141

Merged
merged 4 commits into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading