| Title: | Fetch Data from Yahoo Finance API |
|---|---|
| Description: | Obtain historical and near real time data related to stocks, index and currencies from the Yahoo Finance API. This package is community maintained and is not officially supported by 'Yahoo'. The accuracy of data is only as correct as provided on <https://finance.yahoo.com/>. |
| Authors: | Aravind Hebbali [aut, cre] |
| Maintainer: | Aravind Hebbali <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.6.1 |
| Built: | 2026-09-16 12:17:53 UTC |
| Source: | https://github.com/rsquaredacademy/yahoofinancer |
Retrieve current and historical exchange rates between two currencies via the Yahoo Finance chart API.
currency_converter( from = "EUR", to = "USD", start = NULL, end = NULL, period = "ytd", interval = "1d" )currency_converter( from = "EUR", to = "USD", start = NULL, end = NULL, period = "ytd", interval = "1d" )
from |
ISO 4217 three-letter currency code to convert from
(e.g., |
to |
ISO 4217 three-letter currency code to convert to
(e.g., |
start |
Specific starting date. |
end |
Specific ending date. |
period |
Length of time. Defaults to
|
interval |
Time between data points. Defaults to
|
A tidy tibble with columns: date (POSIXct),
high, low, open, close, volume
(all numeric), and conditionally adj_close (numeric, present
for daily and longer intervals). Rows with NA volume are
excluded. Returns an empty tibble on network failure.
Other currency:
get_currencies()
## Not run: currency_converter("GBP", "USD", "2022-07-01", "2022-07-10") currency_converter("GBP", "USD", period = "1mo", interval = "1d") ## End(Not run)## Not run: currency_converter("GBP", "USD", "2022-07-01", "2022-07-10") currency_converter("GBP", "USD", period = "1mo", interval = "1d") ## End(Not run)
Retrieves the list of currencies supported by Yahoo Finance.
get_currencies()get_currencies()
A data.frame with 4 columns:
short_name (character), long_name (character),
symbol (character), local_long_name (character).
Returns invisible(NULL) on network failure.
Other currency:
currency_converter()
## Not run: get_currencies() ## End(Not run)## Not run: get_currencies() ## End(Not run)
Retrieve live market overview snapshots across global benchmark indices, commodities, currencies, and futures.
get_market_summary(as_tibble = TRUE)get_market_summary(as_tibble = TRUE)
as_tibble |
Logical; if |
If as_tibble = TRUE, a tibble with 9 columns:
symbol, short_name, regular_market_price,
regular_market_change, regular_market_change_percent,
regular_market_previous_close, market_state,
exchange, market_time (POSIXct, UTC).
If as_tibble = FALSE, a nested list.
Returns an empty tibble (or invisible(NULL)) on failure.
Other market data:
get_trending(),
yf_get_market_stats()
## Not run: # Tidy tibble output (default) market_df <- get_market_summary() # Raw list output market_list <- get_market_summary(as_tibble = FALSE) ## End(Not run)## Not run: # Tidy tibble output (default) market_df <- get_market_summary() # Raw list output market_list <- get_market_summary(as_tibble = FALSE) ## End(Not run)
Retrieves the list of currently trending securities for a specific region from Yahoo Finance.
get_trending(country = "US", count = 10)get_trending(country = "US", count = 10)
country |
ISO 3166-1 alpha-2 region code (e.g., |
count |
Maximum number of trending securities to return.
Defaults to |
A character vector of trending ticker symbols.
Returns invisible(NULL) on network failure or if no data
is available (with a message).
Other market data:
get_market_summary(),
yf_get_market_stats()
## Not run: get_trending() get_trending(country = "GB", count = 5) ## End(Not run)## Not run: get_trending() get_trending(country = "GB", count = 5) ## End(Not run)
Class for retrieving data related to market indices from the Yahoo Finance API.
Inherits get_history() from YahooFinanceBase-class.
An R6 class object
yahoofinancer::YahooFinanceBase -> Index
indexDeprecated. Returns self$symbol.
new()
Create a new Index object.
Index$new(symbol = NA, index = NA, validate = TRUE)
symbolSymbol (e.g., "^NSEI").
indexDeprecated. Use symbol instead.
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
A new Index object.
\dontrun{
nifty_50 <- Index$new('^NSEI')
}
set_index()
Set a new index symbol.
Index$set_index(symbol = NA, index = NA, validate = TRUE)
symbolNew symbol.
indexDeprecated. Use symbol instead.
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
\dontrun{
indice <- Index$new('^NSEI')
indice$set_index('^NDX')
}
clone()
The objects of this class are cloneable with this method.
Index$clone(deep = FALSE)
deepWhether to make a deep clone.
Other historical data:
Ticker-class,
Tickers,
yf_download_prices(),
yf_get_index_quotes()
## ------------------------------------------------ ## Method `Index$new` ## ------------------------------------------------ ## Not run: nifty_50 <- Index$new('^NSEI') ## End(Not run) ## ------------------------------------------------ ## Method `Index$set_index` ## ------------------------------------------------ ## Not run: indice <- Index$new('^NSEI') indice$set_index('^NDX') ## End(Not run)## ------------------------------------------------ ## Method `Index$new` ## ------------------------------------------------ ## Not run: nifty_50 <- Index$new('^NSEI') ## End(Not run) ## ------------------------------------------------ ## Method `Index$set_index` ## ------------------------------------------------ ## Not run: indice <- Index$new('^NSEI') indice$set_index('^NDX') ## End(Not run)
Class for retrieving all data related to a single ticker from the
Yahoo Finance API. Inherits get_history() from
YahooFinanceBase-class.
An R6 class object
yahoofinancer::YahooFinanceBase -> Ticker
valuation_measuresRetrieves valuation measures
recommendationsRelated symbols recommended by Yahoo Finance and their scores.
technical_insightsTechnical insights and indicators snapshot.
currencyCurrency code for the symbol.
exchange_nameShort name of the stock exchange.
full_exchange_nameFull name of the stock exchange.
first_trade_dateTimestamp of the first recorded trade.
regular_market_timeTimestamp of the last market trade.
timezoneTimezone code of the exchange.
exchange_timezone_nameFull timezone name of the exchange.
regular_market_priceCurrent regular market price.
fifty_two_week_high52-week high price.
fifty_two_week_low52-week low price.
regular_market_day_highHighest price during the current trading session.
regular_market_day_lowLowest price during the current trading session.
regular_market_volumeCurrent trading volume.
previous_closeClosing price of the previous trading day.
new()
Create a new Ticker object.
Ticker$new(symbol = NA, validate = TRUE)
symbolSymbol (e.g., "AAPL").
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
set_symbol()
Set a new symbol and clear cached metadata.
Ticker$set_symbol(symbol, validate = TRUE)
symbolNew symbol (e.g., "AAPL").
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
get_income_statement()
Retrieve income statement data.
Ticker$get_income_statement(frequency = c("annual", "quarterly"))frequencyOne of "annual" or "quarterly". Defaults to "annual".
A tibble with columns date, period_type,
and income statement line items, or invisible(NULL) on failure.
get_balance_sheet()
Retrieve balance sheet data.
Ticker$get_balance_sheet(frequency = c("annual", "quarterly"))frequencyOne of "annual" or "quarterly". Defaults to "annual".
A tibble with columns date, period_type,
and balance sheet line items, or invisible(NULL) on failure.
get_cash_flow()
Retrieve cash flow statement data.
Ticker$get_cash_flow(frequency = c("annual", "quarterly"))frequencyOne of "annual" or "quarterly". Defaults to "annual".
A tibble with columns date, period_type,
and cash flow statement line items, or invisible(NULL) on failure.
clone()
The objects of this class are cloneable with this method.
Ticker$clone(deep = FALSE)
deepWhether to make a deep clone.
Other historical data:
Indice-class,
Tickers,
yf_download_prices(),
yf_get_index_quotes()
Validate symbols before retrieving data. This function checks whether the provided ticker strings are valid according to the Yahoo Finance API.
validate(symbol = NULL, index = NA, return_logical = FALSE)validate(symbol = NULL, index = NA, return_logical = FALSE)
symbol |
A character vector of one or more ticker strings, index or fund names (e.g., |
index |
Deprecated. Use |
return_logical |
A logical value indicating whether to return a named logical vector.
If |
Symbol validation
If return_logical = FALSE (the default), a character vector of valid symbols.
If return_logical = TRUE, a named logical vector indicating validation status for each symbol.
## Not run: validate("AAPL") validate(c("AAPL", "NOTASTOCK", "MSFT")) validate(c("AAPL", "NOTASTOCK", "MSFT"), return_logical = TRUE) ## End(Not run)## Not run: validate("AAPL") validate(c("AAPL", "NOTASTOCK", "MSFT")) validate(c("AAPL", "NOTASTOCK", "MSFT"), return_logical = TRUE) ## End(Not run)
Fetches historical OHLCV price data for one or more tickers using the
Yahoo Finance chart API. Results are combined into a single long-format
tibble suitable for dplyr pipelines.
**Intraday lookback limits** (imposed by Yahoo Finance):
"1m": max 7 days
"5m", "15m", "30m": max 60 days
"1h": max 730 days
yf_download_prices( tickers, start = NULL, end = NULL, interval = "1d", period = NULL )yf_download_prices( tickers, start = NULL, end = NULL, interval = "1d", period = NULL )
tickers |
Character vector of one or more stock symbols
(e.g., |
start |
Date or character string in |
end |
Date or character string in |
interval |
Time between data points. Valid values:
|
period |
Relative time period. Valid values:
|
A tibble with 8 columns:
symbol, date, open, high, low,
close, adj_close, volume.
Returns an empty tibble if all tickers fail.
Other historical data:
Indice-class,
Ticker-class,
Tickers,
yf_get_index_quotes()
## Not run: # Single ticker with date range yf_download_prices("AAPL", start = "2023-01-01", end = "2023-01-10") # Multiple tickers with relative period yf_download_prices(c("AAPL", "MSFT"), period = "6mo", interval = "1mo") ## End(Not run)## Not run: # Single ticker with date range yf_download_prices("AAPL", start = "2023-01-01", end = "2023-01-10") # Multiple tickers with relative period yf_download_prices(c("AAPL", "MSFT"), period = "6mo", interval = "1mo") ## End(Not run)
Retrieves quarterly or annual financial statements (income statement, balance sheet, or cash flow) for one or more tickers.
yf_get_financials( tickers, statement_type = c("income", "balance-sheet", "cash-flow"), frequency = c("annual", "quarterly") )yf_get_financials( tickers, statement_type = c("income", "balance-sheet", "cash-flow"), frequency = c("annual", "quarterly") )
tickers |
Character vector of stock symbols. |
statement_type |
The type of financial statement to retrieve.
One of |
frequency |
One of |
A tibble with symbol as the first
column. Remaining columns vary by statement_type and reflect the
line items returned by the Yahoo Finance API.
Returns an empty tibble if all tickers fail.
## Not run: yf_get_financials("AAPL", statement_type = "income") yf_get_financials(c("AAPL", "MSFT"), statement_type = "balance-sheet", frequency = "quarterly") ## End(Not run)## Not run: yf_get_financials("AAPL", statement_type = "income") yf_get_financials(c("AAPL", "MSFT"), statement_type = "balance-sheet", frequency = "quarterly") ## End(Not run)
Retrieves the most recent 1-day price snapshot for a given market index.
yf_get_index_quotes(index_symbol)yf_get_index_quotes(index_symbol)
index_symbol |
Character string of the index symbol (e.g.,
|
A tibble with the same 8-column schema as
yf_download_prices: symbol, date,
open, high, low, close, adj_close,
volume.
Returns an empty tibble on failure.
Other historical data:
Indice-class,
Ticker-class,
Tickers,
yf_download_prices()
## Not run: yf_get_index_quotes("^GSPC") ## End(Not run)## Not run: yf_get_index_quotes("^GSPC") ## End(Not run)
Retrieves key real-time valuation and summary fields for one or more tickers.
yf_get_market_stats(tickers)yf_get_market_stats(tickers)
tickers |
Character vector of stock symbols. |
A tibble with 7 columns:
symbol (character), regular_market_price (numeric),
fifty_two_week_high (numeric), fifty_two_week_low (numeric),
regular_market_volume (numeric), previous_close (numeric),
currency (character).
Returns an empty tibble if all tickers fail.
Other market data:
get_market_summary(),
get_trending()
## Not run: yf_get_market_stats("AAPL") yf_get_market_stats(c("AAPL", "MSFT")) ## End(Not run)## Not run: yf_get_market_stats("AAPL") yf_get_market_stats(c("AAPL", "MSFT")) ## End(Not run)