download_tidy_finance.download_data_risk_free()

Download risk-free rate data.

Usage

Source

download_tidy_finance.download_data_risk_free(
    start_date=None, end_date=None, frequency="monthly"
)

Downloads pre-processed risk-free rate data from the ‘tidy-finance/risk-free’ dataset on Hugging Face. The dataset is updated monthly via a scheduled GitHub Actions workflow that splices the 3-Month Treasury Bill Secondary Market Rate (pre-2001) with the 4-Week Treasury Bill Secondary Market Rate (from 2001 onwards) sourced from FRED. For monthly data, the monthly TB3MS series is spliced with the daily DTB4WK series aggregated to month-end. For daily data, the daily DTB3 series is spliced with the daily DTB4WK series, both at the business-day frequency provided by FRED.

Both series are quoted as annualised bank discount rates on a 360-day basis. Given an annualised discount rate ‘d’ and a T-bill with ‘n’ days to maturity, the holding-period return is ‘HPR = d * n / 360 / (1 - d * n / 360)’, which is then converted to the target period length via ‘(1 + HPR) ** (target / source) - 1’.

The series are spliced at 2001-07-01. Pre-2001, TB3MS (monthly) or DTB3 (daily) is used (3-month T-bill, n = 90). Monthly conversion uses exponent ‘1 / 3’; daily conversion uses exponent ‘1 / 63’ (approximate trading days per quarter). From 2001 onwards, DTB4WK (4-week T-bill, n = 28) is used. For monthly data, the last non-missing observation per calendar month is taken and the exponent is ‘365 / (28 * 12)’. For daily data, observations are used as-is and the exponent is ‘1 / 20’ (approximate trading days per 4-week period).

Business-day gaps in the daily series (e.g. holidays) are handled by forward-filling the most recent available rate. Monthly data starts in 1934-01-01 (TB3MS). Daily data starts in 1954-01-04 because of the availability of DTB3.

Parameters

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.

frequency: str = "monthly"
A character string, either ‘monthly’ (default) or ‘daily’, specifying the frequency of the returned data. Daily data starts in 1954-01-04 because of availability of DTB3, while monthly data starts in 1934-01-01.

Returns

pl.DataFrame

A data frame with two columns:

  • ‘date’: the date of the observation.
  • ‘risk_free’: the risk-free rate for the period.

Examples

from tidyfinance import download_data_risk_free
download_data_risk_free('2020-01-01', '2020-12-31')
download_data_risk_free(
    '2020-01-01', '2020-12-31', frequency='daily'
)