Dessign the function valor_presente(I, r) that calculates the present value of an investment I represented as a list of monthly payments and a monthly interest rate r.
Example: John asks Paul to rent his vehicle for 3 months for a monthly payment of 5000 euros (the first payment is today). Once this time has passed, he will buy the vehicle for 45000 euros. John’s opportunity cost is 5% monthly. ¿Which is the present value of the project?
John’s investment is: I= [5000, 5000, 5000, 45000]. The opportunity cost is r = 0.05. The valor_presente(I, r) is
5000 + 5000/(1.05) + 5000/(1.05)2 + 45000/(1.05)3 = 53169.74408811143 |
In general, if the investment is given by I = [I0, I1, …, In], the present value is I[0] + ∑i=1nI[i]/(1+r)i
>>> round(valor_presente([5000, 5000, 5000, 45000], 5), 2) 53169.74 >>> round(valor_presente([100, -50, 35], 7), 2) 83.84 >>> valor_presente([], 3) 0.0