Learn R Programming

edgarfundamentals (version 0.1.2)

get_fundamentals_batch: Retrieve fundamental financial ratios for a portfolio of stocks

Description

A vectorized wrapper around get_fundamentals that accepts a vector of ticker symbols and returns a tidy data frame with one row per stock. Failed lookups are recorded as NA rather than stopping execution, so a single problematic ticker does not interrupt the batch.

Usage

get_fundamentals_batch(symbols, to_date = as.character(Sys.Date()))

Value

A data frame with one row per symbol and the following columns:

symbol, CIK, EPS, NetIncome, Revenue,

ROE, ROA, DE, CurrentRatio,

GrossMargin, OperatingMargin, NetMargin,

PE, PB, DIV. See get_fundamentals

for definitions. Rows where data retrieval failed contain NA

for all ratio columns.

Arguments

symbols

A character vector of stock ticker symbols (e.g. c("LLY", "PFE", "UNH")). Case-insensitive.

to_date

A character string in "YYYY-MM-DD" format. Passed to get_fundamentals for each symbol. Defaults to today's date.

Details

Each symbol requires two SEC EDGAR API calls (one for the CIK lookup and one for the companyfacts data) plus one Yahoo Finance call for the current price. A 0.5-second pause is inserted after each companyfacts call to respect the SEC rate limit of 10 requests per second. For a portfolio of 14 stocks, expect a total retrieval time of approximately 20--30 seconds.

Set your User-Agent once per session: options(edgarfundamentals.user_agent = "Your Name your@email.com")

See Also

get_fundamentals for single-stock retrieval.

Examples

Run this code
if (FALSE) {
options(edgarfundamentals.user_agent = "Jane Smith jane@example.com")

healthcare <- c("UNH", "PFE", "MRK", "ABT", "LLY", "CVS", "AMGN")
get_fundamentals_batch(healthcare, "2024-12-31")

defense <- c("LMT", "RTX", "NOC", "GD", "HII", "LHX", "LDOS")
get_fundamentals_batch(defense, "2024-12-31")
}

Run the code above in your browser using DataLab