actuarial

Define base class for actuarial math, with utility helpers and constants

MIT License. Copyright (c) 2022-2023 Terence Lim

class actuarialmath.actuarial.Actuarial[source]

Bases: object

Define constants and common utility functions

Constants:

VARIANCE : select variance as the statistical moment to calculate

WHOLE : indicates that term of insurance or annuity is Whole Life

VARIANCE = -2
WHOLE = -999
static isclose(r: float, target: float = 0.0, abs_tol=1e-06) bool[source]

Is close to zero or target value

Parameters:
  • r – value to test if close to zero or target

  • target – target value, default is 0.0

static integral(fun: Callable[[float], float], lower: float, upper: float) float[source]

Compute integral of the function between lower and upper limits

Parameters:
  • fun – function to integrate

  • upper – upper limit

  • lower – lower limit

static derivative(fun: Callable[[float], float], x: float) float[source]

Compute derivative of the function at a value

Parameters:
  • fun – function to compute derivative

  • x – value to compute derivative at

Examples

>>> print(Actuarial.derivative(fun=lambda x: x/50, x=25))
static solve(fun: Callable[[float], float], target: float, grid: float | Tuple | List, mad: bool = False) float[source]

Solve root, or parameter that minimizes absolute value, of a function

Parameters:
  • fun – function to compute output given input values

  • target – target value of function output

  • grid – initial range of guesses

  • root – whether to solve root (True), or minimize absolute function (False)

Returns:

value s.t. output of function fun(value) ~ target

Examples

>>> print(Actuarial.solve(fun=lambda omega: 1/omega,
>>>                       target=0.05, grid=[1, 100]))
add_term(t: int, n: int) int[source]

Add two terms, either term may be Whole Life

Parameters:
  • t – first term to add

  • n – second term to add

max_term(x: int, t: int, u: int = 0) int[source]

Decrease term t if adding deferral period u to (x) exceeds maxage

Parameters:
  • x – age

  • t – term of insurance or annuity, after deferral period

  • u – term deferred

Returns:

value of term t adjusted by deferral and maxage s.t. maxage not exceeded