YAHOOFINANCE() Function Reference


The YAHOOFINANCE() function is a powerful and flexible tool for fetching data from Yahoo Finance. The function’s behavior is context-aware, meaning it will return either real-time or historical data based on the parameters you provide.


Syntax

js

YAHOOFINANCE(ticker, [attribute], [start_date], [end_date|num_days], [interval])


Parameter Breakdown

Parameter Description
ticker

Required. The stock ticker symbol(s). Provide a single ticker as a string (e.g., "AAPL") or multiple tickers as a comma-separated string (e.g., "AAPL,GOOGL"). Multi-ticker requests are only supported for historical data.

[attribute]

Optional. The specific data point you want to fetch. This can be a real-time metric or a historical data type. Defaults to "price" if omitted.

[start_date]

Optional. A valid date. The presence of a start_date triggers a historical data request. If omitted, the function will fetch real-time data.

[end_date|num_days]

Optional. Can be either a valid end date for a historical period (e.g., TODAY()) or a number of days to add to the start_date. If omitted for a historical request, it will return data for the start_date only.

[interval]

Optional. The interval for historical data. Valid options are "1d" (daily), "1wk" (weekly), and "1mo" (monthly). Defaults to "1d".


Available Attributes

The [attribute] parameter is the key to controlling the function. Its behavior depends on whether you are making a real-time or historical request.

Real-Time Attributes

Use these attributes when you do not provide a [start_date].

Attribute Description
"price"The current or most recent market price. (Default)
"name"The full name of the company or security.
"shortname"The short name of the company.
"high"The highest price of the current trading day.
"low"The lowest price of the current trading day.
"volume"The trading volume for the current day.
"prevclose"The closing price of the previous trading day.
"52weekhigh"The highest price in the last 52 weeks.
"52weeklow"The lowest price in the last 52 weeks.
"currency"The currency in which the security is traded.
"timezone"The timezone of the exchange.

Historical Attributes

Use these attributes when you do provide a [start_date].

Attribute Description
"ALL"Returns a full table with headers: Date, Open, High, Low, Close, Volume.
"OPEN"Returns a two-column table with Date and the opening price.
"HIGH"Returns a two-column table with Date and the highest price.
"LOW"Returns a two-column table with Date and the lowest price.
"CLOSE"Returns a two-column table with Date and the closing price.
"VOLUME"Returns a two-column table with Date and the trading volume.
"dividends"Returns a table with the Date and amount of all dividend payments in the period.
"splits"Returns a table with the Date and ratio of all stock splits in the period.

Examples

Real-Time Examples

// Get the current price of Apple (default attribute)
=YAHOOFINANCE("AAPL")

// Get the full company name for Google
=YAHOOFINANCE("GOOGL", "name")

// Get the 52-week high for NVIDIA
=YAHOOFINANCE("NVDA", "52weekhigh")

Historical Examples

// Get a full OHLCV table for Tesla for the last 30 days
=YAHOOFINANCE("TSLA", "ALL", TODAY()-30, TODAY())

// Get only the closing price for Microsoft since the beginning of the year
=YAHOOFINANCE("MSFT", "CLOSE", "1/1/2024")

// Get all dividends paid by Coca-Cola since 2015
=YAHOOFINANCE("KO", "dividends", "1/1/2015", TODAY())

// Get historical closing prices for multiple stocks
=YAHOOFINANCE("F,GM,TM", "CLOSE", "6/1/2024", "6/30/2024")

Important Notes

How to Handle Data Refreshes

Custom functions in Google Sheets do not refresh automatically like the native GOOGLEFINANCE() function. The formula will only recalculate when one of its input cells changes. For real-time data, if you want the price to update periodically, you can add a “dummy” cell that changes frequently. The standard method is to have a cell that contains the =NOW() formula and reference that cell within your YAHOOFINANCE() formula, although this is not officially supported.