Discounting bond cash flows with a known yield
After laying out the bond's cash flows, we can now go through the steps of calculating the present value of each cash flow and value the bond. Recall that the value of the bond is the sum of the present value of its cash flows.
In this exercise, you will calculate the appropriate present value factor, pv_factor
, for each cash flow, so we can calculate each cash flow's present value pv
. You will then sum the pv
to find the value of the bond.
Recall that this bond has a yield of 6%, which acts as the discount rate. The data frame you created in the prior exercise, cf
, is present in your workspace.
This exercise is part of the course
Bond Valuation and Analysis in R
Exercise instructions
- Create a new column,
t
, in yourcf
data frame to indicate the year in which cash flow is received. Note that for your purposes, the year is equivalent to the name of the rows in your data frame (1
,2
,3
, etc.). This means you can simply userownames()
to namet
. Useas.numeric()
to make sure the values oft
are numeric. - Create another new column,
pv_factor
in yourcf
object to store each year's present value factor. Recall that each year's present value factor is calculated as 1 divided by 1 + the yield rate (in this case 6%, or0.06
) set to the power of your time variable (t
). - Create a
pv
column incf
to store the present value of each year's cash flow. The present value is calculated as cash flow (cf
) multiplied by the year's present value factor (pv_factor
). - Finally, use
sum()
to sum the values inpv
to find the value of the bond.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add column t to cf
cf$t <- as.numeric(___(___))
# Calculate pv_factor
cf$pv_factor <- 1 / (1 + ___)^___
# Calculate pv
cf$pv <- ___ * ___
# Calculate the bond price
sum(___$___)