Get Started

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”

View Course

Exercise instructions

  • Import numpy as np.
  • 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 to investment_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")

This exercise is part of the course

Introduction to Financial Concepts in Python

BeginnerSkill Level
4.6+
8 reviews

Using Python and NumPy, learn the most fundamental financial concepts.

Learn about fundamental financial concepts like the time value of money, growth and rate of return, discount factors, depreciation, and inflation.

Exercise 1: Fundamental financial conceptsExercise 2: Growth and rate of returnExercise 3: Compound interestExercise 4: Discount factors and depreciationExercise 5: Present and future valueExercise 6: Present value
Exercise 7: Future valueExercise 8: Adjusting future values for inflationExercise 9: Net present value and cash flowsExercise 10: Discounting cash flowsExercise 11: Initial project costsExercise 12: Diminishing cash flows

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free