Skip to content

Markets

Functions

getData

getData(tickers: Union[str, List[str]], start_date: str | None = None, end_date: str | None = None, period: str | None = None, interval: str = '1d') -> pd.DataFrame

Retrieve OHLCV market data for one or more tickers via yfinance.

Parameters:

Name Type Description Default
tickers str or list[str]

Ticker symbol or list of ticker symbols.

required
start_date str

Start date in YYYY-MM-DD format. Cannot be used with period.

None
end_date str

End date in YYYY-MM-DD format. Cannot be used with period.

None
period str

Rolling lookback period. Cannot be used with start_date/end_date. Valid values: 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max.

None
interval str

Bar interval. Default "1d". Intraday intervals (< 1d) are limited to the last 60 days by Yahoo Finance. Valid values: 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo.

'1d'

Returns:

Type Description
DataFrame

DataFrame indexed by date with columns: Open, High, Low, Close, Volume.

Raises:

Type Description
ValueError

If both period and start_date/end_date are provided.

Examples:

>>> from quantmod.markets import getData
>>> df = getData("AAPL", start_date="2024-01-01", end_date="2024-12-31")
>>> df = getData(["AAPL", "MSFT"], period="6mo")
>>> df = getData("TSLA", period="1mo", interval="1h")

getTicker

getTicker(ticker: str) -> yf.Ticker

Return a yfinance.Ticker object for a given symbol.

The Ticker object exposes a wide range of fundamental and market data attributes, including info, history, dividends, splits, financials, balance_sheet, cashflow, earnings, options, option_chain, recommendations, and news.

Parameters:

Name Type Description Default
ticker str

Ticker symbol (e.g. "AAPL", "^NSEI").

required

Returns:

Type Description
Ticker

yfinance Ticker object.

Examples:

>>> from quantmod.markets import getTicker
>>> t = getTicker("AAPL")
>>> t.info["longName"]
'Apple Inc.'
>>> t.dividends