Metadata-Version: 2.1
Name: heavylight
Version: 1.0.2
Summary: Heavylight Actuarial Modelling Framework
Project-URL: Homepage, https://github.com/lewisfogden/heavylight/
Project-URL: Bug Tracker, https://github.com/lewisfogden/heavylight/issues
Author-email: Lewis Fogden <lewisfogden@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Requires-Dist: pandas>=1.2
Description-Content-Type: text/markdown

# heavylight

A lightweight actuarial modelling framework for Python

- single script
- installation optional: package with your models.
- only depends on `pandas`

## Components

Model:
    - projection controller
    - class to subclass with your proprietary models
    - `BeforeRun` and `AfterRun` methods


Table:
    - simple long format table object
    - type information encoded via `|int`, `|float`, `|str` header suffixes


## Usage

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

```python
class Annuity(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
```

Define input data as a dictionary

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

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

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

display result as a pandas table

```python
model_cashflows = model.ToDataFrame()
```

Use numpy_financial or another package to calculate NPVs.

## Notes

### Projecting vs. discounting

 - 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.
 

