| Type: | Package |
| Title: | Fetch Data from Yahoo Finance API |
| Version: | 0.6.1 |
| 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/. |
| Depends: | R (≥ 4.1) |
| Imports: | curl, dplyr, httr2 (≥ 1.0.0), jsonlite, lubridate, magrittr, purrr, R6, tibble |
| Suggests: | covr, ggplot2, httptest2, knitr, rmarkdown, scales, shiny, testthat (≥ 3.0.0), tidyr, zoo |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| URL: | https://yahoofinancer.rsquaredacademy.com/, https://github.com/rsquaredacademy/yahoofinancer |
| BugReports: | https://github.com/rsquaredacademy/yahoofinancer/issues |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-15 14:49:09 UTC; HP |
| Author: | Aravind Hebbali [aut, cre] |
| Maintainer: | Aravind Hebbali <hebbali.aravind@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-16 08:50:02 UTC |
yahoofinancer package
Description
Fetch Data from Yahoo Finance API
Details
See the README on GitHub
Author(s)
Maintainer: Aravind Hebbali hebbali.aravind@gmail.com
See Also
Useful links:
Report bugs at https://github.com/rsquaredacademy/yahoofinancer/issues
R6 Class Representing an Index
Description
Class for retrieving data related to market indices from the Yahoo Finance API.
Inherits get_history() from YahooFinanceBase-class.
Format
An R6 class object
Super class
yahoofinancer::YahooFinanceBase -> Index
Active bindings
indexDeprecated. Returns
self$symbol.
Methods
Public methods
Inherited methods
Method new()
Create a new Index object.
Usage
Index$new(symbol = NA, index = NA, validate = TRUE)
Arguments
symbolSymbol (e.g.,
"^NSEI").indexDeprecated. Use
symbolinstead.validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Returns
A new Index object.
Examples
\dontrun{
nifty_50 <- Index$new('^NSEI')
}
Method set_index()
Set a new index symbol.
Usage
Index$set_index(symbol = NA, index = NA, validate = TRUE)
Arguments
symbolNew symbol.
indexDeprecated. Use
symbolinstead.validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Examples
\dontrun{
indice <- Index$new('^NSEI')
indice$set_index('^NDX')
}
Method clone()
The objects of this class are cloneable with this method.
Usage
Index$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other historical data:
Ticker-class,
Tickers,
yf_download_prices(),
yf_get_index_quotes()
Examples
## ------------------------------------------------
## 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)
R6 Class Representing a Ticker
Description
Class for retrieving all data related to a single ticker from the
Yahoo Finance API. Inherits get_history() from
YahooFinanceBase-class.
Format
An R6 class object
Super class
yahoofinancer::YahooFinanceBase -> Ticker
Active bindings
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.
Methods
Public methods
Inherited methods
Method new()
Create a new Ticker object.
Usage
Ticker$new(symbol = NA, validate = TRUE)
Arguments
symbolSymbol (e.g.,
"AAPL").validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Method set_symbol()
Set a new symbol and clear cached metadata.
Usage
Ticker$set_symbol(symbol, validate = TRUE)
Arguments
symbolNew symbol (e.g.,
"AAPL").validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Method get_income_statement()
Retrieve income statement data.
Usage
Ticker$get_income_statement(frequency = c("annual", "quarterly"))Arguments
frequencyOne of
"annual"or"quarterly". Defaults to"annual".
Returns
A tibble with columns date, period_type,
and income statement line items, or invisible(NULL) on failure.
Method get_balance_sheet()
Retrieve balance sheet data.
Usage
Ticker$get_balance_sheet(frequency = c("annual", "quarterly"))Arguments
frequencyOne of
"annual"or"quarterly". Defaults to"annual".
Returns
A tibble with columns date, period_type,
and balance sheet line items, or invisible(NULL) on failure.
Method get_cash_flow()
Retrieve cash flow statement data.
Usage
Ticker$get_cash_flow(frequency = c("annual", "quarterly"))Arguments
frequencyOne of
"annual"or"quarterly". Defaults to"annual".
Returns
A tibble with columns date, period_type,
and cash flow statement line items, or invisible(NULL) on failure.
Method clone()
The objects of this class are cloneable with this method.
Usage
Ticker$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other historical data:
Indice-class,
Tickers,
yf_download_prices(),
yf_get_index_quotes()
Multi-Symbol Ticker Data Aggregator
Description
An R6 class to manage and aggregate data from multiple Yahoo Finance tickers
simultaneously. It wraps the Ticker class to provide a unified,
long-format data interface suitable for bulk analysis and visualization.
Details
The Tickers class automates the process of iterating over a vector of
symbols. It handles per-symbol errors gracefully via an internal
aggregate_data helper, ensuring that a failure in one symbol does
not prevent the collection of data for others.
Most properties return a data.frame where the first column is
symbol, facilitating easy filtering and joining in tidy workflows.
Public fields
symbolsA unique character vector of symbols being tracked.
ticker_objsA named list of underlying
TickerR6 objects.
Active bindings
recommendationsRelated symbols suggested by Yahoo Finance and their relevance scores.
valuation_measuresQuarterly valuation statistics including PE and Enterprise Value.
technical_insightsTechnical indicator snapshots (e.g., RSI, Moving Averages).
regular_market_priceThe current market price for each symbol.
regular_market_timeThe timestamp of the last market trade.
regular_market_volumeThe current trading volume.
regular_market_day_highThe highest price during the current trading session.
regular_market_day_lowThe lowest price during the current trading session.
previous_closeThe closing price of the previous trading day.
fifty_two_week_highThe highest price over the last 52 weeks.
fifty_two_week_lowThe lowest price over the last 52 weeks.
currencyThe currency code (e.g., "USD") for the symbols.
exchange_nameThe short name of the stock exchange.
full_exchange_nameThe full name of the stock exchange.
first_trade_dateThe Unix timestamp of the first recorded trade.
timezoneThe timezone code (e.g., "EDT").
exchange_timezone_nameThe full name of the exchange's timezone.
Methods
Public methods
Method new()
Create a new Tickers object.
Usage
Tickers$new(symbols, validate = TRUE)
Arguments
symbolsA character vector of Yahoo Finance ticker symbols.
validateLogical; if TRUE, validate symbols against Yahoo Finance. Defaults to TRUE.
Returns
A new Tickers object.
Method get_history()
Retrieve historical market data for all symbols.
Usage
Tickers$get_history(period = "1y", interval = "1d", start = NULL, end = NULL)
Arguments
periodLength of time. Defaults to
'1y'. Valid values:"1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max". Ignored whenstartis provided.intervalTime between data points. Defaults to
'1d'. Valid values:"1m","2m","5m","15m","30m","60m","90m","1h","1d","5d","1wk","1mo","3mo".startSpecific starting date.
StringorDateobject in"YYYY-MM-DD"format.endSpecific ending date.
StringorDateobject in"YYYY-MM-DD"format. Defaults to today whenstartis provided butendisNULL.
Returns
A tidy tibble containing historical prices and volumes.
Columns: symbol, date, open, high, low,
close, adj_close, volume. Returns an empty tibble if all tickers fail.
Method aggregate_data()
Internal helper to execute a method across all symbols and combine results. Not intended for direct end-user use.
Usage
Tickers$aggregate_data(fn)
Arguments
fnA function or anonymous function that takes a
Tickerobject.
Returns
A combined tibble, or an empty tibble if all tickers fail.
Method clone()
The objects of this class are cloneable with this method.
Usage
Tickers$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Other historical data:
Indice-class,
Ticker-class,
yf_download_prices(),
yf_get_index_quotes()
Examples
## Not run:
# Initialize for a set of tech stocks
stocks <- Tickers$new(c("AAPL", "MSFT", "GOOGL"))
# 1. Get 1 month of historical daily prices
hist_data <- stocks$get_history(period = "1mo", interval = "1d")
head(hist_data)
# 2. Get current market prices for the group
current_prices <- stocks$regular_market_price
# 3. View recommended related symbols and scores
recs <- stocks$recommendations
# 4. Get technical insights (RSI, Moving Averages)
tech <- stocks$technical_insights
## End(Not run)
R6 Class Representing a Yahoo Finance Base Object
Description
Base class for Ticker and Index classes.
Format
An R6 class object
Public fields
symbolSymbol for which data is retrieved.
Methods
Public methods
Method new()
Create a new YahooFinanceBase object.
Usage
YahooFinanceBase$new(symbol = NA, validate = TRUE)
Arguments
symbolSymbol.
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Method set_symbol()
Set a new symbol.
Usage
YahooFinanceBase$set_symbol(symbol, validate = TRUE)
Arguments
symbolNew symbol
validateLogical; if TRUE, validate symbol against Yahoo Finance. Defaults to TRUE.
Method get_history()
Retrieves historical pricing data from the Yahoo Finance chart API.
**Intraday lookback limits** (imposed by Yahoo Finance):
-
"1m": max 7 days -
"2m","5m","15m","30m","60m","90m": max 60 days -
"1h": max 730 days
Usage
YahooFinanceBase$get_history( period = "ytd", interval = "1d", start = NULL, end = NULL )
Arguments
periodLength of time. Defaults to
'ytd'. Valid values:"1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max". Ignored whenstartis provided.intervalTime between data points. Defaults to
'1d'. Valid values:"1m","2m","5m","15m","30m","60m","90m","1h","1d","5d","1wk","1mo","3mo".startSpecific starting date.
StringorDateobject in"YYYY-MM-DD"format.endSpecific ending date.
StringorDateobject in"YYYY-MM-DD"format. Defaults to today whenstartis provided butendisNULL.
Returns
A tibble with 8 columns:
symbolCharacter. Ticker symbol.
datePOSIXct. Timestamp of the data point (UTC).
openNumeric. Opening price.
highNumeric. Period high.
lowNumeric. Period low.
closeNumeric. Closing price.
adj_closeNumeric. Split- and dividend-adjusted close. Falls back to
closewhen the API omits adjusted data.volumeNumeric. Trading volume.
Returns invisible(NULL) on network failure or invalid symbol.
Method clone()
The objects of this class are cloneable with this method.
Usage
YahooFinanceBase$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Currency Converter
Description
Retrieve current and historical exchange rates between two currencies via the Yahoo Finance chart API.
Usage
currency_converter(
from = "EUR",
to = "USD",
start = NULL,
end = NULL,
period = "ytd",
interval = "1d"
)
Arguments
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
|
Value
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.
See Also
Other currency:
get_currencies()
Examples
## Not run:
currency_converter("GBP", "USD", "2022-07-01", "2022-07-10")
currency_converter("GBP", "USD", period = "1mo", interval = "1d")
## End(Not run)
Get Supported Currencies
Description
Retrieves the list of currencies supported by Yahoo Finance.
Usage
get_currencies()
Value
A data.frame with 4 columns:
short_name (character), long_name (character),
symbol (character), local_long_name (character).
Returns invisible(NULL) on network failure.
See Also
Other currency:
currency_converter()
Examples
## Not run:
get_currencies()
## End(Not run)
Get Real-Time Market Summary
Description
Retrieve live market overview snapshots across global benchmark indices, commodities, currencies, and futures.
Usage
get_market_summary(as_tibble = TRUE)
Arguments
as_tibble |
Logical; if |
Value
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.
See Also
Other market data:
get_trending(),
yf_get_market_stats()
Examples
## 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)
Get Trending Securities
Description
Retrieves the list of currently trending securities for a specific region from Yahoo Finance.
Usage
get_trending(country = "US", count = 10)
Arguments
country |
ISO 3166-1 alpha-2 region code (e.g., |
count |
Maximum number of trending securities to return.
Defaults to |
Value
A character vector of trending ticker symbols.
Returns invisible(NULL) on network failure or if no data
is available (with a message).
See Also
Other market data:
get_market_summary(),
yf_get_market_stats()
Examples
## Not run:
get_trending()
get_trending(country = "GB", count = 5)
## End(Not run)
Symbol validation
Description
Validate symbols before retrieving data. This function checks whether the provided ticker strings are valid according to the Yahoo Finance API.
Usage
validate(symbol = NULL, index = NA, return_logical = FALSE)
Arguments
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 |
Details
Symbol validation
Value
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.
Examples
## Not run:
validate("AAPL")
validate(c("AAPL", "NOTASTOCK", "MSFT"))
validate(c("AAPL", "NOTASTOCK", "MSFT"), return_logical = TRUE)
## End(Not run)
Download Historical Prices
Description
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
Usage
yf_download_prices(
tickers,
start = NULL,
end = NULL,
interval = "1d",
period = NULL
)
Arguments
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:
|
Value
A tibble with 8 columns:
symbol, date, open, high, low,
close, adj_close, volume.
Returns an empty tibble if all tickers fail.
See Also
Other historical data:
Indice-class,
Ticker-class,
Tickers,
yf_get_index_quotes()
Examples
## 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)
Get Financial Statements
Description
Retrieves quarterly or annual financial statements (income statement, balance sheet, or cash flow) for one or more tickers.
Usage
yf_get_financials(
tickers,
statement_type = c("income", "balance-sheet", "cash-flow"),
frequency = c("annual", "quarterly")
)
Arguments
tickers |
Character vector of stock symbols. |
statement_type |
The type of financial statement to retrieve.
One of |
frequency |
One of |
Value
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.
Examples
## Not run:
yf_get_financials("AAPL", statement_type = "income")
yf_get_financials(c("AAPL", "MSFT"), statement_type = "balance-sheet", frequency = "quarterly")
## End(Not run)
Get Index Quotes
Description
Retrieves the most recent 1-day price snapshot for a given market index.
Usage
yf_get_index_quotes(index_symbol)
Arguments
index_symbol |
Character string of the index symbol (e.g.,
|
Value
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.
See Also
Other historical data:
Indice-class,
Ticker-class,
Tickers,
yf_download_prices()
Examples
## Not run:
yf_get_index_quotes("^GSPC")
## End(Not run)
Get Market Statistics
Description
Retrieves key real-time valuation and summary fields for one or more tickers.
Usage
yf_get_market_stats(tickers)
Arguments
tickers |
Character vector of stock symbols. |
Value
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.
See Also
Other market data:
get_market_summary(),
get_trending()
Examples
## Not run:
yf_get_market_stats("AAPL")
yf_get_market_stats(c("AAPL", "MSFT"))
## End(Not run)