Skip to main content

risksim

Portfolio Monte Carlo: aggregate simulation, dependence, reinsurance contracts, and risk measures.

CI PyPI Python

Overview

risksim simulates the aggregate loss of a portfolio whose components can be anything exposing a .sample(n, rng=...) method — lossmodels aggregate models, extremeloss tails, or your own objects. Components are independent by default; rank correlation is imposed with the Iman–Conover construction when you specify a dependence structure.

Aggregate reinsurance is applied as layers or stacked programs, and results come back with the standard risk measures (VaR, TVaR, exceedance probabilities) plus bootstrap confidence intervals, so a simulation answer always carries its simulation error.

Installation

pip install risksim

Requires Python 3.10 or newer.

Quick start

The example pairs risksim with lossmodels (pip install lossmodels), the intended combination for frequency–severity components.

from lossmodels import Poisson, Lognormal, CollectiveRiskModel
from risksim import Portfolio, PortfolioItem, AggregateLayer

# two lines of business, each a collective-risk model (any .sample object works)
line_a = CollectiveRiskModel(Poisson(3.0), Lognormal(8.0, 0.9))
line_b = CollectiveRiskModel(Poisson(1.5), Lognormal(9.0, 0.7))

portfolio = Portfolio([
    PortfolioItem("line_a", line_a),
    PortfolioItem("line_b", line_b, weight=1.25),   # optional exposure weight
])

# aggregate annual loss, net of an aggregate layer
layer = AggregateLayer(attachment=250_000, limit=500_000, share=1.0)
result = portfolio.simulate(100_000, contract=layer, rng=42)

print("gross mean    :", result.gross_mean)
print("ceded mean    :", result.ceded_mean)
print("retained mean :", result.retained_mean)
print("net (retained) 99% TVaR:", result.tvar(0.99))

What's inside

  • Portfolios — Portfolio / PortfolioItem over any objects exposing .sample, with optional exposure weights.
  • Dependence — Iman–Conover rank correlation via risksim.dependence.impose_rank_correlation.
  • Contracts — AggregateLayer, stacked ContractPrograms, and apply_contract on raw loss vectors.
  • Risk measures — empirical VaR, TVaR, exceedance probabilities, and one-call summaries in risksim.metrics.
  • Uncertainty — bootstrap confidence intervals for any statistic in risksim.uncertainty.

The full API reference and end-to-end worked examples live at openactuarial.org/risksim.html.

The OpenActuarial ecosystem

risksim is one of seven packages that share conventions — tidy tables, explicit distribution parameterizations, reproducible random-number handling — and compose across package seams:

Package Role
actuarialpy Calculation primitives the workflow packages build on
experiencestudies Experience reporting, actual-vs-expected, claimant and concentration analysis
projectionmodels Claim, premium, and expense projection over a renewal horizon
ratingmodels Manual and experience rating, credibility, indication, GLM relativities
lossmodels Severity and frequency fitting, aggregate loss distributions
extremeloss Extreme-value tails: POT/GPD, GEV, return levels, splicing
risksim Portfolio Monte Carlo, dependence, reinsurance contracts, risk measures

Install everything at once with pip install openactuarial.

Development

git clone https://github.com/OpenActuarial/risksim
cd risksim
python -m pip install -e ".[dev]"
pytest
ruff check src tests

CI runs the same gate on Python 3.10–3.14 across Linux and Windows.

Versioning and stability

All ecosystem packages are pre-1.0: minor releases may change APIs, and every release is documented in CHANGELOG.md. Current per-package API stability is tracked at openactuarial.org/stability.html.

License

MIT — see LICENSE.

Release files for risksim 0.5.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for risksim 0.5.5
File Size Uploaded
risksim-0.5.5.tar.gz 32.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for risksim 0.5.5
File Interpreter ABI Platform
risksim-0.5.5-py3-none-any.whl Python 3 none any Details

Total release size: 50.6 kB

Release files / risksim-0.5.5.tar.gz

Download URL risksim-0.5.5.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
674a323be13b19d8a72cd701bc065e056eca69c804234bb7e797dd9719059c04
BLAKE2b-256 checksum
How to use checksums
8e8bebdd54911ba0b46b58a1fb42d5831d3405c847ae51229f3b061a4bde474c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release files / risksim-0.5.5-py3-none-any.whl

Download URL risksim-0.5.5-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6eadbc113eed41a34864bb2503f398bcaf85dd0f84ff7cc36600caa79dca6d8d
BLAKE2b-256 checksum
How to use checksums
4d1a29bfbc0664f6e74a62f0d4c594247d0ae5700b077920c891df4a87908e42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.5 This release

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page