download_open_source.download_data_macro_predictors()
Download and process macro predictor data.
Usage
download_open_source.download_data_macro_predictors(
dataset=None,
start_date=None,
end_date=None,
type=None,
sheet_id="1bM7vCWd3WOt95Sf9qjLPZjoiafgF_8EG"
)Downloads and processes macroeconomic predictor data based on the specified dataset (monthly, quarterly, or annual), date range, and source URL. The function downloads the data from a Google Sheets export link and processes the raw data into a structured format, calculating additional financial metrics and filtering by the specified date range.
Parameters
dataset: str = None-
The dataset to download. Accepts ‘monthly’, ‘quarterly’, or ‘annual’.
start_date: str = None-
A character string or date in ‘YYYY-MM-DD’ format specifying the start date for the data. If not provided, the full dataset is returned.
end_date: str = None-
A character string or date in ‘YYYY-MM-DD’ format specifying the end date for the data. If not provided, the full dataset is returned.
type: str = None-
Deprecated. Use ‘dataset’ instead. If supplied, a leading ‘macro_predictors_’ prefix is stripped (e.g., ‘macro_predictors_monthly’ becomes ‘monthly’) and a DeprecationWarning is emitted.
sheet_id: str = "1bM7vCWd3WOt95Sf9qjLPZjoiafgF_8EG"- The Google Sheets ID from which to download the dataset, with the default ‘1bM7vCWd3WOt95Sf9qjLPZjoiafgF_8EG’.
Returns
pl.DataFrame- A data frame with processed data, filtered by the specified date range and including financial metrics. ‘rp_div’ is the future excess market return: the log return of the index with dividends in the next period minus the log risk-free rate of the next period, ‘log(1 + Rfree)’.
References
Welch, I., and Goyal, A. (2008). A comprehensive look at the empirical performance of equity premium prediction. Review of Financial Studies, 21(4), 1455-1508. https://doi.org/10.1093/rfs/hhm014
Examples
from tidyfinance import download_data_macro_predictors
download_data_macro_predictors('monthly')
download_data_macro_predictors(
'quarterly', '2000-01-01', '2020-12-31'
)