使用 yfinance 获取带有“.”的代码信息。

Get information using yfinance for tickers with "."

我正在使用yfinance获取多只股票的基本信息。 使用这几行。

import yfinance as yf
tickers = yf.Tickers('msft aapl goog')
tickers.msft.info

然而,香港的股票代号有'.'。在股票行情中 即 0001.HK、0002.HK 等

曾经写过

tickers.0001.HK.info

由于 '.' 而出错它之间。 如何用'.'指定符号?

提前致谢。

我认为您可能需要自己循环查看代码:

tickers = ['0001.HK', '0002.HK']
data = [yf.Ticker(ticker).info for ticker in tickers]
stock_info = dict(zip(ticker, data))

然后访问字典中的数据:

stock_info['0001.HK']
  • 下载组在这种情况下不起作用,因为 Ticker 对象方法是通过 . 访问的
    • 要在符号中没有 . 时下载多个代码,请参阅此 solution
  • tickers 中的每个代码创建 Ticker 对象的 dict,然后您将能够在 [=18= 中使用任何 Ticker 方法] 在 dict
  • TAB. 处完成将显示 Ticker 对象的正确可用方法。
import yfinance as yf

tickers = ['0001.HK', '0002.HK', 'msft']

# create dict of Ticker objects
ticker_dict = {t: yf.Ticker(t) for t in tickers}

# print(ticker_dict)
{'0001.HK': yfinance.Ticker object <0001.HK>,
 '0002.HK': yfinance.Ticker object <0002.HK>,
 'msft': yfinance.Ticker object <MSFT>}

# access Ticker info
print(ticker_dict['0001.HK'].get_info())

[out]:
{'52WeekChange': -0.24687731000000002,
 'SandP52WeekChange': 0.13263035,
 'address1': 'Cheung Kong Center',
 'address2': "48th Floor 2 Queen's Road",
 'algorithm': None,
 'annualHoldingsTurnover': None,
 'annualReportExpenseRatio': None,
 'ask': 50.95,
 'askSize': 0,
 'averageDailyVolume10Day': 6584419,
 'averageVolume': 9287631,
 'averageVolume10days': 6584419,
 'beta': 1.069105,
 'beta3Year': None,
 'bid': 50.9,
 'bidSize': 0,
 'bookValue': 123.617,
 'category': None,
 'circulatingSupply': None,
 'city': 'Central',
 'companyOfficers': [],
 'country': 'Hong Kong',
 'currency': 'HKD',
 'dateShortInterest': None,
 'dayHigh': 51.6,
 'dayLow': 50,
 'dividendRate': 3.17,
 'dividendYield': 0.061900000000000004,
 'earningsQuarterlyGrowth': 0.025,
 'enterpriseToEbitda': 7.18,
 'enterpriseToRevenue': 2.077,
 'enterpriseValue': 621169344512,
 'exDividendDate': 1589846400,
 'exchange': 'HKG',
 'exchangeTimezoneName': 'Asia/Hong_Kong',
 'exchangeTimezoneShortName': 'HKT',
 'expireDate': None,
 'fax': '852 2128 1705',
 'fiftyDayAverage': 50.92857,
 'fiftyTwoWeekHigh': 76,
 'fiftyTwoWeekLow': 45.05,
 'fiveYearAverageReturn': None,
 'fiveYearAvgDividendYield': 3.55,
 'floatShares': 2674341349,
 'forwardEps': 10.81,
 'forwardPE': 4.708603,
 'fromCurrency': None,
 'fundFamily': None,
 'fundInceptionDate': None,
 'gmtOffSetMilliseconds': '28800000',
 'heldPercentInsiders': 0.3057,
 'heldPercentInstitutions': 0.20788999,
 'industry': 'Conglomerates',
 'isEsgPopulated': False,
 'lastCapGain': None,
 'lastDividendValue': None,
 'lastFiscalYearEnd': 1577750400,
 'lastMarket': None,
 'lastSplitDate': None,
 'lastSplitFactor': None,
 'legalType': None,
 'logo_url': 'https://logo.clearbit.com/ckh.com.hk',
 'longBusinessSummary': 'CK Hutchison Holdings Limited, an investment holding '
                        'company, operates in ports and related services, '
                        'retail, infrastructure, energy, and '
                        'telecommunications businesses worldwide. The company '
                        'invests in, develops, and operates ports, which '
                        'operate 290 berths in 52 ports spanning 27 countries '
                        'throughout Asia, the Middle East, Africa, Europe, the '
                        'Americas, and Australasia; and provides logistics and '
                        'transportation-related services, such as cruise ship '
                        'terminals, airport operations, distribution centers, '
                        'rail services, and ship repair facilities. It also '
                        'operates a network of approximately 15,700 retail '
                        'stores that offer health and beauty products, food '
                        'and fine wines, consumer electronics, and electrical '
                        'appliances in Asia and Europe, as well as operates '
                        'supermarkets; and manufactures and distributes '
                        'bottled water and beverages under the Watsons Water '
                        'and Mr. Juicy brands in Hong Kong and Mainland China. '
                        'In addition, the company invests in energy '
                        'infrastructure, transportation infrastructure, water '
                        'infrastructure, waste management, waste-to-energy, '
                        'household infrastructure, and other infrastructure '
                        'related businesses primarily in Hong Kong, Mainland '
                        'China, the United Kingdom, Continental Europe, '
                        'Australia, New Zealand, and Canada. Further, it '
                        'provides mobile telecommunications and data services, '
                        'as well as operates as an integrated energy company '
                        'in the United States and the Asia Pacific. '
                        'Additionally, it manufactures and sells '
                        'pharmaceuticals and healthcare products; researches, '
                        'develops, manufactures, commercializes, markets, and '
                        'sells nutraceuticals and agriculture-related '
                        'products; provides marine construction and ship '
                        'repair yard, water and sewerage, gas distribution, '
                        'and aircraft maintenance services; and leases rolling '
                        'stocks. CK Hutchison Holdings Limited was '
                        'incorporated in 2014 and is based in Central, Hong '
                        'Kong.',
 'longName': 'CK Hutchison Holdings Limited',
 'market': 'hk_market',
 'marketCap': 196282630144,
 'maxAge': 1,
 'maxSupply': None,
 'messageBoardId': 'finmb_411322',
 'morningStarOverallRating': None,
 'morningStarRiskRating': None,
 'mostRecentQuarter': 1577750400,
 'navPrice': None,
 'netIncomeToCommon': 39829999616,
 'nextFiscalYearEnd': 1640908800,
 'open': 51.5,
 'openInterest': None,
 'payoutRatio': 0.3069,
 'pegRatio': None,
 'phone': '852 2128 1188',
 'previousClose': 51.25,
 'priceHint': 3,
 'priceToBook': 0.41175568,
 'priceToSalesTrailing12Months': 0.65641755,
 'profitMargins': 0.13319999,
 'quoteType': 'EQUITY',
 'regularMarketDayHigh': 51.6,
 'regularMarketDayLow': 50,
 'regularMarketOpen': 51.5,
 'regularMarketPreviousClose': 51.25,
 'regularMarketPrice': 51.5,
 'regularMarketVolume': 5395197,
 'revenueQuarterlyGrowth': None,
 'sector': 'Industrials',
 'sharesOutstanding': 3856240128,
 'sharesPercentSharesOut': None,
 'sharesShort': None,
 'sharesShortPreviousMonthDate': None,
 'sharesShortPriorMonth': None,
 'shortName': 'CKH HOLDINGS',
 'shortPercentOfFloat': None,
 'shortRatio': None,
 'startDate': None,
 'strikePrice': None,
 'symbol': '0001.HK',
 'threeYearAverageReturn': None,
 'toCurrency': None,
 'totalAssets': None,
 'tradeable': False,
 'trailingAnnualDividendRate': 3.17,
 'trailingAnnualDividendYield': 0.061853660000000005,
 'trailingEps': 10.33,
 'trailingPE': 4.9273963,
 'twoHundredDayAverage': 57.365494,
 'volume': 5395197,
 'volume24Hr': None,
 'volumeAllCurrencies': None,
 'website': 'http://www.ckh.com.hk',
 'yield': None,
 'ytdReturn': None}