.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples\annuallife\plot_tradlife_a.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_annuallife_plot_tradlife_a.py: TradLife_A: cashflow ========================== Draw a graph of liability cashflows of a simple whole life policy projected by the :mod:`~annuallife` ``TradLife_A`` model. .. seealso:: * The :mod:`~annuallife` library .. GENERATED FROM PYTHON SOURCE LINES 11-42 .. image-sg:: /generated_examples/annuallife/images/sphx_glr_plot_tradlife_a_001.png :alt: Insurance Cashflows :srcset: /generated_examples/annuallife/images/sphx_glr_plot_tradlife_a_001.png :class: sphx-glr-single-img .. code-block:: Python import pandas as pd import modelx as mx import seaborn as sns sns.set_theme(style="darkgrid") # PolicyID 171 in simplelife corresponds to idx 170 (0-based array index) # in TradLife_A. idx = 170 proj = mx.read_model("TradLife_A").Projection[idx] # Draw NetCashflows Graph data = {'NetCashflows': [proj.net_cf[t] for t in range(50)]} ax = pd.DataFrame(data).plot.line(marker='o', color='r') # Draw components of net cashflows vars = ['premiums', 'claims_surr', 'claims_death', 'exps_maint', 'commissions', 'exps_acq'] for cells in vars: list(proj.cells[cells](t) for t in range(50)) df = proj.frame[vars].sort_index().dropna().droplevel(['x', 'y', 'basis']) df.index = df.index.astype(int) df[vars[1:]] = df[vars[1:]].mul(-1) # Change outflows to negatives df.plot(kind='bar', stacked=True, ax=ax, title='Insurance Cashflows') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.641 seconds) .. _sphx_glr_download_generated_examples_annuallife_plot_tradlife_a.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tradlife_a.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tradlife_a.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_tradlife_a.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_