股票代码与股票代码列表#
类#
Ticker模块允许您以Python风格的方式访问股票代码数据。
股票代码示例代码#
Ticker模块允许您以Python风格的方式访问股票代码数据。
import yfinance as yf
dat = yf.Ticker("MSFT")
# get historical market data
dat.history(period='1mo')
# options
dat.option_chain(dat.options[0]).calls
# get financials
dat.balance_sheet
dat.quarterly_income_stmt
# dates
dat.calendar
# general info
dat.info
# analysis
dat.analyst_price_targets
# websocket
dat.live()
要初始化多个Ticker对象,请使用
import yfinance as yf
tickers = yf.Tickers('msft aapl goog')
# access each ticker using (example)
tickers.tickers['MSFT'].info
tickers.tickers['AAPL'].history(period="1mo")
tickers.tickers['GOOG'].actions
# websocket
tickers.live()
对于ETF/共同基金的股票代码,Ticker.funds_data提供与基金相关数据的访问。
基金的前十大持仓及其他数据与类别平均值一起以pd.DataFrame格式返回。
import yfinance as yf
spy = yf.Ticker('SPY')
data = spy.funds_data
# show fund description
data.description
# show operational information
data.fund_overview
data.fund_operations
# show holdings related information
data.asset_classes
data.top_holdings
data.equity_holdings
data.bond_holdings
data.bond_ratings
data.sector_weightings
如果你想使用代理服务器下载数据,可以使用:
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_capital_gains(proxy="PROXY_SERVER")
msft.get_balance_sheet(proxy="PROXY_SERVER")
msft.get_cashflow(proxy="PROXY_SERVER")
msft.option_chain(..., proxy="PROXY_SERVER")
...
要初始化多个Ticker对象,请使用Tickers模块
import yfinance as yf
tickers = yf.Tickers('msft aapl goog')
# access each ticker using (example)
tickers.tickers['MSFT'].info
tickers.tickers['AAPL'].history(period="1mo")
tickers.tickers['GOOG'].actions
# websocket
tickers.live()