Heavylight Actuarial Modelling Framework
Project description
heavylight
A lightweight actuarial modelling framework for Python
- single script
- installation optional: package with your models.
- only depends on
pandas
andnumpy
Components
Model:
- projection controller
- class to subclass with your proprietary models
BeforeRun
andAfterRun
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file heavylight-1.0.9.tar.gz
.
File metadata
- Download URL: heavylight-1.0.9.tar.gz
- Upload date:
- Size: 2.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd729f0b68923f8b094c1583e777fc8ee42128701e790d1313efd0fbb9bedae8 |
|
MD5 | 961599caedaad4abdc2026e79cd59075 |
|
BLAKE2b-256 | f5a685646f1feee47faf4957218dd69ce5b1f88437d216ef6b03d2a8e22a08cc |
File details
Details for the file heavylight-1.0.9-py3-none-any.whl
.
File metadata
- Download URL: heavylight-1.0.9-py3-none-any.whl
- Upload date:
- Size: 395.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61975683ada45152697bf2297165750a760f941867d3f22ec86c1a915048c834 |
|
MD5 | a656b90c69f589c84d83aa38301f9adf |
|
BLAKE2b-256 | bbc983f8133c47df1c9f8fcae6c15f9a6500cf97d280e86fb395e6571c1c53df |