Building Actuarial Functions in Python

Building Actuarial Functions in Python

In college, I studied Actuarial Science. When I graduated I decided to learn more about data science and programming as I had always been interested in computer science. Soon after I began studying data science at the Flatiron School, I wrote a blog about the potential overlap between these two studies of actuarial science and data science (Actuarial Science and Data Science with LifeLib).

Having finished my educational program a few weeks ago, I set out to begin creating an actuarial library for Python. In theory, this will eventually be available to all data scientists and actuaries and will work to bridge the gap between actuarial science and programming. I believe these applications can significantly increase an actuary’s productivity and efficiency.

Financial Mathematics

These concepts learned for the FM Exam serves as a foundation for a lot of the more advanced material in actuarial science. The BAII-Plus calculator is often used on later exams such as the Long Term Actuarial Mathematics Exam. While these Python tools will not be available during the sitting of the exams, once an actuary is in the field, utilizing computing power in order to automate and speed up calculations can be immensely valuable.

Creating a Financial Mathematics Calculator in Python

First, I started with the basics. Accumulation and Discount.

In order to accumulate a payment n years ahead at an interest rate of i, the payment must be multiplied by the accumulation factor, (1+i)ⁿ.

In order to discount a payment back n years at an interest rate of i, the payment must be multiplied by the discount factor, v=(1+i)⁻ⁿ, or divided by the accumulation factor. (v=1/(1+i)).

Next, I needed to create functions for annuities.

In actuarial science, there are formulas for annuities immediate and annuities due.

An annuity immediate has payments that start on year 1, or one interest period after the annuity started.

Annuity Immediate Visualization by Mackenzie Mitchell

An annuity due has payments that start the same year or time that the annuity begins at year 0.

Annuity Due Visualization by Mackenzie Mitchell

These annuity formulas can help us to find any unknown in an annuity problem. In the calculator file I mainly use these annuity functions to help solve for unknown payment amounts. While I could have also utilized these formulas for present value and future value calculations, I decided to take a more intuitive programming approach in iteration through each discount/accumulation and summing the discounts or accumulations together. I have not yet thought of a better way to solve for unknown payments without the use of annuity formulas.

Starting the Calculator

  1. How much money must you deposit now at 6% interest compounded quarterly in order to be able to withdraw $3,000 at the end of each quarter year for two years? (Answer: $22,457.78)
    -Running baii(n=8,i=1.5,pmt=3000,pv=’solve’)
    will output 22457.775239802715.
  2. Switching some things up in Question 1 to ensure the payment function works… (Answer: $3,000).
    -Running baii(n=8,i=1.5,pv=22457.775239802715, pmt=’solve’)
    will output 3000.0000000000164
  3. How much would I have to deposit in an account today that pays 12% interest compounded quarterly, so that I have a balance of 20,000 in the account at the end of 10 years? (Answer: $6,131.14)
    -Running baii(n=40,i=3,pv=’solve’,fv=20000)
    will output 6131.136815476127.
  4. Suppose you invested $1000 per quarter over a 15 year period. If money earns an annual rate of 6.5% compounded quarterly, how much would be available at the end of the time period? (Answer: $100,336.68)
    -Running baii(n=60,i=1.625,pmt=1000,fv=’solve’)
    will output 100336.67614366407.
  5. Determine the present value of a 15-month annuity immediate with monthly payments of 7 using a monthly effective interest rate of 0.6%. (Answer: $100.13)
    -Running baii(n=15,i=0.6,pmt=7,pv=’solve’)
    will output 100.12683669679065.
  6. Find the present value of an annuity due of 5 years with 5% aeir with payments of 100. (Answer: $454.60)
    -Running baii(n=5,i=5,pmt=100,bng=True,pv=’solve’)
    will output 454.595050416236.

Future Work

Source: towardsdatascience