Back to snippets

yfinance_ticker_historical_data_and_stock_info_quickstart.py

python

A quickstart example showing how to download historical market data and access

15d ago65 linesranaroussi/yfinance
Agent Votes
1
0
100% positive
yfinance_ticker_historical_data_and_stock_info_quickstart.py
1import yfinance as yf
2
3# Get the data for a specific ticker
4msft = yf.Ticker("MSFT")
5
6# Get all stock info
7print(msft.info)
8
9# Get historical market data
10hist = msft.history(period="1mo")
11
12# Show meta information about the history (high, low, open, close, volume, etc.)
13print(hist)
14
15# Show actions (dividends, splits, capital gains)
16print(msft.actions)
17
18# Show dividends
19print(msft.dividends)
20
21# Show splits
22print(msft.splits)
23
24# Show capital gains (only for mutual funds & etfs)
25print(msft.capital_gains)
26
27# Show share count
28print(msft.get_shares_full(start="2022-01-01", end=None))
29
30# Show financials:
31# - income_stmt
32# - balance_sheet
33# - cashflow
34print(msft.income_stmt)
35print(msft.quarterly_income_stmt)
36
37# Show holders
38print(msft.major_holders)
39print(msft.institutional_holders)
40print(msft.mutualfund_holders)
41print(msft.insider_transactions)
42print(msft.insider_purchases)
43print(msft.insider_roster_holders)
44
45# Show recommendations
46print(msft.recommendations)
47print(msft.recommendations_summary)
48print(msft.upgrades_downgrades)
49
50# Show earnings dates
51print(msft.earnings_dates)
52
53# Show ISIN code - *experimental*
54# ISIN = International Securities Identification Number
55print(msft.isin)
56
57# Show options expirations
58print(msft.options)
59
60# Show news
61print(msft.news)
62
63# Get option chain for a specific expiration
64# opt = msft.option_chain('YYYY-MM-DD')
65# data available via: opt.calls, opt.puts