https://github.com/narasiva90/cmtratebootstrap
Bootstrap arbitrage-free yield curves from US Treasury CMT rates using piecewise linear or monotone cubic forward interpolation
https://github.com/narasiva90/cmtratebootstrap
bootstrap finance fixed-income monotone-splines quantitative-finance treasury yield-curve
Last synced: 4 months ago
JSON representation
Bootstrap arbitrage-free yield curves from US Treasury CMT rates using piecewise linear or monotone cubic forward interpolation
- Host: GitHub
- URL: https://github.com/narasiva90/cmtratebootstrap
- Owner: NaraSiva90
- License: mit
- Created: 2026-02-15T08:57:26.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-02-15T09:13:35.000Z (5 months ago)
- Last Synced: 2026-02-15T15:08:44.963Z (5 months ago)
- Topics: bootstrap, finance, fixed-income, monotone-splines, quantitative-finance, treasury, yield-curve
- Language: Python
- Homepage:
- Size: 292 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Treasury CMT Yield Curve Bootstrap
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
Bootstrap discount factors and zero-coupon yield curves from US Treasury CMT rates.
## Quick Start
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Download Historical Data
Download the Treasury par yield curve data (1990-2023) from:
https://home.treasury.gov/resource-center/data-chart-center/interest-rates/TextView?type=daily_treasury_yield_curve
Save as: `data/par-yield-curve-rates-1990-2023.csv`
### 3. Build Initial Dataset
```bash
# All data from 1990
python scripts/build_initial_treasury_file.py
# Or filter to recent years (recommended for faster processing)
python scripts/build_initial_treasury_file.py --start-date 2022-01-01
```
This creates `Treasury_CMT_Data_Tool.xlsx` with combined historical + current data.
### 4. Run Bootstrap
```bash
# Scheme 2 (piecewise linear forward - recommended)
python scripts/run_bootstrap.py --scheme 2
# Scheme 3 (monotone cubic forward - smoother) with Excel output
python scripts/run_bootstrap.py --scheme 3 --write-excel
```
Outputs:
- `Treasury_CMT_Data_Tool_curves_S2_YYYY-YYYY.npz` (compressed data)
- `Treasury_CMT_Data_Tool_curves_S2_YYYY-YYYY.xlsx` (human-readable)
### 5. Update Data (Ongoing)
```bash
python scripts/update_treasury_cmt.py
```
Updates `Treasury_CMT_Data_Tool.xlsx` with latest rates from Treasury API.
## 📊 Interactive Visualization
Explore bootstrapped yield curves with mathematically correct reconstruction:
```bash
# Run with sample data (2022-2026 included)
python -m streamlit run scripts/yield_curve_app.py
```
### Why Curve Reconstruction Matters
Most yield curve tools use **linear interpolation** between tenor points - this is mathematically incorrect!
Our approach **reconstructs continuous curves** from bootstrap parameters:
- **S1:** Piecewise constant forwards → Exponential discount decay
- **S2:** Piecewise linear forwards → Smooth exponential decay
- **S3:** Monotone cubic forwards → Perfectly smooth curves
### Features
**Tab 1: Yield Curves**
- Par, spot, and forward rates (smooth reconstruction)
- Discount factor curves (exponential decay)
- Spot-par spread analysis
- Data table with CSV export (expandable)

*Scheme 3 shows perfectly smooth forward rates - true cubic interpolation, not linear approximation*
**Tab 2: Spread Analysis**
- Compare any two tenors (e.g., 10Y-2Y inversion)
- Date range filtering
- Distribution histograms with statistics
**Tab 3: Forward Projections**
- Forward term structure: f(0, s, s+M)
- Multiple tenors (1Mo to 30Yr)
- Shows market rate expectations
- Progressive smoothing demonstration

*Progressive smoothing: 1Mo forward is jagged, 10Yr forward is smooth - mathematics visualized*
See [Visualization Guide](docs/VISUALIZATION_GUIDE.md) for complete documentation.
## Project Structure
```
cmt-yield-curve-bootstrap/
├── README.md # This file
├── LICENSE
├── requirements.txt # Python dependencies
├── .gitignore
│
├── src/
│ └── cmt_bootstrap.py # Core bootstrap algorithms
│
├── scripts/
│ ├── run_bootstrap.py # Wrapper to run bootstrap on Excel file
│ ├── update_short_rates.py # Combine SOFR/Fed Funds histories
│ ├── update_treasury_cmt.py # Fetch latest CMT rates from Treasury API
│ └── build_initial_treasury_file.py # One-time: build complete historical dataset
│
├── data/
│ ├── Treasury_CMT_Data_Tool.xlsx # Main data file (generated by build script)
│ ├── par-yield-curve-rates-1990-2023.csv # Historical data (download from Treasury)
│ └── short_rates/
│ ├── fed_funds_1954_2018.csv # FRED DFF series (included)
│ └── sofr_manual.csv # SOFR baseline (included)
│ # short_rate_combined.csv # Generated by update_short_rates.py
│
└── docs/
├── USER_GUIDE.md # Detailed usage guide
└── BOOTSTRAP_GUIDE.md # Bootstrap methodology
```
V1.1 Directory Structure:
```
cmt-yield-curve-bootstrap/
├── README.md ← UPDATE
├── LICENSE
├── requirements.txt ← UPDATED
├── .gitignore ← UPDATE
├── RELEASE_NOTES.md ← NEW
│
├── src/
│ └── cmt_bootstrap.py
│
├── scripts/
│ ├── yield_curve_app.py ← NEW
│ ├── curve_reconstruction.py ← NEW
│ ├── build_initial_treasury_file.py
│ ├── update_treasury_cmt.py
│ ├── update_short_rates.py
│ └── run_bootstrap.py
│
├── data/
│ ├── samples/ ← NEW
│ │ ├── README.md ← NEW
│ │ ├── Treasury_CMT_curves_S1_2022_2026.npz ← NEW
│ │ ├── Treasury_CMT_curves_S2_2022_2026.npz ← NEW
│ │ └── Treasury_CMT_curves_S3_2022_2026.npz ← NEW
│ └── short_rates/
│ ├── fed_funds_1954_2018.csv
│ └── sofr_manual.csv
│
└── docs/
├── USER_GUIDE.md
├── BOOTSTRAP_GUIDE.md
├── VISUALIZATION_GUIDE.md ← NEW
├── CURVE_RECONSTRUCTION.md ← NEW
├── INSTALLATION_GUIDE.md ← NEW
└── images/ ← NEW
├── yield_curves_s1.png
├── yield_curves_s3.png
├── spread_analysis.png
└── forward_projections.png
```
## Bootstrap Schemes
**Scheme 1:** Piecewise constant instantaneous forward
- Simplest, fast
- Discontinuous forwards
**Scheme 2:** Piecewise linear instantaneous forward
- Good balance of speed and smoothness
- **Recommended for most use cases**
**Scheme 3:** Monotone cubic instantaneous forward
- Smoothest curves
- Slower computation
- Best for derivatives pricing
## Output Files
### NPZ File (Primary)
Compressed NumPy archive with:
- Par rates (input)
- Discount factors at each tenor
- Spot (zero) rates (continuous compounding)
- Forward rates at tenor endpoints
- Bootstrap parameters (scheme-dependent)
- Validation: implied par rates, round-trip errors
### Excel File (Optional)
```bash
# Output to excel modifier
python scripts/run_bootstrap.py --scheme 2 --write-excel
```
Human-readable tables:
- Par Rates (input)
- Discount Factors
- Spot Rates (cc)
- Forward @ TenorEnd
- Par Rates (implied)
- Round-Trip Error (bp)
- Bootstrap parameters
## Data Sources
**CMT Rates:** US Treasury Department
- Historical: CSV download (1990-2023)
- Recent: XML API (2024-present)
**Short Rates (r₀ anchor):**
- SOFR: 2018-present (preferred)
- Effective Fed Funds: 1954-2018 (fallback)
## Notes
- Par rates interpreted as swap/coupon-equivalent rates
- Missing tenors are skipped (no interpolation)
- Payment frequency: 24 per year (semi-monthly, configurable with `--nu`)
- All rates stored in decimal form (0.0555 = 5.55%)
## References
- US Treasury: https://home.treasury.gov/
- FRED (Fed Funds): https://fred.stlouisfed.org/series/DFF
- NY Fed (SOFR): https://www.newyorkfed.org/markets/reference-rates/sofr
## License
MIT License
---