Download data from a Hugging Face dataset
Source:R/download_data_huggingface.R
download_data_huggingface.RdDownloads 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. Seestart_date.- type
- ...
For
dataset = "factor_library": either named arguments used to filter the portfolio grid, orids = <vector>to bypass the grid filter and download specific portfolios directly viadownload_factor_library_ids(). Filter arguments take the formcolumn = value, wherevaluemay be a vector to match multiple levels. Optionally passfill_all = TRUEto leave unspecified columns unrestricted (default:FALSE, i.e. unspecified columns are fixed at the defaults listed below). PassingNULLfor any parameter removes that filter entirely, returning all values for that column (e.g.,min_size_quantile = NULLincludes all size groups). Passing an unrecognised column name raises an error listing the supported names.idscannot be combined with filter arguments. Ignored whendataset != "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). Seedownload_factor_library_grid()for all values. No default is applied.min_size_quantile(defaults to0.2): Fraction of the smallest stocks (by market cap) excluded from the portfolio universe.0.2drops the bottom 20%.exclude_financials(defaults toFALSE): 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 toFALSE): 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 to10): Number of quantile groups (e.g.,10for 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 toNULL): Number of size groups for the secondary sort. Required whensorting_methodis 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 toNA): Minimum size quantile of the stocks that set the main breakpoints (e.g.,0.2).NAmeans 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.
See also
Other download functions:
download_data(),
download_data_constituents(),
download_data_factors_ff(),
download_data_factors_q(),
download_data_fred(),
download_data_fred_md(),
download_data_jkp(),
download_data_macro_predictors(),
download_data_osap(),
download_data_pastor_stambaugh(),
download_data_risk_free(),
download_data_stambaugh_yuan(),
download_data_stock_prices(),
download_factor_library_grid(),
download_factor_library_ids()
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))
} # }