## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  eval     = FALSE
)

## ----user-agent---------------------------------------------------------------
# library(edgarfundamentals)
# 
# options(edgarfundamentals.user_agent = "Jane Smith jane@example.com")

## ----get-cik------------------------------------------------------------------
# get_cik("LLY")   # Eli Lilly
# get_cik("LMT")   # Lockheed Martin

## ----single-------------------------------------------------------------------
# get_fundamentals("LLY", to_date = "2024-12-31")

## ----batch--------------------------------------------------------------------
# healthcare <- c("UNH", "PFE", "MRK", "ABT", "LLY", "CVS", "AMGN")
# defense    <- c("LMT", "RTX", "NOC", "GD",  "HII", "LHX", "LDOS")
# 
# healthcare.fund <- get_fundamentals_batch(healthcare, to_date = "2024-12-31")
# defense.fund    <- get_fundamentals_batch(defense,    to_date = "2024-12-31")
# 
# healthcare.fund
# defense.fund

## ----screening----------------------------------------------------------------
# library(dplyr)
# 
# # Growth screen: high EPS stocks relative to peers signal strong earnings
# healthcare.fund |> arrange(desc(EPS))
# 
# # Value screen: low PE and low PB suggest the market is pricing the stock cheaply
# # High dividend yield is also characteristic of value stocks
# defense.fund |> filter(PE < 20 & PB < 3) |> select(symbol, PE, PB, DIV, ROE)
# 
# # GARP screen (Growth at a Reasonable Price): PE below EPS
# # Stocks where the market is not overcharging for growth
# healthcare.fund |> filter(EPS > 0 & PE < EPS) |> select(symbol, PE, EPS)
# 
# # Profitability screen: strong margins signal pricing power and operational efficiency
# bind_rows(healthcare.fund, defense.fund) |>
#   filter(GrossMargin > 40 & OperatingMargin > 15) |>
#   arrange(desc(NetMargin)) |>
#   select(symbol, GrossMargin, OperatingMargin, NetMargin, ROA)
# 
# # Liquidity screen: current ratio above 1.5 and low leverage
# bind_rows(healthcare.fund, defense.fund) |>
#   filter(CurrentRatio > 1.5 & DE < 1) |>
#   arrange(desc(CurrentRatio)) |>
#   select(symbol, CurrentRatio, DE, ROE)

## ----filing-history-----------------------------------------------------------
# # Five most recent annual reports for Lockheed Martin
# get_filing_history("LMT", form_type = "10-K", n = 5)
# 
# # Four most recent quarterly reports for Eli Lilly
# get_filing_history("LLY", form_type = "10-Q", n = 4)

