Skip to contents

Given a vector of portfolio IDs from the tidy-finance/factor-library-grid Hugging Face dataset, downloads the corresponding return data from the tidy-finance/factor-library dataset on Hugging Face. The returns are stored in files of 1,000 consecutive IDs named after the range they cover (e.g., id_0000001-0001000.parquet), so the function downloads only the files that hold the requested IDs. The grid metadata is joined onto the result.

Usage

download_factor_library_ids(ids, revision = "main", grid_revision = "main")

Arguments

ids

Integer or numeric vector of portfolio IDs to download. IDs correspond to rows of the tidy-finance/factor-library-grid dataset.

revision

Character(1). The revision of tidy-finance/factor-library to read the returns from: a commit hash, a branch, or a tag. Defaults to "main", the latest release.

grid_revision

Character(1). The revision of tidy-finance/factor-library-grid to read: a commit hash, a branch, or a tag. Defaults to "main", the latest release. Pin it to the release of the returns, see the section Revisions of download_data_huggingface().

Value

A tibble with the columns id, date, and ret (the monthly long-short excess return) and the grid metadata columns for the requested IDs.

Details

Use this function when you already know the portfolio IDs you want (for example, from a previous call to download_data_huggingface() with dataset = "factor_library"). To resolve IDs from filter criteria (sorting variable, weighting scheme, breakpoints, etc.) and download in a single call, use download_data_huggingface() instead.

Raises an error if none of the requested IDs exist in the grid. IDs whose portfolio sort produced no portfolios have no returns; they are absent from the result, with a warning, and the result has no rows if none of the requested IDs has returns. Returns are stored in single precision, and months without a valid long-short return are stored as 0.

Examples

if (FALSE) { # \dontrun{
  download_factor_library_ids(c(1L, 2L, 3L))
  download_factor_library_ids(
    c(1L, 2L, 3L),
    revision = "e47bd85accd9b9b168ac7f478f12fe89ba5c2430",
    grid_revision = "a5a74cdf1df0c2c3d1ce3d7bf6403a8386fbf99d"
  )
} # }