Educational Python library for interest rate term structure estimation
Project description
PyTermStructure
Educational Python library for interest rate term structure estimation
Inspired by Damir Filipović's "Interest Rate Models"
École Polytechnique Fédérale de Lausanne (EPFL)
Course Link
Version 0.0.1 - Educational Beta
Status: Educational implementation for learning purposes.
Accuracy: Results may deviate by ±15 basis points from reference values due to:
- Simplified interpolation methods
- Approximations in long-term swap pricing
- Day-count convention simplifications|
Recommendation: Use for educational purposes, research, and prototyping. For production systems requiring high precision, consider QuantLib or FinancePy.
Quick Start
Installation
pip install pytermstructure
Your First Term Structure
import pytermstructure as pts
# Create bootstrap method
bootstrap = pts.BootstrapMethod(verbose=True)
# Add market instruments
bootstrap.add_instrument(pts.MarketInstrument(
instrument_type=pts.InstrumentType.LIBOR,
maturity=0.25, # 3 months
quote=0.15 # 0.15%
))
bootstrap.add_instrument(pts.MarketInstrument(
instrument_type=pts.InstrumentType.SWAP,
maturity=2.0, # 2 years
quote=0.50 # 0.50%
))
# Fit discount curve
discount_curve = bootstrap.fit()
# Get zero rates
zero_rates = bootstrap.get_zero_rates()
Getting Help
import pytermstructure as pts
# General help
pts.help()
# Method-specific help
pts.help("bootstrap")
pts.help("lorimier")
Features
5 Methods Implemented
| Method | Type | Accuracy | Use Case |
|---|---|---|---|
| Bootstrap | Exact | ±15 bps | Educational, trading desks |
| Pseudoinverse | Exact | ±15 bps | Smooth + exact pricing |
| Lorimier | Smooth | ±5 bps | Central banks, smooth curves |
| PCA | Analysis | N/A | Risk management |
| Nelson-Siegel | Parametric | N/A | Quick approximation |
Educational Quality
- 📖 Comprehensive documentation - Built-in help system
- 🎓 Based on academic course - Filipović'"'"'s EPFL materials
- ✅ Type hints - Full typing support
- 🧪 Tested - Validated with course examples
- 🔓 Free Software - GNU GPLv3 license
- 📊 Professional structure - Ready for contributions
Methods Overview
1. Bootstrap Method
Sequential construction from LIBOR → Futures → Swaps.
bootstrap = pts.BootstrapMethod(verbose=True)
bootstrap.add_instrument(pts.MarketInstrument(
pts.InstrumentType.LIBOR, 0.25, 0.15
))
discount_curve = bootstrap.fit()
Accuracy: ±13 bps on 30Y forward rates
2. Lorimier Method
Smoothing splines with parameter α for smooth forward curves.
import numpy as np
maturities = np.array()
yields = np.array([-0.79, -0.73, -0.65, -0.55,
-0.33, -0.04, 0.54, 0.73]) / 100
lorimier = pts.LorimierMethod(alpha=0.1)
discount_curve = lorimier.fit(yields, maturities)
y_6y = lorimier.get_yield_at(6.0)
Accuracy: ±3 bps on Swiss government bonds
3. PCA Analysis
Principal component analysis of yield curve movements.
pca = pts.PCAAnalysis()
eigenvalues, eigenvectors, explained_var = pca.fit(yield_changes)
print(f"Level: {explained_var:.1f}%")
print(f"Slope: {explained_var:.1f}%")[1]
print(f"Curvature: {explained_var:.1f}%")
Installation
From PyPI
pip install pytermstructure
From Source
git clone https://github.com/MarcoGigante/pytermstructure.git
cd pytermstructure
pip install -e .
Test Installation
python -c "import pytermstructure as pts; pts.version(); pts.help()"
Expected output:
PyTermStructure 0.0.1 loaded. For help: pts.help()
PyTermStructure 0.0.1
Author: Marco Gigante
License: GPLv3
Running Examples
# Example 1: Bootstrap US market
python examples/example_bootstrap.py
# Example 2: Pseudoinverse
python examples/example_pseudoinverse.py
# Example 3: Lorimier Swiss bonds
python examples/example_lorimier.py
# Run all examples
python examples/practical_examples.py
Academic Reference
This library implements methods from:
Filipović, D. (2009). Term-Structure Models: A Graduate Course. Springer Finance.
Online Course: Interest Rate Models
École Polytechnique Fédérale de Lausanne (EPFL)
License
GNU General Public License v3.0 or later.
This ensures PyTermStructure remains free software forever.
See LICENSE for details.
Contributing
Contributions welcome! Areas for improvement:
- Accuracy refinement (target: <5 bps)
- Full pseudoinverse implementation (cash flow matrix)
- True Lorimier optimization (with α parameter)
- More day-count conventions
- Business day calendars
Please ensure GPL-compatible contributions.
Author
Marco Gigante
MSc in Quantitative Finance, University of Siena
Inspired by Prof. Damir Filipović'"'"'s course at EPFL.
Acknowledgments
- Prof. Damir Filipović (EPFL)
- École Polytechnique Fédérale de Lausanne
- NumPy, SciPy, Pandas communities
- Free Software Foundation
Support
- Documentation:
pts.help() - Issues: GitHub Issues
- Documentation: pytermstructure.readthedocs.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytermstructure-0.0.1.tar.gz.
File metadata
- Download URL: pytermstructure-0.0.1.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f1760532cc83206da9b41eaf90289ac8fd66c3e5ad9eae9a108c71d7683bd31
|
|
| MD5 |
d9f18a7447505fb4fd25619cad76df3f
|
|
| BLAKE2b-256 |
64abac776458decbbd3b1693905822b993c3a83580e2b165cf7e9b84161f47de
|
Provenance
The following attestation bundles were made for pytermstructure-0.0.1.tar.gz:
Publisher:
publish.yml on MarcoGigante/pytermstructure
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytermstructure-0.0.1.tar.gz -
Subject digest:
7f1760532cc83206da9b41eaf90289ac8fd66c3e5ad9eae9a108c71d7683bd31 - Sigstore transparency entry: 702444121
- Sigstore integration time:
-
Permalink:
MarcoGigante/pytermstructure@985c4e48aebb0b9b1e1efcaabae15e869a35234e -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/MarcoGigante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@985c4e48aebb0b9b1e1efcaabae15e869a35234e -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytermstructure-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pytermstructure-0.0.1-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
549f2daf9fef9c47fbb3a32d453506f525ba3151cd629b8b1db021fe837ea22b
|
|
| MD5 |
e39a9f2176560c23c3b2cab9f6287b21
|
|
| BLAKE2b-256 |
b2c38f9ddd58e8a70a7da55b5f9252c865e232b17a3db28d5ce3eaf179ce823f
|
Provenance
The following attestation bundles were made for pytermstructure-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on MarcoGigante/pytermstructure
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytermstructure-0.0.1-py3-none-any.whl -
Subject digest:
549f2daf9fef9c47fbb3a32d453506f525ba3151cd629b8b1db021fe837ea22b - Sigstore transparency entry: 702444123
- Sigstore integration time:
-
Permalink:
MarcoGigante/pytermstructure@985c4e48aebb0b9b1e1efcaabae15e869a35234e -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/MarcoGigante
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@985c4e48aebb0b9b1e1efcaabae15e869a35234e -
Trigger Event:
release
-
Statement type: