Yfinance雅虎金融市场数据下载器
自从雅虎金融部门停用了他们的历史数据 API 后,许多依赖它的程序都无法正常工作。yfinance 旨在通过提供一种可靠、线程化和 Pythonic 的方式从 Yahoo 金融下载历史市场数据来解决这个问题。
快速开始
Ticker 模块
该Ticker
模块允许你以更 Pythonic 的方式访问股票数据:
注意:雅虎金融的日期时间接收为 UTC。
import yfinance as yf msft = yf.Ticker("MSFT") # get stock info msft.info # get historical market data hist = msft.history(period="max") # show actions (dividends, splits) msft.actions # show dividends msft.dividends # show splits msft.splits # show financials msft.financials msft.quarterly_financials # show major holders msft.major_holders # show institutional holders msft.institutional_holders # show balance sheet msft.balance_sheet msft.quarterly_balance_sheet # show cashflow msft.cashflow msft.quarterly_cashflow # show earnings msft.earnings msft.quarterly_earnings # show sustainability msft.sustainability # show analysts recommendations msft.recommendations # show next event (earnings, etc) msft.calendar # show ISIN code - *experimental* # ISIN = International Securities Identification Number msft.isin # show options expirations msft.options # show news msft.news # get option chain for specific expiration opt = msft.option_chain('YYYY-MM-DD') # data available via: opt.calls, opt.puts
如果要使用代理服务器下载数据,请使用:
import yfinance as yf msft = yf.Ticker("MSFT") msft.history(..., proxy="PROXY_SERVER") msft.get_actions(proxy="PROXY_SERVER") msft.get_dividends(proxy="PROXY_SERVER") msft.get_splits(proxy="PROXY_SERVER") msft.get_balance_sheet(proxy="PROXY_SERVER") msft.get_cashflow(proxy="PROXY_SERVER") msft.option_chain(..., proxy="PROXY_SERVER") ...
要使用自定义requests
会话(例如缓存对 API 的调用或自定义User-agent
标头),请将session=
参数传递给 Ticker 构造函数。
import requests_cache session = requests_cache.CachedSession('yfinance.cache') session.headers['User-agent'] = 'my-program/1.0' ticker = yf.Ticker('msft aapl goog', session=session) # The scraped response will be stored in the cache ticker.actions
要初始化多个Ticker
对象,请使用
import yfinance as yf tickers = yf.Tickers('msft aapl goog') # ^ returns a named tuple of Ticker objects # access each ticker using (example) tickers.tickers.MSFT.info tickers.tickers.AAPL.history(period="1mo") tickers.tickers.GOOG.actions
获取多个代码的数据
import yfinance as yf data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")
安装
使用pip
安装yfinance
$ pip install yfinance --upgrade --no-cache-dir
要求
可选(如果你想使用pandas_datareader
)
- pandas_datareader >= 0.4.0
评论
proxyee-downHTTP 下载器
项目已经停止维护proxyee-down是http下载工具,基于http代理,支持多连接分块下载。proxyee-down使用本地http代理服务器方式嗅探下载请求,支持所有操作系统和大部分主流浏览器
proxyee-downHTTP 下载器
0
youtube-dlGyoutube-dl 媒体下载器
youtube-dlG,流行的 youtube-dl 媒体下载器的跨平台前端 GUI。是用 wxPy
youtube-dlGyoutube-dl 媒体下载器
0
AcDown动漫下载器
AcDown动漫下载器是一个免费、开源、专业、跨平台的下载器。界面简洁,使用方便,能够下载国内大部分在线视频网站和在线漫画网站的资源。支持解析下载的网站包括Acfun、哔哩哔哩(Bilibili)、优
AcDown动漫下载器
0
youtube-dlGyoutube-dl 媒体下载器
youtube-dlG,流行的youtube-dl媒体下载器的跨平台前端GUI。是用 wxPython所写的,wxPython是Python语言的一套优秀的GUI图形库。要求:Python2.7.3+
youtube-dlGyoutube-dl 媒体下载器
0