LifeFlow
  • Home
  • Tutorial
  • Reference
  • Changelog
  • Author
  • GitHub
  • PyPI

LifeFlow.

Project life-insurance cash flows and compute the reserves. Write your own flows as plain Python; LifeFlow vectorizes them across the whole portfolio as N × T grids and compiles the hot paths with numba.

Get started → GitHub PyPI
pip install lifeflow
reserve.py
import lifeflow as lf

port = lf.Portfolio(df, "id")
prob = lf.Probabilities(port, [qx])

@lf.grid(port, tl)
def death_benefit(t, capital):
    return capital

# reserve = amount × probability × discount
reserve = (death_benefit()
           * prob.exit_by(qx)
           * discount).sum(axis=1)

LifeFlow computes reserves for life-insurance portfolios

Easy to write, flexible to your product, and fast at scale.

Easy to code

Object-oriented — the repetitive calculations are automated inside objects, so your own code stays clean.
Decorators — ready-made decorators simplify building each calculation and guide you through defining the flows.

Yours to shape

Your flows, your rules — define the shape of every flow yourself: use conditions and any portfolio variable you need.
You stay in control — LifeFlow expects you to drive. It hands you the tools and gets out of the way, so you can fit it to your exact product.

Computationally efficient

Fast foundations — built on powerful Python libraries designed for fast, parallelizable numerical work.
Speed without losing clarity — the grid design keeps calculations fast and easy to audit and review.
Rust modules for a few specific processes are on the roadmap.
complement · not a replacement

LifeFlow works with numpy, not instead of it

LifeFlow doesn't box you into closed-form formulas. It gives the actuary a small set of tools — an object-oriented engine for in-force and exit probabilities, and decorators to project cash flows — so you keep total control of the numbers while the boilerplate and the performance are taken care of.

numpy

The arrays and the maths.

+
LifeFlow

The actuarial structure and the speed.

Ideal for moving Excel calculations to Python and standardizing them into a calculation flow that is easy to design, reproducible and fast.

How it works

Every flow is an N × T matrix — one row per policy, one column per period — and two tools build them.

T periods N policies t₁t₂t₃t₄t₅ P₁P₂Pₙ N × T

Objects: the fixed maths

Portfolio, Timeline, Decrement and Probabilities handle the calculations that are identical for any portfolio — in-force and exit-by-cause probabilities. Set them up once and reuse them everywhere.

Decorators: your freedom

With the @grid decorator you write a flow's value for one policy at one instant, in plain Python. It broadcasts that into the full N × T matrix — you keep total freedom to define your own flows while the grid is built for you.

Tutorial

See LifeFlow work, end to end

A hands-on tour of the whole library on a tiny three-policy portfolio — probabilities, cash flows, ALM and reserves, with every grid printed in full.

Open the tutorial →
SA
The author

Built by SergiActuary

Actuary from Barcelona who likes to build things. LifeFlow is my project to bring life-insurance calculations out of Excel and into fast, easy and scalable Python.

Visit my site

lifeflow · MIT License

 

Built by Sergi López Vergara