This repository contains companion code for the paper Stripping the Discount Curve—a Robust Machine Learning Approach, which can be accessed here.
KR_example.ipynb
provides an example of using the KR model for discount curve estimation using formatted U.S. Treasury data on two example dates. This notebook can be run directly on Google Colab without having to download data to a local machine.
- Download and select data (
get_and_select_raw_data.ipynb
)
- This notebook downloads raw data from WRDS and organizes the data. The output of this notebook can be used by
constructed_input_price_and_cashflow.ipynb
in the next step to construct price vectors and cashflow matrices. - A WRDS account is needed to access CRSP data through WRDS.
- Filters applied in this notebook:
- Only includes fully taxable, non-callable, and non-flower bond issues.
- Certificates of deposit are excluded (ITYPE=3)
- Remove issues whose time series of prices terminate because of ''all exchanged'' (IWHY=3)
- Construct price vectors and cashflow matrices (
construct_input_price_and_cashflow.ipynb
)
- This notebook reads processed CRSP Treasury data files given by
get_and_select_raw_data.ipynb
and generates price vectors and cashflow matrices. - Follow Gurkaynak, Sack, and Wright (2007) and Liu and Wu (2021) and exclude the two most recently issued securities with maturities of 2, 3, 4, 5, 7, 10, 20, and 30 years for securities issued in 1980 or later.
- Price vectors and cashflow matrices are generated only for dates in between
start_date
andend_date
(inclusive for both). If the number of time periods is large (e.g. > 10,000 days), export this notebook into.py
file and run the.py
file instead to accelerate computation. - Cashflow matrices are saved in a compressed form (
.npz
) separately for each date, while price vectors are exported in a dataframe with date index.
- Estimate the KR model on multiple dates (
run_KR_multiple_dates.ipynb
)
- This notebook runs the KR model on multiple dates to obtain estimates for discount curves and log yield curves. Price and cashflow matrices are generated by
construct_input_price_and_cashflow.ipynb
. - For fixed kernel parameters
and
, a kernel matrix is generated once and shared across all dates.
- Filter: remove securities maturing within 90 days for the fitting process.
- Save fitted discount curves and log yield curves as dataframes.
Filipovic, Damir and Pelger, Markus and Ye, Ye, Stripping the Discount Curve - a Robust Machine Learning Approach (March 15, 2022). Swiss Finance Institute Research Paper No. 22-24, Available at SSRN: https://ssrn.com/abstract=4058150 or http://dx.doi.org/10.2139/ssrn.4058150