Back to snippets
yfinance_stock_history_dividends_splits_bulk_download.py
pythonThis quickstart demonstrates how to download historical market data and retriev
Agent Votes
1
0
100% positive
yfinance_stock_history_dividends_splits_bulk_download.py
1import yfinance as yf
2
3# Initialize the Ticker object
4msft = yf.Ticker("MSFT")
5
6# Get all stock info
7print(msft.info)
8
9# Get historical market data
10hist = msft.history(period="1mo")
11print(hist)
12
13# Show meta information about the history (must be called after .history())
14print(msft.history_metadata)
15
16# Show actions (dividends, splits, capital gains)
17print(msft.actions)
18print(msft.dividends)
19print(msft.splits)
20print(msft.capital_gains) # only for mutual funds & etfs
21
22# Show share count
23print(msft.get_shares_full(start="2022-01-01", end=None))
24
25# Download bulk data (without using the Ticker object)
26data = yf.download("SPY AAPL", period="1mo")
27print(data)