Skip to content

Commit

Permalink
Add popular stocks to ticker reference data
Browse files Browse the repository at this point in the history
  • Loading branch information
dgunning committed Nov 11, 2024
1 parent ccd038a commit d5efa13
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 9 deletions.
5 changes: 2 additions & 3 deletions edgar/reference/data/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ def read_pyarrow_from_package(parquet_filename: str):
return table


@lru_cache(maxsize=1)
def read_csv_from_package(csv_filename: str):
def read_csv_from_package(csv_filename: str, **pandas_kwargs):
package_name = 'edgar.reference.data'

with resources.path(package_name, csv_filename) as csv_path:
df = pd.read_csv(csv_path)
df = pd.read_csv(csv_path, **pandas_kwargs)

return df
86 changes: 86 additions & 0 deletions edgar/reference/data/popular_us_stocks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Ticker,Company,Cik
AAPL,Apple Inc.,320193
MSFT,Microsoft Corporation,789019
AMZN,"Amazon.com, Inc.",1018724
NVDA,NVIDIA Corporation,1045810
TSLA,"Tesla, Inc.",1318605
GOOGL,Alphabet Inc. Class A,1652044
META,"Meta Platforms, Inc.",1326801
AMD,"Advanced Micro Devices, Inc.",2488
NFLX,"Netflix, Inc.",1065280
BRK.B,Berkshire Hathaway Inc.,1067983
V,Visa Inc.,1403161
JNJ,Johnson & Johnson,200406
PG,Procter & Gamble Co.,80424
JPM,JPMorgan Chase & Co.,19617
UNH,UnitedHealth Group Incorporated,731766
DIS,The Walt Disney Company,1744489
HD,"Home Depot, Inc.",354950
XOM,Exxon Mobil Corporation,34088
KO,Coca-Cola Company,21344
PEP,"PepsiCo, Inc.",77476
PFE,Pfizer Inc.,78003
MA,Mastercard Incorporated,1141391
ADBE,Adobe Inc.,796343
CRM,"Salesforce, Inc.",1108524
INTC,Intel Corporation,50863
CSCO,"Cisco Systems, Inc.",858877
NKE,"Nike, Inc.",320187
T,AT&T Inc.,732717
CMCSA,Comcast Corporation,1166691
VZ,Verizon Communications Inc.,732712
CVX,Chevron Corporation,93410
ABBV,AbbVie Inc.,1551152
MRK,"Merck & Co., Inc.",310158
BMY,Bristol-Myers Squibb Company,14272
WMT,Walmart Inc.,104169
MCD,McDonald's Corporation,63908
SBUX,Starbucks Corporation,829224
GS,"Goldman Sachs Group, Inc.",886982
MS,Morgan Stanley,895421
AXP,American Express Company,4962
C,Citigroup Inc.,831001
BA,Boeing Company,12927
DAL,"Delta Air Lines, Inc.",27904
LUV,Southwest Airlines Co.,92380
MAR,"Marriott International, Inc.",1048286
HLT,Hilton Worldwide Holdings Inc.,1585689
BKNG,Booking Holdings Inc.,1075531
PYPL,"PayPal Holdings, Inc.",1633917
SQ,"Square, Inc.",1512673
ZM,"Zoom Video Communications, Inc.",1585521
SNOW,Snowflake Inc.,1640147
UBER,"Uber Technologies, Inc.",1543151
LYFT,"Lyft, Inc.",1759509
ROKU,"Roku, Inc.",1428439
SPOT,Spotify Technology S.A.,1639920
SHOP,Shopify Inc.,1594805
EBAY,eBay Inc.,1065088
TWTR,"Twitter, Inc.",1418091
SNAP,Snap Inc.,1564408
PINS,"Pinterest, Inc.",1506293
PLTR,Palantir Technologies Inc.,1321655
ZI,ZoomInfo Technologies Inc.,1794515
DOCU,"DocuSign, Inc.",1261333
TWLO,Twilio Inc.,1447669
CRWD,"CrowdStrike Holdings, Inc.",1535527
NET,"Cloudflare, Inc.",1477333
DDOG,"Datadog, Inc.",1561550
MDB,"MongoDB, Inc.",1441816
ZS,"Zscaler, Inc.",1713683
OKTA,"Okta, Inc.",1660134
DBX,"Dropbox, Inc.",1467623
SMAR,Smartsheet Inc.,1366561
ASAN,"Asana, Inc.",1477720
RNG,"RingCentral, Inc.",1384905
PTON,"Peloton Interactive, Inc.",1639825
TTD,"The Trade Desk, Inc.",1671933
HUBS,"HubSpot, Inc.",1404655
COUP,Coupa Software Incorporated,1385867
AYX,"Alteryx, Inc.",1689923
SPLK,Splunk Inc.,1353283
NEWR,"New Relic, Inc.",1448056
DT,"Dynatrace, Inc.",1773383
NOW,"ServiceNow, Inc.",1373715
WDAY,"Workday, Inc.",1327811
ADSK,"Autodesk, Inc.",769397
17 changes: 12 additions & 5 deletions edgar/reference/tickers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import os
import json
import os
import re
from functools import lru_cache
from io import StringIO
from pathlib import Path
Expand All @@ -10,12 +10,12 @@
import pyarrow as pa
from httpx import HTTPStatusError

from edgar.httprequests import download_file, download_json, download_datafile
from edgar.reference.data.common import read_parquet_from_package
from edgar.core import log, get_edgar_data_directory
from edgar.httprequests import download_file, download_json, download_datafile
from edgar.reference.data.common import read_parquet_from_package, read_csv_from_package

__all__ = ['cusip_ticker_mapping', 'get_ticker_from_cusip', 'get_company_tickers', 'get_icon_from_ticker', 'find_cik',
'get_cik_tickers', 'get_company_ticker_name_exchange', 'get_companies_by_exchange',
'get_cik_tickers', 'get_company_ticker_name_exchange', 'get_companies_by_exchange', 'popular_us_stocks',
'get_mutual_fund_tickers', 'find_mutual_fund_cik', 'list_all_tickers']

ticker_txt_url = "https://www.sec.gov/include/ticker.txt"
Expand Down Expand Up @@ -380,6 +380,13 @@ def get_icon_from_ticker(ticker: str) -> Optional[bytes]:
else:
raise

def popular_us_stocks():
df = (read_csv_from_package('popular_us_stocks.csv', dtype={'Cik': int})
.set_index('Cik')
)
return df



def download_ticker_data(reference_data_directory: Path):
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/batch/batch_management_discussions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from edgar.reference.tickers import popular_us_stocks
from edgar import *
from tqdm.auto import tqdm

def load_management_discussions():
for cik in tqdm(popular_us_stocks().index):
company = Company(cik)
tenk = company.latest_tenk
if tenk:
mda = tenk['Item 7']
if not mda:
print(f"No MDA found for {company.tickers}")
print(tenk.items)

if __name__ == '__main__':
load_management_discussions()


8 changes: 7 additions & 1 deletion tests/test_tickers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from edgar.reference.tickers import cusip_ticker_mapping, get_ticker_from_cusip, get_company_tickers, get_icon_from_ticker, clean_company_suffix
from edgar.reference.tickers import popular_us_stocks, get_ticker_from_cusip, get_company_tickers, get_icon_from_ticker, clean_company_suffix
import pandas as pd
import pyarrow as pa
import pytest
Expand Down Expand Up @@ -49,3 +49,9 @@ def test_get_icon_bad_ticker():

with pytest.raises(ValueError):
icon = get_icon_from_ticker(123)


def test_popular_us_stocks():
stocks = popular_us_stocks()
assert not stocks.empty
assert stocks[stocks.Ticker=='WDAY'].index.item() ==1327811

0 comments on commit d5efa13

Please sign in to comment.