Pebble Coding


macOS10.15 Catalinaでdockerでpandas環境で米国のファイナンス情報を取得する

Docker Desktop on Macをインストールする。

Install Docker Desktop on Mac | Docker Documentation

python3.7が入ったDocker イメージをpullする。

$ docker pull python:3.7


$ docker run -it --name pytest python:3.7 /bin/bash


root@2a63671a0430:/home# pip3 install yfinance


root@2a63671a0430:/home# pip3 install lxml

root@2a63671a0430:/home# python3  
>>> import yfinance as yf
>>> msft = yf.Ticker("MSFT")
{'zip': '98052',
 'sector': 'Technology',
 'fullTimeEmployees': 144000,
 'longBusinessSummary': "Microsoft Corporation develops, licenses, and supports software, services, devices, and solutions worldwide. The company's Productivity and Business Processes segment offers Office, Exchange, SharePoint, Microsoft Teams, Office 365 Security and Compliance, and Skype for Business, as well as related Client Access Licenses (CAL); and Skype,, and OneDrive. It also provides LinkedIn that includes Talent and marketing solutions, and subscriptions; and Dynamics 365, a set of cloud-based and on-premises business solutions for small and medium businesses, large organizations, and divisions of enterprises. The company's Intelligent Cloud segment licenses SQL and Windows Servers, Visual Studio, System Center, and related CALs; GitHub that provides a collaboration platform and code hosting service for developers; and Azure, a cloud platform. It also provides support services and Microsoft consulting services to assist customers in developing, deploying, and managing Microsoft server and desktop solutions; and training and certification to developers and IT professionals on various Microsoft products. The company's More Personal Computing segment offers 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; Windows Internet of Things; and MSN advertising. It also provides Microsoft Surface, PC accessories, and other intelligent devices; Gaming, including Xbox hardware, and Xbox software and services; video games and third-party video game royalties; and Search, including Bing and Microsoft advertising. The company sells its products through distributors and resellers; and directly through digital marketplaces, online stores, and retail stores. It has strategic partnerships with Humana Inc. and Nokia. The company was founded in 1975 and is headquartered in Redmond, Washington.", 
'city': 'Redmond',
 'phone': '425-882-8080',
 'state': 'WA', 
'country': 'United States',
 'companyOfficers': [],
 'website': '',
 'maxAge': 1,
 'address1': 'One Microsoft Way', 
'fax': '425-706-7329', 
'industry': 'Software—Infrastructure',
 'previousClose': 184.42,
 'regularMarketOpen': 183.17, 
'twoHundredDayAverage': 150.7186, 
'trailingAnnualDividendYield': 0.010519467,
 'payoutRatio': 0.32930002, 
'volume24Hr': None, 
'regularMarketDayHigh': 183.5,
 'navPrice': None,
 'averageDailyVolume10Day': 33274840, 
'totalAssets': None,
 'regularMarketPreviousClose': 184.42,
 'fiftyDayAverage': 172.45728, 
'trailingAnnualDividendRate': 1.94, 
'open': 183.17,
 'averageVolume10days': 33274840, 
'expireDate': None,
 'yield': None, 
'algorithm': None,
 'dividendRate': 2.04,
 'exDividendDate': 1582070400, 
'beta': 1.154593,
 'circulatingSupply': None,
 'startDate': None, 
'regularMarketDayLow': 177.25,
 'priceHint': 2,
 'currency': 'USD', 
'trailingPE': 31.107819,
 'regularMarketVolume': 48600385,
 'lastMarket': None, 
'maxSupply': None,
 'openInterest': None,
 'marketCap': 1358364409856,
 'volumeAllCurrencies': None,
 'strikePrice': None, 
'averageVolume': 26463705,
 'priceToSalesTrailing12Months': 10.118246,
 'dayLow': 177.25, 
'ask': 172.35,
 'ytdReturn': None,
 'askSize': 2200,
 'volume': 48600385,
 'fiftyTwoWeekHigh': 190.7,
 'forwardPE': 28.347618,
 'fromCurrency': None, 
'fiveYearAvgDividendYield': 2.02,
 'fiftyTwoWeekLow': 108.8, 
'bid': 172.8, 
'tradeable': True,
 'dividendYield': 0.0111,
 'bidSize': 1400, 
'dayHigh': 183.5, 
'exchange': 'NMS', 
'shortName': 'Microsoft Corporation',
 'longName': 'Microsoft Corporation', 
'exchangeTimezoneName': 'America/New_York',
 'exchangeTimezoneShortName': 'EST',
 'isEsgPopulated': False,
 'gmtOffSetMilliseconds': '-18000000', 
'quoteType': 'EQUITY',
 'symbol': 'MSFT',
 'messageBoardId': 'finmb_21835',
 'market': 'us_market',
 'annualHoldingsTurnover': None,
 'enterpriseToRevenue': 9.768,
 'beta3Year': None, 
'profitMargins': 0.33016,
 'enterpriseToEbitda': 21.403, 
'52WeekChange': 0.65265703, 
'morningStarRiskRating': None, 
'forwardEps': 6.3,
 'revenueQuarterlyGrowth': None,
 'sharesOutstanding': 7606049792, 
'fundInceptionDate': None, 
'annualReportExpenseRatio': None,
 'bookValue': 14.467,
 'sharesShort': 56674560,
 'sharesPercentSharesOut': 0.0075,
 'fundFamily': None,
 'lastFiscalYearEnd': 1561852800,
 'heldPercentInstitutions': 0.75201, 
'netIncomeToCommon': 44323000320, 
'trailingEps': 5.741,
 'lastDividendValue': None, 
'SandP52WeekChange': 0.20640099,
 'priceToBook': 12.344646, 
'heldPercentInsiders': 0.014249999, 
'nextFiscalYearEnd': 1625011200, 
'mostRecentQuarter': 1577750400,
 'shortRatio': 2.16,
 'sharesShortPreviousMonthDate': 1577750400, 
'floatShares': 7494542361, 
'enterpriseValue': 1311279939584,
 'threeYearAverageReturn': None,
 'lastSplitDate': 1045526400,
 'lastSplitFactor': '2:1', 
'legalType': None,
 'morningStarOverallRating': None, 
'earningsQuarterlyGrowth': 0.383,
 'dateShortInterest': 1580428800, 
'pegRatio': 2.2,
 'lastCapGain': None,
 'shortPercentOfFloat': 0.0075,
 'sharesShortPriorMonth': 62706418,
 'category': None,
 'fiveYearAverageReturn': None,
 'regularMarketPrice': 183.17,
 'logo_url': ''}


DockerでPython3.6の環境構築!matplotlibインストールで詰まった話とかも - Qiita
Reliably download historical market data from Yahoo! Finance with Python | Ran Aroussi (Official Website)