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