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]))