This project provides a Python-based, first-principles demonstration of fixed-income numerics. It covers the entire workflow from raw data to risk analysis, including curve construction, pricing of vanilla interest rate products, and volatility modeling.
The project is organized into the following modules:
main.py: The main execution script that runs the entire workflow.config.py: Configuration file for the project, including paths and conventions.data_loader.py: Handles data ingestion from various sources with graceful fallbacks.curve_construction.py: Implements the bootstrapping of the discount curve.pricing.py: Contains functions for pricing bonds, swaps, and FRAs.risk.py: Implements the calculation of DV01 and key-rate sensitivities.volatility.py: Includes the Black-76 model for swaptions and a SABR model calibration.hull_white.py: A lightweight implementation of the Hull-White short-rate model.visualizations.py: Generates plots for risk and volatility analysis.
To run this project, you need to install the required packages. You can do this by running:
pip install numpy pandas matplotlib scipy pandas_datareader yfinanceTo run the project, simply execute the main.py script:
python main.pyThe script will perform the following steps:
- Load data from CSV files, FRED, Yahoo Finance, or generate synthetic data.
- Build the OIS discount curve.
- Price a fixed-coupon bond, an interest rate swap, and a forward rate agreement.
- Calculate DV01 and key-rate DV01 for the bond.
- Price a European swaption using the Black-76 model and calibrate a SABR model.
- Price a Bermudan swaption using the Hull-White model.
- Generate and save plots for the analysis.
- Export the results to CSV files in the
outputdirectory.
The project can load data from the following CSV files located in the data directory:
| Column | Description |
|---|---|
tenor_str |
Tenor string (e.g., ON, 1W, 1M, 1Y) |
instrument |
Instrument type (OIS, IRS, DEP, FRA) |
quote_type |
Type of quote (rate or par) |
quote_value |
The value of the quote |
| Column | Description |
|---|---|
expiry_code |
Expiry code of the future (e.g., EDZ5) |
type |
Type of instrument (FUT or FRA) |
price_or_rate |
Price of the future or rate of the FRA |
| Column | Description |
|---|---|
tenor_str |
Tenor string (e.g., 6M, 1Y, 5Y) |
spread_bps |
Par spread in basis points |
| Column | Description |
|---|---|
expiry_yrs |
Expiry in years |
strike |
Strike of the option |
black_vol |
Black volatility |
| Column | Description |
|---|---|
expiry_yrs |
Expiry in years |
tenor_yrs |
Tenor of the underlying swap in years |
black_vol |
Black volatility |
The project generates the following files in the output directory:
discount_curve.csv: The bootstrapped discount curve.keyrate_dv01.csv: The key-rate DV01 sensitivities.keyrate_dv01.png: A bar chart of the key-rate DV01 sensitivities.sabr_fit.png: A plot of the SABR model fit against market volatilities.hw_convergence.png: A plot showing the convergence of the Hull-White model.
This project can be extended in several ways:
- Multi-Curve Framework: Implement a proper multi-curve framework with separate discount and projection curves.
- Calendars and Day Counts: Integrate a proper business day calendar and accurate day-count conventions.
- Richer SABR Calibration: Calibrate the SABR model to the full volatility surface.
- LSMC for Bermudans: Use a Least-Squares Monte Carlo (LSMC) approach for more accurate pricing of Bermudan options.