Map Tickers, CIKs, CUSIPs and Company Details with Python
In this guide, we will explore how to use Python to map and resolve ticker symbols, CIKs, and CUSIPs to company details, and vice versa. We will demonstrate how to find and list all companies and securities traded on NASDAQ, NYSE, and other exchanges. As an example, we will visualize the distribution of listings per sector and industry per exchange. Additionally, we will look into how to find and list all companies by sector and industry.
Map Tickers, CIKs, CUSIPs, and Company Details with Python
In this guide, we will explore how to use Python to map and resolve ticker symbols, CIKs, and CUSIPs to company details, and vice versa. We will demonstrate how to find and list all companies and securities traded on NASDAQ, NYSE, and other exchanges. As an example, we will visualize the distribution of listings per sector and industry per exchange. Additionally, we will look into how to find and list all companies by sector and industry.
Quick Start
The MappingApi
with its .resolve('ticker|cik|cusip|exchange', 'value')
function offers a straightforward interface for mapping
- tickers to CIKs and CUSIPS,
- CIKs to tickers and CUSIPS,
- CUSIPs to tickers and CIKs,
- and any of the above properties to its company name, its exchange, industry, sector, and currency, among others.
By using the .resolve()
function, we can obtain the corresponding information as a list of dictionaries, which can be easily loaded into a pandas dataframe and exported to Excel or CSV formats. The following code examples demonstrate how to use these options.
!pip install -q sec-api
from sec_api import MappingApi
mappingApi = MappingApi(api_key='YOUR_API_KEY')
# map ticker to CIK, CUSIP and company details
by_ticker = mappingApi.resolve('ticker', 'TSLA')
# map CIK to ticker, CUSIP and company details
by_cik = mappingApi.resolve('cik', '1318605')
# map CUSIP to ticker, CIK and company details
by_cusip = mappingApi.resolve('cusip', '88160R101')
# list on companies trading on the NASDAQ exchange
by_exchange = mappingApi.resolve('exchange', 'NASDAQ')
print('Ticker "TSLA" resolved to its company details')
print('---------------------------------------------')
by_ticker
Ticker "TSLA" resolved to its company details
---------------------------------------------
[{'name': 'TESLA INC',
'ticker': 'TSLA',
'cik': '1318605',
'cusip': '88160R101',
'exchange': 'NASDAQ',
'isDelisted': False,
'category': 'Domestic Common Stock',
'sector': 'Consumer Cyclical',
'industry': 'Auto Manufacturers',
'sic': '3711',
'sicSector': 'Manufacturing',
'sicIndustry': 'Motor Vehicles & Passenger Car Bodies',
'famaSector': '',
'famaIndustry': 'Automobiles and Trucks',
'currency': 'USD',
'location': 'California; U.S.A',
'id': 'eaeafc4ffc04a49da153adebf1f6960a'}]
import pandas as pd
by_ticker_goog = mappingApi.resolve('ticker', 'GOOG')
print('Ticker "GOOG" mapped to its CIK, CUSIP and company details')
print('----------------------------------------------------------')
pd.json_normalize(by_ticker_goog)
Ticker "GOOG" mapped to its CIK, CUSIP and company details
----------------------------------------------------------
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ALPHABET INC | GOOGL | 1652044 | 02079K305 38259P508 | NASDAQ | False | Domestic Common Stock Primary Class | Technology | Internet Content & Information | 7370 | Services | Services-Computer Programming Data Processing ... | Business Services | USD | California; U.S.A | 69afd258d97df8700e5c3b1ff5dc814b | |
1 | ALPHABET INC | GOOG | 1652044 | 02079K107 38259P706 | NASDAQ | False | Domestic Common Stock Secondary Class | Technology | Internet Content & Information | 7370 | Services | Services-Computer Programming Data Processing ... | Business Services | USD | California; U.S.A | 972f224b99db63cc3f0ab175eb171249 |
We observe that the Mapping API returns two entries for the ticker symbol GOOG
. This is due to the fact that GOOGL
also matches GOOG
, as the API uses regular expressions for finding matches. In case we want to perform an exact match, we can use the expression ^GOOG$
.
by_ticker_goog2 = mappingApi.resolve('ticker', '^GOOG$')
print('Ticker "GOOG" mapped to its CIK, CUSIP and company details')
print('----------------------------------------------------------')
pd.json_normalize(by_ticker_goog2)
Ticker "GOOG" mapped to its CIK, CUSIP and company details
----------------------------------------------------------
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ALPHABET INC | GOOG | 1652044 | 02079K107 38259P706 | NASDAQ | False | Domestic Common Stock Secondary Class | Technology | Internet Content & Information | 7370 | Services | Services-Computer Programming Data Processing ... | Business Services | USD | California; U.S.A | 972f224b99db63cc3f0ab175eb171249 |
Map Ticker to CIK, CUSIP and Company Details
In this example, we showcase how to use the .resolve('ticker', 'value')
function to map a ticker to its corresponding CIK and CUSIP, as well as obtain the sector and industry information of a company. Specifically, we demonstrate how to resolve the ticker for Nvidia NVDA
to its CIK, CUSIP, and company details.
by_ticker = mappingApi.resolve('ticker', '^NVDA$')
print('Ticker:\t', 'NVDA')
print('CIK:\t', by_ticker[0]['cik'])
print('CUSIP:\t', by_ticker[0]['cusip'])
print('')
print('Ticker "NVDA" resolved to its company details')
print('---------------------------------------------')
by_ticker
Ticker: NVDA
CIK: 1045810
CUSIP: 67066G104
Ticker "NVDA" resolved to its company details
---------------------------------------------
[{'name': 'NVIDIA CORP',
'ticker': 'NVDA',
'cik': '1045810',
'cusip': '67066G104',
'exchange': 'NASDAQ',
'isDelisted': False,
'category': 'Domestic Common Stock',
'sector': 'Technology',
'industry': 'Semiconductors',
'sic': '3674',
'sicSector': 'Manufacturing',
'sicIndustry': 'Semiconductors & Related Devices',
'famaSector': '',
'famaIndustry': 'Electronic Equipment',
'currency': 'USD',
'location': 'California; U.S.A',
'id': '4a73b69083f93d38e05e0b76219875c9'}]
Map CIK to Ticker, CUSIP and Company Details
In this example, we demonstrate how to map a company's CIK to its ticker symbol and CUSIP. By using the .resolve('cik', 'value')
function, we can easily retrieve a list of dictionaries containing a company's details, including its ticker symbol and CUSIP, by providing its CIK as value
. Netflix' CIK 1065280
serves as an example.
by_cik = mappingApi.resolve('cik', '1065280')
print('CIK:\t', '1065280')
print('Ticker:\t', by_cik[0]['ticker'])
print('CUSIP:\t', by_cik[0]['cusip'])
print('')
print('CIK "1065280" resolved to its company details')
print('---------------------------------------------')
by_cik
CIK: 1065280
Ticker: NFLX
CUSIP: 64110L106
CIK "1065280" resolved to its company details
---------------------------------------------
[{'name': 'NETFLIX INC',
'ticker': 'NFLX',
'cik': '1065280',
'cusip': '64110L106',
'exchange': 'NASDAQ',
'isDelisted': False,
'category': 'Domestic Common Stock',
'sector': 'Consumer Cyclical',
'industry': 'Entertainment',
'sic': '7841',
'sicSector': 'Services',
'sicIndustry': 'Services-Video Tape Rental',
'famaSector': '',
'famaIndustry': 'Entertainment',
'currency': 'USD',
'location': 'California; U.S.A',
'id': '5f4668d981ee0a2d8d6e26c685087426'}]
Map CUSIP to Ticker, CIK and Company Details
This part demonstrates how to map a CUSIP code to its ticker, CIK, and company details by using the .resolve('cusip', 'value')
function. Specifically, we cover how to map Microsoft's CUSIP 594918104
to its ticker MSFT
and CIK 789019
as well as all company details, such as sector (Technology
) and industry (Software - Infrastructure
) among others.
by_cusip = mappingApi.resolve('cusip', '594918104')
print('CUSIP:\t', '594918104')
print('Ticker:\t', by_cusip[0]['ticker'])
print('CIK:\t', by_cusip[0]['cik'])
print('')
print('CUSIP "594918104" resolved to its company details')
print('-------------------------------------------------')
by_cusip
CUSIP: 594918104
Ticker: MSFT
CIK: 789019
CUSIP "594918104" resolved to its company details
-------------------------------------------------
[{'name': 'MICROSOFT CORP',
'ticker': 'MSFT',
'cik': '789019',
'cusip': '594918104',
'exchange': 'NASDAQ',
'isDelisted': False,
'category': 'Domestic Common Stock',
'sector': 'Technology',
'industry': 'Software - Infrastructure',
'sic': '7372',
'sicSector': 'Services',
'sicIndustry': 'Services-Prepackaged Software',
'famaSector': '',
'famaIndustry': 'Business Services',
'currency': 'USD',
'location': 'Washington; U.S.A',
'id': '0f08a6a6742dc4148badfef6977406cf'}]
Map Ticker to CUSIPs
This example demonstrates how to retrieve all CUSIPs associated with a particular ticker, using Arlington Asset Investment Corp as an example with ticker AAIC. The same approach can be used to find all CUSIPs by CIK.
The CUSIPs returned by .resolve('ticker', 'AAIC')
are represented as strings, which can sometimes contain multiple values separated by spaces, for instance 041356205 041356106
. To convert these values into lists, the .apply(lambda x: x.split())
function is used, allowing us to simply merge all cusip
columns of the resulting mappings dataframe.
import pandas as pd
by_ticker_aaic = mappingApi.resolve('ticker', 'AAIC')
aaic_details = pd.json_normalize(by_ticker_aaic)
# CUSIP column contains string values, e.g. '041356205 041356106'
# convert strings into lists: '041356205 041356106' => ['041356205', '041356106']
aaic_details['cusip'] = aaic_details['cusip'].apply(lambda x: x.split())
print('Ticker "AAIC" details')
print('---------------------')
aaic_details
Ticker "AAIC" details
---------------------
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ARLINGTON ASSET INVESTMENT CORP | AAIC | 1209028 | [041356205, 358433100, 358434108, 041356106] | NYSE | False | Domestic Common Stock Primary Class | Real Estate | REIT - Mortgage | 6798 | Finance Insurance And Real Estate | Real Estate Investment Trusts | Trading | USD | Virginia; U.S.A | eaed09b8158c49bc5365b32c33ddc379 | |
1 | ARLINGTON ASSET INVESTMENT CORP | AAIC-PB | 1209028 | [041356601] | NYSE | False | Domestic Preferred Stock | Real Estate | REIT - Mortgage | 6798 | Finance Insurance And Real Estate | Real Estate Investment Trusts | Trading | USD | Virginia; U.S.A | 2bb499e069feddfc6d9492f2a8fbfa98 | |
2 | ARLINGTON ASSET INVESTMENT CORP | AAIC-PC | 1209028 | [041356700] | NYSE | False | Domestic Preferred Stock | Real Estate | REIT - Mortgage | 6798 | Finance Insurance And Real Estate | Real Estate Investment Trusts | Trading | USD | Virginia; U.S.A | 3753ef2ce86aadeba6ecb5e309d6adc4 |
aaic_cusip = [element for sublist in aaic_details['cusip'] for element in sublist]
print('CUSIPs of AAIC')
print('--------------')
print(aaic_cusip)
CUSIPs of AAIC
--------------
['041356205', '358433100', '358434108', '041356106', '041356601', '041356700']
List Companies by Exchange
The .resolve('exchange', <EXCHANGE>)
function can be used to retrieve a list of all companies listed on a specific exchange, where <EXCHANGE>
is one of the values listed in the table below, also showing the number of listings for each supported exchange:
Exchange | Number of Listings |
---|---|
NASDAQ | 14128 |
NYSE | 13036 |
NYSEARCA | 2930 |
NYSEMKT | 1478 |
BATS | 761 |
OTC | 294 |
INDEX | 5 |
List Companies on NASDAQ
This section demonstrates how to retrieve a list of all companies and securities that are currently listed, as well as delisted ones, on the NASDAQ exchange by using the .resolve('exchange', 'NASDAQ')
function. We provide examples on how to filter the list to only display tickers of common stocks, ADRs, warrants, ETFs, and ETNs. We also demonstrate how to further filter the list to only show currently active securities.
all_nasdaq_listings_json = mappingApi.resolve('exchange', 'NASDAQ')
all_nasdaq_listings = pd.DataFrame(all_nasdaq_listings_json)
print('Companies and securities traded on NASDAQ, including delisted ones')
print('------------------------------------------------------------------')
print('Number of listings on NASDAQ:', len(all_nasdaq_listings))
all_nasdaq_listings
Companies and securities traded on NASDAQ, including delisted ones
------------------------------------------------------------------
Number of listings on NASDAQ: 14128
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ADMIRALTY BANCORP INC | AAAB | 1066808 | 007231103 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6022 | Finance Insurance And Real Estate | State Commercial Banks | Banking | USD | Florida; U.S.A | 3daf92ec6639eede5c282d6cd20f8342 | |
1 | ADVANCED ACCELERATOR APPLICATIONS SA | AAAP | 1611787 | 00790T100 | NASDAQ | True | ADR Common Stock | Healthcare | Biotechnology | 2834 | Manufacturing | Pharmaceutical Preparations | Pharmaceutical Products | EUR | France | cf1185a716b218ee7db7d812695108eb | |
2 | ACCESS ANYTIME BANCORP INC | AABC | 1024015 | 00431F105 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6035 | Finance Insurance And Real Estate | Savings Institution Federally Chartered | Banking | USD | New Mexico; U.S.A | 800e1a7171119770ea03175a8f58830a | |
3 | ALLIANCE ATLANTIS COMMUNICATIONS INC | AACB | 1005887 | 01853E204 | NASDAQ | True | Canadian Common Stock | Consumer Cyclical | Entertainment | 7812 | Services | Services-Motion Picture & Video Tape Production | Entertainment | CAD | Ontario; Canada | ad7ea446a3f717df221b05f16b88a291 | |
4 | ASSET ACCEPTANCE CAPITAL CORP | AACC | 1264707 | 04543P100 | NASDAQ | True | Domestic Common Stock | Financial Services | Asset Management | 6153 | Finance Insurance And Real Estate | Short-Term Business Credit Institutions | Banking | USD | Michigan; U.S.A | cee355397a974512760921762e03c30c | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
14123 | PROSHARES ULTRAPRO SHORT NASDAQ BIOTECHNOLOGY | ZBIO | 74347B623 74347B193 | NASDAQ | True | ETF | USD | ee75b5fff5780ac275c8c5e3b47468a0 | |||||||||
14124 | THE GEN Z ETF | ZGEN | 1592900 | 02072L763 | NASDAQ | False | ETF | USD | Pennsylvania; U.S.A | 90da3bf04872487200fc7fb16bf94c1f | |||||||
14125 | ZIONS BANCORPORATION NATIONAL ASSOCIATION | ZIONL | 109380 | 989701818 | NASDAQ | False | ETD | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | Utah; U.S.A | ad82a386e84d48ad55d9adcbd0194793 | |||
14126 | VELOCITYSHARES DAILY INVERSE VIX MEDIUM TERM ETN | ZIVZF | 22542D829 | NASDAQ | True | ETN | USD | 18b5578dedec056b43fd29e1a1530a50 | |||||||||
14127 | Z SEVEN FUND INC | ZSEV | 730476 | 988789103 | NASDAQ | True | CEF | USD | Arizona; U.S.A | 690ceef6c32ae5d67b7897a9d826825e |
14128 rows × 17 columns
nasdaq_listings_active = all_nasdaq_listings[all_nasdaq_listings['isDelisted'] != False]
print('Companies and securities on NASDAQ, excluding delisted ones')
print('-----------------------------------------------------------')
print('Number of active listings on NASDAQ:', len(nasdaq_listings_active))
nasdaq_listings_active
Companies and securities on NASDAQ, excluding delisted ones
-----------------------------------------------------------
Number of active listings on NASDAQ: 8650
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ADMIRALTY BANCORP INC | AAAB | 1066808 | 007231103 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6022 | Finance Insurance And Real Estate | State Commercial Banks | Banking | USD | Florida; U.S.A | 3daf92ec6639eede5c282d6cd20f8342 | |
1 | ADVANCED ACCELERATOR APPLICATIONS SA | AAAP | 1611787 | 00790T100 | NASDAQ | True | ADR Common Stock | Healthcare | Biotechnology | 2834 | Manufacturing | Pharmaceutical Preparations | Pharmaceutical Products | EUR | France | cf1185a716b218ee7db7d812695108eb | |
2 | ACCESS ANYTIME BANCORP INC | AABC | 1024015 | 00431F105 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6035 | Finance Insurance And Real Estate | Savings Institution Federally Chartered | Banking | USD | New Mexico; U.S.A | 800e1a7171119770ea03175a8f58830a | |
3 | ALLIANCE ATLANTIS COMMUNICATIONS INC | AACB | 1005887 | 01853E204 | NASDAQ | True | Canadian Common Stock | Consumer Cyclical | Entertainment | 7812 | Services | Services-Motion Picture & Video Tape Production | Entertainment | CAD | Ontario; Canada | ad7ea446a3f717df221b05f16b88a291 | |
4 | ASSET ACCEPTANCE CAPITAL CORP | AACC | 1264707 | 04543P100 | NASDAQ | True | Domestic Common Stock | Financial Services | Asset Management | 6153 | Finance Insurance And Real Estate | Short-Term Business Credit Institutions | Banking | USD | Michigan; U.S.A | cee355397a974512760921762e03c30c | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
14119 | VELOCITYSHARES DAILY INVERSE VIX SHORT TERM ETN | XIV | 22542D795 | NASDAQ | True | ETN | USD | 97b1b1f0bdf040617d100a4c3872bce4 | |||||||||
14122 | ADVISORSHARES YIELDPRO ETF | YPRO | 1408970 | 00768Y644 | NASDAQ | True | ETF | USD | 28be3034866813061bc79b0083a16e6d | ||||||||
14123 | PROSHARES ULTRAPRO SHORT NASDAQ BIOTECHNOLOGY | ZBIO | 74347B623 74347B193 | NASDAQ | True | ETF | USD | ee75b5fff5780ac275c8c5e3b47468a0 | |||||||||
14126 | VELOCITYSHARES DAILY INVERSE VIX MEDIUM TERM ETN | ZIVZF | 22542D829 | NASDAQ | True | ETN | USD | 18b5578dedec056b43fd29e1a1530a50 | |||||||||
14127 | Z SEVEN FUND INC | ZSEV | 730476 | 988789103 | NASDAQ | True | CEF | USD | Arizona; U.S.A | 690ceef6c32ae5d67b7897a9d826825e |
8650 rows × 17 columns
etfs_on_nasdaq = nasdaq_listings_active[nasdaq_listings_active['category'] == 'ETF']
print('ETFs on NASDAQ, excluding delisted ones')
print('-----------------------------------------------------------')
print('Number of active ETFs on NASDAQ:', len(etfs_on_nasdaq))
etfs_on_nasdaq
ETFs on NASDAQ, excluding delisted ones
-----------------------------------------------------------
Number of active ETFs on NASDAQ: 165
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
936 | WISDOMTREE NEGATIVE DURATION US AGGREGATE BOND... | AGND | 1350487 | 97717W364 | NASDAQ | True | ETF | USD | 9ad41ce65eb4b26708992bc949772cf1 | ||||||||
4397 | WISDOMTREE MIDDLE EAST DIVIDEND FUND | GULF | 1350487 | 97717X305 | NASDAQ | True | ETF | USD | af2d7f6cda6784ab04c29b140f41f33b | ||||||||
5321 | ISHARES MSCI ACWI EX US FINANCIALS ETF | AXFN | 1100663 | 464289164 | NASDAQ | True | ETF | USD | 2882af5b8d0f2bcb1a1abc44ff9a0fd1 | ||||||||
5604 | ISHARES MSCI ALL COUNTRY ASIA EX JAPAN SMALL-C... | AXJS | 1100663 | 46429B622 | NASDAQ | True | ETF | USD | 046ae799ff2167d1808b954842b5d99f | ||||||||
9120 | REALITY SHARES NASDAQ NEXGEN ECONOMY CHINA ETF | BCNA | 1573496 | 75605A801 | NASDAQ | True | ETF | USD | a33db62485d0c51854ad82e76fc1e1e8 | ||||||||
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
14098 | VICTORYSHARES TOP VETERAN EMPLOYERS ETF | VTRN | 1547580 | 92647X889 | NASDAQ | True | ETF | USD | Ohio; U.S.A | 6313a82d7b6c99eea27aa43b5f696717 | |||||||
14102 | ACCUSHARES SPOT CBOE VIX UP SHARES | VXUP | 00439V102 00439V797 00439V821 00441G309 00439V771 | NASDAQ | True | ETF | USD | 439ec243fdc215aa939bed65eef844b5 | |||||||||
14106 | JEFFERIES/TR/J CRB WILDCATTERS EXPLORATION & P... | WCAT | 1414040 | 00162Q809 | NASDAQ | True | ETF | USD | 8541d24cc10c893f7f8a816de8bc81c5 | ||||||||
14122 | ADVISORSHARES YIELDPRO ETF | YPRO | 1408970 | 00768Y644 | NASDAQ | True | ETF | USD | 28be3034866813061bc79b0083a16e6d | ||||||||
14123 | PROSHARES ULTRAPRO SHORT NASDAQ BIOTECHNOLOGY | ZBIO | 74347B623 74347B193 | NASDAQ | True | ETF | USD | ee75b5fff5780ac275c8c5e3b47468a0 |
165 rows × 17 columns
Instruments Traded on NASDAQ
The following example demonstrates how to obtain a list of security types traded on NASDAQ.
print('Instruments traded on NASDAQ')
print('----------------------------')
list(sorted(nasdaq_listings_active['category'].unique()))
Instruments traded on NASDAQ
----------------------------
['',
'ADR Common Stock',
'ADR Common Stock Primary Class',
'ADR Common Stock Secondary Class',
'ADR Preferred Stock',
'ADR Stock Warrant',
'CEF',
'Canadian Common Stock',
'Canadian Common Stock Primary Class',
'Canadian Common Stock Secondary Class',
'Canadian Preferred Stock',
'Domestic Common Stock',
'Domestic Common Stock Primary Class',
'Domestic Common Stock Secondary Class',
'Domestic Preferred Stock',
'Domestic Stock Warrant',
'ETD',
'ETF',
'ETN']
Sectors and Industries Represented on NASDAQ
This example demonstrates how to count the number of securities per sector that are listed on NASDAQ, and how to visualize the distribution in a bar chart. If you prefer to analyze industries instead of sectors, you can simply change the group_key
to industry
.
import numpy as np
# change to 'industry' if you want print industry statistics
group_key = 'sector'
nasdaq_sector_stats = nasdaq_listings_active.drop_duplicates(subset=['cik']) \
.replace('', np.nan) \
.dropna(subset=[group_key]) \
.groupby(group_key) \
.count() \
.reset_index()[[group_key, 'cik']]
nasdaq_sector_stats = nasdaq_sector_stats.rename(columns={'cik': 'counter'})
nasdaq_sector_stats.set_index(group_key, inplace=True)
nasdaq_sector_stats = nasdaq_sector_stats.sort_values(by='counter', ascending=False)
nasdaq_sector_stats = nasdaq_sector_stats[nasdaq_sector_stats['counter'] > 100]
print('Active listings on NASDAQ:', len(nasdaq_listings_active))
nasdaq_sector_stats.head(10)
Active listings on NASDAQ: 8650
counter | |
---|---|
sector | |
Technology | 2145 |
Healthcare | 1222 |
Financial Services | 1194 |
Industrials | 936 |
Consumer Cyclical | 888 |
Communication Services | 266 |
Consumer Defensive | 248 |
Basic Materials | 225 |
Energy | 194 |
import matplotlib.pyplot as plt
ax = nasdaq_sector_stats.plot(kind='barh', figsize=(8, 4), legend=False)
ax.set_xlabel('Listings per Sector')
ax.set_ylabel('Sector')
ax.set_title('Number of Listings by Sector on NASDAQ')
ax.invert_yaxis()
plt.show()
List Companies on NYSE
Next, we utilize the .resolve('exchange', 'NYSE')
function to generate a list of all companies listed on the NYSE exchange, along with their corresponding tickers, CIKs, CUSIPs, industry, and sector information. This list encompasses both active and delisted securities.
all_nyse_listings_json = mappingApi.resolve('exchange', 'NYSE')
all_nyse_listings = pd.DataFrame(all_nyse_listings_json)
print('Companies and securities traded on NYSE, including delisted ones')
print('----------------------------------------------------------------')
print('Number of NYSE listings:', len(all_nyse_listings))
all_nyse_listings
Companies and securities traded on NYSE, including delisted ones
----------------------------------------------------------------
Number of NYSE listings: 13036
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | AGILENT TECHNOLOGIES INC | A | 1090872 | 00846U101 | NYSE | False | Domestic Common Stock | Healthcare | Diagnostics & Research | 3826 | Manufacturing | Laboratory Analytical Instruments | Measuring and Control Equipment | USD | California; U.S.A | 81e134d27f5a89e6e88c39798d1497b0 | |
1 | ALCOA CORP | AA | 1675149 | 013872106 | NYSE | False | Domestic Common Stock | Basic Materials | Aluminum | 3334 | Manufacturing | Primary Production Of Aluminum | Steel Works Etc | USD | Pennsylvania; U.S.A | 06b2234c0416841fec48880d3a0fa76d | |
2 | ALTANA AKTIENGESELLSCHAFT | AAAGY | 1182802 | 02143N103 | NYSE | True | ADR Common Stock | Healthcare | Biotechnology | 2834 | Manufacturing | Pharmaceutical Preparations | Pharmaceutical Products | EUR | Jordan | 50630842b4586991a40d76c913a7b5de | |
3 | ARES ACQUISITION CORP | AAC | 1829432 | G33032106 | NYSE | False | Domestic Common Stock Primary Class | Industrials | Shell Companies | 6770 | Finance Insurance And Real Estate | Blank Checks | Trading | USD | New York; U.S.A | 3fd560f6b81a7525affb90b150a56f5d | |
4 | ARCADIA FINANCIAL LTD | AAC1 | 879674 | 039101100 681593109 681593208 | NYSE | True | Domestic Common Stock | Financial Services | Asset Management | 6153 | Finance Insurance And Real Estate | Short-Term Business Credit Institutions | Banking | USD | Minnesota; U.S.A | ccb04fc280f2dc864af66cb132fc40aa | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
13031 | USCF SUSTAINABLE BATTERY METALS STRATEGY FUND | ZSB | 1597389 | 90290T841 | NYSEARCA | False | ETF | USD | California; U.S.A | 5e1fbda7db8ee8d9691a8b4ffd44394f | |||||||
13032 | PROSHARES ULTRASHORT SILVER | ZSL | 74347W114 74347Y847 74347W643 74347W726 74347W833 | NYSEARCA | False | ETF | USD | 906990129f2d3eceacd7f55a4162222c | |||||||||
13033 | ETFS ZACKS EARNINGS SMALL-CAP US INDEX FUND | ZSML | 1597934 | 26923J206 | NYSEARCA | True | ETF | USD | 50f57ed61a12f8ee6dbf4e7674f1b7fb | ||||||||
13034 | ASYMMETRIC SMART ALPHA S&P 500 ETF | ZSPY | 1833032 | 04651A200 | NYSEARCA | False | ETF | USD | New York; U.S.A | fe6748afbcf622424d7468073d81eade | |||||||
13035 | VIRTUS TOTAL RETURN FUND INC | ZTR | 836412 | 92835W107 989837208 989837109 | NYSE | False | CEF | USD | Massachusetts; U.S.A | 1f7526f6e72cbdfea4034dde5663fd3d |
13036 rows × 17 columns
nyse_listings_active = all_nyse_listings[all_nyse_listings['isDelisted'] != False]
# change to 'industry' if you want print industry statistics
group_key = 'sector'
nyse_industry_stats = nyse_listings_active.drop_duplicates(subset=['cik']) \
.replace('', np.nan) \
.dropna(subset=[group_key]) \
.groupby(group_key) \
.count() \
.reset_index()[[group_key, 'cik']]
nyse_industry_stats = nyse_industry_stats.rename(columns={'cik': 'counter'})
nyse_industry_stats.set_index(group_key, inplace=True)
nyse_industry_stats = nyse_industry_stats.sort_values(by='counter', ascending=False)
nyse_industry_stats = nyse_industry_stats[nyse_industry_stats['counter'] > 50]
print('Active listings on NYSE:', len(nyse_listings_active))
nyse_industry_stats.head(10)
Active listings on NYSE: 7180
counter | |
---|---|
sector | |
Industrials | 617 |
Consumer Cyclical | 567 |
Financial Services | 494 |
Technology | 484 |
Energy | 418 |
Basic Materials | 362 |
Real Estate | 330 |
Healthcare | 296 |
Consumer Defensive | 187 |
Utilities | 160 |
ax = nyse_industry_stats.plot(kind='barh', figsize=(8, 4), legend=False)
ax.set_xlabel('Listings per Sector')
ax.set_ylabel('Sector')
ax.set_title('Number of Companies by Sector on NYSE')
ax.invert_yaxis()
plt.show()
List All Companies by Sector and Industry
The following example demonstrates how to filter companies by industry and sector. We merge the results of .resolve('exchange', 'NASDAQ')
and .resolve('exchange', 'NYSE')
, filter for active, not delisted, companies, and remove duplicates based on their unique CIK. We then apply pandas filter masks such as listings['sector'] == 'Industrials'
to create a list of companies operating in a specific sector or industry.
all_nasdaq_listings_json = mappingApi.resolve('exchange', 'NASDAQ')
all_nyse_listings_json = mappingApi.resolve('exchange', 'NYSE')
all_nasdaq_listings = pd.DataFrame(all_nasdaq_listings_json)
all_nyse_listings = pd.DataFrame(all_nyse_listings_json)
listings = pd.concat([all_nasdaq_listings, all_nyse_listings])
listings = listings[listings['isDelisted'] != False].drop_duplicates(subset=['cik'])
industrials_companies = listings[listings['sector'] == 'Industrials']
print('All companies of the "Industrials" sector')
print('-----------------------------------------')
print('Number of industrial companies:', len(industrials_companies))
industrials_companies
All companies of the "Industrials" sector
-----------------------------------------
Number of industrial companies: 1551
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8 | AUSTRALIA ACQUISITION CORP | AACPF | 1499593 | G06368123 G06368107 | NASDAQ | True | ADR Common Stock | Industrials | Shell Companies | 6770 | Finance Insurance And Real Estate | Blank Checks | Trading | USD | Australia | 04d6f2d514edf89f239d4492c0197e69 | |
11 | AIRTRAN HOLDINGS INC | AAI | 948846 | 00949P108 919906107 | NASDAQ | True | Domestic Common Stock | Industrials | Airlines | 4512 | Transportation Communications Electric Gas And... | Air Transportation Scheduled | Transportation | USD | Florida; U.S.A | 735b07a1290378a621e58ac658381732 | |
13 | ALABAMA AIRCRAFT INDUSTRIES INC | AAIIQ | 771729 | 01023E100 706444106 740327200 740327101 | NASDAQ | True | Domestic Common Stock | Industrials | Aerospace & Defense | 3721 | Manufacturing | Aircraft | Aircraft | USD | Alabama; U.S.A | 23911e913b6e095c59488f5effb85953 | |
24 | ANALYSIS & TECHNOLOGY INC | AATI1 | 310876 | 032672107 | NASDAQ | True | Domestic Common Stock | Industrials | Engineering & Construction | 8711 | Services | Services-Engineering Services | Business Services | USD | Connecticut; U.S.A | f6f65579ddd95482db247968ff7b7ed4 | |
25 | AAVID THERMAL TECHNOLOGIES INC | AATT | 1003481 | 002539104 | NASDAQ | True | Domestic Common Stock | Industrials | Electrical Equipment & Parts | 3679 | Manufacturing | Electronic Components Nec | Electronic Equipment | USD | New Hampshire; U.S.A | 6d28a801a1b864118a1069f093c72bae | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8576 | RAYTHEON TECHNOLOGIES CORP | UTX-PA | 101829 | 913017117 | NYSE | True | Domestic Preferred Stock | Industrials | Aerospace & Defense | 3724 | Manufacturing | Aircraft Engines & Engine Parts | Aircraft | USD | Massachusetts; U.S.A | 6e4bbad1e71b0373fc58a3a9cf084481 | |
8588 | V2X INC | VEC.W | 1601548 | NYSE | True | Domestic Stock Warrant | Industrials | Aerospace & Defense | 8744 | Services | Services-Facilities Support Management Services | Business Services | USD | Colorado; U.S.A | 1a07bc45c6f8116d6e5d3b3e71d40d56 | ||
8591 | VERTIV HOLDINGS CO | VERT.U | 1674101 | 36255F201 92537N207 | NYSE | True | Domestic Common Stock Secondary Class | Industrials | Electrical Equipment & Parts | 3679 | Manufacturing | Electronic Components Nec | Electronic Equipment | USD | Ohio; U.S.A | 803fc31abbbbaa70c2499dcc846f0388 | |
8636 | WESTINGHOUSE AIR BRAKE TECHNOLOGIES CORP | WAB.W | 943452 | NYSE | True | Domestic Stock Warrant | Industrials | Railroads | 3743 | Manufacturing | Railroad Equipment | Shipbuilding Railroad Equipment | USD | Pennsylvania; U.S.A | d30a6b6b5b6fca47f4f61593847fe386 | ||
8739 | SKY HARBOUR GROUP CORP | YSAC.U | 1823587 | 98566K204 | NYSE | True | Domestic Common Stock Secondary Class | Industrials | Aerospace & Defense | 3720 | Manufacturing | Aircraft & Parts | Aircraft | USD | Nebraska; U.S.A | f6773981e6ca7f6562ba9a8d029de172 |
1551 rows × 17 columns
Find and List All Regional Banks
The task of finding all regional banks can be accomplished in a single line of code by adjusting the pandas filter to listings['industry'] == 'Banks - Regional'
.
regional_banks = listings[listings['industry'] == 'Banks - Regional']
print('All companies of the "Banks - Regional" industry')
print('------------------------------------------------')
print('Number of regional banks:', len(regional_banks))
regional_banks
All companies of the "Banks - Regional" industry
------------------------------------------------
Number of regional banks: 1032
name | ticker | cik | cusip | exchange | isDelisted | category | sector | industry | sic | sicSector | sicIndustry | famaSector | famaIndustry | currency | location | id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ADMIRALTY BANCORP INC | AAAB | 1066808 | 007231103 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6022 | Finance Insurance And Real Estate | State Commercial Banks | Banking | USD | Florida; U.S.A | 3daf92ec6639eede5c282d6cd20f8342 | |
2 | ACCESS ANYTIME BANCORP INC | AABC | 1024015 | 00431F105 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6035 | Finance Insurance And Real Estate | Savings Institution Federally Chartered | Banking | USD | New Mexico; U.S.A | 800e1a7171119770ea03175a8f58830a | |
10 | ADVANTAGE BANCORP INC | AADV | 881892 | 00755C100 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6036 | Finance Insurance And Real Estate | Savings Institutions Not Federally Chartered | Banking | USD | Wisconsin; U.S.A | 6e12a9c1713bdc734c8dd912e4c05b52 | |
17 | ABIGAIL ADAMS NATIONAL BANCORP INC | AANB | 356809 | 003390101 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | District Of Columbia; U.S.A | 64075d90bdd55532a6d69e57409fbe0f | |
29 | AMERICAN BANCSHARES INC | ABAN | 1004528 | 024086100 | NASDAQ | True | Domestic Common Stock | Financial Services | Banks - Regional | 6022 | Finance Insurance And Real Estate | State Commercial Banks | Banking | USD | Florida; U.S.A | a2e0f4fce24aa06cbd63a5cad4c2e608 | |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
8298 | SYNOVUS FINANCIAL CORP | SNV-PC | 18349 | 87161C402 | NYSE | True | Domestic Preferred Stock | Financial Services | Banks - Regional | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | Georgia; U.S.A | 469c165aad7f4f4da06e046f79915a60 | |
8567 | US BANCORP | USB-PM | 36104 | 902973833 | NYSE | True | Domestic Preferred Stock | Financial Services | Banks - Regional | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | Minnesota; U.S.A | 447befd267f7a5a8954d2e6f146884fd | |
8607 | VALLEY NATIONAL BANCORP | VLY-PA | 714310 | 92856Q203 | NYSE | True | Domestic Preferred Stock | Financial Services | Banks - Regional | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | New York; U.S.A | b93e4b9633e9342ac0bc9739459a5314 | |
8644 | WEBSTER FINANCIAL CORP | WBS-PE | 801337 | 947890406 | NYSE | True | Domestic Preferred Stock | Financial Services | Banks - Regional | 6021 | Finance Insurance And Real Estate | National Commercial Banks | Banking | USD | Connecticut; U.S.A | 38dfe55e7ffce7ca1ab6192d43819c1c | |
8660 | WOORI FINANCIAL GROUP INC | WF.W | 1264136 | NYSE | True | ADR Stock Warrant | Financial Services | Banks - Regional | 6029 | Finance Insurance And Real Estate | Commercial Banks Nec | Banking | USD | Republic Of Korea | 68b529cc88036a78e3c6ff32f6acf4ef |
1032 rows × 17 columns
List All Sectors
Listing all sectors can be achieved in a single line of code by retrieving all unique non-empty values in the sector
column of our listings
dataframe.
sectors = sorted(list(listings['sector'].replace('', np.nan).dropna().unique()))
print('All Sectors')
print('-----------')
sectors
All Sectors
-----------
['Basic Materials',
'Communication Services',
'Consumer Cyclical',
'Consumer Defensive',
'Energy',
'Financial Services',
'Healthcare',
'Industrials',
'Real Estate',
'Technology',
'Utilities']
List All Industries
Generating a list of all industries is as simple as filtering all unique non-empty values in the industry
column of our listings
dataframe.
industries = sorted(list(listings['industry'].replace('', np.nan).dropna().unique()))
print('All Industries')
print('--------------')
industries
All Industries
--------------
['Advertising Agencies',
'Aerospace & Defense',
'Agricultural Inputs',
'Airlines',
'Airports & Air Services',
'Aluminum',
'Apparel Manufacturing',
'Apparel Retail',
'Asset Management',
'Auto & Truck Dealerships',
'Auto Manufacturers',
'Auto Parts',
'Banks - Diversified',
'Banks - Regional',
'Beverages - Brewers',
'Beverages - Non-Alcoholic',
'Beverages - Wineries & Distilleries',
'Biotechnology',
'Broadcasting',
'Building Materials',
'Building Products & Equipment',
'Business Equipment & Supplies',
'Capital Markets',
'Chemicals',
'Coking Coal',
'Communication Equipment',
'Computer Hardware',
'Computer Systems',
'Conglomerates',
'Consulting Services',
'Consumer Electronics',
'Copper',
'Credit Services',
'Department Stores',
'Diagnostics & Research',
'Discount Stores',
'Diversified Industrials',
'Drug Manufacturers - General',
'Drug Manufacturers - Major',
'Drug Manufacturers - Specialty & Generic',
'Education & Training Services',
'Electrical Equipment & Parts',
'Electronic Components',
'Electronic Gaming & Multimedia',
'Electronics & Computer Distribution',
'Engineering & Construction',
'Entertainment',
'Farm & Heavy Construction Machinery',
'Farm Products',
'Food Distribution',
'Footwear & Accessories',
'Furnishings',
'Furnishings Fixtures & Appliances',
'Gambling',
'Gold',
'Grocery Stores',
'Health Information Services',
'Healthcare Plans',
'Home Improvement Retail',
'Household & Personal Products',
'Industrial Distribution',
'Industrial Metals & Minerals',
'Information Technology Services',
'Infrastructure Operations',
'Insurance - Diversified',
'Insurance - Life',
'Insurance - Property & Casualty',
'Insurance - Reinsurance',
'Insurance - Specialty',
'Insurance Brokers',
'Integrated Freight & Logistics',
'Internet Content & Information',
'Internet Retail',
'Leisure',
'Lodging',
'Lumber & Wood Production',
'Luxury Goods',
'Marine Shipping',
'Medical Care Facilities',
'Medical Devices',
'Medical Distribution',
'Medical Instruments & Supplies',
'Metal Fabrication',
'Mortgage Finance',
'Oil & Gas Drilling',
'Oil & Gas E&P',
'Oil & Gas Equipment & Services',
'Oil & Gas Integrated',
'Oil & Gas Midstream',
'Oil & Gas Refining & Marketing',
'Other Industrial Metals & Mining',
'Other Precious Metals & Mining',
'Packaged Foods',
'Packaging & Containers',
'Paper & Paper Products',
'Personal Services',
'Pharmaceutical Retailers',
'Pollution & Treatment Controls',
'Publishing',
'REIT - Diversified',
'REIT - Healthcare Facilities',
'REIT - Hotel & Motel',
'REIT - Industrial',
'REIT - Mortgage',
'REIT - Office',
'REIT - Residential',
'REIT - Retail',
'REIT - Specialty',
'Railroads',
'Real Estate - Development',
'Real Estate - Diversified',
'Real Estate Services',
'Recreational Vehicles',
'Rental & Leasing Services',
'Residential Construction',
'Resorts & Casinos',
'Restaurants',
'Savings & Cooperative Banks',
'Scientific & Technical Instruments',
'Security & Protection Services',
'Semiconductor Equipment & Materials',
'Semiconductors',
'Shell Companies',
'Shipping & Ports',
'Software - Application',
'Software - Infrastructure',
'Solar',
'Specialty Business Services',
'Specialty Chemicals',
'Specialty Industrial Machinery',
'Specialty Retail',
'Staffing & Employment Services',
'Steel',
'Telecom Services',
'Textile Manufacturing',
'Thermal Coal',
'Tobacco',
'Tools & Accessories',
'Travel Services',
'Trucking',
'Uranium',
'Utilities - Diversified',
'Utilities - Independent Power Producers',
'Utilities - Regulated Electric',
'Utilities - Regulated Gas',
'Utilities - Regulated Water',
'Utilities - Renewable',
'Waste Management']