## 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.

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

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
{"ft_lang_label":"__label__en","ft_lang_prob":0.9220688,"math_prob":0.82151896,"size":5457,"snap":"2019-51-2020-05","text_gpt3_token_len":1294,"char_repetition_ratio":0.11901706,"word_repetition_ratio":0.025730994,"special_character_ratio":0.2435404,"punctuation_ratio":0.122201495,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9906215,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-11T17:02:17Z\",\"WARC-Record-ID\":\"<urn:uuid:50d73625-8334-4dfb-ba63-31551d9a94cf>\",\"Content-Length\":\"79670\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:53f96463-5227-4395-a592-03e5415ad870>\",\"WARC-Concurrent-To\":\"<urn:uuid:2b1cd7cb-d742-4ff8-be6d-4d18ba6df22b>\",\"WARC-IP-Address\":\"77.104.148.114\",\"WARC-Target-URI\":\"https://learningactors.com/building-actuarial-functions-in-python/\",\"WARC-Payload-Digest\":\"sha1:G6NKK4HXUWVUUJ23XIPGD5AJTW5VBO5M\",\"WARC-Block-Digest\":\"sha1:C5WZVW5UBXUCBYQIT5JOJAFHKGKV6CGN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540531974.7_warc_CC-MAIN-20191211160056-20191211184056-00163.warc.gz\"}"}