Skip to main content

Heavylight Actuarial Modelling Framework

Project description

codecov

heavylight

A lightweight actuarial modelling framework for Python

  • single script
  • installation optional: package with your models.
  • only depends on pandas and numpy

Components

Model:

  • projection controller
  • class to subclass with your proprietary models
  • BeforeRun and AfterRun methods
  • get all values as a list with values attribute
  • get the sum of all values with sum() method

Table:

  • simple long format table object
  • type information encoded via |int, |int_bound, |band, |str header suffixes

Usage

Model Class

Create your model as a subclass of heavylight.Model. Each model variable is defined as a method:

import heavylight

class Annuity(heavylight.Model):
    def t(self, t):
        return t

    def expected_claim(self, t):
        return self.number_alive(t) * self.data["annuity_per_period"]

    def number_alive(self, t):
        if t == 0:
            return self.data["initial_policies"]
        else:
            return self.number_alive(t - 1) - self.deaths(t - 1)
    
    def deaths(self, t):
        return self.number_alive(t) * self.mortality_rate(t)

    def mortality_rate(self, t):
        return 0.02

    def v(self, t):
        """discount factor from time t to time 0"""
        if t == 0:
            return 1
        else:
            return self.v(t - 1) / (1 + self.forward_rate(t))
    
    def forward_rate(self, t):
        return 0.04

    def pv_expected_claim(self, t):
        return self.expected_claim(t) * self.v(t)

Define input data as a dictionary

policy_data = {
    "initial_policies": 10,
    "annuity_per_period": 55,
}

Call the model, passing in the data dictionary, with a projection length of 20.

model = Annuity(data = policy_data,
                do_run = True,
                proj_len = 20,
                )

Get the sum of pv_expected_claim:

print(model.pv_expected_claim.sum())

Display result as a pandas table

model_cashflows = model.ToDataFrame()

Notes

  • This package is designed for projecting actuarial variables, and calculates t=0, 1... in order.

  • Actuarial models are generally highly recursive.

  • If you create a method which refers to future t value (such as an NPV function) you may hit the python stack limit.

  • The recommended solution is to project forward first, and then calculate T0 metrics based on the result, for example using an `npv()`` function

Project details


Download files

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

Source Distribution

heavylight-1.0.10.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

heavylight-1.0.10-py3-none-any.whl (395.5 kB view details)

Uploaded Python 3

File details

Details for the file heavylight-1.0.10.tar.gz.

File metadata

  • Download URL: heavylight-1.0.10.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for heavylight-1.0.10.tar.gz
Algorithm Hash digest
SHA256 93f151ec2d961dd66b6878470e191636e1d799cf01caa1baf3a64015fef34f8b
MD5 dc63800207fbc69259195eed183feaf7
BLAKE2b-256 1b98c2a713de7b54eab4121558873285bffbae8c1b70ea003e9c8e14da90b49e

See more details on using hashes here.

File details

Details for the file heavylight-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for heavylight-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e25688cb9b3b11bf530fd75d5421a0423a1372e2a9aa25e04670fa11e0aa2ab7
MD5 0b70b280c42d627b527e5bf84e444da4
BLAKE2b-256 e83b7ea4cb2b9c37f4ea30a0dcf699ce17525f2a3ebab86dc8bf7a79f5651da7

See more details on using hashes here.

Supported by

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