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
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., |
[attribute] | Optional. The specific data point you want to fetch. This can be a real-time metric or a historical data type. Defaults to |
[start_date] | Optional. A valid date. The presence of a |
[end_date|num_days] | Optional. Can be either a valid end date for a historical period (e.g., |
[interval] | Optional. The interval for historical data. Valid options are |
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.