screen

Overview

'yfscreen' provides simple and efficient access to Yahoo Finance's screener API https://finance.yahoo.com/research-hub/screener/ for querying and retrieving financial data.

The 'yfscreen' package abstracts the complexities of interacting with Yahoo Finance APIs, such as session management, crumb and cookie handling, query construction, pagination, and JSON payload generation. This abstraction allows users to focus on filtering and retrieving data rather than managing API details. Use cases include screening across a range of security types:

The package supports advanced query capabilities, including logical operators, nested filters, and customizable payloads. It automatically handles pagination for efficient retrieval of large datasets by fetching results in batches of up to 250 entries per request. Filters are defined as lists of conditions to accommodate a wide range of screens.

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

Installation

install.packages("yfscreen")
# install.packages("pak")
pak::pak("jasonjfoster/screen/r")

Usage

First, load the package and explore the available filter options:

library(yfscreen)

print(data_filters)

To create a query, define filters and use the create_query() function:

filters <- list(
  list("eq", list("region", "us")),
  list("btwn", list("intradaymarketcap", 2000000000, 10000000000)),
  list("btwn", list("intradaymarketcap", 10000000000, 100000000000)),
  list("gt", list("intradaymarketcap", 100000000000)),
  list("gt", list("dayvolume", 5000000))
)

query <- create_query(filters)

Next, specify the security type and create the payload with the create_payload() function:

payload <- create_payload("equity", query)

Finally, retrieve the data using the get_data() function:

data <- get_data(payload)