insurance_simulation, a Python code which simulates a highly simplified model of term life insurance, in which a customer agrees to pay an annual fee for a given number of years, so that if the customer dies within that term, the family receives a large payout.

To simulate this process, it is necessary to estimate the chances that a person aged Y years will die before reaching the age of Y+1. This program makes a simple estimate of this process using some mortality data from 2007.

For testing, we might assume a person aged 25 agrees to pay $500 a year for 40 years, with a benefit (if dying before age 65) of $100,000. If this customer lives past age 65, no benefit at all will be paid.

As a side calculation, the program considers an alternative plan in which the same payments are put yearly into a bank account with four percent interest. Whether the customer dies early or later, this money would be available to the family.

The benefit of term life insurance is precisely to protect a family from cases in which the income earner dies unexpectedly early, leaving little or no savings to support the survivors.


The computer code and data files described and made available on this web page are distributed under the MIT license.


insurance_simulation is available in a MATLAB version and an Octave version and a Python version.

Related Data and codes:

python_simulation, a Python code which uses simulation to study card games, contests, and other processes which have a random element. Usually, the purpose is to try to predict the average behavior of the system over many trials.

Source Code:

Last revised on 10 February 2024.