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-06-05 02:51:29 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 functionality 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: additional 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 ensure accessibility 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.

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 that contains an index column and the requested column created using the get_data function.

col

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

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 symbols using a date range and interval.

Usage

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

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.

interval

string. Data interval (see "data_intervals").

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 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()