Um agrupamento de calculos atuariais
Project description
NumberCommutation
Pyrisky is an easy-to-use python library for actuarial calculations, focused on mortality tables and annuity calculations.Date: 2024-02-12
Version: 0.0.3
Author: Pedro Cavalcante
Introduction
NumberCommutation is an open library written in Python for calculating annuities and actuarial tables, based on methodologies commonly used among Brazilian actuaries.
This library consists of only one file module and has dependencies on the Pandas and Numpy libraries.
Installation
Once Pyhon is running, just install this library with pip install NumberCommutation
Quick Start
The import process boils down to the command from NumberCommutation import Pyrisky
The names of functions and variables follow the Actuarial Notation of switching numbers: lx, dx, qx, px, Lx, Tx, Ex, Dx, Nx, Cx, Mx, Sx, äx, ax.
The functions created were as follows:
To create a complete mortality table we have AllTable():
-
lx= The actuarial table used to estimate the number of people alive at age X. -
taxa= interest rate in one year.
The idade_inicio variable can be omitted, in this case it will be 0 by default. It indicates the age at which lx begins.
This formula must include at least 2 variables: lx and taxa If necessary, the idade_inicio variable must be included if the informed lx does not start at age 0.
There is also a way to calculate an individual commutation number at a specific age x, through Commutation():
-
idade= Series of data referring to age(x) according to the probability data entered. -
dados= Data series referring to probabilistic survival or death data
The variable data_type defaults to 'q', indicating that the data are probabilities of death (qx). However, this variable accepts three more arguments: 'p' (px), 'd' (dx) and 'l' (lx).
There is also the variable amostra, which defaults to 1000000. Indicating the radix of the sample or the initial number of people at age 0.
That said, we have the switching functions that come with Commutation:
Those that only need to inform the age (X) sought are:
lx = Number of living people aged x px = A person's probability of survival aged 𝑥 before reaching age 𝑥 + 1. qx = Probability of death of a person aged 𝑥 before of reaching the age of 𝑥 + 1 years. dx = Number of people who died between ages 𝑥 and 𝑥 + 1. Lx = Time lived in the age range 𝑥 to 𝑥 + 1 (amount of person-years between ages 𝑥 and 𝑥 + 1). Tx = Time lived from age 𝑥 (number of person-years to from age 𝑥). ex = Average number of years someone of x age should live.
And those that only need to inform the age (X) and the interest rate sought are:
Dx = Indicates how many individuals from a given cohort (group of people) will survive from age x to age x + n, where n is the age range. Nx = The expected number of deaths between age x and age x + 1. Cx = The remaining life expectancy of a person who has already reached age x. Mx = Represents the probability that a person of exactly x years of age will die before reaching the next oldest age, that is, the probability that a person will die during the interval of one year.
Example 1: Print the complete mortality table. Based on the lx of the BR-EMSsb-2021-m table and an interest rate of 5%:
from NumberCommutation import Pyrisky
import pandas as pd
# To download the table go to: https://www.gov.br/susep/pt-br/assuntos/informacoes-ao-mercado/informacoes-tecnicas-e-planos-padroes/tabuas-biometricas-br-ems
Tabua = pd.read_excel("tabuas-br-ems-2010-2015-2021-010721.xlsx", sheet_name = "BR-EMSsb-2021-m ",skiprows=5)
print(TableAnnuity(Tabua["lx"],0.05).AllTable())
Example 2: Calculating the Time lived in the age range of 10 to 11 years and the Time lived from age 10 onwards:
from NumberCommutation import Pyrisky
import pandas as pd
# To download the table go to: https://www.gov.br/susep/pt-br/assuntos/informacoes-ao-mercado/informacoes-tecnicas-e-planos-padroes/tabuas-biometricas-br-ems
Tabua = pd.read_excel("tabuas-br-ems-2010-2015-2021-010721.xlsx", sheet_name = "BR-EMSsb-2021-m ",skiprows=5)
print(Comutation(Tabua["Idade"], Tabua["qx"], data_type='q').Lx(10))
print(Comutation(Tabua["Idade"], Tabua["lx"], data_type='l').Tx(10))
Example 3:: Calculating the expected number of deaths between age 10 and age 11 years old, at a rate of 5%::
from NumberCommutation import Pyrisky
import pandas as pd
# To download the table go to: https://www.gov.br/susep/pt-br/assuntos/informacoes-ao-mercado/informacoes-tecnicas-e-planos-padroes/tabuas-biometricas-br-ems
Tabua = pd.read_excel("tabuas-br-ems-2010-2015-2021-010721.xlsx", sheet_name = "BR-EMSsb-2021-m ",skiprows=5)
print(Comutation(Tabua["Idade"],1 - Tabua["qx"], data_type='p').Nx(10, 0.05))
Requeriments
It can be used in both Python versions 2.7 and 3.6. Pylirisky has dependencies on the Pandas and Numpy Libraries.
Contributions
Any comments, suggestions or improvements are very welcome.
For this purpose, I remain at your disposal through my email: ph.cavalcante29@gmail.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file NumberCommutation-0.0.3.tar.gz.
File metadata
- Download URL: NumberCommutation-0.0.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16d90ab011f68280378431d467e3ead72028fc6f168e23ba34996e64aa1f6236
|
|
| MD5 |
e58327687f0b31726073a5bd826f88cf
|
|
| BLAKE2b-256 |
7fdd6eaf89e2ac3af3c5ecccf5f4b9268dfd186f531be554b004bfdc2598ad9f
|
File details
Details for the file NumberCommutation-0.0.3-py3-none-any.whl.
File metadata
- Download URL: NumberCommutation-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bf936de0ce895b640dd5491e28e068c30f30a7d637d6f02a57f1f22dc0d41e2
|
|
| MD5 |
255bf31c83d09b166e7cd44145a36abb
|
|
| BLAKE2b-256 |
dc6fde5952f030d8422312aa47e6043d88de01140675f783c39fb14d4ddb5f07
|