Giter Site home page Giter Site logo

lifelib-dev / lifelib Goto Github PK

View Code? Open in Web Editor NEW
141.0 20.0 42.0 31.21 MB

Python package of actuarial models, tools, examples and learning materials.

Home Page: https://lifelib.io

License: MIT License

Python 14.24% Makefile 0.01% Batchfile 0.02% HTML 0.02% Jupyter Notebook 85.69% CSS 0.03%
python actuarial actuary quantitative-finance risk-management

lifelib's People

Contributors

declann avatar fumitoh avatar matthewcaseres avatar open-source-modelling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lifelib's Issues

About providing excel template for the project

Hi, i am a new university graduate for ACT and am quite new to github and python and I really like your project. Do you need an Excel spreadsheet to simulate what is going on in your Python project? This can facilitate checking and help those new to python to better understand the material of your project. If you think this idea is good, I can do the excel spreadsheet.

Spyder plugin breaks Spyder on Anaconda

I installed lifelib using conda and started up Spyder without a problem. Then I installed the Spyder plugin using conda, and Spyder initiates but doesn't complete the startup. I am using Spyder 5.4.2 under Python 3.11. I was able to capture the error messages which are below. When I uninstall the plugin, it works again. Any suggestions?

modelx_plugin: cannot import name 'PY2' from 'spyder.py3compat' (C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\py3compat.py)
Traceback (most recent call last):
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\find_plugins.py", line 67, in find_external_plugins
mod = importlib.import_module(entry_point.module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1128, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1128, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in load_unlocked
File "", line 940, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx_init
.py", line 25, in
from .plugins.mxplugin import ModelxPlugin
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxplugin.py", line 51, in
from .mxplugin_5_3 import ModelxPlugin_5_3 as ModelxPlugin
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxplugin_5_3.py", line 5, in
from .mxconsole_5_3 import MxConsoleAPI_5_3
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxconsole_5_3.py", line 14, in
from spyder.py3compat import is_string, PY2, to_text_string
ImportError: cannot import name 'PY2' from 'spyder.py3compat' (C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\py3compat.py)
mxdataviewer: cannot import name 'PY2' from 'spyder.py3compat' (C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\py3compat.py)
Traceback (most recent call last):
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\find_plugins.py", line 67, in find_external_plugins
mod = importlib.import_module(entry_point.module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1149, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in call_with_frames_removed
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\dataview_plugin.py", line 63, in
from spyder_modelx.widgets.mxdataviewer.dataframeviewer import MxDataFrameViewer
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx_init
.py", line 25, in
from .plugins.mxplugin import ModelxPlugin
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxplugin.py", line 51, in
from .mxplugin_5_3 import ModelxPlugin_5_3 as ModelxPlugin
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxplugin_5_3.py", line 5, in
from .mxconsole_5_3 import MxConsoleAPI_5_3
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\mxconsole_5_3.py", line 14, in
from spyder.py3compat import is_string, PY2, to_text_string
ImportError: cannot import name 'PY2' from 'spyder.py3compat' (C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\py3compat.py)
: Plugin "modelx_plugin" not found!
Traceback (most recent call last):
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\mainwindow.py", line 796, in setup
plugin_instance = PLUGIN_REGISTRY.register_plugin(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\api\plugin_registration\registry.py", line 342, in register_plugin
instance = self._instantiate_spyder5_plugin(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\api\plugin_registration\registry.py", line 193, in _instantiate_spyder5_plugin
plugin_instance.initialize()
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\api\plugins\new_api.py", line 679, in initialize
self.on_initialize()
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder_modelx\plugins\analyzer_plugin.py", line 194, in on_initialize
self.get_plugin('modelx_plugin').get_container().set_child_plugin('analyzer', self.get_container())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\api\plugins\new_api.py", line 442, in get_plugin
raise e
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\api\plugins\new_api.py", line 437, in get_plugin
return self._main.get_plugin(plugin_name, error=error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\mainwindow.py", line 356, in get_plugin
raise SpyderAPIError(f'Plugin "{plugin_name}" not found!')
spyder.api.exceptions.SpyderAPIError: Plugin "modelx_plugin" not found!
Traceback (most recent call last):
File "C:\Users\sunil\anaconda3\envs\LifeLib\Scripts\spyder-script.py", line 10, in
sys.exit(main())
^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\start.py", line 257, in main
mainwindow.main(options, args)
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\mainwindow.py", line 1823, in main
mainwindow = create_window(MainWindow, app, splash, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\utils.py", line 300, in create_window
main.post_visible_setup()
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\app\mainwindow.py", line 1013, in post_visible_setup
self.layouts.on_mainwindow_visible()
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\plugins\layout\plugin.py", line 203, in on_mainwindow_visible
self.create_plugins_menu()
File "C:\Users\sunil\anaconda3\envs\LifeLib\Lib\site-packages\spyder\plugins\layout\plugin.py", line 908, in create_plugins_menu
action.setChecked(plugin.dockwidget.isVisible())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'isVisible'

Discussion about Abstract concepts about Lifelib 19/2/2019

I have tried to read your tutorial about modelx and understood the basic concepts. The following are some recommendations about how to present the (actuarial) model in a more organized and nicer way. I dont know if they are good ideas or can be compatible with modelx though (I think you have mentioned similar ideas in your introduction to lifelib and your example in modelx, but you dont explicitly state them in much detail).

I find that for every time series variable (those with parameter t), its concept can be a combination of several other conceptual "classes". For example,
ExpsCommInit's concept is actually a combination of 2 "classes"

  1. Negative->Expenses->Commission
  2. Event: Init
    For the first class(actually a sequence of classes, which can be views as subsets of one another), this variable is a part of commission, which is a kind of expense, which may be considered as "negative"
    For the second class, "Init" indicates that the variable should be charged at the beginning of the policy term. "Event" is a special class, which is comprised of 2 parts: 1) when will the event occurs 2) what is the probability of the event. "Event" include surrender/ death/ beginning of the policy term/ beginning of every survival period) etc. The default event should be the event of survival. Including concepts like "Event" is beneficial for changing between deterministic and stochastic scenarios.

Another example is ExpsCommTotal, it only contains 1 class

  1. Negative->Expense->Commission ------------Total
    "Total" should be a special name tag for the variable. Any other variable with class "Negative->Expense->Commission-> any other smaller classes" should be thought of "sons" of this variable. You can also say they "inherited" from this variable. (The concept of "inherit" here may be different from that in modelx documentation, about cells or spaces)

Many other variables may be different combination of many different classes (as opposed to your concept about a cell cannot be contained from 2 spaces). For example, some variables specific to certain accounting principles should have extra 1 "class" related to that accounting principle.

The nice thing about adding these concept of "classes" or "name tags" or whatever, is that it is good for "slicing of concepts". If I want to review all the variables about the event "surrender" I can choose the name tag (or class) "surrender", starting from the top (with total name tag), I can review several tree structures about it. It is even good for designing different products quickly. To change a critical illness to simple life, I can "uncheck" all the variables related to "hospital" and "illness".

It may be possible to write a python script to produce the different python projects for different user-defined products. The python script has the ability to change all the variable unnecessary to commented segment(which has the same effect as deleting the variable, but clearer). The good thing about this is, the actuary will not be confused with many useless variables. The bad thing about this is, If we want to evaluate the aggregate level variable across different products, we have to run different scripts for different products.

As I am not an experienced actuary, many of the above ideas may be useless or even bad. Feel free to comment though. Thanks.

Lifelib on Python 3.10

Hi Team,

I am not able to import Lifelib package on Python 3.10. I am able to install lifelib from command prompt and use it in Anaconda. Could anayone please help me to import this package on python. Is there any documentation available?

Regards
Shubham Goel

Problems about simplelife project (19/2/2019)

Hi, the following are the issues I have encountered. There are 3 types of issues.

  1. Problems: those I think are errors.
  2. improvements: those that may be improved.
  3. Inquiries: those that I dont understand.

1 Problems:
1.1. In projection.py, there is a variable called SizeExpsCommInit, which includes CnsmpTax. SizeExpsCommInit is included in ExpsTotal, which is included in ProfitBefTax. But by definition, ProfitBefTax should be something before tax.

2 Improvements:
2.1. in assumption.py, there is a variable called ExpsMaintAnnPrem, but the variable name in input.xlsx is ExpsMaintPrem. It is better to be consistent.
2.2. (already mentioned in the python script) in lifetable.py, the calculation for actuarial symbols should stop until last age but not 110.

3 Inquiries:
3.1. in policy.py, why for NetPremRate, several calculations of AnnDuenx all assumes payment frequency is 1, instead of 12(actual frequency). Is this the definition?
3.2. in policy.py, for NetPremRate->AnnDuenx, what does "m" means (compared to "n")? I find that you set both m and n to policy term.
3.3. I dont know how to find out the "RateBasis" of the policy. I assume it is "PREM"
3.4. for economic py, what is the difference between DiscRate and InvstRetRate? I guess DiscRate is related to CF and InvstRetRate is related to profit.
3.5.for projection.py, what is the difference between SizeReservePremRsrvAftMat and SizeReservePremRsrvEnd? why SizeInvstIncome uses SizeReservePremRsrvAftMat but not SizeReservePremRsrvEnd?
3.6. What does "Gen" stands for?
3.7. in input.xlsx, AssumptionTables tab contain a column called LapseRate1. I use that column for surrender rate. The problem is that column only contain 20 years' data. Therefore, my results will contain many errors after 20 years. How is the real logic in the python project going on here?
3.8. For my "checking.xlsx" file. I want to generate all the variables from projection.py and then compare them with my results obtained in "calculation.xlsm". What I currently do is to run "plot_simplelife.py", then run "df=proj.to_frame()". df here only contain fifty-something variables, not the eighty-something variables listed in "projection.py".

Simplelife.build() error with latest Modelx version

Hi,

I updated modelx to the latest version and tried to incorporate the new "new_excel_range" method and was getting errors. I resorted to rerunning the basic Simplelife project I had (which previously worked) that now gives an error
"File "C:\Demosthenis_PythonRelated_Anaconda\lib\site-packages\modelx\core\base.py", line 419, in new
raise ValueError("Invalid direct constructor call.")"
lifelib version = '0.0.14'
modelx version = '0.9.0'

Here are the order of the commands (with output):

import simplelife
model = simplelife.build()

Traceback (most recent call last):

  File "<ipython-input-102-f7600826e8fb>", line 1, in <module>
    model = simplelife.build()

  File "C:\Demosthenis\_PythonRelated\ModelX\LifeLib\mylife\simplelife.py", line 37, in build
    model = mx.new_model(name='simplelife')

  File "C:\Demosthenis\_PythonRelated\_Anaconda\lib\site-packages\modelx\core\api.py", line 101, in new_model
    """

  File "C:\Demosthenis\_PythonRelated\_Anaconda\lib\site-packages\modelx\core\system.py", line 489, in new_model
    self.currentmodel = ModelImpl(system=self, name=name)

  File "C:\Demosthenis\_PythonRelated\_Anaconda\lib\site-packages\modelx\core\model.py", line 362, in __init__
    Impl.__init__(self, system=system, parent=None, name=name)

  File "C:\Demosthenis\_PythonRelated\_Anaconda\lib\site-packages\modelx\core\base.py", line 202, in __init__
    self.interface = self.interface_cls(self)

  File "C:\Demosthenis\_PythonRelated\_Anaconda\lib\site-packages\modelx\core\base.py", line 419, in __new__
    raise ValueError("Invalid direct constructor call.")

ValueError: Invalid direct constructor call.


import lifelib

lifelib.__version__
Out[104]: '0.0.14'

mx.__version__
Out[105]: '0.9.0'

Reading "simplelife.mx" file

Hi Fumito,

I copied the simplelife project.
I see all the various *.py files that seem to be mainly the various UserSpaces.

  • How are these "triggering" a new UserSpace to be created (I cannot pin point the command in them for this)? I was expecting to see something like space="" or mx.new_space() or something like that...

  • How can we read the simplelife.mx file? Is this where the "coming together" of the various spaces takes place?

Thanks,
Demosthenis

Using Spyder plugin (Reading a Model)

Hello everyone, after I created a copy of a lifelib project from Spyder’s IPython console using lifelib.create function, and a new folder is created.
in Reading a Model
The project folder I just created doesn't contain a model folder named model, like what they said, and hence I cannot read The model from the model folder into a live IPython session.

please any help

How to Install this package in Linux Mint

Hi Team,

I am new to python. I am not able to instal this package in my linux mint. Could you please help me to install this package. Is there any document available.

Please help me.

Regards
Ranga

TypeError when building the simplelife model

Hi,
Thanks for releasing this code. I am enjoying going through it and am learning a lot.
Whenever I follow the instructions on the website for "Building a Model" using the Spyder plugin I get an error. I have attempted to debug however I am only beginning to learn python and have not had much luck.
The error message is as below.

File "C:\Users\Local Administrator\Anaconda3\lib\site-packages\modelx\core\space.py", line 1237, in new_cells_from_excel

sig = "=None, ".join(cellstable.param_names) + "=None"

TypeError: sequence item 0: expected str instance, NoneType found

Thanks,
ro-co

Creating an EV Model

Hi Fumitoh

I am trying to create an EV projection model using modelx. Probably something that might be useful to package into lifelib in the future and so asking my query here.

Just as an example and also for my own learning, I started creating a model to calculate the PVFP (Present Value of Future Profits) for a simple Term product. Here is all my current coding to re-create the Model.

The setup is pretty basic. It contains a single "new business" model point with a policy term of 20 years and modelling is done at annual time steps. It comprises of the following spaces:

  • a Life space to calculate probabilities
  • a Term_Life space to calculate the Best Estimate cash flows. Currently I have just modelled premiums and death outgo. This space inherits from Life space.
  • a Term_Life_Res space to calculate the reserves using more prudent assumptions. This space inherits from Term_Life space.

As a final step, I want to compute the profit for each year and then discount the profit stream to get to PVFP. However, for this I need:

  • the premiums and death outgo to come from the Term_Life layer, and
  • the increase in reserve to be based on per-policy reserve from the Term_Life_Res layer but then rebased for the BE probabilities

At this stage I am stuck and can't think of a way to call some values from the Term_Life layer and some from the Term_Life_Res layer to get to my profit vector. Any suggestions on how this can be achieved? Happy to discuss further if anything is unclear.

Regards
Kaustav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.