[PYTHON] I made a library for actuarial science

Introduction

It's a certain virus, it seems that moss will grow on my body soon because I refrain from going out ... By the way, I was studying for an actuary exam recently, and I thought, "By the way, I wonder if Python has a library for actuarial science," so I made it because it didn't seem like I was googled.

Development motive

・ To deepen understanding of actuarial science. ・ To simplify numerical calculations using actuarial science. ・ I've never given my own library to PyPI in Python, so let's try it. ・ ~~ I was free ~~

Installation

Installation is possible with pip

pip install amaryllis

How to use

Calculate the expected value of insurance premiums. It implements each type of insurance algorithm, but the function arguments are different.

i :Annual interest rate,The default value is 0.03
x :The insured's age at the time of the insurance contract,The default value is 30
n :Insurance contract period,The default value is 20
f :Deferment period,The default value is 10
lifespan :Last age,The default value is 112
population :Surviving population from 0 to final age, default value is the 20th example life table(Man)Created with reference to.
Note that it is not actual data

It has become.

sample

① Present value of life pension (amaryllis.models.pension)

>>> from amaryllis.models.pension import *
>>> import numpy as np
>>> population = np.array([100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0])
>>> x = 0
>>> n = 3
>>> lifespan = 10
>>> f = 0
>>> a = life_annuity(population=population, x=x, n=n, f=f, lifespan=lifespan)
>>> print("a = {}".format(a))
a = 2.6278631350739943

② Present value of one-time premium (amaryllis.models.single)

>>> from amaryllis.models.single import *
>>> import numpy as np
>>> population = np.array([100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0])
>>> i = 0.03
>>> x = 0
>>> n = 3
>>> f = 1
>>> lifespan = 10
>>> A = single_term_insurance(i=i, population=population, x=x, n=n, f=f, lifespan=lifespan)
>>> print("A = {}".format(A))
A = 0.2746224616402602

Since each insurance is implemented by type, see github (https://github.com/yk-amarly-20/Amaryllis) for detailed function documentation.

in conclusion

I haven't implemented much of the content related to survival time analysis, so I plan to implement it from now on. Also, all the documents in the function are still in Japanese, so I have to change it to English (~~ troublesome ~~)

Recommended Posts

I made a library for actuarial science
I made a Python wrapper library for docomo image recognition API.
〇✕ I made a game
I made a python dictionary file for Neocomplete
I made a spare2 cheaper algorithm for uWSGI
I made a useful tool for Digital Ocean
I made a peeping prevention product for telework.
[Updated Ver1.3.1] I made a data preprocessing library DataLiner for machine learning.
I made a user management tool for Let's Chat
I made a library to separate Japanese sentences nicely
I made a window for Log output with Tkinter
I made a cleaning tool for Google Container Registry
I made a VM that runs OpenCV for Python
[Python] I made a classifier for irises [Machine learning]
I made a python text
Made a command for FizzBuzz
I made a python library to do rolling rank
I made a discord bot
[VSCode] I made a user snippet for Python print f-string
I made a resource monitor for Raspberry Pi with a spreadsheet
I made a learning kit for word2vec / doc2vec / GloVe / fastText
I made a face diagnosis AI for a female professional golfer ③
I made a C ++ learning site
I touched PyAutoIt for a moment
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
I made my own Python library
I made a fortune with Python.
I made a CUI-based translation script
I made a daemon with Python
I made a library to easily read config files with Python
Python> I made a test code for my own external file
I made a client / server CLI tool for WebSocket (like Netcat for WebSocket)
I made a lot of files for RDP connection with Python
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
I made a scaffolding tool for the Python web framework Bottle
I made a library that adds docstring to a Python stub file.
I made a new AWS S3 bucket
I made a payroll program in Python!
I touched "Orator" so I made a note
I made an alternative module for japandas.DataReader
Beginner: I made a launcher using dictionary
I made a conversation partner like Siri
I made a script to display emoji
I made a Hex map with Python
I made a stamp generator with GAN
I made a browser automatic stamping tool.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a WEB application with Django
A textbook for beginners made by Python beginners
I made a neuron simulator with Python
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
I made a library konoha that switches the tokenizer to a nice feeling
I made a stamp substitute bot with line
I checked the library for using the Gracenote API
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5