10.12.2019 Views

Python for Finance

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Time Value of Money

Example 1: >>>pv_f(0.1,1,100) # meanings of input variables

90.9090909090909 # based on their input order

>>>

Example #2 >>>pv_f(r=0.1,fv=100,n=1) # meanings based on keywords

90.9090909090909

Last but not least, a new learner could write his/her own financial calculator! For

more detail, see the Writing your own financial calculator written in Python section and

Appendix H.

From the preceding discussion, it is known that for the present value of annuity, the

following formula could be used:

In the preceding formula, we have four variables of pv, c, R, and n. To estimate a

present value, we are given c, R, and n. Actually, for any set of three values, we could

estimate the number 4. Let's use the same notations in SciPy and NumPy:

The four corresponding functions are: sp.pv(), sp.pmt(), sp.rate(), and

sp.nper(). Here is an example. John is planning to buy a used car with a price tag of

$5,000. Assume that he would pay $1,000 as the download payment and borrow the

rest. The annual interest rate for a car load is 1.9% compounded monthly. What is his

monthly payment if he plans to retire his load in three years? We could calculate the

monthly payment manually; see the following code:

>>> r=0.019/12

>>> pv=4000

>>> n=3*12

>>> pv*r/(1-1/(1+r)**n)

114.39577546409993

[ 84 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!