Learn R Programming

edgarfundamentals (version 0.1.2)

get_fundamentals: Retrieve key fundamental financial ratios for a single stock

Description

Pulls fundamental financial data directly from a company's most recent annual 10-K filing in SEC EDGAR and computes key financial ratios. No API key or paid subscription is required.

Usage

get_fundamentals(symbol, to_date = as.character(Sys.Date()))

Value

A named numeric vector with the following elements:

CIK

SEC Central Index Key -- the company's unique EDGAR identifier.

EPS

Diluted Earnings Per Share (USD per share) from the most recent qualifying 10-K. Falls back to basic EPS if diluted is unavailable.

NetIncome

Net income attributable to the company (USD).

Revenue

Total revenue (USD).

ROE

Return on Equity as a percentage (NetIncome / StockholdersEquity * 100). A measure of how efficiently the company generates profit from shareholder capital.

ROA

Return on Assets as a percentage (NetIncome / TotalAssets * 100). A measure of how efficiently the company uses its assets.

DE

Debt-to-Equity ratio (LongTermDebt / StockholdersEquity). A measure of financial leverage.

CurrentRatio

Current Assets divided by Current Liabilities. A measure of short-term liquidity; values above 1 indicate the company can cover near-term obligations.

GrossMargin

Gross Profit as a percentage of Revenue. Measures pricing power and production efficiency.

OperatingMargin

Operating Income as a percentage of Revenue. Measures operational efficiency before interest and taxes.

NetMargin

Net Income as a percentage of Revenue. Bottom-line profitability after all expenses.

PE

Price-to-Earnings ratio, computed by dividing the most recent adjusted closing price (from Yahoo Finance via tidyquant) by EPS. Returns NA if EPS is zero or negative.

PB

Price-to-Book ratio, computed by dividing the most recent adjusted closing price by Book Value per Share (StockholdersEquity / SharesOutstanding). Returns NA if shares outstanding is zero or unavailable.

DIV

Dividend Yield as a percentage (DividendsPerShareDeclared / Price * 100). Returns NA if no dividend data is available.

Arguments

symbol

A character string containing the stock ticker symbol (e.g. "LLY"). Case-insensitive.

to_date

A character string in "YYYY-MM-DD" format. The function returns ratios from the most recent 10-K with a period end date on or before this date. Defaults to today's date.

Details

Financial statement values are extracted from XBRL-tagged 10-K filings via the SEC EDGAR companyfacts API (https://data.sec.gov/api/xbrl/companyfacts/). Because data comes from annual filings, ratios reflect the most recently completed fiscal year ending on or before to_date, not real-time values.

Fallback XBRL tags are attempted automatically when a company uses a non-standard tag name for a concept. A courtesy pause of 0.5 seconds is inserted after the companyfacts API call to respect the SEC's rate limit of 10 requests per second.

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

Examples

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

# Fundamentals for Eli Lilly as of end of 2024
get_fundamentals("LLY", "2024-12-31")

# Fundamentals as of today
get_fundamentals("JNJ")
}

Run the code above in your browser using DataLab