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.

๐Ÿ“ฆ PyPI package: https://pypi.org/project/pymort-palqc/


โœจ 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.6.tar.gz (147.8 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.6-py3-none-any.whl (128.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymort_palqc-1.0.6.tar.gz
Algorithm Hash digest
SHA256 aaebf0ef710cc02fbb490fab74f7309ce77a0c8190607a2d3589ec0f0c65e075
MD5 8ee23095af8e04d008bd6bac3f3d0b78
BLAKE2b-256 4c5b069be85b11507b973941c27f82db76811547b7fe400bdafcb6a36f98c3b6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pymort_palqc-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fbe96011a8a4b95802e1cfefc470ad33684fc0ded3303223778ff3744147d896
MD5 a997d58e51960ab14dc8401fe51cfcd0
BLAKE2b-256 7bf6bd8b050e2f9e212d782cea163e6ac2a0c3a6a4b282acfee2586aae55005a

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