Package 'yfhist'

Title: Yahoo Finance 'history' API
Description: Simple and efficient access to Yahoo Finance's 'history' API <https://finance.yahoo.com/> for querying and retrieving financial data. The 'yfhist' package abstracts the complexities of interacting with Yahoo Finance APIs, such as session management, crumb and cookie handling, query construction, date validation, and interval management. This abstraction allows users to focus on retrieving data rather than managing API details. Use cases include retrieving historical data across a range of security types such as equities and ETFs, indices, and other tickers. The package supports flexible query capabilities, including customizable date ranges, multiple time intervals, and automatic data validation. It manages interval-specific limitations automatically, such as lookback periods for intraday data and maximum date ranges for minute-level intervals. The implementation uses standard HTTP libraries to handle API interactions efficiently and is available in both R and 'Python' for accessibility to a broad audience.
Authors: Jason Foster [aut, cre]
Maintainer: Jason Foster <[email protected]>
License: GPL (>= 2)
Version: 0.1.4
Built: 2026-11-10 00:12:35 UTC
Source: https://github.com/jasonjfoster/hist

Help Index


Yahoo Finance 'history' API

Description

Simple and efficient access to Yahoo Finance's 'history' API <https://finance.yahoo.com/> for querying and retrieving financial data. The 'yfhist' package abstracts the complexities of interacting with Yahoo Finance APIs, such as session management, crumb and cookie handling, query construction, date validation, and interval management. This abstraction allows users to focus on retrieving data rather than managing API details. Use cases include retrieving historical data across a range of security types such as equities and ETFs, indices, and other tickers. The package supports flexible query capabilities, including customizable date ranges, multiple time intervals, and automatic data validation. It manages interval-specific limitations automatically, such as lookback periods for intraday data and maximum date ranges for minute-level intervals. The implementation uses standard HTTP libraries to handle API interactions efficiently and is available in both R and 'Python' for accessibility to a broad audience.

Details

yfhist is a package that provides simple and efficient access to Yahoo Finance's history API for querying and retrieving financial data.

The core functionality of the yfhist package abstracts the complexities of interacting with Yahoo Finance APIs, such as session management, crumb and cookie handling, query construction, date validation, and interval management. This abstraction allows users to focus on retrieving data rather than managing API details. Use cases include retrieving historical data across a range of security types:

  • Equities and ETFs: end-of-day or intraday Open, High, Low, Close, Volume (OHLCV), and adjusted close prices

  • Indices: levels over time for benchmarking and research

  • Other tickers: symbols supported by Yahoo Finance where chart data is available

The implementation leverages standard HTTP libraries to handle API interactions efficiently and provides support for both R and Python to make it accessible for a broad audience.

Author(s)

Jason Foster [aut, cre]


Intervals Data for the Yahoo Finance API

Description

A data frame with the available intervals data for the Yahoo Finance API. Each row gives the name and field of an interval, whether it is intraday, and the lookback in days that the get_data function enforces for intraday intervals.

Usage

data_intervals

Format

A data frame.


Get a Column from the Yahoo Finance API

Description

A function to get a column from data retrieved from the Yahoo Finance API.

Usage

get_col(data, col)

Arguments

data

data frame or list. Data created using the get_data function that contains an index column and the requested column.

col

string. Column name to get (i.e., "open", "high", "low", "close", "adjclose", "volume").

Details

"adjclose" falls back to "close" with a warning when the data is intraday. For a single data frame the result has an index column and a column named by the symbol; for a list the series are merged on index with an outer join, so a date missing for one symbol is missing in that column.

Value

A data frame with rows as the index and columns as the symbols.

Examples

## Not run: 
data <- get_data(c("AAPL", "MSFT"))

adj <- get_col(data, "adjclose")

## End(Not run)

Get Data from the Yahoo Finance API

Description

A function to get data from the Yahoo Finance API for one or more symbols with optional date range and interval.

Usage

get_data(symbols, from_date = "2007-01-01", to_date = NULL,
  interval = "1d", session = NULL)

Arguments

symbols

string. Symbol or vector of symbols.

from_date

string. Start date in "YYYY-MM-DD" format (e.g., "2007-01-01").

to_date

string. End date in "YYYY-MM-DD" format, inclusive for daily and longer intervals and the exact timestamp for intraday intervals.

interval

string. Data interval (see "data_intervals").

session

list. Session created using the get_session function. When a session is not provided, a session is created internally.

Details

Intraday intervals are limited by the lookback in data_intervals: from_date must be within the lookback of today (30 days for "1m", 730 for "60m" and "1h", and 60 for the other intraday intervals), and for "1m" the range may span at most 8 days. The index is a date, or a date-time for intraday intervals, in the exchange's time zone, and the adjclose column is present for daily and longer intervals only.

One request is made per symbol, and a session (crumb, cookies, and handle) can be reused across calls with one second paused after every five requests. Symbols with no data are dropped, a single symbol returns a data frame with the symbol as an attribute, and no data at all returns an empty data frame.

Value

A data frame or list of data frame(s) that contains data from the Yahoo Finance API for the specified symbol(s).

Examples

## Not run: 
data <- get_data(c("AAPL", "MSFT"))

## End(Not run)

Get the Crumb, Cookies, and Handle for the Yahoo Finance API

Description

A function to get the crumb, cookies, and handle required to authenticate and interact with the Yahoo Finance API.

Usage

get_session()

Value

A list containing the following elements:

handle

A curl handle object for subsequent requests.

crumb

A string representing the crumb value for authentication.

cookies

A data frame of cookies for the request.

Examples

session <- get_session()