Present value
Luckily for you, there is a module called numpy
which contains many functions which will make your life much easier when working with financial values.
The .pv(rate, nper, pmt, fv)
function, for example, allows you to calculate the present value of an investment as before with a few simple parameters:
- rate: The rate of return of the investment
- nper: The lifespan of the investment
- pmt: The (fixed) payment at the beginning or end of each period (which is 0 in our example)
- fv: The future value of the investment
You can use this formula in many ways. For example, you can calculate the present value of future investments in today's dollars.
This is a part of the course
“Introduction to Financial Concepts in Python”
Exercise instructions
- Import
numpy
asnp
. - Using NumPy's
.pv()
function, compute the present value of an investment which will yield $10,000 15 years from now at an inflation rate of 3% per year and assign it toinvestment_1
. - Compute the present value of the same investment, but with a time horizon of only 10 years and an inflation rate of 5%, assigning it to
investment_2
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import numpy as np
____
# Calculate investment_1
investment_1 = ____(rate=____, nper=____, pmt=____, fv=10000)
# Note that the present value returned is negative, so we multiply the result by -1
print("Investment 1 is worth " + str(round(-investment_1, 2)) + " in today's dollars")
# Calculate investment_2
investment_2 = ____
print("Investment 2 is worth " + str(round(-investment_2, 2)) + " in today's dollars")