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

  • PortfoliosPortfolio / PortfolioItem over any objects exposing .sample, with optional exposure weights.
  • Dependence — Iman–Conover rank correlation via risksim.dependence.impose_rank_correlation.
  • ContractsAggregateLayer, 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

risksim-0.5.3.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

risksim-0.5.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file risksim-0.5.3.tar.gz.

File metadata

  • Download URL: risksim-0.5.3.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for risksim-0.5.3.tar.gz
Algorithm Hash digest
SHA256 4ef4f5d6553e46651d3a2c75fa1be166814776b78c6d9e04c68facb9b950ef45
MD5 71b0f9c8c467164c22e41397e7c33f3d
BLAKE2b-256 a9704b3673fe07382b6d7f50d8fcc5712113a9d9ee9d3b9fc80a730a359b658a

See more details on using hashes here.

Provenance

The following attestation bundles were made for risksim-0.5.3.tar.gz:

Publisher: release.yml on OpenActuarial/risksim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file risksim-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: risksim-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for risksim-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70dd730914a12a2ed04d385aa80d1baa54bd0fef1032740cb8495f1d63af3d9d
MD5 2cb0fdbbd74aba77036dfba4b1826f4b
BLAKE2b-256 1f90cfd704b8c3b1d3adf26a2c87ee3081dc0c0fc7219da4fc351946a3c5240b

See more details on using hashes here.

Provenance

The following attestation bundles were made for risksim-0.5.3-py3-none-any.whl:

Publisher: release.yml on OpenActuarial/risksim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page