heavylight
A lightweight actuarial modelling framework for Python
- single script
- installation optional: package with your models.
- only depends on
pandasandnumpy
Components
Model:
- projection controller
- class to subclass with your proprietary models
BeforeRunandAfterRunmethods- get all values as a list with
valuesattribute - get the sum of all values with
sum()method
Table:
- simple long format table object
- type information encoded via
|int,|int_bound,|band,|strheader 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
Metadata
Release files for heavylight 1.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| heavylight-1.0.11.tar.gz | 2.4 MB | Without provenance | Details for heavylight-1.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| heavylight-1.0.11-py3-none-any.whl | Python 3 | none | any | Details for heavylight-1.0.11-py3-none-any.whl |
Total release size: 2.8 MB
Release files / heavylight-1.0.11.tar.gz
| Download URL | heavylight-1.0.11.tar.gz |
|---|---|
| Size | 2.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d5612059e03ab5e108b2ad11804e74e885f7d7b4e28221a763f35ef36f37ed9
|
|
BLAKE2b-256 checksum How to use checksums |
b5352d0e4415cede5cd39422740f991e7dfc1f0377f0518a88c8589a87d771f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Release files / heavylight-1.0.11-py3-none-any.whl
| Download URL | heavylight-1.0.11-py3-none-any.whl |
|---|---|
| Size | 395.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bee036340f2aa79896565ce0845f5fc7fff344239e1489397b337477dc06e632
|
|
BLAKE2b-256 checksum How to use checksums |
6d3a92a1e9c14adcea2bf0e95c3f788f97c54a08551862d522c0c235aac75777
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Security for heavylight 1.0.11
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.