首页 > 解决方案 > yFinance 多股票代码信息不起作用

问题描述

我无法通过 yFinance 获取多行情信息。我想建立多股票代码方法,而不是单独遍历每只股票,这样我就可以使用会话功能并提高性能。

我使用 yfinance 0.1.63 和 python 364。

我的代码是这个

import yfinance as yf

tickers = yf.Tickers('msft aapl goog')
print(tickers.tickers.GOOG.actions)
print(tickers.tickers.AAPL.history(period="1mo"))
print(tickers.tickers.MSFT.info)

但我的输出是这样的

Traceback (most recent call last):
  File "C:\opt\jobs\python\multitech.py", line 32, in <module>
    print(tickers.tickers.GOOG.actions)
AttributeError: 'dict' object has no attribute 'GOOG'

这似乎对其他人有用,但对我不起作用

标签: pythonapiyfinance

解决方案


我遇到了同样的问题。花了一些时间四处寻找,但想出了解决方案。在 Anaconda 包下使用 python 3.8 和 yfinance 0.1.63。

import yfinance as yf

tickers = yf.Tickers('msft aapl goog')

print(tickers.tickers['GOOG'].actions)
print(tickers.tickers['AAPL'].history(period="1mo"))
print(tickers.tickers['MSFT'].info)

推荐阅读