Appendix B — The yahooquery Package

B.1 Single Company

from yahooquery import Ticker

ticker = Ticker("NFLX")

Company information:

ticker.summary_profile
{'NFLX': {'address1': '121 Albright Way',
  'city': 'Los Gatos',
  'state': 'CA',
  'zip': '95032',
  'country': 'United States',
  'phone': '(408) 540-3700',
  'website': 'https://www.netflix.com',
  'industry': 'Entertainment',
  'industryKey': 'entertainment',
  'industryDisp': 'Entertainment',
  'sector': 'Communication Services',
  'sectorKey': 'communication-services',
  'sectorDisp': 'Communication Services',
  'longBusinessSummary': 'Netflix, Inc. provides entertainment services. It offers TV series, documentaries, feature films, and games across various genres and languages. The company also provides members the ability to receive streaming content through a host of internet-connected devices, including TVs, digital video players, TV set-top boxes, and mobile devices. It has operations in approximately 190 countries. The company was incorporated in 1997 and is headquartered in Los Gatos, California.',
  'fullTimeEmployees': 13000,
  'companyOfficers': [],
  'maxAge': 86400}}

Historical prices:

df = ticker.history(start="2024-01-01", end="2024-01-31", adj_ohlc=True)
df.head()
open high low volume close
symbol date
NFLX 2024-01-02 483.190002 484.649994 461.859985 5049400 468.500000
2024-01-03 467.320007 475.049988 465.769989 3443700 470.260010
2024-01-04 472.980011 480.739990 466.529999 3636500 474.670013
2024-01-05 476.500000 479.549988 471.799988 2612500 474.059998
2024-01-08 473.890015 485.239990 473.649994 3675800 485.029999

B.2 Multiple Companies

from yahooquery import Ticker

tickers = Ticker( ["MSFT", "AAPL", "GOOGL"])

Company information:

tickers.summary_profile
{'MSFT': {'address1': 'One Microsoft Way',
  'city': 'Redmond',
  'state': 'WA',
  'zip': '98052-6399',
  'country': 'United States',
  'phone': '425 882 8080',
  'website': 'https://www.microsoft.com',
  'industry': 'Software - Infrastructure',
  'industryKey': 'software-infrastructure',
  'industryDisp': 'Software - Infrastructure',
  'sector': 'Technology',
  'sectorKey': 'technology',
  'sectorDisp': 'Technology',
  'longBusinessSummary': 'Microsoft Corporation develops and supports software, services, devices and solutions worldwide. The Productivity and Business Processes segment offers office, exchange, SharePoint, Microsoft Teams, office 365 Security and Compliance, Microsoft viva, and Microsoft 365 copilot; and office consumer services, such as Microsoft 365 consumer subscriptions, Office licensed on-premises, and other office services. This segment also provides LinkedIn; and dynamics business solutions, including Dynamics 365, a set of intelligent, cloud-based applications across ERP, CRM, power apps, and power automate; and on-premises ERP and CRM applications. The Intelligent Cloud segment offers server products and cloud services, such as azure and other cloud services; SQL and windows server, visual studio, system center, and related client access licenses, as well as nuance and GitHub; and enterprise services including enterprise support services, industry solutions, and nuance professional services. The More Personal Computing segment offers Windows, including windows OEM licensing and other non-volume licensing of the Windows operating system; Windows commercial comprising volume licensing of the Windows operating system, windows cloud services, and other Windows commercial offerings; patent licensing; and windows Internet of Things; and devices, such as surface, HoloLens, and PC accessories. Additionally, this segment provides gaming, which includes Xbox hardware and content, and first- and third-party content; Xbox game pass and other subscriptions, cloud gaming, advertising, third-party disc royalties, and other cloud services; and search and news advertising, which includes Bing, Microsoft News and Edge, and third-party affiliates. The company sells its products through OEMs, distributors, and resellers; and directly through digital marketplaces, online, and retail stores. The company was founded in 1975 and is headquartered in Redmond, Washington.',
  'fullTimeEmployees': 228000,
  'companyOfficers': [],
  'irWebsite': 'http://www.microsoft.com/investor/default.aspx',
  'maxAge': 86400},
 'AAPL': {'address1': 'One Apple Park Way',
  'city': 'Cupertino',
  'state': 'CA',
  'zip': '95014',
  'country': 'United States',
  'phone': '(408) 996-1010',
  'website': 'https://www.apple.com',
  'industry': 'Consumer Electronics',
  'industryKey': 'consumer-electronics',
  'industryDisp': 'Consumer Electronics',
  'sector': 'Technology',
  'sectorKey': 'technology',
  'sectorDisp': 'Technology',
  'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. The company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, and HomePod. It also provides AppleCare support and cloud services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts, as well as advertising services include third-party licensing arrangements and its own advertising platforms. In addition, the company offers various subscription-based services, such as Apple Arcade, a game subscription service; Apple Fitness+, a personalized fitness service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was founded in 1976 and is headquartered in Cupertino, California.',
  'fullTimeEmployees': 164000,
  'companyOfficers': [],
  'irWebsite': 'http://investor.apple.com/',
  'maxAge': 86400},
 'GOOGL': {'address1': '1600 Amphitheatre Parkway',
  'city': 'Mountain View',
  'state': 'CA',
  'zip': '94043',
  'country': 'United States',
  'phone': '650 253 0000',
  'website': 'https://abc.xyz',
  'industry': 'Internet Content & Information',
  'industryKey': 'internet-content-information',
  'industryDisp': 'Internet Content & Information',
  'sector': 'Communication Services',
  'sectorKey': 'communication-services',
  'sectorDisp': 'Communication Services',
  'longBusinessSummary': 'Alphabet Inc. offers various products and platforms in the United States, Europe, the Middle East, Africa, the Asia-Pacific, Canada, and Latin America. It operates through Google Services, Google Cloud, and Other Bets segments. The Google Services segment provides products and services, including ads, Android, Chrome, devices, Gmail, Google Drive, Google Maps, Google Photos, Google Play, Search, and YouTube. It is also involved in the sale of apps and in-app purchases and digital content in the Google Play and YouTube; and devices, as well as in the provision of YouTube consumer subscription services. The Google Cloud segment offers infrastructure, cybersecurity, databases, analytics, AI, and other services; Google Workspace that include cloud-based communication and collaboration tools for enterprises, such as Gmail, Docs, Drive, Calendar, and Meet; and other services for enterprise customers. The Other Bets segment sells healthcare-related and internet services. The company was incorporated in 1998 and is headquartered in Mountain View, California.',
  'fullTimeEmployees': 181269,
  'companyOfficers': [],
  'maxAge': 86400}}

Historical prices:

df = tickers.history()
df.head()
open high low close volume adjclose
symbol date
MSFT 2025-01-02 425.529999 426.070007 414.850006 418.579987 16896500 418.579987
2025-01-03 421.079987 424.029999 419.540009 423.350006 16640200 423.350006
AAPL 2025-01-02 248.929993 249.100006 241.820007 243.850006 55740700 243.850006
2025-01-03 243.360001 244.179993 241.889999 243.360001 40202700 243.360001
GOOGL 2025-01-02 190.649994 192.000000 187.500000 189.429993 20370800 189.429993
df.tail()
open high low close volume adjclose
symbol date
MSFT 2025-01-03 421.079987 424.029999 419.540009 423.350006 16640200 423.350006
AAPL 2025-01-02 248.929993 249.100006 241.820007 243.850006 55740700 243.850006
2025-01-03 243.360001 244.179993 241.889999 243.360001 40202700 243.360001
GOOGL 2025-01-02 190.649994 192.000000 187.500000 189.429993 20370800 189.429993
2025-01-03 191.369995 193.210007 189.979996 191.789993 18582000 191.789993

Simplifying the multi-index:

df["symbol"] = df.index.get_level_values(0)
df["date"] = df.index.get_level_values(1)

df.reset_index(drop=True, inplace=True)

df[["date", "symbol", "adjclose"]].head()
date symbol adjclose
0 2025-01-02 MSFT 418.579987
1 2025-01-03 MSFT 423.350006
2 2025-01-02 AAPL 243.850006
3 2025-01-03 AAPL 243.360001
4 2025-01-02 GOOGL 189.429993

Optionally converting dates to be datetime-aware:

from pandas import to_datetime

# fix date values (see: https://github.com/dpguthrie/yahooquery/issues/210)
df["date"] = df["date"].astype("str")
df["date"] = df["date"].str.split(" ").str[0]
# convert to datetime-aware values:
df["date"] = to_datetime(df["date"]).dt.date

df[["date", "symbol", "adjclose"]].head()
date symbol adjclose
0 2025-01-02 MSFT 418.579987
1 2025-01-03 MSFT 423.350006
2 2025-01-02 AAPL 243.850006
3 2025-01-03 AAPL 243.360001
4 2025-01-02 GOOGL 189.429993

Pivoting the data:

prices_pivot = df.pivot(columns="symbol", values="adjclose", index="date")
prices_pivot.head()
symbol AAPL GOOGL MSFT
date
2025-01-02 243.850006 189.429993 418.579987
2025-01-03 243.360001 191.789993 423.350006