0% found this document useful (0 votes)
18 views90 pages

Financial Mathematics with Python Guide

The document is a book titled 'Financial Mathematics with Python' by Stephen Fratini, published in January 2021, which aims to provide a mathematical foundation for key financial concepts such as interest rates, annuities, loans, bonds, and capital budgeting. It includes Python programs to assist with financial calculations and is targeted at individual investors, small business owners, and students. The book also offers a minimal mathematical background requirement and provides supporting resources on GitHub.

Uploaded by

kkstore001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views90 pages

Financial Mathematics with Python Guide

The document is a book titled 'Financial Mathematics with Python' by Stephen Fratini, published in January 2021, which aims to provide a mathematical foundation for key financial concepts such as interest rates, annuities, loans, bonds, and capital budgeting. It includes Python programs to assist with financial calculations and is targeted at individual investors, small business owners, and students. The book also offers a minimal mathematical background requirement and provides supporting resources on GitHub.

Uploaded by

kkstore001
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

See discussions, stats, and author profiles for this publication at: [Link]

net/publication/353919145

Financial Mathematics with Python: A Concise Guide

Book · January 2021

CITATION READS
1 2,404

1 author:

Stephen Fratini

18 PUBLICATIONS 34 CITATIONS

SEE PROFILE

All content following this page was uploaded by Stephen Fratini on 28 March 2024.

The user has requested enhancement of the downloaded file.


Financial Mathematics with Python

by Stephen Fratini
Financial Math with Python 2

Table of Contents
List of Figures ......................................................................................................................................... 6
List of Tables .......................................................................................................................................... 7
Preface ................................................................................................................................................... 8
Acknowledgements ............................................................................................................................... 9
1 Introduction.................................................................................................................................. 11
1.1 Purpose ................................................................................................................................. 11
1.2 Intended Usage ..................................................................................................................... 11
1.3 Prerequisites ......................................................................................................................... 11
1.4 Conventions .......................................................................................................................... 11
1.5 Outline .................................................................................................................................. 12
2 Background................................................................................................................................... 13
2.1 Progressions.......................................................................................................................... 13
2.1.1 Arithmetic Progressions ................................................................................................ 13
2.1.2 Geometric Progressions ................................................................................................ 13
2.1.3 Recursive Progressions ................................................................................................. 14
2.2 Supporting Programs ............................................................................................................ 15
2.2.1 Arithmetic Progression Calculator ................................................................................ 15
2.2.2 Geometric Progression Calculator ................................................................................ 15
2.3 Exercises ............................................................................................................................... 16
3 Interest ......................................................................................................................................... 17
3.1 Simple Interest...................................................................................................................... 17
3.2 Compound Interest............................................................................................................... 17
3.3 Continuous Interest .............................................................................................................. 18
3.4 Effective Rate of Interest ...................................................................................................... 19
3.5 Present Value ........................................................................................................................ 21
3.6 Discounting ........................................................................................................................... 21
3.7 Time Value of Money ........................................................................................................... 23
3.8 Interest, Inflation and Taxes ................................................................................................. 25
3.9 Supporting Programs ............................................................................................................ 26
3.9.1 Interest Compounding Calculator ................................................................................. 26
3.10 Exercises ............................................................................................................................... 27
4 Annuities....................................................................................................................................... 28

©2020 The Art of Managing Things


All Rights Reserved
3 Financial Math with Python

4.1 Terminology .......................................................................................................................... 28


4.2 Accumulated Value of Ordinary, Simple, Certain Annuities ................................................ 28
4.2.1 Concept and Formulas .................................................................................................. 28
4.2.2 Examples ....................................................................................................................... 29
4.2.3 Blocking ......................................................................................................................... 30
[Link] Example ..................................................................................................................... 30
[Link] Generalization ........................................................................................................... 31
4.3 Discounted (Present) Value of Ordinary, Simple, Certain Annuities ................................... 31
4.3.1 Concept and Formulas .................................................................................................. 31
4.3.2 Examples ....................................................................................................................... 32
4.4 Annuities Due ....................................................................................................................... 33
4.5 Deferred Annuities ............................................................................................................... 33
4.6 Forborne Annuities ............................................................................................................... 35
4.7 General Annuities ................................................................................................................. 35
4.7.1 Concept and Interest Conversion Formulas ................................................................. 35
4.7.2 Example – Accumulated Value of a General Annuity ................................................... 36
4.7.3 Example – Discounted (Present) Value of a General Annuity ...................................... 36
4.8 Perpetuities .......................................................................................................................... 37
4.9 Continuous Annuities ........................................................................................................... 37
4.9.1 Discounted (Present) Value .......................................................................................... 37
4.9.2 Accumulated Value ....................................................................................................... 39
4.10 Supporting Programs ............................................................................................................ 39
4.10.1 Block Annuity Calculator ............................................................................................... 39
4.10.2 Annuity Payout Calculator ............................................................................................ 40
4.10.3 Deferred Annuity Calculator ......................................................................................... 41
4.11 Exercises ............................................................................................................................... 42
5 Repayment of Loans ..................................................................................................................... 44
5.1 Amortization of Loans .......................................................................................................... 44
5.1.1 General Formula and Equivalence to Annuities ........................................................... 44
5.1.2 Breakdown of Interest versus Principal Repayment .................................................... 45
5.1.3 Rounding Mortgage Payments ..................................................................................... 46
5.2 Balloon Loans ........................................................................................................................ 47
5.2.1 Concept and Formulas .................................................................................................. 47

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 4

5.2.2 Example – Balloon Loan as a General Annuity ............................................................. 48


5.3 Computation of Remaining Balance on a Loan .................................................................... 48
5.4 Refinancing a Loan ................................................................................................................ 49
5.5 Supporting Programs ............................................................................................................ 51
5.5.1 Annuity Payout Calculator ............................................................................................ 51
5.5.2 Amortization Calculator ................................................................................................ 51
5.5.3 Balloon Loan Calculator ................................................................................................ 51
5.5.4 Loan Refinance Calculator ............................................................................................ 51
5.5.5 Loan Refinance - Breakeven Interest Rate Analyzer .................................................... 52
5.6 Exercises ............................................................................................................................... 54
6 Bonds ............................................................................................................................................ 56
6.1 Terminology .......................................................................................................................... 56
6.2 Similarity between Bonds and Balloon Loans ...................................................................... 57
6.2.1 School Bond Example .................................................................................................... 58
6.2.2 Determine Purchase Price of Bond to Generate Various Yields ................................... 58
6.2.3 Bond Prices versus Yield ............................................................................................... 59
6.3 Schedule for a Bond.............................................................................................................. 59
6.3.1 Schedule for a Bond Bought at a Premium................................................................... 60
6.3.2 Schedule for a Bond Bought at a Discount ................................................................... 61
6.4 Correction if Bond Not Purchased on a Coupon Date .......................................................... 62
6.4.1 Dirty Price of a Bond ..................................................................................................... 62
6.4.2 Dirty Bond Price Example.............................................................................................. 63
6.4.3 Clean Price of a Bond .................................................................................................... 63
6.5 Computing the Yield given the Bond Price ........................................................................... 66
6.6 Supporting Programs ............................................................................................................ 67
6.6.1 Balloon Loan Calculator ................................................................................................ 67
6.6.2 Bond Schedule Creator ................................................................................................. 68
6.7 Exercises ............................................................................................................................... 69
7 Capital Budgeting ......................................................................................................................... 71
7.1 Net Present Value (NPV)....................................................................................................... 71
7.1.1 Concept with an Example ............................................................................................. 71
7.1.2 Negative Cash Flows ..................................................................................................... 74
7.1.3 Multiple Investments .................................................................................................... 75

©2020 The Art of Managing Things


All Rights Reserved
5 Financial Math with Python

7.1.4 Range of Cash Flow Estimates ...................................................................................... 76


7.1.5 Initial Investment is Loaned .......................................................................................... 77
7.1.6 Comparison of Projects ................................................................................................. 78
7.2 Internal Rate of Return (IRR) ................................................................................................ 79
7.2.1 Acme Furniture Example Revisited ............................................................................... 80
7.2.2 Multiple IRR Values for a Given Cash Flow ................................................................... 80
7.3 Modified IRR ......................................................................................................................... 81
7.4 Payback and Discounted Payback Period ............................................................................. 83
7.5 Profitability Index ................................................................................................................. 84
7.6 Computational Support via Microsoft Excel ......................................................................... 85
7.7 Exercises ............................................................................................................................... 86
Acronyms and Symbols ........................................................................................................................ 87
References ........................................................................................................................................... 88
Index of Terms ..................................................................................................................................... 89

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 6

List of Figures
Figure 1. Effective Rate of Discount for a Given Time Period ............................................................. 22
Figure 2. Accumulating with a Discount Rate ...................................................................................... 23
Figure 3. Equivalent Values to X in the Past and Future ..................................................................... 24
Figure 4. Debt and Payments Relative to a Focal Date ....................................................................... 25
Figure 5. Payment Schedule for Accumulated Value of Ordinary, Simple, Certain Annuities ............ 28
Figure 6. Payment Schedule for an Annuity Due ................................................................................. 33
Figure 7. Deferred Annuity .................................................................................................................. 34
Figure 8. Multiple Payments per Compounding Period ...................................................................... 37
Figure 9. Payouts timeline for a bond ................................................................................................. 58
Figure 10. Bond Purchases between Coupon Dates............................................................................ 63
Figure 11. Graph of Dirty Bond Prices over Time ................................................................................ 65
Figure 12. Graph of Clean Bond Prices over Time ............................................................................... 66
Figure 13. Graph of NPV as a Function of the Rate of Return ............................................................. 81

©2020 The Art of Managing Things


All Rights Reserved
7 Financial Math with Python

List of Tables
Table 1. Computation of Final Principal using Compound Interest .................................................... 18
Table 2. Accumulated Value of an Ordinary, Simple, Certain Annuity ................................................ 29
Table 3. Interest-Principal Repayment Breakdown Example .............................................................. 46
Table 4. Interest Rate Analysis for Refinancing ................................................................................... 50
Table 5. Bond Purchase Price versus Yield .......................................................................................... 59
Table 6. Schedule for Bond Purchased at a Premium ......................................................................... 61
Table 7. Schedule for Bond Purchased at a Discount .......................................................................... 62
Table 8. Dirty Price Changes over Time for a Bond ............................................................................. 64
Table 9. Clean Price Changes over Time for a Bond ............................................................................ 65
Table 10. Balloon Loan – Bond Comparison ........................................................................................ 67
Table 11. Answer to Exercise 6 ............................................................................................................ 69
Table 12. Initial Investment and Cash Flow in Half-year Increments .................................................. 72
Table 13. Investment Analysis for Acme Furniture ............................................................................. 73
Table 14. Initial Investment, and Cash Flow in Half-year Increments - Revised ................................. 73
Table 15. Investment Analysis for Acme Furniture - Revised .............................................................. 74
Table 16. Project Quarterly Cash Flows for a Resort Business ............................................................ 74
Table 17. Investment Analysis for Resort Investment ......................................................................... 75
Table 18. Operating and Investment Cash Flows ................................................................................ 75
Table 19. NPV Analysis in the Case of Multiple Investments .............................................................. 76
Table 20. Optimistic-Pessimistic Cash Flows for New Restaurant ...................................................... 76
Table 21. NPV for Optimistic and Pessimistic Scenarios ..................................................................... 77
Table 22. Acme Furniture - Cash Flow Estimates with Loan Repayments .......................................... 78
Table 23. Investment Analysis for Acme Furniture with Loan Repayments ....................................... 78
Table 24. Cash Flows for Projects A and B based on Same Initial Investment .................................... 79
Table 25. NPV Comparison for Projects A and B ................................................................................. 79
Table 26. Cash Flow with Two IRRs...................................................................................................... 80
Table 27. Input for MIRR Example ....................................................................................................... 83
Table 28. DPP for Project A .................................................................................................................. 84
Table 29. DPP for Project B .................................................................................................................. 84

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 8

Preface
This book is targeted at people who are interested in learning about the mathematics behind some
basic financial concepts, such as interest rates, annuities, loans, bonds and capital budgeting, as
well as trained mathematicians looking to apply their skills to finance. The target audience includes
individual investors, small business owners, and students of business and finance.
Derivations for most of the stated formulas are provided in the text. The assumed mathematical
background is minimal (basic algebra and just a touch of the limit and integral concepts from
calculus). For more extensive coverage of basic financial mathematics, the reader is referred to the
textbooks by Brown and Kopp [2], Broverman [3] and Alhabeeb [4].
[Author’s Remark: In my opinion, the financial concepts are more complex than the mathematics
used in this book.] By the way, the convention of using “author’s remark” is used elsewhere in the
book when I state a personal opinion or add a note that is not in the flow of the discussion.
Many of the financial processes discussed in this book are supported by Python programs that the
author has made freely available at the following Github site:
[Link]
Further, some of the computations concerning capital budgeting are supported by Microsoft Excel
financial functions such as NPV, IRR and MIRR. The associated Excel spreadsheets (supporting
examples in this document) are also made available at the above mentioned Github site.
While this document does provide some background and description for each Python program, it is
not intended to be a Python tutorial. However, the reader should be able to use the Python
programs without understanding Python. The programs were developed on the open source
Anaconda software environment using the Jupyter Notebook (which is a browser-based
development platform for Python), see [Link] There are several good online
tutorials on Python (see [Link] or
[Link]

©2020 The Art of Managing Things


All Rights Reserved
9 Financial Math with Python

Acknowledgements
The author wishes to thank Jenny Huang and James Swigart for their helpful review and comments
on this book.

Stephen Fratini
Sole Proprietor of The Art of Managing Things
Eatontown, New Jersey (USA)
Email: sfratini@[Link]
LinkedIn: [Link]/in/stephenfratini

Copyright © 2020 by The Art of Managing Things


All rights reserved. This book or any portion thereof may not be reproduced or used in any manner
whatsoever without the expressed written permission of the author except for the use of brief
quotations in a book review.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 10

Other books by the author:


The Art of Managing Things (2nd edition), self-published on Amazon,
[Link]
January 2019.
Mathematical Thinking: Exercises for the Mind, self-published on Amazon,
[Link]
ebook/dp/B08F75CDD6/, August 2020.

©2020 The Art of Managing Things


All Rights Reserved
11 Financial Math with Python

1 Introduction
1.1 Purpose
The purpose of this book is to provide the mathematical basis for several fundamental financial
concepts, i.e., interest compounding, annuities, loans, bonds and capital budgeting. A secondary
purpose is to provide the reader with some simple Python programs to assist with the associated
financial calculations. [Author’s Remark: While the Python programs do some checking for data
entry errors, they are not production level. Feel free to make modifications to the code and use
elsewhere. I only ask that you give attribution to the source (i.e., me) if you make commercial use
of my programs.]

1.2 Intended Usage


This book can be used in several ways:
• for self-study by those wanting to learn about the mathematics behind some basic financial
concepts
• as a supplement to a business or finance course for advance high school or college students
• as a quick reference to basic finance formulas and associated procedures.

1.3 Prerequisites
As noted in the preface, the mathematical prerequisites are minimal (basic algebra). The
summation of a series of numbers is a common theme in the book (the basics concerning series are
covered in Section 2). From a financial perspective, very little background is assumed but the
reader is warned that some of the concepts are subtle and will require some reflection.
To use the Python programs, one needs to know how to install Anaconda (or a similar environment
for executing Python code). The provided programs are Graphical User Interface (GUI) based, with
some of the output going to the GUI and in a few cases, the output goes to a Comma-Separated
Values (CSV) file which can be opened with any spreadsheet application such as Microsoft Excel or
even a simple text editor.

1.4 Conventions
This book uses a period as the decimal separator and a comma as the thousand’s separator, e.g.,
$24,000.98. This is the convention used in the United States and many other countries. However,
there are several other conventions used in other parts of the world. For further information
concerning conventions for number representation (and not just for money), see the Wikipedia
article entitled “Decimal separator” [1].
1
Fractions with repeating digits are represented using an overhead bar. For example, we write 3 as

3 with the meaning that there are an infinite number of threes after the decimal point. This also
applies for multiple repeated digits, e.g., 12.345781781781 … would be written 12.345781 ̅̅̅̅̅ (the
bar just goes over the infinitely repeating digits).

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 12

1.5 Outline
Section 1 is this introduction.
Section 2 provides some background on various types of progressions and their sums. Basic
mathematical concepts such as progressions are a recurring topic in the book.
Section 3 covers topics concerning interest rates, and the past and future value of money.
Conceptually, Section 3.7 (concerning the time value of money) is critical to the understanding of
much of what follows in the book.
Annuities are discussed in Section 4.
Section 5 covers topics concerning the repayment of loans such as mortgages.
Various types of bonds are discussed in Section 6.
Section 7 covers decision making techniques for capital budgeting.

©2020 The Art of Managing Things


All Rights Reserved
13 Financial Math with Python

2 Background
2.1 Progressions
Progressions are sequences where each term is based on mathematical operations applied to one
or more previous terms. Progressions are essential in finance concerning topics such as interest
accumulation.

2.1.1 Arithmetic Progressions


An arithmetic progression is an ordered list (i.e., sequence) of terms where each term is the sum of
the previous terms plus some common amount (which can be positive or negative). For example,
• 1, 4, 7, 10, 13, … is an arithmetic progression with difference 3 between successive terms
• 10, 5, 0, −5, −10, … is an arithmetic progression with difference -5
• −0.125, 0.125, 0.375, 0.625, 0.875, … is an arithmetic progression with difference 0.25.

In general, an arithmetic progression with initial term 𝑥1 and difference 𝑑 can be represented as
𝑥1 , 𝑥1 + 𝑑, 𝑥1 + 2𝑑, …
where the 𝑛𝑡ℎ term is 𝑥𝑛 = 𝑥1 + (𝑛 − 1)𝑑.
The sum of the first 𝑛 terms (call it 𝑆𝑛 ) can be computed by writing the progression forward and
backward, and then adding, i.e.,
𝑆𝑛 = 𝑥1 + (𝑥1 + 𝑑) + (𝑥1 + 2𝑑) + ⋯ (𝑥𝑛 − 2𝑑) + (𝑥𝑛 − 𝑑) + 𝑥𝑛
𝑆𝑛 = 𝑥𝑛 + (𝑥𝑛 − 𝑑) + (𝑥𝑛 − 2𝑑) + ⋯ (𝑥1 + 2𝑑) + (𝑥1 + 𝑑) + 𝑥1
which implies (after some cancellation of terms)
2𝑆𝑛 = 𝑛(𝑥1 + 𝑥𝑛 )
or
𝑛
𝑆𝑛 = (𝑥 + 𝑥𝑛 )
2 1

2.1.2 Geometric Progressions


A geometric progression is an ordered list of terms where each term is a multiple of the preceding
term. For example,
• 3, 15, 75, 375, 1875 … is a geometric progression with a common multiple of 5
• −10, 1.25, −0.15625, 0.01953125, … is a geometric progression with a common multiple
−0.125.
In general, a geometric progression with initial term 𝑎 and multiplier 𝑟 can be represented as
𝑎, 𝑎𝑟, 𝑎𝑟 2 , 𝑎𝑟 3 , …
where the 𝑛𝑡ℎ term is 𝑥𝑛 = 𝑎𝑟 𝑛−1 where 𝑛 = 1,2,3, …
The sum of the first 𝑛 terms is
𝑆𝑛 = 𝑎 + 𝑎𝑟 + 𝑎𝑟 2 + ⋯ + 𝑎𝑟 𝑛−1 (1)

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 14

Multiplying by 𝑟 on both sides of the equation gives


𝑟𝑆𝑛 = 𝑎𝑟 + 𝑎𝑟 2 + 𝑎𝑟 3 + ⋯ + 𝑎𝑟 𝑛 (2)
Subtracting equation (2) from (1) yields
𝑆𝑛 − 𝑟𝑆𝑛 = 𝑎 − 𝑎𝑟 𝑛
𝑎(1 − 𝑟 𝑛 )
𝑆𝑛 =
1−𝑟
In subsequent parts of this book, we use a slightly modified version of the above formula (gotten by
multiplying the top and bottom of the fraction by -1)
𝑎(𝑟 𝑛 − 1)
𝑆𝑛 =
𝑟−1
As an example, consider the sum of the first 5 terms in the geometric sequence with multiplier 2
and with initial term 𝑎 = 100. Using former version of the summation formula for geometric series,
we get the following
100(1 − 25 )
𝑆5 = = −100(−31) = 3,100
1−2

For −1 < 𝑟 < 1, the term 𝑟 𝑛 approaches zero for 𝑛 approaching infinity. Apply this observation to
the formula for 𝑆𝑛 gives the following result:
𝑎
𝑎 + 𝑎𝑟 + 𝑎𝑟 2 + 𝑎𝑟 3 + ⋯ = , −1 < 𝑟 < 1
1−𝑟
1
For example, the sum of the series with first term 2 and multiplier is
3
2 2 2 2
2+ + 2+ 3+⋯= =3
3 3 3 1
1−3

2.1.3 Recursive Progressions


A recursive progression is a progression in which each term is defined using one or more of the
previous terms where the first several terms are given. For example, 𝑎𝑛 = 𝑎𝑛−1 + 𝑎𝑛−2 with 𝑎1 =
𝑎2 = 1 defines the famous Fibonacci sequence. When expanded, the recursion gives the following
progression:

1 1 2 3 5 8 13 21 34 55 89 144 …

For another example, consider the tetranacci numbers which start with four predetermined terms,
with each term afterwards being the sum of the preceding four terms, i.e., 𝑎𝑛 = 𝑎𝑛−1 + 𝑎𝑛−2 +
𝑎𝑛−3 + 𝑎𝑛−4 with 𝑎1 = 𝑎2 = 𝑎3 = 0 and 𝑎4 = 1. When expanded, the recursive formula yields the
following:

0 0 0 1 1 2 4 8 15 29
56 108 208 401 773 1,490 2,872 5,536 10,671 20,569
39,648 76,424 147,312 283,953 547,337 1,055,026 …

©2020 The Art of Managing Things


All Rights Reserved
15 Financial Math with Python

The Fibonacci and tetranacci progressions are examples of difference equations.


[Author’s remark: Recursive progressions are not discussed further in this book. They are
mentioned here for completeness with regard to the types of progressions.]

2.2 Supporting Programs

2.2.1 Arithmetic Progression Calculator


File name: arith_prog.py (see the preface for location of this file and instructions about running
Python programs)
This program generates an arithmetic progression, given a starting value (it can be a decimal, and it
can be positive or negative), an increment (it can be a decimal, and it can be positive or negative)
and a desired number of terms. If the number of terms is large (fills the output window), then a
scroll bar will appear on the right.
There is another button that allows one to request a given term in an arithmetic progression
without computing the entire progression up to that term. For example, the program can compute
the 101st term of the arithmetic progression with initial term 71 and increment 19035, which is
1,903,571.
There is a button to clear the input so that another progression can be computed. There is also a
button to quit the program. (For the record, the clear and quit buttons are present in the other
programs provided in support of this book.)
For those looking to learn the tkinter module of Python, this program may be helpful as an
example. The tkinter module focuses on the user interface.
There are several tkinter tutorials on the Internet, e.g., [Link]
tkinter-tutorial/ and the YouTube video entitled “Tkinter Course - Create Graphic User Interfaces in
Python Tutorial” at [Link]

2.2.2 Geometric Progression Calculator


File name: geo_prog.py
This program generates a geometric progression, given a starting value (it can be a decimal, and it
can be positive or negative), an increment (it can be a decimal, and it can be positive or negative)
and a desired number of terms. The sum of the progression is also computed and displayed.
The output is listed in the GUI, with one number per line.
There is another button that only generates the 𝑛𝑡ℎ term in a given progression.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 16

2.3 Exercises
1. Show that the sum of an arithmetic progression can also be represented as
𝑛
𝑆𝑛 = 2 (2𝑥1 + (𝑛 − 1)𝑑).

2. Find the 335th term in the arithmetic progression 3, 9, 15, 21, … and also find the sum of the
first 335 terms. Hint: Use the Python program on arithmetic progressions.
3. If the 57th term in an arithmetic progression is 677 and the different between terms is 12,
what is the first term. Hints: One approach is to use the equation for the 𝑛𝑡ℎ term in an
arithmetic progression and solve of 𝑥1 . Another approach is to use the Python program with
677 as the initial term, -12 as the difference and 57 as the desired term (basically working
backward with negative steps).
4. Find the 237th term in the geometric progression with initial term 2 and multiplier 1.1. Hint:
Use the Python program on geometric progressions.
5. Find the sum of the first 10 terms in the geometric progression with initial term 25 and
multiplier 7. Hint: Use the Python program on geometric progressions.
6. If the 8th term in a geometric progression is 2,470,629 and the multiplier is 7, what is the
first term? Hint: Work backwards by dividing by 7 (eight times).
7. The Lucas progression is given by 2, 1, 3, 4, 7, 11,18, … Determine a recursive formula that
yields the Lucas progression. Hint: The initial two terms (2 and 1) are given. The recursive
formula should start with the third term.

©2020 The Art of Managing Things


All Rights Reserved
17 Financial Math with Python

3 Interest
3.1 Simple Interest
Simple interest is computed based on the amount of principal and time duration, but without any
compounding. Simple interest can be applied to a loan or to money saved in a bank account.
In its most basic form, simple interest entails an interest rate 𝑟 (which is typically stated per year), a
given amount of principal (𝑃) and the term (𝑡) when the principal and interest is paid back to the
lender. The term is typically stated in years or fractions thereof. Under these assumptions, the
amount of simple interest plus the original principal is given by the formula:
𝑃 + 𝑃𝑟𝑡
which can be written as
𝑷(𝟏 + 𝒓𝒕)
For example, Mr. Smith purchases a car from a car dealer. The car costs $28,440. Mr. Smith agrees
to make an initial (upfront) payment of $20,000 and the car dealer agrees to allow Mr. Smith to pay
the remaining amount, with 6% annual interest, in 7 years. At the end of 7 years, Mr. Smith must
pay the principal ($8,400) plus simple interest over the 7 years, i.e., $8,400 ∗ .06 ∗ 7 = $3,528.
In a variation of the above example, Mr. Smith pays the principal back to the car dealer at the end
.06
of 7 years but he must make monthly interest payments in the amount of $8,400 ∗ ( 12 ) = $42.
The accumulated amount of interest paid to the car dealer is an arithmetic progression, i.e.,
42, 84, 126, … , 3,528. This is an example of what is called a balloon loan that allows for the entire
principal to be paid back at the end of the loan’s term.

3.2 Compound Interest


Compound interest is computed on the sum of the original principal plus accrued interest.
Compound interest can be thought of as "interest on interest," and grows faster than simple
interest of the same rate.
The term nominal annual interest rate or just nominal interest rate as used here is the interest rate
“as stated,” without adjustment for the effect of compounding. An interest rate is called nominal if
the frequency of compounding (e.g., monthly or daily) is not identical to the basic time unit in
which the nominal rate is quoted (normally a year). For example, a bank may advertise a nominal
yearly interest rate of 6% compounded daily which (as will be shown at the end of Section 3.4) is
effectively about 6.183% when daily compounding is applied.
Let 𝑃 be the initial principal (e.g., money placed in a bank account), 𝑟 be the nominal annual
interest rate, 𝑛 be the compounding frequency per year, and 𝑡 be the length of time the interest is
applied (using the same units as 𝑟). Table 1 shows the computation of principal after the 1st, 2nd and
final compounding intervals. The entries in the right-hand column constitute a geometric
𝑟
progression, with initial term P and multiplier (1 + 𝑛).

Some financial books and articles use the notation 𝑖 (𝑛) to indicate a nominal annual interest rate
that is compounded 𝑛 times per year. Thus, our 𝑟 is 𝑖 (𝑛) . [Author’s remark: This notation is
confusing. First, it is not a power of 𝑖. Secondly, if the nominal annual interest rate is 𝑖, we would
say that 𝑖 (𝑛) = 𝑖 for all values of 𝑛 (also confusing). So, I have avoided using this notation as much

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 18

as possible and have taken the approach of writing out in prose what is meant, i.e., “nominal
annual interest of 6% compounded monthly” rather than 𝑖 (12) = .06.]

Table 1. Computation of Final Principal using Compound Interest


Initial principal 𝑃

Principal after first 𝑟 𝑟


𝑃+ 𝑃 = 𝑃 (1 + )
compounding interval 𝑛 𝑛

Principal after second 𝑟 𝑟 𝑟


𝑃 (1 + ) + P (1 + ) ( )
compounding interval 𝑛 𝑛 𝑛
𝑟 𝑟
= 𝑃 (1 + ) (1 + )
𝑛 𝑛
𝑟
= 𝑃(1 + )2
𝑛

… …

Principal after 𝑛𝑡 compounding 𝒓


𝑷(𝟏 + )𝒏𝒕
intervals 𝒏

𝑟
Alternately, we can let 𝑖 = 𝑛 be the interest rate per compounding period and 𝑠 = 𝑛𝑡 be the
number of compounding intervals. These substitutions yield an equivalent formula for the
accumulated principal after 𝑠 compounding intervals, i.e., 𝑷(𝟏 + 𝒊)𝒔 .
As an example, consider a scenario where Ms. Ortega deposits $10,000 into a bank account that
advertises a 2% nominal annual interest rate which is computed monthly. Assuming no withdraws
have been made, how much is the account worth after 3 years and 6 months? Using the formula
for compound interest with 𝑃 = $10,000, 𝑟 = .02, 𝑛 = 12 and 𝑡 = 3.5, the final principal is
.02
$10,000(1 + 12 )42 = $10,724.46.

3.3 Continuous Interest


At first thought, one might think there is no bound to the amount of interest that can be accrued if
the compounding is done infinitely often. However, that is not the case. As the number of
compounding intervals approach infinity, the formula converges.
[Author’s remark: The following derivation entails calculus. If you are not familiar with calculus,
don’t worry. The key point here is that if the number of compounding periods is infinite, the
formula for accumulated interest is simply 𝑃𝑒 𝑟𝑡 where 𝑒 ≅ 2.71828.]
In terms of calculus, we want to determine
𝑟 𝑛𝑡
lim 𝑃 (1 + )
𝑛→∞ 𝑛
where r is the nominal annual interest rate (compounded n times per year where n approaches
infinity) and t is duration of interest accumulation in years.
To this end, let 𝑖 = 𝑛/𝑟 and substitute into the above expression to get
𝑟𝑡
𝑟 𝑛𝑡 1 𝑖𝑟𝑡 1 𝑖
lim 𝑃 (1 + ) = lim 𝑃 (1 + ) = 𝑃 lim [(1 + ) ]
𝑛→∞ 𝑛 𝑖→∞ 𝑖 𝑖→∞ 𝑖

©2020 The Art of Managing Things


All Rights Reserved
19 Financial Math with Python

1 𝑖
From calculus, we have that lim (1 + 𝑖 ) = 𝑒 where 𝑒 ≅ 2.71828 (known as Euler’s number).
𝑖→∞
Thus, the formula for continuous interest is given by 𝑷𝒆𝒓𝒕 .
Returning to the example of Ms. Ortega’s bank account, assume the same interest rate and time
period (3.5 years) but with continuous interest. In this case, the account would be worth
$10,000𝑒 (.02)(3.5) = $10,725.08 which is only slightly more than monthly compounding!

3.4 Effective Rate of Interest


As defined by Brown and Kopp in their book Financial Mathematics: Theory and Practice [1]
The effective rate of interest is the amount of money that one unit of capital, invested at
the beginning of a period, will earn during the period, where interest is paid at the end of
the period.
[Other sources define effective interest rate as pertaining to a period of one year. For example,
Wikipedia provides the following definition:
The effective interest rate (EIR), effective annual interest rate, annual equivalent rate (AER)
or simply effective rate is the interest rate on a loan or financial product restated from the
nominal interest rate and expressed as the equivalent interest rate if compound interest
were payable annually in arrears.
This is perhaps a more common definition but less general than the definition from Brown and
Kopp.]
For example, if Ms. DeMarco buys a house (as an investment) at $200,000 and sells the house 18
months later (assuming no capital investment in the house) at $275,000, then the gain is $75,000
over 18 months. What is the percentage gain? In other words, what percentage (call it x) of 200,000
equals 75,000? This can be converted into a precise equation, i.e.,
𝑥
∙ 200,000 = 75,000
100
37.5
which yields, 𝑥 = .375 or 37.5% over 1.5 years, which equates to = 25% per year (assuming
1.5
simple interest).
Take the same problem as above but assume the house was held 30 months before being sold. In
37.5
this case, the effective interest rate per year is 2.5 = 15% (assuming simple interest).
Again, using the same base problem, but now assuming the owner incurs $25,000 in capital
improvements and nets $20,000 from renting the house during the 2.5 years the house is owned by
Ms. DeMarco. The net capital gain is now 75,000 + 20,000 − 25,000 = $70,000. So, the effective
interest rate per year is

(70,000)(100)
( 200,000 ) 35
= = 14%
2.5 2.5

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 20

In general, if the value of an investment is 𝑉(𝑡) at time 𝑡 and 𝑉(𝑡̂) at some later time 𝑡̂, then the
effective interest rate from time 𝑡 to 𝑡̂ is given by the formula
𝑉(𝑡̂) − 𝑉(𝑡)
𝑉(𝑡)
In words, the effective interest rate formula indicates the increase or decrease (as a fraction) of an
investment from time 𝑡 to a later time 𝑡̂.
The effective interest rate provides a way to compare the growth of simple and compound interest.
Assume the starting principal is P and the interest rate per time period is 𝑖.
In case of compound interest, the effective interest rate in period 𝑛 is
𝑃(1 + 𝑖)𝑛 − 𝑃(1 + 𝑖)𝑛−1 1 + 𝑖 − 1
= =𝑖
𝑃(1 + 𝑖)𝑛−1 1
In the case of simple interest, the effective interest rate in period 𝑛 is
𝑃(1 + 𝑛𝑖) − 𝑃(1 + (𝑛 − 1)𝑖) 𝑖
=
𝑃(1 + (𝑛 − 1)𝑖) 1 + (𝑛 − 1)𝑖
The effective interest rate for compound interest remains constant over time. However, the
effective interest rate for simple interest decrease over time (i.e., as 𝑛 gets larger) because there is
no compounding.
It is common for banks to state the effective yearly interest rate when principal is compounded at a
nominal yearly rate of 𝑟. This is referred to as Annual Percentage Yield (APY). The APY (represented
as the variable 𝑦 below) is derived by inserting the compound interest formula (with 𝑡 = 1) into the
effective interest rate formula to get:
𝑟
𝑃(1 + 𝑛)𝑛 − 𝑃 𝑟
𝑦= = (1 + )𝑛 − 1
𝑃 𝑛
For example, if a bank advertises a nominal yearly interest rate of 6% compounded daily, then the
.06 365
APY is (1 + ) − 1 ≅ .06183 or about 6.183%.
365

It is also possible to solve for the nominal yearly compound interest rate that is equivalent to a
given APY, i.e.,
𝑟 = 𝑛((𝑦 + 1)1/𝑛 − 1)
For example, what nominal interest rate (compounded monthly) is equivalent to an APY of 8%?
1
Using the above equation with 𝑛 = 12 and 𝑦 = .08, we get 𝑟 = 12 (1.0812 − 1) = .077206 or
7.7206%.
A common use of effective interest rate is to normalize other types of interest accumulation with
respect to simple interest. It is also possible to relate (via formulas) different types of interest (this
is covered in Section 4.7).

©2020 The Art of Managing Things


All Rights Reserved
21 Financial Math with Python

3.5 Present Value


Present value refers to the sum of money which if invested now at a given rate of interest will
accumulate to a specified amount at a particular future date.
For example, what is the present value of $25,000 three years from now assuming 5% interest
compounded monthly? In other words, how much money needs to be invested now at 5% interest
compounded monthly (with no additional investments or withdraws) to have $25,000 in three
years? In terms of the compound interest formula, the following needs to be solved for P
. 05 (12)(3)
$25,000 = 𝑃(1 + )
12
Solving this equation, we get 𝑃 = $21,524.41. Someone might do such a calculation if he or she
wants to buy a $25,000 car three years from now and wants to know how much to put into a given
fixed interest investment (such as a government bond) right now.
Let 𝑃𝑉 be the present value and 𝐹𝑉 be the future value of 𝑃𝑉 over 𝑠 compounding periods
with interest rate 𝑖 per compounding period. In terms of the compound interest formula, we have
𝐹𝑉 = 𝑃𝑉(1 + 𝑖)𝑠
Solving for FV yields the following formula for PV in the case of compound interest
𝑷𝑽 = 𝑭𝑽(𝟏 + 𝒊)−𝒔
𝒓
[The other formulation for compound interest, i.e., 𝑷(𝟏 + 𝒏)𝒏𝒕 , could also have been used in the
above calculation.]
In the cases of simple interest and continuous interest, similar formulas can be derived, i.e.,
• 𝑷𝑽 = 𝑭𝑽(𝟏 + 𝒓𝒕)−𝟏 (present value for simple interest)
• 𝑷𝑽 = 𝑭𝑽(𝒆−𝒓𝒕 ) (present value for continuous interest).
In both of the above formulas, 𝑟 is the nominal annual interest rate.

3.6 Discounting
Discount is a concept similar to interest, i.e.,
• Discount is paid/due at the beginning of a payment period and is calculated on the balance
at the end of the period.
• Interest is paid/due at the end of a payment period and calculated on the balance at the
beginning of the period.
There are some cases where the anticipated amount of money owed at the end of a loan is
deducted at the start of the loan, i.e., the “interest” is paid up front. This is known as “discounting a
loan” and the rate of discount is represented by the symbol 𝑑. (Note that the term “discount rate”
also refers to the interest rate that the United States Federal Reserve charges banks for short term
loans. However, that is not the topic of this section.)
For example, a bank makes a short-term (9 months) $10,000 loan to Ms. Peeples at a 7% annual
9
discount rate. The bank deducts 12 (7) = 5.25% ($525) at the beginning of the loan. Ms. Peeples

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 22

receives $10,000 − $525 = $9,475 up front, and needs to repay $10,000 at the end of 9 months.
525
The effective interest rate per 9 months (as seen by the bank) is 9,475 ≅ .05541 or 5.541%.

The effective rate of discount (denoted as 𝑑) from time 𝑡 to some later time 𝑡̂ is the ratio of the
change in value of an investment (known as the amount of discount) to the value at the end of
period (at time 𝑡̂), i.e.,

𝑉(𝑡̂ ) − 𝑉(𝑡)
𝑑=
𝑉(𝑡̂ )
where 𝑉(𝑠) is the value of an investment at time 𝑠. This is almost the same as the effective interest
rate formula except that the denominator is the value at the end of the time period rather than at
the beginning. The situation is depicted in Figure 1.
10,000−9,475 525
In the previous example, 𝑑 = = = .0525 or 5.25%.
10,000 10,000

Figure 1. Effective Rate of Discount for a Given Time Period

In the case of compound interest, the effective rate of discount is constant for the repayment
periods as can be seen from the calculation below. (Note that 𝑖 is the interest rate per
compounding period.)
𝑉(𝑡𝑛 ) − 𝑉(𝑡𝑛−1 ) 𝑃(1 + 𝑖)𝑛 − 𝑃(1 + 𝑖)𝑛−1 1 + 𝑖 − 1 𝑖
𝑑= = 𝑛
= =
𝑉(𝑡𝑛 ) 𝑃(1 + 𝑖) 1+𝑖 1+𝑖
𝑑
Solving for 𝑖 in the above equation, we get 𝑖 = 1−𝑑.

In the case of simple interest, the effective rate of discount depends on both the duration of the
loan (𝑡) and the annual interest rate (𝑟). Since there is no compounding, there is only one
repayment period which starts at time 0 and ends at time 𝑡. The formula for the effective rate of
discount in this case is derived as follows:
𝑉(𝑡) − 𝑉(0) 𝑃(1 + 𝑟𝑡) − 𝑃 𝑟𝑡
𝑑= = =
𝑉(𝑡) 𝑃(1 + 𝑟𝑡) 1 + 𝑟𝑡
What is the effective rate of discount for a simple interest discount loan of $10,000 for 18 months
.15
at 10% interest? We are given 𝑟 = .1 and 𝑡 = 1.5. Thus, 𝑑 = 1+.15 = .130435 or 13.0435%. Note
that 13.0435% of the final value (expected payment) of the loan (i.e., $11,500) is the stated
amount of the loan, i.e., $10,000. In summary, an 18-month loan of $11,500 at a discount rate of
13.0435% would result in the borrower getting $10,000 at the beginning of the loan with an
obligation to pay the bank $11,500 in 18 months.

©2020 The Art of Managing Things


All Rights Reserved
23 Financial Math with Python

While uncommon, it is possible to accumulate a sum of money with a discount rate. Consider an
initial investment of 𝑥0 that is compounded at a discount rate of 𝑑 for 𝑛 periods:
• At the beginning (time 0), 𝑥0 is calculated as the value of the investment at time 1 (call it 𝑥1 )
minus the discount, i.e., 𝑑𝑥1 (note that juxtaposition is meant to imply multiplication). So,
𝑥0 = 𝑥1 − 𝑑𝑥1 which implies 𝑥1 = 𝑥0 (1 − 𝑑)−1 .
• Similarly, 𝑥1 = 𝑥2 − 𝑑𝑥2 which implies 𝑥2 = 𝑥1 (1 − 𝑑)−1 = 𝑥0 (1 − 𝑑)−2 .
• Continuing in this manner, 𝑥𝑛 = 𝑥0 (1 − 𝑑)−𝑛 .
Growth of the initial amount (𝑥0 ) is depicted in Figure 2.

Figure 2. Accumulating with a Discount Rate

For example, what amount must be invested, at a discount rate of .45% per month, to have
$50,000 at the end of 10 years under a monthly compound discount approach? We are given 𝑑 =
.0045 and 𝑛 = 10 × 12 = 120 and are looking for 𝑥0 such that 𝑥120 = 50,000. Using the formula
for compound discounting, we have
𝑥120 = $50,000 = 𝑥0 (1 − .0045)−120
𝑥0 = $50,000(1 − .0045)120 ≅ $29,101.93.
As another example, consider a discounted 5-year loan at a discount rate of .4% per month where
the loanee initially receives $100,000 from a bank. What is the actual size of the loan, i.e., the
amount of money to be paid back to the loaner at the end of 5-years? We are given 𝑑 = .004, 𝑛 =
5 × 12 = 60 and 𝑥0 = 100,000 and are being asked to find 𝑥60 . Using the formula for compound
discounting, we have
𝑥60 = (100,000)(1 − .004)−60 ≅ $127,186.11
In other words, a discounted loan in the amount of $127,186.11 is requested. The discount
amount $27,186.11 = $127,186.11 − $100,000 is deducted from the loan by the bank and the
loanee receives $100,000. At the end of 5 years, the loanee must pay back $127,186.11 to the
bank.
𝑑 .004
The equivalent interest rate is 𝑖 = 1−𝑑 = 1−.004 = .004016064 (monthly). Compounding at 𝑖 for 60
months with an initial value of $100,000 yields a future value (in 60 months) of
$100,000(1 + .004016064)60 = $127,186.11

3.7 Time Value of Money


Regarding financial decisions, the value of an amount of money (relative to a given time frame)
needs to be considered. For example, receiving $100 from an investment today is not the same as
receiving $100 ten years from now assuming that the $100 could be making interest over the ten
year span.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 24

Figure 3 shows the value of 𝑋 at a focal date (could be the present or some other date of
importance) and equivalent values in the past and future based on simple, compound, and
continuous interest. For example, if the amount 𝑋(1 + 𝑖)−𝑛 is compounded for 𝑛 time periods,
then we will have 𝑋(1 + 𝑖)−𝑛 (1 + 𝑖)𝑛 = 𝑋. If the amount 𝑋𝑒 −𝑖𝑛 is continuously compounding for 𝑛
time periods, then it would grow to (𝑋𝑒 −𝑖𝑛 )𝑒 𝑖𝑛 = 𝑋 at time 𝑛. We can also work in the opposite
direction. For example, how much is needed at the focal date to have 𝑋 + 𝑖𝑛 at n time periods in
the future. From the diagram, we see the required amount is 𝑋.

Figure 3. Equivalent Values to X in the Past and Future

Consider a personal loan of $5000 between friends that is due at the end of a three year period.
Determine an equivalent amount of debt due in 1 year and in 5 years if they agree to annual
nominal interest rate of 6% compounded monthly.
Select the focal date to be when the debt is due, i.e., in three years. The equivalent value of
the debt two years before the focal date (i.e., one year from the present) is
.06 −24
5,000(1 + 12
) = $4,435.93. In this case, the debt is paid early. The equivalent value of
.06 24
the debt two years after the focal date is 5,000(1 + 12
) = $5,635.80. In this case, the
debt is later than the agreed repayment time (which we assumed to be the focal date in the
calculations).

As a second example, assume Mr. Jasper owes Ms. Dubois $1,000 in 6 months and another $1,500
in 2 years from now. What single payment, in the present, will liquidate these debts if both parties
agree money is worth 3% (compounded monthly). Same question if the debt is paid in a year.
For the first question, we compute the equivalent value of the two future payments if made
at the present time, i.e.,
. 03 −6 . 03 −24
𝑋 = 1,000 (1 + ) + 1,500 (1 + ) = $2,397.88
12 12
For the second question, notice that the first expected payment is being paid late and will
thus be greater than $1000.
6 −12
. 03 . 03
𝑋 = 1,000 (1 + ) + 1,500 (1 + ) = $2,470.82
12 12

A useful technique in financial mathematics is to replace one set of payments/debts with an


equivalent set. Two sets of payments/debts are equivalent if the sum of the dated values of one set
is equal to that of the other set on any date (known as a focal date or the comparison date or the
valuation date). This is under the assumption of a common interest rate scheme.

©2020 The Art of Managing Things


All Rights Reserved
25 Financial Math with Python

As an example of this principle, consider a $100,000 business loan that is to be paid in 3 equal
payments at the end of 4, 7 and 11 months, with a final payment of $20,000 in 13 months.
Determine the value of the 3 equal payments. The nominal annual interest rate is 4% (compounded
monthly).
To solve the problem, first select a focal date. Any date will do. Let’s select 7 months from
the start of the loan to be the focal date. At the focal date, the equivalent value of the
payments must equal the equivalent value of the debt. If we let 𝑥 be amount of each
unknown payment, then we have the following equation:
value of payments relative to focal date = value of debt relative to focal date
. 04 3 . 04 −4 . 04 −6 . 04 7
𝑥 (1 + ) + 𝑥 + 𝑥 (1 + ) + 20,000 (1 + ) = 100,000 (1 + )
12 12 12 12
2.99681 𝑥 + 19,604.62549 = 98,023.12747
𝑥 = $27,613.42
The relationship between the debt and payments relative to the focal date is depicted in
Figure 4.

Figure 4. Debt and Payments Relative to a Focal Date

If a different focal date is used, the same answer should be obtained. For example, the
following equation uses the end of the loan (13 months) as the focal date.
. 04 9 . 04 6 . 04 2 . 04 13
𝑥 (1 + ) + 𝑥 (1 + ) + 𝑥 (1 + ) + 20,000 = 100,000 (1 + )
12 12 12 12
3.05725 𝑥 + 20,000 = 10,4421.0681
𝑥 = $27,613.42

3.8 Interest, Inflation and Taxes


At the beginning of a given period of time, assume that you have $1 and the inflation rate is 3% for
that period. An item that costs $1 at the beginning of the period will cost $1.03 at the end of the
1
period. Your $1 at the end of the period can only purchase 1.03 ≅ .97 of what it could have at the
beginning of the period. So, the effective simple interest rate is -3%. Another way to view this is ask
“what is the future value of $1 under -3% simple interest for one year?” The answer is

𝐹𝑉 = 𝑃(1 + 𝑟𝑡) = 1(1 − .03) = .97

noting that 𝑃 = 1, 𝑟 = −.03 and 𝑡 = 1 in the above equation.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 26

However, if you invested your $1 at 5% interest at the beginning of the period, you would have
1.05
$1.05 which could be used to purchase 1.03 ≅ 1.0194 of what you could have at the beginning of
the period with $1. So, the real rate of return (for the noted investment) is 1.94% in this scenario.
Look at it this way:
Let’s say that at the beginning of the year, a candy bar costs $1. Also, at the beginning of
the year, you invest $1 at 5% simple interest. Over the course of the year, inflation is 3%. At
the end of the year, you have $1.05 and you want to know how many of the candy bars you
can now buy (call this quantity 𝑥). Due to inflation, the candy bar now cost $1.03. So, we
1.05
have the task of solving the equation 1.05 = 1.03 𝑥. This gives the result 𝑥 = 1.03 = 1.0194
candy bars.
In general, if the interest rate for a given period is 𝑖 and the inflation rate is 𝑟𝑖𝑛𝑓 , the real rate of
return (i.e., interest adjusted for inflation) is
1+𝑖
−1
1 + 𝑟𝑖𝑛𝑓
The above is known as the Fisher equation [5].
If there is a tax rate of 𝑖𝑡 at the end of the year or given period, the effective interest becomes 𝑖𝑡 ∙ 𝑖.
This gives us the modified real rate of return (with taxes considered):
1 + (1 − 𝑖𝑡 ) ∙ 𝑖
−1
1 + 𝑟𝑖𝑛𝑓
Returning to the previous problem with .05 simple interest and a .03 rate of inflation, and assuming
a tax rate of 20%, we get the following real rate of return
1 + (1 − .2)(.05) 1.04
−1= − 1 ≅ 1.0097 or .97%
1 + .03 1.03

3.9 Supporting Programs

3.9.1 Interest Compounding Calculator


File name: [Link]
This calculator determines compound interest and continuous interest. The expected input is
• the original principal
• number of compounding periods per year (this is left blank if continuous interest desired)
• an indication of whether continuous interest is desired (enter True or False)
• time that interest accrues in years or fraction of years (e.g., 1.75 years is allowed).
The output is the final principal (which includes the original principal plus accrued interest).
[Author’s Remark: While I did not plan it, the interest compounding calculator also works for a
negative number of years. For example, let’s say you want to know how much to invest now at 5%
nominal annual interest (compounded monthly) so that in 10 years you have $1,000. In the
calculator, enter 1000 as the principal, 5 for the interest rate, 12 for the number of compounding
periods per year and -10 for the number of years. This will give an answer of 607.16.]

©2020 The Art of Managing Things


All Rights Reserved
27 Financial Math with Python

3.10 Exercises
1. Determine the value of a simple interest investment of $10,000 at 3% annual interest rate
over a period of 2 years and 7 months. What would the value of the investment be if daily
compounding were used instead? Hint: For the second part of the problem, use the interest
compounding calculator.
2. Country A makes a 100 year loan to Country B from 1 billion dollars at an annual interest
rate of 6%. Compute the amount of interest paid back to Country A under the assumption
of yearly compounded interest, daily compounded interest and continuous compounding.
Hint: Use the interest compounding calculator for each scenario.
3. Mr. Wimple buys a diamond for investment purposes at $55,000, holds the diamond for 5
years and 6 months and then sells the diamond for $100,000. What is the effective interest
rate per year (assuming simple interest)? What is the effective interest rate if monthly
compounding is assumed? Hint: For the second question, use the compound interest
formula with 𝑃 = 55,000, 𝑛 = 12 and 𝑡 = 5.5, set the result equal to 100,000 solve for r,
𝑟
i.e., solve 55,000(1 + )12𝑡 = 100,000 for 𝑟 by taking the natural log on both sides and
12
then apply some basic algebra. The answer is 10.9191% which, as expected, is smaller than
the solution to the first question, i.e., 14.876%.
4. Given a nominal yearly interest rate of 𝑟, compute the effective annual interest rate under
the assumption of continuous compounding between times 𝑡 and 𝑡̂. Hint: From the formula
for effective interest rate, we have
𝑉(𝑡̂) − 𝑉(𝑡) 𝑃𝑒 𝑟(𝑡̂−𝑡) − 𝑃
= = 𝑒 𝑟(𝑡̂−𝑡) − 1
𝑉(𝑡) 𝑃
which is the effect interest rate for the entire time period 𝑡̂ − 𝑡. To get the effective annual
interest rate, just divide by 𝑡̂ − 𝑡.
5. What nominal annual interest rate 𝑟 is required to quadruple an initial amount in 20 years,
with monthly compounding? Same question with continuous compounding? Hint and
𝑟
Answer: For the first question, solve the equation 4𝑃 = 𝑃(1 + )240 to get 𝑟 = 6.9515%.
12
For the second question, solve the equation 4𝑃 = 𝑃𝑒 20𝑟 to get 𝑟 = 6.9315%. In both cases,
you need to take the natural log (i.e., log base e) on both sides and then do some algebra.
6. A rich uncle leaves $5 million to 3 heirs (all nieces). Each niece is to receive an equal amount
of money when she turns 21 years old, which will be 12 months, 27 months, and 43 months
from the time the will is executed. In the meantime, the money is invested at a nominal
annual interest rate of %6 (compounded monthly). How much money is each niece to
receive? Hint: Use the time that the will is executed as the focal date and equate present
value of the investment with that of the payouts to get the following equation (where x is
the amount to be paid to each heir): 𝑥(1 + .005)−12 + 𝑥(1 + .005)−27 + 𝑥(1 + .005)−43 =
5,000,000. Solve for 𝑥.
7. Given a debt of 𝑄 at time 0 which is resolved by 𝑛 equal payments of amount 𝑥 with
periodic interest rate 𝑖, determine 𝑥. Hint: Using the concept of equivalent payments/debts
with the focal date being time 0, we get the equation 𝑄 = 𝑥(1 + 𝑖)−1 + 𝑥(1 + 𝑖)−2 + ⋯ +
𝑥(1 + 𝑖)−𝑛 . Use the formula for the sum of a geometric series and then solve for 𝑥. We will
return to this problem in Section 4.3.1.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 28

4 Annuities
4.1 Terminology
An annuity is a series of payments, usually (but not necessarily) made at equal intervals of time and
in equal amounts. The time between successive payments of an annuity is called the payment
interval (or period). The time from the beginning of the first payment interval to the end of the last
payment interval is referred to as the term of an annuity.
When the dates of the first and the last payments of an annuity are fixed, the annuity is called an
annuity certain. When the term of the annuity depends on some uncertain event (e.g., death of the
annuity’s holder), the annuity is called a contingent annuity.
When payment is made at the end of each payment interval, the annuity is called an ordinary
annuity (or immediate annuity). When payment is made at the beginning of each payment interval,
the annuity is called an annuity-due. A deferred annuity is an ordinary annuity whose first payment
is due at a later date.
When the beginning and end of the payment interval, and the interest compounding period
coincide, the annuity is called a simple annuity (e.g., the mortgages defined in Section 5.1 are
simple annuities); otherwise, it is a general annuity.
The accumulated (or future) value of an annuity is the value of the recurring payments to an
annuity at a certain date in the future, assuming a particular rate of return. The discounted (or
present) value of an annuity is the current value of future payments of an annuity, given a
specified rate of return, or discount rate. The higher the discount rate, the lower the present value
of the annuity.

4.2 Accumulated Value of Ordinary, Simple, Certain Annuities

4.2.1 Concept and Formulas


Consider an annuity where an amount R is added (by the entity buying the annuity) at the end of
each period, interest is compounded at the end of each period, the interest rate is 𝑖 (per period)
and there are 𝑛 periods. The payment schedule for such an annuity is shown in Figure 5.

Figure 5. Payment Schedule for Accumulated Value of Ordinary, Simple, Certain Annuities

No interest is earned on the contribution at the end of period 𝑛 since that is the end of the
annuity’s term. The contribution at the end of period 𝑛 − 1 earns interest 𝑖𝑅 and so its
accumulated value at the end of the annuity’s term is 𝑅 + 𝑖𝑅 = 𝑅(1 + 𝑖). The accumulated value
for the contributions is summarized in Table 2.

©2020 The Art of Managing Things


All Rights Reserved
29 Financial Math with Python

Table 2. Accumulated Value of an Ordinary, Simple, Certain Annuity

End of Period Accumulated Value of Given Investment


𝑛 𝑅
𝑛−1 𝑅 + 𝑖𝑅 = 𝑅(1 + 𝑖)
𝑛−2 𝑅(1 + 𝑖) + 𝑖𝑅(1 + 𝑖) = 𝑅(1 + 𝑖)2
… …
1 𝑅(1 + 𝑖)𝑛−1

The value of the annuity at term is the sum (call it 𝑆) of the following geometric series:
𝑆 = 𝑅 + 𝑅(1 + 𝑖) + 𝑅(1 + 𝑖)2 + ⋯ + 𝑅(1 + 𝑖)𝑛−1
(1 + 𝑖)𝑛 − 1 (𝟏 + 𝒊)𝒏 − 𝟏
=𝑅 =𝑹
(1 + 𝑖) − 1 𝒊
(1+𝑖)𝑛 −1
[Remark concerning notation: the quantity 𝑖
is often represented by a shorthand notation in
financial books and articles. The notation is usually some variation of 𝑠𝑛|𝑖 .]

4.2.2 Examples
For example, Mr. Munch agrees to an annuity savings plan from an investment company. Under the
plan, Mr. Munch will contribute $300 at the end of each month for a period of three years. Interest
is compounded at the end of each month at a nominal annual rate of 6%. How much is the annuity
worth at term?
.06
We have at 𝑅 = 300, 𝑛 = 3(12) = 36 and 𝑖 = 12
= .005. Using the accumulated value formula
for an annuity gives the following result:
1.00536 − 1
𝑆 = 300 = $11,800.83
. 005
Mr. Munch reconsiders and tells that investment company that he really needs about $15,000 to
buy a car in three years and would like to know how much he needs to save each month to reach
that goal under the same conditions as stated above.
In this case, we need so solve for R given 𝑆 = 15,000, 𝑛 = 36 and 𝑖 = .005. We first solve the
accumulation formula for R to get
𝒊𝑺
𝑹=
(𝟏 + 𝒊)𝒏 − 𝟏
We then substitute the specific values for the problem at hand into the above formula and get the
following result
(.005)(15,000)
𝑅= ≅ $381.33
1.00536 − 1

In yet another variation of the problem, assume Mr. Munch wants to limit his monthly payment to
$300 but is willing to wait longer to reach his goal of $15,000. In this scenario, we need to solve the
(1+𝑖)𝑛 −1
equation 𝑆 = 𝑅 𝑖
for 𝑛. With some rearrangement of the equation, we get

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 30

𝑖𝑆
+ 1 = (1 + 𝑖)𝑛
𝑅
Take the natural log on both sides and the equation, and then isolation 𝑛 to get:
𝒊𝑺
𝐥𝐧( 𝑹 + 𝟏)
𝒏=
𝐥𝐧(𝟏 + 𝒊)
For the problem at hand, we get 𝑛 = 44.74 which we need to round-up to the next whole number,
i.e., 45 payments of $300 are required at the given interest rate for the annuity to surpass $15,000
at term.

4.2.3 Blocking
Especially for longer-term annuities, the entity offering the annuity is not likely to provide a fixed
interest rate for the entire term of the annuity. The investment entity may vary the rate based on
something like the 30-year United States treasury bond interest rate. In such cases, the
computation of the annuity’s value needs to be blocked into several computations.

[Link] Example
An example will illustrate the point. Ms. Gold agrees to an annuity savings plan from a bank that
stipulates a deposit of $500 at the end of each month for 10 years. The interest rate is based on the
average 30-year treasury bond rate for the past month. For the first 5 years (60 deposits), the
nominal annual rate for the annuity was 3% and for the last 5 years, the nominal annual rate was
3.5%. How much was the annuity worth at term, assuming Ms. Gold has contributed the agreed
$500 per month?
We first compute value of the annuity at the end of the initial 5 years (call it 𝑆1 ):
. 03
(1 + 12 )60 − 1
𝑆1 = 500 = $32,323.36
. 03
12
Next, compute the value of the contributions to the annuity during the second 5 years (call it 𝑆2 ):
. 035
(1 + 12 )60 − 1
𝑆2 = 500 = $32,733.06
. 035
12
We are not done because it is necessary to consider the interest accrued to 𝑆1 during the second 5
.035
years of the annuity, which is 𝑆1 (1 + 12 )60 = $38,495.27
So, the total value of the annuity at term is $32,733.06 + $38,495.27 = $71,228.33, while Ms.
Gold contributed a total of 120 × $500 = $60,000.
In a variation of the above problem, assume the term is changed to 15 years with the first 10 years
being as before but for the last five years the nominal interest rate is 6% (compounded monthly).
Further, Ms. Gold does not make further contributions beyond the first 10 years. In this scenario,
we simply need to compound $71,716.26 for another 5 years, i.e.,
. 06 60
$71,228.33(1 + ) = $96,076.34
12

©2020 The Art of Managing Things


All Rights Reserved
31 Financial Math with Python

[Link] Generalization
Blocking can be made even more general than what is suggested in the above example. Each block
can have a different interest rate per period, a different payment per period and a different
number of periods. So, each block is defined by three variables, i.e., interest rate, payment amount
and number of periods. If either the interest rate or payment amount changes, we start a new
block. So, these two attributes (i.e., interest rate and payment amount) determine the third
variable (i.e., number of periods in a block).
The following algorithm can be used to determine the final value of an annuity with 𝑚 blocks:
1. For each of the 𝑚 blocks, compute the accrued value of the annuity for the interval when
the block is active. This is done using the formula below for block 𝑘. The subscript 𝑘 is put
on 𝑖, 𝑅 and 𝑛 to emphasize these values can change for each block.
(1 + 𝑖𝑘 )𝑛𝑘 − 1
𝑆𝑘 = 𝑅𝑘
𝑖𝑘
2. For each 𝑆𝑘 (𝑘 = 1,2, … , 𝑚 − 1), the value continues to accrue during subsequent blocks,
based on the interest rate and number of periods for each subsequent block. So, the value
at the end of the annuity for block 𝑘 is
𝑉𝑘 = 𝑆𝑘 (1 + 𝑖𝑘+1 )𝑛𝑘+1 (1 + 𝑖𝑘+2 )𝑛𝑘+2 … (1 + 𝑖𝑚 )𝑛𝑚
3. Since there is no further accumulation of interest after the last block is finished, we have
that 𝑉𝑚 = 𝑆𝑚 .
4. The total value of the annuity at term is 𝑉 = 𝑉1 + 𝑉2 + ⋯ + 𝑉𝑚−1 + 𝑆𝑚

4.3 Discounted (Present) Value of Ordinary, Simple, Certain Annuities

4.3.1 Concept and Formulas


Consider a scenario in which someone purchases an annuity up front and then gets constant
payments in the amount 𝑅 at the end of each of 𝑛 periods. At the end of period 𝑛, the value of the
annuity is 0. The interest rate per period is 𝑖.
In order to cover the first payment (end of period #1), how much needs to be invested at beginning
of period 1? If we call this quantity 𝑥1 , then we need to solve 𝑥1 + 𝑥1 𝑖 = 𝑅 for 𝑥1 . This gives us
𝑥1 = 𝑅(1 + 𝑖)−1 . So, 𝑥1 invested at the time 0 will be worth 𝑅 at the end of the first period. This is
basically a present value calculation for a future desired amount.
In general, we need to calculate the present value for each of the 𝑛 pays of amount 𝑅 and then
sum the amounts, i.e.,
𝑄 = 𝑅(1 + 𝑖)−1 + 𝑅(1 + 𝑖)−2 + ⋯ + 𝑅(1 + 𝑖)−𝑛
= 𝑅(1 + 𝑖)−1 {1 + (1 + 𝑖)−1 + [(1 + 𝑖)−1 ]2 + ⋯ + [(1 + 𝑖)−1 ]𝑛−1 }
Noting that the above is the sum of a geometric series with 𝑎 = 𝑅(1 + 𝑖)−1 and 𝑟 = (1 + 𝑖)−1 , we
get the following equation
1 − (1 + 𝑖)−𝑛
𝑄 = 𝑅(1 + 𝑖)−1
1 − (1 + 𝑖)−1
1+𝑖
Multiplying by 1+𝑖 and some simplification results in the following formula

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 32

𝟏 − (𝟏 + 𝒊)−𝒏
𝑸=𝑹
𝒊
So, an initial investment in the amount of 𝑄 with interest rate 𝑖 per period (compounded at the end
of each period) is equivalent to 𝑛 payments in the amount 𝑅 at the beginning of each period.
(Recall Exercise 7 from Section 3.10.)
Alternately, the above formula can be solved for R in terms of the other variables to get
𝒊𝑸
𝑹=
𝟏 − (𝟏 + 𝒊)−𝒏
This is useful if one knows the interest rate, desired number of distributions and the initial
investment, and wants to determine how much can be distributed at the end of each period.
We can also solve for 𝑛 to determine how long an initial investment will last given the distribution
amount per period and interest rate, i.e.,
𝒍𝒏 𝑹 − 𝒍𝒏(𝑹 − 𝒊𝑸)
𝒏=
𝒍𝒏(𝟏 + 𝒊)
where 𝑙𝑛(𝑥) is the natural log of 𝑥 (i.e., log base 𝑒).
1−(1+𝑖)−𝑛
[Remark concerning notation: the quantity 𝑖
is often represented by a shorthand notation
in financial books and articles. The notation is usually some variation of 𝑎𝑛|𝑖 .]

4.3.2 Examples
What initial investment is needed to get a monthly payment of $750 for 20 years given a nominal
yearly interest rate of 5% (compounded monthly)?
.05
We are given 𝑅 = $750, 𝑛 = 12 × 20 = 240 and 𝑖 = 12
. Using the formula for 𝑄, we get

. 05 −240
1 − (1 + )
𝑄 = 750 12 = $113,643.98
. 05
12
As a second example, consider someone who has $100,000 to invest in an annuity with a nominal
annual interest rate of 4% (compounded monthly) and wants to have the annuity distribution
monthly for 15 years. How much can be distributed each month for the given period?
In this scenario, we are given 𝑄 = $100,000, 𝑛 = 12 × 15 = 180 and 𝑖 = .04/12, and we need to
determine 𝑅.
. 04
𝑖𝑄 ( )(100,000)
𝑅= = 12 = $739.69
1 − (1 + 𝑖) −𝑛 . 04 −180
1 − (1 + )
12
In yet another example, we want to find the number of quarters (i.e., quarter-years) that an
investment in the amount of $27,976.08 will last, given equal quarterly payments in the amount of
$1000 with a quarterly interest rate of .013.
We are given 𝑅 = $1,000, 𝑄 = $27,976.08 and 𝑖 = .013, and want to find n (the number of
quarters) the investment will last. Using the formula for n from the previous subsection, we get

©2020 The Art of Managing Things


All Rights Reserved
33 Financial Math with Python

𝑙𝑛 𝑅 − 𝑙𝑛(𝑅 − 𝑖𝑄) ln(1,000) − ln (1,000 − (. 013)(27,976.08))


𝑛= = = 35
𝑙𝑛(1 + 𝑖) ln (1 + .013)
So, the annuity can payout $1,000 per quarter for 35 quarters or 8 years and 9 months.
(In most cases, the value of n will not be a whole number. In such cases, the final payment will be
less than the previous recurring payments.)

4.4 Annuities Due


In an annuity-due, the periodic payments are due at the beginning of each payment interval. The
term of an annuity-due starts at the time of the first payment and ends one payment period after
the date of the last payment. The payment schedule for an annuity due is shown in Figure 6.

Figure 6. Payment Schedule for an Annuity Due

The accumulated (or future) value of an annuity-due at term is similar to the formula for 𝑆 in
Section 4.2.1, except that interest is earned on each contribution for one additional period. So, we
need to multiple the formula for the accumulated value of an ordinary, simple, certain annuity by
(1 + 𝑖) to get the accumulated value for an annuity due:
(1 + 𝑖)𝑛 − 1
(1 + 𝑖)𝑅
𝑖
which can be written as
(𝟏 + 𝒊)𝒏+𝟏 − (𝟏 + 𝒊)
𝑹
𝒊
The discounted (or present) value of an annuity-due is similar to the formula for 𝑄 in Section 4.3.1,
except that all the payments are done at the beginning of each period. So, the discounted value of
an annuity-due is
𝑅 + 𝑅(1 + 𝑖)−1 + 𝑅(1 + 𝑖)−2 + ⋯ + 𝑅(1 + 𝑖)−(𝑛−1)
= 𝑅[1 + (1 + 𝑖)−1 + (1 + 𝑖)−2 + ⋯ + (1 + 𝑖)−(𝑛−1) ]
𝟏 − (𝟏 + 𝒊)−𝒏
=𝑹
𝟏 − (𝟏 + 𝒊)−𝟏
Note that the above is just (1 + 𝑖) times the formula for discounted (present) value of an ordinary,
simple, certain annuity.

4.5 Deferred Annuities


As noted earlier, a deferred annuity is an ordinary annuity where the first payment is made after a
given number of periods 𝑚. Take the example of two parents buying an annuity for their daughter’s
education. Assume the child is 11 years old when the annuity is purchased and there are no
payments back to the annuity owners until the child turns 18. In this case, the annuity is deferred
for 7 years (earning interest in the meantime) and the payments are made during the child’s time in

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 34

college (say 5 years). At the annuity’s term (12 years from time of purchase), all the money has
been distributed back to the parents who are presumably using the money to pay college bills for
their daughter.
In general, assume
• the annuity is purchased at time 0
• there are to be 𝑛 payments (to the owner of the annuity), each in the amount of 𝑅
• the payments start at the end of period m (i.e., at time m+1)
• the interest rate per period is 𝑖.
The scenario is summarized in Figure 7.

Figure 7. Deferred Annuity

To compute the overall present value (purchase price) of the annuity, we compute the present
value of each payment. To cover the first payment (at time 𝑚 + 1), how much needs to be invested
at time 0? If we call that quantity 𝑥1 , then we need to solve 𝑥1 (1 + 𝑖)𝑚+1 = 𝑅 for 𝑥1 . This gives us
𝑥1 = 𝑅(1 + 𝑖)−(𝑚+1) . So, 𝑥1 invested at the time 0 will be worth 𝑅 at time 𝑚 + 1. Using similar
reasoning, the present value of the second payment is 𝑅(1 + 𝑖)−(𝑚+2) , and so on. Thus, the
present value for the annuity is the sum
𝑄 = 𝑅(1 + 𝑖)−(𝑚+1) + 𝑅(1 + 𝑖)−(𝑚+2) + ⋯ + 𝑅(1 + 𝑖)−(𝑚+𝑛)
= 𝑅(1 + 𝑖)−(𝑚+1) [1 + (1 + 𝑖)−1 + (1 + 𝑖)−2 + ⋯ + (1 + 𝑖)−(𝑛−1) ]
𝟏 − (𝟏 + 𝒊)−𝒏
= 𝑹(𝟏 + 𝒊)−(𝒎+𝟏)
𝟏 − (𝟏 + 𝒊)−𝟏
If the interest rate is assumed to be different in the deferral period (call it 𝑗) from the rate during
the payment periods (call it 𝑖), then we get a more general equation for 𝑄. To be clear, it is
assumed the interest rate changes from 𝑖 to 𝑗 after the first payment. This is almost the same as
the previous equation, with the difference highlighted in bold.
1 − (1 + 𝑖)−𝑛
𝑄 = 𝑅(1 + 𝒋)−(𝑚+1)
1 − (1 + 𝑖)−1
Going back to the college expense savings example, we have the following inputs:
• 𝑚 + 1 = 7 × 12 = 84 and 𝑚 = 83
• 𝑛 = 5 × 12 = 60
.05
• 𝑖=𝑗= 12
̅ (assume interest is fixed over the entire term of the annuity)
= .00416

• assume that $2,500/month is needed during the child’s college years, so 𝑅 = $2,500.

©2020 The Art of Managing Things


All Rights Reserved
35 Financial Math with Python

Assuming payments and compounding are done monthly, and using the formula for 𝑄, we get
1 − (1 + 𝑖)−𝑛
𝑄 = 𝑅(1 + 𝑖)−(𝑚+1)
1 − (1 + 𝑖)−1
̅)−60
1 − (1.00416
̅)−84
= (2,500)(1.00416 = $93,811.97
̅)−1
1 − (1.00416
In a variation of the above scenario, assume that during the deferral interval, the interest rate is 6%
.06 .04
and 4% just after the payments start. Thus, 𝑗 = = .005 and 𝑖 = ̅ and using the second
= .003
12 12
formula for 𝑄, we get that 𝑄 = $89,583.59.

4.6 Forborne Annuities


In a forborne annuity, the annuity continues to earn interest after the last payment into the
annuity is made. We have already seen a forborne annuity in the variation of the example in
Section [Link].
There are two steps in calculating the accumulated value of a forborne annuity:
• Calculate the accumulated value at the time of the last payment using the formula from
(1+𝑖)𝑛 −1
Section 4.2.1, i.e., 𝑅 𝑖
, where 𝑖 is the interest rate per period, 𝑅 is the payment
amount (in the annuity per period) and 𝑛 is the number of payments.
• Calculate the interest earned while the annuity is held after the last payment into the
(1+𝑖)𝑛 −1
annuity, using the formula for compound interest where the principal is given by 𝑅 𝑖
.
Assuming the annuity is held for m periods after the last payment, the final accumulated
(1+𝑖)𝑛 −1
value of the annuity is 𝑅 𝑖
(1 + 𝑖)𝑚 .

4.7 General Annuities

4.7.1 Concept and Interest Conversion Formulas


In the case of general annuities, the compounding and payment periods do not coincide (unlike the
case for simple annuities). This problem can be solved by converting the general annuity into an
equivalent ordinary simple annuity where the compounding and payments are on the same
schedule.
In general, if compounding is done 𝑠 times per year at a rate of 𝑖, and payments are made 𝑡 times
per year, we want to know the equivalent interest rate to 𝑖 (call it 𝑗) if compounding is done 𝑡 times
per year. The problem is to solve for 𝑗 in the following equation
(1 + 𝑖)𝑠 = (1 + 𝑗)𝑡
1
Taking the 𝑡 power of both sides of the equation and then doing some rearrangement of terms
gives us the following formula
𝒋 = (𝟏 + 𝒊)𝒔/𝒕 − 𝟏
If interest is compounded continuously, then we need to solve 𝑒 𝑟∙1 = (1 + 𝑗)𝑡 in terms of 𝑗, where
1
𝑟 is the nominal annual interest rate. Taking the 𝑡 power of both sides of the equation gives

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 36

𝒋 = 𝒆𝒓/𝒕 − 𝟏
Alternately, one can solve for r to get
𝒓 = 𝒕 𝐥𝐧(𝟏 + 𝒋)
For example, 6% interest compounded monthly (i.e., 𝑡 = 12 and 𝑗 = .005) is equivalent to 𝑟 =
12 ln(1.005) = 0.05985 or 5.985% compounded continuously.

4.7.2 Example – Accumulated Value of a General Annuity


Compute the accumulated value of a general annuity with term 11 years, where the interest is
compounded 5 times per year at a nominal annual rate of 5%. Payments into the annuity are made
7 times per year in the amount of $1,000 per payment.
.05
Determine the interest rate per compounding period, i.e., 𝑖 = 5
= .01.
Determine the equivalent interest rate if compounding is done 7 times per year, i.e.,
5
𝑗 = (1 + .01)7 − 1 = 0.007132697
Use the formula for the accumulated value of a simple annuity (from Section 4.2.1) with per period
interest rate 0.007132697, 𝑛 = 11 × 7 = 77 and 𝑅 = 1000
(1 + 𝑗)𝑛 − 1 1.00713269777 − 1
𝑆=𝑅 = 1000 = $102,138.73
𝑗 . 007132697
This can be verified using the block annuity calculator with an input csv file containing the following
line:
.007132697, 1000, 77
Solve the same problem as above, except that the interest in compounded continuously. In this
.05
scenario, 𝑗 = 𝑒 𝑖/𝑡 − 1 = 𝑒 7 − 1 = 0.007168428 and 𝑆 = $102,289.23.
This can be verified using the block annuity calculator with an input csv file containing the following
line:
.007168428, 1000, 77

4.7.3 Example – Discounted (Present) Value of a General Annuity


Compute the discounted value of a general annuity with term 13 years, where the interest is
compounded 12 times per year at a nominal annual rate of 6%. Payments out of the annuity are
made 26 times per year in the amount of $500 per payment.
.06
Determine the interest rate per compounding period, i.e., 𝑖 = 12
= .005.
Determine the equivalent interest rate if compounding is done 26 times per year, i.e.,
12
𝑗 = (1 + .005)26 − 1 = 0.0023046
Use the formula for the discounted value of a simple annuity (from Section 4.3.1) with per period
interest rate 0.0023046, 𝑛 = 26 × 13 = 338 and 𝑅 = 500 to get

©2020 The Art of Managing Things


All Rights Reserved
37 Financial Math with Python

1 − (1 + 𝑗)−𝑛 1 − (1.0023046)−338
𝑄=𝑅 = 500 = $117,309.55
𝑗 . 0023046

4.8 Perpetuities
A perpetuity is an annuity in which regular payments begin on a fixed date and continue
indefinitely. It is sometimes referred to as a perpetual annuity.
The formula for a perpetuity is straightforward, i.e., an initial investment of 𝑆 at a per compounding
period interest rate of 𝑖 can payout 𝑅 = 𝑖𝑆 at the end of every period forever. If less than 𝑅 is paid
out per period, then the principal will increase and one can eventually increase the payout amount
(while still preserving the perpetuity). This could, for example, allow one to adapt for inflation.
In practice, such investment instruments are not offered. However, payments from an endowment
fund (e.g., for college scholarships) are similar in concept with the exceptions that the interest rate
is not guaranteed (based on multiple investments with varying returns), the endowment typically
increases based on new contributions from alumni, and only part of the investment returns are
typically distributed.

4.9 Continuous Annuities


A continuous annuity is a type of an annuity where payments are made continuously but interest is
compounded per some given period.

4.9.1 Discounted (Present) Value


To compute the present value formula for a continuous annuity, we start with a finite number of
payments 𝑚 within a given compounding period and then take the limit as 𝑚 approaches infinity.
To that end, start with an annuity that distributes 𝑛 payments in the amount of 𝑅 (𝑚 = 1 at this
point). Interest is compounded at the end of each period at the rate 𝑖. Recall from Section 4.3.1
that the current value of such an annuity is
𝑄 = 𝑅(1 + 𝑖)−1 + 𝑅(1 + 𝑖)−2 + ⋯ + 𝑅(1 + 𝑖)−𝑛
𝑅
Next, assume that 𝑚 payments in the amount of are made during each compounding period (see
𝑚
Figure 8).

Figure 8. Multiple Payments per Compounding Period

To determine the equivalent interest rate for each of the 𝑚 mini-periods, we use the formula 𝑗 =
1
(1 + 𝑖)𝑠/𝑡 − 1 (from Section 4.7.1) with 𝑠 = 1 and 𝑡 = 𝑚 to get 𝑗 = (1 + 𝑖)𝑚 − 1. Noting that there
are 𝑚𝑛 mini-periods (i.e., payments), the present value of the annuity with the m payments per
compounding period is given by

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 38

𝑅 𝑅 𝑅
𝑄𝑚 = (1 + 𝑗)−1 + (1 + 𝑗)−2 + ⋯ + (1 + 𝑗)−𝑚𝑛
𝑚 𝑚 𝑚
𝑅 1 2 𝑚𝑛
= [(1 + 𝑖)−𝑚 + (1 + 𝑖)−𝑚 + ⋯ + (1 + 𝑖)− 𝑚 ]
𝑚
𝑚𝑛
𝑅 𝑥
= ∑(1 + 𝑖)−𝑚
𝑚
𝑥=1

To get the formula for the present value of an annuity with a continuous number of payments in
each compound period, we take the limit of the above expression as 𝑚 goes to infinity, i.e.,
𝑚𝑛 𝑚𝑛 𝑛
𝑅 −
𝑥 1 −
𝑥
𝑄∞ = lim 𝑄𝑚 = lim ∑(1 + 𝑖) 𝑚 = 𝑅 lim ∑( )(1 + 𝑖) 𝑚 = 𝑅 ∫ (1 + 𝑖)−𝑥 𝑑𝑥
𝑚→∞ 𝑚→∞ 𝑚 𝑚→∞ 𝑚 0
𝑥=1 𝑥=1

The second summation in the above sequence is the right Reimann sum of the function (1 + 𝑖)−𝑥
1
from 0 to 𝑛. The typical Δ𝑥 (used in Riemann sums) is effectively replaced by which approaches
𝑚
zero as 𝑚 → ∞.
Solving the definite integral, we get
𝑛
−(1 + 𝑖)−𝑥 𝑥=𝑛 𝟏 − (𝟏 + 𝒊)−𝒏
𝑄∞ = 𝑅 ∫ (1 + 𝑖)−𝑥 𝑑𝑥 = 𝑅 [ ] =𝑹
0 ln(1 + 𝑖) 𝑥=0 𝐥𝐧(𝟏 + 𝒊)
If 𝑄∞ , 𝑖 and 𝑛 are known, we can solve for R, i.e.,
𝐥𝐧(𝟏 + 𝒊)
𝑹 = 𝑸∞
𝟏 − (𝟏 + 𝒊)−𝒏
As an example, consider two scenarios:
• Scenario A: Ordinary, simple, certain annuity with 𝑛 = 60 equal payments of $10,000 and
an interest rate of .5% per period
• Scenario B: Annuity with continuous payments over 𝑛 = 60 periods with an interest rate of
.5% per period. The continuous payments equal $10,000 in each period.
For Scenario A, the present value of the annuity is
1 − (1 + 𝑖)−𝑛 1 − 1.005−60
𝑄=𝑅 = 10,000 = $517,255.61
𝑖 . 005
For Scenario B, the present value of the annuity is
1 − (1 + 𝑖)−𝑛 1 − 1.005−60
𝑄∞ = 𝑅 = 10,000 = $518,547.67
ln(1 + 𝑖) ln(1.005)
The present value of the annuity in Scenario B is larger than the present value of the annuity in
Scenario A which is to be expected since payments are effectively distributed sooner in Scenario B.

©2020 The Art of Managing Things


All Rights Reserved
39 Financial Math with Python

4.9.2 Accumulated Value


It is also possible to accumulate value with continuous investments into the annuity. We first
𝑅
consider the case of 𝑚 mini-investments into the annuity in the amount of 𝑚 during each
compounding period. This is basically Figure 8 except that money is being added to the annuity
rather than removed. If the interest rate for each compounding period is 𝑖 then (using the same
1
calculation as in Section 4.9.1) the equivalent interest rate for the mini-period is 𝑗 = (1 + 𝑖)𝑚 − 1.
The accumulated value of the annuity is given by
𝑅 𝑅 𝑅 𝑅
𝑆𝑚 = + (1 + 𝑗) + (1 + 𝑗)2 + ⋯ + (1 + 𝑗)𝑚𝑛−1
𝑚 𝑚 𝑚 𝑚
𝑅 1 2 𝑚𝑛−1
= [1 + (1 + 𝑖)𝑚 + (1 + 𝑖)𝑚 + ⋯ + (1 + 𝑖) 𝑚 ]
𝑚
𝑚𝑛−1
𝑅 𝑥
= ∑ (1 + 𝑖)𝑚
𝑚
𝑥=0

To get the accumulated value of an annuity with continuous input investments, we take the limit as
𝑚 approaches infinity of 𝑆𝑚
𝑚𝑛−1 𝑚𝑛−1 𝑛
𝑅 𝑥 1 𝑥
𝑆∞ = lim 𝑆𝑚 = lim ∑ (1 + 𝑖)𝑚 = 𝑅 lim ∑ ( )(1 + 𝑖)𝑚 = 𝑅 ∫ (1 + 𝑖)𝑥 𝑑𝑥
𝑚→∞ 𝑚→∞ 𝑚 𝑚→∞ 𝑚 0
𝑥=0 𝑥=0

The second summation is the left Riemann sum of the function (1 + 𝑖)𝑥 from 0 to 𝑛, and thus
1
taking the limit as 𝑚 → ∞ (and 𝑚 → 0) yields the stated integral. Solving the definite integral, we
get
𝑛
𝑥
(1 + 𝑖)𝑥 𝑥=𝑛 (𝟏 + 𝒊)𝒏 − 𝟏
𝑆∞ = 𝑅 ∫ (1 + 𝑖) 𝑑𝑥 = 𝑅 [ ] =𝑹
0 ln(1 + 𝑖) 𝑥=0 𝐥𝐧(𝟏 + 𝒊)
As an example, compare the accumulated value of an ordinary, simple, certain annuity with 120
investments of $5,000 at an interest rate of .6% per period to a continuous investment annuity with
the same parameters.
For the ordinary, simple, certain annuity, the accumulated value is
(1 + 𝑖)𝑛 − 1 1.006120 − 1
𝑆=𝑅 = 5,000 = $875,015.05
𝑖 . 006
and for the continuous investment annuity, the accumulated value is
(1 + 𝑖)𝑛 − 1 1.006120 − 1
𝑆∞ = 𝑅 = 5,000 = $877,637.48
ln(1 + 𝑖) ln(1.006)
The accumulated value in the continuous case is slightly larger since money is deposited sooner,
i.e., during each compounding period rather than at the end of each compounding period.

4.10 Supporting Programs

4.10.1 Block Annuity Calculator


File name: block_annuity.py

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 40

This program computes the total value of a savings annuity over several blocks, where
• Each block has a fixed interest rate and fixed payment (i.e., investment) per period.
• The interest rate and payment amount may vary among the blocks.
• The blocks can be of different sizes, i.e., different number of periods.
There is no pop-up GUI for this program. The input and output are done via the terminal associated
with the Python code. For input to this program, a CSV file needs to be created (put this in the
same directory as the program file). The program will ask for the file name (leave off .csv when you
enter the file name). Each line of the CSV file represents one block of an annuity. The format for
each line is as follows:
interest rate per period, saving amount per period, number of periods
As an example, put the following lines in a CSV file and run the program:
0.0042, 500, 10
0.0033, 400, 25
0.0038, 300, 30
0.0045, 700, 15
0.0047, 200, 20
The output is as follows (this is displayed on the terminal associated with the Python code):
The value of each block without interest accrued during subsequent blocks:
Block 0: $5,095.57
Block 1: $10,406.20
Block 2: $9,513.95
Block 3: $10,837.29
Block 4: $4,183.74

The value of each block at the end of the annuity's term, i.e., with the interest accrued
during subsequent blocks:
Block 0: $7,283.76
Block 1: $13,698.88
Block 2: $11,177.33
Block 3: $11,902.79
Block 4: $4,183.74

Total value of the annuity at the end of its term:


$48,246.50

4.10.2 Annuity Payout Calculator


File name: simple_annuity_payout.py
This program does computations for ordinary, simple, certain annuities. It is assumed that the
compounding and the periodic payouts happen on the same schedule, e.g., at the end of each

©2020 The Art of Managing Things


All Rights Reserved
41 Financial Math with Python

month. The required input values are the initial investment amount in the annuity, the per period
interest rate (as a decimal, e.g., .05 rather than 5%), and either the desired number of payouts or
the amount of each payout (but not both).
• If, in addition to the required inputs, the number of payouts is provided, the program will
compute the amount of each payout.
• If, in addition to the required inputs, the desired amount of each payout is provided, the
program will compute the number of payouts until the annuity is depleted.
o If the desired payout amount is less than the accrued interest per period, the
payouts can continue indefinitely. In this case, the program will output “infinite” for
the number of payouts.
o If the desired payout amount is greater than the value of the original investment at
the end of the first period, then the payout is not possible and an error message is
generated (displayed on the terminal associated with the Python code).

4.10.3 Deferred Annuity Calculator


File name: deferred_annuity.py
This program does computations concerning deferred annuities. It is assumed that the
compounding and the periodic payouts are on the same schedule, e.g., at the end of each quarter.
The required input values are the interest rate per period, desired number of payouts and the
number of deferral periods.
• If initial investment is given, the amount of each payout will be computed.
• If the desired payout amount is provided, the program will compute the required initial
investment.
This program can be used to solve the example presented in Section 4.5. In the program, leave the
Initial Investment blank (as this is to be computed), enter .004166666 for the Interest per Period,
60 for the Number of Payouts, 84 for the Number of Deferral Periods and 2500 for the Amount of
Each Payout.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 42

4.11 Exercises
1. Mr. Periwinkle agrees to purchase an annuity from a bank (this is intended to be a savings
plan). He is to deposit $750 at the end of each month for 5 years, with a guaranteed
nominal annual interest rate of 3% (compounded monthly). How much is Mr. Periwinkle’s
annuity worth at term? Hint: Use the block annuity calculator with a single block. The input
is a csv file with just one line, i.e., .0025, 750, 60. Note that .0025 is the month rate based
on a 3% nominal annual interest rate.
2. Continuing with the previous exercise, assume the term and interest rate is the same but
Mr. Periwinkle asks the bank how much he would need to save each month to reach
$50,000 at the end of the term. Hint and Answer: Use the formula for 𝑅 in terms of 𝑖, 𝑆 and
𝑛 in Section 4.2.2. The answer is $773.44 (rounding up to the next cent). You can check the
answer using the block annuity calculator.
3. Joan and John Song are saving for a down payment on a house. An investment company has
offered them a savings annuity that pays a guaranteed nominal annual interest rate of 3%
(compounded monthly) for the first 30 months, which may change (depending on market
conditions) for the remaining 30 months of the annuity. However, it is guaranteed that the
interest rate will drop at most .5% during the second 30 months. The couple would like to
know how much the annuity will be worth at term if they invest $1,000 per month,
assuming the least optimistic interest rate for the second 30 months of the annuity, i.e.,
2.5%. Hint and Answer: Use the block annuity calculator with two blocks to determine that
the value of the annuity at term is $64,041.91.
4. In the previous example, assume that the Song’s really needed $75,000. If the term (5
years) and interest rates are the same, how much do they need to save each month to
reach their goal? Hint: Clearly, there are multiple possible answers here. One approach is to
increase the payment amount in the first block and leave the payment amount in the second
block at $1,000/month. Use the block annuity calculator and experiment with various
payment amounts for the first 30 months. For example, a monthly payment of $1,333 for
the first 30 months and $1,000/month in the second 30 months yields a final accrued value
of $75,070,14.
5. Mr. Trubisky has just retired early after a lucrative career as a professional athlete. He has
$10,000,000 in a savings account and would like to invest half of that amount in an annuity.
How long will the annuity last at 3% nominal annual interest rate (compounded monthly) if
he takes a payment of $50,000 per month? Hint: Use the simple annuity payout calculator.
6. After doing the computation, Mr. Trubisky realizes that his withdraw amount will last about
9.6 years. Given that he is now 35 years old, he wants the payouts to continue for 50 years.
With the interest rate conditions being the same, how much can Mr. Trubisky be paid each
month if the annuity is to last 50 years? Hint: Use the annuity payout calculator.
7. How can the block annuity calculator be used to calculate an annuity due where the
payments are made at the beginning of each period and there is one accrual period after
the last payment? Hint: Use two blocks, with the second block consisting of a $0 payment
but at the same interest rate as the first block.

©2020 The Art of Managing Things


All Rights Reserved
43 Financial Math with Python

8. Test out your methodology from Exercise 7 on the following annuity due: $150 payment (at
the beginning of each monthly payment period), for four years and at a nominal annual
interest rate of 6% (compounded monthly). Check your answer by using the formula for the
accumulated value of an annuity due in Section 4.4.
9. Milton invests $75,000 in a deferred annuity at a nominal annual interest rate of 4%
(compounded monthly) with the first of 90 payments to start in 5 years. Compute the
amount of the regular payments. Hint: use the deferred annuity calculator.
10. As a variation of the previous exercise, assume Milton wants to get payments of $1,175.50
per month for 90 payments with the first payment 5 years from now. How much money
does he need to invest up front in the deferred annuity? Hint: use the deferred annuity
calculator.
11. Modify the Python program for the deferred annuity calculator to support the case where
the interest rate during the time of deferral is different from the interest rate during the
payment periods. Hint: You need to add another input for the interest rate during the
deferral period, and then use that rate in the calculation of interest during the deferral
period.
12. Compute the accumulated value of a general annuity with term 13 years, where the
interest is compounded 7 times per year at a nominal annual rate of 7% and payments into
the annuity are made 23 times per year in the amount of $500 per payment. Hint: The
.07
interest rate per compounding period is 𝑖 = 7 = .01. If compounding is done at the same
7
rate as the payments, the equivalent rate is 𝑗 = (1 + .01)23 − 1 = .003032952. Next, use
the formula for the accumulated value of a simple annuity with per period interest rate 𝑗,
𝑛 = 13 × 23 = 299 and 𝑅 = 500. Check your answer with the block annuity calculator
using a csv file with the following line: .003032952,500,299.
13. Compare the present value of an ordinary, simple, certain annuity with 360 equal payments
of $2,000 at an interest rate of .005 per period with a continuous annuity of the same term,
payout, and interest rate. Hint: See the example in Section 4.9.1. Answer: $333,583.23 for
the ordinary, simple, certain annuity and $334,416.49 for the continuous annuity.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 44

5 Repayment of Loans
5.1 Amortization of Loans

5.1.1 General Formula and Equivalence to Annuities


“Amortization” refers to the distribution of payments into multiple equal installments where each
payment consists of both principal and interest. Amortization is mainly used in loan repayments
(e.g., home mortgages and car loans) and in sinking funds (i.e., money set aside over a period of
time to fund a future capital expense, or repayment of a long-term debt). Repayments are divided
into equal amounts for the duration of the loan. However, the amount of interest and principal
pay-back in each installment varies, as demonstrated in the example that follows below. This
process is known as Equated Monthly Installment (EMI).
(Note: In what follows, we say “payment” although technically it is a “repayment” of money that
had been previously loaned, since “payment” is the term more commonly used in the literature.)
Make the following assignments:
𝑃 = principal amount borrowed
𝐴 = equal periodic amortization payment
𝑖 = the interest rate per compounding period
𝑛 = total number of payment periods.
It is assumed that the compounding and payment periods coincide.
When doing the calculation, it is important to note that the loanee (person who receives the loan)
must pay back the amount of interest due at the end of each payment period.
At the end of the first payment period, the amount still owed to the loaner (“the balance”) is the
original principal plus the interest due for the first period minus the amount of principal paid back
by the loanee to the loaner, i.e.,
𝐵1 = 𝑃 + 𝑖𝑃 − 𝐴 = (1 + 𝑖)𝑃 − 𝐴
At the end of the second payment period, the balance is
𝐵2 = (1 + 𝑖)𝐵1 − 𝐴 = (1 + 𝑖)2 𝑃 − 𝐴(1 + 𝑖) − 𝐴
At the end of the third payment period, the balance is
𝐵3 = (1 + 𝑖)𝐵2 − 𝐴
= (1 + 𝑖)3 𝑃 − 𝐴(1 + 𝑖)2 − 𝐴(1 + 𝑖) − 𝐴
In general, after payment period 𝑘, the balance is
𝐵𝑘 = (1 + 𝑖)𝑘 𝑃 − 𝐴[(1 + 𝑖)𝑘−1 + ⋯ + (1 + 𝑖) + 1]
At the end of 𝑛 payment periods (for 𝑛 ≥ 1), the balance of the mortgage should be zero, i.e.,
0 = 𝐵𝑛 = (1 + 𝑖)𝑛 𝑃 − 𝐴[(1 + 𝑖)𝑛−1 + ⋯ + (1 + 𝑖) + 1]
which implies
(1 + 𝑖)𝑛 𝑃 = 𝐴[(1 + 𝑖)𝑛−1 + ⋯ + (1 + 𝑖) + 1]

©2020 The Art of Managing Things


All Rights Reserved
45 Financial Math with Python

Solving for A and noting that the terms in the square brackets constitute a geometric series whose
sum we know how to calculate from Section 2.1.2, we get
𝑖𝑃(1 + 𝑖)𝑛
𝐴=
(1 + 𝑖)𝑛 − 1
which can be rewritten as
𝒊𝑷
𝑨=
𝟏 − (𝟏 + 𝒊)−𝒏
The above formula should look familiar as it is equivalent to the formula for regular payments from
an ordinary, simple, certain annuity (see Section 4.3.1). A mortgage can be thought of as an annuity
(purchased by a lending institution such as a bank) from an individual. The discounted (present)
value of the annuity (𝑄) is the amount of the mortgage (𝑃), and the annuity payments (𝑅) are
essentially the periodic amortization payments (𝐴).

5.1.2 Breakdown of Interest versus Principal Repayment


As noted, each payment is a combination principal payback and interest payment where the sum of
the two is equal to A for each payment. However, the ratio of principal payback to interest
payment changes over time. At the end of each payment period, the interest owed is 𝑖 times the
amount of outstanding balance at the beginning of the period. Thus, the interest owed at the end
of period 𝑘 is given by the following formula:
𝑰𝒌 = 𝒊𝑩𝒌−𝟏 = 𝒊(𝟏 + 𝒊)𝒌−𝟏 𝑷 − 𝒊𝑨[(𝟏 + 𝒊)𝒌−𝟐 + ⋯ + (𝟏 + 𝒊) + 𝟏]
and of course, the amount of principal repayment at the end of period 𝑘 (call it 𝑅𝑘 ) is given by
𝑹𝒌 = 𝑨 − 𝑰𝒌
The interest owed at the end of period 𝑖 can also be represented recursively, i.e.,
𝑰𝒌 = (𝒊 + 𝟏)𝑰𝒌−𝟏 − 𝒊𝑨
which is convenient for programming purposes.
As an example, consider a 3-year loan on a car for $10,000 at a 3% annual interest rate where the
loanee pays back the loan on a monthly basis. In terms of the above formulas, 𝑃 = 10,000, 𝑖 =
3
100∗12
= .0025 and 𝑛 = 12 ∗ 3 = 36. Using the formula for equal periodic amortization payment
yields 𝐴 = $290.81. A breakdown (interest versus principal) for the first four repayments is given in
Table 3. Given the relatively short term of the loan, the principal payments outweigh the interest
payments from the start. For home mortgages (e.g., 30 years), the interest payments are greater
than principal payback at the beginning of the loan.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 46

Table 3. Interest-Principal Repayment Breakdown Example


Period Interest Owed Formula Interest to Principal to
be paid for be paid for
given period given period
1 𝐼1 = 𝑖𝑃 $25.00 $265.81
2 𝐼2 = 𝑖(1 + 𝑖)𝑃 − 𝑖𝐴 $24.34 $266.48
3 𝐼3 = 𝑖(1 + 𝑖)2 𝑃 − 𝑖𝐴(1 + 𝑖) − 𝑖𝐴 $23.67 $267.14
4 𝐼4 = 𝑖(1 + 𝑖)3 𝑃 − 𝑖𝐴(1 + 𝑖)2 − 𝑖𝐴(1 + 𝑖) − 𝑖𝐴 $23.00 $267.81

5.1.3 Rounding Mortgage Payments


It may be desirable to round upward (or downward) the periodic mortgage payments to the next
dollar or 10 dollar value, and then adjust the final payment downward (or upward). The algorithm
for doing this is as follows:
1. Determine the periodic payment 𝐴
2. Round 𝐴 up to the next dollar or 10 dollar value. Call this new value 𝐴̂.
3. Determine the penultimate balance assuming the amount 𝐴̂ was used for all past payments
as well as the penultimate payment and we have
(1 + 𝑖)𝑛−1 − 1
𝐵𝑛−1 = (1 + 𝑖)𝑛−1 𝑃 − 𝐴̂[(1 + 𝑖)𝑛−1 + ⋯ + (1 + 𝑖) + 1] = (1 + 𝑖)𝑛−1 𝑃 − 𝐴̂
𝑖
4. Calculate the adjusted last payment which is
(1 + 𝑖)𝑛 − (1 + 𝑖)
𝐵𝑛−1 + 𝑖𝐵𝑛−1 = (1 + 𝑖)𝐵𝑛−1 = (1 + 𝑖)𝑛 𝑃 − 𝐴̂
𝑖
Actually, one can go directly to the formula in Step 4 and skip Step 3, or do Step 3 and then just
multiple by (1 + 𝑖).

As an example, consider a $200,000 mortgage at a 6% nominal annual interest rate with payments
due each month. The term of the mortgage is short (just 10 years). The 6% nominal annual interest
.06
rate means the monthly interest rate is 12
= .005.

The monthly payment is 𝐴 = $2,220.41 which we round up to 𝐴̂ = $2,221. Using the formula from
Step 4 in the above algorithm gives us the amount of the final payment:
(1 + 𝑖)𝑛 − (1 + 𝑖) (1.005)120 − 1.005
(1 + 𝑖)𝑛 𝑃 − 𝐴̂ = (1.005)120 (200,000) − (2,221) = $2,124.32
𝑖 1.005
Alternately, we could round the payments to the nearest multiple of $10 ($2,220 in this case) and
then calculate the final payment, i.e., $2,287.20 which as one would expect, is slightly higher than
the other 119 payments of $2,220.
We could even round to the nearest multiple of $100 (i.e., $2,200) and compute the final payment,
i.e., $5,544.78.
In terms of rounding down, keep in mind that the loanee is expected to pay at least the amount of
interest owned each period, and so we cannot go beyond that limit.

©2020 The Art of Managing Things


All Rights Reserved
47 Financial Math with Python

In terms of rounding up, it is possible to round up to the point where some of the last several
payments are not needed since all the principal is already paid off.

5.2 Balloon Loans

5.2.1 Concept and Formulas


In Section 3.1, an example of a balloon loan was given. In the example, payment of all principal was
deferred until the last payment of the loan. All the intermediate payments only entailed interest
payment on the initial principal 𝑃. In the more general case, an amount 𝐵 (less than or equal to the
original principal) is made at the last payment. The loanee does, in some scenarios, repay some of
the principle along the way (i.e., 𝑃 – 𝐵).
In the following calculations, the terms 𝐴, 𝑃, 𝐵𝑛 and 𝑖 are as defined in Section 5.1.1. It is assumed
that 𝑛 equals payments are made in the amount 𝐴 and then a final payment in the amount of 𝐵 (at
the same time as the nth payment).
Relying on the derivation from Section 5.1.1, at the end of 𝑛 periods (for 𝑛 ≥ 1, the total amount
owed to the loaner should be 𝐵 (the balloon payment). Using this fact, we solve for A in the
equations below:
𝐵 = 𝐵𝑛 = (1 + 𝑖)𝑛 𝑃 − 𝐴[(1 + 𝑖)𝑛−1 + ⋯ + (1 + 𝑖) + 1]
(1 − (1 + 𝑖)𝑛 )
𝐵 = (1 + 𝑖)𝑛 𝑃 − 𝐴
−𝑖
((1 + 𝑖)𝑛 − 1)
𝐴 = (1 + 𝑖)𝑛 𝑃 − 𝐵
𝑖
𝒊𝑷(𝟏 + 𝒊)𝒏 − 𝒊𝑩
𝑨=
(𝟏 + 𝒊)𝒏 − 𝟏
If 𝐴, 𝑖, 𝐵 and 𝑛 are known, the above equation can be solved for 𝑃:
𝐴[(1 + 𝑖)𝑛 − 1] + 𝑖𝐵
𝑃=
𝑖(1 + 𝑖)𝑛
which can also be written as
𝟏 − (𝟏 + 𝒊)−𝒏
𝑷=𝑨 + 𝑩(𝟏 + 𝒊)−𝒏
𝒊
If 𝐵 = 0, the formula for A is the same as for a non-balloon mortgage. If 𝐵 = 𝑃 (all the principal is
paid at the end of the term), then
𝑖𝑃(1 + 𝑖)𝑛 − 𝑖𝑃
𝐴= = 𝑖𝑃
(1 + 𝑖)𝑛 − 1
which is to be expected since one is only paying interest during the course of the loan, with the
principal repayment deferred until the end of the loan.
There are variants on the assumptions for balloon loans which lead to slightly different formulas for
𝐴. For example, one could assume that 𝑛 payments in the amount of 𝐴 are made, followed by
payment 𝑛 + 1 in the amount of 𝐵. In this case, 𝐵 = 𝐵𝑛 + 𝑖𝐵𝑛 = 𝐵𝑛 (1 + 𝑖) which when solved for
A leads to

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 48

𝒊𝑷(𝟏 + 𝒊)𝒏 𝒊𝑩
𝐴= 𝒏
− 𝒏+𝟏
(𝟏 + 𝒊) − 𝟏 (𝟏 + 𝒊) − (𝟏 + 𝒊)

5.2.2 Example – Balloon Loan as a General Annuity


A car loan stipulates payments of $500 at the end of each quarter for 5 years, with an additional
payment of $7,000 at the end of 5 years. What is the present value of the loan at a 6% nominal
annual interest rate (compounded monthly)?
.06
The monthly rate is 𝑖 = 12
= .005 which can be converted to an equivalent quarterly rate as
12
follows: 𝑗 = (1 + 𝑖)𝑠/𝑡 − 1 = 1.005 4 − 1 = 0.015075125
We are essentially being asked to work backwards and find the cost of the car, given payments
(𝐴 = 500), interest rate (𝑗 = 0.015075125), the balloon amount (𝐵 = 7,000) and the number of
payment (𝑛 = 20). Using the formula for P from Section 5.2.1 yields
𝐴[(1 + 𝑗)𝑛 − 1] + 𝑗𝐵 500[. 01507512520 − 1] + (.015075125)(7,000)
𝑃= = = $13,767.57
𝑗(1 + 𝑗)𝑛 (.015075125)(. 01507512520 )

5.3 Computation of Remaining Balance on a Loan


In Section 5.1.1, we used a retrospective method to determine the balance on a loan at the end of
a given period. In the formula below, 𝐵𝑘 is the accumulated value of the debt at time 𝑘 minus the
accumulated value of the payments at time 𝑘. This difference is the balance owed at time 𝑘.
𝐵𝑘 = (1 + 𝑖)𝑘 𝑃 − 𝐴[(1 + 𝑖)𝑘−1 + ⋯ + (1 + 𝑖) + 1]
applying the formula for the sum of a geometric series to the above, we get the more compact
form
(𝟏 + 𝒊)𝒌 − 𝟏
𝐵𝑘 = (𝟏 + 𝒊)𝒌 𝑷 − 𝑨
𝒊
Another approach (the prospective method) is to sum the present (discounted) value of the
remaining 𝑛 − 𝑘 payments, i.e.,
𝐵𝑖 = 𝐴(1 + 𝑖)−1 + 𝐴(1 + 𝑖)−2 + ⋯ + 𝐴(1 + 𝑖)−(𝑛−𝑘)
𝐵𝑖 = 𝐴(1 + 𝑖)−1 [1 + (1 + 𝑖)−1 + ⋯ + (1 + 𝑖)−(𝑛−𝑘)−1 ]
1 − (1 + 𝑖)−(𝑛−𝑘)
𝐵𝑖 = 𝐴(1 + 𝑖)−1
1 − (1 + 𝑖)−1
𝟏 − (𝟏 + 𝒊)−(𝒏−𝒌)
𝑩𝒊 = 𝑨
𝒊
The first formula works even if the final payment is irregular (e.g., a balloon payment) while the
second formula does not work in that case. However, the second formula works even when the
original amount of the loan is unknown.
The two formulas are algebraically equivalent, as is shown below:
At the end of the loan (focal date), the dated value of the debt minus the dated value of the
payments should equal zero, i.e.,
0 = (1 + 𝑖)𝑛 𝑃 − 𝐴[(1 + 𝑖)𝑛−1 + ⋯ + (1 + 𝑖) + 1]

©2020 The Art of Managing Things


All Rights Reserved
49 Financial Math with Python

which is equivalent to
(1 + 𝑖)𝑛 − 1
(1 + 𝑖)𝑛 𝑃 = 𝐴
𝑖
The above can be rewritten as
1 − (1 + 𝑖)−𝑛
𝑃=𝐴
𝑖
1−(1+𝑖)−𝑘
Subtracting 𝐴 from both sides, we get
𝑖

1 − (1 + 𝑖)−𝑘 1 − (1 + 𝑖)−𝑛 1 − (1 + 𝑖)−𝑘 (1 + 𝑖)−𝑘 − (1 + 𝑖)−𝑛


𝑃−𝐴 =𝐴 −𝐴 =𝐴
𝑖 𝑖 𝑖 𝑖
Multiplying by (1 + 𝑖)𝑘 yields
(1 + 𝑖)𝑘 − 1 1 − (1 + 𝑖)−(𝑛−𝑘)
𝑃(1 + 𝑖)𝑘 − 𝐴 =𝐴
𝑖 𝑖
Thus, the two formulas for 𝐵𝑘 are algebraically equivalent.

5.4 Refinancing a Loan


When interest rates drop, it is not unusual for folks with existing mortgages to consider refinancing.
Refinancing entails the termination of an existing mortgage (perhaps with a penalty to pay) and the
initiation of a new mortgage (which will also involve various costs, e.g., legal fees, application fee,
title search, local taxes, and appraisal fee). A typical goal for the borrower is to lower their monthly
payments and to lower the amount of interest paid for the remainder of the mortgage (i.e., from
the time of refinancing).
For example, the Butterfields have a $300,000, 30-year mortgage which is paid back to the bank on
a monthly basis at a rate of .005 per month (6% nominal annual rate). They can now (exactly 5
̅ per
years into their initial mortgage) get a 30-year mortgage at 4% nominal annual rate (. 003
month). Assume the total cost of terminating the existing mortgage and getting a new mortgage is
$6,000. Does it make sense for the Butterfields to refinance?
To answer the question, we first compute the monthly payment for the existing mortgage (which is
$1,798.65) and the balance on the initial mortgage (which is $279,163.07).
So, the new mortgage would need to be in the amount of $279,163.07. At the stipulated interest
rate and term, the new mortgage would entail monthly payments of $1,332.76.
• The remaining payments for the initial loan (over the next 25 years), if not refinanced, equal
$539,595.47 of which $260,432.40 are interest payments.
• The payments in the refinancing scenario, which includes the costs to terminate the initial
loan and to initiate the new loan, equal $485,793.87. The interest paid in this scenario is
$206,630.80.
Assuming the Butterfields are not going to sell their house before they recover the $6,000 in
refinancing costs (which will take 13 months), it makes sense to refinance.
A relevant question is “at what interest rate does it make sense to refinance?” Table 4 shows the
total payments (for the new loan) and payments per period (in this case, per month) for various
interest rates, starting with the interest rate for the existing mortgage. As one can see, the total

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 50

payments (for the new loan) are less than that for the remaining part of the existing loan up to a
nominal annual interest rate of up to a little more than 5.86% but less than 5.92%.
The first line of the Table 4 below is the status quo, i.e., keep the existing loan and do not
refinance. The amount listed under “total payments” in the first line is actually about left to be paid
under the conditions of the existing loan.
Table 4 was generated by the “Loan Refinance - Breakeven Interest Rate Analyzer”, see Section
5.5.5 for a description of this program.

Table 4. Interest Rate Analysis for Refinancing


Interest Rate per Nominal Annual Total Payments Payment per
Period Interest Rate Period
0.005000 6.00% $539,595.47 $1,798.65
0.003333 4.00% $448,057.64 $1,473.53
0.003383 4.06% $450,836.89 $1,482.79
0.003433 4.12% $453,625.56 $1,492.09
0.003483 4.18% $456,423.60 $1,501.41
0.003533 4.24% $459,230.99 $1,510.77
0.003583 4.30% $462,047.70 $1,520.16
0.003633 4.36% $464,873.71 $1,529.58
0.003683 4.42% $467,708.98 $1,539.03
0.003733 4.48% $470,553.47 $1,548.51
0.003783 4.54% $473,407.17 $1,558.02
0.003833 4.60% $476,270.04 $1,567.57
0.003883 4.66% $479,142.04 $1,577.14
0.003933 4.72% $482,023.16 $1,586.74
0.003983 4.78% $484,913.35 $1,596.38
0.004033 4.84% $487,812.58 $1,606.04
0.004083 4.90% $490,720.82 $1,615.74
0.004133 4.96% $493,638.05 $1,625.46
0.004183 5.02% $496,564.21 $1,635.21
0.004233 5.08% $499,499.30 $1,645.00
0.004283 5.14% $502,443.26 $1,654.81
0.004333 5.20% $505,396.07 $1,664.65
0.004383 5.26% $508,357.69 $1,674.53
0.004433 5.32% $511,328.09 $1,684.43
0.004483 5.38% $514,307.24 $1,694.36
0.004533 5.44% $517,295.10 $1,704.32
0.004583 5.50% $520,291.63 $1,714.31
0.004633 5.56% $523,296.80 $1,724.32
0.004683 5.62% $526,310.59 $1,734.37
0.004733 5.68% $529,332.94 $1,744.44
0.004783 5.74% $532,363.83 $1,754.55

©2020 The Art of Managing Things


All Rights Reserved
51 Financial Math with Python

Interest Rate per Nominal Annual Total Payments Payment per


Period Interest Rate Period
0.004833 5.80% $535,403.22 $1,764.68
0.004883 5.86% $538,451.07 $1,774.84
0.004933 5.92% $541,507.36 $1,785.02

5.5 Supporting Programs

5.5.1 Annuity Payout Calculator


As described in Section 4.10.2

5.5.2 Amortization Calculator


File name: [Link]
The program offers three different capabilities
• Compute the periodic payments on a mortgage given the loan amount, annual interest rate
(but leave off the percentage sign), number of payments per year and the length of the loan
in years (doesn't need to be a whole number).
• Compute the maximum affordable loan given the interest rate per year, number of
payments per year, length of the loan in years and the maximum affordable payment per
period.
• Compute the interest versus principal payback breakdown given the loan amount, interest
rate, number of payments per year and the length of the loan in years. The result is sent to
a file named [Link] (in the same directory as the program). The name of the output
file can be changed by editing the Python program on line 106.

5.5.3 Balloon Loan Calculator


File name: balloon_loan.py
This calculator offers two capabilities, i.e.,
• Compute the periodic payment amount for a balloon loan given the loan amount, interest
rate per period (as a decimal, e.g., .03 for 3%), total number of payments and the amount
of the balloon payment.
• Compute the present value (initial amount of loan) of a balloon loan given the interest rate
per period, total number of payments, the amount of the balloon payment and the amount
of a periodic payment.

5.5.4 Loan Refinance Calculator


File name: loan_refinance.py
This program analyzes the refinancing of a loan (such as a mortgage) given the following input:
• the amount of the initial (existing loan)
• interest rate per period for the initial loan (as a decimal, e.g., .03 for 3%)

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 52

• number of periods in the initial loan


• number of periods completed in the initial loan when refinancing
• penalties on termination of initial loan and financing cost for the new loan
• interest rate per period for the refinanced loan
• number of periods for the refinanced loan. There is not an assumption that the number of
periods in the refinanced loan equal the number of periods left in the original loan. For
example, you can start with a 30 loan, and refinance after 10 years with say a 15 year loan.
It is assumed that the period for the original loan (e.g., a month) is the same as the period for the
new loan.
The output gives decision information concerning whether to refinance or not.
For example, take the following as input to the program (exactly as-is, e.g., no commas or
percentage signs):
Amount of initial loan: 300000
Interest rate per period for initial loan: .005
Number of periods for initial loan: 360
Number of periods completed in initial loan: 60
Penalties and refinancing costs: 6000
New interest rate per period: .0033
Number of periods for new loan: 360
The result from the program is as follows:
The balance on the initial loan is $279,163.07
The periodic payment for the initial loan is $1,798.65
The periodic payment for the new loan is $1,326.34
The remaining payments for initial loan, if not refinanced, equal $539,595.47
of which $260,432.40 are interest payments.
The payments in the refinancing scenario, which includes the costs to
terminate the initial loan and to initiate the new loan, equal $483,481.54
The interest paid in this scenario is $204,318.47
It will take 13 periods to recover the cost of refinancing.

5.5.5 Loan Refinance - Breakeven Interest Rate Analyzer


File name: loan_refinance_int_rate_analyzer.py
This program analyzes the refinancing of a loan (such as a mortgage) given
• the amount of the initial (existing loan)
• interest rate per period for the initial loan (as a decimal, e.g., .03 for 3%)
• number of periods in the initial loan

©2020 The Art of Managing Things


All Rights Reserved
53 Financial Math with Python

• number of periods that have transpired in the initial loan when the new loan is to start
• the amount of penalties on termination of the initial loan plus the cost of the new loan
• interest rate per period where the analysis is to start
• number of periods for the new loan
• number of payments per year for the new loan.
It is assumed that the period for the original loan (e.g., a month) is the same as the period for the
new loan.
The program prepares a list of scenarios for various interest rates up to the point where the
refinancing rate leads to a situation where the remaining payments are more than that of the
original loan.
The output of the analysis is sent to a file named breakeven_int.csv. An example output (with some
reformatting) is shown in Table 4.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 54

5.6 Exercises
1. Complete Table 3 and generate the entire repayment schedule. Hint: Use the “Compute
Interest – Principal breakdown” feature in the amortization calculator.
2. Assume that a potential home buying couple has determined that they can afford a
maximum of $1,500 per month for a home mortgage. Further, they have found the best 15-
year mortgage rate to be 3%, the best 20-year mortgage rate to be 3.5% and the best 30-
year mortgage rate to be 3.75%. For all three scenarios, assume that payments on the
mortgage are made monthly. What is the maximum mortgage (initial principal) that they
𝑖𝑃(1+𝑖)𝑛
can afford? Hint: Solve the equation 𝐴 = (1+𝑖)𝑛 for 𝑃 and use the derived formula to
−1
determine the value for P in each of the three cases. Check your calculations using the “Max
affordable loan given interest rate …” feature in the amortization calculator. Answer: In
terms of being able to afford the most expensive house, the 30-year mortgage is the best
option. It allows the couple to purchase a $323,893.22 house.
3. For a $300,000 30-year mortgage at a nominal annual interest rate of 4% with monthly
payments back to the lender, determine the amount of the monthly payments. Adjust the
monthly payment to the nearest multiple of $10 and determine the final payment in this
case. Hint: Use the formula from Step 4 in Section 5.1.3. Answer: From the amortization
calculator, we determine the monthly payment to be $1432.25. So, the adjusted monthly
payment (to the nearest $10) is $1,430 and the final payment (based on the modified
monthly payment) is $2,988.76. If we just wanted to eliminate the cents (i.e., pay $1432 per
month), the final payment would be $1602.66. If we adjust the monthly payment to the
nearest multiple of $100 (i.e., $1,400), then the final payment is a surprising $23,780.24.
4. Continuing with the previous problem, how many payments would it take if the monthly
payment is increased to $1,500? Hint: Use the simple annuity payout calculator with
$300,000 as the initial investment (from the point of view of the loaning entity) and $1,500
as the amount of each payout. Note that you need to enter the monthly interest as a
decimal, i.e., .04/12 = .003̅. So, with a modest increase in the monthly payment, one can
pay off this mortgage in 330.13 months or about 2.5 years early.
5. For a car loan of $30,000 at a nominal annual rate of 2% (compounded monthly) for 3 years,
and a balloon payment of $15,000 at the same time as the last monthly payment, how
𝑖𝑃(1+𝑖)𝑛 −𝑖𝐵
much is each monthly payment? Hint: Use the balloon formula, i.e., 𝐴 = (1+𝑖)𝑛 −1
, and
check your answer with the balloon loan calculator. Answer: $454.64.
6. Continuing with the previous exercise, how does the answer change if the loanee makes the
balloon payment one period after the last regular payment? Hint: Use the alternate formula
at the end of Section 5.2.1. Answer: $455.31 which is slightly more than the answer to
Exercise 5, as expected since the balloon payment is made a month later.
7. Jedediah (goes by “Jed”) has a 30-year mortgage in the amount of $5 million at a nominal
annual interest rate of 3% (compounded monthly and with monthly payments back to the
bank). How much is the balance on the mortgage at the end of 73 months? Hint: Use either
of the formulas for the remaining balance from Section 5.3. Check your answer with the loan
.03
refinance calculator (with 12 = .0025 for the interest rate per period). Use the amount 0 in
the penalties and costs field. The interest rate and number of periods for the refinanced loan
are not relevant, but to avoid an error, use . 0025 and 360.

©2020 The Art of Managing Things


All Rights Reserved
55 Financial Math with Python

8. Continuing with the previous exercise, Jed has the opportunity (73 months into the original
mortgage) to refinance at a 1% nominal annual interest rate (compounding and payments
are monthly). The new mortgage would be for 30 years. There is no cost to terminate the
original mortgage (as written in the mortgage agreement if he uses the same bank to
refinance, which he is doing) but the new mortgage costs $55,000. Should Jed refinance,
assuming he intends not to sell the house in the next ten years? Hint: Use the loan
refinancing calculator.
9. Continuing with the previous exercise, what is roughly the highest interest rate (above 1%
and less than 3%) at which it still makes sense for Jed to refinance in terms of having a
lower total (remaining) payments? Hint: Use the “Loan Refinance - Breakeven Interest Rate
Analyzer.”

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 56

6 Bonds
6.1 Terminology
A bond is a fixed income instrument that represents a loan made by an investor to a borrower
(usually a corporation or government). When an entity needs to raise money for a long period of
time (e.g., a city looking to build a sports stadium), they issue bonds (also known as debentures)
which are sold to investors. Bonds are a form of debt.
A bond is essentially a contract between the issuer (borrower) and the investor (lender) that
specifies:
• The face value, or the denomination, of the bond, which is stated on the front of the bond.
This is usually (but not always) the amount of money to be paid to the borrower when the
bond matures.
• The date of maturity (also known as the redemption date) is when the loan will be repaid.
In some cases, it is possible to redeem a bond after the maturity date but typically, no
interest is accumulated after the maturity date. For example, United States Series EE
savings bonds can be held beyond the maturity but no interest accrues after the maturity.
• The rate of interest that the bond issuer pays the borrower is known as the coupon rate. It
is critical to keep in mind that the coupon rate is on the face value of the bond and not on
the purchase price of the bond.
o There is also something called a zero-coupon bond which does not have a coupon
rate and does not pay regular interest to the holder but rather is sold at a discount
and renders a profit at maturity when the bond is redeemed for its full face value.
• The price at which the bond issuer originally sells the bonds is known as the issue price.
Since bonds can be resold, there could be additional purchase prices. It is important to note
that the coupon rate does not change when a bond is resold.
• The amount of money that will be paid on the date of maturity is known as the redemption
value. If the redemption value is the same as the face value, the bond is said to be
redeemed at par.
• The yield of a bond is the rate of return the bond generates. This is not to be confused with
a bond’s coupon rate which is based on the face value of a bond.
o An example may help distinguish the two concepts. If a $100 bond with a 6%
coupon rate sells for $100, then the current yield is also 6%. However, because of
market price fluctuation, it may be possible to purchase this bond for the price of
$80. So, if a $100 (face value) bond is purchased for $80, the yield is 7.5% since the
$6 annual coupon payment is now 7.5% of the $80 purchase price. If the $100 (face
value) band was purchased for $120, then the yield will be just 5%.

A callable bond (also known as a redeemable bond) allows the issuer to redeem the bond before it
reaches the stated maturity date. In other words, on the call date, the bond issuer has the option
(not the obligation) to buy back the bond from the bond holder at a defined call price. The issuer of
a callable bond may choose to call their bonds if market interest rates move lower, and then re-
issue another series of bonds at a lower rate. Callable bonds compensate investors for the

©2020 The Art of Managing Things


All Rights Reserved
57 Financial Math with Python

possibility of the bond being called by offering a higher interest rate than comparable non-callable
bonds.
Savings bonds (as offered by the United States Treasury) can be redeemed any time after the
maturity date. The investor (bond holder) will receive the face value of the bond (typically the
purchase price) plus accrued interest.
Marketable bonds (e.g., corporate bonds or government bonds) do not allow for redemption
before the maturity date. If the holder of a marketable bond needs to liquidate a bond before the
maturity date, the holder must sell the bond on the open bond market at a price that depends on
current interest rates and other market factors (e.g., the financial stability of the bond issuer).

6.2 Similarity between Bonds and Balloon Loans


Consider a bond that has the following characteristics:
• coupon rate 𝑗 (per compounding period)
• face value 𝐹
• periodic payment A (computed by applying the coupon rate against the face value of the
bond, i.e., 𝐴 = 𝑗 × 𝐹)
• a final payout (redemption value) of 𝐵
• a purchase price P
• a yield y (per the same compounding period as the coupon rate)
To determine the price of the bond, we need to determine the present value (at time of purchase)
for each interest payout and the final payout.
This is the same problem as computing the principal for a balloon loan given the per period interest
rate, payout per period and the balloon payout at the end of the loan. The only difference is that
the entity providing the loan is the bond purchaser and the entity taking the loan is the bond issuer.
Simply restating the formula for the principal of a balloon loan, we also have the formula for the
price of a bond (with the conditions stated above):
𝟏 − (𝟏 + 𝒚)−𝒏
𝑷=𝑨 + 𝑩(𝟏 + 𝒚)−𝒏
𝒚
The first part of the right-hand side of the above equation is the present value (at the time of bond
purchase) of the individual interest payments and the second term is the present value of the final
bond payout.
Remarks:
• The bond purchaser is sold the bond under the guarantee that the yield will be 𝑦 and the
purchase price 𝑃 is computed under this assumption. The coupon rate is only used to
compute the regular payout amount 𝐴.
• It is assumed that the yield rate applies on the same schedule as the coupon schedule (e.g.,
semi-annually or quarterly). If not, then the yield rate needs to be converted to an
equivalent rate on the same schedule as the coupon rate using the conversion formula from
Section 4.7.1.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 58

The payout timeline for the type of bond described above is shown Figure 9.

Figure 9. Payouts timeline for a bond

6.2.1 School Bond Example


Consider the scenario where a municipality wants to raise $1,000,000 for a new school building.
The head financial planner for the town wants to offer 5-year bonds at a semi-annual yield of 1.5%,
with a coupon rate of 2% paid semi-annually and with a redemption value of $5,000 (which is equal
to the face value in this case). How many bonds does the municipality need to sell?
The coupon A is (.02)(5,000) = 100. We are given that 𝐵 = 5,000, 𝑦 = 1.5% and 𝑛 = 10. Using
the balloon loan calculator with these values yields the required issue price of the bond, i.e.,
$5,230.55. Dividing the issue price of the bond into $1,000,000, we get 191.18 and so the town
needs to sell at least 192 bonds to fully cover the cost of their planned school building.

6.2.2 Determine Purchase Price of Bond to Generate Various Yields


A purchase price other than the bond face value will lead to a different yield from the coupon rate,
as we saw in the example in the previous section. As a second example, consider a bond with the
following characteristics:
• Redemption value (equal to face value in this example) of the bond is $1,000
• The coupon rate is compounded semi-annually at a nominal annual rate of 6%
• Length of the bond is 5 years.
Determine the purchase prices that will give yields of 4%, 6% and 8% (compounded semi-annually
.06
in each case). In all three cases, the semi-annual coupon payout is 𝐴 = (1,000) = 30, 𝑗 = .03
2
and 𝑛 = 10.

In the case that a 6% yield is desired, 𝑦 = 𝑗 = .03 and the price should be set at the redemption
value of $1,000. As noted previously, when the redemption value and face value are equal, a bond
is said to be purchased at par.

In the case a 4% yield, we have 𝑦 = .02. It should be emphasized the 𝐴 does not change. Using the
balloon loan calculator, the required price to give the desired yield is $1,089.83. Since the bond is
being purchased for more than its redemption value, it is said to be purchased at a premium. Such

©2020 The Art of Managing Things


All Rights Reserved
59 Financial Math with Python

1,089.83
a bond would be listed as 1,000
× 100 ≅ $108.99 (it is typical to list a bond’s price per $100 of
face value).

In the case of an 8% yield, we have 𝑦 = .04. Using the balloon loan calculator, the required price to
produce the desired yield is $918.89. Since the bond is being purchased for less than its redemption
value, it is said to be purchased at a discount. The price of this bond would typically be listed as
$91.89 (i.e., the price per $100 of face value).

6.2.3 Bond Prices versus Yield


Extending the previous example to include semi-annual yields between 1% and 5%, in .5%
increments, we get the following table relating yields to purchase price:

Table 5. Bond Purchase Price versus Yield


Semi-annual Yield Bond Price Purchased
1% $ 1,189.43 at a premium
1.5% $ 1,138.33 at a premium
2% $ 1,089.83 at a premium
2.5% $ 1,043.76 at a premium
𝑖 = 𝑦 = 3% $ 1,000.00 at par
3.5% $ 958.42 at a discount
4% $ 918.89 at a discount
4.5% $ 881.31 at a discount
5% $ 845.57 at a discount

In general, as the yield increases, the bond price drops and vice versa. For example, assume Abe
purchases a bond with a 6% coupon rate (compounded semi-annually), a face value (with equal
redemption value) of $1,000 and a term of 5 years. Abe decides to sell his bond after 2.5 years.
Excluding brokerage fees, for how much should Abe expected to sell his bond?
First, note that Abe is basically selling a 2.5 year bond at this point with a redemption value of
$1,000. We need to compare this to other bonds with a 2.5 year term. Assume that such bonds
now (at the time Abe wants to sell) have an average coupon rate of 7% (semi-annual
compounding). Thus, the price estimate should be based on a bond with 𝑦 = .035, 𝐴 =
(.03)(1,000) = 30 and 𝑛 = 5. The key here is the A remains at $30 (the bond issuer does not
change their conditions when the bond gets sold). Using the balloon loan calculator, an estimate
for price of the resold bond is $977.42. This is different from the 3.5% row in Table 5, because the
calculations in Table 5 are based on 𝑛 = 10 periods.

6.3 Schedule for a Bond


For accounting and tax purposes, it is useful to have a schedule for the various payments and gains
(or losses) related to a bond. Such a schedule is developed in this section.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 60

1−(1+𝑖)−𝑛
If we use the annuity notation mentioned in Section 4.3.1 (i.e., 𝑎𝑛|𝑖 = 𝑖
), the price formula
for a bond (from Section 6.2) can be written as
𝑃 = 𝐴𝑎𝑛|𝑦 + 𝐵(1 − 𝑦𝑎𝑛|𝑦 )
and with some rearrangement, we get
𝑃 − 𝐵 = (𝐴 − 𝑦𝐵)𝑎𝑛|𝑦
If 𝑃 > 𝐵 (i.e., purchase price exceeds redemption value), the bond is purchased at a premium.
From the formula above, the amount of the premium is 𝑃 − 𝐵. The above formula also provides
another way to characterize a premium bond purchase, i.e., when 𝐴 − 𝑦𝐵 > 0. In other words, if
the coupon exceeds the periodic yield (i.e., effective interest paid on the redemption value of the
bond for a period), then the bond is purchased at a premium. If the redemption value equals the
face value, then 𝐴 = 𝑗𝐵 (where 𝑗 is the periodic coupon rate). Substituting 𝐴 = 𝑗𝐵 into 𝐴 − 𝑦𝐵 >
0, we get (𝑗 − 𝑦)𝐵 > 0 which implies 𝑗 − 𝑦 > 0 (i.e., a bond is purchased at a premium if the
coupon rate is greater than the yield).
Similar, if 𝑃 < 𝐵 (equivalently, 𝐴 − 𝑦𝐵 < 0 or 𝑗 − 𝑦 < 0), then the bond is purchased at a discount.
Of course, if a bond is purchased at its redemption value (assuming this is the same as the face
value) then 𝑃 = 𝐵, 𝐴 = 𝑦𝐵 and 𝑗 = 𝑦.
We now return to the accounting/tax issue mentioned at the beginning of this subsection. If a bond
is purchased at a premium, the redemption amount (not the purchase amount) is returned to the
bond holder on the redemption date and in effect, the bond holder will incur a loss. Depending on
the applicable tax laws for the bond holder, there are at least two cases:
• This loss can be applied against the bond holder’s income at the time of redemption, i.e.,
for a given tax year.
• Alternately, the bond holder could allocate (i.e., distribute) the loss over each bond interest
period (over several tax years with the exception of short term bonds that do not span
more than one year).

6.3.1 Schedule for a Bond Bought at a Premium


Ms. Erdnussbutter purchased a $100,000 bond (redemption and face value being the same) with a
nominal annual coupon rate of 8% (with semi-annual coupon payments) and at a nominal annual
yield of 6% (semi-annual compounding). The length of the bond is 10 years.
The coupon rate is 𝑗 = .08/2 = .04 per period (i.e., half-year), the yield rate is 𝑦 = .06/2 = .03 per
period, and 𝑛 = 20. Since the 𝑗 > 𝑦, we can conclude the bond has been purchased at a premium.
Using the bond schedule creator, we get the schedule shown in Table 6. The purchase price is
shown as the book value in row 0, i.e., $114,877.47.
Depending on her circumstances, Ms. Erdnussbutter can either declare a single loss of $14,877.47
in the final year of the bond’s term, or she could take a series of smaller losses in each of the years
she holds the bond. The smaller losses are listed in the “Book Value Adjustment” column in Table 6.
Note that the sum of the book value adjustments equals the total amount of loss, i.e., $14,877.47.
In either case, she needs to pay taxes on the coupon payments received each year.

©2020 The Art of Managing Things


All Rights Reserved
61 Financial Math with Python

For each period, the book value adjustment (loss in this case) is subtracted from the coupon
payment and thus reduces the taxable income. For example, if the bond scheduling technique is
used, the taxable amount on the bond from period 1 is $3,446.32 rather than $4,000.
The computations are as follows:
• (interest on book value for period 𝑘) = (periodic yield) times (book value from period 𝑘 − 1)
• (book value adjustment for period 𝑘) = (coupon) minus (interest on book value for period
𝑘).

Table 6. Schedule for Bond Purchased at a Premium


Period (k) Coupon Interest on Book Value Book Value
Book Value Adjustment
0 - - - $114,877.47
1 $4,000.00 $3,446.32 $553.68 $114,323.80
2 $4,000.00 $3,429.71 $570.29 $113,753.51
3 $4,000.00 $3,412.61 $587.39 $113,166.12
4 $4,000.00 $3,394.98 $605.02 $112,561.10
5 $4,000.00 $3,376.83 $623.17 $111,937.94
6 $4,000.00 $3,358.14 $641.86 $111,296.07
7 $4,000.00 $3,338.88 $661.12 $110,634.96
8 $4,000.00 $3,319.05 $680.95 $109,954.00
9 $4,000.00 $3,298.62 $701.38 $109,252.62
10 $4,000.00 $3,277.58 $722.42 $108,530.20
11 $4,000.00 $3,255.91 $744.09 $107,786.11
12 $4,000.00 $3,233.58 $766.42 $107,019.69
13 $4,000.00 $3,210.59 $789.41 $106,230.28
14 $4,000.00 $3,186.91 $813.09 $105,417.19
15 $4,000.00 $3,162.52 $837.48 $104,579.71
16 $4,000.00 $3,137.39 $862.61 $103,717.10
17 $4,000.00 $3,111.51 $888.49 $102,828.61
18 $4,000.00 $3,084.86 $915.14 $101,913.47
19 $4,000.00 $3,057.40 $942.60 $100,970.87
20 $4,000.00 $3,029.13 $970.87 $100,000.00
Totals $80,000.00 $65,122.53 $14,877.47 -

6.3.2 Schedule for a Bond Bought at a Discount


In this example, Mr. Everest buys a $50,000 bond. The term of the bond is 5 years, the coupon rate
is 4% (with payments semi-annually) and the yield is 5% (with semi-annual compounding).

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 62

The coupon rate is 𝑗 = .04/2 = .02, the yield rate is 𝑦 = .05/2 = .025, and 𝑛 = 10. Since the 𝑗 <
𝑦, we can conclude the bond has been purchased at a discount. Using the bond schedule creator,
we get the schedule shown in Table 7. Note that the amounts in parentheses are meant to be
negative (this is a convention in accounting).
Mr. Everest can choose to pay tax on the realized gain of $2,188.02 in the final year of the bond’s
terms, or distribute the gains over the life of the loan (by the amounts shown in the book value
adjustment column). In either case, he needs to pay taxes on the coupon payments received each
year. The formulas for the calculations are the same as those used to construct Table 6.
[Author’s remark: Showing the book value adjustments as negative in Table 7 seems odd to me
since the amounts are being listed as profits on one’s tax return. I have a similar comment on Table
6. I guess the idea is for the Interest on Book Value plus the Book Value Adjustment to equal the
Coupon.]

Table 7. Schedule for Bond Purchased at a Discount


Period Coupon Interest on Book Value Book Value
Book Value Adjustment
0 - - - $47,811.98
1 $1,000.00 $1,195.30 ($195.30) $48,007.28
2 $1,000.00 $1,200.18 ($200.18) $48,207.47
3 $1,000.00 $1,205.19 ($205.19) $48,412.65
4 $1,000.00 $1,210.32 ($210.32) $48,622.97
5 $1,000.00 $1,215.57 ($215.57) $48,838.54
6 $1,000.00 $1,220.96 ($220.96) $49,059.51
7 $1,000.00 $1,226.49 ($226.49) $49,285.99
8 $1,000.00 $1,232.15 ($232.15) $49,518.14
9 $1,000.00 $1,237.95 ($237.95) $49,756.10
10 $1,000.00 $1,243.90 ($243.90) $50,000.00
Totals $10,000.00 $12,188.02 ($2,188.02) -

6.4 Correction if Bond Not Purchased on a Coupon Date


The discussion in the previous sections has been under the assumption that the bonds were
purchased on the date of a coupon payout (with the payout going to the bond seller) or at the time
of the initial issue of the bond. However, it is far more likely that a bond is sold between coupon
payout dates. In such cases, a correction is needed to the calculations.

6.4.1 Dirty Price of a Bond


Figure 10 depicts a situation where a bond is purchased between two coupon payout dates (or
possibly between the issue date of the bond and the first coupon payout date). The bond purchase
price at time 0 is 𝑃. The coupon payouts are in the amount 𝐴. At maturity, the bond holder receives
the final coupon payout plus the redemption value of the bond 𝐵. 𝑃 is the price of the bond if it
had been purchased at time 0 with the given yield.

©2020 The Art of Managing Things


All Rights Reserved
63 Financial Math with Python

Figure 10. Bond Purchases between Coupon Dates


1−(1+𝑦)−𝑛
The price P of the bond at time 0 can be calculated with the bond price formula, i.e., 𝐴 𝑦
+
𝐵(1 + 𝑦)−𝑛 , since this time coincides with the initial bond issue date or a coupon payment date.
Using the concepts from Section 3.7, the equivalent value of 𝑃 at the time of settlement can be
computed (this is shown as 𝐷 in the figure and in the calculations that follow). If simple interest (at
rate y) is assumed over the fraction of the period between time 0 and the settlement date (call this
fraction 𝑘), then 𝐷 = 𝑃(1 + 𝑘𝑦). [Sometimes, perhaps usually, an alternate formula is used, i.e.,
𝐷 = 𝑃(1 + 𝑦)𝑘 .] 𝐷 is known as the full or dirty price of a bond.

6.4.2 Dirty Bond Price Example


As an example, consider a 30-year US Treasury bond with an annual yield of 1.61%, an annual
coupon rate of 1.25% (interest paid semi-annually) and redemption value (same as face value in
this case) of $10,000. The bond was purchased by a brokerage house. At what price should the
bond be sold to achieve the advertised yield if the settlement date is 5 June 2020 (i.e., when the
bond is resold to a customer of the brokerage house) and the maturity day is 15 May 2050?
Based on the maturity date and condition of semi-annual coupon payouts, one can deduce that the
coupon payouts are on May 15th and November 15th of each year. There are 21 days between May
21
15th and June 5th, and 184 days between May 15th and November 15th. So, 𝑘 = 184 ≅ .11413. The
other input variables are as follows:
• yield rate per period = .0161/2 = .00805
• total number of payments = 60 (note that no payments are missed as the broker resells
the bond before the first coupon payout)
• redemption value = $10,000
• coupon rate per period = .0125/2 = .00625
• coupon payout per period = .00625 × 10,000 = $62.50
Using the bond price formula, we get 𝑃 = $9,146.12 (this can be checked using the balloon loan
calculator as described previously). Finally, we get 𝐷 = 𝑃(1 + 𝑘𝑦) ≅ $9,154.52. Using the
alternate formula, we get 𝐷 = 𝑃(1 + 𝑦)𝑘 = $9,154.49.
179
If the bond was sold later in the coupon period (e.g., 10 November 2020) then 𝑘 would be 184 ≅
.972826 and 𝐷 ≅ $9217.75. Using the alternate formula, we get 𝐷 = 𝑃(1 + 𝑦)𝑘 = $9,217.74.

6.4.3 Clean Price of a Bond


Before we get to the definition of the clean price for a bond, let’s further analyze how the dirty
price changes over time. For the example in the Section 6.4.2, Table 8 shows the dirty price for the

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 64

bond starting at time 0 and going through the end of period 4 (the other 55 periods are not shown
in the table). Each period is divided into 8 equal time intervals. (There is nothing special about 8.
The point is to get a few representative points for the graph in Figure 11.)For example, the dirty
115
price of the bond at time 2 184 is $9,214.59 (shown in bold in the table). The column on the
extreme right (Diff) shows the difference between the dirty bond price at the end of one interval
and the beginning of the next (just before and after a coupon payout). For example, the difference
between the price at the end of period 0 (just before the first coupon payout) and the beginning of
period 1 (just after the first coupon payout) is $9,219.75 - $9,157.24 = $62.51 (see the shaded cells
table below). The difference should be exactly the coupon payout amount 𝐴 but there is a small
rounding error in the calculations.
The fact that the dirty price drops by exactly 𝐴 at the end of a period can be proven as follows
(noting that 𝑘 is 1 just before the end of a period and 0 at the beginning of a period):
Take the dirty price of a bond just before the end of a period with 𝑚 remaining coupon
payments and subtract the dirty price of the bond at the beginning of the next period (at
which point there are 𝑚 − 1 coupon payments remaining) to get the following (with terms
in bold cancelling each other):
−(𝑚−1)
1 − (1 + 𝑦)−𝑚 1 − (1 + 𝑦) −(𝑚−1)
(1 + 1 ∙ 𝑦) [𝐴 + 𝐵(1 + 𝑦)−𝑚 ] − (1 + 0 ∙ 𝑦) [𝐴 + 𝐵(1 + 𝑦) ]
𝑦 𝑦

(1 + 𝑦) − (1 + 𝑦)−(𝑚−1) 1 − (1 + 𝑦)−(𝑚−1)
=𝐴 + 𝑩(𝟏 + 𝒚)−(𝒎−𝟏) − 𝐴 − 𝑩(𝟏 + 𝒚)−(𝒎−𝟏)
𝑦 𝑦

𝐴𝑦 𝟏 − (𝟏 + 𝒚)−(𝒎−𝟏) 𝟏 − (𝟏 + 𝒚)−(𝒎−𝟏)
= +𝑨 −𝑨 =𝐴
𝑦 𝒚 𝒚

Table 8. Dirty Price Changes over Time for a Bond


Period 0 23/184 46/184 69/184 92/184 115/184 138/184 161/184 <1 Diff

0 9,146.12 9,155.32 9,164.53 9,173.73 9,182.93 9,192.14 9,201.34 9,210.54 9,219.75

1 9,157.24 9,166.45 9,175.67 9,184.88 9,194.10 9,203.31 9,212.53 9,221.74 9,230.96 62.51

2 9,168.46 9,177.69 9,186.91 9,196.14 9,205.36 9,214.59 9,223.81 9,233.04 9,242.27 62.50

3 9,179.76 9,189.00 9,198.23 9,207.47 9,216.71 9,225.95 9,235.18 9,244.42 9,253.66 62.51

4 9,191.16 9,200.41 9,209.66 9,218.91 9,228.15 9,237.40 9,246.65 9,255.90 9,265.15 62.50

The points in Table 8 are plotted on the graph shown in Figure 11. Each upward line represents one
period (one row from the table). The drop-off from one period to another is actually discontinuous,
i.e., the downward lines should not be in the figure (limitation of the plotting tool used).

©2020 The Art of Managing Things


All Rights Reserved
65 Financial Math with Python

Figure 11. Graph of Dirty Bond Prices over Time

The reason for the increase in the price over a period is that the dirty price reflects the accrued
interest on the coupon before it is paid out at the end of the period. Look at it this way, if the price
did not reflect the accrued interest on the coupon, everyone would buy bonds just before the
coupon dates and immediately get the coupon payment for the previous period.
The clean price of a bond (also known as the flat price) considers the accrued interest on the bond
since its last coupon payment date. The clean price equals the present value of the bond's future
cash flows (i.e., the dirty price) minus the interest earned on the bond between the last payment
date and the transaction date. Most financial markets (particularly in the US) quote bonds using
their clean prices. Accrued interest is added back to the quoted price to determine the purchase
price. So, bonds are typically advertised at their clean price and sold at their dirty price.
In terms of equations, we have the following definitions:
• Accrued interest: 𝐼𝑘 = 𝑘𝐴 where 𝑘 is the fraction of a given coupon period that has
transpired at settlement time (i.e., time of purchase).
• Clean price: 𝐶 = 𝐷 − 𝐼𝑘
Table 9 shows the clean prices corresponding to the dirty prices in Table 8.
Table 9. Clean Price Changes over Time for a Bond
Period 0 23/184 46/184 69/184 92/184 115/184 138/184 161/184 <1

0 9,146.12 9,147.51 9,148.90 9,150.29 9,151.68 9,153.07 9,154.46 9,155.86 9,157.25

1 9,157.24 9,158.64 9,160.04 9,161.45 9,162.85 9,164.25 9,165.65 9,167.05 9,168.46

2 9,168.46 9,169.87 9,171.29 9,172.70 9,174.11 9,175.53 9,176.94 9,178.35 9,179.77

3 9,179.76 9,181.18 9,182.61 9,184.03 9,185.46 9,186.88 9,188.31 9,189.73 9,191.16

4 9,191.16 9,192.60 9,194.03 9,195.47 9,196.90 9,198.34 9,199.78 9,201.21 9,202.65

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 66

The points in Table 9 are plotted on the graph shown in Figure 12. This would be a straight line but
for some rounding errors in the computations.

Figure 12. Graph of Clean Bond Prices over Time

6.5 Computing the Yield given the Bond Price


So far, all the work in this section assumes that the yield price is given (along with the coupon rate,
redemption value, and term of the bond) and the bond price is derived. In fact, it is possible to
determine the yield when given the bond price, coupon rate and term of the bond, but there is no
closed formula for the yield in terms of the other characteristics of a bond. A numerical
approximation method is required to solve the problem.
Fortunately, Microsoft Excel offers a yield function that computes the yield for a bond given:
• Settlement – the date when the security is sold to the buyer (this could be the issue date of
the bond or a later date). Need to use the Excel DATE function to enter the date.
• Maturity – the date when the security expires. Again, one needs to use the Excel DATE
function to end the date.
• Coupon rate per year
• Purchase price per $100 of face value.
• Redemption value per $100 face value.
• Frequency – the number of coupon payments per year. For annual payments, frequency =
1; for semiannual, frequency = 2; for quarterly, frequency = 4. No other options are
supported.
• Basis (optional) - the type of day count basis to use.
Consider the example from Section 6.3.2 concerning Mr. Everett but this time assume we are given
the purchase price $47,811.98 and asked to find the yield. In order to use the Excel function, we
need actual dates that span (in this case) 5 years. We can arbitrarily choose January 1, 2000 as the
settlement date and January 1, 2005 as the maturity date. The nominal annual coupon rate is 4%.

©2020 The Art of Managing Things


All Rights Reserved
67 Financial Math with Python

100
The purchase price per $100 of face value is 47,811.98 × 50,000 = 95.62396. The redemption value
is equal to the $100 per $100 of face value. The frequency is 2.
If the following is entered in an Excel cell, the result is 0.050000019 (not exact but pretty good):
= YIELD(DATE(2000,1,1), DATE(2005,1,1),0.04,95.62396,100,2)

6.6 Supporting Programs

6.6.1 Balloon Loan Calculator


Usage of the balloon loan calculator was described in Section 5.5.3.
As described in Section 6.2, a bond can be viewed as the balloon loan (see the mappings in Table
10). The differences are as follows:
• The yield of a bond is modified by changing the asking (purchase) price, while the loan
interest rate is set by the entity offering the loan.
• The periodic payments on a balloon loan entail payment of interest and principal, while the
coupon payments on a bond only entail interest payments.

Table 10. Balloon Loan – Bond Comparison


Balloon Loan Concept Bond Concept
Amount of loan (𝑃) Purchase price of bond (𝑃)
Interest rate per period (𝑖) Yield rate per period (𝑦)
Number of payments (𝑛) Number of payments (𝑛)
- Coupon rate per period (𝑗)
Amount of each periodic payment (A) – computed Amount of coupon payment – computed using the
using the formula formula 𝐴 = 𝑗𝐵
𝒊𝑷(𝟏 + 𝒊)𝒏 − 𝒊𝑩
𝑨=
(𝟏 + 𝒊)𝒏 − 𝟏
Amount of balloon payment (𝐵) Redemption value bond (𝐵) – assumed to be equal
to the face value of the bond

When using the balloon loan calculator for bonds, one enters the yield (in the “interest rate per
period” field), total number of payments, redemption value (in the “amount of balloon payment”
field) and the coupon amount (in the “amount of each periodic payment” field).

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 68

6.6.2 Bond Schedule Creator


File name: bond_schedule_creator.py
This program creates a schedule of payments for a bond.
• The input consists of the redemption value of the bond (assumed to be the same as the
face value), the number of payment periods, the coupon rate per period (as a decimal) and
the yield rate per period (as a decimal).
• The output shows the time period, coupon interest (which is a constant), interest on book
value and book value adjustment for each period. The output is placed in a file named
bond_schedule.csv (in the same directory where the program has been placed). It is
recommended that the file be opened using a spreadsheet application such as Microsoft
Excel.
The program works for bonds purchased at a premium, at a discount and at face value.

©2020 The Art of Managing Things


All Rights Reserved
69 Financial Math with Python

6.7 Exercises
1. Compute the price of a 10-year zero coupon bond that effectively yields 3.5% per year
(under the assumption of yearly compounding). The redemption value of the bond is
$15,000. Answer: Use the formula for the bond price from Section 6.2 with 𝐴 = 0 (since
there is no coupon) and 𝐵 = 15,000 to get the result 𝑃 = 15,000(1 + .035)−10 =
$10,633.78. Note: If no compounding is assumed, then we need to compute the present
15,000
value of 15000 under the assumption of simple interest, i.e., 𝑃 = 1+10(.035) = $11,111.11.

2. Compute the price of a 5-year bond with semi-annual coupon payments at a nominal
annual rate of 5%. The redemption and face value are the same, i.e., $50,000. The nominal
annual yield rate is 4% (compounded semi-annually). Hints: Use the balloon loan calculator
.05
in the manner described in Sections 6.2 and 6.6.1. The coupon is 2 (50,000) = 1,250.
Answer: $52,245.65
3. Is the bond from Exercise 2 purchased at a premium, at a discount or at par? Answer: The
coupon rate is higher than the yield. So, the bond is purchased at a premium.
4. Using the information from Exercise 2, create a table that shows the bond price for the
following nominal annual yields (again assuming semi-annual compounding): 2%, 3%, 4%,
5%, 6%, 7% and 8%. Hints: This is similar to the example in Section 6.2.3. Don’t forget to
convert the nominal annual yields to semi-annual yields. Also, keep in mind that the coupon
is the same for all cases in this exercise. Answer:

Table 11. Answer to Exercise 6


Semi-annual Bond price Purchased
yield
1 $57,103.48 at a premium
1.5 $54,611.09 at a premium
2 $52,245.65 at a premium
2.5 $50,000.00 at par
3 $47,867.45 at a discount
3.5 $45,841.70 at a discount
4 $43,916.83 at a discount

5. For the bond described in Exercise 2, create bond schedules for two cases, i.e., when the
yield is 3% and 7% (semi-annual compounding in both cases). Hint: Use the bond schedule
creator.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 70

6. Compute the dirty (full) price for a 20-year US Treasury bond that is to have an annual yield
of 1% (compounded semi-annually), an annual coupon rate of 1.25% (interest paid semi-
annually) and redemption value (same as face value in this case) of $25,000. The settlement
(purchase) date is 15 June 2020 and the redemption (maturity) date is 31 August 2030.
Hints and answer: Clearly, the bond is being resold since the settlement date is far less than
20 prior to the redemption date. The coupon dates are August 31st and March 3rd (note the
issue with February having only 28 days) and so there are 21 coupon payments remaining,
i.e., 𝑛 = 21. Use the balloon calculator to compute the price of the bond at the time of last
coupon payment before the settlement date which is $25,621.50 (this is P in the formula for
the dirty price from Section 6.4.1). Use the online application at
[Link] to count the number of days from 3
March 2020 to 15 June 2020 (105 days), and between 3 March 2020 to 31 August 2020 (182
105
day) which means that 𝑘 = ≅ .5769. Applying the dirty price formula, we get 𝐷 =
182
𝑃(1 + 𝑘𝑦) ≅ 25,621.50(1 + (. 5769)(. 005)) ≅ $25,695.41. If we use the alternate formula
for the dirty price, we get 𝐷 = 𝑃(1 + 𝑦)𝑘 ≅ $25,695.33.
7. Using the simple interest version of the dirty price formula, show that the clean price can
be represented by the formula 𝐶 = 𝑃 + 𝑘(𝑦𝑃 − 𝑖𝐵) with 𝑃, 𝑘, 𝑦, 𝑖 and 𝐵 as defined in
Section 6.4.1. Hint: Assume that the face value is redemption value and thus 𝐴 = 𝑖𝐵.
8. For the bond described in Exercise 6, compute the clean price. Answer: 𝐶 = 𝐷 − 𝑘𝐴 ≅
25,695.41 − .5769(156.25) ≅ $25,605.27.

©2020 The Art of Managing Things


All Rights Reserved
71 Financial Math with Python

7 Capital Budgeting
This section covers some financial concepts that help in decision making with regard to business
investments and the incremental cash flows that results from such investments. The reader is
assumed to be familiar with cash flow and how it is different from profit. For a refresher on cash
flow and profit, see the YouTube video “What is a cash flow statement?” [8] and the Investopedia
article on cash flow [9]. For a more extensive discussion of cash flow analysis and capital budgeting,
see Chapters 12 and 13 of The Basics of Finance [6].
[Author’s Remark: While I have not provided any Python programs in support of this section, there
is an Excel spreadsheet that covers many of the computations related to the examples. It is
recommended that you have this spreadsheet in hand when reading this section. For a summary of
the various sheets within the spreadsheet, see Section 7.6.]

7.1 Net Present Value (NPV)

7.1.1 Concept with an Example


Net Present Value (NPV) refers to the present value of all cash flows related to a given project and
associated investments. NPV is used as a method for making decisions concerning capital
budgeting. If the NPV for a project is negative, then it is recommended not to proceed with the
project. If the NPV for a project is positive, then it is recommended to proceed with the project.
The NPV can also be used to compare several projects (see the example in Section 7.1.6). As we
shall see, NPV is but one measure used to decide whether to go ahead with a project or not.
Calculation of the NPV depends on the stipulation of a given rate of return (known as the cost of
capital). The general idea is that a proposed capital investment project should provide a higher rate
of return than some other (typically external) investment of similar risk. For example, if a company
can make a 5% rate of return with, in their opinion, a moderate risk investment in the bond market,
then an internal project, with similar risk, would be expected to make more than 5% per year.
Wikipedia provides the following definition of Cost of Capital [7]:
In economics and accounting, the cost of capital is the cost of a company's funds (both debt
and equity), or, from an investor's point of view "the required rate of return on a portfolio
[of a] company's existing securities". It is used to evaluate new projects of a company. It is
the minimum return that investors expect for providing capital to the company, thus setting
a benchmark that a new project has to meet.
As an example, consider a small business (Acme Furniture) that makes custom furniture and does
antique furniture restoration. The business is currently run by Alice and Bob in a converted garage.
On a regular basis, Alice and Bob are turning down business because of the lack of resources. To
address this issue, they are considering an expansion of the garage, the purchase of additional
equipment, the hiring of additional staff, additional parking spaces and a small showroom for
customers. The upgrade to their business will require an investment of $225,000. On the other
hand, Alice and Bob could invest the $225,000 in three other ways, with the following semi-annual
rate of returns
• 2% (conservative investment, e.g., bank certificate of deposits)
• 4% (moderate risk, e.g., government and corporate bonds)
• 6% (higher risk, e.g., stocks and higher risk bonds).

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 72

Alice and Bob know their business well and are able to make (in their opinion) reasonably accurate
projections of cash flows for the business expansion (as a result of the planned expansion). The
problem at hand is to compare the projected cash flows against the three alternative investment
options.
Table 12 shows Alice and Bob’s projected cash flows concerning Acme Furniture after the planned
expansion.
• The top row is time in half-year increments, up to the end of year number 5.
• The second row contains the cash inflows to Acme Furniture, e.g., sales of furniture.
• The third row contains the cash outflow, e.g., the initial investment, supplies, wages.
• The bottom row shows net cash flows for each 6-month period. In this example, there is
only a net outflow at time 0. However, in general, any of the periods could be a net inflow
or outflow of cash.
(Note: In the examples that follow, we usually only show the net cash flow for each period and omit
the details concerning cash inflows and outflows.)

Table 12. Initial Investment and Cash Flow in Half-year Increments


Year 0 .5 1 1.5 2 2.5

Cash Inflow 30,000 35,000 35,000 40,000 35,000

Cash Outflow (225,000) (10,000) (13,000) (11,000) (14,000) (7,000)

Net Cash Flow (225,000) 20,000 22,000 24,000 26,000 28,000

Year 3 3.5 4 4.5 5

Cash Inflow 40,000 45,000 50,000 50,000 50,000

Cash Outflow (10,000) (13,000) (16,000) (14,000) (12,000)

Net Cash Flow 30,000 32,000 34,000 36,000 38,000

Recall from Section 3.7 that we can compare the value of money realized at different times by
computing the various values at some common focal date. For the problem at hand, we will use the
time of the initial investment (i.e., time 0) as the focal date and compute the value of the various
net cash flows for each period based on their value at the focal date. In general, we make the
following assignment
• let 𝐶0 be the initial investment
• let 𝐶𝑘 be the net cash flow for period 𝑘 which ends at time 𝑡𝑘 (measured in time periods,
e.g., half-years, quarters or months)
• 𝑖 is the interest rate per period, i.e., the cost of capital
• 𝑛 is the number of cash flows.
With the above assignments, the general formula for net present value is given by
𝑛

𝑁𝑃𝑉 = −𝐶0 + ∑ 𝐶𝑘 (1 + 𝑖)−𝑡𝑘


𝑘=1

©2020 The Art of Managing Things


All Rights Reserved
73 Financial Math with Python

The formula allows for the cash flows to be unequally spaced in terms of the number of periods.
For example, we could have cash flow estimates at periods number 3, 5, 11 and 13. In this case,
𝑛 = 4, 𝑡1 = 3, 𝑡2 = 5, 𝑡3 = 11 and 𝑡4 = 13. However, it is more usual to have a net cash flow
estimate for each period, in which case, 𝑡𝑘 = 𝑘 and the formula becomes
𝑛

𝑁𝑃𝑉 = −𝐶0 + ∑ 𝐶𝑘 (1 + 𝑖)−𝑘


𝑘=1

Getting back to the problem at hand, we can use the Microsoft Excel function NPV to compute the
NPV for each of the 3 cost of capital scenarios, i.e., 2%, 4% and 6% semi-annual rates. The Excel
NPV function is easy to use. The first parameter is the rate of return and the following parameters
are the net cash flows for each period (see [Link]
function-8672cb67-2576-4d07-b67b-ac28acf2a568 for further details). The results are summarized
in Table 13 (the parenthesis indicate a negative NPV). For 2% and 4%, Acme Furniture will have a
positive NPV and thus it makes sense to go ahead with the expansion in these two cases. However,
at 5%, the NPV is negative and it may not be a good idea to go forward with the expansion in this
case.

Table 13. Investment Analysis for Acme Furniture


Semi-annual Cost NPV
of Capital
2% $31,923.43
4% $4,789.06
5% ($6,915.43)
6% ($17,541.15)

For the sake of argument, let’s say that Alice and Bob think that the risk in expanding their business
is similar in risk to the 6% cost of capital alternative. [This is a key point, i.e., the cost of capital
needs to be at the same estimated risk as the proposed investment!] With the given information,
they should not go forward with their business expansion. However, it may be that consideration of
a longer time frame for the cash flows will change the decision. For example, assume Alice and Bob
are able to project the cash flow for a 6th year, as shown in Table 14.

Table 14. Initial Investment, and Cash Flow in Half-year Increments - Revised
0 .5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6

(225,000) 20,000 22,000 24,000 26,000 28,000 30,000 32,000 34,000 36,000 38,000 41,000 44,000

The two extra semi-annual cash flow projections change the investment analysis, as shown in Table
15. With the extra year of cash flow taken into consideration, it now makes sense to go forward
with the business expansion, even for the case of a 7% return on the alternative investment. It is
not until about 8% where the alternative investment makes more sense.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 74

Table 15. Investment Analysis for Acme Furniture - Revised


Semi-annual Cost NPV
of Capital
2% $98,265.08
4% $56,822.80
6% $23,463.51
7% $9,269.22
8% ($3,506.95)

7.1.2 Negative Cash Flows


The previous example showed positive cash flows for each period but this is not always the case,
and it is quite possible to have negative net cash flows for some periods. For example, the capital
expenditure could be negative in some periods because of start-up issues, seasonal businesses, or
expected charges (e.g., insurance payments) at various points in time.
As an example, consider a vacation resort that has a seasonal business, with Fall being a time for
repairs and a reduced number of customers. The resort owners are considering a $500,000
investment to improve the resort. Table 16 shows the estimated project cash flows for each season
(quarter) in the 5 years following the potential investment.

Table 16. Project Quarterly Cash Flows for a Resort Business


Year Winter Spring Summer Fall
1 40,000 41,000 42,000 (3000)
2 41,000 42,000 43,000 (2000)
3 41,000 42,000 43,000 (2000)
4 43,000 44,000 45,000 (1500)
5 43,000 44,000 45,000 (1500)

Table 17 shows an analysis of the potential investment at various costs of capital (keeping in mind
that the cost of capital refers to alternative investments). The project’s cash flows outweigh the
alternative investments up to and including a quarterly rate of 2.25%. At 2.5%, it may make more
sense not to invest in the resort but rather in the alternative investment. On the other hand, the
2.5% alternative investment may be very risky (perhaps junk bonds and small growth stocks) and
the resort improvement investment may be seen as much more certain than the 2.5% alternative
investment. The point is that the final decision by the resort owners is not black and white, and the
NPV analysis is just one tool to help with their decision.

©2020 The Art of Managing Things


All Rights Reserved
75 Financial Math with Python

Table 17. Investment Analysis for Resort Investment


Quarterly Cost NPV
of Capital
.5% $97,678
.75% $82,931
1% $68,758
1.25% $55,134
1.5% $42,037
1.75% $29,444
2% $17,334
2.25% $5,685
2.5% $(5,520)
2.75% $(16,300)

7.1.3 Multiple Investments


The examples thus far have only had one investment and that occurred at the beginning of the
project in question. This does not always need to be the case and in fact, it is quite possible that a
project will require several investments at various times. In the case of several investments, one
can separate the cash flow into what are called operating cash flow and investment cash flow
(these are not to be confused with cash inflow and outflow). These two types of cash flow are
added together for each period to get a net cash flow. In general, investment cash flows are
negative. Operating cash flows can be positive or negative (as we saw in example from the previous
section).
Table 18 shows a project that requires an initial investment of $70,000 (e.g., purchase of some
equipment) and another investment of $10,000 in 4 year of the project (e.g., maintenance on the
equipment or perhaps purchase of another piece of equipment).

Table 18. Operating and Investment Cash Flows


Time in Years 0 1 2 3 4 5 6 7

Operating Cash Flow $ 7,500 $ 10,000 $ 12,500 $ 15,000 $ 15,000 $ 17,500 $ 20,000

Investment Cash Flow $(70,000) $(10,000)

Net Cash Flow $(70,000) $ 7,500 $ 10,000 $ 12,500 $ 5,000 $ 15,000 $ 17,500 $ 20,000

The operating and investment cash flows are added to get a net cash flow for each period, and we
proceed as before to compute the NPV for various rates of return, as shown in Table 19. The
investments in the project make financial sense up a little over a 5% rate for the cost of capital.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 76

Table 19. NPV Analysis in the Case of Multiple Investments


Yearly Cost NPV
of Capital
0.02 $9,705
0.03 $6,258
0.04 $3,078
0.05 $143
0.06 ($2,568)
0.07 ($5,072)

7.1.4 Range of Cash Flow Estimates


In the previous examples, it was assumed that the decision making parties (regarding capital
expenditure) had a good idea of potential cash flows as a result of their investment. Another
approach (particularly when the decision makers are not so sure of the potential cash flows) is to
stipulate a range of values. For example, consider the case of Mr. Throckmorton who is starting a
new restaurant. Unfortunately, Mr. Throckmorton has only a rough idea of cash flow based on
market analysis and consequently, he can only stipulate a range of projected cash flows for each
period. It is clear, however, that the restaurant will require an initial investment of $625,000. Table
20 shows the yearly (projected) cash flows for the restaurant under pessimistic and optimistic
scenarios.

Table 20. Optimistic-Pessimistic Cash Flows for New Restaurant


Year 0 1 2 3 4 5 6 7 8 9 10

Pessimistic (625,000) 50,000 55,000 60,000 65,000 70,000 75,000 80,000 85,000 90,000 95,000

Optimistic (625,000) 60,000 66,000 72,000 78,000 84,000 90,000 96,000 102,000 108,000 114,000

Table 21 lists the NPV results for the optimistic and pessimistic cases. For the pessimistic case, the
net cash flow is only positive up to 2.5%. The optimistic case has a positive cash flow up to 5.5%.
Mr. Throckmorton could, for example, make his decision based on a compromise between the
optimistic and pessimistic scenarios, and use 4% as the cut-off point, i.e., if he can get more than
4% with an alternative investment of similar risk to the restaurant business then he should not go
ahead with the restaurant business.

©2020 The Art of Managing Things


All Rights Reserved
77 Financial Math with Python

Table 21. NPV for Optimistic and Pessimistic Scenarios


Cost of Capital Pessimistic Optimistic
per Year
0.02 $18,534.07 $144,789.90
0.025 $604.08 $122,676.11
0.03 ($16,452.34) $101,616.42
0.035 ($32,680.60) $81,556.23
0.04 ($48,123.51) $62,444.10
0.045 ($62,821.42) $44,231.52
0.05 ($76,812.39) $26,872.75
0.055 ($90,132.34) $10,324.61
0.06 ($102,815.13) ($5,453.63)
0.065 ($114,892.78) ($20,500.44)

7.1.5 Initial Investment is Loaned


All the previous examples in this section had the tacit assumption that the parties involved had the
money required for the initial investment. It is likely, however, that some or all of the money may
need to be borrowed. This clearly affects the NPV analysis since the loan repayments need to be
subtracted from the cash flow estimates.
Consider the Acme Furniture example in the case where Alice and Bob need to take out a 5-year
small business loan in the amount of $50,000 at a nominal interest rate of 3% (repaid semi-
annually). Under this scenario, Alice and Bob would need to make payments of $5,069 twice per
year for five years. These payments need to be subtracted from the cash flow estimates as shown
in Table 22.
Notes:
• In some locales, interest payments on debt are tax deductible. This would reduce the
impact on cash flow, but we didn’t consider this issue in our analysis of the project.
• While investment is entirely within the cash outflow category, operating cash flow entails
both cash inflow and outflow.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 78

Table 22. Acme Furniture - Cash Flow Estimates with Loan Repayments
Time in years 0 .5 1 1.5 2 2.5 3 3.5
Operating Cash Flow 20,000 22,000 24,000 26,000 28,000 30,000 32,000
Investment Cash Flow (225,000) (5,069) (5,069) (5,069) (5,069) (5,069) (5,069) (5,069)
Net Cash Flow (225,000) 14,931 16,931 18,931 20,931 22,931 24,931 26,931

3.5 4 4.5 5 5.5 6


32,000 34,000 36,000 38,000 41,000 44,000
(5,069) (5,069) (5,069) (5,069) 0 0
26,931 28,931 30,931 32,931 41,000 44,000

Table 23 shows the NPVs for various rates of return for alternative investments. In this scenario,
there is positive NPV up to and including 5%. Recall from the associated scenario without the loan
that it still made business sense to go ahead with the improvements to Acme Furniture up to
something over 7% but less than 8%. This is to be expected since the loan decreases net cash inflow
for each period.

Table 23. Investment Analysis for Acme Furniture with Loan Repayments
Semi-annual NPV
Cost of Capital
2% $53,625.16
3% $34,429.15
4% $17,289.98
5% $1,971.44
6% ($11,732.98)

In the above example, the length of the loan and the project were the same. If the term of the loan
was

longer than the project, then the results of the NPV analysis would not accurately reflect the value
of the proposed capital expenditure since one is not considering the effects of the loan on cash
flow after the end of the project. To address this type of problem one could extend the project
length to coincide with the length of the loan but that could involve making long-term (and likely
inaccurate) cash flow projections.

7.1.6 Comparison of Projects


It is possible to use NPV analysis to decide where to make an investment among several projects of
similar risk. Table 24 shows projected yearly cash flows for Projects A and B, based on an initial
investment of $155,000.

©2020 The Art of Managing Things


All Rights Reserved
79 Financial Math with Python

Table 24. Cash Flows for Projects A and B based on Same Initial Investment
Time in Years 0 1 2 3 4 5 6 7 8
Project A (155,000) 20,000 20,000 30,000 40,000 30,000 30,000 25,000 5,000
Project B (155,000) 50,000 10,000 20,000 20,000 20,000 30,000 25,000 25,000

Table 25 shows the computed NPVs for Projects A and B at various costs of capital. For lower rates
(from .02 to .035), Project A has a higher NPV and would thus be a slightly better choice for
investment. For rates between .04 and .06, Project B has a higher NPV and would be a better
choice in this case. For rates higher than .06, the NPV is negative for both projects. In this case, it is
better to put the capital into the alternative investment.

Table 25. NPV Comparison for Projects A and B


Cost of Capital NPV Project A NPV Project B

0.02 $28,330.62 $28,244.78


0.025 $24,550.62 $24,474.07
0.03 $20,912.86 $20,855.77
0.035 $17,411.50 $17,383.12
0.04 $14,040.96 $14,049.69
0.045 $10,795.93 $10,849.36
0.05 $7,671.35 $7,776.33
0.055 $4,662.36 $4,825.07
0.06 $1,764.37 $1,990.33
0.065 ($1,027.06) ($732.89)
0.07 ($3,716.12) ($3,349.36)

7.2 Internal Rate of Return (IRR)


In the examples from the previous section, we evaluated the NPV of a series of cash flows against a
rate of return for an alternative (and assumed to be external) investment such as bank notes,
stocks or bonds. However, we did not pinpoint the exact rate of return where the NPV is 0, i.e., the
point where there is an exact balance between the internal investment and the external alternative
(i.e., the cost of capital). This balance point is known as the internal rate of return. From Wikipedia
[11] we have the following definition:
The internal rate of return (IRR) is a measure of an investment’s expected future rate of
return. As the IRR is an estimate of a future annual rate of return, IRR should not be confused
with the actual achieved investment return of an historical investment. The term internal
refers to the fact that the calculation excludes external factors, such as the risk-free rate,
inflation, the cost of capital, or various financial risks.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 80

Technically, to find the IRR, one solves the equation for 𝑖:


𝑛

𝑁𝑃𝑉 = −𝐶0 + ∑ 𝐶𝑘 (1 + 𝑖)−𝑘 = 0


𝑘=1

which is equivalent to
𝑛

𝐶0 = ∑ 𝐶𝑘 (1 + 𝑖)−𝑘
𝑘=1

In words, we are looking for the value (or values) of 𝑖 such that the initial investment equals the
present value of the subsequent cash flows resulting from the initial investment.
The decision rules concerning the IRR are as follows:
• If the IRR is greater than the cost of capital, go forward with the project.
• If the IRR is less than the cost of capital, do not go forward with the project.
• In the unlikely event that the IRR exactly equals the cost of capital, the analysis is indifferent
as to whether the project should go forward or not.

7.2.1 Acme Furniture Example Revisited


Consider Table 14 regarding the Acme Furniture example from Section 7.1.1. From the analysis in
Table 15, we see that the IRR is somewhere between 7% and 8%. Using the Microsoft Excel IRR
function with the information from Table 14, we get the more precise value of 7.71% for the IRR.
The Excel IRR function is very easy to use (just input the initial investment and the subsequent cash
flows). For more details, see the description at [Link]
function-64925eaa-9988-495b-b290-3ad0c163c1bc.
So, if the cost of capital is less than 7.71%, the Acme Furniture should invest in the project. For cost
of capital rates higher than 7.71%, the NPV for the project becomes negative.

7.2.2 Multiple IRR Values for a Given Cash Flow


It is possible for a given cash flow to have more than one IRR, i.e., for the NPV equation to have
several values of 𝑖 that give an NPV value of 0. For example, the cash flow in Table 26 has two IRRs.

Table 26. Cash Flow with Two IRRs


Time 0 1 2 3 4 5
Net Cash Flow $ (10,000) $ 10,000 $ 11,000 $ 13,000 $ 10,000 $ (37,000)

The existence of two IRRs can be seen by graphing the equation for the NPV as a function of 𝑖
(divided by 1000 to simplify the equation), i.e.,
−10 + 10(1 + 𝑖)−1 + 11(1 + 𝑖)−2 + 13(1 + 𝑖)−3 + 10(1 + 𝑖)−4 − 37(1 + 𝑖)−5
The graph of the NPV as a function of 𝑖 is shown in Figure 13. In the graph, the y-axis is the NPV and
the x-axis represent the cost of capital 𝑖. As one can see, the graph crosses the x-axis around .05
and then again around .83. The Microsoft Excel IRR function has an optional parameter called
“guess” that allows one to start the numerical algorithm for root determination around a given
value. This is exactly what is needed in the case of several IRRs. If we use a guess of .05, the IRR

©2020 The Art of Managing Things


All Rights Reserved
81 Financial Math with Python

function in Excel returns the more precise value of .0507, and if we guess .8, the Excel IRR function
returns the value of .8243. Thus, the two IRRs are 5.07% and 82.43%. Between these two values,
the NPV is positive and it makes sense to go ahead with the initial investment of $10,000. For
values of 𝑖 less than 5.07% or greater than 82.43%, the NPV is negative and so, the initial
investment is not advised in these cases (at least not based on IRR analysis).
The possibility of multiple IRRs is one of the shortcomings with this approach to capital budgeting.
As we shall see in Section 7.3, there is a modification to the IRR concept that eliminates the
possibility of multiple solutions to the equation 𝑁𝑃𝑉 = 0.

Figure 13. Graph of NPV as a Function of the Rate of Return

7.3 Modified IRR


When comparing mutually exclusive projects, the project with the highest IRR may not be the one
with the highest NPV. The IRR approach can lead to a different decision than the NPV approach
when evaluating mutually exclusive projects because of the underlying assumptions in these
approaches:
• The NPV approach assumes that net cash flows are reinvested at the cost of capital.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 82

• The IRR approach assumes that net cash flows are reinvested at the internal rate of return.
This can lead to extreme overestimates of the future value of a project. Issues with the IRR
approach are well explained in an article from McKinsey & Company [12].
[Author’s remark: The above assumptions are common in finance books and articles, but have
nothing to do with the actual computation of the NPV or IRR. It is the decision of the party involved
concerning what interest rate they use to compute the reinvestment value of the net cash flows. In
fact, the net cash flows could be spent in a subsequent period and not reinvested at all.]
The Modified Internal Rate of Return (MIRR) is a measure of an investment's attractiveness. It is
used in capital budgeting to rank alternative investments of equal size. The MIRR is a modification
of the IRR concept and as such aims to resolve some problems with the IRR.
The MIRR is calculated as follows for a given investment:
• Determine the future value of all periods with positive cash flows using the cost of
reinvestment (call it 𝑖). The calculation is done from the time of the inflow until the end of
the project. The compute value is referred to as the Terminal Value (TV) of the cash flows.
In the equations that follow, we call this value 𝑥.
• Determine the present value (at time zero) of all the periods with negative cash flows
(including the initial investment), using the cost of financing (call it 𝑗). In the equations that
follows, we call this value 𝑦.
• Determine the MIRR, i.e., the rate of return at which the value 𝑦 accumulates to the value 𝑥
by the end of the project. Assume the project transpires over 𝑛 time periods. In the
equations that follows, the MIRR is represented by the variable 𝑧.

More formally, we have the following equation


−𝑦(1 + 𝑧)𝑛 = 𝑥
which can be solved for 𝑧 as follows
𝑥
(1 + 𝑧)𝑛 = −
𝑦

𝒏 𝒙
𝒛 = √− ( ) − 𝟏
𝒚

where
𝑥 = ∑𝑢𝑘=1 𝐶𝑘 (1 + 𝑖)𝑛−𝑡𝑘 , 𝑦 = ∑𝑣ℎ=1 𝐶ℎ (1 + 𝑗)−𝑡ℎ and 𝐶𝑚 is the cash flow for period 𝑡𝑚 .

The MIRR is used in a manner similar to the IRR. If the MIRR for a project is greater than the cost of
capital, then go forward with the project; otherwise, do not go forward with the project. When
comparing several projects, the project with the highest MIRR is preferred. Further, the MIRR can
be used to rank projects of different sizes.
Unlike the IRR, there is only one MIRR for a given project. Further, and as noted in the definitions
above, the MIRR computation allows one to use a reinvestment rate of return 𝑖 that is different
from the MIRR itself.

©2020 The Art of Managing Things


All Rights Reserved
83 Financial Math with Python

As an example, consider the investment and cash flow data for a potential project in Table 27.

Table 27. Input for MIRR Example


Year 0 1 2 3 4 5
Net Cash Flow for year (25,000) (5,000) 5,000 20,000 20,000 20,000

Assume that the cash inflows in years 2, 3 and 4 are reinvested at rate 𝑖 = .04. The cash inflow in
year 5 is at the end of the project and so, there is no reinvestment (at least not during the time
duration of the project). We now have sufficient information to calculate 𝑥.
𝑥 = 5,000(1.04)3 + 20,000(1.04)2 + 20,000(1.04)1 + 20,000 = 68,056.32
Next, we compute the net cash outflows at 𝑡 = 0, assuming a financing rate 𝑗 = .05
𝑦 = −(25,000 + 5,000(1.05)−1 ) = −29,761.90476
The MIRR is

5 68,056.32
√− ( ) − 1 ≅ 0.1799
−29,761.90476

This can be cross checked with the Microsoft Excel MIRR function, which does in fact return the
result of 17.99%. A description of the Excel MIRR function can be found at
[Link]
35c345b53524.
Using the Excel IRR function, we find that the IRR for this problem is 23.99%.
For an additional example, see the Wikipedia article on MIRR [13].

7.4 Payback and Discounted Payback Period


Payback Period and Discounted Payback Period (DPP) are decision techniques used to evaluate
investment projects. The payback period approach entails a calculation of the time duration
required to recover the cost of an initial investment. The shorter the time, the better the
investment. The discounted payback period approach is similar except that one uses the
discounted values of the cash flows.
From the Investopedia article on Payback Period [14]:
The payback period refers to the amount of time it takes to recover the cost of an
investment. Simply put, the payback period is the length of time an investment reaches a
break-even point.
From the Investopedia article on DDP [15]:
The discounted payback period is a capital budgeting procedure used to determine the
profitability of a project. A discounted payback period gives the number of years it takes to
break even from undertaking the initial expenditure, by discounting future cash flows and
recognizing the time value of money. The metric is used to evaluate the feasibility and
profitability of a given project.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 84

The DDP concept is very simple as can be illustrated via an example. Consider Projects A and B from
the example in Section 7.1.3, with an assumed cost of capital of 2.5%. Table 28 shows the
discounted cash flows for Project A and the cumulative sum of the discounted cash flows. As can be
seen, it is not until the end of year 6 that Project A has recovered the initial investment. (The
discounting is done with respect to time 0.)

Table 28. DPP for Project A


Years 0 1 2 3 4 5 6 7 8

Cash Flows (155,000) 20,000 20,000 30,000 40,000 30,000 30,000 25,000 5,000

Discounted Cash Flows (155,000) 19,512 19,036 27,858 36,238 26,516 25,869 21,032 4,104

Accumulated Discounted Cash (155,000) (135,488) (116,452) (88,594) (52,356) (25,840) 29 21,061 25,164
Flows

Table 29 shows similar calculations for Project B, which takes an additional year to break even.

Table 29. DPP for Project B


Years 0 1 2 3 4 5 6 7 8

Cash Flows (155,000) 50,000 10,000 20,000 20,000 20,000 30,000 25,000 25,000

Discounted Cash Flows (155,000) 48,780 9,518 18,572 18,119 17,677 25,869 21,032 20,519

Accumulated Discounted Cash (155,000) (106,220) (96,701) (78,129) (60,010) (42,333) (16,464) 4,567 25,086
Flows

Based on DPP analysis, the decision should be to go forward with Project A since it achieves
payback of the initial investment in 6 years whereas payback for Project B is not until the 7th year.

7.5 Profitability Index


The Profitability Index (PI) is the ratio of payoff to investment for a proposed project. It is useful for
ranking projects because it allows one to quantify the amount of value created per unit of
investment. More precisely, the profitability index is defined as the NPV of the cash inflows for a
project divided by the NPV of the cash outflows. In terms of a formula, we have
∑𝑛𝑘=1 𝐶𝐼𝐹𝑘 (1 + 𝑖)−𝑡𝑘
𝑃𝐼 = −𝑡𝑗
∑𝑚𝑗=1 𝐶𝑂𝐹𝑗 (1 + 𝑖)

where 𝐶𝐼𝐹𝑘 stands for 𝑘 𝑡ℎ cash inflow at time 𝑡𝑘 and 𝐶𝑂𝐹𝑗 stands for 𝑗 𝑡ℎ cash outflow at time 𝑡𝑗 .
Keep in mind that the cash outflows are converted to positive numbers for the calculation of the PI.
[Author’s remarks: This looks worse that it is. It’s just a matter of computing the NPV for the cash
inflows and outflows separately and then dividing to get the PI.
Also, some (perhaps most) sources use an alternative definition of PI where the denominator only
includes the initial investment and the numerator is the sum of the present values of all other cash
flows. See, for example, the article on PI in Investopedia [16] which uses the alternate definition of
PI.]
As an example, we will compute the PI for Projects A and B from Section 7.1.3, under the
assumption of a 2.5% cost of capital:

©2020 The Art of Managing Things


All Rights Reserved
85 Financial Math with Python

180,164
PI for Project A = 155,000 = 1.1624
180,086
PI for Project A = 155,000 = 1.1618

The general rule is to select the project with the highest PI. So, in this case, we should go forward
with Project A (albeit by a small margin).

7.6 Computational Support via Microsoft Excel


There are no supporting Python programs for this section. However, there is an Excel spreadsheet
that covers many of the concepts in this section. The spreadsheet is in a file named “Capital
[Link]”. The spreadsheet is located in the same Github directory as the Python programs.
A brief summary of the sheets within the spreadsheet is listed below:
• Acme Furniture – this sheet shows the NPV calculations for the Acme Furniture example
under the 5 year and 6 year scenarios. The calculation of the IRR is also provided (using the
Excel IRR function).
• Resort – this sheet provides an NPV analysis for the resort example in Section 7.1.2
concerning negative cash flows.
• Multiple Inv – this sheet supports the multiple investments example from Section 7.1.3.
• Restaurant – this sheet provides an NPV analysis for pessimistic and optimistic scenarios
regarding a restaurant (from Section 7.1.4).
• Acme Furniture – scroll down on this sheet and there is a separate calculation for the loan
scenario in Section 7.1.5
• Project Comparison – this sheet provides an analysis of Projects A and B in Section 7.1.6.
• Multiple IRRs – this sheet supports the multiple IRR example in Section 7.2.2.
• MIRR – this supports the MIRR example in Section 7.3.
• DDP and PI – this sheet supports DDP and PI examples that span Sections 7.4 and 7.5.
• Ex 1 – this sheet provides the answer to Exercise 1 in Section 7.7.
• Ex 2 – this sheet provides the answer to Exercise 2 in Section 7.7.

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 86

7.7 Exercises
1. Given an initial investment of $70,000 and projected yearly cash flows of $5,000, $7,500,
$10,000, $12,500, $15,000, $17,500 and $20,000, compute the NPV for rates of return of 2,
3, 4, 5, 6 and 7 percent. Answer: See the sheet entitled “Ex 1” in the Excel file “Capital
[Link]”.
2. For the example in Section 7.1.5, assume the term of the loan is 10 years at 3% per year
with semi-annual payments. Further, assume the project returns no cash inflows after year
6. Compute the NPV for the (semi-annual) cost of capital ranging from 2% to 8% in
increments of .5%. Hint: Use the Amortization Calculator to determine the semi-annual
payments. Answer: See the sheet entitled “Ex 2” in the Excel file “Capital [Link]”.
3. For the example in Section 7.1.5, what is the maximum amount that Alice and Bob can loan
(under the same terms as the example) and still have a positive NPV at 2% rate of return?
Hint: Use the amortization calculator to determine the semi-annual loan repayments for
different loan amounts, subtract the repayment amount from each of the cash flow
estimates in Table 14 (just for the first years) and then compute the NPV for a 2% rate of
return. You will need to experiment with several different loan amounts. Answer: For a loan
in the amount of $110,075, the NPV is about -$9.86 (at 2% cost of capital). So, for a positive
NPV (at 2% cost of capital), the loan needs to be a little less than $110,075 (assuming a 3%
nominal interest rate paid semi-annually on the loan).
4. Use the Microsoft Excel IRR function to compute the IRRs for Projects A and B in the
example from Section 7.1.6. Answer: 6.31% for Project A and 6.36% for Project B.
5. Use the Microsoft Excel MIRR function to compute the MIRRs for Project A and B in the
example from Section 7.1.6. Assume a reinvestment rate of .015 and a financing rate of
.025. Do the calculation again with a reinvestment rate of .08 and a financing rate of .06.
Answer: In the first scenario, 3.96% for Project A and 3.95% for Project B. In the second
scenario, 7.15% for Project A and 7.20% for Project B.

©2020 The Art of Managing Things


All Rights Reserved
87 Financial Math with Python

Acronyms and Symbols


AER – Annual Equivalent Rate
APY – Annual Percentage Yield
CSV – Comma-Separated Values
DPP – Discounted Payback Period
EIR – Effective Interest Rate
EMI – Equated Monthly Installment
FV – Future Value
GUI – Graphical User Interface
IRR – Internal Rate of Return
MIRR – Modified Internal Rate of Return
NPV – Net Present Value
P – typically used to represent Principal
PV – Present Value
TV – Terminal Value

©2020 The Art of Managing Things


All Rights Reserved
Financial Math with Python 88

References
[1] Decimal separator, Wikipedia, [Link]/wiki/Decimal_separator, accessed on 19
December 2020.
[2] Brown, R., Kopp, S., Financial Mathematics: Theory and Practice, McGraw-Hill Ryerson
Limited, 2012.
[3] Broverman, S., Mathematics of Investment and Credit, ACTEX Publications, 2010.
[4] Alhabeeb, M.J., Mathematical Finance, John Wiley & Sons, Inc., 2012.
[5] Fisher equation, Wikipedia, [Link]/wiki/Fisher_equation, accessed on 21
December 2020.
[6] Peterson Drake, P., Fabozzi, F., The Basics of Finance: An Introduction to Financial
Markets, Business Finance, and Portfolio Management, John Wiley & Sons, Inc., 2012.
[7] Cost of capital, Wikipedia, [Link]/wiki/Cost_of_capital, accessed on 27 August
2020.
[8] Bennett, T., What is a cash flow statement? - MoneyWeek Investment Tutorials, YouTube
Video, [Link] accessed 16 August 2020.
[9] Tuovila, A., Cash Flow, Investopedia article and embedded video,
[Link] accessed 16 August 2020.
[10] Net present value, Wikipedia, [Link]/wiki/Net_present_value, accessed 17
August 2020.
[11] Internal rate of return, Wikipedia, [Link]/wiki/Internal_rate_of_return,
accessed 21 August 2020.
[12] Kelleher, J.C., and Justin J. MacCormack, J.J., Internal rate of return: A cautionary tale,
McKinsey Quarterly, April 2004. [Document available at
[Link]
insights/internal-rate-of-return-a-cautionary-tale]
[13] Modified internal rate of return, Wikipedia,
[Link]/wiki/Modified_internal_rate_of_return, accessed on 26 August 2020.
[14] Payback Period, Investopedia,
[Link] accessed 30 December
2020.
[15] Discounted Payback Period, Investopedia,
[Link] accessed 30
December 2020.
[16] Chen, J., Profitability Index, Investopedia,
[Link] accessed on 25 August 2020.

©2020 The Art of Managing Things


All Rights Reserved
89 Financial Math with Python

Index of Terms

Accumulated value of an annuity, 28 Forborne annuity, 35


Amortization, 44 General annuity, 28
Annual percentage yield, 20 Internal rate of return, 79
Annuity, 28 Issue price, 56
Annuity certain, 28 Marketable bonds, 57
Annuity-due, 28, 33 Maturity date of a bond, 56
Balloon loan, 17 Modified internal rate of return, 82
Bond, 56 Net present value, 71
Callable bond, 56 Nominal interest rate, 17
Clean price of a bond, 65 Ordinary annuity, 28
Contingent annuity, 28 Payback Period, 83
Continuous annuity, 37 Perpetuity, 37
Cost of capital, 71 Present value, 21
Coupon rate, 56 Profitability index, 84
Deferred annuity, 28 Real rate of return, 26
Dirty price of a bond, 63 Redeemed at par, 56
Discount, 21 Redemption value of a bond, 56
Discounted Payback Period, 83 Savings bonds, 57
Discounted value of an annuity, 28 Simple annuity, 28
Effective rate of interest, 19 Term of annuity, 28
Face value of a bond, 56 Yield of a bond, 56
Focal date, 24 Zero-coupon bond, 56

©2020 The Art of Managing Things


All Rights Reserved

View publication stats

You might also like