Coder Social home page Coder Social logo

kr_example's Introduction

Kernel Ridge (KR) Regression for Discount Curve Estimation

This repository contains companion code for the paper Stripping the Discount Curve—a Robust Machine Learning Approach, which can be accessed here.

Example to get started

  • 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 data from WRDS and estimate KR term structure on multiple dates

  1. 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)
  1. 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 and end_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.
  1. 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 eq and eq, 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.

Suggested citation

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.