Get Started

Present value of projected cash flows (1)

Time for some analysis! Earlier, Lore introduced the idea of present value. You will use that idea in the next two exercises, so here is another example.

If you expect a cash flow of $100 to be received 1 year from now, what is the present value of that cash flow at a 5% interest rate? To calculate this, you discount the cash flow to get it in terms of today's dollars. The general formula for this is:

present_value <- cash_flow * (1 + interest / 100) ^ -year

95.238 = 100 * (1.05) ^ -1

Another way to think about this is to reverse the problem. If you have $95.238 today, and it earns 5% over the next year, how much money do you have at the end of the year? We know how to do this problem from way back in chapter 1! Find the multiplier that corresponds to 5% and multiply by $95.238!

100 = 95.238 * (1.05)

Aha! To discount your money, just do the reverse of what you did with stock returns in chapter 1.

This is a part of the course

“Introduction to R for Finance”

View Course

Exercise instructions

  • If you expect to receive $4000 in 3 years, at a 5% interest rate, what is the present value of that money? Follow the general formula above and assign the result to present_value_4k.
  • Using vectors, you can calculate the present value of the entire column of cash_flow at once! Use cash$cash_flow, cash$year and the general formula to calculate the present value of all of your cash flows at 5% interest. Add it to cash as the column present_value.
  • Print out cash to see your new column.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Present value of $4000, in 3 years, at 5%
present_value_4k <- 

# Present value of all cash flows
cash$present_value <-

# Print out cash

This exercise is part of the course

Introduction to R for Finance

BeginnerSkill Level
4.8+
12 reviews

Learn essential data structures such as lists and data frames and apply that knowledge directly to financial examples.

Arguably the most important data structure in R, the data frame is what most of your data will take the form of. It combines the structure of a matrix with the flexibility of having different types of data in each column.

Exercise 1: What is a data frame?Exercise 2: Create your first data.frame()Exercise 3: What goes in a data frame?Exercise 4: Making head()s and tail()s of your data with some str()uctureExercise 5: Naming your columns / rowsExercise 6: Data frame manipulationExercise 7: Accessing and subsetting data frames (1)Exercise 8: Accessing and subsetting data frames (2)Exercise 9: Accessing and subsetting data frames (3)Exercise 10: Adding new columnsExercise 11: Present valueExercise 12: Present value of projected cash flows (1)
Exercise 13: Present value of projected cash flows (2)

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