RSLife
A comprehensive Rust library for actuarial mortality table calculations and life insurance mathematics, following standard actuarial principles and notation.
Features
- Unified API Interface: Consistent and clear parameter requirements across all actuarial functions for enhanced usability
- Performance Optimized: 4-level detail system automatically optimizes calculations for your needs
- XML Parsing: Load mortality data from Society of Actuaries (SOA) XML sources using ACORD XTbML standard
- Multiple Mortality Assumptions: UDD, CFM, and HPB methods for fractional age calculations
- Comprehensive Functions: Life insurance, annuities, and demographic calculations
- Standard Notation: Follows traditional actuarial notation with modern Rust conventions
- Polars Integration: Built on Polars DataFrames for efficient data processing
- Well-Documented: Extensive documentation with mathematical formulations
Quick Start
Add this to your Cargo.toml:
[]
= "0.1.3"
Basic Example
use *;
Custom Data Example
use *;
use *;
Performance Optimization
SOA Mortality Table Automatical Classification
- Only XML files with exactly 1 table are supported.
- The package automatically detects whether
qxorlxis provided and generates a complete mortality table as needed. - Selection functions automatically detect whether the appropriate SOA mortality table is used for calculation.
Computation
RSLife automatically optimizes performance with a 4-level detail system:
- Level 1 (~3x faster): Demographics only
age,qx,px,lx,dx - Level 2 (standard): Level 1 + basic commutation
Cx,Dx - Level 3 (extended): Level 2 + additional commutation
Mx,Nx,Px - Level 4 (complete): Level 3 + additional
Rx,Sx
Functions automatically select the minimum required level for optimal performance.
Mortality Assumptions
The library supports three standard actuarial assumptions for fractional age calculations:
UDD (Uniform Distribution of Deaths)
Linear interpolation between integer ages:
ₜpₓ = 1 - t · qₓ
CFM (Constant Force of Mortality)
Exponential survival model:
ₜpₓ = (1 - qₓ)ᵗ
HPB (Hyperbolic/Balmer)
Hyperbolic interpolation:
ₜpₓ = (1 - qₓ) / (1 - (1-t) · qₓ)
Actuarial Functions & Naming Convention
Function Structure
Systematic Modifiers:
- Imediate: Single letter →
Ax,Axn(payments at end) - Due: Double letter →
aax,aaxn(payments at start) - Increasing:
Iprefix →IAx,Iaax(arithmetic growth) - Decreasing:
Dprefix →DAx1n,Daaxn(arithmetic decrease) - Geometric:
gprefix →gAx,gaax(geometric growth)
These modifiers are applicable to most but not all functions.
Please take a look at Full list
Full list of actuarial functions available via rslife::prelude::*
Annuities:
aax,aaxnIaax,IaaxnDaaxngaax,gaaxn
Benefits and Life Insurance:
Ax,Ax1n,nEx,AxnIAx,IAx1n,IAxnDAx1n,DAxngAx,gAx1n,gnEx,gAxn
Survival Probabilities:
tpx,tqx
For more details, please visit the full documentation
Examples
Check out the examples/ directory for more comprehensive examples:
prelude_demo.rs- Basic usage with the preludemortality_calculations.rs- Detailed actuarial calculationsxml_loading.rs- Various ways to load mortality data
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Willian Nguyen - hieunt.hello@gmail.com
Project Link: https://github.com/hnlearndev/rslife
References
- Actuarial Mathematics for Life Contingent Risks
- Actuarial Mathematics
- Society of Actuaries Mortality Tables
- Standard actuarial notation and practices
Similar Projects
Python:
- pyliferisk - Python library for actuarial calculations and life insurance mathematics
- pymort - Python mortality table library with XML parsing capabilities
R:
- lifecontingencies - R package for actuarial life contingencies calculations
- MortalityTables - R package for working with life and pension tables
- demography - R package for demographic analysis and mortality forecasting
Julia:
- MortalityTables.jl - Julia package for mortality table calculations and life contingencies
- ActuaryUtilities.jl - Julia utilities for actuarial modeling and analysis
Note:
Mojo is a relatively new language and doesn't yet have established actuarial libraries, but its performance characteristics make it promising for computational actuarial work.