{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IFRS17 CSM Waterfall Chart Notebook\n", "To run this notebook and get all the outputs below, Go to the **Cell** menu above, and then click **Run All**.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## About this notebook\n", "\n", "This noteook demonstrates the usage of [ifrs17sim] project in [lifelib], by building and running a model and drawing a waterfall graph of CSM amortization on a single modelpoint.\n", "\n", "\n", "[ifrs17sim]: https://lifelib.io/projects/ifrs17sim.html\n", "[lifelib]: https://lifelib.io\n", "\n", "
\n", "\n", "**Warning:**\n", "\n", "The primary purpose of this model is to showcase the capability of [lifelib] and its base system [modelx], and less attention has been paid to the accuracy of the model or the compliance with the accounting standards. \n", "At very least, following items are identified as over-simplification or lack of implementation.\n", "\n", "\n", "\n", "
\n", "\n", "[modelx]: http://docs.modelx.io" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to use Jupyter Notebook\n", "Jupter notebook enables you to run a Python script piece by piece. You can run each piece of code (called a \"cell\") by putting the cursor in the cell and pressing **Shift + Enter**, and get the output right below the input code of the cell.\n", "\n", "If you want to learn more about Jupyter Notebook, [this tutorial] will help you. There are also plenty of other resources on the internet as Jupyter Notebook is quite popular.\n", "\n", "[this tutorial]: https://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Running%20Code.ipynb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The entire script\n", "Below is the entire script of this example. The enire scipt is broken down to several parts in differenc cells, and each part is explained below. The pieces of code in cells below are executable one after another from the top.\n", "\n", "```python\n", "%matplotlib notebook\n", "import collections\n", "import pandas as pd\n", "from draw_charts import draw_waterfall, get_waterfalldata\n", "import modelx as mx\n", "\n", "model = mx.read_model(\"model\")\n", "proj = model.OuterProj[1]\n", "\n", "df = get_waterfalldata(\n", " proj,\n", " items=['CSM',\n", " 'IntAccrCSM',\n", " 'AdjCSM_FlufCF',\n", " 'TransServices'],\n", " length=15,\n", " reverseitems=['TransServices'])\n", "\n", "draw_waterfall(df)\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initial set-up\n", "\n", "The first line `%matplotlib notebook`, is for specifying drawing mode.\n", "\n", "The next few lines are import statements, by which functions defined in other modules become avaialbe in this script.\n", "\n", "`ifrs17sim` and `draw_charts` modules are in the project directory of this project. To see what fiels are in the project directory, select **Open** from the **File** menu in the tool bar above." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbsphinx": "hidden" }, "outputs": [], "source": [ "%matplotlib inline\n", "import collections\n", "import pandas as pd\n", "from lifelib.projects.ifrs17sim.draw_charts import draw_waterfall, get_waterfalldata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Building the model\n", "\n", "The next line is to create a model from `build` function defined in `ifrs17sim` module which has just been imported. \n", "\n", "By supplying `True` to `load_saved` parameter of the `build` function, the input data is read from `ifrs17sim.mx`, the 'pickled' file to save loading time. To read input from `input.xlsm`, call `build` with `load_saved=False` or without any parameter because `False` is the default value of `load_saved`. \n", "\n", "If you run this code multiple time, the previous model is renamed to `ifrs17sim_BAK*`, and a new model is created and returned as `model`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import modelx as mx\n", "model = mx.read_model(\"model\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To see what space is inside `model`, execute `model.spaces` in an empty cell.\n", "```python\n", "model.spaces\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculating CSM\n", "\n", "In `model` thre is a space called `OuterProj` and other spaces. `OuterProj` is parametrized by Policy ID, i.e. each of the spaces with parameters corresponds to a projection of one policy. For example, `model.OuterProj[1]` return the projection of policy ID 1, `model.OuterProj[171]` return the projection of policy ID 171.\n", "\n", "The first line below sets `proj` as a shorthand for the projection of Policy ID 1. To see what cells are in `proj`, execute `proj.cells` in an empty cell. \n", "```python\n", "proj.cells\n", "```\n", "\n", "You can change the sample policy to output by supplying some other ID." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "proj = model.OuterProj[1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exporting values into DataFrame\n", "\n", "The code below is to construct a DataFrame object for drawing the waterfall chart, from the cells that make up bars in the waterfall chart.\n", "\n", "`TransServices` is passed to `reverseitems` parameter, to reverse the sign of its values, as we want to draw is as reduction that pushes down the CSM balance." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = get_waterfalldata(\n", " proj,\n", " items=['CSM',\n", " 'IntAccrCSM',\n", " 'AdjCSM_FlufCF',\n", " 'TransServices'],\n", " length=15,\n", " reverseitems=['TransServices'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tha table below show the DataFrame values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Draw waterfall chart\n", "\n", "The last line is to draw the waterfall graph. The function to draw the graph was imported from the separate module `draw_charts` in this project directory, and was imported at the first part of this script." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "draw_waterfall(df)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }