from yahooquery import Ticker
= Ticker("NFLX") ticker
Appendix B — The yahooquery
Package
B.1 Single Company
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:
= ticker.history(start="2024-01-01", end="2024-01-31", adj_ohlc=True)
df 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
= Ticker( ["MSFT", "AAPL", "GOOGL"]) tickers
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:
= tickers.history()
df df.head()
open | high | low | close | volume | adjclose | dividends | ||
---|---|---|---|---|---|---|---|---|
symbol | date | |||||||
MSFT | 2024-01-02 | 373.859985 | 375.899994 | 366.769989 | 370.869995 | 25258600 | 368.117249 | 0.0 |
2024-01-03 | 369.010010 | 373.260010 | 368.510010 | 370.600006 | 23083500 | 367.849274 | 0.0 | |
2024-01-04 | 370.670013 | 373.100006 | 367.170013 | 367.940002 | 20901500 | 365.208984 | 0.0 | |
2024-01-05 | 368.970001 | 372.059998 | 366.500000 | 367.750000 | 20987000 | 365.020416 | 0.0 | |
2024-01-08 | 369.299988 | 375.200012 | 369.010010 | 374.690002 | 23134000 | 371.908905 | 0.0 |
Simplifying the multi-index:
from pandas import to_datetime
"symbol"] = df.index.get_level_values(0)
df["date"] = to_datetime(df.index.get_level_values(1)).date
df[
=True, inplace=True)
df.reset_index(drop"date", "symbol", "adjclose"]].head() df[[
date | symbol | adjclose | |
---|---|---|---|
0 | 2024-01-02 | MSFT | 368.117249 |
1 | 2024-01-03 | MSFT | 367.849274 |
2 | 2024-01-04 | MSFT | 365.208984 |
3 | 2024-01-05 | MSFT | 365.020416 |
4 | 2024-01-08 | MSFT | 371.908905 |
Pivoting the data:
= df.pivot(columns="symbol", values="adjclose", index="date")
prices_pivot prices_pivot.head()
symbol | AAPL | GOOGL | MSFT |
---|---|---|---|
date | |||
2024-01-02 | 184.734970 | 137.828705 | 368.117249 |
2024-01-03 | 183.351746 | 138.576859 | 367.849274 |
2024-01-04 | 181.023163 | 136.053101 | 365.208984 |
2024-01-05 | 180.296722 | 135.394745 | 365.020416 |
2024-01-08 | 184.655365 | 138.497055 | 371.908905 |