A framework for actuarial modelling.
pip install predictable
A model.py
file will be used to house the modelling logic which will be applied to each modelpoint.
# import the library
from predictable import CashFlow, DiscountFactors, Model, StaticCashFlow
# Create new model instance
model = Model()
# Add a premium component
model.add_component(
CashFlow(
input_array=[100], formula=lambda prev: prev * 1.05, label="premium"
)
)
# Add a sum assured component
model.add_component(CashFlow(label="cover", input_array=[1_000_000]))
# Add an expense component
model.add_component(
StaticCashFlow(
input_array=[10, 10, 10, 10, 10],
label="expense",
)
)
# Add discounting component
model.add_component(DiscountFactors(interest_rate=0.05, label="V"))
# Project cashflows over term
# Results return a pandas df object
df = model.project(term=10)
# Perform linear combination style manipulations
# Discounting the components
components = ["premium", "cover", "expense"]
for component in components:
df[f"V_{component}"] = df[component] * df["V"]
# Define reserving relationship
df["Reserve"] = df["V_cover"] + df["V_expense"] - df["V_premium"]
# Results get returned as a pandas dataframe
print(df)
This project is documented using sphinx and the full documentation can be found at predictable.readthedocs.io.
The following steps can be followed to set up a development environment.
-
Clone the project:
git clone https://github.com/RatulMaharaj/predictable.git cd predictable
-
Install hatch
pipx install hatch
-
Enter the default environment (this will activate the default virtual environment and install the project in editable mode).
hatch shell default
This project uses pytest
for testing purposes. The tests can be found in the tests
directory. Tests will run after every commit (locally) and on every push (using github actions) but can also be run manually using:
hatch run test
This project is linted using ruff
and formatted with black
. The linting and formatting can be run manually using:
hatch run lint
hatch run format
The documentation for this project can be found in the docs
directory. The documentation is created using mkdocs and can be viewed locally using:
hatch run docs:serve
The docs can also be built for deployment using:
hatch run docs:build