Skip to contents

Downloads data from a supported Hugging Face dataset. For "high_frequency_sp500", parquet files are filtered by date range and row-bound. For "factor_library", portfolio characteristics are selected via filter_factor_library_grid(), the matching return data is downloaded, and the result is filtered to start_date/end_date when both are supplied. For "factor_library_grid", the grid itself is returned via download_factor_library_grid().

Usage

download_data_huggingface(
  dataset = NULL,
  start_date = NULL,
  end_date = NULL,
  type = deprecated(),
  ...
)

Arguments

dataset

Character(1). The dataset to download. Supported values are "high_frequency_sp500", "factor_library", and "factor_library_grid".

start_date

Date or character. Start date (inclusive) in "YYYY-MM-DD" format. Used for "high_frequency_sp500" and "factor_library". When omitted for "factor_library", the full return history is returned; "high_frequency_sp500" falls back to a built-in sample window.

end_date

Date or character. End date (inclusive) in "YYYY-MM-DD" format. See start_date.

type

[Deprecated] Use dataset instead.

...

For dataset = "factor_library": either named arguments used to filter the portfolio grid, or ids = <vector> to bypass the grid filter and download specific portfolios directly via download_factor_library_ids(). Filter arguments take the form column = value, where value may be a vector to match multiple levels. Optionally pass fill_all = TRUE to leave unspecified columns unrestricted (default: FALSE, i.e. unspecified columns are fixed at the defaults listed below). Passing NULL for any parameter removes that filter entirely, returning all values for that column (e.g., min_size_quantile = NULL includes all size groups). Passing an unrecognised column name raises an error listing the supported names. ids cannot be combined with filter arguments. Ignored when dataset != "factor_library". See the Details section for supported columns and their defaults.

Value

A tibble with the downloaded data. For "high_frequency_sp500", contains 5-second aggregated orderbook snapshots filtered to the requested date range. For "factor_library", contains the columns id, date, and ret joined with the full grid metadata for the matched portfolio IDs.

Details

Note on dataset = "factor_library" defaults: The defaults below reflect one common portfolio construction choice, but may not suit every research question. Always verify that the selected combination matches your intended design.

Supported columns and their defaults for ...:

  • sorting_variable: Required. The firm characteristic used to sort stocks into portfolios, named like the Open Source Asset Pricing signals (e.g., "size" for market equity, "bm" for book-to-market). See download_factor_library_grid() for all values. No default is applied.

  • min_size_quantile (defaults to 0.2): Fraction of the smallest stocks (by market cap) excluded from the portfolio universe. 0.2 drops the bottom 20%.

  • exclude_financials (defaults to FALSE): Whether to drop financial-sector stocks (SIC 6000-6799) from the universe.

  • exclude_utilities (default: FALSE): Whether to drop utility-sector stocks (SIC 4900-4999) from the universe.

  • exclude_negative_earnings (defaults to FALSE): Whether to drop firms with negative earnings before sorting.

  • sorting_variable_lag (defaults to "6m"): Lag applied to the sorting variable before portfolio assignment: "1m" (the timing of Open Source Asset Pricing), "3m", "6m", or "ff" (Fama-French).

  • rebalancing (defaults to "monthly"): How frequently portfolios are reformed: "monthly" or "annual".

  • n_portfolios_main (defaults to 10): Number of quantile groups (e.g., 10 for decile portfolios).

  • sorting_method (defaults to "univariate"): Whether portfolios are formed on a single sort ("univariate") or on a double sort with size as the second variable ("bivariate-dependent" or "bivariate-independent").

  • n_portfolios_secondary (defaults to NULL): Number of size groups for the secondary sort. Required when sorting_method is not "univariate".

  • breakpoints_exchanges (defaults to: "NYSE"): Exchange(s) used to compute breakpoints. "NYSE" uses only NYSE-listed stocks to define quantile cutoffs (the conventional Fama-French approach).

  • breakpoints_min_size_threshold (defaults to NA): Minimum size quantile of the stocks that set the main breakpoints (e.g., 0.2). NA means no minimum-size screen is applied.

  • weighting_scheme (defaults to "VW"): Return weighting within portfolios: "VW" for value-weighted, "EW" for equal-weighted, or "capped VW" for value-weighted with capped weights.

Examples

if (FALSE) { # \dontrun{
  download_data_huggingface(
    "high_frequency_sp500", "2007-07-26", "2007-07-27"
  )
  download_data_huggingface(
    "factor_library",
    sorting_variable = "high52",
    rebalancing = "annual"
  )
  download_data_huggingface(
    "factor_library", sorting_variable = "assetgrowth", fill_all = TRUE
  )
  download_data_huggingface(
    "factor_library",
    sorting_variable = "size",
    start_date = "2000-01-01",
    end_date = "2020-12-31"
  )
  download_data_huggingface("factor_library", ids = c(1L, 2L, 3L))
} # }