Skip to content

Commit c27e951

Browse files
kangaroo-eating-carrotsJeonghyun Mincclauss
authored
feat: create get_ordinary_annuity_future_value function in financial (#12358)
* feat: create get_ordinary_annuity_future_value * Rename function to ordinary_annuity_future_value * updating DIRECTORY.md * updating DIRECTORY.md --------- Co-authored-by: Jeonghyun Min <20122791@tafe.wa.edu.au> Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: cclauss <cclauss@users.noreply.github.com>
1 parent 793a5f7 commit c27e951

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

DIRECTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@
551551
* [Interest](financial/interest.py)
552552
* [Kelly Criterion](financial/kelly_criterion.py)
553553
* [Macaulay Duration](financial/macaulay_duration.py)
554+
* [Ordinary Annuity Future Value](financial/ordinary_annuity_future_value.py)
554555
* [Present Value](financial/present_value.py)
555556
* [Price Plus Tax](financial/price_plus_tax.py)
556557
* [Sharpe Ratio](financial/sharpe_ratio.py)
Lines changed: 58 additions & 0 deletions
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, 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 you understand how much you will receive if you make a
17+
regular deposit at the end of each term for saving with a fixed period and
18+
interest rate.
19+
"""
20+
21+
22+
def 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(ordinary_annuity_future_value(500, 10, 0.05), 2)
34+
6288.95
35+
>>> round(ordinary_annuity_future_value(1000, 10, 0.05), 2)
36+
12577.89
37+
>>> round(ordinary_annuity_future_value(1000, 10, 0.10), 2)
38+
15937.42
39+
>>> round(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+
ordinary_annuity_future_value(
56+
user_input_amount, user_input_payment_number, term_interest_rate
57+
)
58+
)

0 commit comments

Comments
 (0)