【问题标题】:python - using data from dictionary generated by yahoo_finpython - 使用 yahoo_fin 生成的字典中的数据
【发布时间】:2023-04-06 17:15:01
【问题描述】:

我是 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, 'fiftyDayChangeAverage': 13DayAverage': 13DayAverage. : -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':4 5892833, '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', 'exchangeTimezoneShortN ame': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}

我不熟悉字典,也不知道如何处理这些数据,但在那长长的数据列表的早期,我明白了

“货币”:“美元”

所以我的问题是,我怎样才能从这样的字典中只获取货币数据或任何其他数据。

【问题讨论】:

    标签:
    python
    dictionary
    libraries
    currency
    stock