{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "To run this sample, from the *Cell* menu above, click *Run All*." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "\"\"\"\n", ":mod:`simplelife` cashflow\n", "==========================\n", "\n", "Draw a graph of liability cashflows of a simple whole life policy\n", "\n", "*Run this sample now!* |binder simplelife_demo|\n", "\n", ".. include:: /binderlinks.rst\n", " :start-after: Begin binder simplelife_demo\n", " :end-before: End binder simplelife_demo\n", "\n", "\"\"\"\n", "import os\n", "import modelx as mx\n", "import pandas as pd\n", "import seaborn as sns\n", "sns.set()\n", "\n", "polid = 171\n", "proj = mx.read_model('model').Projection[polid]\n", "\n", "# %% Draw NetCashflows Graph\n", "data = {'NetCashflows': [proj.NetInsurCF[t] for t in range(50)]}\n", "ax = pd.DataFrame(data).plot.line(marker='o', color='r')\n", "\n", "# %% Draw componets of net cashflows\n", "\n", "vars = ['PremIncome',\n", " 'BenefitSurr',\n", " 'BenefitDeath',\n", " 'ExpsMaint',\n", " 'ExpsCommTotal',\n", " 'ExpsAcq']\n", "\n", "\n", "df = proj.cells[vars].to_frame(range(50))\n", "\n", "df[vars[1:]] = df[vars[1:]].mul(-1) # Change outflows to negatives\n", "df.plot(kind='bar', stacked=True, ax=ax, title='Insurance Cashflows')" ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "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 }