zeki¶
Fast insurance capital modelling in Python.
zeki is a Python package for building capital models: simulated reserve and underwriting risk, reinsurance, dependency between classes and years, and the statistics drawn from them. It was written for capital modelling teams in the London Market, though nothing in it is specific to them.
You describe a model in Python, much as you would describe a query in Polars. zeki records how each value is computed, then evaluates the whole model in one parallel pass, on every core, in a compiled Rust engine.
rng = np.random.default_rng(2026)
gross = (
zk.Collection.of(Parameters, parameters)
.with_columns(gross=zk.float(rng.lognormal, zk.dim("mu"), zk.dim("sigma"), 10_000))
.drop_dims("mu", "sigma")
.validate(Business, Gross)
)
recovery = (gross - 20_000.0).clamp(0.0, 30_000.0) # 30k xs 20k, per row and simulation
net = (gross - recovery).rename({"gross": "net"})
copula = zk.Copula.gaussian(lambda row_a, row_b: 1.0 if row_a == row_b else 0.5)
zk.correlate(gross, copula)
total_net = net.sum() # every row summed: one row, no dims
by_class = net.group_by(zk.dim("class_of_business")).sum()
total, classes = zk.collect_all(total_net, by_class)
net_values = total.to_numpy("net")[0] # the row's 10,000 simulated values
print(f"mean {net_values.mean():,.0f}, 1-in-200 {np.quantile(net_values, 0.995):,.0f}")
print(classes.to_polars())
What it gives you¶
- Collections, like data frames of simulations. A collection is a table: dimension columns, such as class of business and underwriting year, and value columns holding a constant, an array of simulations, or a jagged value per row.
- Three shapes of value. A constant holds one value, an array holds one value per simulation, and a jagged value holds any number of values per simulation, such as the events of a frequency-severity distribution.
- Typed schemas.
zk.Collection[Business, zk.FloatA[Literal["gross"]]]says what a collection holds, and a type checker follows it through your model. - Dependency without the bookkeeping. Correlate values with a copula, and everything built from them, before or after, stays consistent. zeki tracks which inputs are tied to which.
- Lazy, then fast. Nothing is computed until you
collect(). zeki then evaluates only what's needed, in chunks small enough to stay in cache, so intermediate values are never held in memory in full. - Works with the Python ecosystem. Values come in as NumPy arrays or from a Polars DataFrame, and go out as NumPy, Polars, pandas or plain Python.
Where next¶
- Getting started: install zeki and build your first model.
- User guide: the concepts, and how to build, combine, correlate and read collections.
- API reference: every public class and function.