Skip to main content

Longevity bond pricing and mortality modeling toolkit

Project description

๐Ÿงฎ PyMORT โ€” Longevity Bond Pricing & Mortality Modeling

A teaching-size Python library and CLI for pricing longevity-linked securities and modeling mortality risk.


โœจ Overview

PyMORT provides a compact yet extensible framework for mortality modeling and longevity-linked security pricing.
It is designed for educational and research purposes within the Data Science & Advanced Programming MSc course (HEC Lausanne, Winter 2025).


๐Ÿ“ฆ Key Features

Mortality Models

  • Lee-Carter model for mortality forecasting
  • Cairns-Blake-Dowd (CBD) model extensions
  • Age-Period-Cohort models
  • Stochastic mortality projections

Pricing Instruments

  • Longevity bonds (survivor-linked coupons)
  • Survivor swaps and forwards
  • q-forwards (mortality derivatives)
  • Annuity valuations

Risk Analysis

  • Scenario analysis and stress testing
  • Sensitivity to mortality parameters
  • Hedging strategy optimization
  • Mortality surface visualization

Core Tools

  • CLI and Python package modes
  • Full test coverage (80%+) with pytest and hypothesis
  • Type safety via strict mypy configuration
  • Reproducible builds using Makefile targets

๐Ÿ“Š Project Structure

pymort/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ pymort/
โ”‚       โ”œโ”€โ”€ analysis/                 # Mortality analysis & risk tools
โ”‚       โ”‚   โ”œโ”€โ”€ bootstrap.py
โ”‚       โ”‚   โ”œโ”€โ”€ fitting.py
โ”‚       โ”‚   โ”œโ”€โ”€ projections.py
โ”‚       โ”‚   โ”œโ”€โ”€ reporting.py
โ”‚       โ”‚   โ”œโ”€โ”€ risk_tools.py
โ”‚       โ”‚   โ”œโ”€โ”€ scenario.py
โ”‚       โ”‚   โ”œโ”€โ”€ scenario_analysis.py
โ”‚       โ”‚   โ”œโ”€โ”€ sensitivities.py
โ”‚       โ”‚   โ”œโ”€โ”€ smoothing.py           # CPsplines-based smoothing (optional)
โ”‚       โ”‚   โ””โ”€โ”€ validation.py
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ interest_rates/            # Interest-rate models
โ”‚       โ”‚   โ””โ”€โ”€ hull_white.py
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ models/                    # Mortality models
โ”‚       โ”‚   โ”œโ”€โ”€ apc_m3.py
โ”‚       โ”‚   โ”œโ”€โ”€ cbd_m5.py
โ”‚       โ”‚   โ”œโ”€โ”€ cbd_m6.py
โ”‚       โ”‚   โ”œโ”€โ”€ cbd_m7.py
โ”‚       โ”‚   โ”œโ”€โ”€ gompertz.py
โ”‚       โ”‚   โ”œโ”€โ”€ lc_m1.py
โ”‚       โ”‚   โ”œโ”€โ”€ lc_m2.py
โ”‚       โ”‚   โ””โ”€โ”€ utils.py
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ pricing/                   # Pricing of longevity-linked instruments
โ”‚       โ”‚   โ”œโ”€โ”€ hedging.py
โ”‚       โ”‚   โ”œโ”€โ”€ liabilities.py
โ”‚       โ”‚   โ”œโ”€โ”€ longevity_bonds.py
โ”‚       โ”‚   โ”œโ”€โ”€ mortality_derivatives.py
โ”‚       โ”‚   โ”œโ”€โ”€ risk_neutral.py
โ”‚       โ”‚   โ”œโ”€โ”€ survivor_swaps.py
โ”‚       โ”‚   โ””โ”€โ”€ utils.py
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ visualization/             # Plotting & diagnostics
โ”‚       โ”‚   โ”œโ”€โ”€ fans.py
โ”‚       โ”‚   โ””โ”€โ”€ lexis.py
โ”‚       โ”‚
โ”‚       โ”œโ”€โ”€ cli.py                     # Command-line interface
โ”‚       โ”œโ”€โ”€ lifetables.py
โ”‚       โ”œโ”€โ”€ pipeline.py                # High-level pricing & sensitivity pipeline
โ”‚       โ”œโ”€โ”€ utils.py
โ”‚       โ”œโ”€โ”€ _types.py
โ”‚       โ””โ”€โ”€ py.typed                   # PEP 561 typing marker
โ”‚
โ”œโ”€โ”€ streamlit_app/                     # Interactive Streamlit application
โ”‚   โ”œโ”€โ”€ App.py
โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”œโ”€โ”€ 1_Data_Upload.py
โ”‚   โ”‚   โ”œโ”€โ”€ 2_Data_Slicing.py
โ”‚   โ”‚   โ”œโ”€โ”€ 3_Fit_Select.py
โ”‚   โ”‚   โ”œโ”€โ”€ 4_Projection_P.py
โ”‚   โ”‚   โ”œโ”€โ”€ 5_Risk_Neutral_Q.py
โ”‚   โ”‚   โ”œโ”€โ”€ 6_Pricing.py
โ”‚   โ”‚   โ”œโ”€โ”€ 7_Hedging.py
โ”‚   โ”‚   โ”œโ”€โ”€ 8_Scenario_Analysis.py
โ”‚   โ”‚   โ”œโ”€โ”€ 9_Sensitivities.py
โ”‚   โ”‚   โ””โ”€โ”€ 10_Report_Export.py
โ”‚   โ”œโ”€โ”€ assets/
โ”‚   โ”‚   โ””โ”€โ”€ logo.png
โ”‚   โ””โ”€โ”€ .streamlit/
โ”‚       โ”œโ”€โ”€ config.toml
โ”‚       โ””โ”€โ”€ secrets.toml
โ”‚
โ”œโ”€โ”€ cpsplines/                         # External CPsplines dependency (optional)
โ”‚   โ””โ”€โ”€ README.md                      # Install notes & Python โ‰ฅ 3.12 requirement
โ”‚
โ”œโ”€โ”€ tests/                             # Pytest suite (โ‰ฅ80% coverage)
โ”‚
โ”œโ”€โ”€ validation_against_StMoMo/         # External validation vs R (StMoMo)
โ”‚   โ”œโ”€โ”€ stmomo_fit_cbd.R
โ”‚   โ”œโ”€โ”€ stmomo_fit_lc.R
โ”‚   โ”œโ”€โ”€ validate_vs_stmomo.py
โ”‚   โ””โ”€โ”€ outputs/
โ”‚
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ”œโ”€โ”€ ci.yml                     # CI: tests, coverage, ruff, mypy
โ”‚       โ””โ”€โ”€ release.yml                # Build & PyPI release
โ”‚
โ”œโ”€โ”€ .coverage                          # Local coverage database (gitignored)
โ”œโ”€โ”€ coverage.xml                       # Coverage report (CI / Codecov)
โ”‚
โ”œโ”€โ”€ .editorconfig
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .pre-commit-config.yaml            # Pre-commit hooks (ruff, mypy, etc.)
โ”œโ”€โ”€ .secrets.baseline                  # Secret scanning baseline
โ”‚
โ”œโ”€โ”€ CONTRIBUTING.md                    # Contribution guidelines
โ”œโ”€โ”€ PROJECT_SPECIFICATION.md           # Technical & academic specification
โ”œโ”€โ”€ README.md                          # Main project README
โ”œโ”€โ”€ README_cli.md                      # CLI documentation
โ”œโ”€โ”€ LICENSE                            # MIT license
โ”œโ”€โ”€ Makefile                           # Developer shortcuts
โ”œโ”€โ”€ pyproject.toml                     # Build, deps, tooling config
โ””โ”€โ”€ requirements.txt

๐Ÿ› ๏ธ Development Workflow

make install-dev    # Set up development environment
make check          # Run all quality checks
make test           # Run tests with coverage

๐Ÿ“– Documentation

See PROJECT_SPECIFICATION.md for full project requirements.

See CONTRIBUTING.md for development guidelines.

See README_cli.md for CLI documentation.


๐Ÿ“„ License

MIT License - see LICENSE for details.


๐Ÿ‘ค Author

Developed and maintained by Pierre-Antoine Le Quellec (@palqc) MSc Finance โ€“ HEC Lausanne | Focus: Financial Data Science & Risk Analytics.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymort_palqc-1.0.1.tar.gz (148.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymort_palqc-1.0.1-py3-none-any.whl (127.5 kB view details)

Uploaded Python 3

File details

Details for the file pymort_palqc-1.0.1.tar.gz.

File metadata

  • Download URL: pymort_palqc-1.0.1.tar.gz
  • Upload date:
  • Size: 148.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pymort_palqc-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6f430811d3ee27edf92273b064133ce97a42b56d715846d5c491e5660e47d0ad
MD5 cc524809fa2e8b46fb8dfde83e0e5fe0
BLAKE2b-256 3c0651a5239ba5fe28e289821c39f0fc445a1af8929ad217a4f60d9080e9c572

See more details on using hashes here.

File details

Details for the file pymort_palqc-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pymort_palqc-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 127.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pymort_palqc-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73237032bd885bb8a47a4d018864302471b30db3c9dc176b97f649f0c6bcc858
MD5 fe542bbeb76e4d26e2cf589400a26ed5
BLAKE2b-256 3d60bd8bca1901c2014cb20bfca3efded002d55f441ece6305067e3b740a18a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page