python - 使用 yahoo_fin 生成的字典中的数据
python - using data from dictionary generated by yahoo_fin
我是 python 的新手,我的目标是编写一些股票分析代码。我已经安装了 yahoo_fin 并且刚刚开始尝试使用它。我已经开始使用 get_live_price
提取实时报价
即
>>> get_live_price('aapl')
126.12000274658203
我正在处理以美元和加元计价的股票,这使我需要用一种通用货币来表示它们。所以我想将所有美元股票转换为加元,反之亦然。当然,在我转换货币之前,我需要先确定一只股票的上市货币。
我发现 yahoo_fin.stock_info 包括 get_quote_data 例如
>>> get_quote_data('aapl')
得到了这个词典
{'language': 'en-US', 'region': 'US', 'quoteType': 'EQUITY', 'quoteSourceName': 'Nasdaq Real Time Price', 'triggerable': True, 'currency': 'USD', 'epsTrailingTwelveMonths': 3.687, 'epsForward': 4.68, 'epsCurrentYear': 4.45, 'priceEpsCurrentYear': 28.476248, 'sharesOutstanding': 16788100096, 'bookValue': 3.936, 'fiftyDayAverage': 133.55576, 'fiftyDayAverageChange': -6.8364563, 'fiftyDayAverageChangePercent': -0.051188033, 'twoHundredDayAverage': 122.48235, 'twoHundredDayAverageChange': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'forwardPE': 27.076775, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy': 0, 'tradeable': False, 'marketState': 'REGULAR', 'regularMarketChange': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayHigh': 129.72, 'regularMarketDayRange': '125.6 - 129.72', 'regularMarketDayLow': 125.6, 'regularMarketVolume': 45892833, 'regularMarketPreviousClose': 129.87, 'bid': 126.36, 'ask': 126.3, 'bidSize': 8, 'askSize': 8, 'fullExchangeName': 'NasdaqGS', 'financialCurrency': 'USD', 'regularMarketOpen': 128.01, 'averageDailyVolume3Month': 104097755, 'averageDailyVolume10Day': 84604500, 'fiftyTwoWeekLowChange': 73.5668, 'fiftyTwoWeekLowChangePercent': 1.3840704, 'fiftyTwoWeekRange': '53.1525 - 145.09', 'fiftyTwoWeekHighChange': -18.370697, 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1613001600, 'earningsTimestamp': 1611765000, 'earningsTimestampStart': 1619607540, 'earningsTimestampEnd': 1620043200, 'trailingAnnualDividendRate': 0.807, 'trailingPE': 34.369217, 'trailingAnnualDividendYield': 0.006213906, 'firstTradeDateMilliseconds': 345479400000, 'priceHint': 2, 'exchange': 'NMS', 'shortName': 'Apple Inc.', 'longName': 'Apple Inc.', 'messageBoardId': 'finmb_24937', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}
我不熟悉字典,也不知道如何使用这些数据,但在那一长串数据的早期,我看到了
'currency': 'USD'
所以我的问题是,如何从这样的字典中获取货币数据或任何其他相关数据。
so my question is, how can I take just the currency data, or any other
data for that matter, from a dictionary like this.
字典中存在键值对。在您的特定情况下,您可以通过以下方式访问 'currency':'USD'
:
data = {'language': 'en-US', 'region': 'US', 'quoteType': 'EQUITY', 'quoteSourceName': 'Nasdaq Real Time Price', 'triggerable': True, 'currency': 'USD', 'epsTrailingTwelveMonths': 3.687, 'epsForward': 4.68, 'epsCurrentYear': 4.45, 'priceEpsCurrentYear': 28.476248, 'sharesOutstanding': 16788100096, 'bookValue': 3.936, 'fiftyDayAverage': 133.55576, 'fiftyDayAverageChange': -6.8364563, 'fiftyDayAverageChangePercent': -0.051188033, 'twoHundredDayAverage': 122.48235, 'twoHundredDayAverageChange': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'forwardPE': 27.076775, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy': 0, 'tradeable': False, 'marketState': 'REGULAR', 'regularMarketChange': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayHigh': 129.72, 'regularMarketDayRange': '125.6 - 129.72', 'regularMarketDayLow': 125.6, 'regularMarketVolume': 45892833, 'regularMarketPreviousClose': 129.87, 'bid': 126.36, 'ask': 126.3, 'bidSize': 8, 'askSize': 8, 'fullExchangeName': 'NasdaqGS', 'financialCurrency': 'USD', 'regularMarketOpen': 128.01, 'averageDailyVolume3Month': 104097755, 'averageDailyVolume10Day': 84604500, 'fiftyTwoWeekLowChange': 73.5668, 'fiftyTwoWeekLowChangePercent': 1.3840704, 'fiftyTwoWeekRange': '53.1525 - 145.09', 'fiftyTwoWeekHighChange': -18.370697, 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1613001600, 'earningsTimestamp': 1611765000, 'earningsTimestampStart': 1619607540, 'earningsTimestampEnd': 1620043200, 'trailingAnnualDividendRate': 0.807, 'trailingPE': 34.369217, 'trailingAnnualDividendYield': 0.006213906, 'firstTradeDateMilliseconds': 345479400000, 'priceHint': 2, 'exchange': 'NMS', 'shortName': 'Apple Inc.', 'longName': 'Apple Inc.', 'messageBoardId': 'finmb_24937', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}
print(data['currency'])
当您从字典 data
.
中访问键 currency
的值时,输出将是 USD
如需进一步阅读词典,我建议:
我是 python 的新手,我的目标是编写一些股票分析代码。我已经安装了 yahoo_fin 并且刚刚开始尝试使用它。我已经开始使用 get_live_price
提取实时报价
即
>>> get_live_price('aapl') 126.12000274658203
我正在处理以美元和加元计价的股票,这使我需要用一种通用货币来表示它们。所以我想将所有美元股票转换为加元,反之亦然。当然,在我转换货币之前,我需要先确定一只股票的上市货币。 我发现 yahoo_fin.stock_info 包括 get_quote_data 例如
>>> get_quote_data('aapl')
得到了这个词典
{'language': 'en-US', 'region': 'US', 'quoteType': 'EQUITY', 'quoteSourceName': 'Nasdaq Real Time Price', 'triggerable': True, 'currency': 'USD', 'epsTrailingTwelveMonths': 3.687, 'epsForward': 4.68, 'epsCurrentYear': 4.45, 'priceEpsCurrentYear': 28.476248, 'sharesOutstanding': 16788100096, 'bookValue': 3.936, 'fiftyDayAverage': 133.55576, 'fiftyDayAverageChange': -6.8364563, 'fiftyDayAverageChangePercent': -0.051188033, 'twoHundredDayAverage': 122.48235, 'twoHundredDayAverageChange': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'forwardPE': 27.076775, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy': 0, 'tradeable': False, 'marketState': 'REGULAR', 'regularMarketChange': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayHigh': 129.72, 'regularMarketDayRange': '125.6 - 129.72', 'regularMarketDayLow': 125.6, 'regularMarketVolume': 45892833, 'regularMarketPreviousClose': 129.87, 'bid': 126.36, 'ask': 126.3, 'bidSize': 8, 'askSize': 8, 'fullExchangeName': 'NasdaqGS', 'financialCurrency': 'USD', 'regularMarketOpen': 128.01, 'averageDailyVolume3Month': 104097755, 'averageDailyVolume10Day': 84604500, 'fiftyTwoWeekLowChange': 73.5668, 'fiftyTwoWeekLowChangePercent': 1.3840704, 'fiftyTwoWeekRange': '53.1525 - 145.09', 'fiftyTwoWeekHighChange': -18.370697, 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1613001600, 'earningsTimestamp': 1611765000, 'earningsTimestampStart': 1619607540, 'earningsTimestampEnd': 1620043200, 'trailingAnnualDividendRate': 0.807, 'trailingPE': 34.369217, 'trailingAnnualDividendYield': 0.006213906, 'firstTradeDateMilliseconds': 345479400000, 'priceHint': 2, 'exchange': 'NMS', 'shortName': 'Apple Inc.', 'longName': 'Apple Inc.', 'messageBoardId': 'finmb_24937', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}
我不熟悉字典,也不知道如何使用这些数据,但在那一长串数据的早期,我看到了
'currency': 'USD'
所以我的问题是,如何从这样的字典中获取货币数据或任何其他相关数据。
so my question is, how can I take just the currency data, or any other data for that matter, from a dictionary like this.
字典中存在键值对。在您的特定情况下,您可以通过以下方式访问 'currency':'USD'
:
data = {'language': 'en-US', 'region': 'US', 'quoteType': 'EQUITY', 'quoteSourceName': 'Nasdaq Real Time Price', 'triggerable': True, 'currency': 'USD', 'epsTrailingTwelveMonths': 3.687, 'epsForward': 4.68, 'epsCurrentYear': 4.45, 'priceEpsCurrentYear': 28.476248, 'sharesOutstanding': 16788100096, 'bookValue': 3.936, 'fiftyDayAverage': 133.55576, 'fiftyDayAverageChange': -6.8364563, 'fiftyDayAverageChangePercent': -0.051188033, 'twoHundredDayAverage': 122.48235, 'twoHundredDayAverageChange': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'forwardPE': 27.076775, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy': 0, 'tradeable': False, 'marketState': 'REGULAR', 'regularMarketChange': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayHigh': 129.72, 'regularMarketDayRange': '125.6 - 129.72', 'regularMarketDayLow': 125.6, 'regularMarketVolume': 45892833, 'regularMarketPreviousClose': 129.87, 'bid': 126.36, 'ask': 126.3, 'bidSize': 8, 'askSize': 8, 'fullExchangeName': 'NasdaqGS', 'financialCurrency': 'USD', 'regularMarketOpen': 128.01, 'averageDailyVolume3Month': 104097755, 'averageDailyVolume10Day': 84604500, 'fiftyTwoWeekLowChange': 73.5668, 'fiftyTwoWeekLowChangePercent': 1.3840704, 'fiftyTwoWeekRange': '53.1525 - 145.09', 'fiftyTwoWeekHighChange': -18.370697, 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1613001600, 'earningsTimestamp': 1611765000, 'earningsTimestampStart': 1619607540, 'earningsTimestampEnd': 1620043200, 'trailingAnnualDividendRate': 0.807, 'trailingPE': 34.369217, 'trailingAnnualDividendYield': 0.006213906, 'firstTradeDateMilliseconds': 345479400000, 'priceHint': 2, 'exchange': 'NMS', 'shortName': 'Apple Inc.', 'longName': 'Apple Inc.', 'messageBoardId': 'finmb_24937', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}
print(data['currency'])
当您从字典 data
.
currency
的值时,输出将是 USD
如需进一步阅读词典,我建议: