Skip to main content

download_tidy_finance.download_factor_library_grid()

Download the factor library grid from Hugging Face.

Usage

Source

download_tidy_finance.download_factor_library_grid(
    refresh=False, grid_revision="main"
)

Returns the grid of the ‘tidy-finance/factor-library-grid’ dataset, which describes every portfolio construction available in the factor library (one row per construction, identified by ‘id’). Use the returned data frame to discover which combinations of ‘sorting_variable’, ‘weighting_scheme’, ‘rebalancing’, and other columns exist before requesting their returns with ‘download_factor_library_ids’. The grid is read by name from ‘portfolio_sort_grid.parquet’, without listing the files of the dataset.

The grid is downloaded once per Python session and revision and cached in memory, so repeated calls (including those made by ‘download_factor_library_ids’ and ‘download_data(“Tidy Finance”, “factor_library”, …)’) reuse it. Set ‘refresh=True’ to download it again.

Parameters

refresh: bool = False

If True, the grid is downloaded again and replaces the copy cached in the current session.

grid_revision: str = "main"
Commit hash, branch, or tag of the Hugging Face dataset ‘tidy-finance/factor-library-grid’ to read the grid from. Pin a commit to reproduce results with a fixed release of the factor library.

Returns

pl.DataFrame
A data frame with one row per portfolio construction in the factor library, including the integer ‘id’ column used by ‘download_factor_library_ids’.

Raises

ValueError
If ‘refresh’ is not True or False, if ‘grid_revision’ is not a single string, or if the revision does not exist or holds no grid.

Examples

from tidyfinance import download_factor_library_grid
grid = download_factor_library_grid()
grid = download_factor_library_grid(refresh=True)