## Time Value of Money¶

Let us see what happens when we deposit an amount $A_0$ for a 2 year term.

Assuming that rate of interest is $r$, the deposit at the end of first year will grow to be

$$A_{1} = A_{0}+ rA_{0} = A_0 (1+r)$$

Further assuming same rate of interest, the deposit at the end of 2nd year is: $$A_2 = A_1 (1+r) = A_0 (1+r)^2$$

### Future Value of current money¶

Similarly, if the amount is deposited for N years, the final value of the at the end of term is: $$A_N = A_0 (1+r)^N$$.

### Current value of future money¶

Above expression is the formula for future value of money. It also can be used to calculate current value of future payables i.e $$A_0 = \frac{A_N}{(1+r)^N}$$ Note : $A_0$ is also called the discounted value of $A_N$.

The term of the deposit does not have to be quoted in number years necessarily, it could be months as well. In such a case the symbol $r$ would stand for monthly rate of interest and N for “number of months in term deposit’.

Now let us write a function to calculate time value of money.

```
###################################################
# Filename : time_value_of_money #
# Purpose : To demonstrate #
# 1. Console input/output #
# 2. Control Structures: while, if-else #
# #
# Author : Niel S. #
# The English Tea Company LLC #
###################################################
# The main function
def main():
# The shut down switch for calculator.
keep_running = 'Y'
#While the switch is on...
while (keep_running=='Y'):
#Gather data from screen
amount = float (input ("Enter amount: "))
time_n = float (input ("Enter time (+ for FV/ - for CV) : "))
r = float (input ("Enter rate of interest: "))
#Function call. User's arguments supplied to parameters.
time_val = time_value (a=amount,r=r,N=time_n)
#Being smart about Future Value (FV) vs Current Value (CV)
out_type = 'FV'
if time_n < 0 : out_type = 'CV'
#Prepare a nice output string, and show results.
output = 'The '+out_type+' of $'+str(amount)+' is : $'+str(time_val)+'. '
print (output)
#Ask user if he wishes to shut down the calculator.
keep_running = input ('Enter Y to continue: ').strip().upper()
#print a nice space separator.
print ('\n'*2)
return 0
def time_value(a, r, N):
'''
Parameters:
a = Amount (+ values only)
r = Rate of interest (+ values only)
N = Number of time-units (Years/Months) (+ or - values).
Note: The r must be quoted in same time-units as N.
Returns: a1
When N > 0 : Future Value of 'a' after N time-units.
When N < 0 : Current Value of 'a' payable after N time-units.
'''
#Check for insane input
if a < 0 : return -1
if r < 0 : return -1
#Calculate using formula a_n = a*(1+r)^n
a1 = a *pow((1+r),N)
a1 = round (a1,2)
return a1
if __name__ == '__main__':
main()
```