Skip to content

Commit 72eebde

Browse files
author
Jeonghyun Min
committed
feat: create get_ordinary_annuity_future_value
1 parent 6e24935 commit 72eebde

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
An ordinary annuity means making or requiring payments at the end
3+
of each term during a given period.
4+
For example, if the given period is 3 terms long and the payment
5+
for each term is $1000, then the cash flow is as follows:
6+
7+
0: no payment --- 1: $1000 --- 2: $1000 --- 3: $1000
8+
9+
The function, get_ordinary_annuity_future_value, calculates the future value of
10+
the given ordinary annuity. In the example above, the function should return
11+
the sum of each payment's future value at the end of term 3,
12+
which means the sum is returned as soon as the last payment is made.
13+
14+
More info on: https://www.investopedia.com/retirement/calculating-present-and-future-value-of-annuities
15+
16+
This function can help to understand how much you will receive
17+
if you make a regular deposit at the end of each term
18+
for saving with a fix period and interest rate.
19+
"""
20+
21+
22+
def get_ordinary_annuity_future_value(
23+
term_payment: float, number_of_payments: int, term_interest_rate: float
24+
) -> float:
25+
"""
26+
Calculate the future value of the given ordinary annuity
27+
:param term_payment: payment made at the end of each term
28+
:param number_of_payments: the number of payments
29+
:param term_interest_rate: the interest rate for each term
30+
:return: the future value (maturity value) of the given ordinary annuity
31+
32+
Examples:
33+
>>> round(get_ordinary_annuity_future_value(500, 10, 0.05), 2)
34+
6288.95
35+
>>> round(get_ordinary_annuity_future_value(1000, 10, 0.05), 2)
36+
12577.89
37+
>>> round(get_ordinary_annuity_future_value(1000, 10, 0.10), 2)
38+
15937.42
39+
>>> round(get_ordinary_annuity_future_value(1000, 20, 0.10), 2)
40+
57275.0
41+
"""
42+
43+
annuity_factor = (
44+
((1 + term_interest_rate) ** number_of_payments) - 1
45+
) / term_interest_rate
46+
future_value = term_payment * annuity_factor
47+
return future_value
48+
49+
50+
if __name__ == "__main__":
51+
user_input_amount = float(input("How much money will be deposited each term?\n> "))
52+
user_input_payment_number = int(input("How many payments will be made?\n> "))
53+
term_interest_rate = float(input("What is the interest rate per term?\n> "))
54+
print(
55+
get_ordinary_annuity_future_value(
56+
user_input_amount, user_input_payment_number, term_interest_rate
57+
)
58+
)

0 commit comments

Comments
 (0)